@@ -35,6 +35,27 @@ static const unsigned int DISPLAY_REFRESH_HZ = 40000000;
3535static const int DISPLAY_SPI_QUEUE_LEN = 10 ;
3636static const int SPI_MAX_TRANSFER_SIZE = 32768 ;
3737
38+ #if CONFIG_IDF_TARGET_ESP32S3
39+ static const gpio_num_t SPI_CLOCK = GPIO_NUM_11 ;
40+ static const gpio_num_t SPI_MOSI = GPIO_NUM_10 ;
41+ static const gpio_num_t SPI_MISO = GPIO_NUM_13 ;
42+ static const gpio_num_t TFT_CS = GPIO_NUM_3 ;
43+ static const gpio_num_t TFT_RESET = GPIO_NUM_46 ;
44+ static const gpio_num_t TFT_DC = GPIO_NUM_9 ;
45+ static const gpio_num_t TFT_BACKLIGHT = GPIO_NUM_12 ;
46+ #elif CONFIG_IDF_TARGET_ESP32
47+ static const gpio_num_t SPI_CLOCK = GPIO_NUM_14 ;
48+ static const gpio_num_t SPI_MOSI = GPIO_NUM_15 ;
49+ static const gpio_num_t SPI_MISO = GPIO_NUM_2 ;
50+ static const gpio_num_t TFT_CS = GPIO_NUM_16 ;
51+ static const gpio_num_t TFT_RESET = GPIO_NUM_NC ;
52+ static const gpio_num_t TFT_DC = GPIO_NUM_17 ;
53+ static const gpio_num_t TFT_BACKLIGHT = GPIO_NUM_18 ;
54+ #else
55+ #error Unsure which GPIO to use for SPI/TFT, please update code accordingly.
56+ #endif
57+ static const lcd_rgb_element_order_t TFT_COLOR_MODE = COLOR_RGB_ELEMENT_ORDER_BGR ;
58+
3859// Default to 25 lines of color data
3960static const size_t LV_BUFFER_SIZE = DISPLAY_HORIZONTAL_PIXELS * 25 ;
4061static const int LVGL_UPDATE_PERIOD_MS = 5 ;
@@ -88,7 +109,7 @@ static void display_brightness_init(void)
88109{
89110 const ledc_channel_config_t LCD_backlight_channel =
90111 {
91- .gpio_num = ( gpio_num_t ) CONFIG_TFT_BACKLIGHT_PIN ,
112+ .gpio_num = TFT_BACKLIGHT ,
92113 .speed_mode = BACKLIGHT_LEDC_MODE ,
93114 .channel = BACKLIGHT_LEDC_CHANNEL ,
94115 .intr_type = LEDC_INTR_DISABLE ,
@@ -108,7 +129,7 @@ static void display_brightness_init(void)
108129 .freq_hz = BACKLIGHT_LEDC_FRQUENCY ,
109130 .clk_cfg = LEDC_AUTO_CLK
110131 };
111- ESP_LOGI (TAG , "Initializing LEDC for backlight pin: %d" , CONFIG_TFT_BACKLIGHT_PIN );
132+ ESP_LOGI (TAG , "Initializing LEDC for backlight pin: %d" , TFT_BACKLIGHT );
112133
113134 ESP_ERROR_CHECK (ledc_timer_config (& LCD_backlight_timer ));
114135 ESP_ERROR_CHECK (ledc_channel_config (& LCD_backlight_channel ));
@@ -135,12 +156,12 @@ void display_brightness_set(int brightness_percentage)
135156void initialize_spi ()
136157{
137158 ESP_LOGI (TAG , "Initializing SPI bus (MOSI:%d, MISO:%d, CLK:%d)" ,
138- CONFIG_SPI_MOSI , CONFIG_SPI_MISO , CONFIG_SPI_CLOCK );
159+ SPI_MOSI , SPI_MISO , SPI_CLOCK );
139160 spi_bus_config_t bus =
140161 {
141- .mosi_io_num = CONFIG_SPI_MOSI ,
142- .miso_io_num = CONFIG_SPI_MISO ,
143- .sclk_io_num = CONFIG_SPI_CLOCK ,
162+ .mosi_io_num = SPI_MOSI ,
163+ .miso_io_num = SPI_MISO ,
164+ .sclk_io_num = SPI_CLOCK ,
144165 .quadwp_io_num = GPIO_NUM_NC ,
145166 .quadhd_io_num = GPIO_NUM_NC ,
146167 .data4_io_num = GPIO_NUM_NC ,
@@ -160,15 +181,19 @@ void initialize_display()
160181{
161182 const esp_lcd_panel_io_spi_config_t io_config =
162183 {
163- .cs_gpio_num = CONFIG_TFT_CS_PIN ,
164- .dc_gpio_num = CONFIG_TFT_DC_PIN ,
184+ .cs_gpio_num = TFT_CS ,
185+ .dc_gpio_num = TFT_DC ,
165186 .spi_mode = 0 ,
166187 .pclk_hz = DISPLAY_REFRESH_HZ ,
167188 .trans_queue_depth = DISPLAY_SPI_QUEUE_LEN ,
168189 .on_color_trans_done = notify_lvgl_flush_ready ,
169190 .user_ctx = & lv_disp_drv ,
170191 .lcd_cmd_bits = DISPLAY_COMMAND_BITS ,
171192 .lcd_param_bits = DISPLAY_PARAMETER_BITS ,
193+ #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL (5 ,4 ,0 )
194+ .cs_ena_pretrans = 0 ,
195+ .cs_ena_posttrans = 0 ,
196+ #endif
172197 .flags =
173198 {
174199#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL (5 , 0 , 0 )
@@ -188,8 +213,8 @@ void initialize_display()
188213
189214 const esp_lcd_panel_dev_config_t lcd_config =
190215 {
191- .reset_gpio_num = CONFIG_TFT_RESET_PIN ,
192- .color_space = CONFIG_DISPLAY_COLOR_MODE ,
216+ .reset_gpio_num = TFT_RESET ,
217+ .color_space = TFT_COLOR_MODE ,
193218 .bits_per_pixel = 18 ,
194219 .flags =
195220 {
0 commit comments