task.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (C) 2023 Daniele Lacamera <root@danielinux.net>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <stdint.h>
  18. #ifndef TASK_H_INCLUDED
  19. #define TASK_H_INCLUDED
  20. #define EV_NONE (0)
  21. /* Events are ordered by priority (lower position = higher prio) */
  22. #define EV_BUTTON (1 << 1)
  23. #define EV_HEARTBEAT (1 << 3)
  24. #define EV_SYSTICK (1 << 5)
  25. #define EV_SERIAL (1 << 6)
  26. #define EV_VESSELDATA (1 << 7)
  27. struct task
  28. {
  29. void (*init)(void);
  30. void (*run)(uint32_t ev, void *arg);
  31. uint32_t events;
  32. const char *name;
  33. struct screen *screen;
  34. struct task *next;
  35. };
  36. struct screen
  37. {
  38. struct task *task;
  39. void (*draw)(void);
  40. void (*refresh)(void);
  41. const char *name;
  42. int id;
  43. struct screen *next;
  44. };
  45. void register_task(struct task *t);
  46. void register_screen(struct task *t, struct screen *s);
  47. void task_add_events(struct task *t, uint32_t ev);
  48. void task_del_events(struct task *t, uint32_t ev);
  49. void trigger_event(uint32_t ev);
  50. struct screen *screen_get_focus(void);
  51. struct screen *screens(void);
  52. #endif