11
11
#ifdef CONFIG_LV_Z_USE_FILESYSTEM
12
12
#include "lvgl_fs.h"
13
13
#endif
14
- #ifdef CONFIG_LV_Z_POINTER_KSCAN
15
- #include <zephyr/drivers/kscan.h>
16
- #endif
17
14
#include LV_MEM_CUSTOM_INCLUDE
18
15
19
16
#define LOG_LEVEL CONFIG_LV_LOG_LEVEL
@@ -24,12 +21,8 @@ static lv_disp_drv_t disp_drv;
24
21
struct lvgl_disp_data disp_data = {
25
22
.blanking_on = false,
26
23
};
27
- #ifdef CONFIG_LV_Z_POINTER_KSCAN
28
- static lv_indev_drv_t indev_drv ;
29
- #endif /* CONFIG_LV_Z_POINTER_KSCAN */
30
24
31
25
#define DISPLAY_NODE DT_CHOSEN(zephyr_display)
32
- #define KSCAN_NODE DT_CHOSEN(zephyr_keyboard_scan)
33
26
34
27
#ifdef CONFIG_LV_Z_BUFFER_ALLOC_STATIC
35
28
@@ -195,139 +188,6 @@ static int lvgl_allocate_rendering_buffers(lv_disp_drv_t *disp_driver)
195
188
}
196
189
#endif /* CONFIG_LV_Z_BUFFER_ALLOC_STATIC */
197
190
198
- #ifdef CONFIG_LV_Z_POINTER_KSCAN
199
- K_MSGQ_DEFINE (kscan_msgq , sizeof (lv_indev_data_t ), CONFIG_LV_Z_POINTER_KSCAN_MSGQ_COUNT , 4 );
200
-
201
- static void lvgl_pointer_kscan_callback (const struct device * dev , uint32_t row , uint32_t col ,
202
- bool pressed )
203
- {
204
- lv_indev_data_t data = {
205
- .point .x = col ,
206
- .point .y = row ,
207
- .state = pressed ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL ,
208
- };
209
-
210
- if (k_msgq_put (& kscan_msgq , & data , K_NO_WAIT ) != 0 ) {
211
- LOG_DBG ("Could not put input data into queue" );
212
- }
213
- }
214
-
215
- static void lvgl_pointer_kscan_read (lv_indev_drv_t * drv , lv_indev_data_t * data )
216
- {
217
- lv_disp_t * disp ;
218
- struct lvgl_disp_data * disp_data ;
219
- struct display_capabilities * cap ;
220
- lv_indev_data_t curr ;
221
-
222
- static lv_indev_data_t prev = {
223
- .point .x = 0 ,
224
- .point .y = 0 ,
225
- .state = LV_INDEV_STATE_REL ,
226
- };
227
-
228
- if (k_msgq_get (& kscan_msgq , & curr , K_NO_WAIT ) != 0 ) {
229
- goto set_and_release ;
230
- }
231
-
232
- prev = curr ;
233
-
234
- disp = lv_disp_get_default ();
235
- disp_data = disp -> driver -> user_data ;
236
- cap = & disp_data -> cap ;
237
-
238
- /* adjust kscan coordinates */
239
- if (IS_ENABLED (CONFIG_LV_Z_POINTER_KSCAN_SWAP_XY )) {
240
- lv_coord_t x ;
241
-
242
- x = prev .point .x ;
243
- prev .point .x = prev .point .y ;
244
- prev .point .y = x ;
245
- }
246
-
247
- if (IS_ENABLED (CONFIG_LV_Z_POINTER_KSCAN_INVERT_X )) {
248
- if (cap -> current_orientation == DISPLAY_ORIENTATION_NORMAL ||
249
- cap -> current_orientation == DISPLAY_ORIENTATION_ROTATED_180 ) {
250
- prev .point .x = cap -> x_resolution - prev .point .x ;
251
- } else {
252
- prev .point .x = cap -> y_resolution - prev .point .x ;
253
- }
254
- }
255
-
256
- if (IS_ENABLED (CONFIG_LV_Z_POINTER_KSCAN_INVERT_Y )) {
257
- if (cap -> current_orientation == DISPLAY_ORIENTATION_NORMAL ||
258
- cap -> current_orientation == DISPLAY_ORIENTATION_ROTATED_180 ) {
259
- prev .point .y = cap -> y_resolution - prev .point .y ;
260
- } else {
261
- prev .point .y = cap -> x_resolution - prev .point .y ;
262
- }
263
- }
264
-
265
- /* rotate touch point to match display rotation */
266
- if (cap -> current_orientation == DISPLAY_ORIENTATION_ROTATED_90 ) {
267
- lv_coord_t x ;
268
-
269
- x = prev .point .x ;
270
- prev .point .x = prev .point .y ;
271
- prev .point .y = cap -> y_resolution - x ;
272
- } else if (cap -> current_orientation == DISPLAY_ORIENTATION_ROTATED_180 ) {
273
- prev .point .x = cap -> x_resolution - prev .point .x ;
274
- prev .point .y = cap -> y_resolution - prev .point .y ;
275
- } else if (cap -> current_orientation == DISPLAY_ORIENTATION_ROTATED_270 ) {
276
- lv_coord_t x ;
277
-
278
- x = prev .point .x ;
279
- prev .point .x = cap -> x_resolution - prev .point .y ;
280
- prev .point .y = x ;
281
- }
282
-
283
- /* filter readings within display */
284
- if (prev .point .x <= 0 ) {
285
- prev .point .x = 0 ;
286
- } else if (prev .point .x >= cap -> x_resolution ) {
287
- prev .point .x = cap -> x_resolution - 1 ;
288
- }
289
-
290
- if (prev .point .y <= 0 ) {
291
- prev .point .y = 0 ;
292
- } else if (prev .point .y >= cap -> y_resolution ) {
293
- prev .point .y = cap -> y_resolution - 1 ;
294
- }
295
-
296
- set_and_release :
297
- * data = prev ;
298
-
299
- data -> continue_reading = k_msgq_num_used_get (& kscan_msgq ) > 0 ;
300
- }
301
-
302
- static int lvgl_pointer_kscan_init (void )
303
- {
304
- const struct device * kscan_dev = DEVICE_DT_GET (KSCAN_NODE );
305
-
306
- if (!device_is_ready (kscan_dev )) {
307
- LOG_ERR ("Keyboard scan device not ready." );
308
- return - ENODEV ;
309
- }
310
-
311
- if (kscan_config (kscan_dev , lvgl_pointer_kscan_callback ) < 0 ) {
312
- LOG_ERR ("Could not configure keyboard scan device." );
313
- return - ENODEV ;
314
- }
315
-
316
- lv_indev_drv_init (& indev_drv );
317
- indev_drv .type = LV_INDEV_TYPE_POINTER ;
318
- indev_drv .read_cb = lvgl_pointer_kscan_read ;
319
-
320
- if (lv_indev_drv_register (& indev_drv ) == NULL ) {
321
- LOG_ERR ("Failed to register input device." );
322
- return - EPERM ;
323
- }
324
-
325
- kscan_enable_callback (kscan_dev );
326
-
327
- return 0 ;
328
- }
329
- #endif /* CONFIG_LV_Z_POINTER_KSCAN */
330
-
331
191
static int lvgl_init (void )
332
192
{
333
193
@@ -375,11 +235,12 @@ static int lvgl_init(void)
375
235
return - EPERM ;
376
236
}
377
237
378
- #ifdef CONFIG_LV_Z_POINTER_KSCAN
379
- lvgl_pointer_kscan_init ();
380
- #endif /* CONFIG_LV_Z_POINTER_KSCAN */
381
-
382
238
return 0 ;
383
239
}
384
240
241
+ BUILD_ASSERT (CONFIG_APPLICATION_INIT_PRIORITY < CONFIG_LV_Z_INPUT_INIT_PRIORITY );
242
+ #ifdef CONFIG_INPUT
243
+ BUILD_ASSERT (CONFIG_INPUT_INIT_PRIORITY < CONFIG_LV_Z_INPUT_INIT_PRIORITY );
244
+ #endif /* CONFIG_INPUT */
245
+
385
246
SYS_INIT (lvgl_init , APPLICATION , CONFIG_APPLICATION_INIT_PRIORITY );
0 commit comments