diff --git a/main/boards/esp32-s3-touch-lcd-3.5/config.h b/main/boards/esp32-s3-touch-lcd-3.5/config.h index 91e9821b..78529040 100644 --- a/main/boards/esp32-s3-touch-lcd-3.5/config.h +++ b/main/boards/esp32-s3-touch-lcd-3.5/config.h @@ -47,4 +47,23 @@ #define DISPLAY_BACKLIGHT_PIN GPIO_NUM_6 #define DISPLAY_BACKLIGHT_OUTPUT_INVERT false + +#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/esp32-s3-touch-lcd-3.5/config.json b/main/boards/esp32-s3-touch-lcd-3.5/config.json index 81906aaf..45e34fa5 100644 --- a/main/boards/esp32-s3-touch-lcd-3.5/config.json +++ b/main/boards/esp32-s3-touch-lcd-3.5/config.json @@ -3,7 +3,9 @@ "builds": [ { "name": "esp32-s3-touch-lcd-3.5", - "sdkconfig_append": [] + "sdkconfig_append": [ + "CONFIG_USE_WECHAT_MESSAGE_STYLE=y" + ] } ] } \ No newline at end of file diff --git a/main/boards/esp32-s3-touch-lcd-3.5/esp32-s3-touch-lcd-3.5.cc b/main/boards/esp32-s3-touch-lcd-3.5/esp32-s3-touch-lcd-3.5.cc index b7747aee..41e9b139 100644 --- a/main/boards/esp32-s3-touch-lcd-3.5/esp32-s3-touch-lcd-3.5.cc +++ b/main/boards/esp32-s3-touch-lcd-3.5/esp32-s3-touch-lcd-3.5.cc @@ -22,6 +22,10 @@ #include "axp2101.h" #include "power_save_timer.h" +#include +#include + +#include "esp32_camera.h" #define TAG "waveshare_lcd_3_5" @@ -47,9 +51,12 @@ class Pmic : public Axp2101 { // Set ALDO1 to 3.3V WriteReg(0x92, (3300 - 500) / 100); + + WriteReg(0x96, (1500 - 500) / 100); + WriteReg(0x97, (2800 - 500) / 100); - // Enable ALDO1(MIC) - WriteReg(0x90, 0x01); + // Enable ALDO1 BLDO1 BLDO2 + WriteReg(0x90, 0x31); WriteReg(0x64, 0x02); // CV charger voltage setting to 4.1V @@ -108,6 +115,7 @@ private: 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); @@ -133,10 +141,16 @@ private: void InitializeI2c() { // Initialize I2C peripheral i2c_master_bus_config_t i2c_bus_cfg = { - .i2c_port = (i2c_port_t)0, + .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_)); } @@ -145,14 +159,14 @@ private: { 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"); + 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_1, 0); + 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_0 | IO_EXPANDER_PIN_NUM_1, 1); + ret = esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_1, 1); ESP_ERROR_CHECK(ret); } @@ -172,6 +186,86 @@ private: buscfg.max_transfer_sz = DISPLAY_WIDTH * DISPLAY_HEIGHT * sizeof(uint16_t); ESP_ERROR_CHECK(spi_bus_initialize(SPI3_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 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_FT5x06_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_ft5x06(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 InitializeLcdDisplay() { esp_lcd_panel_io_handle_t panel_io = nullptr; @@ -258,7 +352,9 @@ public: fflush(stdout); esp_restart(); } + InitializeTouch(); InitializeButtons(); + InitializeCamera(); InitializeTools(); GetBacklight()->RestoreBrightness(); } @@ -297,6 +393,10 @@ public: } WifiBoard::SetPowerSaveMode(enabled); } + + virtual Camera* GetCamera() override { + return camera_; + } }; DECLARE_BOARD(CustomBoard);