From b0f0f4d4db7b7b84c4224c118435ce91cd0773e6 Mon Sep 17 00:00:00 2001 From: Kevincoooool <33611679+Kevincoooool@users.noreply.github.com> Date: Mon, 24 Feb 2025 11:07:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0LCD=E5=B1=8F=E5=B9=95?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B\RGB=E5=B1=8F=E5=8F=82=E8=80=83\=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=B1=BC=E9=B9=B03.13=E5=AF=B8LCD=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E6=9D=BF=20(#191)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 增加LCD屏幕类型\RGB屏参考\增加鱼鹰3.13寸LCD开发板 1、增加LCD屏幕类型判断,lvgl port对不同屏幕初始化不一样 2、增加RGB屏使用参考 3、增加鱼鹰3.13寸LCD开发板 * Update lcd_display.h * 修改xingzhi两个board为SpiLcdDisplay --- main/CMakeLists.txt | 3 + main/Kconfig.projbuild | 2 + .../atk-dnesp32s3-box/atk_dnesp32s3_box.cc | 2 +- main/boards/atk-dnesp32s3/atk_dnesp32s3.cc | 2 +- .../atoms3-echo-base/atoms3_echo_base.cc | 2 +- .../atoms3r-echo-base/atoms3r_echo_base.cc | 2 +- .../compact_wifi_board_lcd.cc | 2 +- main/boards/du-chatx/du-chatx-wifi.cc | 2 +- main/boards/esp-box-3/esp_box3_board.cc | 2 +- .../boards/esp-sparkbot/esp_sparkbot_board.cc | 2 +- .../esp32-s3-touch-lcd-1.85.cc | 2 +- .../esp32-s3-touch-lcd-1.85c.cc | 2 +- .../esp32s3_korvo2_v3_board.cc | 2 +- main/boards/kevin-sp-v3-dev/config.json | 9 + .../kevin-sp-v3-dev/kevin-sp-v3_board.cc | 2 +- main/boards/kevin-yuying-313lcd/config.h | 35 ++ main/boards/kevin-yuying-313lcd/config.json | 9 + .../kevin-yuying-313lcd/esp_lcd_gc9503.c | 479 ++++++++++++++++++ .../kevin-yuying-313lcd/esp_lcd_gc9503.h | 145 ++++++ .../kevin_yuying_313lcd.cc | 178 +++++++ main/boards/kevin-yuying-313lcd/pin_config.h | 47 ++ .../lichuang-c3-dev/lichuang_c3_dev_board.cc | 2 +- .../boards/lichuang-dev/lichuang_dev_board.cc | 2 +- .../lilygo-t-circle-s3/lilygo-t-circle-s3.cc | 2 +- .../boards/m5stack-core-s3/m5stack_core_s3.cc | 2 +- .../movecall_moji_esp32s3.cc | 2 +- main/boards/taiji-pi-s3/taiji_pi_s3.cc | 2 +- .../xingzhi-cube-1.54tft-ml307.cc | 2 +- .../xingzhi-cube-1.54tft-wifi.cc | 2 +- main/display/lcd_display.cc | 85 +++- main/display/lcd_display.h | 65 ++- main/idf_component.yml | 1 + 32 files changed, 1069 insertions(+), 29 deletions(-) create mode 100644 main/boards/kevin-sp-v3-dev/config.json create mode 100644 main/boards/kevin-yuying-313lcd/config.h create mode 100644 main/boards/kevin-yuying-313lcd/config.json create mode 100644 main/boards/kevin-yuying-313lcd/esp_lcd_gc9503.c create mode 100644 main/boards/kevin-yuying-313lcd/esp_lcd_gc9503.h create mode 100644 main/boards/kevin-yuying-313lcd/kevin_yuying_313lcd.cc create mode 100644 main/boards/kevin-yuying-313lcd/pin_config.h diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 3b69b6ae..42f5e364 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -12,6 +12,7 @@ set(SOURCES "audio_codecs/audio_codec.cc" "display/lcd_display.cc" "display/ssd1306_display.cc" "boards/lilygo-t-circle-s3/esp_lcd_gc9d01n.c" + "boards/kevin-yuying-313lcd/esp_lcd_gc9503.c" "protocols/protocol.cc" "iot/thing.cc" "iot/thing_manager.cc" @@ -51,6 +52,8 @@ elseif(CONFIG_BOARD_TYPE_KEVIN_C3) set(BOARD_TYPE "kevin-c3") elseif(CONFIG_BOARD_TYPE_KEVIN_SP_V3_DEV) set(BOARD_TYPE "kevin-sp-v3-dev") +elseif(CONFIG_BOARD_TYPE_KEVIN_YUYING_313LCD) + set(BOARD_TYPE "kevin-yuying-313lcd") elseif(CONFIG_BOARD_TYPE_LICHUANG_DEV) set(BOARD_TYPE "lichuang-dev") elseif(CONFIG_BOARD_TYPE_LICHUANG_C3_DEV) diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index 5bfa9cb4..c7a03400 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -68,6 +68,8 @@ choice BOARD_TYPE bool "Kevin C3" config BOARD_TYPE_KEVIN_SP_V3_DEV bool "Kevin SP V3开发板" + config BOARD_TYPE_KEVIN_YUYING_313LCD + bool "鱼鹰科技3.13LCD开发板" config BOARD_TYPE_LICHUANG_DEV bool "立创·实战派ESP32-S3开发板" config BOARD_TYPE_LICHUANG_C3_DEV diff --git a/main/boards/atk-dnesp32s3-box/atk_dnesp32s3_box.cc b/main/boards/atk-dnesp32s3-box/atk_dnesp32s3_box.cc index 6efcb202..a5eeec76 100644 --- a/main/boards/atk-dnesp32s3-box/atk_dnesp32s3_box.cc +++ b/main/boards/atk-dnesp32s3-box/atk_dnesp32s3_box.cc @@ -152,7 +152,7 @@ private: esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y); ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel, true)); - display_ = new LcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new SpiLcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, 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, diff --git a/main/boards/atk-dnesp32s3/atk_dnesp32s3.cc b/main/boards/atk-dnesp32s3/atk_dnesp32s3.cc index 086879c0..7ed2c8bc 100644 --- a/main/boards/atk-dnesp32s3/atk_dnesp32s3.cc +++ b/main/boards/atk-dnesp32s3/atk_dnesp32s3.cc @@ -132,7 +132,7 @@ private: esp_lcd_panel_invert_color(panel, true); esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY); esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y); - display_ = new LcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new SpiLcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, 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, diff --git a/main/boards/atoms3-echo-base/atoms3_echo_base.cc b/main/boards/atoms3-echo-base/atoms3_echo_base.cc index a426fa6f..69b16942 100644 --- a/main/boards/atoms3-echo-base/atoms3_echo_base.cc +++ b/main/boards/atoms3-echo-base/atoms3_echo_base.cc @@ -177,7 +177,7 @@ private: ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true)); - display_ = new LcdDisplay(io_handle, panel_handle, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new SpiLcdDisplay(io_handle, panel_handle, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY, { .text_font = &font_puhui_16_4, diff --git a/main/boards/atoms3r-echo-base/atoms3r_echo_base.cc b/main/boards/atoms3r-echo-base/atoms3r_echo_base.cc index 226dd396..3b60def8 100644 --- a/main/boards/atoms3r-echo-base/atoms3r_echo_base.cc +++ b/main/boards/atoms3r-echo-base/atoms3r_echo_base.cc @@ -237,7 +237,7 @@ private: ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle)); ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true)); - display_ = new LcdDisplay(io_handle, panel_handle, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new SpiLcdDisplay(io_handle, panel_handle, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY, { .text_font = &font_puhui_16_4, diff --git a/main/boards/bread-compact-wifi-lcd/compact_wifi_board_lcd.cc b/main/boards/bread-compact-wifi-lcd/compact_wifi_board_lcd.cc index fe3f6d87..01224b4b 100644 --- a/main/boards/bread-compact-wifi-lcd/compact_wifi_board_lcd.cc +++ b/main/boards/bread-compact-wifi-lcd/compact_wifi_board_lcd.cc @@ -74,7 +74,7 @@ private: esp_lcd_panel_invert_color(panel, DISPLAY_INVERT_COLOR); esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY); esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y); - display_ = new LcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new SpiLcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY, { .text_font = &font_puhui_16_4, diff --git a/main/boards/du-chatx/du-chatx-wifi.cc b/main/boards/du-chatx/du-chatx-wifi.cc index 3643dd72..85521bc0 100644 --- a/main/boards/du-chatx/du-chatx-wifi.cc +++ b/main/boards/du-chatx/du-chatx-wifi.cc @@ -74,7 +74,7 @@ private: esp_lcd_panel_invert_color(panel, DISPLAY_INVERT_COLOR); esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY); esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y); - display_ = new LcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new SpiLcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY, { .text_font = &font_puhui_16_4, diff --git a/main/boards/esp-box-3/esp_box3_board.cc b/main/boards/esp-box-3/esp_box3_board.cc index 841df0a0..07631fd6 100644 --- a/main/boards/esp-box-3/esp_box3_board.cc +++ b/main/boards/esp-box-3/esp_box3_board.cc @@ -121,7 +121,7 @@ private: esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY); esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y); esp_lcd_panel_disp_on_off(panel, true); - display_ = new LcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new SpiLcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, 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, diff --git a/main/boards/esp-sparkbot/esp_sparkbot_board.cc b/main/boards/esp-sparkbot/esp_sparkbot_board.cc index 1a83a06a..ab2f51d9 100644 --- a/main/boards/esp-sparkbot/esp_sparkbot_board.cc +++ b/main/boards/esp-sparkbot/esp_sparkbot_board.cc @@ -113,7 +113,7 @@ private: esp_lcd_panel_init(panel); esp_lcd_panel_invert_color(panel, false); esp_lcd_panel_disp_on_off(panel, true); - display_ = new LcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new SpiLcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, 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, diff --git a/main/boards/esp32-s3-touch-lcd-1.85/esp32-s3-touch-lcd-1.85.cc b/main/boards/esp32-s3-touch-lcd-1.85/esp32-s3-touch-lcd-1.85.cc index a61f29ef..9ee5ad84 100644 --- a/main/boards/esp32-s3-touch-lcd-1.85/esp32-s3-touch-lcd-1.85.cc +++ b/main/boards/esp32-s3-touch-lcd-1.85/esp32-s3-touch-lcd-1.85.cc @@ -111,7 +111,7 @@ private: esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY); esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y); - display_ = new LcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new SpiLcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY, { .text_font = &font_puhui_16_4, diff --git a/main/boards/esp32-s3-touch-lcd-1.85c/esp32-s3-touch-lcd-1.85c.cc b/main/boards/esp32-s3-touch-lcd-1.85c/esp32-s3-touch-lcd-1.85c.cc index a1157cd1..ecc18138 100644 --- a/main/boards/esp32-s3-touch-lcd-1.85c/esp32-s3-touch-lcd-1.85c.cc +++ b/main/boards/esp32-s3-touch-lcd-1.85c/esp32-s3-touch-lcd-1.85c.cc @@ -110,7 +110,7 @@ private: esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY); esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y); - display_ = new LcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new SpiLcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY, { .text_font = &font_puhui_16_4, 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 cf4191da..7ba1e664 100644 --- a/main/boards/esp32s3-korvo2-v3/esp32s3_korvo2_v3_board.cc +++ b/main/boards/esp32s3-korvo2-v3/esp32s3_korvo2_v3_board.cc @@ -152,7 +152,7 @@ private: ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y)); ESP_ERROR_CHECK(esp_lcd_panel_invert_color(panel, true)); - display_ = new LcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new SpiLcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, 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, diff --git a/main/boards/kevin-sp-v3-dev/config.json b/main/boards/kevin-sp-v3-dev/config.json new file mode 100644 index 00000000..74cf3501 --- /dev/null +++ b/main/boards/kevin-sp-v3-dev/config.json @@ -0,0 +1,9 @@ +{ + "target": "esp32c3", + "builds": [ + { + "name": "kevin-sp-v3-dev", + "sdkconfig_append": [] + } + ] +} \ No newline at end of file diff --git a/main/boards/kevin-sp-v3-dev/kevin-sp-v3_board.cc b/main/boards/kevin-sp-v3-dev/kevin-sp-v3_board.cc index a2d6f328..152d7ef0 100644 --- a/main/boards/kevin-sp-v3-dev/kevin-sp-v3_board.cc +++ b/main/boards/kevin-sp-v3-dev/kevin-sp-v3_board.cc @@ -82,7 +82,7 @@ private: ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y)); ESP_ERROR_CHECK(esp_lcd_panel_invert_color(panel, true)); - display_ = new LcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new SpiLcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, 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, diff --git a/main/boards/kevin-yuying-313lcd/config.h b/main/boards/kevin-yuying-313lcd/config.h new file mode 100644 index 00000000..b5337413 --- /dev/null +++ b/main/boards/kevin-yuying-313lcd/config.h @@ -0,0 +1,35 @@ +#ifndef _BOARD_CONFIG_H_ +#define _BOARD_CONFIG_H_ + +#include + +#define AUDIO_INPUT_SAMPLE_RATE 16000 +#define AUDIO_OUTPUT_SAMPLE_RATE 16000 + +#define AUDIO_I2S_GPIO_MCLK GPIO_NUM_42 +#define AUDIO_I2S_GPIO_WS GPIO_NUM_39 +#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_41 +#define AUDIO_I2S_GPIO_DIN GPIO_NUM_40 +#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_38 + +#define AUDIO_CODEC_PA_PIN GPIO_NUM_45 +#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_1 +#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_2 +#define AUDIO_CODEC_ES8311_ADDR ES8311_CODEC_DEFAULT_ADDR + +#define BUILTIN_LED_GPIO GPIO_NUM_NC +#define BOOT_BUTTON_GPIO GPIO_NUM_0 + +#define DISPLAY_WIDTH 376 +#define DISPLAY_HEIGHT 960 +#define DISPLAY_MIRROR_X true +#define DISPLAY_MIRROR_Y false +#define DISPLAY_SWAP_XY true + +#define DISPLAY_OFFSET_X 0 +#define DISPLAY_OFFSET_Y 0 + +#define DISPLAY_BACKLIGHT_PIN GPIO_NUM_4 +#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false + +#endif // _BOARD_CONFIG_H_ diff --git a/main/boards/kevin-yuying-313lcd/config.json b/main/boards/kevin-yuying-313lcd/config.json new file mode 100644 index 00000000..88a0506d --- /dev/null +++ b/main/boards/kevin-yuying-313lcd/config.json @@ -0,0 +1,9 @@ +{ + "target": "esp32c3", + "builds": [ + { + "name": "kevin-yuying-313lcd", + "sdkconfig_append": [] + } + ] +} \ No newline at end of file diff --git a/main/boards/kevin-yuying-313lcd/esp_lcd_gc9503.c b/main/boards/kevin-yuying-313lcd/esp_lcd_gc9503.c new file mode 100644 index 00000000..f319f1b1 --- /dev/null +++ b/main/boards/kevin-yuying-313lcd/esp_lcd_gc9503.c @@ -0,0 +1,479 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "driver/gpio.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_check.h" +#include "esp_lcd_panel_commands.h" +#include "esp_lcd_panel_interface.h" +#include "esp_lcd_panel_io.h" +#include "esp_lcd_panel_rgb.h" +#include "esp_lcd_panel_vendor.h" +#include "esp_log.h" + +#include "esp_lcd_gc9503.h" + +#define GC9503_CMD_MADCTL (0xB1) // Memory data access control +#define GC9503_CMD_MADCTL_DEFAULT (0x10) // Default value of Memory data access control +#define GC9503_CMD_SS_BIT (1 << 0) // Source driver scan direction, 0: top to bottom, 1: bottom to top +#define GC9503_CMD_GS_BIT (1 << 1) // Gate driver scan direction, 0: left to right, 1: right to left +#define GC9503_CMD_BGR_BIT (1 << 5) // RGB/BGR order, 0: RGB, 1: BGR + +typedef struct +{ + esp_lcd_panel_io_handle_t io; + int reset_gpio_num; + uint8_t madctl_val; // Save current value of GC9503_CMD_MADCTL register + uint8_t colmod_val; // Save current value of LCD_CMD_COLMOD register + const gc9503_lcd_init_cmd_t *init_cmds; + uint16_t init_cmds_size; + struct + { + unsigned int mirror_by_cmd : 1; + unsigned int auto_del_panel_io : 1; + unsigned int display_on_off_use_cmd : 1; + unsigned int reset_level : 1; + } flags; + // To save the original functions of RGB panel + esp_err_t (*init)(esp_lcd_panel_t *panel); + esp_err_t (*del)(esp_lcd_panel_t *panel); + esp_err_t (*reset)(esp_lcd_panel_t *panel); + esp_err_t (*mirror)(esp_lcd_panel_t *panel, bool x_axis, bool y_axis); + esp_err_t (*disp_on_off)(esp_lcd_panel_t *panel, bool on_off); +} gc9503_panel_t; + +static const char *TAG = "gc9503"; + +static esp_err_t panel_gc9503_send_init_cmds(gc9503_panel_t *gc9503); + +static esp_err_t panel_gc9503_init(esp_lcd_panel_t *panel); +static esp_err_t panel_gc9503_del(esp_lcd_panel_t *panel); +static esp_err_t panel_gc9503_reset(esp_lcd_panel_t *panel); +static esp_err_t panel_gc9503_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y); +static esp_err_t panel_gc9503_disp_on_off(esp_lcd_panel_t *panel, bool off); + +esp_err_t esp_lcd_new_panel_gc9503(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *panel_dev_config, + esp_lcd_panel_handle_t *ret_panel) +{ + ESP_RETURN_ON_FALSE(io && panel_dev_config && ret_panel, ESP_ERR_INVALID_ARG, TAG, "invalid arguments"); + gc9503_vendor_config_t *vendor_config = (gc9503_vendor_config_t *)panel_dev_config->vendor_config; + ESP_RETURN_ON_FALSE(vendor_config && vendor_config->rgb_config, ESP_ERR_INVALID_ARG, TAG, "`verndor_config` and `rgb_config` are necessary"); + ESP_RETURN_ON_FALSE(!vendor_config->flags.auto_del_panel_io || !vendor_config->flags.mirror_by_cmd, + ESP_ERR_INVALID_ARG, TAG, "`mirror_by_cmd` and `auto_del_panel_io` cannot work together"); + + esp_err_t ret = ESP_OK; + gpio_config_t io_conf = {0}; + + gc9503_panel_t *gc9503 = (gc9503_panel_t *)calloc(1, sizeof(gc9503_panel_t)); + ESP_RETURN_ON_FALSE(gc9503, ESP_ERR_NO_MEM, TAG, "no mem for gc9503 panel"); + + if (panel_dev_config->reset_gpio_num >= 0) + { + io_conf.mode = GPIO_MODE_OUTPUT; + io_conf.pin_bit_mask = 1ULL << panel_dev_config->reset_gpio_num; + ESP_GOTO_ON_ERROR(gpio_config(&io_conf), err, TAG, "configure GPIO for RST line failed"); + } + + gc9503->madctl_val = GC9503_CMD_MADCTL_DEFAULT; + switch (panel_dev_config->rgb_ele_order) + { + case LCD_RGB_ELEMENT_ORDER_RGB: + gc9503->madctl_val &= ~GC9503_CMD_BGR_BIT; + break; + case LCD_RGB_ELEMENT_ORDER_BGR: + gc9503->madctl_val |= GC9503_CMD_BGR_BIT; + break; + default: + ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported color element order"); + break; + } + + gc9503->colmod_val = 0; + switch (panel_dev_config->bits_per_pixel) + { + case 16: // RGB565 + gc9503->colmod_val = 0x50; + break; + case 18: // RGB666 + gc9503->colmod_val = 0x60; + break; + case 24: // RGB888 + gc9503->colmod_val = 0x70; + break; + default: + ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported pixel width"); + break; + } + + gc9503->io = io; + gc9503->init_cmds = vendor_config->init_cmds; + gc9503->init_cmds_size = vendor_config->init_cmds_size; + gc9503->reset_gpio_num = panel_dev_config->reset_gpio_num; + gc9503->flags.reset_level = panel_dev_config->flags.reset_active_high; + gc9503->flags.auto_del_panel_io = vendor_config->flags.auto_del_panel_io; + gc9503->flags.mirror_by_cmd = vendor_config->flags.mirror_by_cmd; + gc9503->flags.display_on_off_use_cmd = (vendor_config->rgb_config->disp_gpio_num >= 0) ? 0 : 1; + + if (gc9503->flags.auto_del_panel_io) + { + if (gc9503->reset_gpio_num >= 0) + { // Perform hardware reset + gpio_set_level(gc9503->reset_gpio_num, gc9503->flags.reset_level); + vTaskDelay(pdMS_TO_TICKS(10)); + gpio_set_level(gc9503->reset_gpio_num, !gc9503->flags.reset_level); + } + else + { // Perform software reset + ESP_GOTO_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_SWRESET, NULL, 0), err, TAG, "send command failed"); + } + vTaskDelay(pdMS_TO_TICKS(120)); + + /** + * In order to enable the 3-wire SPI interface pins (such as SDA and SCK) to share other pins of the RGB interface + * (such as HSYNC) and save GPIOs, we need to send LCD initialization commands via the 3-wire SPI interface before + * `esp_lcd_new_rgb_panel()` is called. + */ + ESP_GOTO_ON_ERROR(panel_gc9503_send_init_cmds(gc9503), err, TAG, "send init commands failed"); + // After sending the initialization commands, the 3-wire SPI interface can be deleted + ESP_GOTO_ON_ERROR(esp_lcd_panel_io_del(io), err, TAG, "delete panel IO failed"); + gc9503->io = NULL; + ESP_LOGD(TAG, "delete panel IO"); + } + + // Create RGB panel + ESP_GOTO_ON_ERROR(esp_lcd_new_rgb_panel(vendor_config->rgb_config, ret_panel), err, TAG, "create RGB panel failed"); + ESP_LOGD(TAG, "new RGB panel @%p", ret_panel); + + // Save the original functions of RGB panel + gc9503->init = (*ret_panel)->init; + gc9503->del = (*ret_panel)->del; + gc9503->reset = (*ret_panel)->reset; + gc9503->mirror = (*ret_panel)->mirror; + gc9503->disp_on_off = (*ret_panel)->disp_on_off; + // Overwrite the functions of RGB panel + (*ret_panel)->init = panel_gc9503_init; + (*ret_panel)->del = panel_gc9503_del; + (*ret_panel)->reset = panel_gc9503_reset; + (*ret_panel)->mirror = panel_gc9503_mirror; + (*ret_panel)->disp_on_off = panel_gc9503_disp_on_off; + (*ret_panel)->user_data = gc9503; + ESP_LOGD(TAG, "new gc9503 panel @%p", gc9503); + + // ESP_LOGI(TAG, "LCD panel create success, version: %d.%d.%d", ESP_LCD_GC9503_VER_MAJOR, ESP_LCD_GC9503_VER_MINOR, + // ESP_LCD_GC9503_VER_PATCH); + return ESP_OK; + +err: + if (gc9503) + { + if (panel_dev_config->reset_gpio_num >= 0) + { + gpio_reset_pin(panel_dev_config->reset_gpio_num); + } + free(gc9503); + } + return ret; +} + +// *INDENT-OFF* +// static const gc9503_lcd_init_cmd_t vendor_specific_init_default[] = { +// // {cmd, { data }, data_size, delay_ms} +// {0x11, (uint8_t []){0x00}, 0, 120}, + +// {0xf0, (uint8_t []){0x55, 0xaa, 0x52, 0x08, 0x00}, 5, 0}, +// {0xf6, (uint8_t []){0x5a, 0x87}, 2, 0}, +// {0xc1, (uint8_t []){0x3f}, 1, 0}, +// {0xc2, (uint8_t []){0x0e}, 1, 0}, +// {0xc6, (uint8_t []){0xf8}, 1, 0}, +// {0xc9, (uint8_t []){0x10}, 1, 0}, +// {0xcd, (uint8_t []){0x25}, 1, 0}, +// {0xf8, (uint8_t []){0x8a}, 1, 0}, +// {0xac, (uint8_t []){0x45}, 1, 0}, +// {0xa0, (uint8_t []){0xdd}, 1, 0}, +// {0xa7, (uint8_t []){0x47}, 1, 0}, +// {0xfa, (uint8_t []){0x00, 0x00, 0x00, 0x04}, 4, 0}, +// {0x86, (uint8_t []){0x99, 0xa3, 0xa3, 0x51}, 4, 0}, +// {0xa3, (uint8_t []){0xee}, 1, 0}, +// {0xfd, (uint8_t []){0x3c, 0x3c, 0x00}, 3, 0}, +// {0x71, (uint8_t []){0x48}, 1, 0}, +// {0x72, (uint8_t []){0x48}, 1, 0}, +// {0x73, (uint8_t []){0x00, 0x44}, 2, 0}, +// {0x97, (uint8_t []){0xee}, 1, 0}, +// {0x83, (uint8_t []){0x93}, 1, 0}, +// {0x9a, (uint8_t []){0x72}, 1, 0}, +// {0x9b, (uint8_t []){0x5a}, 1, 0}, +// {0x82, (uint8_t []){0x2c, 0x2c}, 2, 0}, +// {0x6d, (uint8_t []){0x00, 0x1f, 0x19, 0x1a, 0x10, 0x0e, 0x0c, 0x0a, 0x02, 0x07, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, +// 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x08, 0x01, 0x09, 0x0b, 0x0d, 0x0f, 0x1a, 0x19, 0x1f, 0x00}, 32, 0}, +// {0x64, (uint8_t []){0x38, 0x05, 0x01, 0xdb, 0x03, 0x03, 0x38, 0x04, 0x01, 0xdc, 0x03, 0x03, 0x7a, 0x7a, 0x7a, 0x7a}, 16, 0}, +// {0x65, (uint8_t []){0x38, 0x03, 0x01, 0xdd, 0x03, 0x03, 0x38, 0x02, 0x01, 0xde, 0x03, 0x03, 0x7a, 0x7a, 0x7a, 0x7a}, 16, 0}, +// {0x66, (uint8_t []){0x38, 0x01, 0x01, 0xdf, 0x03, 0x03, 0x38, 0x00, 0x01, 0xe0, 0x03, 0x03, 0x7a, 0x7a, 0x7a, 0x7a}, 16, 0}, +// {0x67, (uint8_t []){0x30, 0x01, 0x01, 0xe1, 0x03, 0x03, 0x30, 0x02, 0x01, 0xe2, 0x03, 0x03, 0x7a, 0x7a, 0x7a, 0x7a}, 16, 0}, +// {0x68, (uint8_t []){0x00, 0x08, 0x15, 0x08, 0x15, 0x7a, 0x7a, 0x08, 0x15, 0x08, 0x15, 0x7a, 0x7a}, 13, 0}, +// {0x60, (uint8_t []){0x38, 0x08, 0x7a, 0x7a, 0x38, 0x09, 0x7a, 0x7a}, 8, 0}, +// {0x63, (uint8_t []){0x31, 0xe4, 0x7a, 0x7a, 0x31, 0xe5, 0x7a, 0x7a}, 8, 0}, +// {0x69, (uint8_t []){0x04, 0x22, 0x14, 0x22, 0x14, 0x22, 0x08}, 7, 0}, +// {0x6b, (uint8_t []){0x07}, 1, 0}, +// {0x7a, (uint8_t []){0x08, 0x13}, 2, 0}, +// {0x7b, (uint8_t []){0x08, 0x13}, 2, 0}, +// {0xd1, (uint8_t []){0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00, +// 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee, +// 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03, +// 0xff}, 52, 0}, +// {0xd2, (uint8_t []){0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00, +// 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee, +// 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03, +// 0xff}, 52, 0}, +// {0xd3, (uint8_t []){0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00, +// 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee, +// 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03, +// 0xff}, 52, 0}, +// {0xd4, (uint8_t []){0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00, +// 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee, +// 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03, +// 0xff}, 52, 0}, +// {0xd5, (uint8_t []){0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00, +// 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee, +// 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03, +// 0xff}, 52, 0}, +// {0xd6, (uint8_t []){0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00, +// 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee, +// 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03, +// 0xff}, 52, 0}, +// {0x11, (uint8_t []){0x00}, 0, 120}, +// {0x29, (uint8_t []){0x00}, 0, 20}, +// }; +static const gc9503_lcd_init_cmd_t vendor_specific_init_default[] = { + // {0x11, (uint8_t[]){}, 0, 20}, + + {0xF0, (uint8_t[]){0x55, 0xAA, 0x52, 0x08, 0x00}, 5, 0}, + {0xF6, (uint8_t[]){0x5A, 0x87}, 2, 0}, + {0xC1, (uint8_t[]){0x3F}, 1, 0}, + {0xCD, (uint8_t[]){0x25}, 1, 0}, + {0xC9, (uint8_t[]){0x10}, 1, 0}, + {0xF8, (uint8_t[]){0x8A}, 1, 0}, + {0xAC, (uint8_t[]){0x45}, 1, 0}, + {0xA7, (uint8_t[]){0x47}, 1, 0}, + {0xA0, (uint8_t[]){0x88}, 1, 0}, + {0x86, (uint8_t[]){0x99, 0xA3, 0xA3, 0x51}, 4, 0}, + {0xFA, (uint8_t[]){0x08, 0x08, 0x00, 0x04}, 4, 0}, + {0xA3, (uint8_t[]){0x6E}, 1, 0}, + {0xFD, (uint8_t[]){0x28, 0x3C, 0x00}, 3, 0}, + {0x9A, (uint8_t[]){0x4B}, 1, 0}, + {0x9B, (uint8_t[]){0x4B}, 1, 0}, + {0x82, (uint8_t[]){0x20, 0x20}, 2, 0}, + {0xB1, (uint8_t[]){0x10}, 1, 0}, + {0x7A, (uint8_t[]){0x0F, 0x13}, 2, 0}, + {0x7B, (uint8_t[]){0x0F, 0x13}, 2, 0}, + {0x6D, (uint8_t[]){0x1e, 0x1e, 0x04, 0x02, 0x0d, 0x1e, 0x12, 0x11, 0x14, 0x13, 0x05, 0x06, 0x1d, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1d, 0x06, 0x05, 0x0b, 0x0c, 0x09, 0x0a, 0x1e, 0x0d, 0x01, 0x03, 0x1e, 0x1e}, 32, 0}, + {0x64, (uint8_t[]){0x38, 0x08, 0x03, 0xc0, 0x03, 0x03, 0x38, 0x06, 0x03, 0xc2, 0x03, 0x03, 0x20, 0x6d, 0x20, 0x6d}, 16, 0}, + {0x65, (uint8_t[]){0x38, 0x04, 0x03, 0xc4, 0x03, 0x03, 0x38, 0x02, 0x03, 0xc6, 0x03, 0x03, 0x20, 0x6d, 0x20, 0x6d}, 16, 0}, + {0x66, (uint8_t[]){0x83, 0xcf, 0x03, 0xc8, 0x03, 0x03, 0x83, 0xd3, 0x03, 0xd2, 0x03, 0x03, 0x20, 0x6d, 0x20, 0x6d}, 16, 0}, + {0x60, (uint8_t[]){0x38, 0x0C, 0x20, 0x6D, 0x38, 0x0B, 0x20, 0x6D}, 8, 0}, + {0x61, (uint8_t[]){0x38, 0x0A, 0x20, 0x6D, 0x38, 0x09, 0x20, 0x6D}, 8, 0}, + {0x62, (uint8_t[]){0x38, 0x25, 0x20, 0x6D, 0x63, 0xC9, 0x20, 0x6D}, 8, 0}, + {0x69, (uint8_t[]){0x14, 0x22, 0x14, 0x22, 0x14, 0x22, 0x08}, 7, 0}, + {0x6B, (uint8_t[]){0x07}, 1, 0}, + {0xD1, (uint8_t[]){0x00, 0x00, 0x00, 0x70, 0x00, 0x8f, 0x00, 0xab, 0x00, 0xbf, 0x00, 0xdf, 0x00, 0xfa, 0x01, 0x2a, 0x01, 0x52, 0x01, 0x90, 0x01, 0xc1, 0x02, 0x0e, 0x02, 0x4f, 0x02, 0x51, 0x02, 0x8d, 0x02, 0xd3, 0x02, 0xff, 0x03, 0x3c, 0x03, 0x64, 0x03, 0xa1, 0x03, 0xf1, 0x03, 0xff, 0x03, 0xfF, 0x03, 0xff, 0x03, 0xFf, 0x03, 0xFF}, 52, 0}, + {0xD2, (uint8_t[]){0x00, 0x00, 0x00, 0x70, 0x00, 0x8f, 0x00, 0xab, 0x00, 0xbf, 0x00, 0xdf, 0x00, 0xfa, 0x01, 0x2a, 0x01, 0x52, 0x01, 0x90, 0x01, 0xc1, 0x02, 0x0e, 0x02, 0x4f, 0x02, 0x51, 0x02, 0x8d, 0x02, 0xd3, 0x02, 0xff, 0x03, 0x3c, 0x03, 0x64, 0x03, 0xa1, 0x03, 0xf1, 0x03, 0xff, 0x03, 0xfF, 0x03, 0xff, 0x03, 0xFf, 0x03, 0xFF}, 52, 0}, + {0xD3, (uint8_t[]){0x00, 0x00, 0x00, 0x70, 0x00, 0x8f, 0x00, 0xab, 0x00, 0xbf, 0x00, 0xdf, 0x00, 0xfa, 0x01, 0x2a, 0x01, 0x52, 0x01, 0x90, 0x01, 0xc1, 0x02, 0x0e, 0x02, 0x4f, 0x02, 0x51, 0x02, 0x8d, 0x02, 0xd3, 0x02, 0xff, 0x03, 0x3c, 0x03, 0x64, 0x03, 0xa1, 0x03, 0xf1, 0x03, 0xff, 0x03, 0xfF, 0x03, 0xff, 0x03, 0xFf, 0x03, 0xFF}, 52, 0}, + {0xD4, (uint8_t[]){0x00, 0x00, 0x00, 0x70, 0x00, 0x8f, 0x00, 0xab, 0x00, 0xbf, 0x00, 0xdf, 0x00, 0xfa, 0x01, 0x2a, 0x01, 0x52, 0x01, 0x90, 0x01, 0xc1, 0x02, 0x0e, 0x02, 0x4f, 0x02, 0x51, 0x02, 0x8d, 0x02, 0xd3, 0x02, 0xff, 0x03, 0x3c, 0x03, 0x64, 0x03, 0xa1, 0x03, 0xf1, 0x03, 0xff, 0x03, 0xfF, 0x03, 0xff, 0x03, 0xFf, 0x03, 0xFF}, 52, 0}, + {0xD5, (uint8_t[]){0x00, 0x00, 0x00, 0x70, 0x00, 0x8f, 0x00, 0xab, 0x00, 0xbf, 0x00, 0xdf, 0x00, 0xfa, 0x01, 0x2a, 0x01, 0x52, 0x01, 0x90, 0x01, 0xc1, 0x02, 0x0e, 0x02, 0x4f, 0x02, 0x51, 0x02, 0x8d, 0x02, 0xd3, 0x02, 0xff, 0x03, 0x3c, 0x03, 0x64, 0x03, 0xa1, 0x03, 0xf1, 0x03, 0xff, 0x03, 0xfF, 0x03, 0xff, 0x03, 0xFf, 0x03, 0xFF}, 52, 0}, + {0xD6, (uint8_t[]){0x00, 0x00, 0x00, 0x70, 0x00, 0x8f, 0x00, 0xab, 0x00, 0xbf, 0x00, 0xdf, 0x00, 0xfa, 0x01, 0x2a, 0x01, 0x52, 0x01, 0x90, 0x01, 0xc1, 0x02, 0x0e, 0x02, 0x4f, 0x02, 0x51, 0x02, 0x8d, 0x02, 0xd3, 0x02, 0xff, 0x03, 0x3c, 0x03, 0x64, 0x03, 0xa1, 0x03, 0xf1, 0x03, 0xff, 0x03, 0xfF, 0x03, 0xff, 0x03, 0xFf, 0x03, 0xFF}, 52, 0}, + // {0x3A, (uint8_t[]){0x55}, 1, 0}, + + {0x11, NULL, 0, 120}, // Delay 120ms + {0x29, NULL, 0, 120}}; + +// *INDENT-OFF* + +static esp_err_t panel_gc9503_send_init_cmds(gc9503_panel_t *gc9503) +{ + esp_lcd_panel_io_handle_t io = gc9503->io; + + ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, GC9503_CMD_MADCTL, (uint8_t[]){ + gc9503->madctl_val, + }, + 1), + TAG, "send command failed"); + ; + ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_COLMOD, (uint8_t[]){ + gc9503->colmod_val, + }, + 1), + TAG, "send command failed"); + ; + + // Vendor specific initialization, it can be different between manufacturers + // should consult the LCD supplier for initialization sequence code + const gc9503_lcd_init_cmd_t *init_cmds = NULL; + uint16_t init_cmds_size = 0; + if (gc9503->init_cmds) + { + init_cmds = gc9503->init_cmds; + init_cmds_size = gc9503->init_cmds_size; + } + else + { + init_cmds = vendor_specific_init_default; + init_cmds_size = sizeof(vendor_specific_init_default) / sizeof(gc9503_lcd_init_cmd_t); + } + + bool is_cmd_overwritten = false; + for (int i = 0; i < init_cmds_size; i++) + { + // Check if the command has been used or conflicts with the internal + switch (init_cmds[i].cmd) + { + case LCD_CMD_MADCTL: + is_cmd_overwritten = true; + gc9503->madctl_val = ((uint8_t *)init_cmds[i].data)[0]; + break; + case LCD_CMD_COLMOD: + is_cmd_overwritten = true; + gc9503->colmod_val = ((uint8_t *)init_cmds[i].data)[0]; + break; + default: + is_cmd_overwritten = false; + break; + } + + if (is_cmd_overwritten) + { + ESP_LOGW(TAG, "The %02Xh command has been used and will be overwritten by external initialization sequence", + init_cmds[i].cmd); + } + + ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, init_cmds[i].cmd, init_cmds[i].data, init_cmds[i].data_bytes), + TAG, "send command failed"); + vTaskDelay(pdMS_TO_TICKS(init_cmds[i].delay_ms)); + } + ESP_LOGD(TAG, "send init commands success"); + + return ESP_OK; +} + +static esp_err_t panel_gc9503_init(esp_lcd_panel_t *panel) +{ + gc9503_panel_t *gc9503 = (gc9503_panel_t *)panel->user_data; + + if (!gc9503->flags.auto_del_panel_io) + { + ESP_RETURN_ON_ERROR(panel_gc9503_send_init_cmds(gc9503), TAG, "send init commands failed"); + } + // Init RGB panel + ESP_RETURN_ON_ERROR(gc9503->init(panel), TAG, "init RGB panel failed"); + + return ESP_OK; +} + +static esp_err_t panel_gc9503_del(esp_lcd_panel_t *panel) +{ + gc9503_panel_t *gc9503 = (gc9503_panel_t *)panel->user_data; + + if (gc9503->reset_gpio_num >= 0) + { + gpio_reset_pin(gc9503->reset_gpio_num); + } + // Delete RGB panel + gc9503->del(panel); + free(gc9503); + ESP_LOGD(TAG, "del gc9503 panel @%p", gc9503); + return ESP_OK; +} + +static esp_err_t panel_gc9503_reset(esp_lcd_panel_t *panel) +{ + gc9503_panel_t *gc9503 = (gc9503_panel_t *)panel->user_data; + esp_lcd_panel_io_handle_t io = gc9503->io; + + // Perform hardware reset + if (gc9503->reset_gpio_num >= 0) + { + gpio_set_level(gc9503->reset_gpio_num, gc9503->flags.reset_level); + vTaskDelay(pdMS_TO_TICKS(10)); + gpio_set_level(gc9503->reset_gpio_num, !gc9503->flags.reset_level); + vTaskDelay(pdMS_TO_TICKS(120)); + } + else if (io) + { // Perform software reset + ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_SWRESET, NULL, 0), TAG, "send command failed"); + vTaskDelay(pdMS_TO_TICKS(120)); + } + // Reset RGB panel + ESP_RETURN_ON_ERROR(gc9503->reset(panel), TAG, "reset RGB panel failed"); + + return ESP_OK; +} + +static esp_err_t panel_gc9503_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y) +{ + gc9503_panel_t *gc9503 = (gc9503_panel_t *)panel->user_data; + esp_lcd_panel_io_handle_t io = gc9503->io; + + if (gc9503->flags.mirror_by_cmd) + { + ESP_RETURN_ON_FALSE(io, ESP_FAIL, TAG, "Panel IO is deleted, cannot send command"); + // Control mirror through LCD command + if (mirror_x) + { + gc9503->madctl_val |= GC9503_CMD_GS_BIT; + } + else + { + gc9503->madctl_val &= ~GC9503_CMD_GS_BIT; + } + if (mirror_y) + { + gc9503->madctl_val |= GC9503_CMD_SS_BIT; + } + else + { + gc9503->madctl_val &= ~GC9503_CMD_SS_BIT; + } + ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, GC9503_CMD_MADCTL, (uint8_t[]){ + gc9503->madctl_val, + }, + 1), + TAG, "send command failed"); + ; + } + else + { + // Control mirror through RGB panel + ESP_RETURN_ON_ERROR(gc9503->mirror(panel, mirror_x, mirror_y), TAG, "RGB panel mirror failed"); + } + return ESP_OK; +} + +static esp_err_t panel_gc9503_disp_on_off(esp_lcd_panel_t *panel, bool on_off) +{ + gc9503_panel_t *gc9503 = (gc9503_panel_t *)panel->user_data; + esp_lcd_panel_io_handle_t io = gc9503->io; + int command = 0; + + if (gc9503->flags.display_on_off_use_cmd) + { + ESP_RETURN_ON_FALSE(io, ESP_FAIL, TAG, "Panel IO is deleted, cannot send command"); + // Control display on/off through LCD command + if (on_off) + { + command = LCD_CMD_DISPON; + } + else + { + command = LCD_CMD_DISPOFF; + } + ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command, NULL, 0), TAG, "send command failed"); + } + else + { + // Control display on/off through display control signal + ESP_RETURN_ON_ERROR(gc9503->disp_on_off(panel, on_off), TAG, "RGB panel disp_on_off failed"); + } + return ESP_OK; +} diff --git a/main/boards/kevin-yuying-313lcd/esp_lcd_gc9503.h b/main/boards/kevin-yuying-313lcd/esp_lcd_gc9503.h new file mode 100644 index 00000000..1bc18d5f --- /dev/null +++ b/main/boards/kevin-yuying-313lcd/esp_lcd_gc9503.h @@ -0,0 +1,145 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +/** + * @file + * @brief ESP LCD: GC9503 + */ + +#pragma once + +#include + +#include "esp_lcd_panel_vendor.h" +#include "esp_lcd_panel_rgb.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief LCD panel initialization commands. + * + */ +typedef struct { + int cmd; /* +#include +#include +#include "esp_lcd_gc9503.h" +#include +#include +#include + +#define TAG "Yuying_313lcd" + +LV_FONT_DECLARE(font_puhui_30_4); +LV_FONT_DECLARE(font_awesome_30_4); + +class Yuying_313lcd : public WifiBoard { +private: + i2c_master_bus_handle_t codec_i2c_bus_; + Button boot_button_; + LcdDisplay* display_; + + + void InitializeRGB_GC9503V_Display() { + ESP_LOGI(TAG, "Init GC9503V"); + + esp_lcd_panel_io_handle_t panel_io = nullptr; + esp_lcd_panel_handle_t panel = nullptr; + + ESP_LOGI(TAG, "Install 3-wire SPI panel IO"); + spi_line_config_t line_config = { + .cs_io_type = IO_TYPE_GPIO, + .cs_gpio_num = GC9503V_LCD_IO_SPI_CS_1, + .scl_io_type = IO_TYPE_GPIO, + .scl_gpio_num = GC9503V_LCD_IO_SPI_SCL_1, + .sda_io_type = IO_TYPE_GPIO, + .sda_gpio_num = GC9503V_LCD_IO_SPI_SDO_1, + .io_expander = NULL, + }; + esp_lcd_panel_io_3wire_spi_config_t io_config = GC9503_PANEL_IO_3WIRE_SPI_CONFIG(line_config, 0); + (esp_lcd_new_panel_io_3wire_spi(&io_config, &panel_io)); + + ESP_LOGI(TAG, "Install RGB LCD panel driver"); + esp_lcd_panel_handle_t panel_handle = NULL; + esp_lcd_rgb_panel_config_t rgb_config = { + .clk_src = LCD_CLK_SRC_PLL160M, + .timings = GC9503_376_960_PANEL_60HZ_RGB_TIMING(), + .data_width = 16, // RGB565 in parallel mode, thus 16bit in width + .bits_per_pixel = 16, + .num_fbs = GC9503V_LCD_RGB_BUFFER_NUMS, + .bounce_buffer_size_px = GC9503V_LCD_H_RES * GC9503V_LCD_RGB_BOUNCE_BUFFER_HEIGHT, + .dma_burst_size = 64, + .hsync_gpio_num = GC9503V_PIN_NUM_HSYNC, + .vsync_gpio_num = GC9503V_PIN_NUM_VSYNC, + .de_gpio_num = GC9503V_PIN_NUM_DE, + .pclk_gpio_num = GC9503V_PIN_NUM_PCLK, + .disp_gpio_num = GC9503V_PIN_NUM_DISP_EN, + .data_gpio_nums = { + GC9503V_PIN_NUM_DATA0, + GC9503V_PIN_NUM_DATA1, + GC9503V_PIN_NUM_DATA2, + GC9503V_PIN_NUM_DATA3, + GC9503V_PIN_NUM_DATA4, + GC9503V_PIN_NUM_DATA5, + GC9503V_PIN_NUM_DATA6, + GC9503V_PIN_NUM_DATA7, + GC9503V_PIN_NUM_DATA8, + GC9503V_PIN_NUM_DATA9, + GC9503V_PIN_NUM_DATA10, + GC9503V_PIN_NUM_DATA11, + GC9503V_PIN_NUM_DATA12, + GC9503V_PIN_NUM_DATA13, + GC9503V_PIN_NUM_DATA14, + GC9503V_PIN_NUM_DATA15, + }, + .flags= { + .fb_in_psram = true, // allocate frame buffer in PSRAM + } + }; + + ESP_LOGI(TAG, "Initialize RGB LCD panel"); + + gc9503_vendor_config_t vendor_config = { + .rgb_config = &rgb_config, + .flags = { + .mirror_by_cmd = 0, + .auto_del_panel_io = 1, + }, + }; + const esp_lcd_panel_dev_config_t panel_config = { + .reset_gpio_num = -1, + .rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB, + .bits_per_pixel = 16, + .vendor_config = &vendor_config, + }; + (esp_lcd_new_panel_gc9503(panel_io, &panel_config, &panel_handle)); + (esp_lcd_panel_reset(panel_handle)); + (esp_lcd_panel_init(panel_handle)); + + display_ = new RgbLcdDisplay(panel_io, panel_handle, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, + DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY, + { + .text_font = &font_puhui_30_4, + .icon_font = &font_awesome_30_4, + .emoji_font = font_emoji_64_init(), + }); + } + void InitializeCodecI2c() { + // Initialize I2C peripheral + i2c_master_bus_config_t i2c_bus_cfg = { + .i2c_port = I2C_NUM_0, + .sda_io_num = AUDIO_CODEC_I2C_SDA_PIN, + .scl_io_num = AUDIO_CODEC_I2C_SCL_PIN, + .clk_source = I2C_CLK_SRC_DEFAULT, + .glitch_ignore_cnt = 7, + .intr_priority = 0, + .trans_queue_depth = 0, + .flags = { + .enable_internal_pullup = 1, + }, + }; + ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_cfg, &codec_i2c_bus_)); + } + + void InitializeButtons() { + boot_button_.OnClick([this]() { + auto& app = Application::GetInstance(); + if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) { + ResetWifiConfiguration(); + } + }); + boot_button_.OnPressDown([this]() { + Application::GetInstance().StartListening(); + }); + boot_button_.OnPressUp([this]() { + Application::GetInstance().StopListening(); + }); + } + + // 物联网初始化,添加对 AI 可见设备 + void InitializeIot() { + auto& thing_manager = iot::ThingManager::GetInstance(); + thing_manager.AddThing(iot::CreateThing("Speaker")); + thing_manager.AddThing(iot::CreateThing("Backlight")); + } + +public: + Yuying_313lcd() : boot_button_(BOOT_BUTTON_GPIO) { + InitializeCodecI2c(); + InitializeButtons(); + InitializeIot(); + InitializeRGB_GC9503V_Display(); + } + + virtual AudioCodec* GetAudioCodec() override { + static Es8311AudioCodec audio_codec(codec_i2c_bus_, I2C_NUM_0, AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE, + AUDIO_I2S_GPIO_MCLK, AUDIO_I2S_GPIO_BCLK, AUDIO_I2S_GPIO_WS, AUDIO_I2S_GPIO_DOUT, AUDIO_I2S_GPIO_DIN, + AUDIO_CODEC_PA_PIN, AUDIO_CODEC_ES8311_ADDR); + return &audio_codec; + } + virtual Display* GetDisplay() override { + return display_; + } + + // virtual Display* GetDisplayType() override { + // return display_; + // } +}; + +DECLARE_BOARD(Yuying_313lcd); diff --git a/main/boards/kevin-yuying-313lcd/pin_config.h b/main/boards/kevin-yuying-313lcd/pin_config.h new file mode 100644 index 00000000..0bcd0594 --- /dev/null +++ b/main/boards/kevin-yuying-313lcd/pin_config.h @@ -0,0 +1,47 @@ + +#pragma once +#define GC9503V_LCD_H_RES 376 +#define GC9503V_LCD_V_RES 960 + + +#define GC9503V_LCD_LVGL_DIRECT_MODE (1) +#define GC9503V_LCD_LVGL_AVOID_TEAR (1) +#define GC9503V_LCD_RGB_BOUNCE_BUFFER_MODE (1) +#define GC9503V_LCD_DRAW_BUFF_DOUBLE (0) +#define GC9503V_LCD_DRAW_BUFF_HEIGHT (100) +#define GC9503V_LCD_RGB_BUFFER_NUMS (2) +#define GC9503V_LCD_RGB_BOUNCE_BUFFER_HEIGHT (10) + +#define GC9503V_LCD_PIXEL_CLOCK_HZ (16 * 1000 * 1000) +#define GC9503V_LCD_BK_LIGHT_ON_LEVEL 1 +#define GC9503V_LCD_BK_LIGHT_OFF_LEVEL !GC9503V_LCD_BK_LIGHT_ON_LEVEL +#define GC9503V_PIN_NUM_BK_LIGHT GPIO_NUM_4 +#define GC9503V_PIN_NUM_HSYNC 6 +#define GC9503V_PIN_NUM_VSYNC 5 +#define GC9503V_PIN_NUM_DE 15 +#define GC9503V_PIN_NUM_PCLK 7 + +#define GC9503V_PIN_NUM_DATA0 47 // B0 +#define GC9503V_PIN_NUM_DATA1 21 // B1 +#define GC9503V_PIN_NUM_DATA2 14 // B2 +#define GC9503V_PIN_NUM_DATA3 13 // B3 +#define GC9503V_PIN_NUM_DATA4 12 // B4 + +#define GC9503V_PIN_NUM_DATA5 11 // G0 +#define GC9503V_PIN_NUM_DATA6 10 // G1 +#define GC9503V_PIN_NUM_DATA7 9 // G2 +#define GC9503V_PIN_NUM_DATA8 46 // G3 +#define GC9503V_PIN_NUM_DATA9 3 // G4 +#define GC9503V_PIN_NUM_DATA10 20 // G5 + +#define GC9503V_PIN_NUM_DATA11 19 // R0 +#define GC9503V_PIN_NUM_DATA12 8 // R1 +#define GC9503V_PIN_NUM_DATA13 18 // R2 +#define GC9503V_PIN_NUM_DATA14 17 // R3 +#define GC9503V_PIN_NUM_DATA15 16 // R4 + +#define GC9503V_PIN_NUM_DISP_EN -1 + +#define GC9503V_LCD_IO_SPI_CS_1 (GPIO_NUM_48) +#define GC9503V_LCD_IO_SPI_SCL_1 (GPIO_NUM_17) +#define GC9503V_LCD_IO_SPI_SDO_1 (GPIO_NUM_16) \ No newline at end of file diff --git a/main/boards/lichuang-c3-dev/lichuang_c3_dev_board.cc b/main/boards/lichuang-c3-dev/lichuang_c3_dev_board.cc index 930ac101..5305b5bb 100644 --- a/main/boards/lichuang-c3-dev/lichuang_c3_dev_board.cc +++ b/main/boards/lichuang-c3-dev/lichuang_c3_dev_board.cc @@ -91,7 +91,7 @@ private: esp_lcd_panel_invert_color(panel, true); esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY); esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y); - display_ = new LcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new SpiLcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, 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, diff --git a/main/boards/lichuang-dev/lichuang_dev_board.cc b/main/boards/lichuang-dev/lichuang_dev_board.cc index 7b6b090c..9cd0949a 100644 --- a/main/boards/lichuang-dev/lichuang_dev_board.cc +++ b/main/boards/lichuang-dev/lichuang_dev_board.cc @@ -117,7 +117,7 @@ private: esp_lcd_panel_invert_color(panel, true); esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY); esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y); - display_ = new LcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new SpiLcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, 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, diff --git a/main/boards/lilygo-t-circle-s3/lilygo-t-circle-s3.cc b/main/boards/lilygo-t-circle-s3/lilygo-t-circle-s3.cc index 6495811d..c716837f 100644 --- a/main/boards/lilygo-t-circle-s3/lilygo-t-circle-s3.cc +++ b/main/boards/lilygo-t-circle-s3/lilygo-t-circle-s3.cc @@ -169,7 +169,7 @@ private: esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY); esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y); - display_ = new LcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new SpiLcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY, { diff --git a/main/boards/m5stack-core-s3/m5stack_core_s3.cc b/main/boards/m5stack-core-s3/m5stack_core_s3.cc index 263eac40..86bc6cd3 100644 --- a/main/boards/m5stack-core-s3/m5stack_core_s3.cc +++ b/main/boards/m5stack-core-s3/m5stack_core_s3.cc @@ -262,7 +262,7 @@ private: esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY); esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y); - display_ = new LcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new SpiLcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, 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, diff --git a/main/boards/movecall-moji-esp32s3/movecall_moji_esp32s3.cc b/main/boards/movecall-moji-esp32s3/movecall_moji_esp32s3.cc index 143f1562..fe543836 100644 --- a/main/boards/movecall-moji-esp32s3/movecall_moji_esp32s3.cc +++ b/main/boards/movecall-moji-esp32s3/movecall_moji_esp32s3.cc @@ -109,7 +109,7 @@ private: ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, true, false)); ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true)); - display_ = new LcdDisplay(io_handle, panel_handle, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new SpiLcdDisplay(io_handle, panel_handle, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, 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, diff --git a/main/boards/taiji-pi-s3/taiji_pi_s3.cc b/main/boards/taiji-pi-s3/taiji_pi_s3.cc index 95686e47..b202123d 100644 --- a/main/boards/taiji-pi-s3/taiji_pi_s3.cc +++ b/main/boards/taiji-pi-s3/taiji_pi_s3.cc @@ -185,7 +185,7 @@ private: esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY); esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y); - display_ = new LcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new SpiLcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, 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, diff --git a/main/boards/xingzhi-cube-1.54tft-ml307/xingzhi-cube-1.54tft-ml307.cc b/main/boards/xingzhi-cube-1.54tft-ml307/xingzhi-cube-1.54tft-ml307.cc index d57b87d9..56a63ffe 100644 --- a/main/boards/xingzhi-cube-1.54tft-ml307/xingzhi-cube-1.54tft-ml307.cc +++ b/main/boards/xingzhi-cube-1.54tft-ml307/xingzhi-cube-1.54tft-ml307.cc @@ -99,7 +99,7 @@ private: ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y)); ESP_ERROR_CHECK(esp_lcd_panel_invert_color(panel, true)); - display_ = new LcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new SpiLcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY, { .text_font = &font_puhui_16_4, diff --git a/main/boards/xingzhi-cube-1.54tft-wifi/xingzhi-cube-1.54tft-wifi.cc b/main/boards/xingzhi-cube-1.54tft-wifi/xingzhi-cube-1.54tft-wifi.cc index d7b28134..72f688f9 100644 --- a/main/boards/xingzhi-cube-1.54tft-wifi/xingzhi-cube-1.54tft-wifi.cc +++ b/main/boards/xingzhi-cube-1.54tft-wifi/xingzhi-cube-1.54tft-wifi.cc @@ -103,7 +103,7 @@ private: ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y)); ESP_ERROR_CHECK(esp_lcd_panel_invert_color(panel, true)); - display_ = new LcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new SpiLcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY, { .text_font = &font_puhui_16_4, diff --git a/main/display/lcd_display.cc b/main/display/lcd_display.cc index 3e8ead36..455e0ff3 100644 --- a/main/display/lcd_display.cc +++ b/main/display/lcd_display.cc @@ -16,12 +16,11 @@ LV_FONT_DECLARE(font_awesome_30_4); -LcdDisplay::LcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, +SpiLcdDisplay::SpiLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, gpio_num_t backlight_pin, bool backlight_output_invert, int width, int height, int offset_x, int offset_y, bool mirror_x, bool mirror_y, bool swap_xy, DisplayFonts fonts) - : panel_io_(panel_io), panel_(panel), backlight_pin_(backlight_pin), backlight_output_invert_(backlight_output_invert), - fonts_(fonts) { + : LcdDisplay(panel_io, panel, backlight_pin, backlight_output_invert, fonts) { width_ = width; height_ = height; @@ -98,6 +97,86 @@ LcdDisplay::LcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_ SetBacklight(brightness_); } +// RGB LCD实现 +RgbLcdDisplay::RgbLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, + gpio_num_t backlight_pin, bool backlight_output_invert, + int width, int height, int offset_x, int offset_y, + bool mirror_x, bool mirror_y, bool swap_xy, + DisplayFonts fonts) + : LcdDisplay(panel_io, panel, backlight_pin, backlight_output_invert, fonts) { + width_ = width; + height_ = height; + + // 创建背光渐变定时器 + const esp_timer_create_args_t timer_args = { + .callback = [](void* arg) { + LcdDisplay* display = static_cast(arg); + display->OnBacklightTimer(); + }, + .arg = this, + .dispatch_method = ESP_TIMER_TASK, + .name = "backlight_timer", + .skip_unhandled_events = true, + }; + ESP_ERROR_CHECK(esp_timer_create(&timer_args, &backlight_timer_)); + InitializeBacklight(backlight_pin); + + // draw white + std::vector buffer(width_, 0xFFFF); + for (int y = 0; y < height_; y++) { + esp_lcd_panel_draw_bitmap(panel_, 0, y, width_, y + 1, buffer.data()); + } + + ESP_LOGI(TAG, "Initialize LVGL library"); + lv_init(); + + ESP_LOGI(TAG, "Initialize LVGL port"); + lvgl_port_cfg_t port_cfg = ESP_LVGL_PORT_INIT_CONFIG(); + lvgl_port_init(&port_cfg); + + ESP_LOGI(TAG, "Adding LCD screen"); + const lvgl_port_display_cfg_t display_cfg = { + .io_handle = panel_io_, + .panel_handle = panel_, + .buffer_size = static_cast(width_ * 10), + .double_buffer = true, + .hres = static_cast(width_), + .vres = static_cast(height_), + .rotation = { + .swap_xy = swap_xy, + .mirror_x = mirror_x, + .mirror_y = mirror_y, + }, + .flags = { + .buff_dma = 1, + .swap_bytes = 0, + .full_refresh = 1, + .direct_mode = 1, + }, + }; + + const lvgl_port_display_rgb_cfg_t rgb_cfg = { + .flags = { + .bb_mode = true, + .avoid_tearing = true, + } + }; + + display_ = lvgl_port_add_disp_rgb(&display_cfg, &rgb_cfg); + if (display_ == nullptr) { + ESP_LOGE(TAG, "Failed to add RGB display"); + return; + } + + if (offset_x != 0 || offset_y != 0) { + lv_display_set_offset(display_, offset_x, offset_y); + } + + SetupUI(); + + SetBacklight(brightness_); +} + LcdDisplay::~LcdDisplay() { if (backlight_timer_ != nullptr) { esp_timer_stop(backlight_timer_); diff --git a/main/display/lcd_display.h b/main/display/lcd_display.h index 04f87245..4256c229 100644 --- a/main/display/lcd_display.h +++ b/main/display/lcd_display.h @@ -31,23 +31,76 @@ protected: esp_timer_handle_t backlight_timer_ = nullptr; uint8_t current_brightness_ = 0; - void OnBacklightTimer(); void InitializeBacklight(gpio_num_t backlight_pin); virtual void SetupUI(); virtual bool Lock(int timeout_ms = 0) override; virtual void Unlock() override; -public: +protected: + // 添加protected构造函数 LcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, - gpio_num_t backlight_pin, bool backlight_output_invert, - int width, int height, int offset_x, int offset_y, bool mirror_x, bool mirror_y, bool swap_xy, - DisplayFonts fonts); + gpio_num_t backlight_pin, bool backlight_output_invert, + DisplayFonts fonts) + : panel_io_(panel_io), panel_(panel), + backlight_pin_(backlight_pin), backlight_output_invert_(backlight_output_invert), + fonts_(fonts) {} + +public: ~LcdDisplay(); - + virtual void OnBacklightTimer(); virtual void SetEmotion(const char* emotion) override; virtual void SetIcon(const char* icon) override; virtual void SetBacklight(uint8_t brightness) override; }; +// RGB LCD显示器 +class RgbLcdDisplay : public LcdDisplay { +public: + RgbLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, + gpio_num_t backlight_pin, bool backlight_output_invert, + int width, int height, int offset_x, int offset_y, + bool mirror_x, bool mirror_y, bool swap_xy, + DisplayFonts fonts); +}; + +// MIPI LCD显示器 +class MipiLcdDisplay : public LcdDisplay { +public: + MipiLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, + gpio_num_t backlight_pin, bool backlight_output_invert, + int width, int height, int offset_x, int offset_y, + bool mirror_x, bool mirror_y, bool swap_xy, + DisplayFonts fonts); +}; + +// // SPI LCD显示器 +class SpiLcdDisplay : public LcdDisplay { +public: + SpiLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, + gpio_num_t backlight_pin, bool backlight_output_invert, + int width, int height, int offset_x, int offset_y, + bool mirror_x, bool mirror_y, bool swap_xy, + DisplayFonts fonts); +}; + +// QSPI LCD显示器 +class QspiLcdDisplay : public LcdDisplay { +public: + QspiLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, + gpio_num_t backlight_pin, bool backlight_output_invert, + int width, int height, int offset_x, int offset_y, + bool mirror_x, bool mirror_y, bool swap_xy, + DisplayFonts fonts); +}; + +// MCU8080 LCD显示器 +class Mcu8080LcdDisplay : public LcdDisplay { +public: + Mcu8080LcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, + gpio_num_t backlight_pin, bool backlight_output_invert, + int width, int height, int offset_x, int offset_y, + bool mirror_x, bool mirror_y, bool swap_xy, + DisplayFonts fonts); +}; #endif // LCD_DISPLAY_H diff --git a/main/idf_component.yml b/main/idf_component.yml index 0f824d82..a65c2623 100644 --- a/main/idf_component.yml +++ b/main/idf_component.yml @@ -6,6 +6,7 @@ dependencies: espressif/esp_lcd_st77916: "^1.0.1" espressif/esp_lcd_spd2010: "==1.0.2" espressif/esp_io_expander_tca9554: "==2.0.0" + espressif/esp_lcd_panel_io_additions: "^1.0.1" 78/esp_lcd_nv3023: "~1.0.0" 78/esp-wifi-connect: "~2.3.0" 78/esp-opus-encoder: "~2.1.0"