From 4b46e4890da834255ecfe6a1b10a8d6cc74ba865 Mon Sep 17 00:00:00 2001 From: hbs2001 <56549893+hbs2001@users.noreply.github.com> Date: Tue, 11 Mar 2025 01:43:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86ESP32S3=5FKORVO2=5FV?= =?UTF-8?q?3=E5=AE=98=E6=96=B9lcd=E5=B1=8F=E5=B9=95=E7=9A=84=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20(#323)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ESP32S3_KORVO2_V3添加官方开发板屏幕支持 * 修正笔误 * Update esp32s3_korvo2_v3_board.cc --------- Co-authored-by: hbs2001 Co-authored-by: Xiaoxia --- main/Kconfig.projbuild | 12 +++ main/boards/esp32s3-korvo2-v3/config.h | 18 +++++ .../esp32s3_korvo2_v3_board.cc | 77 ++++++++++++++++++- 3 files changed, 105 insertions(+), 2 deletions(-) diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index a81e79c..affcf55 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -194,6 +194,18 @@ choice DISPLAY_LCD_TYPE bool "自定义屏幕参数" endchoice +choice DISPLAY_ESP32S3_KORVO2_V3 + depends on BOARD_TYPE_ESP32S3_KORVO2_V3 + prompt "ESP32S3_KORVO2_V3 LCD Type" + default LCD_ST7789 + help + 屏幕类型选择 + config LCD_ST7789 + bool "ST7789, 分辨率240*280" + config LCD_ILI9341 + bool "ILI9341, 分辨率240*320" +endchoice + config USE_AUDIO_PROCESSOR bool "启用音频降噪、增益处理" default y diff --git a/main/boards/esp32s3-korvo2-v3/config.h b/main/boards/esp32s3-korvo2-v3/config.h index 020cabb..b4f8f0f 100644 --- a/main/boards/esp32s3-korvo2-v3/config.h +++ b/main/boards/esp32s3-korvo2-v3/config.h @@ -26,6 +26,7 @@ #define VOLUME_UP_BUTTON_GPIO GPIO_NUM_NC #define VOLUME_DOWN_BUTTON_GPIO GPIO_NUM_NC +#ifdef CONFIG_LCD_ST7789 #define DISPLAY_SDA_PIN GPIO_NUM_NC #define DISPLAY_SCL_PIN GPIO_NUM_NC #define DISPLAY_WIDTH 280 @@ -37,6 +38,23 @@ #define DISPLAY_OFFSET_X 20 #define DISPLAY_OFFSET_Y 0 +#endif + +#ifdef CONFIG_LCD_ILI9341 +#define LCD_TYPE_ILI9341_SERIAL +#define DISPLAY_SDA_PIN GPIO_NUM_NC +#define DISPLAY_SCL_PIN GPIO_NUM_NC +#define DISPLAY_WIDTH 320 +#define DISPLAY_HEIGHT 240 + +#define DISPLAY_SWAP_XY false +#define DISPLAY_MIRROR_X true +#define DISPLAY_MIRROR_Y true +#define BACKLIGHT_INVERT false + +#define DISPLAY_OFFSET_X 0 +#define DISPLAY_OFFSET_Y 0 +#endif #define DISPLAY_BACKLIGHT_PIN GPIO_NUM_NC #define DISPLAY_BACKLIGHT_OUTPUT_INVERT false diff --git a/main/boards/esp32s3-korvo2-v3/esp32s3_korvo2_v3_board.cc b/main/boards/esp32s3-korvo2-v3/esp32s3_korvo2_v3_board.cc index febb10e..1fd7339 100644 --- a/main/boards/esp32s3-korvo2-v3/esp32s3_korvo2_v3_board.cc +++ b/main/boards/esp32s3-korvo2-v3/esp32s3_korvo2_v3_board.cc @@ -3,7 +3,6 @@ #include "display/lcd_display.h" #include "application.h" #include "button.h" - #include "config.h" #include "i2c_device.h" #include "iot/thing_manager.h" @@ -11,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -20,6 +20,28 @@ LV_FONT_DECLARE(font_puhui_20_4); LV_FONT_DECLARE(font_awesome_20_4); +// Init ili9341 by custom cmd +static const ili9341_lcd_init_cmd_t vendor_specific_init[] = { + {0xC8, (uint8_t []){0xFF, 0x93, 0x42}, 3, 0}, + {0xC0, (uint8_t []){0x0E, 0x0E}, 2, 0}, + {0xC5, (uint8_t []){0xD0}, 1, 0}, + {0xC1, (uint8_t []){0x02}, 1, 0}, + {0xB4, (uint8_t []){0x02}, 1, 0}, + {0xE0, (uint8_t []){0x00, 0x03, 0x08, 0x06, 0x13, 0x09, 0x39, 0x39, 0x48, 0x02, 0x0a, 0x08, 0x17, 0x17, 0x0F}, 15, 0}, + {0xE1, (uint8_t []){0x00, 0x28, 0x29, 0x01, 0x0d, 0x03, 0x3f, 0x33, 0x52, 0x04, 0x0f, 0x0e, 0x37, 0x38, 0x0F}, 15, 0}, + + {0xB1, (uint8_t []){00, 0x1B}, 2, 0}, + {0x36, (uint8_t []){0x08}, 1, 0}, + {0x3A, (uint8_t []){0x55}, 1, 0}, + {0xB7, (uint8_t []){0x06}, 1, 0}, + + {0x11, (uint8_t []){0}, 0x80, 0}, + {0x29, (uint8_t []){0}, 0x80, 0}, + + {0, (uint8_t []){0}, 0xff, 0}, +}; + + class Esp32S3Korvo2V3Board : public WifiBoard { private: Button boot_button_; @@ -123,6 +145,53 @@ private: }); } + void InitializeIli9341Display() { + esp_lcd_panel_io_handle_t panel_io = nullptr; + esp_lcd_panel_handle_t panel = nullptr; + + // 液晶屏控制IO初始化 + ESP_LOGD(TAG, "Install panel IO"); + esp_lcd_panel_io_spi_config_t io_config = {}; + io_config.cs_gpio_num = GPIO_NUM_NC; + io_config.dc_gpio_num = GPIO_NUM_2; + io_config.spi_mode = 0; + io_config.pclk_hz = 40 * 1000 * 1000; + io_config.trans_queue_depth = 10; + io_config.lcd_cmd_bits = 8; + io_config.lcd_param_bits = 8; + ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(SPI3_HOST, &io_config, &panel_io)); + + // 初始化液晶屏驱动芯片 + ESP_LOGD(TAG, "Install LCD driver"); + const ili9341_vendor_config_t vendor_config = { + .init_cmds = &vendor_specific_init[0], + .init_cmds_size = sizeof(vendor_specific_init) / sizeof(ili9341_lcd_init_cmd_t), + }; + + esp_lcd_panel_dev_config_t panel_config = {}; + panel_config.reset_gpio_num = GPIO_NUM_NC; + // panel_config.flags.reset_active_high = 0, + panel_config.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB; + panel_config.bits_per_pixel = 16; + panel_config.vendor_config = (void *)&vendor_config; + ESP_ERROR_CHECK(esp_lcd_new_panel_ili9341(panel_io, &panel_config, &panel)); + + ESP_ERROR_CHECK(esp_lcd_panel_reset(panel)); + EnableLcdCs(); + ESP_ERROR_CHECK(esp_lcd_panel_init(panel)); + ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY)); + ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y)); + ESP_ERROR_CHECK(esp_lcd_panel_invert_color(panel, false)); + ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel, true)); + display_ = new SpiLcdDisplay(panel_io, panel, + DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY, + { + .text_font = &font_puhui_20_4, + .icon_font = &font_awesome_20_4, + .emoji_font = font_emoji_64_init(), + }); + } + void InitializeSt7789Display() { esp_lcd_panel_io_handle_t panel_io = nullptr; esp_lcd_panel_handle_t panel = nullptr; @@ -176,7 +245,11 @@ public: InitializeTca9554(); InitializeSpi(); InitializeButtons(); - InitializeSt7789Display(); + #ifdef LCD_TYPE_ILI9341_SERIAL + InitializeIli9341Display(); + #else + InitializeSt7789Display(); + #endif InitializeIot(); }