diff --git a/main/boards/waveshare-p4-nano/esp32-p4-nano.cc b/main/boards/waveshare-p4-nano/esp32-p4-nano.cc index 507cdabf..daa69a50 100644 --- a/main/boards/waveshare-p4-nano/esp32-p4-nano.cc +++ b/main/boards/waveshare-p4-nano/esp32-p4-nano.cc @@ -17,13 +17,13 @@ #include #include #include - +#include +#include "esp_lcd_touch_gt911.h" #define TAG "WaveshareEsp32p4nano" LV_FONT_DECLARE(font_puhui_20_4); LV_FONT_DECLARE(font_awesome_20_4); -// TODO: Backlight control and i2c drive conflict, has not been resolved class CustomBacklight : public Backlight { public: CustomBacklight(i2c_master_bus_handle_t i2c_handle) @@ -70,7 +70,7 @@ private: i2c_master_bus_handle_t codec_i2c_bus_; Button boot_button_; LcdDisplay *display__; - // CustomBacklight *backlight_; + CustomBacklight *backlight_; void InitializeCodecI2c() { // Initialize I2C peripheral @@ -167,10 +167,40 @@ private: .icon_font = &font_awesome_20_4, .emoji_font = font_emoji_64_init(), }); - // backlight_ = new CustomBacklight(codec_i2c_bus_); - // backlight_->RestoreBrightness(); + backlight_ = new CustomBacklight(codec_i2c_bus_); + backlight_->RestoreBrightness(); + } + 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 = 0, + .mirror_x = 0, + .mirror_y = 0, + }, + }; + 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_GT911_CONFIG(); + tp_io_config.scl_speed_hz = 100 * 1000; + ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c(codec_i2c_bus_, &tp_io_config, &tp_io_handle)); + ESP_LOGI(TAG, "Initialize touch controller"); + ESP_ERROR_CHECK(esp_lcd_touch_new_i2c_gt911(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"); } - void InitializeButtons() { boot_button_.OnClick([this]() { auto& app = Application::GetInstance(); @@ -184,7 +214,7 @@ private: 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("Screen")); } public: @@ -193,6 +223,7 @@ public: InitializeCodecI2c(); InitializeIot(); InitializeLCD(); + InitializeTouch(); InitializeButtons(); } @@ -207,9 +238,9 @@ public: return display__; } - // virtual Backlight *GetBacklight() override { - // return backlight_; - // } + virtual Backlight *GetBacklight() override { + return backlight_; + } }; DECLARE_BOARD(WaveshareEsp32p4nano); diff --git a/main/display/lcd_display.cc b/main/display/lcd_display.cc index c5a66c33..3dd400ee 100644 --- a/main/display/lcd_display.cc +++ b/main/display/lcd_display.cc @@ -435,8 +435,11 @@ void LcdDisplay::SetupUI() { lv_obj_center(low_battery_label_); lv_obj_add_flag(low_battery_popup_, LV_OBJ_FLAG_HIDDEN); } - +#if CONFIG_IDF_TARGET_ESP32P4 +#define MAX_MESSAGES 40 +#else #define MAX_MESSAGES 20 +#endif void LcdDisplay::SetChatMessage(const char* role, const char* content) { DisplayLockGuard lock(this); if (content_ == nullptr) { diff --git a/main/idf_component.yml b/main/idf_component.yml index f9b7319f..b44561a4 100644 --- a/main/idf_component.yml +++ b/main/idf_component.yml @@ -19,6 +19,7 @@ dependencies: espressif/button: "~4.1.3" espressif/knob: "^1.0.0" espressif/esp_lcd_touch_ft5x06: "~1.0.7" + espressif/esp_lcd_touch_gt911: "^1" lvgl/lvgl: "~9.2.2" esp_lvgl_port: "~2.6.0" espressif/esp_io_expander_tca95xx_16bit: "^2.0.0" @@ -26,6 +27,15 @@ dependencies: version: "^1.0.0" rules: - if: 'idf_version >= "5.4.0"' + + waveshare/esp_lcd_jd9365_10_1: + version: "*" + rules: + - if: "target in [esp32p4]" + espressif/esp_wifi_remote: + version: "*" + rules: + - if: "target in [esp32p4]" ## Required IDF version idf: version: ">=5.3"