1 /** 2 * @file lv_hal_indev.h 3 * 4 * @description Input Device HAL interface layer header file 5 * 6 */ 7 8 #ifndef LV_HAL_INDEV_H 9 #define LV_HAL_INDEV_H 10 11 #ifdef __cplusplus 12 extern "C" { 13 #endif 14 15 /********************* 16 * INCLUDES 17 *********************/ 18 #ifdef LV_CONF_INCLUDE_SIMPLE 19 #include "lv_conf.h" 20 #else 21 #include "../../lv_conf.h" 22 #endif 23 24 #include <stdbool.h> 25 #include <stdint.h> 26 #include "../lv_misc/lv_area.h" 27 #include "../lv_misc/lv_task.h" 28 29 /********************* 30 * DEFINES 31 *********************/ 32 33 /********************** 34 * TYPEDEFS 35 **********************/ 36 37 struct _lv_obj_t; 38 struct _disp_t; 39 struct _lv_indev_t; 40 struct _lv_indev_drv_t; 41 42 /** Possible input device types*/ 43 enum { 44 LV_INDEV_TYPE_NONE, /**< Uninitialized state*/ 45 LV_INDEV_TYPE_POINTER, /**< Touch pad, mouse, external button*/ 46 LV_INDEV_TYPE_KEYPAD, /**< Keypad or keyboard*/ 47 LV_INDEV_TYPE_BUTTON, /**< External (hardware button) which is assigned to a specific point of the 48 screen*/ 49 LV_INDEV_TYPE_ENCODER, /**< Encoder with only Left, Right turn and a Button*/ 50 }; 51 typedef uint8_t lv_indev_type_t; 52 53 /** States for input devices*/ 54 enum { LV_INDEV_STATE_REL = 0, LV_INDEV_STATE_PR }; 55 typedef uint8_t lv_indev_state_t; 56 57 /** Data structure passed to an input driver to fill */ 58 typedef struct 59 { 60 lv_point_t point; /**< For LV_INDEV_TYPE_POINTER the currently pressed point*/ 61 uint32_t key; /**< For LV_INDEV_TYPE_KEYPAD the currently pressed key*/ 62 uint32_t btn_id; /**< For LV_INDEV_TYPE_BUTTON the currently pressed button*/ 63 int16_t enc_diff; /**< For LV_INDEV_TYPE_ENCODER number of steps since the previous read*/ 64 65 lv_indev_state_t state; /**< LV_INDEV_STATE_REL or LV_INDEV_STATE_PR*/ 66 } lv_indev_data_t; 67 68 /** Initialized by the user and registered by 'lv_indev_add()'*/ 69 typedef struct _lv_indev_drv_t 70 { 71 72 /**< Input device type*/ 73 lv_indev_type_t type; 74 75 /**< Function pointer to read input device data. 76 * Return 'true' if there is more data to be read (buffered). 77 * Most drivers can safely return 'false' */ 78 bool (*read_cb)(struct _lv_indev_drv_t * indev_drv, lv_indev_data_t * data); 79 80 /** Called when an action happened on the input device. 81 * The second parameter is the event from `lv_event_t`*/ 82 void (*feedback_cb)(struct _lv_indev_drv_t *, uint8_t); 83 84 #if LV_USE_USER_DATA 85 lv_indev_drv_user_data_t user_data; 86 #endif 87 88 /**< Pointer to the assigned display*/ 89 struct _disp_t * disp; 90 91 /**< Task to read the periodically read the input device*/ 92 lv_task_t * read_task; 93 94 /**< Number of pixels to slide before actually drag the object*/ 95 uint8_t drag_limit; 96 97 /**< Drag throw slow-down in [%]. Greater value means faster slow-down */ 98 uint8_t drag_throw; 99 100 /**< Long press time in milliseconds*/ 101 uint16_t long_press_time; 102 103 /**< Repeated trigger period in long press [ms] */ 104 uint16_t long_press_rep_time; 105 } lv_indev_drv_t; 106 107 /** Run time data of input devices 108 * Internally used by the library, you should not need to touch it. 109 */ 110 typedef struct _lv_indev_proc_t 111 { 112 lv_indev_state_t state; /**< Current state of the input device. */ 113 union 114 { 115 struct 116 { /*Pointer and button data*/ 117 lv_point_t act_point; /**< Current point of input device. */ 118 lv_point_t last_point; /**< Last point of input device. */ 119 lv_point_t vect; /**< Difference between `act_point` and `last_point`. */ 120 lv_point_t drag_sum; /*Count the dragged pixels to check LV_INDEV_DEF_DRAG_LIMIT*/ 121 lv_point_t drag_throw_vect; 122 struct _lv_obj_t * act_obj; /*The object being pressed*/ 123 struct _lv_obj_t * last_obj; /*The last obejct which was pressed (used by dragthrow and 124 other post-release event)*/ 125 struct _lv_obj_t * last_pressed; /*The lastly pressed object*/ 126 127 /*Flags*/ 128 uint8_t drag_limit_out : 1; 129 uint8_t drag_in_prog : 1; 130 } pointer; 131 struct 132 { /*Keypad data*/ 133 lv_indev_state_t last_state; 134 uint32_t last_key; 135 } keypad; 136 } types; 137 138 uint32_t pr_timestamp; /**< Pressed time stamp*/ 139 uint32_t longpr_rep_timestamp; /**< Long press repeat time stamp*/ 140 141 /*Flags*/ 142 uint8_t long_pr_sent : 1; 143 uint8_t reset_query : 1; 144 uint8_t disabled : 1; 145 uint8_t wait_until_release : 1; 146 } lv_indev_proc_t; 147 148 struct _lv_obj_t; 149 struct _lv_group_t; 150 151 /** The main input device descriptor with driver, runtime data ('proc') and some additional 152 * information*/ 153 typedef struct _lv_indev_t 154 { 155 lv_indev_drv_t driver; 156 lv_indev_proc_t proc; 157 struct _lv_obj_t * cursor; /**< Cursor for LV_INPUT_TYPE_POINTER*/ 158 struct _lv_group_t * group; /**< Keypad destination group*/ 159 const lv_point_t * btn_points; /**< Array points assigned to the button ()screen will be pressed 160 here by the buttons*/ 161 } lv_indev_t; 162 163 /********************** 164 * GLOBAL PROTOTYPES 165 **********************/ 166 167 /** 168 * Initialize an input device driver with default values. 169 * It is used to surly have known values in the fields ant not memory junk. 170 * After it you can set the fields. 171 * @param driver pointer to driver variable to initialize 172 */ 173 void lv_indev_drv_init(lv_indev_drv_t * driver); 174 175 /** 176 * Register an initialized input device driver. 177 * @param driver pointer to an initialized 'lv_indev_drv_t' variable (can be local variable) 178 * @return pointer to the new input device or NULL on error 179 */ 180 lv_indev_t * lv_indev_drv_register(lv_indev_drv_t * driver); 181 182 /** 183 * Update the driver in run time. 184 * @param indev pointer to a input device. (return value of `lv_indev_drv_register`) 185 * @param new_drv pointer to the new driver 186 */ 187 void lv_indev_drv_update(lv_indev_t * indev, lv_indev_drv_t * new_drv); 188 189 /** 190 * Get the next input device. 191 * @param indev pointer to the current input device. NULL to initialize. 192 * @return the next input devise or NULL if no more. Give the first input device when the parameter 193 * is NULL 194 */ 195 lv_indev_t * lv_indev_get_next(lv_indev_t * indev); 196 197 /** 198 * Read data from an input device. 199 * @param indev pointer to an input device 200 * @param data input device will write its data here 201 * @return false: no more data; true: there more data to read (buffered) 202 */ 203 bool lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data); 204 205 /********************** 206 * MACROS 207 **********************/ 208 209 #ifdef __cplusplus 210 } /* extern "C" */ 211 #endif 212 213 #endif 214