From f002a1185b27cb614ffab5a6429f6e7480095f70 Mon Sep 17 00:00:00 2001 From: flying1425 <79792003+flying1425@users.noreply.github.com> Date: Sat, 5 Jul 2025 18:09:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=B9=E5=BE=AE=E9=9B=AA?= =?UTF-8?q?=E7=94=B5=E5=AD=90=20ESP32-S3-Touch-LCD-3.5B=20=E5=BC=80?= =?UTF-8?q?=E5=8F=91=E6=9D=BF=E7=9A=84=E6=94=AF=E6=8C=81=20(#849)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 添加对微雪电子 ESP32-S3-Touch-LCD-3.5B 开发板的支持 * 更改config.json的错误 * 修改板子的id以waveshare开头 * 更改config.json * 修改config.json的 name --------- Co-authored-by: flyingtjy --- main/CMakeLists.txt | 2 + main/Kconfig.projbuild | 3 + .../waveshare-s3-touch-lcd-3.5b/README.md | 3 + .../waveshare-s3-touch-lcd-3.5b/config.h | 78 ++++ .../waveshare-s3-touch-lcd-3.5b/config.json | 11 + .../custom_lcd_display.cc | 353 +++++++++++++++ .../custom_lcd_display.h | 20 + .../waveshare-s3-touch-lcd-3.5b.cc | 410 ++++++++++++++++++ main/idf_component.yml | 1 + 9 files changed, 881 insertions(+) create mode 100644 main/boards/waveshare-s3-touch-lcd-3.5b/README.md create mode 100644 main/boards/waveshare-s3-touch-lcd-3.5b/config.h create mode 100644 main/boards/waveshare-s3-touch-lcd-3.5b/config.json create mode 100644 main/boards/waveshare-s3-touch-lcd-3.5b/custom_lcd_display.cc create mode 100644 main/boards/waveshare-s3-touch-lcd-3.5b/custom_lcd_display.h create mode 100644 main/boards/waveshare-s3-touch-lcd-3.5b/waveshare-s3-touch-lcd-3.5b.cc diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 04451ba2..5f0d2f45 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -115,6 +115,8 @@ elseif(CONFIG_BOARD_TYPE_ESP32S3_Touch_LCD_1_46) set(BOARD_TYPE "esp32-s3-touch-lcd-1.46") elseif(CONFIG_BOARD_TYPE_ESP32S3_Touch_LCD_3_5) set(BOARD_TYPE "esp32-s3-touch-lcd-3.5") +elseif(CONFIG_BOARD_TYPE_ESP32S3_Touch_LCD_3_5B) + set(BOARD_TYPE "waveshare-s3-touch-lcd-3.5b") elseif(CONFIG_BOARD_TYPE_ESP32C6_LCD_1_69) set(BOARD_TYPE "waveshare-c6-lcd-1.69") elseif(CONFIG_BOARD_TYPE_ESP32P4_NANO) diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index 72b894ce..ca5dec3a 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -160,6 +160,9 @@ choice BOARD_TYPE config BOARD_TYPE_ESP32S3_Touch_LCD_3_5 bool "Waveshare ESP32-S3-Touch-LCD-3.5" depends on IDF_TARGET_ESP32S3 + config BOARD_TYPE_ESP32S3_Touch_LCD_3_5B + bool "Waveshare ESP32-S3-Touch-LCD-3.5B" + depends on IDF_TARGET_ESP32S3 config BOARD_TYPE_ESP32P4_NANO bool "Waveshare ESP32-P4-NANO" depends on IDF_TARGET_ESP32P4 diff --git a/main/boards/waveshare-s3-touch-lcd-3.5b/README.md b/main/boards/waveshare-s3-touch-lcd-3.5b/README.md new file mode 100644 index 00000000..aaadeae5 --- /dev/null +++ b/main/boards/waveshare-s3-touch-lcd-3.5b/README.md @@ -0,0 +1,3 @@ +新增 微雪 开发板: ESP32-S3-Touch-LCD-3.5B +产品链接: +https://www.waveshare.net/shop/ESP32-S3-Touch-LCD-3.5B.htm \ No newline at end of file diff --git a/main/boards/waveshare-s3-touch-lcd-3.5b/config.h b/main/boards/waveshare-s3-touch-lcd-3.5b/config.h new file mode 100644 index 00000000..c44d734c --- /dev/null +++ b/main/boards/waveshare-s3-touch-lcd-3.5b/config.h @@ -0,0 +1,78 @@ +#ifndef _BOARD_CONFIG_H_ +#define _BOARD_CONFIG_H_ + +#include +#include +#include "lvgl.h" + +#define AUDIO_INPUT_SAMPLE_RATE 24000 +#define AUDIO_OUTPUT_SAMPLE_RATE 24000 + +#define AUDIO_I2S_GPIO_MCLK GPIO_NUM_44 +#define AUDIO_I2S_GPIO_WS GPIO_NUM_15 +#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_13 +#define AUDIO_I2S_GPIO_DIN GPIO_NUM_14 +#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_16 + +#define AUDIO_CODEC_PA_PIN GPIO_NUM_NC +#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_8 +#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_7 +#define AUDIO_CODEC_ES8311_ADDR ES8311_CODEC_DEFAULT_ADDR + +#define BUILTIN_LED_GPIO GPIO_NUM_NC +#define BOOT_BUTTON_GPIO GPIO_NUM_0 +#define VOLUME_UP_BUTTON_GPIO GPIO_NUM_NC +#define VOLUME_DOWN_BUTTON_GPIO GPIO_NUM_NC + +#define DISPLAY_SPI_MODE 0 +#define DISPLAY_CS_PIN GPIO_NUM_12 +#define DISPLAY_CLK_PIN GPIO_NUM_5 +#define DISPLAY_DATA0_PIN GPIO_NUM_1 +#define DISPLAY_DATA1_PIN GPIO_NUM_2 +#define DISPLAY_DATA2_PIN GPIO_NUM_3 +#define DISPLAY_DATA3_PIN GPIO_NUM_4 + +#define DISPLAY_RST_PIN GPIO_NUM_NC + + + +#define DISPLAY_WIDTH 480 +#define DISPLAY_HEIGHT 320 +#define DISPLAY_TRANS_SIZE (DISPLAY_WIDTH * 10) + +#define DISPLAY_MIRROR_X false +#define DISPLAY_MIRROR_Y false +#define DISPLAY_SWAP_XY false +#define DISPLAY_RGB_ORDER LCD_RGB_ELEMENT_ORDER_RGB +#define DISPLAY_INVERT_COLOR false + +#define DISPLAY_OFFSET_X 0 +#define DISPLAY_OFFSET_Y 0 + +#define LV_DISPLAY_ROTATION LV_DISPLAY_ROTATION_90 + +#define DISPLAY_BACKLIGHT_PIN GPIO_NUM_6 +#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false + +#define PMIC_ENABLE 0 +#define TOUCH_ENABLE 1 + +#define CAM_PIN_PWDN GPIO_NUM_NC +#define CAM_PIN_RESET GPIO_NUM_NC +#define CAM_PIN_VSYNC GPIO_NUM_17 +#define CAM_PIN_HREF GPIO_NUM_18 +#define CAM_PIN_PCLK GPIO_NUM_41 +#define CAM_PIN_XCLK GPIO_NUM_38 +#define CAM_PIN_SIOD GPIO_NUM_NC +#define CAM_PIN_SIOC GPIO_NUM_NC +#define CAM_PIN_D0 GPIO_NUM_45 +#define CAM_PIN_D1 GPIO_NUM_47 +#define CAM_PIN_D2 GPIO_NUM_48 +#define CAM_PIN_D3 GPIO_NUM_46 +#define CAM_PIN_D4 GPIO_NUM_42 +#define CAM_PIN_D5 GPIO_NUM_40 +#define CAM_PIN_D6 GPIO_NUM_39 +#define CAM_PIN_D7 GPIO_NUM_21 + + +#endif // _BOARD_CONFIG_H_ diff --git a/main/boards/waveshare-s3-touch-lcd-3.5b/config.json b/main/boards/waveshare-s3-touch-lcd-3.5b/config.json new file mode 100644 index 00000000..aaa7c6e6 --- /dev/null +++ b/main/boards/waveshare-s3-touch-lcd-3.5b/config.json @@ -0,0 +1,11 @@ +{ + "target": "esp32s3", + "builds": [ + { + "name": "waveshare-s3-touch-lcd-3.5b", + "sdkconfig_append": [ + "CONFIG_USE_WECHAT_MESSAGE_STYLE=y" + ] + } + ] +} \ No newline at end of file diff --git a/main/boards/waveshare-s3-touch-lcd-3.5b/custom_lcd_display.cc b/main/boards/waveshare-s3-touch-lcd-3.5b/custom_lcd_display.cc new file mode 100644 index 00000000..a864d52c --- /dev/null +++ b/main/boards/waveshare-s3-touch-lcd-3.5b/custom_lcd_display.cc @@ -0,0 +1,353 @@ +#include "custom_lcd_display.h" + +#include "lcd_display.h" + +#include +#include +#include +#include +#include +#include "assets/lang_config.h" +#include +#include "settings.h" + +#include "esp_lcd_panel_io.h" + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/semphr.h" + +#include "config.h" + +#include "board.h" + + +#define TAG "CustomLcdDisplay" + +// Color definitions for dark theme +#define DARK_BACKGROUND_COLOR lv_color_hex(0x121212) // Dark background +#define DARK_TEXT_COLOR lv_color_white() // White text +#define DARK_CHAT_BACKGROUND_COLOR lv_color_hex(0x1E1E1E) // Slightly lighter than background +#define DARK_USER_BUBBLE_COLOR lv_color_hex(0x1A6C37) // Dark green +#define DARK_ASSISTANT_BUBBLE_COLOR lv_color_hex(0x333333) // Dark gray +#define DARK_SYSTEM_BUBBLE_COLOR lv_color_hex(0x2A2A2A) // Medium gray +#define DARK_SYSTEM_TEXT_COLOR lv_color_hex(0xAAAAAA) // Light gray text +#define DARK_BORDER_COLOR lv_color_hex(0x333333) // Dark gray border +#define DARK_LOW_BATTERY_COLOR lv_color_hex(0xFF0000) // Red for dark mode + +// Color definitions for light theme +#define LIGHT_BACKGROUND_COLOR lv_color_white() // White background +#define LIGHT_TEXT_COLOR lv_color_black() // Black text +#define LIGHT_CHAT_BACKGROUND_COLOR lv_color_hex(0xE0E0E0) // Light gray background +#define LIGHT_USER_BUBBLE_COLOR lv_color_hex(0x95EC69) // WeChat green +#define LIGHT_ASSISTANT_BUBBLE_COLOR lv_color_white() // White +#define LIGHT_SYSTEM_BUBBLE_COLOR lv_color_hex(0xE0E0E0) // Light gray +#define LIGHT_SYSTEM_TEXT_COLOR lv_color_hex(0x666666) // Dark gray text +#define LIGHT_BORDER_COLOR lv_color_hex(0xE0E0E0) // Light gray border +#define LIGHT_LOW_BATTERY_COLOR lv_color_black() // Black for light mode + + +// Define dark theme colors +static const ThemeColors DARK_THEME = { + .background = DARK_BACKGROUND_COLOR, + .text = DARK_TEXT_COLOR, + .chat_background = DARK_CHAT_BACKGROUND_COLOR, + .user_bubble = DARK_USER_BUBBLE_COLOR, + .assistant_bubble = DARK_ASSISTANT_BUBBLE_COLOR, + .system_bubble = DARK_SYSTEM_BUBBLE_COLOR, + .system_text = DARK_SYSTEM_TEXT_COLOR, + .border = DARK_BORDER_COLOR, + .low_battery = DARK_LOW_BATTERY_COLOR +}; + +// Define light theme colors +static const ThemeColors LIGHT_THEME = { + .background = LIGHT_BACKGROUND_COLOR, + .text = LIGHT_TEXT_COLOR, + .chat_background = LIGHT_CHAT_BACKGROUND_COLOR, + .user_bubble = LIGHT_USER_BUBBLE_COLOR, + .assistant_bubble = LIGHT_ASSISTANT_BUBBLE_COLOR, + .system_bubble = LIGHT_SYSTEM_BUBBLE_COLOR, + .system_text = LIGHT_SYSTEM_TEXT_COLOR, + .border = LIGHT_BORDER_COLOR, + .low_battery = LIGHT_LOW_BATTERY_COLOR +}; + +// Current theme - initialize based on default config +static ThemeColors current_theme = LIGHT_THEME; + +static SemaphoreHandle_t trans_done_sem = NULL; +static uint16_t *trans_act; +static uint16_t *trans_buf_1; +static uint16_t *trans_buf_2; + + + +bool CustomLcdDisplay::lvgl_port_flush_io_ready_callback(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx) +{ + BaseType_t taskAwake = pdFALSE; + lv_display_t *disp_drv = (lv_display_t *)user_ctx; + assert(disp_drv != NULL); + if (trans_done_sem) { + xSemaphoreGiveFromISR(trans_done_sem, &taskAwake); + } + return false; +} + +void CustomLcdDisplay::lvgl_port_flush_callback(lv_display_t *drv, const lv_area_t *area, uint8_t *color_map) +{ + assert(drv != NULL); + esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t)lv_display_get_driver_data(drv); + assert(panel_handle != NULL); + + + size_t len = lv_area_get_size(area); + lv_draw_sw_rgb565_swap(color_map, len); + + const int x_start = area->x1; + const int x_end = area->x2; + const int y_start = area->y1; + const int y_end = area->y2; + const int width = x_end - x_start + 1; + const int height = y_end - y_start + 1; + + int32_t hor_res = lv_display_get_horizontal_resolution(drv); + int32_t ver_res = lv_display_get_vertical_resolution(drv); + + // printf("hor_res: %ld, ver_res: %ld\r\n", hor_res, ver_res); + // printf("x_start: %d, x_end: %d, y_start: %d, y_end: %d, width: %d, height: %d\r\n", x_start, x_end, y_start, y_end, width, height); + uint16_t *from = (uint16_t *)color_map; + uint16_t *to = NULL; + + if (DISPLAY_TRANS_SIZE > 0) { + assert(trans_buf_1 != NULL); + + int x_draw_start = 0; + int x_draw_end = 0; + int y_draw_start = 0; + int y_draw_end = 0; + int trans_count = 0; + + trans_act = trans_buf_1; + lv_display_rotation_t rotate = LV_DISPLAY_ROTATION; + + int x_start_tmp = 0; + int x_end_tmp = 0; + int max_width = 0; + int trans_width = 0; + + int y_start_tmp = 0; + int y_end_tmp = 0; + int max_height = 0; + int trans_height = 0; + + if (LV_DISPLAY_ROTATION_270 == rotate || LV_DISPLAY_ROTATION_90 == rotate) { + max_width = ((DISPLAY_TRANS_SIZE / height) > width) ? (width) : (DISPLAY_TRANS_SIZE / height); + trans_count = width / max_width + (width % max_width ? (1) : (0)); + + x_start_tmp = x_start; + x_end_tmp = x_end; + } else { + max_height = ((DISPLAY_TRANS_SIZE / width) > height) ? (height) : (DISPLAY_TRANS_SIZE / width); + trans_count = height / max_height + (height % max_height ? (1) : (0)); + + y_start_tmp = y_start; + y_end_tmp = y_end; + } + + for (int i = 0; i < trans_count; i++) { + + if (LV_DISPLAY_ROTATION_90 == rotate) { + trans_width = (x_end - x_start_tmp + 1) > max_width ? max_width : (x_end - x_start_tmp + 1); + x_end_tmp = (x_end - x_start_tmp + 1) > max_width ? (x_start_tmp + max_width - 1) : x_end; + } else if (LV_DISPLAY_ROTATION_270 == rotate) { + trans_width = (x_end_tmp - x_start + 1) > max_width ? max_width : (x_end_tmp - x_start + 1); + x_start_tmp = (x_end_tmp - x_start + 1) > max_width ? (x_end_tmp - trans_width + 1) : x_start; + } else if (LV_DISPLAY_ROTATION_0 == rotate) { + trans_height = (y_end - y_start_tmp + 1) > max_height ? max_height : (y_end - y_start_tmp + 1); + y_end_tmp = (y_end - y_start_tmp + 1) > max_height ? (y_start_tmp + max_height - 1) : y_end; + } else { + trans_height = (y_end_tmp - y_start + 1) > max_height ? max_height : (y_end_tmp - y_start + 1); + y_start_tmp = (y_end_tmp - y_start + 1) > max_height ? (y_end_tmp - max_height + 1) : y_start; + } + + trans_act = (trans_act == trans_buf_1) ? (trans_buf_2) : (trans_buf_1); + to = trans_act; + + switch (rotate) { + case LV_DISPLAY_ROTATION_90: + for (int y = 0; y < height; y++) { + for (int x = 0; x < trans_width; x++) { + *(to + x * height + (height - y - 1)) = *(from + y * width + x_start_tmp + x); + } + } + x_draw_start = ver_res - y_end - 1; + x_draw_end = ver_res - y_start - 1; + y_draw_start = x_start_tmp; + y_draw_end = x_end_tmp; + break; + case LV_DISPLAY_ROTATION_270: + for (int y = 0; y < height; y++) { + for (int x = 0; x < trans_width; x++) { + *(to + (trans_width - x - 1) * height + y) = *(from + y * width + x_start_tmp + x); + } + } + x_draw_start = y_start; + x_draw_end = y_end; + y_draw_start = hor_res - x_end_tmp - 1; + y_draw_end = hor_res - x_start_tmp - 1; + break; + case LV_DISPLAY_ROTATION_180: + for (int y = 0; y < trans_height; y++) { + for (int x = 0; x < width; x++) { + *(to + (trans_height - y - 1)*width + (width - x - 1)) = *(from + y_start_tmp * width + y * (width) + x); + } + } + x_draw_start = hor_res - x_end - 1; + x_draw_end = hor_res - x_start - 1; + y_draw_start = ver_res - y_end_tmp - 1; + y_draw_end = ver_res - y_start_tmp - 1; + break; + case LV_DISPLAY_ROTATION_0: + for (int y = 0; y < trans_height; y++) { + for (int x = 0; x < width; x++) { + *(to + y * (width) + x) = *(from + y_start_tmp * width + y * (width) + x); + } + } + x_draw_start = x_start; + x_draw_end = x_end; + y_draw_start = y_start_tmp; + y_draw_end = y_end_tmp; + break; + default: + break; + } + + if (0 == i) { + // if (disp_ctx->draw_wait_cb) { + // disp_ctx->draw_wait_cb(disp_ctx->panel_handle->user_data); + // } + xSemaphoreGive(trans_done_sem); + } + + xSemaphoreTake(trans_done_sem, portMAX_DELAY); + // printf("i: %d, x_draw_start: %d, x_draw_end: %d, y_draw_start: %d, y_draw_end: %d\r\n", i, x_draw_start, x_draw_end, y_draw_start, y_draw_end); + esp_lcd_panel_draw_bitmap(panel_handle, x_draw_start, y_draw_start, x_draw_end + 1, y_draw_end + 1, to); + + if (LV_DISPLAY_ROTATION_90 == rotate) { + x_start_tmp += max_width; + } else if (LV_DISPLAY_ROTATION_270 == rotate) { + x_end_tmp -= max_width; + } if (LV_DISPLAY_ROTATION_0 == rotate) { + y_start_tmp += max_height; + } else { + y_end_tmp -= max_height; + } + } + } else { + esp_lcd_panel_draw_bitmap(panel_handle, x_start, y_start, x_end + 1, y_end + 1, color_map); + } + lv_disp_flush_ready(drv); +} + + +CustomLcdDisplay::CustomLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, + 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, fonts, width, height) { + // width_ = width; + // height_ = height; + + // 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()); + } + + // Set the display to on + ESP_LOGI(TAG, "Turning display on"); + ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_, true)); + + 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(); + port_cfg.task_priority = 1; + port_cfg.timer_period_ms = 50; + lvgl_port_init(&port_cfg); + trans_done_sem = xSemaphoreCreateCounting(1, 0); + trans_buf_1 = (uint16_t *)heap_caps_malloc(DISPLAY_TRANS_SIZE * sizeof(uint16_t), MALLOC_CAP_DMA); + trans_buf_2 = (uint16_t *)heap_caps_malloc(DISPLAY_TRANS_SIZE * sizeof(uint16_t), MALLOC_CAP_DMA); +#if 0 + ESP_LOGI(TAG, "Adding LCD screen"); + const lvgl_port_display_cfg_t display_cfg = { + .io_handle = panel_io_, + .panel_handle = panel_, + .control_handle = nullptr, + .buffer_size = static_cast(width_ * height_), + .double_buffer = false, + .trans_size = 0, + .hres = static_cast(width_), + .vres = static_cast(height_), + .monochrome = false, + .rotation = { + .swap_xy = swap_xy, + .mirror_x = mirror_x, + .mirror_y = mirror_y, + }, + .color_format = LV_COLOR_FORMAT_RGB565, + .flags = { + .buff_dma = 0, + .buff_spiram = 1, + .sw_rotate = 0, + .swap_bytes = 1, + .full_refresh = 1, + .direct_mode = 0, + }, + }; + + display_ = lvgl_port_add_disp(&display_cfg); + lv_display_set_flush_cb(display_, lvgl_port_flush_callback); +#else + + uint32_t buffer_size = 0; + lv_color_t *buf1 = NULL; + lvgl_port_lock(0); + uint8_t color_bytes = lv_color_format_get_size(LV_COLOR_FORMAT_RGB565); + display_ = lv_display_create(width_, height_); + lv_display_set_flush_cb(display_, lvgl_port_flush_callback); + buffer_size = width_ * height_; + buf1 = (lv_color_t *)heap_caps_aligned_alloc(1, buffer_size * color_bytes, MALLOC_CAP_SPIRAM); + lv_display_set_buffers(display_, buf1, NULL, buffer_size * color_bytes, LV_DISPLAY_RENDER_MODE_FULL); + lv_display_set_driver_data(display_, panel_); + lvgl_port_unlock(); + +#endif + + esp_lcd_panel_io_callbacks_t cbs = { + .on_color_trans_done = lvgl_port_flush_io_ready_callback, + }; + /* Register done callback */ + esp_lcd_panel_io_register_event_callbacks(panel_io_, &cbs, display_); + + esp_lcd_panel_disp_on_off(panel_, false); + + if (display_ == nullptr) { + ESP_LOGE(TAG, "Failed to add display"); + return; + } + + if (offset_x != 0 || offset_y != 0) { + lv_display_set_offset(display_, offset_x, offset_y); + } + + // Update the theme + if (current_theme_name_ == "dark") { + current_theme = DARK_THEME; + } else if (current_theme_name_ == "light") { + current_theme = LIGHT_THEME; + } + + SetupUI(); +} \ No newline at end of file diff --git a/main/boards/waveshare-s3-touch-lcd-3.5b/custom_lcd_display.h b/main/boards/waveshare-s3-touch-lcd-3.5b/custom_lcd_display.h new file mode 100644 index 00000000..792d4c2b --- /dev/null +++ b/main/boards/waveshare-s3-touch-lcd-3.5b/custom_lcd_display.h @@ -0,0 +1,20 @@ +#ifndef __CUSTOM_LCD_DISPLAY_H__ +#define __CUSTOM_LCD_DISPLAY_H__ + +#include "lcd_display.h" + +// // SPI LCD显示器 +class CustomLcdDisplay : public LcdDisplay { +public: + CustomLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, + int width, int height, int offset_x, int offset_y, + bool mirror_x, bool mirror_y, bool swap_xy, + DisplayFonts fonts); +private: + static bool lvgl_port_flush_io_ready_callback(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx); + static void lvgl_port_flush_callback(lv_display_t *drv, const lv_area_t *area, uint8_t *color_map); +}; + + + +#endif // __CUSTOM_LCD_DISPLAY_H__ \ No newline at end of file diff --git a/main/boards/waveshare-s3-touch-lcd-3.5b/waveshare-s3-touch-lcd-3.5b.cc b/main/boards/waveshare-s3-touch-lcd-3.5b/waveshare-s3-touch-lcd-3.5b.cc new file mode 100644 index 00000000..348accab --- /dev/null +++ b/main/boards/waveshare-s3-touch-lcd-3.5b/waveshare-s3-touch-lcd-3.5b.cc @@ -0,0 +1,410 @@ +#include "wifi_board.h" +#include "audio_codecs/es8311_audio_codec.h" +#include "display/lcd_display.h" +#include "system_reset.h" +#include "application.h" +#include "button.h" +#include "config.h" +#include "iot/thing_manager.h" + + +#include +#include "i2c_device.h" +#include +#include +#include +#include +#include +#include + +#include +#include "esp_io_expander_tca9554.h" + +#include "axp2101.h" +#include "power_save_timer.h" + + +#include "esp_lcd_axs15231b.h" + +#include "custom_lcd_display.h" + +#include + +#include +#include +#include "esp32_camera.h" + +#define TAG "waveshare_lcd_3_5b" + + +LV_FONT_DECLARE(font_puhui_16_4); +LV_FONT_DECLARE(font_awesome_16_4); + + +static const axs15231b_lcd_init_cmd_t lcd_init_cmds[] = { + {0xBB, (uint8_t[]){0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5A, 0xA5}, 8, 0}, + {0xA0, (uint8_t[]){0xC0, 0x10, 0x00, 0x02, 0x00, 0x00, 0x04, 0x3F, 0x20, 0x05, 0x3F, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00}, 17, 0}, + {0xA2, (uint8_t[]){0x30, 0x3C, 0x24, 0x14, 0xD0, 0x20, 0xFF, 0xE0, 0x40, 0x19, 0x80, 0x80, 0x80, 0x20, 0xf9, 0x10, 0x02, 0xff, 0xff, 0xF0, 0x90, 0x01, 0x32, 0xA0, 0x91, 0xE0, 0x20, 0x7F, 0xFF, 0x00, 0x5A}, 31, 0}, + {0xD0, (uint8_t[]){0xE0, 0x40, 0x51, 0x24, 0x08, 0x05, 0x10, 0x01, 0x20, 0x15, 0x42, 0xC2, 0x22, 0x22, 0xAA, 0x03, 0x10, 0x12, 0x60, 0x14, 0x1E, 0x51, 0x15, 0x00, 0x8A, 0x20, 0x00, 0x03, 0x3A, 0x12}, 30, 0}, + {0xA3, (uint8_t[]){0xA0, 0x06, 0xAa, 0x00, 0x08, 0x02, 0x0A, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x55, 0x55}, 22, 0}, + {0xC1, (uint8_t[]){0x31, 0x04, 0x02, 0x02, 0x71, 0x05, 0x24, 0x55, 0x02, 0x00, 0x41, 0x00, 0x53, 0xFF, 0xFF, 0xFF, 0x4F, 0x52, 0x00, 0x4F, 0x52, 0x00, 0x45, 0x3B, 0x0B, 0x02, 0x0d, 0x00, 0xFF, 0x40}, 30, 0}, + {0xC3, (uint8_t[]){0x00, 0x00, 0x00, 0x50, 0x03, 0x00, 0x00, 0x00, 0x01, 0x80, 0x01}, 11, 0}, + {0xC4, (uint8_t[]){0x00, 0x24, 0x33, 0x80, 0x00, 0xea, 0x64, 0x32, 0xC8, 0x64, 0xC8, 0x32, 0x90, 0x90, 0x11, 0x06, 0xDC, 0xFA, 0x00, 0x00, 0x80, 0xFE, 0x10, 0x10, 0x00, 0x0A, 0x0A, 0x44, 0x50}, 29, 0}, + {0xC5, (uint8_t[]){0x18, 0x00, 0x00, 0x03, 0xFE, 0x3A, 0x4A, 0x20, 0x30, 0x10, 0x88, 0xDE, 0x0D, 0x08, 0x0F, 0x0F, 0x01, 0x3A, 0x4A, 0x20, 0x10, 0x10, 0x00}, 23, 0}, + {0xC6, (uint8_t[]){0x05, 0x0A, 0x05, 0x0A, 0x00, 0xE0, 0x2E, 0x0B, 0x12, 0x22, 0x12, 0x22, 0x01, 0x03, 0x00, 0x3F, 0x6A, 0x18, 0xC8, 0x22}, 20, 0}, + {0xC7, (uint8_t[]){0x50, 0x32, 0x28, 0x00, 0xa2, 0x80, 0x8f, 0x00, 0x80, 0xff, 0x07, 0x11, 0x9c, 0x67, 0xff, 0x24, 0x0c, 0x0d, 0x0e, 0x0f}, 20, 0}, + {0xC9, (uint8_t[]){0x33, 0x44, 0x44, 0x01}, 4, 0}, + {0xCF, (uint8_t[]){0x2C, 0x1E, 0x88, 0x58, 0x13, 0x18, 0x56, 0x18, 0x1E, 0x68, 0x88, 0x00, 0x65, 0x09, 0x22, 0xC4, 0x0C, 0x77, 0x22, 0x44, 0xAA, 0x55, 0x08, 0x08, 0x12, 0xA0, 0x08}, 27, 0}, + {0xD5, (uint8_t[]){0x40, 0x8E, 0x8D, 0x01, 0x35, 0x04, 0x92, 0x74, 0x04, 0x92, 0x74, 0x04, 0x08, 0x6A, 0x04, 0x46, 0x03, 0x03, 0x03, 0x03, 0x82, 0x01, 0x03, 0x00, 0xE0, 0x51, 0xA1, 0x00, 0x00, 0x00}, 30, 0}, + {0xD6, (uint8_t[]){0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 0x93, 0x00, 0x01, 0x83, 0x07, 0x07, 0x00, 0x07, 0x07, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00, 0x84, 0x00, 0x20, 0x01, 0x00}, 30, 0}, + {0xD7, (uint8_t[]){0x03, 0x01, 0x0b, 0x09, 0x0f, 0x0d, 0x1E, 0x1F, 0x18, 0x1d, 0x1f, 0x19, 0x40, 0x8E, 0x04, 0x00, 0x20, 0xA0, 0x1F}, 19, 0}, + {0xD8, (uint8_t[]){0x02, 0x00, 0x0a, 0x08, 0x0e, 0x0c, 0x1E, 0x1F, 0x18, 0x1d, 0x1f, 0x19}, 12, 0}, + {0xD9, (uint8_t[]){0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F}, 12, 0}, + {0xDD, (uint8_t[]){0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F}, 12, 0}, + {0xDF, (uint8_t[]){0x44, 0x73, 0x4B, 0x69, 0x00, 0x0A, 0x02, 0x90}, 8, 0}, + {0xE0, (uint8_t[]){0x3B, 0x28, 0x10, 0x16, 0x0c, 0x06, 0x11, 0x28, 0x5c, 0x21, 0x0D, 0x35, 0x13, 0x2C, 0x33, 0x28, 0x0D}, 17, 0}, + {0xE1, (uint8_t[]){0x37, 0x28, 0x10, 0x16, 0x0b, 0x06, 0x11, 0x28, 0x5C, 0x21, 0x0D, 0x35, 0x14, 0x2C, 0x33, 0x28, 0x0F}, 17, 0}, + {0xE2, (uint8_t[]){0x3B, 0x07, 0x12, 0x18, 0x0E, 0x0D, 0x17, 0x35, 0x44, 0x32, 0x0C, 0x14, 0x14, 0x36, 0x3A, 0x2F, 0x0D}, 17, 0}, + {0xE3, (uint8_t[]){0x37, 0x07, 0x12, 0x18, 0x0E, 0x0D, 0x17, 0x35, 0x44, 0x32, 0x0C, 0x14, 0x14, 0x36, 0x32, 0x2F, 0x0F}, 17, 0}, + {0xE4, (uint8_t[]){0x3B, 0x07, 0x12, 0x18, 0x0E, 0x0D, 0x17, 0x39, 0x44, 0x2E, 0x0C, 0x14, 0x14, 0x36, 0x3A, 0x2F, 0x0D}, 17, 0}, + {0xE5, (uint8_t[]){0x37, 0x07, 0x12, 0x18, 0x0E, 0x0D, 0x17, 0x39, 0x44, 0x2E, 0x0C, 0x14, 0x14, 0x36, 0x3A, 0x2F, 0x0F}, 17, 0}, + {0xA4, (uint8_t[]){0x85, 0x85, 0x95, 0x82, 0xAF, 0xAA, 0xAA, 0x80, 0x10, 0x30, 0x40, 0x40, 0x20, 0xFF, 0x60, 0x30}, 16, 0}, + {0xA4, (uint8_t[]){0x85, 0x85, 0x95, 0x85}, 4, 0}, + {0xBB, (uint8_t[]){0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 8, 0}, + {0x13, (uint8_t[]){0x00}, 0, 0}, + {0x11, (uint8_t[]){0x00}, 0, 120}, + {0x2C, (uint8_t[]){0x00, 0x00, 0x00, 0x00}, 4, 0}, + {0x2a, (uint8_t[]){0x00, 0x00, 0x01, 0x3f}, 4, 0}, + {0x2b, (uint8_t[]){0x00, 0x00, 0x01, 0xdf}, 4, 0}}; + + + +class Pmic : public Axp2101 { + public: + Pmic(i2c_master_bus_handle_t i2c_bus, uint8_t addr) : Axp2101(i2c_bus, addr) { + WriteReg(0x22, 0b110); // PWRON > OFFLEVEL as POWEROFF Source enable + WriteReg(0x27, 0x10); // hold 4s to power off + + // Disable All DCs but DC1 + WriteReg(0x80, 0x01); + // Disable All LDOs + WriteReg(0x90, 0x00); + WriteReg(0x91, 0x00); + + // Set DC1 to 3.3V + WriteReg(0x82, (3300 - 1500) / 100); + + // Set ALDO1 to 3.3V + WriteReg(0x92, (3300 - 500) / 100); + + WriteReg(0x96, (1500 - 500) / 100); + WriteReg(0x97, (2800 - 500) / 100); + + // Enable ALDO1 BLDO1 BLDO2 + WriteReg(0x90, 0x31); + + WriteReg(0x64, 0x02); // CV charger voltage setting to 4.1V + + WriteReg(0x61, 0x02); // set Main battery precharge current to 50mA + WriteReg(0x62, 0x08); // set Main battery charger current to 400mA ( 0x08-200mA, 0x09-300mA, 0x0A-400mA ) + WriteReg(0x63, 0x01); // set Main battery term charge current to 25mA + } + }; + +class CustomBoard : public WifiBoard { +private: + Button boot_button_; + Pmic* pmic_ = nullptr; + i2c_master_bus_handle_t i2c_bus_; + esp_io_expander_handle_t io_expander = NULL; + LcdDisplay* display_; + PowerSaveTimer* power_save_timer_; + Esp32Camera* camera_; + + void InitializePowerSaveTimer() { + power_save_timer_ = new PowerSaveTimer(-1, 60, 300); + power_save_timer_->OnEnterSleepMode([this]() { + ESP_LOGI(TAG, "Enabling sleep mode"); + auto display = GetDisplay(); + display->SetChatMessage("system", ""); + display->SetEmotion("sleepy"); + GetBacklight()->SetBrightness(20); + }); + power_save_timer_->OnExitSleepMode([this]() { + auto display = GetDisplay(); + display->SetChatMessage("system", ""); + display->SetEmotion("neutral"); + GetBacklight()->RestoreBrightness(); + }); + power_save_timer_->OnShutdownRequest([this]() { + pmic_->PowerOff(); + }); + power_save_timer_->SetEnabled(true); + } + + void InitializeI2c() { + // Initialize I2C peripheral + i2c_master_bus_config_t i2c_bus_cfg = { + .i2c_port = (i2c_port_t)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, &i2c_bus_)); + } + + void InitializeTca9554(void) + { + esp_err_t ret = esp_io_expander_new_i2c_tca9554(i2c_bus_, ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000, &io_expander); + if(ret != ESP_OK) + ESP_LOGE(TAG, "TCA9554 create returned error"); + ret = esp_io_expander_set_dir(io_expander, IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1, IO_EXPANDER_OUTPUT); + ESP_ERROR_CHECK(ret); + vTaskDelay(pdMS_TO_TICKS(100)); + ret = esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1, 0); + ESP_ERROR_CHECK(ret); + vTaskDelay(pdMS_TO_TICKS(100)); + ret = esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_1, 1); + ESP_ERROR_CHECK(ret); + } + + void InitializeAxp2101() { + ESP_LOGI(TAG, "Init AXP2101"); + pmic_ = new Pmic(i2c_bus_, 0x34); + } + + void InitializeSpi() { + ESP_LOGI(TAG, "Initialize QSPI bus"); + spi_bus_config_t buscfg = {}; + buscfg.data0_io_num = DISPLAY_DATA0_PIN; + buscfg.data1_io_num = DISPLAY_DATA1_PIN; + buscfg.data2_io_num = DISPLAY_DATA2_PIN; + buscfg.data3_io_num = DISPLAY_DATA3_PIN; + buscfg.sclk_io_num = DISPLAY_CLK_PIN; + buscfg.max_transfer_sz = DISPLAY_TRANS_SIZE * sizeof(uint16_t); + ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_CH_AUTO)); + } + + void InitializeCamera() { + camera_config_t config = {}; + + config.pin_pwdn = CAM_PIN_PWDN; + config.pin_reset = CAM_PIN_RESET; + config.pin_xclk = CAM_PIN_XCLK; + config.pin_sccb_sda = CAM_PIN_SIOD; + config.pin_sccb_scl = CAM_PIN_SIOC; + config.sccb_i2c_port = I2C_NUM_0; + + config.pin_d7 = CAM_PIN_D7; + config.pin_d6 = CAM_PIN_D6; + config.pin_d5 = CAM_PIN_D5; + config.pin_d4 = CAM_PIN_D4; + config.pin_d3 = CAM_PIN_D3; + config.pin_d2 = CAM_PIN_D2; + config.pin_d1 = CAM_PIN_D1; + config.pin_d0 = CAM_PIN_D0; + config.pin_vsync = CAM_PIN_VSYNC; + config.pin_href = CAM_PIN_HREF; + config.pin_pclk = CAM_PIN_PCLK; + + /* XCLK 20MHz or 10MHz for OV2640 double FPS (Experimental) */ + config.xclk_freq_hz = 10000000; + config.ledc_timer = LEDC_TIMER_1; + config.ledc_channel = LEDC_CHANNEL_0; + + config.pixel_format = PIXFORMAT_RGB565; /* YUV422,GRAYSCALE,RGB565,JPEG */ + config.frame_size = FRAMESIZE_240X240; /* QQVGA-UXGA, For ESP32, do not use sizes above QVGA when not JPEG. The performance of the ESP32-S series has improved a lot, but JPEG mode always gives better frame rates */ + + config.jpeg_quality = 12; /* 0-63, for OV series camera sensors, lower number means higher quality */ + config.fb_count = 2; /* When jpeg mode is used, if fb_count more than one, the driver will work in continuous mode */ + config.fb_location = CAMERA_FB_IN_PSRAM; + config.grab_mode = CAMERA_GRAB_WHEN_EMPTY; + + esp_err_t err = esp_camera_init(&config); // 测试相机是否存在 + if (err != ESP_OK) { + ESP_LOGE(TAG, "Camera is not plugged in or not supported, error: %s", esp_err_to_name(err)); + // 如果摄像头初始化失败,设置 camera_ 为 nullptr + camera_ = nullptr; + return; + }else + { + esp_camera_deinit();// 释放之前的摄像头资源,为正确初始化做准备 + camera_ = new Esp32Camera(config); + } + + } + + void InitializeLcdDisplay() { + esp_lcd_panel_io_handle_t panel_io = nullptr; + esp_lcd_panel_handle_t panel = nullptr; + // 液晶屏控制IO初始化 + ESP_LOGI(TAG, "Install panel IO"); + esp_lcd_panel_io_spi_config_t io_config = AXS15231B_PANEL_IO_QSPI_CONFIG( + DISPLAY_CS_PIN, + NULL, + NULL); + ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(SPI2_HOST, &io_config, &panel_io)); + + // 初始化液晶屏驱动芯片 + ESP_LOGI(TAG, "Install LCD driver"); + const axs15231b_vendor_config_t vendor_config = { + .init_cmds = lcd_init_cmds, // Uncomment these line if use custom initialization commands + .init_cmds_size = sizeof(lcd_init_cmds) / sizeof(lcd_init_cmds[0]), + .flags = { + .use_qspi_interface = 1, + }, + }; + esp_lcd_panel_dev_config_t panel_config = { + .reset_gpio_num = DISPLAY_RST_PIN, + .rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB, + .bits_per_pixel = 16, + .vendor_config = (void *)&vendor_config, + }; + esp_lcd_new_panel_axs15231b(panel_io, &panel_config, &panel); + + + esp_lcd_panel_reset(panel); + + esp_lcd_panel_init(panel); + esp_lcd_panel_invert_color(panel, DISPLAY_INVERT_COLOR); + // esp_lcd_panel_disp_on_off(panel, false); + esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY); + esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y); + + display_ = new CustomLcdDisplay(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_16_4, + .icon_font = &font_awesome_16_4, + .emoji_font = font_emoji_32_init(), + }); + // display_ = new CustomLcdDisplay(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); + } + + void InitializeButtons() { + boot_button_.OnClick([this]() { + auto& app = Application::GetInstance(); + if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) { + ResetWifiConfiguration(); + } + app.ToggleChatState(); + }); + } + + + void InitializeTouch() + { + esp_lcd_touch_handle_t tp; + esp_lcd_touch_config_t tp_cfg = { + .x_max = DISPLAY_WIDTH, + .y_max = DISPLAY_HEIGHT, + .rst_gpio_num = GPIO_NUM_NC, + .int_gpio_num = GPIO_NUM_NC, + .levels = { + .reset = 0, + .interrupt = 0, + }, + .flags = { + .swap_xy = 1, + .mirror_x = 1, + .mirror_y = 1, + }, + }; + esp_lcd_panel_io_handle_t tp_io_handle = NULL; + esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_AXS15231B_CONFIG(); + tp_io_config.scl_speed_hz = 400 * 1000; + ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c(i2c_bus_, &tp_io_config, &tp_io_handle)); + ESP_LOGI(TAG, "Initialize touch controller"); + ESP_ERROR_CHECK(esp_lcd_touch_new_i2c_axs15231b(tp_io_handle, &tp_cfg, &tp)); + const lvgl_port_touch_cfg_t touch_cfg = { + .disp = lv_display_get_default(), + .handle = tp, + }; + lvgl_port_add_touch(&touch_cfg); + ESP_LOGI(TAG, "Touch panel initialized successfully"); + } + + + // 物联网初始化,添加对 AI 可见设备 + void InitializeIot() { + auto& thing_manager = iot::ThingManager::GetInstance(); + thing_manager.AddThing(iot::CreateThing("Speaker")); + thing_manager.AddThing(iot::CreateThing("Screen")); + + thing_manager.AddThing(iot::CreateThing("BoardControl")); +#if PMIC_ENABLE + thing_manager.AddThing(iot::CreateThing("Battery")); +#endif + } + +public: + CustomBoard() : + boot_button_(BOOT_BUTTON_GPIO) { + + InitializeI2c(); + InitializeTca9554(); + + InitializeAxp2101(); +#if PMIC_ENABLE + InitializePowerSaveTimer(); +#endif + InitializeSpi(); + InitializeLcdDisplay(); +#if TOUCH_ENABLE + InitializeTouch(); +#endif + InitializeButtons(); + InitializeCamera(); + InitializeIot(); + GetBacklight()->RestoreBrightness(); + } + + virtual AudioCodec* GetAudioCodec() override { + static Es8311AudioCodec audio_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 Backlight* GetBacklight() override { + static PwmBacklight backlight(DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT); + return &backlight; + } + virtual Camera* GetCamera() override { + return camera_; + } +#if PMIC_ENABLE + virtual bool GetBatteryLevel(int &level, bool& charging, bool& discharging) override { + static bool last_discharging = false; + charging = pmic_->IsCharging(); + discharging = pmic_->IsDischarging(); + if (discharging != last_discharging) { + power_save_timer_->SetEnabled(discharging); + last_discharging = discharging; + } + + level = pmic_->GetBatteryLevel(); + return true; + } + + virtual void SetPowerSaveMode(bool enabled) override { + if (!enabled) { + power_save_timer_->WakeUp(); + } + WifiBoard::SetPowerSaveMode(enabled); + } +#endif +}; + +DECLARE_BOARD(CustomBoard); diff --git a/main/idf_component.yml b/main/idf_component.yml index b6d71235..9663c519 100644 --- a/main/idf_component.yml +++ b/main/idf_component.yml @@ -4,6 +4,7 @@ dependencies: espressif/esp_lcd_ili9341: ==1.2.0 espressif/esp_lcd_gc9a01: ==2.0.1 espressif/esp_lcd_st77916: ^1.0.1 + espressif/esp_lcd_axs15231b: ^1.0.0 espressif/esp_lcd_st7796: version: 1.3.2 rules: