Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/libs/lvgl/lv_hal/lv_hal_indev.h
1476 views
1
/**
2
* @file hal_indev.h
3
*
4
* @description Input Device HAL interface layer header file
5
*
6
*/
7
8
#ifndef HAL_INDEV_H
9
#define HAL_INDEV_H
10
11
#ifdef __cplusplus
12
extern "C" {
13
#endif
14
15
/*********************
16
* INCLUDES
17
*********************/
18
#include <stdint.h>
19
#include "lv_hal.h"
20
#include <utils/types.h>
21
#include "../lv_misc/lv_area.h"
22
#include "../lv_core/lv_obj.h"
23
24
/*********************
25
* DEFINES
26
*********************/
27
28
/**********************
29
* TYPEDEFS
30
**********************/
31
32
/*Possible input device types*/
33
enum {
34
LV_INDEV_TYPE_NONE, /*Show uninitialized state*/
35
LV_INDEV_TYPE_POINTER, /*Touch pad, mouse, external button*/
36
LV_INDEV_TYPE_KEYPAD, /*Keypad or keyboard*/
37
LV_INDEV_TYPE_BUTTON, /*External (hardware button) which is assinged to a specific point of the screen*/
38
LV_INDEV_TYPE_ENCODER, /*Encoder with only Left, Right turn and a Button*/
39
};
40
typedef uint8_t lv_hal_indev_type_t;
41
42
/*States for input devices*/
43
enum {
44
LV_INDEV_STATE_REL = 0,
45
LV_INDEV_STATE_PR
46
};
47
typedef uint8_t lv_indev_state_t;
48
49
/*Data type when an input device is read */
50
typedef struct {
51
union {
52
lv_point_t point; /*For LV_INDEV_TYPE_POINTER the currently pressed point*/
53
uint32_t key; /*For LV_INDEV_TYPE_KEYPAD the currently pressed key*/
54
uint32_t btn; /*For LV_INDEV_TYPE_BUTTON the currently pressed button*/
55
int16_t enc_diff; /*For LV_INDEV_TYPE_ENCODER number of steps since the previous read*/
56
};
57
void *user_data; /*'lv_indev_drv_t.priv' for this driver*/
58
lv_indev_state_t state; /*LV_INDEV_STATE_REL or LV_INDEV_STATE_PR*/
59
} lv_indev_data_t;
60
61
/*Initialized by the user and registered by 'lv_indev_add()'*/
62
typedef struct {
63
lv_hal_indev_type_t type; /*Input device type*/
64
bool (*read)(lv_indev_data_t *data); /*Function pointer to read data. Return 'true' if there is still data to be read (buffered)*/
65
void *user_data; /*Pointer to user defined data, passed in 'lv_indev_data_t' on read*/
66
} lv_indev_drv_t;
67
68
struct _lv_obj_t;
69
70
/*Run time data of input devices*/
71
typedef struct _lv_indev_proc_t {
72
lv_indev_state_t state;
73
union {
74
struct { /*Pointer and button data*/
75
lv_point_t act_point;
76
lv_point_t last_point;
77
lv_point_t vect;
78
lv_point_t drag_sum; /*Count the dragged pixels to check LV_INDEV_DRAG_LIMIT*/
79
struct _lv_obj_t * act_obj;
80
struct _lv_obj_t * last_obj;
81
82
/*Flags*/
83
uint8_t drag_range_out :1;
84
uint8_t drag_in_prog :1;
85
uint8_t wait_unil_release :1;
86
};
87
struct { /*Keypad data*/
88
lv_indev_state_t last_state;
89
uint32_t last_key;
90
};
91
};
92
93
uint32_t pr_timestamp; /*Pressed time stamp*/
94
uint32_t longpr_rep_timestamp; /*Long press repeat time stamp*/
95
96
/*Flags*/
97
uint8_t long_pr_sent :1;
98
uint8_t reset_query :1;
99
uint8_t disabled :1;
100
} lv_indev_proc_t;
101
102
struct _lv_indev_t;
103
104
typedef void (*lv_indev_feedback_t)(struct _lv_indev_t *, lv_signal_t);
105
106
struct _lv_obj_t;
107
struct _lv_group_t;
108
109
/*The main input device descriptor with driver, runtime data ('proc') and some additional information*/
110
typedef struct _lv_indev_t {
111
lv_indev_drv_t driver;
112
lv_indev_proc_t proc;
113
lv_indev_feedback_t feedback;
114
uint32_t last_activity_time;
115
union {
116
struct _lv_obj_t *cursor; /*Cursor for LV_INPUT_TYPE_POINTER*/
117
struct _lv_group_t *group; /*Keypad destination group*/
118
const lv_point_t * btn_points; /*Array points assigned to the button ()screen will be pressed here by the buttons*/
119
120
};
121
struct _lv_indev_t *next;
122
} lv_indev_t;
123
124
/**********************
125
* GLOBAL PROTOTYPES
126
**********************/
127
128
/**
129
* Initialize an input device driver with default values.
130
* It is used to surly have known values in the fields ant not memory junk.
131
* After it you can set the fields.
132
* @param driver pointer to driver variable to initialize
133
*/
134
void lv_indev_drv_init(lv_indev_drv_t *driver);
135
136
/**
137
* Register an initialized input device driver.
138
* @param driver pointer to an initialized 'lv_indev_drv_t' variable (can be local variable)
139
* @return pointer to the new input device or NULL on error
140
*/
141
lv_indev_t * lv_indev_drv_register(lv_indev_drv_t *driver);
142
143
/**
144
* Get the next input device.
145
* @param indev pointer to the current input device. NULL to initialize.
146
* @return the next input devise or NULL if no more. Gives the first input device when the parameter is NULL
147
*/
148
lv_indev_t * lv_indev_next(lv_indev_t * indev);
149
150
/**
151
* Read data from an input device.
152
* @param indev pointer to an input device
153
* @param data input device will write its data here
154
* @return false: no more data; true: there more data to read (buffered)
155
*/
156
bool lv_indev_read(lv_indev_t * indev, lv_indev_data_t *data);
157
158
/**********************
159
* MACROS
160
**********************/
161
162
#ifdef __cplusplus
163
} /* extern "C" */
164
#endif
165
166
#endif
167
168