Skip to content
This repository was archived by the owner on Dec 4, 2020. It is now read-only.

Commit a50593a

Browse files
committed
Remove ticker (use millis() instead), faster screen update, remove delay from debug print (use .flush())
1 parent 2421bad commit a50593a

File tree

2 files changed

+52
-69
lines changed

2 files changed

+52
-69
lines changed
Lines changed: 50 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#include <lvgl.h>
2-
#include <Ticker.h>
32
#include <TFT_eSPI.h>
43

5-
#define LVGL_TICK_PERIOD 20
6-
7-
Ticker tick; /* timer for interrupt handler */
84
TFT_eSPI tft = TFT_eSPI(); /* TFT instance */
95
static lv_disp_buf_t disp_buf;
106
static lv_color_t buf[LV_HOR_RES_MAX * 10];
@@ -14,95 +10,82 @@ static lv_color_t buf[LV_HOR_RES_MAX * 10];
1410
void my_print(lv_log_level_t level, const char * file, uint32_t line, const char * dsc)
1511
{
1612

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();
1915
}
2016
#endif
2117

2218
/* Display flushing */
2319
void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
2420
{
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);
3923

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();
4328

44-
lv_tick_inc(LVGL_TICK_PERIOD);
29+
lv_disp_flush_ready(disp);
4530
}
4631

4732
/* Reading input device (simulated encoder here) */
4833
bool read_encoder(lv_indev_drv_t * indev, lv_indev_data_t * data)
4934
{
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 */
5338

54-
data->enc_diff = diff - last_diff;;
55-
data->state = btn_state;
39+
data->enc_diff = diff - last_diff;;
40+
data->state = btn_state;
5641

57-
last_diff = diff;
42+
last_diff = diff;
5843

59-
return false;
44+
return false;
6045
}
6146

62-
void setup() {
47+
void setup()
48+
{
6349

64-
Serial.begin(115200); /* prepare for possible serial debug */
50+
Serial.begin(115200); /* prepare for possible serial debug */
6551

66-
lv_init();
52+
lv_init();
6753

6854
#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 */
7056
#endif
7157

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);
10183
}
10284

10385

104-
void loop() {
86+
void loop()
87+
{
10588

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);
10891
}

lv_conf.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ typedef void * lv_img_decoder_user_data_t;
210210

211211
/* 1: use a custom tick source.
212212
* It removes the need to manually update the tick with `lv_tick_inc`) */
213-
#define LV_TICK_CUSTOM 0
213+
#define LV_TICK_CUSTOM 1
214214
#if LV_TICK_CUSTOM == 1
215-
#define LV_TICK_CUSTOM_INCLUDE "something.h" /*Header for the sys time function*/
215+
#define LV_TICK_CUSTOM_INCLUDE "Arduino.h" /*Header for the sys time function*/
216216
#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current systime in ms*/
217217
#endif /*LV_TICK_CUSTOM*/
218218

0 commit comments

Comments
 (0)