1
1
#include < lvgl.h>
2
- #include < Ticker.h>
3
2
#include < TFT_eSPI.h>
4
3
5
- #define LVGL_TICK_PERIOD 20
6
-
7
- Ticker tick; /* timer for interrupt handler */
8
4
TFT_eSPI tft = TFT_eSPI(); /* TFT instance */
9
5
static lv_disp_buf_t disp_buf;
10
6
static lv_color_t buf[LV_HOR_RES_MAX * 10 ];
@@ -14,95 +10,82 @@ static lv_color_t buf[LV_HOR_RES_MAX * 10];
14
10
void my_print (lv_log_level_t level, const char * file, uint32_t line, const char * dsc)
15
11
{
16
12
17
- Serial.printf (" %s@%d->%s\r\n " , file, line, dsc);
18
- delay ( 100 );
13
+ Serial.printf (" %s@%d->%s\r\n " , file, line, dsc);
14
+ Serial. flush ( );
19
15
}
20
16
#endif
21
17
22
18
/* Display flushing */
23
19
void my_disp_flush (lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
24
20
{
25
- uint16_t c;
26
-
27
- tft.startWrite (); /* Start new TFT transaction */
28
- tft.setAddrWindow (area->x1 , area->y1 , (area->x2 - area->x1 + 1 ), (area->y2 - area->y1 + 1 )); /* set the working window */
29
- for (int y = area->y1 ; y <= area->y2 ; y++) {
30
- for (int x = area->x1 ; x <= area->x2 ; x++) {
31
- c = color_p->full ;
32
- tft.writeColor (c, 1 );
33
- color_p++;
34
- }
35
- }
36
- tft.endWrite (); /* terminate TFT transaction */
37
- lv_disp_flush_ready (disp); /* tell lvgl that flushing is done */
38
- }
21
+ uint32_t w = (area->x2 - area->x1 + 1 );
22
+ uint32_t h = (area->y2 - area->y1 + 1 );
39
23
40
- /* Interrupt driven periodic handler */
41
- static void lv_tick_handler (void )
42
- {
24
+ tft.startWrite ();
25
+ tft.setAddrWindow (area->x1 , area->y1 , w, h);
26
+ tft.pushColors (&color_p->full , w * h, true );
27
+ tft.endWrite ();
43
28
44
- lv_tick_inc (LVGL_TICK_PERIOD );
29
+ lv_disp_flush_ready (disp );
45
30
}
46
31
47
32
/* Reading input device (simulated encoder here) */
48
33
bool read_encoder (lv_indev_drv_t * indev, lv_indev_data_t * data)
49
34
{
50
- static int32_t last_diff = 0 ;
51
- int32_t diff = 0 ; /* Dummy - no movement */
52
- int btn_state = LV_INDEV_STATE_REL; /* Dummy - no press */
35
+ static int32_t last_diff = 0 ;
36
+ int32_t diff = 0 ; /* Dummy - no movement */
37
+ int btn_state = LV_INDEV_STATE_REL; /* Dummy - no press */
53
38
54
- data->enc_diff = diff - last_diff;;
55
- data->state = btn_state;
39
+ data->enc_diff = diff - last_diff;;
40
+ data->state = btn_state;
56
41
57
- last_diff = diff;
42
+ last_diff = diff;
58
43
59
- return false ;
44
+ return false ;
60
45
}
61
46
62
- void setup () {
47
+ void setup ()
48
+ {
63
49
64
- Serial.begin (115200 ); /* prepare for possible serial debug */
50
+ Serial.begin (115200 ); /* prepare for possible serial debug */
65
51
66
- lv_init ();
52
+ lv_init ();
67
53
68
54
#if USE_LV_LOG != 0
69
- lv_log_register_print_cb (my_print); /* register print function for debugging */
55
+ lv_log_register_print_cb (my_print); /* register print function for debugging */
70
56
#endif
71
57
72
- tft.begin (); /* TFT init */
73
- tft.setRotation (1 ); /* Landscape orientation */
74
-
75
- lv_disp_buf_init (&disp_buf, buf, NULL , LV_HOR_RES_MAX * 10 );
76
-
77
- /* Initialize the display*/
78
- lv_disp_drv_t disp_drv;
79
- lv_disp_drv_init (&disp_drv);
80
- disp_drv.hor_res = 320 ;
81
- disp_drv.ver_res = 240 ;
82
- disp_drv.flush_cb = my_disp_flush;
83
- disp_drv.buffer = &disp_buf;
84
- lv_disp_drv_register (&disp_drv);
85
-
86
-
87
- /* Initialize the input device driver*/
88
- lv_indev_drv_t indev_drv;
89
- lv_indev_drv_init (&indev_drv);
90
- indev_drv.type = LV_INDEV_TYPE_ENCODER;
91
- indev_drv.read_cb = read_encoder;
92
- lv_indev_drv_register (&indev_drv);
93
-
94
- /* Initialize the graphics library's tick*/
95
- tick.attach_ms (LVGL_TICK_PERIOD, lv_tick_handler);
96
-
97
- /* Create simple label */
98
- lv_obj_t *label = lv_label_create (lv_scr_act (), NULL );
99
- lv_label_set_text (label, " Hello Arduino! (V6.1)" );
100
- lv_obj_align (label, NULL , LV_ALIGN_CENTER, 0 , 0 );
58
+ tft.begin (); /* TFT init */
59
+ tft.setRotation (1 ); /* Landscape orientation */
60
+
61
+ lv_disp_buf_init (&disp_buf, buf, NULL , LV_HOR_RES_MAX * 10 );
62
+
63
+ /* Initialize the display*/
64
+ lv_disp_drv_t disp_drv;
65
+ lv_disp_drv_init (&disp_drv);
66
+ disp_drv.hor_res = 320 ;
67
+ disp_drv.ver_res = 240 ;
68
+ disp_drv.flush_cb = my_disp_flush;
69
+ disp_drv.buffer = &disp_buf;
70
+ lv_disp_drv_register (&disp_drv);
71
+
72
+ /* Initialize the (dummy) input device driver*/
73
+ lv_indev_drv_t indev_drv;
74
+ lv_indev_drv_init (&indev_drv);
75
+ indev_drv.type = LV_INDEV_TYPE_ENCODER;
76
+ indev_drv.read_cb = read_encoder;
77
+ lv_indev_drv_register (&indev_drv);
78
+
79
+ /* Create simple label */
80
+ lv_obj_t *label = lv_label_create (lv_scr_act (), NULL );
81
+ lv_label_set_text (label, " Hello Arduino! (V6.1.1)" );
82
+ lv_obj_align (label, NULL , LV_ALIGN_CENTER, 0 , 0 );
101
83
}
102
84
103
85
104
- void loop () {
86
+ void loop ()
87
+ {
105
88
106
- lv_task_handler (); /* let the GUI do its work */
107
- delay (5 );
89
+ lv_task_handler (); /* let the GUI do its work */
90
+ delay (5 );
108
91
}
0 commit comments