input_manager.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. * Copyright (c) 2018 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file input manager interface
  8. */
  9. #ifndef __INPUT_MANGER_H__
  10. #define __INPUT_MANGER_H__
  11. #include <stdbool.h>
  12. #include <input_manager_type.h>
  13. /**
  14. * @defgroup input_manager_apis App Input Manager APIs
  15. * @ingroup system_apis
  16. * @{
  17. */
  18. /*
  19. * Input device types
  20. */
  21. #define INPUT_DEV_TYPE_KEYBOARD 1
  22. #define INPUT_DEV_TYPE_TOUCHPAD 2
  23. /** key action type */
  24. enum GESTURE_TYPE
  25. {
  26. /** gesture drop down */
  27. GESTURE_DROP_DOWN = 1,
  28. /** gesture drop up */
  29. GESTURE_DROP_UP,
  30. /** gesture drop left */
  31. GESTURE_DROP_LEFT,
  32. /** gesture drop right */
  33. GESTURE_DROP_RIGHT,
  34. };
  35. #define GESTURE_HOR_BITFIELD ((0x1 << GESTURE_DROP_LEFT) | (0x1 << GESTURE_DROP_RIGHT))
  36. #define GESTURE_VER_BITFIELD ((0x1 << GESTURE_DROP_DOWN) | (0x1 << GESTURE_DROP_UP))
  37. #define GESTURE_ALL_BITFIELD (GESTURE_HOR_BITFIELD | GESTURE_VER_BITFIELD)
  38. /** key action type */
  39. enum KEY_VALUE
  40. {
  41. /** key press down */
  42. KEY_VALUE_DOWN = 1,
  43. /** key press release */
  44. KEY_VALUE_UP = 0,
  45. };
  46. /** key event STAGE */
  47. enum KEY_EVENT_STAGE
  48. {
  49. /** key press pre process */
  50. KEY_EVENT_PRE_DONE = 0,
  51. /** key press event done */
  52. KEY_EVENT_DONE = 1,
  53. };
  54. /** States for input devices*/
  55. enum {
  56. INPUT_DEV_STATE_REL = 0,
  57. INPUT_DEV_STATE_PR,
  58. };
  59. typedef uint8_t input_dev_state_t;
  60. /** Possible input device types*/
  61. enum {
  62. INPUT_DEV_TYPE_NONE, /**< Uninitialized state*/
  63. INPUT_DEV_TYPE_POINTER, /**< Touch pad, mouse, external button*/
  64. INPUT_DEV_TYPE_KEYPAD, /**< Keypad or keyboard*/
  65. INPUT_DEV_TYPE_BUTTON, /**< External (hardware button) which is assigned to a specific point of the
  66. screen*/
  67. INPUT_DEV_TYPE_ENCODER, /**< Encoder with only Left, Right turn and a Button*/
  68. };
  69. typedef uint8_t input_dev_type_t;
  70. /**
  71. * Represents a point on the screen.
  72. */
  73. typedef struct {
  74. int16_t x;
  75. int16_t y;
  76. } point_t;
  77. /** Data structure passed to an input driver to fill */
  78. typedef struct _input_dev_data_t {
  79. union {
  80. struct { /**< For INPUT_DEV_TYPE_POINTER the currently pressed point*/
  81. point_t point;
  82. int8_t gesture_dir; /* gesture direction */
  83. int8_t scroll_dir; /* scroll direction */
  84. };
  85. uint32_t key; /**< For INPUT_DEV_TYPE_KEYPAD the currently pressed key*/
  86. uint32_t btn_id; /**< For INPUT_DEV_TYPE_BUTTON the currently pressed button*/
  87. int16_t enc_diff; /**< For INPUT_DEV_TYPE_ENCODER number of steps since the previous read*/
  88. };
  89. input_dev_state_t state; /**< INPUT_DEV_STATE_REL or INPUT_DEV_STATE_PR*/
  90. } input_dev_data_t;
  91. /** Initialized by the user and registered by 'lv_indev_add()'*/
  92. typedef struct _input_drv_t {
  93. /**< Input device type*/
  94. input_dev_type_t type;
  95. struct device *input_dev;
  96. /**< Function pointer to read input device data.
  97. * Return 'true' if there is more data to be read (buffered).
  98. * Most drivers can safely return 'false' */
  99. bool (*read_cb)(struct _input_drv_t * indev_drv, input_dev_data_t * data);
  100. /** Called when an action happened on the input device.
  101. * The second parameter is the event from `lv_event_t`*/
  102. void (*feedback_cb)(struct _input_drv_t *, uint8_t);
  103. void (*enable)(struct _input_drv_t * indev_drv, bool enable);
  104. /**< Number of pixels to slide before actually drag the object*/
  105. uint8_t scroll_limit;
  106. /**< Drag throw slow-down in [%]. Greater value means faster slow-down */
  107. uint8_t scroll_throw;
  108. /**< At least this difference should between two points to evaluate as gesture*/
  109. uint8_t gesture_min_velocity;
  110. /**< At least this difference should be to send a gesture*/
  111. uint8_t gesture_limit;
  112. /**< Long press time in milliseconds*/
  113. uint16_t long_press_time;
  114. /**< Repeated trigger period in long press [ms] */
  115. uint16_t long_press_rep_time;
  116. } input_drv_t;
  117. /** Run time data of input devices
  118. * Internally used by the library, you should not need to touch it.
  119. */
  120. typedef struct _input_dev_runtime_t {
  121. input_dev_state_t state; /**< Current state of the input device. */
  122. int8_t scroll_dir; /* scroll direction */
  123. int8_t last_scroll_dir; /* last scroll direction */
  124. uint16_t pre_view_id;
  125. uint16_t current_view_id;
  126. uint16_t last_view_id;
  127. uint16_t view_id;
  128. uint16_t related_view_id;
  129. /*Flags*/
  130. uint8_t long_pr_sent : 1;
  131. uint8_t reset_query : 1;
  132. uint8_t disabled : 1;
  133. uint8_t wait_until_release : 1;
  134. union {
  135. struct { /*Pointer and button data*/
  136. point_t act_point; /**< Current point of input device. */
  137. point_t last_point; /**< Last point of input device. */
  138. point_t vect; /**< Difference between `act_point` and `last_point`. */
  139. point_t scroll_start; /**< Last point of input device. */
  140. point_t scroll_sum; /*Count the dragged pixels to check scroll_limit*/
  141. point_t scroll_throw_vect;
  142. int16_t last_scroll_off;
  143. point_t gesture_sum; /*Count the gesture pixels to check gesture_limit*/
  144. /*Flags*/
  145. uint8_t scroll_in_prog : 1;
  146. uint8_t scroll_to_screen : 1;
  147. uint8_t scroll_disabled : 1; /* disable gesture scrolling */
  148. uint8_t scroll_wait_until_release : 1; /* do nothing until next release */
  149. uint8_t gesture_sent : 1; /* gesture event reported or not */
  150. int8_t gesture_dir; /* gesture direction */
  151. } pointer;
  152. struct { /*Keypad data*/
  153. input_dev_state_t last_state;
  154. uint32_t last_key;
  155. } keypad;
  156. } types;
  157. uint32_t pr_timestamp; /**< Pressed time stamp*/
  158. uint32_t longpr_rep_timestamp; /**< Long press repeat time stamp*/
  159. } input_dev_runtime_t;
  160. /** The main input device descriptor with driver, runtime data ('proc') and some additional
  161. * information*/
  162. typedef struct _input_dev_t {
  163. /**< Input used flag*/
  164. uint8_t used_flag:1;
  165. input_drv_t driver;
  166. input_dev_runtime_t proc;
  167. } input_dev_t;
  168. typedef struct input_dev_init_param {
  169. /**< Input init param*/
  170. uint16_t long_press_timer;
  171. uint16_t super_long_press_timer;
  172. uint16_t super_long_press_6s_timer;
  173. uint16_t quickly_click_duration;
  174. uint16_t key_event_cancel_duration;
  175. uint16_t hold_delay_time;
  176. uint16_t hold_interval_time;
  177. } input_dev_init_param;
  178. typedef void (*event_trigger)(uint32_t key_value, uint16_t type);
  179. void input_manager_dev_enable(input_dev_t *indev);
  180. input_dev_t *input_manager_get_input_dev(input_dev_type_t dev_type);
  181. /**
  182. * Read data from an input device.
  183. * @param indev pointer to an input device
  184. * @param data input device will write its data here
  185. * @return false: no more data; true: there more data to read (buffered)
  186. */
  187. bool input_dev_read(input_dev_t * indev, input_dev_data_t * data);
  188. /**
  189. * @brief input manager init funcion
  190. *
  191. * This routine calls init input manager ,called by main
  192. *
  193. * @param event_cb when keyevent report ,this callback called before
  194. * key event dispatch.
  195. *
  196. * @return true if invoked succsess.
  197. * @return false if invoked failed.
  198. */
  199. bool input_manager_init(event_trigger event_cb);
  200. /**
  201. * @brief Lock the input event
  202. *
  203. * This routine calls lock input event, input event may not send to system
  204. * if this function called.
  205. *
  206. *
  207. * @return true if invoked succsess.
  208. * @return false if invoked failed.
  209. */
  210. bool input_manager_lock(void);
  211. /**
  212. * @brief unLock the input event
  213. *
  214. * This routine calls unlock input event, input event may send to system
  215. * if this function called.
  216. *
  217. * @note input_manager_lock and input_manager_unlock Must match
  218. *
  219. * @return true if invoked succsess.
  220. * @return false if invoked failed.
  221. */
  222. bool input_manager_unlock(void);
  223. /**
  224. * @brief get the status of input event lock
  225. *
  226. * @return true if input event is locked
  227. * @return false if input event is not locked.
  228. */
  229. bool input_manager_islock(void);
  230. /**
  231. * @brief set filter key event
  232. *
  233. * @return true set success
  234. * @return false set failed.
  235. */
  236. bool input_manager_filter_key_itself(void);
  237. int input_keypad_onoff_inquiry_enable(bool inner_onoff, bool enable);
  238. int input_keypad_onoff_inquiry(bool inner_onoff, int keycode);
  239. void input_manager_set_init_param(input_dev_init_param *data);
  240. void input_manager_boost(bool boost);
  241. /**
  242. * @} end defgroup input_manager_apis
  243. */
  244. #endif