From b94c8a6e8b462fa47447ef73a46f31c06700420c Mon Sep 17 00:00:00 2001 From: Terrence Date: Sun, 5 Jan 2025 21:20:30 +0800 Subject: [PATCH] rename St7789 to LCD --- CMakeLists.txt | 2 +- main/CMakeLists.txt | 2 +- main/application.cc | 1 + main/audio_codecs/no_audio_codec.cc | 8 +- main/boards/common/board.h | 2 +- main/boards/esp-box-3/esp_box3_board.cc | 62 +++++---------- .../boards/lichuang-dev/lichuang_dev_board.cc | 6 +- .../boards/m5stack-core-s3/m5stack_core_s3.cc | 37 ++++++--- .../magiclick-2p4/magiclick_2p4_board.cc | 23 +++--- .../{st7789_display.cc => lcd_display.cc} | 78 +++++++------------ .../{st7789_display.h => lcd_display.h} | 12 +-- main/display/ssd1306_display.cc | 2 +- 12 files changed, 105 insertions(+), 130 deletions(-) rename main/display/{st7789_display.cc => lcd_display.cc} (81%) rename main/display/{st7789_display.h => lcd_display.h} (85%) diff --git a/CMakeLists.txt b/CMakeLists.txt index fd1762e0..5536104d 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.16) -set(PROJECT_VER "0.9.7") +set(PROJECT_VER "0.9.8") include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(xiaozhi) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 6eb69dca..2e4d72a2 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -7,7 +7,7 @@ set(SOURCES "audio_codecs/audio_codec.cc" "led/circular_strip.cc" "display/display.cc" "display/no_display.cc" - "display/st7789_display.cc" + "display/lcd_display.cc" "display/ssd1306_display.cc" "protocols/protocol.cc" "protocols/mqtt_protocol.cc" diff --git a/main/application.cc b/main/application.cc index d4d6b783..876d5741 100644 --- a/main/application.cc +++ b/main/application.cc @@ -548,6 +548,7 @@ void Application::SetDeviceState(DeviceState state) { case kDeviceStateIdle: display->SetStatus("待命"); display->SetEmotion("neutral"); + display->SetChatMessage("", ""); #ifdef CONFIG_IDF_TARGET_ESP32S3 audio_processor_.Stop(); #endif diff --git a/main/audio_codecs/no_audio_codec.cc b/main/audio_codecs/no_audio_codec.cc index 434232e2..d8f64529 100644 --- a/main/audio_codecs/no_audio_codec.cc +++ b/main/audio_codecs/no_audio_codec.cc @@ -77,8 +77,8 @@ NoAudioCodec::NoAudioCodec(int input_sample_rate, int output_sample_rate, gpio_n i2s_chan_config_t chan_cfg = { .id = (i2s_port_t)0, .role = I2S_ROLE_MASTER, - .dma_desc_num = 6, - .dma_frame_num = 240, + .dma_desc_num = 2, + .dma_frame_num = 240 * 3, .auto_clear_after_cb = true, .auto_clear_before_cb = false, .intr_priority = 0, @@ -138,8 +138,8 @@ NoAudioCodec::NoAudioCodec(int input_sample_rate, int output_sample_rate, gpio_n // Create a new channel for speaker i2s_chan_config_t tx_chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG((i2s_port_t)1, I2S_ROLE_MASTER); - tx_chan_cfg.dma_desc_num = 6; - tx_chan_cfg.dma_frame_num = 240; + tx_chan_cfg.dma_desc_num = 2; + tx_chan_cfg.dma_frame_num = 240 * 3; tx_chan_cfg.auto_clear_after_cb = true; tx_chan_cfg.auto_clear_before_cb = false; tx_chan_cfg.intr_priority = 0; diff --git a/main/boards/common/board.h b/main/boards/common/board.h index ce08e763..bf10a785 100644 --- a/main/boards/common/board.h +++ b/main/boards/common/board.h @@ -32,7 +32,7 @@ public: virtual void StartNetwork() = 0; virtual ~Board() = default; - virtual Led* GetLed() = 0; + virtual Led* GetLed(); virtual AudioCodec* GetAudioCodec() = 0; virtual Display* GetDisplay(); virtual Http* CreateHttp() = 0; diff --git a/main/boards/esp-box-3/esp_box3_board.cc b/main/boards/esp-box-3/esp_box3_board.cc index 5ef418f9..1b0e274e 100644 --- a/main/boards/esp-box-3/esp_box3_board.cc +++ b/main/boards/esp-box-3/esp_box3_board.cc @@ -1,6 +1,6 @@ #include "wifi_board.h" #include "audio_codecs/box_audio_codec.h" -#include "display/st7789_display.h" +#include "display/lcd_display.h" #include "esp_lcd_ili9341.h" #include "font_awesome_symbols.h" #include "application.h" @@ -42,7 +42,7 @@ static const ili9341_lcd_init_cmd_t vendor_specific_init[] = { }; // Example Display and UI overwrite in different board -class Ili9341Display : public St7789Display { +class Ili9341Display : public LcdDisplay { private: lv_obj_t *user_messge_label_ = nullptr; lv_obj_t *ai_messge_label_ = nullptr; @@ -50,44 +50,27 @@ public: Ili9341Display(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) - : St7789Display(panel_io, panel, backlight_pin, backlight_output_invert, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {} - - void SetStatus(const std::string &status) override - { - if (status_label_ == nullptr) { - return; - } - if(status=="待命") - { - SetChatMessage(" "," "); - } - DisplayLockGuard lock(this); - lv_label_set_text(status_label_, status.c_str()); - } + : LcdDisplay(panel_io, panel, backlight_pin, backlight_output_invert, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {} void SetChatMessage(const std::string &role, const std::string &content) override { if (ai_messge_label_== nullptr || user_messge_label_== nullptr) { return; } + DisplayLockGuard lock(this); - ESP_LOGI(TAG,"role:%s",role.c_str()); - if(role=="assistant") - { - std::string new_content = "AI:" + content; + ESP_LOGI(TAG, "role:%s", role.c_str()); + if(role == "assistant") { + std::string new_content = "AI: " + content; lv_label_set_text(ai_messge_label_, new_content.c_str()); - } - else if(role=="user") - { - std::string new_content = "User:" + content; - lv_label_set_text(user_messge_label_, new_content.c_str()); - } - else{ - std::string new_content = "AI:"; - lv_label_set_text(ai_messge_label_, new_content.c_str()); - new_content="User:"; + } else if(role == "user") { + std::string new_content = "User: " + content; lv_label_set_text(user_messge_label_, new_content.c_str()); + } else{ + lv_label_set_text(ai_messge_label_, "AI: "); + lv_label_set_text(user_messge_label_, "User: "); } } + void SetupUI() override { DisplayLockGuard lock(this); @@ -97,23 +80,23 @@ public: lv_obj_set_style_text_font(emotion_label_, &font_awesome_30_1, 0); lv_label_set_text(emotion_label_, FONT_AWESOME_AI_CHIP); - lv_obj_align(emotion_label_,LV_ALIGN_TOP_MID, 0, -10); // 左侧居中,向右偏移10个单位 + lv_obj_align(emotion_label_, LV_ALIGN_TOP_MID, 0, -10); // 左侧居中,向右偏移10个单位 static lv_style_t style_msg; lv_style_init(&style_msg); - lv_style_set_width(&style_msg, LV_HOR_RES-25); + lv_style_set_width(&style_msg, LV_HOR_RES - 25); user_messge_label_ = lv_label_create(content_); lv_obj_set_style_text_font(user_messge_label_, &font_puhui_14_1, 0); - lv_label_set_text(user_messge_label_, "User:"); + lv_label_set_text(user_messge_label_, "User: "); lv_obj_add_style(user_messge_label_, &style_msg, 0); - lv_obj_align(user_messge_label_,LV_ALIGN_TOP_LEFT, 2, 25); + lv_obj_align(user_messge_label_, LV_ALIGN_TOP_LEFT, 2, 25); ai_messge_label_ = lv_label_create(content_); lv_obj_set_style_text_font(ai_messge_label_, &font_puhui_14_1, 0); - lv_label_set_text(ai_messge_label_, "AI:"); + lv_label_set_text(ai_messge_label_, "AI: "); lv_obj_add_style(ai_messge_label_, &style_msg, 0); - lv_obj_align(ai_messge_label_,LV_ALIGN_TOP_LEFT, 2, 77); + lv_obj_align(ai_messge_label_, LV_ALIGN_TOP_LEFT, 2, 77); } }; @@ -228,13 +211,6 @@ public: virtual Display* GetDisplay() override { return display_; } - - virtual bool GetBatteryLevel(int &level, bool& charging) override - { - charging = false; - level = 60; - return true; - }; }; DECLARE_BOARD(EspBox3Board); diff --git a/main/boards/lichuang-dev/lichuang_dev_board.cc b/main/boards/lichuang-dev/lichuang_dev_board.cc index 996e43bc..38e6e4e9 100644 --- a/main/boards/lichuang-dev/lichuang_dev_board.cc +++ b/main/boards/lichuang-dev/lichuang_dev_board.cc @@ -1,6 +1,6 @@ #include "wifi_board.h" #include "audio_codecs/box_audio_codec.h" -#include "display/st7789_display.h" +#include "display/lcd_display.h" #include "application.h" #include "button.h" #include "config.h" @@ -36,7 +36,7 @@ private: i2c_master_bus_handle_t i2c_bus_; i2c_master_dev_handle_t pca9557_handle_; Button boot_button_; - St7789Display* display_; + LcdDisplay* display_; Pca9557* pca9557_; void InitializeI2c() { @@ -115,7 +115,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 St7789Display(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new LcdDisplay(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 fbcad424..6226f4ae 100644 --- a/main/boards/m5stack-core-s3/m5stack_core_s3.cc +++ b/main/boards/m5stack-core-s3/m5stack_core_s3.cc @@ -1,9 +1,8 @@ #include "wifi_board.h" #include "audio_codecs/cores3_audio_codec.h" -#include "display/st7789_display.h" +#include "display/lcd_display.h" #include "application.h" #include "button.h" -#include "led.h" #include "config.h" #include "i2c_device.h" #include "iot/thing_manager.h" @@ -31,6 +30,18 @@ public: WriteReg(0x94, 33 - 5); WriteReg(0x95, 33 - 5); } + + int GetBatteryCurrentDirection() { + return (ReadReg(0x01) & 0b01100000) >> 5; + } + + bool IsCharging() { + return GetBatteryCurrentDirection() == 1; + } + + int GetBatteryLevel() { + return ReadReg(0xA4); + } }; class Aw9523 : public I2cDevice { @@ -103,7 +114,7 @@ private: Axp2101* axp2101_; Aw9523* aw9523_; Ft6336* ft6336_; - St7789Display* display_; + LcdDisplay* display_; Button boot_button_; void InitializeI2c() { @@ -227,7 +238,7 @@ private: esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY); esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y); - display_ = new St7789Display(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new LcdDisplay(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); } @@ -256,11 +267,6 @@ public: InitializeIot(); } - virtual Led* GetBuiltinLed() override { - static Led led(GPIO_NUM_NC); - return &led; - } - virtual AudioCodec* GetAudioCodec() override { static CoreS3AudioCodec* audio_codec = nullptr; if (audio_codec == nullptr) { @@ -276,6 +282,19 @@ public: return display_; } + virtual bool GetBatteryLevel(int &level, bool& charging) override { + static int last_level = 0; + static bool last_charging = false; + level = axp2101_->GetBatteryLevel(); + charging = axp2101_->IsCharging(); + if (level != last_level || charging != last_charging) { + last_level = level; + last_charging = charging; + ESP_LOGI(TAG, "Battery level: %d, charging: %d", level, charging); + } + return true; + } + Ft6336* GetTouchpad() { return ft6336_; } diff --git a/main/boards/magiclick-2p4/magiclick_2p4_board.cc b/main/boards/magiclick-2p4/magiclick_2p4_board.cc index 696738e6..ada53db7 100644 --- a/main/boards/magiclick-2p4/magiclick_2p4_board.cc +++ b/main/boards/magiclick-2p4/magiclick_2p4_board.cc @@ -1,9 +1,9 @@ #include "wifi_board.h" -#include "display/st7789_display.h" +#include "display/lcd_display.h" #include "audio_codecs/es8311_audio_codec.h" #include "application.h" #include "button.h" -#include "led.h" +#include "led/single_led.h" #include "config.h" #include #include @@ -17,7 +17,7 @@ class magiclick_2p4 : public WifiBoard { private: i2c_master_bus_handle_t codec_i2c_bus_; Button boot_button_; - St7789Display* display_; + LcdDisplay* display_; void InitializeCodecI2c() { // Initialize I2C peripheral @@ -39,7 +39,7 @@ private: void InitializeButtons() { boot_button_.OnClick([this]() { auto& app = Application::GetInstance(); - if (app.GetChatState() == kChatStateUnknown && !WifiStation::GetInstance().IsConnected()) { + if (app.GetDeviceState() == kDeviceStateUnknown && !WifiStation::GetInstance().IsConnected()) { ResetWifiConfiguration(); } }); @@ -57,6 +57,7 @@ private: gpio_set_direction(BUILTIN_LED_POWER, GPIO_MODE_OUTPUT); gpio_set_level(BUILTIN_LED_POWER, BUILTIN_LED_POWER_OUTPUT_INVERT ? 0 : 1); } + void InitializeSpi() { spi_bus_config_t buscfg = {}; buscfg.mosi_io_num = DISPLAY_SDA_PIN; @@ -68,7 +69,7 @@ private: ESP_ERROR_CHECK(spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO)); } - void InitializeSt7789Display(){ + void InitializeNv3023Display(){ esp_lcd_panel_io_handle_t panel_io = nullptr; esp_lcd_panel_handle_t panel = nullptr; // 液晶屏控制IO初始化 @@ -83,7 +84,7 @@ private: io_config.lcd_param_bits = 8; ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(SPI3_HOST, &io_config, &panel_io)); - // 初始化液晶屏驱动芯片ST7789 + // 初始化液晶屏驱动芯片NV3023 ESP_LOGD(TAG, "Install LCD driver"); esp_lcd_panel_dev_config_t panel_config = {}; panel_config.reset_gpio_num = DISPLAY_RST_PIN; @@ -99,7 +100,7 @@ private: esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY); esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y); ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel, true)); - display_ = new St7789Display(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT, + display_ = new LcdDisplay(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); } @@ -110,13 +111,11 @@ public: InitializeButtons(); InitializeLedPower(); InitializeSpi(); - InitializeSt7789Display(); + InitializeNv3023Display(); } - virtual Led* GetBuiltinLed() override { - // static Led led(BUILTIN_LED_GPIO,BUILTIN_LED_NUM); - static Led led(BUILTIN_LED_GPIO); - + virtual Led* GetLed() override { + static SingleLed led(BUILTIN_LED_GPIO); return &led; } diff --git a/main/display/st7789_display.cc b/main/display/lcd_display.cc similarity index 81% rename from main/display/st7789_display.cc rename to main/display/lcd_display.cc index 1daa67f4..a269cd4b 100644 --- a/main/display/st7789_display.cc +++ b/main/display/lcd_display.cc @@ -1,4 +1,4 @@ -#include "st7789_display.h" +#include "lcd_display.h" #include "font_awesome_symbols.h" #include @@ -6,21 +6,21 @@ #include #include -#define TAG "St7789Display" +#define TAG "LcdDisplay" #define LCD_LEDC_CH LEDC_CHANNEL_0 -#define ST7789_LVGL_TICK_PERIOD_MS 2 -#define ST7789_LVGL_TASK_MAX_DELAY_MS 20 -#define ST7789_LVGL_TASK_MIN_DELAY_MS 1 -#define ST7789_LVGL_TASK_STACK_SIZE (4 * 1024) -#define ST7789_LVGL_TASK_PRIORITY 10 +#define LCD_LVGL_TICK_PERIOD_MS 2 +#define LCD_LVGL_TASK_MAX_DELAY_MS 20 +#define LCD_LVGL_TASK_MIN_DELAY_MS 1 +#define LCD_LVGL_TASK_STACK_SIZE (4 * 1024) +#define LCD_LVGL_TASK_PRIORITY 10 LV_FONT_DECLARE(font_puhui_14_1); LV_FONT_DECLARE(font_awesome_30_1); LV_FONT_DECLARE(font_awesome_14_1); static lv_disp_drv_t disp_drv; -static void st7789_lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map) +static void lcd_lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map) { esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t)drv->user_data; int offsetx1 = area->x1; @@ -33,7 +33,7 @@ static void st7789_lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_c } /* Rotate display and touch, when rotated screen in LVGL. Called when driver parameters are updated. */ -static void st7789_lvgl_port_update_callback(lv_disp_drv_t *drv) +static void lcd_lvgl_port_update_callback(lv_disp_drv_t *drv) { esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t)drv->user_data; @@ -43,48 +43,28 @@ static void st7789_lvgl_port_update_callback(lv_disp_drv_t *drv) // Rotate LCD display esp_lcd_panel_swap_xy(panel_handle, false); esp_lcd_panel_mirror(panel_handle, true, false); -#if CONFIG_ST7789_LCD_TOUCH_ENABLED - // Rotate LCD touch - esp_lcd_touch_set_mirror_y(tp, false); - esp_lcd_touch_set_mirror_x(tp, false); -#endif break; case LV_DISP_ROT_90: // Rotate LCD display esp_lcd_panel_swap_xy(panel_handle, true); esp_lcd_panel_mirror(panel_handle, true, true); -#if CONFIG_ST7789_LCD_TOUCH_ENABLED - // Rotate LCD touch - esp_lcd_touch_set_mirror_y(tp, false); - esp_lcd_touch_set_mirror_x(tp, false); -#endif break; case LV_DISP_ROT_180: // Rotate LCD display esp_lcd_panel_swap_xy(panel_handle, false); esp_lcd_panel_mirror(panel_handle, false, true); -#if CONFIG_ST7789_LCD_TOUCH_ENABLED - // Rotate LCD touch - esp_lcd_touch_set_mirror_y(tp, false); - esp_lcd_touch_set_mirror_x(tp, false); -#endif break; case LV_DISP_ROT_270: // Rotate LCD display esp_lcd_panel_swap_xy(panel_handle, true); esp_lcd_panel_mirror(panel_handle, false, false); -#if CONFIG_ST7789_LCD_TOUCH_ENABLED - // Rotate LCD touch - esp_lcd_touch_set_mirror_y(tp, false); - esp_lcd_touch_set_mirror_x(tp, false); -#endif break; } } -void St7789Display::LvglTask() { +void LcdDisplay::LvglTask() { ESP_LOGI(TAG, "Starting LVGL task"); - uint32_t task_delay_ms = ST7789_LVGL_TASK_MAX_DELAY_MS; + uint32_t task_delay_ms = LCD_LVGL_TASK_MAX_DELAY_MS; while (1) { // Lock the mutex due to the LVGL APIs are not thread-safe @@ -93,20 +73,20 @@ void St7789Display::LvglTask() { task_delay_ms = lv_timer_handler(); Unlock(); } - if (task_delay_ms > ST7789_LVGL_TASK_MAX_DELAY_MS) + if (task_delay_ms > LCD_LVGL_TASK_MAX_DELAY_MS) { - task_delay_ms = ST7789_LVGL_TASK_MAX_DELAY_MS; + task_delay_ms = LCD_LVGL_TASK_MAX_DELAY_MS; } - else if (task_delay_ms < ST7789_LVGL_TASK_MIN_DELAY_MS) + else if (task_delay_ms < LCD_LVGL_TASK_MIN_DELAY_MS) { - task_delay_ms = ST7789_LVGL_TASK_MIN_DELAY_MS; + task_delay_ms = LCD_LVGL_TASK_MIN_DELAY_MS; } vTaskDelay(pdMS_TO_TICKS(task_delay_ms)); } } -St7789Display::St7789Display(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, +LcdDisplay::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) : panel_io_(panel_io), panel_(panel), backlight_pin_(backlight_pin), backlight_output_invert_(backlight_output_invert), @@ -147,8 +127,8 @@ St7789Display::St7789Display(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_h disp_drv.ver_res = height_; disp_drv.offset_x = offset_x_; disp_drv.offset_y = offset_y_; - disp_drv.flush_cb = st7789_lvgl_flush_cb; - disp_drv.drv_update_cb = st7789_lvgl_port_update_callback; + disp_drv.flush_cb = lcd_lvgl_flush_cb; + disp_drv.drv_update_cb = lcd_lvgl_port_update_callback; disp_drv.draw_buf = &disp_buf; disp_drv.user_data = panel_; @@ -158,7 +138,7 @@ St7789Display::St7789Display(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_h // Tick interface for LVGL (using esp_timer to generate 2ms periodic event) const esp_timer_create_args_t lvgl_tick_timer_args = { .callback = [](void* arg) { - lv_tick_inc(ST7789_LVGL_TICK_PERIOD_MS); + lv_tick_inc(LCD_LVGL_TICK_PERIOD_MS); }, .arg = NULL, .dispatch_method = ESP_TIMER_TASK, @@ -166,22 +146,22 @@ St7789Display::St7789Display(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_h .skip_unhandled_events = false }; ESP_ERROR_CHECK(esp_timer_create(&lvgl_tick_timer_args, &lvgl_tick_timer_)); - ESP_ERROR_CHECK(esp_timer_start_periodic(lvgl_tick_timer_, ST7789_LVGL_TICK_PERIOD_MS * 1000)); + ESP_ERROR_CHECK(esp_timer_start_periodic(lvgl_tick_timer_, LCD_LVGL_TICK_PERIOD_MS * 1000)); lvgl_mutex_ = xSemaphoreCreateRecursiveMutex(); assert(lvgl_mutex_ != nullptr); ESP_LOGI(TAG, "Create LVGL task"); xTaskCreate([](void *arg) { - static_cast(arg)->LvglTask(); + static_cast(arg)->LvglTask(); vTaskDelete(NULL); - }, "LVGL", ST7789_LVGL_TASK_STACK_SIZE, this, ST7789_LVGL_TASK_PRIORITY, NULL); + }, "LVGL", LCD_LVGL_TASK_STACK_SIZE, this, LCD_LVGL_TASK_PRIORITY, NULL); SetBacklight(100); SetupUI(); } -St7789Display::~St7789Display() { +LcdDisplay::~LcdDisplay() { ESP_ERROR_CHECK(esp_timer_stop(lvgl_tick_timer_)); ESP_ERROR_CHECK(esp_timer_delete(lvgl_tick_timer_)); @@ -207,7 +187,7 @@ St7789Display::~St7789Display() { vSemaphoreDelete(lvgl_mutex_); } -void St7789Display::InitializeBacklight(gpio_num_t backlight_pin) { +void LcdDisplay::InitializeBacklight(gpio_num_t backlight_pin) { if (backlight_pin == GPIO_NUM_NC) { return; } @@ -238,7 +218,7 @@ void St7789Display::InitializeBacklight(gpio_num_t backlight_pin) { ESP_ERROR_CHECK(ledc_channel_config(&backlight_channel)); } -void St7789Display::SetBacklight(uint8_t brightness) { +void LcdDisplay::SetBacklight(uint8_t brightness) { if (backlight_pin_ == GPIO_NUM_NC) { return; } @@ -254,18 +234,18 @@ void St7789Display::SetBacklight(uint8_t brightness) { ESP_ERROR_CHECK(ledc_update_duty(LEDC_LOW_SPEED_MODE, LCD_LEDC_CH)); } -bool St7789Display::Lock(int timeout_ms) { +bool LcdDisplay::Lock(int timeout_ms) { // Convert timeout in milliseconds to FreeRTOS ticks // If `timeout_ms` is set to 0, the program will block until the condition is met const TickType_t timeout_ticks = (timeout_ms == 0) ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms); return xSemaphoreTakeRecursive(lvgl_mutex_, timeout_ticks) == pdTRUE; } -void St7789Display::Unlock() { +void LcdDisplay::Unlock() { xSemaphoreGiveRecursive(lvgl_mutex_); } -void St7789Display::SetupUI() { +void LcdDisplay::SetupUI() { DisplayLockGuard lock(this); auto screen = lv_disp_get_scr_act(lv_disp_get_default()); @@ -336,7 +316,7 @@ void St7789Display::SetupUI() { lv_obj_set_style_text_font(battery_label_, &font_awesome_14_1, 0); } -void St7789Display::SetChatMessage(const std::string &role, const std::string &content) { +void LcdDisplay::SetChatMessage(const std::string &role, const std::string &content) { if (chat_message_label_ == nullptr) { return; } diff --git a/main/display/st7789_display.h b/main/display/lcd_display.h similarity index 85% rename from main/display/st7789_display.h rename to main/display/lcd_display.h index e053e344..67f6ad9c 100644 --- a/main/display/st7789_display.h +++ b/main/display/lcd_display.h @@ -1,5 +1,5 @@ -#ifndef ST7789_DISPLAY_H -#define ST7789_DISPLAY_H +#ifndef LCD_DISPLAY_H +#define LCD_DISPLAY_H #include "display.h" @@ -10,7 +10,7 @@ #include #include -class St7789Display : public Display { +class LcdDisplay : public Display { protected: esp_lcd_panel_io_handle_t panel_io_ = nullptr; esp_lcd_panel_handle_t panel_ = nullptr; @@ -39,12 +39,12 @@ protected: virtual void Unlock() override; public: - St7789Display(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, + 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); - ~St7789Display(); + ~LcdDisplay(); void SetChatMessage(const std::string &role, const std::string &content) override; }; -#endif // ST7789_DISPLAY_H +#endif // LCD_DISPLAY_H diff --git a/main/display/ssd1306_display.cc b/main/display/ssd1306_display.cc index 645a9f45..b2cc2ed5 100644 --- a/main/display/ssd1306_display.cc +++ b/main/display/ssd1306_display.cc @@ -35,7 +35,7 @@ Ssd1306Display::Ssd1306Display(void* i2c_master_handle, int width, int height, b .dc_low_on_data = 0, .disable_control_phase = 0, }, - .scl_speed_hz = 400 * 1000, + .scl_speed_hz = 100 * 1000, }; ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c_v2((i2c_master_bus_t*)i2c_master_handle, &io_config, &panel_io_));