diff --git a/esp32_s3_lcd_ev_board/Kconfig b/esp32_s3_lcd_ev_board/Kconfig index a368c2d1b..35fbddcf5 100644 --- a/esp32_s3_lcd_ev_board/Kconfig +++ b/esp32_s3_lcd_ev_board/Kconfig @@ -175,7 +175,7 @@ menu "Board Support Package" config BSP_DISPLAY_LVGL_ROTATION_270 bool "Rotation 270" help - Rotate screen when avoid tearing effect is enabled. + Rotate screen when avoid tearing effect is enabled. Need to set BSP_LCD_RGB_BUFFER_NUMS to 3. endchoice config BSP_DISPLAY_LVGL_ROTATION_DEGREE diff --git a/esp32_s3_lcd_ev_board/README.md b/esp32_s3_lcd_ev_board/README.md index e8e9f00dd..6a4202212 100644 --- a/esp32_s3_lcd_ev_board/README.md +++ b/esp32_s3_lcd_ev_board/README.md @@ -37,7 +37,7 @@ Here are some useful configurations in menuconfig that can be customed by user: * `BSP_DISPLAY_LVGL_MODE`: * `BSP_DISPLAY_LVGL_FULL_REFRESH`: Use LVGL full-refresh mode. Set `BSP_LCD_RGB_BUFFER_NUMS` to `3` will get higher FPS when enable `BSP_DISPLAY_LVGL_ROTATION_NONE`. * `BSP_DISPLAY_LVGL_DIRECT_MODE`: Use LVGL's direct mode. - * `BSP_DISPLAY_LVGL_ROTATION`: Rotate the screen clockwise. **The rotation is software-based and will substantially reduce FPS if enabled.** + * `BSP_DISPLAY_LVGL_ROTATION`: Rotate the screen clockwise. This requires setting `BSP_LCD_RGB_BUFFER_NUMS` to `3`. **The rotation is software-based and will substantially reduce FPS if enabled.** * `BSP_DISPLAY_LVGL_ROTATION_NONE`: No rotation. * `BSP_DISPLAY_LVGL_ROTATION_90`: 90-degree rotation. * `BSP_DISPLAY_LVGL_ROTATION_180`: 180-degree rotation. diff --git a/esp32_s3_lcd_ev_board/include/bsp/esp32_s3_lcd_ev_board.h b/esp32_s3_lcd_ev_board/include/bsp/esp32_s3_lcd_ev_board.h index 2923c7321..6ffb65ca0 100644 --- a/esp32_s3_lcd_ev_board/include/bsp/esp32_s3_lcd_ev_board.h +++ b/esp32_s3_lcd_ev_board/include/bsp/esp32_s3_lcd_ev_board.h @@ -75,6 +75,14 @@ typedef enum { extern "C" { #endif +/** + * @brief BSP display configuration structure + * + */ +typedef struct { + void *dummy; /*!< Prepared for future use. */ +} bsp_display_cfg_t; + /************************************************************************************************** * * I2C Interface @@ -252,7 +260,7 @@ esp_codec_dev_handle_t bsp_audio_codec_speaker_init(void); esp_codec_dev_handle_t bsp_audio_codec_microphone_init(void); /** - * @brief Enable/disable audio power amplifier + * @brief Enable/disable audio power amplifier (deprecated) * * @param[in] enable: Enable/disable audio power amplifier * @@ -322,12 +330,6 @@ esp_err_t bsp_audio_poweramp_enable(bool enable); #define LVGL_BUFFER_MALLOC (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT) #endif -typedef enum { - SUB_BOARD_TYPE_UNKNOW = 0, - SUB_BOARD_TYPE_2_480_480, - SUB_BOARD_TYPE_3_800_480, -} bsp_sub_board_type_t; - /** * @brief Initialize display * @@ -338,6 +340,18 @@ typedef enum { */ lv_disp_t *bsp_display_start(void); +/** + * @brief Initialize display + * + * This function initializes SPI, display controller and starts LVGL handling task. + * LCD backlight must be enabled separately by calling `bsp_display_brightness_set()` + * + * @param cfg display configuration + * + * @return Pointer to LVGL display or NULL when error occured + */ +lv_disp_t *bsp_display_start_with_config(const bsp_display_cfg_t *cfg); + /** * @brief Get pointer to input device (touch, buttons, ...) * @@ -398,24 +412,13 @@ void bsp_display_unlock(void); * @brief Rotate screen * * @note Display must be already initialized by calling `bsp_display_start()` + * @note This function can't work with the anti-tearing function. Please use the `BSP_DISPLAY_LVGL_ROTATION` configuration instead. * * @param[in] disp: Pointer to LVGL display * @param[in] rotation: Angle of the display rotation */ void bsp_display_rotate(lv_disp_t *disp, lv_disp_rot_t rotation); -/** - * @brief Get sub-board type - * - * @note This function should be called after calling `bsp_display_new()` or `bsp_display_start()` - * - * @return - * - SUB_BOARD_TYPE_UNKNOW: Unknow sub-board - * - SUB_BOARD_TYPE_2_480_480: Sub-board 2 with 480x480 LCD (GC9503), Touch (FT5x06) - * - SUB_BOARD_TYPE_3_800_480: Sub-board 3 with 800x480 LCD (ST7262), Touch (GT1151) - */ -bsp_sub_board_type_t bsp_display_get_sub_board_type(void); - /** * @brief Get display horizontal resolution * diff --git a/esp32_s3_lcd_ev_board/priv_include/bsp_sub_board.h b/esp32_s3_lcd_ev_board/priv_include/bsp_sub_board.h new file mode 100644 index 000000000..b1e209ac8 --- /dev/null +++ b/esp32_s3_lcd_ev_board/priv_include/bsp_sub_board.h @@ -0,0 +1,35 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef BSP_SUB_BOARD_H +#define BSP_SUB_BOARD_H + +#include "bsp/esp32_s3_lcd_ev_board.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + SUB_BOARD_TYPE_UNKNOW = 0, + SUB_BOARD_TYPE_2_480_480, + SUB_BOARD_TYPE_3_800_480, +} bsp_sub_board_type_t; + +/** + * @brief Get sub-board type + * + * @return + * - SUB_BOARD_TYPE_UNKNOW: Unknow sub-board + * - SUB_BOARD_TYPE_2_480_480: Sub-board 2 with 480x480 LCD (GC9503), Touch (FT5x06) + * - SUB_BOARD_TYPE_3_800_480: Sub-board 3 with 800x480 LCD (ST7262), Touch (GT1151) + */ +bsp_sub_board_type_t bsp_sub_board_get_type(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/esp32_s3_lcd_ev_board/src/bsp_lvgl_port.c b/esp32_s3_lcd_ev_board/src/bsp_lvgl_port.c index 69b382042..b686a6467 100644 --- a/esp32_s3_lcd_ev_board/src/bsp_lvgl_port.c +++ b/esp32_s3_lcd_ev_board/src/bsp_lvgl_port.c @@ -14,6 +14,7 @@ #include "lvgl.h" #include "bsp_err_check.h" +#include "bsp_sub_board.h" #include "bsp/display.h" #include "bsp/esp32_s3_lcd_ev_board.h" @@ -448,7 +449,7 @@ static lv_disp_t *display_init(esp_lcd_panel_handle_t lcd) ESP_LOGD(TAG, "Malloc memory for LVGL buffer"); #ifndef CONFIG_BSP_DISPLAY_LVGL_AVOID_TEAR - bsp_sub_board_type_t type = bsp_display_get_sub_board_type(); + bsp_sub_board_type_t type = bsp_sub_board_get_type(); if ((type == SUB_BOARD_TYPE_2_480_480) || (type == SUB_BOARD_TYPE_3_800_480)) { // Normmaly, for RGB LCD, we just use one frame buffer for LVGL rendering buffer_size = BSP_LCD_H_RES * LVGL_BUFFER_HEIGHT; diff --git a/esp32_s3_lcd_ev_board/src/bsp_sub_board.c b/esp32_s3_lcd_ev_board/src/bsp_sub_board.c index e6b0d8642..c9e8fe2d8 100644 --- a/esp32_s3_lcd_ev_board/src/bsp_sub_board.c +++ b/esp32_s3_lcd_ev_board/src/bsp_sub_board.c @@ -22,6 +22,7 @@ #include "sdkconfig.h" #include "bsp_err_check.h" +#include "bsp_sub_board.h" #include "bsp/display.h" #include "bsp/esp32_s3_lcd_ev_board.h" #include "bsp/touch.h" @@ -330,7 +331,7 @@ uint16_t bsp_display_get_v_res(void) } } -bsp_sub_board_type_t bsp_display_get_sub_board_type(void) +bsp_sub_board_type_t bsp_sub_board_get_type(void) { return sub_board_type; } @@ -341,20 +342,25 @@ static esp_err_t detect_sub_board_type(void) return ESP_OK; } - bsp_sub_board_type_t detect_type = SUB_BOARD_TYPE_UNKNOW; BSP_ERROR_CHECK_RETURN_ERR(bsp_i2c_init()); + uint8_t tp_address[] = { + ESP_LCD_TOUCH_IO_I2C_FT5x06_ADDRESS, + ESP_LCD_TOUCH_IO_I2C_GT1151_ADDRESS, + }; + uint8_t i = 0; i2c_cmd_handle_t cmd; - for (int i = 0; i < 0x7f; i++) { + bsp_sub_board_type_t detect_type = SUB_BOARD_TYPE_UNKNOW; + while (i < sizeof(tp_address)) { cmd = i2c_cmd_link_create(); i2c_master_start(cmd); - i2c_master_write_byte(cmd, (i << 1) | I2C_MASTER_WRITE, true); + i2c_master_write_byte(cmd, (tp_address[i] << 1) | I2C_MASTER_WRITE, true); i2c_master_stop(cmd); - if (i2c_master_cmd_begin(BSP_I2C_NUM, cmd, portMAX_DELAY) == ESP_OK) { - if (i == ESP_LCD_TOUCH_IO_I2C_FT5x06_ADDRESS) { + if (i2c_master_cmd_begin(BSP_I2C_NUM, cmd, pdMS_TO_TICKS(20)) == ESP_OK) { + if (tp_address[i] == ESP_LCD_TOUCH_IO_I2C_FT5x06_ADDRESS) { ESP_LOGI(TAG, "Detect sub_board2 with 480x480 LCD (GC9503), Touch (FT5x06)"); detect_type = SUB_BOARD_TYPE_2_480_480; - } else if (i == ESP_LCD_TOUCH_IO_I2C_GT1151_ADDRESS) { + } else if (tp_address[i] == ESP_LCD_TOUCH_IO_I2C_GT1151_ADDRESS) { ESP_LOGI(TAG, "Detect sub_board3 with 800x480 LCD (ST7262), Touch (GT1151)"); detect_type = SUB_BOARD_TYPE_3_800_480; } @@ -363,6 +369,7 @@ static esp_err_t detect_sub_board_type(void) if (detect_type != SUB_BOARD_TYPE_UNKNOW) { break; } + i++; } ESP_RETURN_ON_FALSE(detect_type != SUB_BOARD_TYPE_UNKNOW, ESP_ERR_INVALID_STATE, TAG, diff --git a/esp32_s3_lcd_ev_board/src/esp32_s3_lcd_ev_board.c b/esp32_s3_lcd_ev_board/src/esp32_s3_lcd_ev_board.c index 89038d044..a426fde9a 100644 --- a/esp32_s3_lcd_ev_board/src/esp32_s3_lcd_ev_board.c +++ b/esp32_s3_lcd_ev_board/src/esp32_s3_lcd_ev_board.c @@ -272,6 +272,12 @@ esp_err_t bsp_audio_poweramp_enable(bool enable) **********************************************************************************************************/ lv_disp_t *bsp_display_start(void) { + return bsp_display_start_with_config(NULL); +} + +lv_disp_t *bsp_display_start_with_config(const bsp_display_cfg_t *cfg) +{ + (void)cfg; bsp_display_config_t disp_config = { 0 }; esp_lcd_panel_handle_t lcd = NULL; // LCD panel handle esp_lcd_touch_handle_t tp = NULL; // LCD touch panel handle @@ -307,7 +313,11 @@ esp_err_t bsp_display_backlight_on(void) void bsp_display_rotate(lv_disp_t *disp, lv_disp_rot_t rotation) { +#if CONFIG_BSP_DISPLAY_LVGL_AVOID_TEAR + ESP_LOGE(TAG, "Unable to rotate the display using the `bsp_display_rotate()` function when the anti-tearing function is enabled. Please use the `BSP_DISPLAY_LVGL_ROTATION` configuration instead."); +#else lv_disp_set_rotation(disp, rotation); +#endif } bool bsp_display_lock(uint32_t timeout_ms) diff --git a/examples/display_audio_photo/main/app_disp_fs.c b/examples/display_audio_photo/main/app_disp_fs.c index 9dd02f90f..c80ad4b52 100644 --- a/examples/display_audio_photo/main/app_disp_fs.c +++ b/examples/display_audio_photo/main/app_disp_fs.c @@ -718,7 +718,7 @@ static void app_disp_lvgl_show_filesystem(lv_obj_t *screen, lv_group_t *group) /* File list */ fs_list = lv_list_create(screen); - lv_obj_set_size(fs_list, 320, 200); + lv_obj_set_size(fs_list, BSP_LCD_H_RES, BSP_LCD_V_RES - 40); lv_obj_set_style_bg_color(fs_list, lv_color_make(0x00, 0x00, 0x00), 0); lv_obj_set_style_text_color(fs_list, lv_color_make(0xFF, 0xFF, 0xFF), 0); lv_obj_center(fs_list);