input.h 997 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef __INPUT_H
  2. #define __INPUT_H
  3. #include <stdbool.h>
  4. #define INPUT_COUNT 7
  5. typedef enum {
  6. InputUp = 0,
  7. InputDown,
  8. InputRight,
  9. InputLeft,
  10. InputOk,
  11. InputBack,
  12. InputCharging,
  13. } Input;
  14. typedef struct {
  15. Input input;
  16. bool state;
  17. } InputEvent;
  18. typedef struct {
  19. bool up : 1;
  20. bool down : 1;
  21. bool right : 1;
  22. bool left : 1;
  23. bool ok : 1;
  24. bool back : 1;
  25. bool charging : 1;
  26. } __attribute__((packed)) InputState;
  27. #define _BITS2STATE(bits) \
  28. { \
  29. .up = (((bits)&0x01) != 0), .down = (((bits)&0x02) != 0), .right = (((bits)&0x04) != 0), \
  30. .left = (((bits)&0x08) != 0), .ok = (((bits)&0x10) != 0), .back = (((bits)&0x20) != 0), \
  31. .charging = (((bits)&0x40) != 0) \
  32. }
  33. #endif /* __INPUT_H */