14
14
#include "lvgl_touch/tp_spi.h"
15
15
16
16
#include "lvgl_spi_conf.h"
17
- #include "lvgl_i2c_conf.h"
18
17
19
- #include "driver/i2c .h"
18
+ #include "lvgl_i2c/i2c_manager .h"
20
19
21
20
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
22
- #include "src/lv_core/lv_refr .h"
21
+ #include "lvgl .h"
23
22
#else
24
- #include "lvgl/src/lv_core/lv_refr .h"
23
+ #include "lvgl/lvgl .h"
25
24
#endif
26
25
27
26
/*********************
53
52
/* Interface and driver initialization */
54
53
void lvgl_driver_init (void )
55
54
{
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 )
56
58
ESP_LOGI (TAG , "Display hor size: %d, ver size: %d" , LV_HOR_RES_MAX , LV_VER_RES_MAX );
59
+ #endif
60
+
57
61
ESP_LOGI (TAG , "Display buffer size: %d" , DISP_BUF_SIZE );
58
62
59
63
#if defined (CONFIG_LV_TFT_DISPLAY_CONTROLLER_FT81X )
@@ -63,7 +67,7 @@ void lvgl_driver_init(void)
63
67
DISP_SPI_MISO , DISP_SPI_MOSI , DISP_SPI_CLK ,
64
68
SPI_BUS_MAX_TRANSFER_SZ , 1 ,
65
69
DISP_SPI_IO2 , DISP_SPI_IO3 );
66
-
70
+
67
71
disp_spi_add_device (TFT_SPI_HOST );
68
72
disp_driver_init ();
69
73
@@ -81,48 +85,29 @@ void lvgl_driver_init(void)
81
85
TP_SPI_MISO , DISP_SPI_MOSI , DISP_SPI_CLK ,
82
86
SPI_BUS_MAX_TRANSFER_SZ , 1 ,
83
87
-1 , -1 );
84
-
88
+
85
89
disp_spi_add_device (TFT_SPI_HOST );
86
90
tp_spi_add_device (TOUCH_SPI_HOST );
87
-
88
- disp_driver_init ();
89
- touch_driver_init ();
90
-
91
- return ;
92
- #endif
93
91
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
-
101
92
disp_driver_init ();
102
93
touch_driver_init ();
103
-
94
+
104
95
return ;
105
96
#endif
106
97
107
98
/* Display controller initialization */
108
99
#if defined CONFIG_LV_TFT_DISPLAY_PROTOCOL_SPI
109
100
ESP_LOGI (TAG , "Initializing SPI master for display" );
110
-
101
+
111
102
lvgl_spi_driver_init (TFT_SPI_HOST ,
112
103
DISP_SPI_MISO , DISP_SPI_MOSI , DISP_SPI_CLK ,
113
104
SPI_BUS_MAX_TRANSFER_SZ , 1 ,
114
105
DISP_SPI_IO2 , DISP_SPI_IO3 );
115
-
106
+
116
107
disp_spi_add_device (TFT_SPI_HOST );
117
-
108
+
118
109
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 )
126
111
disp_driver_init ();
127
112
#else
128
113
#error "No protocol defined for display controller"
@@ -132,22 +117,16 @@ void lvgl_driver_init(void)
132
117
#if CONFIG_LV_TOUCH_CONTROLLER != TOUCH_CONTROLLER_NONE
133
118
#if defined (CONFIG_LV_TOUCH_DRIVER_PROTOCOL_SPI )
134
119
ESP_LOGI (TAG , "Initializing SPI master for touch" );
135
-
120
+
136
121
lvgl_spi_driver_init (TOUCH_SPI_HOST ,
137
122
TP_SPI_MISO , TP_SPI_MOSI , TP_SPI_CLK ,
138
123
0 /* Defaults to 4094 */ , 2 ,
139
124
-1 , -1 );
140
-
125
+
141
126
tp_spi_add_device (TOUCH_SPI_HOST );
142
-
127
+
143
128
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 )
151
130
touch_driver_init ();
152
131
#elif defined (CONFIG_LV_TOUCH_DRIVER_ADC )
153
132
touch_driver_init ();
@@ -160,60 +139,46 @@ void lvgl_driver_init(void)
160
139
#endif
161
140
}
162
141
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.
164
147
*
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.
168
150
*/
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 */
201
151
bool lvgl_spi_driver_init (int host ,
202
152
int miso_pin , int mosi_pin , int sclk_pin ,
203
153
int max_transfer_sz ,
204
154
int dma_channel ,
205
155
int quadwp_pin , int quadhd_pin )
206
156
{
157
+ int dma_chan = 0 /* SPI_DMA_DISABLED */ ;
158
+
207
159
#if defined (CONFIG_IDF_TARGET_ESP32 )
208
160
assert ((SPI_HOST <= host ) && (VSPI_HOST >= host ));
209
161
const char * spi_names [] = {
210
162
"SPI_HOST" , "HSPI_HOST" , "VSPI_HOST"
211
163
};
164
+
165
+ dma_chan = dma_channel ;
212
166
#elif defined (CONFIG_IDF_TARGET_ESP32S2 )
213
167
assert ((SPI_HOST <= host ) && (HSPI_HOST >= host ));
214
168
const char * spi_names [] = {
215
169
"SPI_HOST" , "" , ""
216
170
};
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"
217
182
#endif
218
183
219
184
ESP_LOGI (TAG , "Configuring SPI host %s (%d)" , spi_names [host ], host );
@@ -232,7 +197,7 @@ bool lvgl_spi_driver_init(int host,
232
197
};
233
198
234
199
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 );
236
201
assert (ret == ESP_OK );
237
202
238
203
return ESP_OK != ret ;
0 commit comments