/**1* @file hal_indev.h2*3* @description Input Device HAL interface layer header file4*5*/67#ifndef HAL_INDEV_H8#define HAL_INDEV_H910#ifdef __cplusplus11extern "C" {12#endif1314/*********************15* INCLUDES16*********************/17#include <stdint.h>18#include "lv_hal.h"19#include <utils/types.h>20#include "../lv_misc/lv_area.h"21#include "../lv_core/lv_obj.h"2223/*********************24* DEFINES25*********************/2627/**********************28* TYPEDEFS29**********************/3031/*Possible input device types*/32enum {33LV_INDEV_TYPE_NONE, /*Show uninitialized state*/34LV_INDEV_TYPE_POINTER, /*Touch pad, mouse, external button*/35LV_INDEV_TYPE_KEYPAD, /*Keypad or keyboard*/36LV_INDEV_TYPE_BUTTON, /*External (hardware button) which is assinged to a specific point of the screen*/37LV_INDEV_TYPE_ENCODER, /*Encoder with only Left, Right turn and a Button*/38};39typedef uint8_t lv_hal_indev_type_t;4041/*States for input devices*/42enum {43LV_INDEV_STATE_REL = 0,44LV_INDEV_STATE_PR45};46typedef uint8_t lv_indev_state_t;4748/*Data type when an input device is read */49typedef struct {50union {51lv_point_t point; /*For LV_INDEV_TYPE_POINTER the currently pressed point*/52uint32_t key; /*For LV_INDEV_TYPE_KEYPAD the currently pressed key*/53uint32_t btn; /*For LV_INDEV_TYPE_BUTTON the currently pressed button*/54int16_t enc_diff; /*For LV_INDEV_TYPE_ENCODER number of steps since the previous read*/55};56void *user_data; /*'lv_indev_drv_t.priv' for this driver*/57lv_indev_state_t state; /*LV_INDEV_STATE_REL or LV_INDEV_STATE_PR*/58} lv_indev_data_t;5960/*Initialized by the user and registered by 'lv_indev_add()'*/61typedef struct {62lv_hal_indev_type_t type; /*Input device type*/63bool (*read)(lv_indev_data_t *data); /*Function pointer to read data. Return 'true' if there is still data to be read (buffered)*/64void *user_data; /*Pointer to user defined data, passed in 'lv_indev_data_t' on read*/65} lv_indev_drv_t;6667struct _lv_obj_t;6869/*Run time data of input devices*/70typedef struct _lv_indev_proc_t {71lv_indev_state_t state;72union {73struct { /*Pointer and button data*/74lv_point_t act_point;75lv_point_t last_point;76lv_point_t vect;77lv_point_t drag_sum; /*Count the dragged pixels to check LV_INDEV_DRAG_LIMIT*/78struct _lv_obj_t * act_obj;79struct _lv_obj_t * last_obj;8081/*Flags*/82uint8_t drag_range_out :1;83uint8_t drag_in_prog :1;84uint8_t wait_unil_release :1;85};86struct { /*Keypad data*/87lv_indev_state_t last_state;88uint32_t last_key;89};90};9192uint32_t pr_timestamp; /*Pressed time stamp*/93uint32_t longpr_rep_timestamp; /*Long press repeat time stamp*/9495/*Flags*/96uint8_t long_pr_sent :1;97uint8_t reset_query :1;98uint8_t disabled :1;99} lv_indev_proc_t;100101struct _lv_indev_t;102103typedef void (*lv_indev_feedback_t)(struct _lv_indev_t *, lv_signal_t);104105struct _lv_obj_t;106struct _lv_group_t;107108/*The main input device descriptor with driver, runtime data ('proc') and some additional information*/109typedef struct _lv_indev_t {110lv_indev_drv_t driver;111lv_indev_proc_t proc;112lv_indev_feedback_t feedback;113uint32_t last_activity_time;114union {115struct _lv_obj_t *cursor; /*Cursor for LV_INPUT_TYPE_POINTER*/116struct _lv_group_t *group; /*Keypad destination group*/117const lv_point_t * btn_points; /*Array points assigned to the button ()screen will be pressed here by the buttons*/118119};120struct _lv_indev_t *next;121} lv_indev_t;122123/**********************124* GLOBAL PROTOTYPES125**********************/126127/**128* Initialize an input device driver with default values.129* It is used to surly have known values in the fields ant not memory junk.130* After it you can set the fields.131* @param driver pointer to driver variable to initialize132*/133void lv_indev_drv_init(lv_indev_drv_t *driver);134135/**136* Register an initialized input device driver.137* @param driver pointer to an initialized 'lv_indev_drv_t' variable (can be local variable)138* @return pointer to the new input device or NULL on error139*/140lv_indev_t * lv_indev_drv_register(lv_indev_drv_t *driver);141142/**143* Get the next input device.144* @param indev pointer to the current input device. NULL to initialize.145* @return the next input devise or NULL if no more. Gives the first input device when the parameter is NULL146*/147lv_indev_t * lv_indev_next(lv_indev_t * indev);148149/**150* Read data from an input device.151* @param indev pointer to an input device152* @param data input device will write its data here153* @return false: no more data; true: there more data to read (buffered)154*/155bool lv_indev_read(lv_indev_t * indev, lv_indev_data_t *data);156157/**********************158* MACROS159**********************/160161#ifdef __cplusplus162} /* extern "C" */163#endif164165#endif166167168