Skip to content

Commit d7d36f8

Browse files
authored
update to work with Arduino (lvgl#2200)
1 parent 2c089e5 commit d7d36f8

File tree

3 files changed

+169
-131
lines changed

3 files changed

+169
-131
lines changed

component.mk

+31-18
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
# ESP-IDF component file for make based commands
22

3-
COMPONENT_SRCDIRS := .
4-
COMPONENT_SRCDIRS += src
5-
COMPONENT_SRCDIRS += src/core
6-
COMPONENT_SRCDIRS += src/draw
7-
COMPONENT_SRCDIRS += src/font
8-
COMPONENT_SRCDIRS += src/gpu
9-
COMPONENT_SRCDIRS += src/hal
10-
COMPONENT_SRCDIRS += src/misc
11-
COMPONENT_SRCDIRS += src/widgets
3+
COMPONENT_SRCDIRS := . \
4+
src \
5+
src/core \
6+
src/draw \
7+
src/extra \
8+
src/font \
9+
src/gpu \
10+
src/hal \
11+
src/misc \
12+
src/widgets \
13+
src/extra/layouts \
14+
src/extra/layouts/flex \
15+
src/extra/layouts/grid \
16+
src/extra/themes \
17+
src/extra/themes/basic \
18+
src/extra/themes/default \
19+
src/extra/widgets/calendar \
20+
src/extra/widgets/colorwheel \
21+
src/extra/widgets \
22+
src/extra/widgets/imgbtn \
23+
src/extra/widgets/keyboard \
24+
src/extra/widgets/led \
25+
src/extra/widgets/list \
26+
src/extra/widgets/msgbox \
27+
src/extra/widgets/spinbox \
28+
src/extra/widgets/spinner \
29+
src/extra/widgets/tabview \
30+
src/extra/widgets/tileview \
31+
src/extra/widgets/win
1232

13-
COMPONENT_ADD_INCLUDEDIRS := .
14-
COMPONENT_ADD_INCLUDEDIRS += src
15-
COMPONENT_ADD_INCLUDEDIRS += src/core
16-
COMPONENT_ADD_INCLUDEDIRS += src/draw
17-
COMPONENT_ADD_INCLUDEDIRS += src/font
18-
COMPONENT_ADD_INCLUDEDIRS += src/gpu
19-
COMPONENT_ADD_INCLUDEDIRS += src/hal
20-
COMPONENT_ADD_INCLUDEDIRS += src/misc
21-
COMPONENT_ADD_INCLUDEDIRS += src/widgets
33+
34+
COMPONENT_ADD_INCLUDEDIRS := $(COMPONENT_SRCDIRS) .

examples/arduino/LVGL_Arduino.ino

-113
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#include <lvgl.h>
2+
#include <TFT_eSPI.h>
3+
/*If you want to use the LVGL examples,
4+
make sure to install the lv_examples Arduino library
5+
and uncomment the following line.
6+
#include <lv_examples.h>
7+
*/
8+
9+
#include <lv_demo.h>
10+
11+
TFT_eSPI tft = TFT_eSPI(); /* TFT instance */
12+
13+
/*Change to your screen resolution*/
14+
static const uint32_t screenWidth = 480;
15+
static const uint32_t screenHeight = 320;
16+
17+
static lv_disp_draw_buf_t draw_buf;
18+
static lv_color_t buf[ screenWidth * 10 ];
19+
20+
#if LV_USE_LOG != 0
21+
/* Serial debugging */
22+
void my_print( lv_log_level_t level, const char * file, uint32_t line, const char * fn_name, const char * dsc )
23+
{
24+
Serial.printf( "%s(%s)@%d->%s\r\n", file, fn_name, line, dsc );
25+
Serial.flush();
26+
}
27+
#endif
28+
29+
/* Display flushing */
30+
void my_disp_flush( lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p )
31+
{
32+
uint32_t w = ( area->x2 - area->x1 + 1 );
33+
uint32_t h = ( area->y2 - area->y1 + 1 );
34+
35+
tft.startWrite();
36+
tft.setAddrWindow( area->x1, area->y1, w, h );
37+
tft.pushColors( ( uint16_t * )&color_p->full, w * h, true );
38+
tft.endWrite();
39+
40+
lv_disp_flush_ready( disp );
41+
}
42+
43+
/*Read the touchpad*/
44+
bool my_touchpad_read( lv_indev_drv_t * indev_driver, lv_indev_data_t * data )
45+
{
46+
uint16_t touchX, touchY;
47+
48+
bool touched = tft.getTouch( &touchX, &touchY, 600 );
49+
50+
if( !touched )
51+
{
52+
data->state = LV_INDEV_STATE_REL;
53+
}
54+
else
55+
{
56+
data->state = LV_INDEV_STATE_PR;
57+
58+
/*Set the coordinates*/
59+
data->point.x = touchX;
60+
data->point.y = touchY;
61+
62+
Serial.print( "Data x " );
63+
Serial.println( touchX );
64+
65+
Serial.print( "Data y " );
66+
Serial.println( touchY );
67+
}
68+
69+
return false; /*Return `false` because we are not buffering and no more data to read*/
70+
}
71+
72+
void setup()
73+
{
74+
Serial.begin( 115200 ); /* prepare for possible serial debug */
75+
Serial.println( "Hello Arduino! (V8.0.X)" );
76+
Serial.println( "I am LVGL_Arduino" );
77+
78+
lv_init();
79+
80+
#if LV_USE_LOG != 0
81+
lv_log_register_print_cb( my_print ); /* register print function for debugging */
82+
#endif
83+
84+
tft.begin(); /* TFT init */
85+
tft.setRotation( 3 ); /* Landscape orientation, flipped */
86+
87+
/*Set the touchscreen calibration data,
88+
the actual data for your display can be aquired using
89+
the Generic -> Touch_calibrate example from the TFT_eSPI library*/
90+
uint16_t calData[5] = { 275, 3620, 264, 3532, 1 };
91+
tft.setTouch( calData );
92+
93+
lv_disp_draw_buf_init( &draw_buf, buf, NULL, screenWidth * 10 );
94+
95+
/*Initialize the display*/
96+
static lv_disp_drv_t disp_drv;
97+
lv_disp_drv_init( &disp_drv );
98+
/*Change the following line to your display resolution*/
99+
disp_drv.hor_res = screenWidth;
100+
disp_drv.ver_res = screenHeight;
101+
disp_drv.flush_cb = my_disp_flush;
102+
disp_drv.draw_buf = &draw_buf;
103+
lv_disp_drv_register( &disp_drv );
104+
105+
/*Initialize the (dummy) input device driver*/
106+
static lv_indev_drv_t indev_drv;
107+
lv_indev_drv_init( &indev_drv );
108+
indev_drv.type = LV_INDEV_TYPE_POINTER;
109+
indev_drv.read_cb = my_touchpad_read;
110+
lv_indev_drv_register( &indev_drv );
111+
112+
#if 0
113+
/* Create simple label */
114+
lv_obj_t *label = lv_label_create( lv_scr_act() );
115+
lv_label_set_text( label, "Hello Arduino! (V8.0.X)" );
116+
lv_obj_align( label, LV_ALIGN_CENTER, 0, 0 );
117+
#else
118+
/* Try an example from the lv_examples Arduino library
119+
make sure to include it as written above.
120+
lv_example_btn_1();
121+
*/
122+
123+
// uncomment one of these demos
124+
lv_demo_widgets(); // OK
125+
// lv_demo_benchmark(); // OK
126+
// lv_demo_keypad_encoder(); // works, but I haven't an encoder
127+
// lv_demo_music(); // NOK
128+
// lv_demo_printer();
129+
// lv_demo_stress(); // seems to be OK
130+
#endif
131+
Serial.println( "Setup done" );
132+
}
133+
134+
void loop()
135+
{
136+
lv_timer_handler(); /* let the GUI do its work */
137+
delay( 5 );
138+
}

0 commit comments

Comments
 (0)