1
1
#include <libtock-sync/display/screen.h>
2
2
#include <libtock/sensors/touch.h>
3
+ #include <libtock/services/alarm.h>
3
4
#include <libtock/tock.h>
4
5
#include <lvgl/lvgl.h>
5
6
6
7
#include "lvgl_driver.h"
7
8
8
- static lv_disp_draw_buf_t disp_buf ;
9
- static lv_disp_drv_t disp_drv ;
10
- static lv_disp_t * display_device ;
9
+ #define PIXEL_SIZE 2 // 16 bit for RGB565
11
10
12
- static lv_indev_drv_t indev_drv ;
13
- static lv_indev_t * touch_input_device ;
11
+ static lv_display_t * display_device ;
12
+
13
+ static lv_indev_t * indev ;
14
14
15
15
static int touch_status = LIBTOCK_TOUCH_STATUS_UNSTARTED ;
16
16
static uint16_t touch_x = 0 , touch_y = 0 ;
17
17
18
- static int buffer_size = 0 ;
19
- static uint8_t * buffer ;
20
-
21
18
/* screen driver */
22
- static void screen_lvgl_driver (lv_disp_drv_t * disp , const lv_area_t * area ,
23
- __attribute__ ((unused )) lv_color_t * color_p ) {
19
+ static void screen_lvgl_driver (lv_display_t * disp , const lv_area_t * area ,
20
+ uint8_t * buffer ) {
21
+ void * ud = lv_display_get_user_data (disp );
22
+ uint32_t buffer_size = (uint32_t )ud ;
24
23
int32_t x , y ;
25
24
x = area -> x1 ;
26
25
y = area -> y1 ;
27
26
int w = area -> x2 - area -> x1 + 1 ;
28
27
int h = area -> y2 - area -> y1 + 1 ;
29
28
libtocksync_screen_set_frame (x , y , w , h );
30
- libtocksync_screen_write (buffer , buffer_size , (w * h ) * sizeof ( lv_color_t ) );
29
+ libtocksync_screen_write (buffer , buffer_size , (w * h ) * PIXEL_SIZE );
31
30
32
- lv_disp_flush_ready (disp ); /* Indicate you are ready with the flushing*/
31
+ lv_display_flush_ready (disp ); /* Indicate you are ready with the flushing*/
33
32
}
34
33
35
34
static void touch_event (int status , uint16_t x , uint16_t y ) {
@@ -38,7 +37,7 @@ static void touch_event(int status, uint16_t x, uint16_t y) {
38
37
touch_y = y ;
39
38
}
40
39
41
- static void my_input_read (__attribute__((unused )) lv_indev_drv_t * drv , lv_indev_data_t * data ) {
40
+ static void indev_cb (__attribute__ ((unused )) lv_indev_t * _indev , lv_indev_data_t * data ) {
42
41
if (touch_status == LIBTOCK_TOUCH_STATUS_PRESSED || touch_status == LIBTOCK_TOUCH_STATUS_MOVED ) {
43
42
data -> point .x = touch_x ;
44
43
data -> point .y = touch_y ;
@@ -48,43 +47,44 @@ static void my_input_read(__attribute__((unused)) lv_indev_drv_t* drv, lv_indev_
48
47
}
49
48
}
50
49
50
+ static uint32_t tick_cb (void ) {
51
+ uint32_t ticks ;
52
+ libtock_alarm_command_read (& ticks );
51
53
54
+ uint32_t ms = libtock_alarm_ticks_to_ms (ticks );
55
+ return ms ;
56
+ }
52
57
53
58
int lvgl_driver_init (int buffer_lines ) {
54
59
uint32_t width , height ;
55
60
int error = libtock_screen_get_resolution (& width , & height );
56
61
if (error != RETURNCODE_SUCCESS ) return error ;
57
62
58
- buffer_size = width * buffer_lines * sizeof (lv_color_t );
59
- error = libtock_screen_buffer_init (buffer_size , & buffer );
63
+ uint32_t buffer_size = width * buffer_lines * PIXEL_SIZE ;
64
+ uint8_t * buffer = NULL ;
65
+ error = libtock_screen_buffer_init (buffer_size , & buffer );
60
66
if (error != RETURNCODE_SUCCESS ) return error ;
61
67
62
- /* share the frame buffer with littlevgl */
63
- lv_color_t * buf = (lv_color_t * ) buffer ;
64
-
65
68
/* initialize littlevgl */
66
69
lv_init ();
67
- lv_disp_drv_init (& disp_drv );
68
- disp_drv .flush_cb = screen_lvgl_driver ;
69
- disp_drv .hor_res = width ;
70
- disp_drv .ver_res = height ;
71
- lv_disp_draw_buf_init (& disp_buf , buf , NULL , width * buffer_lines );
72
- disp_drv .draw_buf = & disp_buf ;
73
- display_device = lv_disp_drv_register (& disp_drv );
70
+
71
+ display_device = lv_display_create (width , height );
72
+ lv_display_set_color_format (display_device , LV_COLOR_FORMAT_RGB565 );
73
+ lv_display_set_flush_cb (display_device , screen_lvgl_driver );
74
+ lv_display_set_antialiasing (display_device , false);
75
+
76
+ lv_display_set_buffers (display_device , buffer , NULL , buffer_size , LV_DISPLAY_RENDER_MODE_PARTIAL );
77
+ lv_display_set_user_data (display_device , (void * )buffer_size );
78
+
79
+ lv_tick_set_cb (tick_cb );
74
80
75
81
int touches ;
76
82
if (libtock_touch_get_number_of_touches (& touches ) == RETURNCODE_SUCCESS && touches >= 1 ) {
77
83
libtock_touch_enable_single_touch (touch_event );
78
- lv_indev_drv_init (& indev_drv );
79
- indev_drv .type = LV_INDEV_TYPE_POINTER ;
80
- indev_drv .read_cb = my_input_read ;
81
- touch_input_device = lv_indev_drv_register (& indev_drv );
84
+ indev = lv_indev_create ();
85
+ lv_indev_set_type (indev , LV_INDEV_TYPE_POINTER );
86
+ lv_indev_set_read_cb (indev , indev_cb );
82
87
}
83
88
84
89
return RETURNCODE_SUCCESS ;
85
90
}
86
-
87
- void lvgl_driver_event (int millis ) {
88
- lv_tick_inc (millis );
89
- lv_task_handler ();
90
- }
0 commit comments