You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.0 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. #pragma once
  2. #include "port.h"
  3. #include "ozone_work.h"
  4. #define POWER_KEY_TRIGGER_TIME 3000
  5. #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
  6. #define ZKEY_INIT(_name, _get_key_state) \
  7. { .name = _name, .get_key_state = _get_key_state }
  8. #define ZMODULE_INIT(_keys, _onkey) /**/ \
  9. { /**/ \
  10. .keys = _keys, /**/ \
  11. .nkey = ARRAY_SIZE(_keys), /**/ \
  12. .onkey = _onkey /**/ \
  13. }
  14. typedef enum {
  15. // mode1
  16. zks_keep,
  17. zks_rising_edge, //�����ذ������´�0-1
  18. zks_falling_edge, //�½��ذ���̧��1-0
  19. // mode2
  20. zks_trigger_event, //����
  21. zks_longtime_trigger_event, //��ʱ�䴥��
  22. } zkey_event_t;
  23. typedef zkey_event_t zkey_state_t;
  24. typedef bool (*get_key_state_t)(void);
  25. typedef struct {
  26. const char *name;
  27. get_key_state_t get_key_state;
  28. bool last_io_state;
  29. zkey_state_t cur_state; //��ǰ��״̬
  30. uint32_t keep_state_count; /*������ǰ״̬�����˶���*/
  31. bool hasProcessed; /*useful for user*/
  32. bool after_filter_state;
  33. uint32_t currentstatekeep_count; //����ʹ��
  34. bool last_real_state; //����ʹ��
  35. } zkey_t;
  36. static uint16_t s_key_press_state;
  37. static uint16_t s_key_long_press_time_ms = 3000; //�����ж�ʱ��
  38. #define KEY_SCAN_PERIOD 20 //ɨ������20ms
  39. typedef struct {
  40. zkey_t *keys;
  41. int nkey;
  42. void (*onkey)(zkey_t *key, zkey_state_t key_state);
  43. } zkey_module_t;
  44. static zkey_module_t *s_module;
  45. static bool s_inited;
  46. void zkey_init(zkey_module_t *module);
  47. void zkey_do_loop_in_each_period(void *_null);
  48. void zkey_process_each(zkey_t *each);
  49. void zkey_process_each_after_filter(zkey_t *each, bool now_io_state);
  50. void read_key_state(void);
  51. void onkey(zkey_t *key, zkey_state_t key_state);
  52. void port_key_state(void);