From 7c2a64cc86119f20af7a7813a94d2aea005cd226 Mon Sep 17 00:00:00 2001 From: ZhouKe <9482145@qq.com> Date: Sat, 1 Mar 2025 02:38:11 +0800 Subject: [PATCH] add support for GC9A01_240X240 ST7735 _128X128 ST7789_240X240_7PIN (#244) * add GC9A01 240*240 add ST7735 128*128 add ST7789 240*240 7pin * fix config for ILI9341 --------- Co-authored-by: zk <982145@qq.com> --- main/Kconfig.projbuild | 6 ++ .../compact_wifi_board_lcd.cc | 55 +++++++++++++- main/boards/bread-compact-wifi-lcd/config.h | 76 +++++++++++++++++-- 3 files changed, 128 insertions(+), 9 deletions(-) diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index c7a03400..0b83dfd2 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -158,16 +158,22 @@ choice DISPLAY_LCD_TYPE bool "ST7789, 分辨率240*280" config LCD_ST7789_240X240 bool "ST7789, 分辨率240*240" + config LCD_ST7789_240X240_7PIN + bool "ST7789, 分辨率240*240, 7PIN" config LCD_ST7789_240X135 bool "ST7789, 分辨率240*135" config LCD_ST7735_128X160 bool "ST7735, 分辨率128*160" + config LCD_ST7735_128X128 + bool "ST7735, 分辨率128*128" config LCD_ST7796_320X480 bool "ST7796, 分辨率320*480" config LCD_ILI9341_240X320 bool "ILI9341, 分辨率240*320" config LCD_ILI9341_240X320_NO_IPS bool "ILI9341, 分辨率240*320, 非IPS" + config LCD_GC9A01_240X240 + bool "GC9A01, 分辨率240*240, 圆屏" config LCD_CUSTOM bool "自定义屏幕参数" endchoice 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 01224b4b..e2830d00 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 @@ -12,11 +12,50 @@ #include #include #include +#include +#include #include -#if defined(LCD_ILI9341_240X320) || defined(LCD_ILI9341_240X320_NO_IPS) +#if defined(LCD_TYPE_ILI9341_SERIAL) #include "esp_lcd_ili9341.h" #endif + +#if defined(LCD_TYPE_GC9A01_SERIAL) +#include "esp_lcd_gc9a01.h" +static const gc9a01_lcd_init_cmd_t gc9107_lcd_init_cmds[] = { + // {cmd, { data }, data_size, delay_ms} + {0xfe, (uint8_t[]){0x00}, 0, 0}, + {0xef, (uint8_t[]){0x00}, 0, 0}, + {0xb0, (uint8_t[]){0xc0}, 1, 0}, + {0xb1, (uint8_t[]){0x80}, 1, 0}, + {0xb2, (uint8_t[]){0x27}, 1, 0}, + {0xb3, (uint8_t[]){0x13}, 1, 0}, + {0xb6, (uint8_t[]){0x19}, 1, 0}, + {0xb7, (uint8_t[]){0x05}, 1, 0}, + {0xac, (uint8_t[]){0xc8}, 1, 0}, + {0xab, (uint8_t[]){0x0f}, 1, 0}, + {0x3a, (uint8_t[]){0x05}, 1, 0}, + {0xb4, (uint8_t[]){0x04}, 1, 0}, + {0xa8, (uint8_t[]){0x08}, 1, 0}, + {0xb8, (uint8_t[]){0x08}, 1, 0}, + {0xea, (uint8_t[]){0x02}, 1, 0}, + {0xe8, (uint8_t[]){0x2A}, 1, 0}, + {0xe9, (uint8_t[]){0x47}, 1, 0}, + {0xe7, (uint8_t[]){0x5f}, 1, 0}, + {0xc6, (uint8_t[]){0x21}, 1, 0}, + {0xc7, (uint8_t[]){0x15}, 1, 0}, + {0xf0, + (uint8_t[]){0x1D, 0x38, 0x09, 0x4D, 0x92, 0x2F, 0x35, 0x52, 0x1E, 0x0C, + 0x04, 0x12, 0x14, 0x1f}, + 14, 0}, + {0xf1, + (uint8_t[]){0x16, 0x40, 0x1C, 0x54, 0xA9, 0x2D, 0x2E, 0x56, 0x10, 0x0D, + 0x0C, 0x1A, 0x14, 0x1E}, + 14, 0}, + {0xf4, (uint8_t[]){0x00, 0x00, 0xFF}, 3, 0}, + {0xba, (uint8_t[]){0xFF, 0xFF}, 2, 0}, +}; +#endif #define TAG "CompactWifiBoardLCD" @@ -48,7 +87,7 @@ private: esp_lcd_panel_io_spi_config_t io_config = {}; io_config.cs_gpio_num = DISPLAY_CS_PIN; io_config.dc_gpio_num = DISPLAY_DC_PIN; - io_config.spi_mode = 0; + io_config.spi_mode = DISPLAY_SPI_MODE; io_config.pclk_hz = 40 * 1000 * 1000; io_config.trans_queue_depth = 10; io_config.lcd_cmd_bits = 8; @@ -61,8 +100,14 @@ private: panel_config.reset_gpio_num = DISPLAY_RST_PIN; panel_config.rgb_ele_order = DISPLAY_RGB_ORDER; panel_config.bits_per_pixel = 16; -#if defined(LCD_ILI9341_240X320) || defined(LCD_ILI9341_240X320_NO_IPS) +#if defined(LCD_TYPE_ILI9341_SERIAL) ESP_ERROR_CHECK(esp_lcd_new_panel_ili9341(panel_io, &panel_config, &panel)); +#elif defined(LCD_TYPE_GC9A01_SERIAL) + ESP_ERROR_CHECK(esp_lcd_new_panel_gc9a01(panel_io, &panel_config, &panel)); + gc9a01_vendor_config_t gc9107_vendor_config = { + .init_cmds = gc9107_lcd_init_cmds, + .init_cmds_size = sizeof(gc9107_lcd_init_cmds) / sizeof(gc9a01_lcd_init_cmd_t), + }; #else ESP_ERROR_CHECK(esp_lcd_new_panel_st7789(panel_io, &panel_config, &panel)); #endif @@ -74,6 +119,9 @@ 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); +#ifdef LCD_TYPE_GC9A01_SERIAL + panel_config.vendor_config = &gc9107_vendor_config; +#endif 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, { @@ -99,6 +147,7 @@ private: void InitializeIot() { auto& thing_manager = iot::ThingManager::GetInstance(); thing_manager.AddThing(iot::CreateThing("Speaker")); + thing_manager.AddThing(iot::CreateThing("Backlight")); } public: diff --git a/main/boards/bread-compact-wifi-lcd/config.h b/main/boards/bread-compact-wifi-lcd/config.h index 4591ac70..63c609e9 100644 --- a/main/boards/bread-compact-wifi-lcd/config.h +++ b/main/boards/bread-compact-wifi-lcd/config.h @@ -43,9 +43,8 @@ #define DISPLAY_CS_PIN GPIO_NUM_41 - - #ifdef CONFIG_LCD_ST7789_240X320 +#define LCD_TYPE_ST7789_SERIAL #define DISPLAY_WIDTH 240 #define DISPLAY_HEIGHT 320 #define DISPLAY_MIRROR_X false @@ -59,6 +58,7 @@ #endif #ifdef CONFIG_LCD_ST7789_240X320_NO_IPS +#define LCD_TYPE_ST7789_SERIAL #define DISPLAY_WIDTH 240 #define DISPLAY_HEIGHT 320 #define DISPLAY_MIRROR_X false @@ -69,9 +69,11 @@ #define DISPLAY_OFFSET_X 0 #define DISPLAY_OFFSET_Y 0 #define DISPLAY_BACKLIGHT_OUTPUT_INVERT false +#define DISPLAY_SPI_MODE 0 #endif #ifdef CONFIG_LCD_ST7789_170X320 +#define LCD_TYPE_ST7789_SERIAL #define DISPLAY_WIDTH 170 #define DISPLAY_HEIGHT 320 #define DISPLAY_MIRROR_X false @@ -82,9 +84,11 @@ #define DISPLAY_OFFSET_X 35 #define DISPLAY_OFFSET_Y 0 #define DISPLAY_BACKLIGHT_OUTPUT_INVERT false +#define DISPLAY_SPI_MODE 0 #endif #ifdef CONFIG_LCD_ST7789_172X320 +#define LCD_TYPE_ST7789_SERIAL #define DISPLAY_WIDTH 172 #define DISPLAY_HEIGHT 320 #define DISPLAY_MIRROR_X false @@ -95,9 +99,11 @@ #define DISPLAY_OFFSET_X 34 #define DISPLAY_OFFSET_Y 0 #define DISPLAY_BACKLIGHT_OUTPUT_INVERT false +#define DISPLAY_SPI_MODE 0 #endif #ifdef CONFIG_LCD_ST7789_240X280 +#define LCD_TYPE_ST7789_SERIAL #define DISPLAY_WIDTH 240 #define DISPLAY_HEIGHT 280 #define DISPLAY_MIRROR_X false @@ -108,9 +114,11 @@ #define DISPLAY_OFFSET_X 0 #define DISPLAY_OFFSET_Y 20 #define DISPLAY_BACKLIGHT_OUTPUT_INVERT false +#define DISPLAY_SPI_MODE 0 #endif #ifdef CONFIG_LCD_ST7789_240X240 +#define LCD_TYPE_ST7789_SERIAL #define DISPLAY_WIDTH 240 #define DISPLAY_HEIGHT 240 #define DISPLAY_MIRROR_X false @@ -121,9 +129,26 @@ #define DISPLAY_OFFSET_X 0 #define DISPLAY_OFFSET_Y 0 #define DISPLAY_BACKLIGHT_OUTPUT_INVERT false +#define DISPLAY_SPI_MODE 0 +#endif + +#ifdef CONFIG_LCD_ST7789_240X240_7PIN +#define LCD_TYPE_ST7789_SERIAL +#define DISPLAY_WIDTH 240 +#define DISPLAY_HEIGHT 240 +#define DISPLAY_MIRROR_X false +#define DISPLAY_MIRROR_Y false +#define DISPLAY_SWAP_XY false +#define DISPLAY_INVERT_COLOR true +#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_RGB +#define DISPLAY_OFFSET_X 0 +#define DISPLAY_OFFSET_Y 0 +#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false +#define DISPLAY_SPI_MODE 2 #endif #ifdef CONFIG_LCD_ST7789_240X135 +#define LCD_TYPE_ST7789_SERIAL #define DISPLAY_WIDTH 240 #define DISPLAY_HEIGHT 135 #define DISPLAY_MIRROR_X true @@ -134,9 +159,11 @@ #define DISPLAY_OFFSET_X 40 #define DISPLAY_OFFSET_Y 53 #define DISPLAY_BACKLIGHT_OUTPUT_INVERT false +#define DISPLAY_SPI_MODE 0 #endif #ifdef CONFIG_LCD_ST7735_128X160 +#define LCD_TYPE_ST7789_SERIAL #define DISPLAY_WIDTH 128 #define DISPLAY_HEIGHT 160 #define DISPLAY_MIRROR_X true @@ -149,7 +176,23 @@ #define DISPLAY_BACKLIGHT_OUTPUT_INVERT false #endif +#ifdef CONFIG_LCD_ST7735_128X128 +#define LCD_TYPE_ST7789_SERIAL +#define DISPLAY_WIDTH 128 +#define DISPLAY_HEIGHT 128 +#define DISPLAY_MIRROR_X true +#define DISPLAY_MIRROR_Y true +#define DISPLAY_SWAP_XY false +#define DISPLAY_INVERT_COLOR false +#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_BGR +#define DISPLAY_OFFSET_X 0 +#define DISPLAY_OFFSET_Y 32 +#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false +#define DISPLAY_SPI_MODE 0 +#endif + #ifdef CONFIG_LCD_ST7796_320X480 +#define LCD_TYPE_ST7789_SERIAL #define DISPLAY_WIDTH 320 #define DISPLAY_HEIGHT 480 #define DISPLAY_MIRROR_X false @@ -160,32 +203,52 @@ #define DISPLAY_OFFSET_X 0 #define DISPLAY_OFFSET_Y 0 #define DISPLAY_BACKLIGHT_OUTPUT_INVERT false +#define DISPLAY_SPI_MODE 0 #endif #ifdef CONFIG_LCD_ILI9341_240X320 +#define LCD_TYPE_ILI9341_SERIAL #define DISPLAY_WIDTH 240 #define DISPLAY_HEIGHT 320 -#define DISPLAY_MIRROR_X false +#define DISPLAY_MIRROR_X true #define DISPLAY_MIRROR_Y false #define DISPLAY_SWAP_XY false #define DISPLAY_INVERT_COLOR true -#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_RGB +#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_BGR #define DISPLAY_OFFSET_X 0 #define DISPLAY_OFFSET_Y 0 #define DISPLAY_BACKLIGHT_OUTPUT_INVERT false +#define DISPLAY_SPI_MODE 0 #endif #ifdef CONFIG_LCD_ILI9341_240X320_NO_IPS +#define LCD_TYPE_ILI9341_SERIAL #define DISPLAY_WIDTH 240 #define DISPLAY_HEIGHT 320 -#define DISPLAY_MIRROR_X false +#define DISPLAY_MIRROR_X true #define DISPLAY_MIRROR_Y false #define DISPLAY_SWAP_XY false #define DISPLAY_INVERT_COLOR false -#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_RGB +#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_BGR #define DISPLAY_OFFSET_X 0 #define DISPLAY_OFFSET_Y 0 #define DISPLAY_BACKLIGHT_OUTPUT_INVERT false +#define DISPLAY_SPI_MODE 0 +#endif + +#ifdef CONFIG_LCD_GC9A01_240X240 +#define LCD_TYPE_GC9A01_SERIAL +#define DISPLAY_WIDTH 240 +#define DISPLAY_HEIGHT 240 +#define DISPLAY_MIRROR_X true +#define DISPLAY_MIRROR_Y false +#define DISPLAY_SWAP_XY false +#define DISPLAY_INVERT_COLOR true +#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_BGR +#define DISPLAY_OFFSET_X 0 +#define DISPLAY_OFFSET_Y 0 +#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false +#define DISPLAY_SPI_MODE 0 #endif #ifdef CONFIG_LCD_CUSTOM @@ -199,6 +262,7 @@ #define DISPLAY_OFFSET_X 0 #define DISPLAY_OFFSET_Y 0 #define DISPLAY_BACKLIGHT_OUTPUT_INVERT false +#define DISPLAY_SPI_MODE 0 #endif #endif // _BOARD_CONFIG_H_