Skip to content

Commit 4006495

Browse files
authored
Merge branch 'master' into master
2 parents 35a005a + a68ce89 commit 4006495

28 files changed

+1256
-652
lines changed

CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ if(CONFIG_LV_TOUCH_CONTROLLER)
7070
list(APPEND SOURCES "lvgl_touch/FT81x.c")
7171
elseif(CONFIG_LV_TOUCH_CONTROLLER_RA8875)
7272
list(APPEND SOURCES "lvgl_touch/ra8875_touch.c")
73+
elseif(CONFIG_LV_TOUCH_CONTROLLER_GT911)
74+
list(APPEND SOURCES "lvgl_touch/gt911.c")
7375
endif()
7476

7577
if(CONFIG_LV_TOUCH_DRIVER_PROTOCOL_SPI)
7678
list(APPEND SOURCES "lvgl_touch/tp_spi.c")
77-
elseif(CONFIG_LV_TOUCH_DRIVER_PROTOCOL_I2C)
78-
list(APPEND SOURCES "lvgl_touch/tp_i2c.c")
7979
endif()
8080
endif()
8181

@@ -84,10 +84,14 @@ if(CONFIG_LV_ENABLE_BACKLIGHT_CONTROL)
8484
list(APPEND SOURCES "lvgl_tft/esp_lcd_backlight.c")
8585
endif()
8686

87+
if(CONFIG_LV_I2C)
88+
list(APPEND SOURCES "lvgl_i2c/i2c_manager.c")
89+
endif()
90+
8791
idf_component_register(SRCS ${SOURCES}
8892
INCLUDE_DIRS ${LVGL_INCLUDE_DIRS}
8993
REQUIRES lvgl)
90-
94+
9195
target_compile_definitions(${COMPONENT_LIB} PUBLIC "-DLV_LVGL_H_INCLUDE_SIMPLE")
9296

9397
else()

Kconfig

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
1-
rsource "lvgl_tft/Kconfig"
2-
rsource "lvgl_touch/Kconfig"
1+
menu "LVGL ESP Drivers"
2+
3+
rsource "lvgl_tft/Kconfig"
4+
5+
rsource "lvgl_touch/Kconfig"
6+
7+
endmenu
8+
9+
menu "I2C Port Settings"
10+
depends on LV_I2C && !HAVE_I2C_MANAGER
11+
12+
rsource "lvgl_i2c/Kconfig"
13+
14+
endmenu

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ For a ready to use ESP32 project take look at the [lv_port_esp32](https://github
66
- [Supported display controllers](#supported-display-controllers)
77
- [Supported indev controllers](#supported-indev-controllers)
88
- [Support for predefined development kits](#support-for-predefined-development-kits)
9+
- [Thread-safe I2C with I2C Manager](#thread-safe-i2c-with-i2c-manager)
910

1011
**NOTE:** You need to set the display horizontal and vertical size, color depth and
1112
swap of RGB565 color on the LVGL configuration menuconfig (it's not handled automatically).
@@ -35,8 +36,8 @@ swap of RGB565 color on the LVGL configuration menuconfig (it's not handled auto
3536
## Supported indev controllers
3637

3738
- XPT2046
38-
- FT3236
39-
- other FT6X36 or the FT6206 controllers should work as well (not tested)
39+
- FT3236, FT6X36
40+
- FT6206 controllers should work as well (not tested)
4041
- STMPE610
4142
- FT81x (Single, Dual, and Quad SPI)
4243

@@ -52,7 +53,7 @@ and sets the gpio numbers for the interface.
5253
|---------------------------|-----------------------|-----------|-----------|-----------|
5354
| ESP Wrover Kit v4.1 | ILI9341 | SPI | 240 | 320 |
5455
| M5Stack | ILI9341 | SPI | 240 | 320 |
55-
| M5Core2 | ILI9341 | SPI | 240 | 320 |
56+
| M5Stack Core2 | ILI9341 | SPI | 240 | 320 |
5657
| M5Stick | SH1107 | SPI | - | - |
5758
| M5StickC | ST7735S | SPI | 80 | 160 |
5859
| Adafruit 3.5 Featherwing | HX8357 | SPI | 480 | 320 |
@@ -65,3 +66,16 @@ and sets the gpio numbers for the interface.
6566

6667
**NOTE:** See [Supported display controllers](#supported-display-controllers) for more information on display configuration.
6768
**NOTE:** See [Supported indev controllers](#supported-indev-controllers) for more information about indev configuration.
69+
70+
71+
## Thread-safe I2C with I2C Manager
72+
73+
LVGL can use I2C to read from a touch sensor or write to a display, possibly
74+
many times a second. Meanwhile, other tasks may also want to read from i2c
75+
devices on the same bus. I2C using the ESP-IDF is not thread-safe.
76+
77+
I2C Manager (`i2c_manager`) is a component that will let code in multiple threads
78+
talk to devices on the I2C ports without getting in each other's way. These drivers
79+
use a built-in copy of I2C Manager to talk to the I2C port, but you can also use
80+
the I2C Manager component itself and have others play nice with LVGL and vice-versa.
81+
[Click here](i2c_manager/README.md) for details.

component.mk

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# LVGL ESP32 drivers
22

33
# Define sources and include dirs
4-
COMPONENT_SRCDIRS := . lvgl_tft lvgl_touch
4+
COMPONENT_SRCDIRS := . lvgl_tft lvgl_touch lvgl_i2c
55
COMPONENT_ADD_INCLUDEDIRS := .
66

77
# LVGL is supposed to be used as a ESP-IDF component
@@ -44,4 +44,6 @@ $(call compile_only_if,$(and $(CONFIG_LV_TOUCH_CONTROLLER),$(CONFIG_LV_TOUCH_CON
4444
$(call compile_only_if,$(and $(CONFIG_LV_TOUCH_CONTROLLER),$(CONFIG_LV_TOUCH_CONTROLLER_RA8875)), lvgl_touch/ra8875_touch.o)
4545

4646
$(call compile_only_if,$(and $(CONFIG_LV_TOUCH_CONTROLLER),$(CONFIG_LV_TOUCH_DRIVER_PROTOCOL_SPI)), lvgl_touch/tp_spi.o)
47-
$(call compile_only_if,$(and $(CONFIG_LV_TOUCH_CONTROLLER),$(CONFIG_LV_TOUCH_DRIVER_PROTOCOL_I2C)), lvgl_touch/tp_i2c.o)
47+
48+
# I2C Manager
49+
$(call compile_only_if,$(CONFIG_LV_I2C), lvgl_i2c/i2c_manager.o)

lvgl_helpers.c

Lines changed: 42 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
#include "lvgl_touch/tp_spi.h"
1515

1616
#include "lvgl_spi_conf.h"
17-
#include "lvgl_i2c_conf.h"
1817

19-
#include "driver/i2c.h"
18+
#include "lvgl_i2c/i2c_manager.h"
2019

2120
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
22-
#include "src/lv_core/lv_refr.h"
21+
#include "lvgl.h"
2322
#else
24-
#include "lvgl/src/lv_core/lv_refr.h"
23+
#include "lvgl/lvgl.h"
2524
#endif
2625

2726
/*********************
@@ -53,7 +52,12 @@
5352
/* Interface and driver initialization */
5453
void lvgl_driver_init(void)
5554
{
55+
/* Since LVGL v8 LV_HOR_RES_MAX and LV_VER_RES_MAX are not defined, so
56+
* print it only if they are defined. */
57+
#if (LVGL_VERSION_MAJOR < 8)
5658
ESP_LOGI(TAG, "Display hor size: %d, ver size: %d", LV_HOR_RES_MAX, LV_VER_RES_MAX);
59+
#endif
60+
5761
ESP_LOGI(TAG, "Display buffer size: %d", DISP_BUF_SIZE);
5862

5963
#if defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X)
@@ -63,7 +67,7 @@ void lvgl_driver_init(void)
6367
DISP_SPI_MISO, DISP_SPI_MOSI, DISP_SPI_CLK,
6468
SPI_BUS_MAX_TRANSFER_SZ, 1,
6569
DISP_SPI_IO2, DISP_SPI_IO3);
66-
70+
6771
disp_spi_add_device(TFT_SPI_HOST);
6872
disp_driver_init();
6973

@@ -81,48 +85,29 @@ void lvgl_driver_init(void)
8185
TP_SPI_MISO, DISP_SPI_MOSI, DISP_SPI_CLK,
8286
SPI_BUS_MAX_TRANSFER_SZ, 1,
8387
-1, -1);
84-
88+
8589
disp_spi_add_device(TFT_SPI_HOST);
8690
tp_spi_add_device(TOUCH_SPI_HOST);
87-
88-
disp_driver_init();
89-
touch_driver_init();
90-
91-
return;
92-
#endif
9391

94-
#if defined (SHARED_I2C_BUS)
95-
ESP_LOGI(TAG, "Initializing shared I2C master");
96-
97-
lvgl_i2c_driver_init(DISP_I2C_PORT,
98-
DISP_I2C_SDA, DISP_I2C_SCL,
99-
DISP_I2C_SPEED_HZ);
100-
10192
disp_driver_init();
10293
touch_driver_init();
103-
94+
10495
return;
10596
#endif
10697

10798
/* Display controller initialization */
10899
#if defined CONFIG_LV_TFT_DISPLAY_PROTOCOL_SPI
109100
ESP_LOGI(TAG, "Initializing SPI master for display");
110-
101+
111102
lvgl_spi_driver_init(TFT_SPI_HOST,
112103
DISP_SPI_MISO, DISP_SPI_MOSI, DISP_SPI_CLK,
113104
SPI_BUS_MAX_TRANSFER_SZ, 1,
114105
DISP_SPI_IO2, DISP_SPI_IO3);
115-
106+
116107
disp_spi_add_device(TFT_SPI_HOST);
117-
108+
118109
disp_driver_init();
119-
#elif defined (CONFIG_LV_TFT_DISPLAY_PROTOCOL_I2C)
120-
ESP_LOGI(TAG, "Initializing I2C master for display");
121-
/* Init the i2c master on the display driver code */
122-
lvgl_i2c_driver_init(DISP_I2C_PORT,
123-
DISP_I2C_SDA, DISP_I2C_SCL,
124-
DISP_I2C_SPEED_HZ);
125-
110+
#elif defined (CONFIG_LV_I2C_DISPLAY)
126111
disp_driver_init();
127112
#else
128113
#error "No protocol defined for display controller"
@@ -132,22 +117,16 @@ void lvgl_driver_init(void)
132117
#if CONFIG_LV_TOUCH_CONTROLLER != TOUCH_CONTROLLER_NONE
133118
#if defined (CONFIG_LV_TOUCH_DRIVER_PROTOCOL_SPI)
134119
ESP_LOGI(TAG, "Initializing SPI master for touch");
135-
120+
136121
lvgl_spi_driver_init(TOUCH_SPI_HOST,
137122
TP_SPI_MISO, TP_SPI_MOSI, TP_SPI_CLK,
138123
0 /* Defaults to 4094 */, 2,
139124
-1, -1);
140-
125+
141126
tp_spi_add_device(TOUCH_SPI_HOST);
142-
127+
143128
touch_driver_init();
144-
#elif defined (CONFIG_LV_TOUCH_DRIVER_PROTOCOL_I2C)
145-
ESP_LOGI(TAG, "Initializing I2C master for touch");
146-
147-
lvgl_i2c_driver_init(TOUCH_I2C_PORT,
148-
TOUCH_I2C_SDA, TOUCH_I2C_SCL,
149-
TOUCH_I2C_SPEED_HZ);
150-
129+
#elif defined (CONFIG_LV_I2C_TOUCH)
151130
touch_driver_init();
152131
#elif defined (CONFIG_LV_TOUCH_DRIVER_ADC)
153132
touch_driver_init();
@@ -160,60 +139,46 @@ void lvgl_driver_init(void)
160139
#endif
161140
}
162141

163-
/* Config the i2c master
142+
143+
/* Initialize spi bus master
144+
*
145+
* NOTE: dma_chan type and value changed to int instead of spi_dma_chan_t
146+
* for backwards compatibility with ESP-IDF versions prior v4.3.
164147
*
165-
* This should init the i2c master to be used on display and touch controllers.
166-
* So we should be able to know if the display and touch controllers shares the
167-
* same i2c master.
148+
* We could use the ESP_IDF_VERSION_VAL macro available in the "esp_idf_version.h"
149+
* header available since ESP-IDF v4.
168150
*/
169-
bool lvgl_i2c_driver_init(int port, int sda_pin, int scl_pin, int speed_hz)
170-
{
171-
esp_err_t err;
172-
173-
ESP_LOGI(TAG, "Initializing I2C master port %d...", port);
174-
ESP_LOGI(TAG, "SDA pin: %d, SCL pin: %d, Speed: %d (Hz)",
175-
sda_pin, scl_pin, speed_hz);
176-
177-
i2c_config_t conf = {
178-
.mode = I2C_MODE_MASTER,
179-
.sda_io_num = sda_pin,
180-
.sda_pullup_en = GPIO_PULLUP_ENABLE,
181-
.scl_io_num = scl_pin,
182-
.scl_pullup_en = GPIO_PULLUP_ENABLE,
183-
.master.clk_speed = speed_hz,
184-
};
185-
186-
ESP_LOGI(TAG, "Setting I2C master configuration...");
187-
err = i2c_param_config(port, &conf);
188-
assert(ESP_OK == err);
189-
190-
ESP_LOGI(TAG, "Installing I2C master driver...");
191-
err = i2c_driver_install(port,
192-
I2C_MODE_MASTER,
193-
0, 0 /*I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE */,
194-
0 /* intr_alloc_flags */);
195-
assert(ESP_OK == err);
196-
197-
return ESP_OK != err;
198-
}
199-
200-
/* Initialize spi bus master */
201151
bool lvgl_spi_driver_init(int host,
202152
int miso_pin, int mosi_pin, int sclk_pin,
203153
int max_transfer_sz,
204154
int dma_channel,
205155
int quadwp_pin, int quadhd_pin)
206156
{
157+
int dma_chan = 0 /* SPI_DMA_DISABLED */;
158+
207159
#if defined (CONFIG_IDF_TARGET_ESP32)
208160
assert((SPI_HOST <= host) && (VSPI_HOST >= host));
209161
const char *spi_names[] = {
210162
"SPI_HOST", "HSPI_HOST", "VSPI_HOST"
211163
};
164+
165+
dma_chan = dma_channel;
212166
#elif defined (CONFIG_IDF_TARGET_ESP32S2)
213167
assert((SPI_HOST <= host) && (HSPI_HOST >= host));
214168
const char *spi_names[] = {
215169
"SPI_HOST", "", ""
216170
};
171+
172+
dma_chan = dma_channel;
173+
#elif defined (CONFIG_IDF_TARGET_ESP32C3)
174+
assert((SPI1_HOST <= host) && (SPI3_HOST >= host));
175+
const char *spi_names[] = {
176+
"SPI1_HOST", "SPI2_HOST", "SPI3_HOST"
177+
};
178+
179+
dma_chan = 3 /* SPI_DMA_CH_AUTO */;
180+
#else
181+
#error "Target chip not selected"
217182
#endif
218183

219184
ESP_LOGI(TAG, "Configuring SPI host %s (%d)", spi_names[host], host);
@@ -232,7 +197,7 @@ bool lvgl_spi_driver_init(int host,
232197
};
233198

234199
ESP_LOGI(TAG, "Initializing SPI bus...");
235-
esp_err_t ret = spi_bus_initialize(host, &buscfg, dma_channel);
200+
esp_err_t ret = spi_bus_initialize(host, &buscfg, dma_chan);
236201
assert(ret == ESP_OK);
237202

238203
return ESP_OK != ret;

lvgl_helpers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ extern "C" {
8989
* GLOBAL PROTOTYPES
9090
**********************/
9191

92+
void lvgl_i2c_locking(void* leader);
93+
9294
/* Initialize detected SPI and I2C bus and devices */
9395
void lvgl_driver_init(void);
9496

9597
/* Initialize SPI master */
9698
bool lvgl_spi_driver_init(int host, int miso_pin, int mosi_pin, int sclk_pin,
9799
int max_transfer_sz, int dma_channel, int quadwp_pin, int quadhd_pin);
98-
/* Initialize I2C master */
99-
bool lvgl_i2c_driver_init(int port, int sda_pin, int scl_pin, int speed);
100100

101101
/**********************
102102
* MACROS

0 commit comments

Comments
 (0)