From c87b1eabf4ad7b2dd0429e7d64facd7c7557b134 Mon Sep 17 00:00:00 2001 From: Y1hsiaochunnn <66012385+Y1hsiaochunnn@users.noreply.github.com> Date: Sat, 22 Nov 2025 15:37:22 +0800 Subject: [PATCH] Add Camera support for Waveshare's ESP32-P4 series development board (#1459) * Add Camera support to Waveshare's ESP32-P4 series development board * Fix i2c handle error --- main/boards/waveshare-p4-nano/config.json | 6 ++++- .../boards/waveshare-p4-nano/esp32-p4-nano.cc | 27 +++++++++++++++++++ .../config.json | 6 ++++- .../esp32-p4-wifi6-touch-lcd-4b.cc | 27 +++++++++++++++++++ .../config.json | 6 ++++- .../esp32-p4-wifi6-touch-lcd-7b.cc | 27 +++++++++++++++++++ .../config.json | 12 +++++++-- .../esp32-p4-wifi6-touch-lcd-xc.cc | 27 +++++++++++++++++++ 8 files changed, 133 insertions(+), 5 deletions(-) diff --git a/main/boards/waveshare-p4-nano/config.json b/main/boards/waveshare-p4-nano/config.json index e63c711b..832dee1c 100644 --- a/main/boards/waveshare-p4-nano/config.json +++ b/main/boards/waveshare-p4-nano/config.json @@ -5,7 +5,11 @@ "name": "waveshare-p4-nano-10.1-a", "sdkconfig_append": [ "CONFIG_USE_WECHAT_MESSAGE_STYLE=y", - "CONFIG_LCD_TYPE_800_1280_10_1_INCH_A=y" + "CONFIG_LCD_TYPE_800_1280_10_1_INCH_A=y", + "CONFIG_CAMERA_OV5647=y", + "CONFIG_CAMERA_OV5647_AUTO_DETECT_MIPI_INTERFACE_SENSOR=y", + "CONFIG_CAMERA_OV5647_MIPI_RAW8_800X800_50FPS=y", + "CONFIG_XIAOZHI_ENABLE_CAMERA_ENDIANNESS_SWAP=y" ] } ] diff --git a/main/boards/waveshare-p4-nano/esp32-p4-nano.cc b/main/boards/waveshare-p4-nano/esp32-p4-nano.cc index f2e822bb..9a87981e 100644 --- a/main/boards/waveshare-p4-nano/esp32-p4-nano.cc +++ b/main/boards/waveshare-p4-nano/esp32-p4-nano.cc @@ -6,6 +6,10 @@ #include "button.h" #include "config.h" +#include "esp32_camera.h" +#include "esp_video_init.h" +#include "esp_cam_sensor_xclk.h" + #include "esp_lcd_panel_ops.h" #include "esp_lcd_mipi_dsi.h" #include "esp_ldo_regulator.h" @@ -66,6 +70,7 @@ private: i2c_master_bus_handle_t codec_i2c_bus_; Button boot_button_; LcdDisplay *display__; + Esp32Camera* camera_ = nullptr; CustomBacklight *backlight_; void InitializeCodecI2c() { @@ -196,6 +201,23 @@ private: lvgl_port_add_touch(&touch_cfg); ESP_LOGI(TAG, "Touch panel initialized successfully"); } + void InitializeCamera() { + esp_video_init_csi_config_t base_csi_config = { + .sccb_config = { + .init_sccb = false, + .i2c_handle = codec_i2c_bus_, + .freq = 400000, + }, + .reset_pin = GPIO_NUM_NC, + .pwdn_pin = GPIO_NUM_NC, + }; + + esp_video_init_config_t cam_config = { + .csi = &base_csi_config, + }; + + camera_ = new Esp32Camera(cam_config); + } void InitializeButtons() { boot_button_.OnClick([this]() { auto& app = Application::GetInstance(); @@ -211,6 +233,7 @@ public: InitializeCodecI2c(); InitializeLCD(); InitializeTouch(); + InitializeCamera(); InitializeButtons(); } @@ -225,6 +248,10 @@ public: return display__; } + virtual Camera* GetCamera() override { + return camera_; + } + virtual Backlight *GetBacklight() override { return backlight_; } diff --git a/main/boards/waveshare-p4-wifi6-touch-lcd-4b/config.json b/main/boards/waveshare-p4-wifi6-touch-lcd-4b/config.json index edcb9856..5a8dbb53 100644 --- a/main/boards/waveshare-p4-wifi6-touch-lcd-4b/config.json +++ b/main/boards/waveshare-p4-wifi6-touch-lcd-4b/config.json @@ -5,7 +5,11 @@ "name": "waveshare-p4-wifi6-touch-lcd-4b", "sdkconfig_append": [ "CONFIG_USE_WECHAT_MESSAGE_STYLE=n", - "CONFIG_USE_DEVICE_AEC=y" + "CONFIG_USE_DEVICE_AEC=y", + "CONFIG_CAMERA_OV5647=y", + "CONFIG_CAMERA_OV5647_AUTO_DETECT_MIPI_INTERFACE_SENSOR=y", + "CONFIG_CAMERA_OV5647_MIPI_RAW8_800X800_50FPS=y", + "CONFIG_XIAOZHI_ENABLE_CAMERA_ENDIANNESS_SWAP=y" ] } ] diff --git a/main/boards/waveshare-p4-wifi6-touch-lcd-4b/esp32-p4-wifi6-touch-lcd-4b.cc b/main/boards/waveshare-p4-wifi6-touch-lcd-4b/esp32-p4-wifi6-touch-lcd-4b.cc index 26637ce0..68a29473 100644 --- a/main/boards/waveshare-p4-wifi6-touch-lcd-4b/esp32-p4-wifi6-touch-lcd-4b.cc +++ b/main/boards/waveshare-p4-wifi6-touch-lcd-4b/esp32-p4-wifi6-touch-lcd-4b.cc @@ -6,6 +6,10 @@ #include "button.h" #include "config.h" +#include "esp32_camera.h" +#include "esp_video_init.h" +#include "esp_cam_sensor_xclk.h" + #include "esp_lcd_panel_ops.h" #include "esp_lcd_mipi_dsi.h" #include "esp_ldo_regulator.h" @@ -24,6 +28,7 @@ private: i2c_master_bus_handle_t i2c_bus_; Button boot_button_; LcdDisplay *display_; + Esp32Camera* camera_ = nullptr; void InitializeCodecI2c() { // Initialize I2C peripheral @@ -149,6 +154,23 @@ private: lvgl_port_add_touch(&touch_cfg); ESP_LOGI(TAG, "Touch panel initialized successfully"); } + void InitializeCamera() { + esp_video_init_csi_config_t base_csi_config = { + .sccb_config = { + .init_sccb = false, + .i2c_handle = i2c_bus_, + .freq = 400000, + }, + .reset_pin = GPIO_NUM_NC, + .pwdn_pin = GPIO_NUM_NC, + }; + + esp_video_init_config_t cam_config = { + .csi = &base_csi_config, + }; + + camera_ = new Esp32Camera(cam_config); + } void InitializeButtons() { boot_button_.OnClick([this]() { auto& app = Application::GetInstance(); @@ -164,6 +186,7 @@ public: InitializeCodecI2c(); InitializeLCD(); InitializeTouch(); + InitializeCamera(); InitializeButtons(); GetBacklight()->RestoreBrightness(); } @@ -189,6 +212,10 @@ public: return display_; } + virtual Camera* GetCamera() override { + return camera_; + } + virtual Backlight* GetBacklight() override { static PwmBacklight backlight(DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT); return &backlight; diff --git a/main/boards/waveshare-p4-wifi6-touch-lcd-7b/config.json b/main/boards/waveshare-p4-wifi6-touch-lcd-7b/config.json index 4bd6f37d..8f84bf9d 100644 --- a/main/boards/waveshare-p4-wifi6-touch-lcd-7b/config.json +++ b/main/boards/waveshare-p4-wifi6-touch-lcd-7b/config.json @@ -5,7 +5,11 @@ "name": "waveshare-p4-wifi6-touch-lcd-7b", "sdkconfig_append": [ "CONFIG_USE_WECHAT_MESSAGE_STYLE=n", - "CONFIG_USE_DEVICE_AEC=y" + "CONFIG_USE_DEVICE_AEC=y", + "CONFIG_CAMERA_OV5647=y", + "CONFIG_CAMERA_OV5647_AUTO_DETECT_MIPI_INTERFACE_SENSOR=y", + "CONFIG_CAMERA_OV5647_MIPI_RAW8_800X800_50FPS=y", + "CONFIG_XIAOZHI_ENABLE_CAMERA_ENDIANNESS_SWAP=y" ] } ] diff --git a/main/boards/waveshare-p4-wifi6-touch-lcd-7b/esp32-p4-wifi6-touch-lcd-7b.cc b/main/boards/waveshare-p4-wifi6-touch-lcd-7b/esp32-p4-wifi6-touch-lcd-7b.cc index f83b6c5c..e01cb3d2 100644 --- a/main/boards/waveshare-p4-wifi6-touch-lcd-7b/esp32-p4-wifi6-touch-lcd-7b.cc +++ b/main/boards/waveshare-p4-wifi6-touch-lcd-7b/esp32-p4-wifi6-touch-lcd-7b.cc @@ -6,6 +6,10 @@ #include "button.h" #include "config.h" +#include "esp32_camera.h" +#include "esp_video_init.h" +#include "esp_cam_sensor_xclk.h" + #include "esp_lcd_panel_ops.h" #include "esp_lcd_mipi_dsi.h" #include "esp_ldo_regulator.h" @@ -24,6 +28,7 @@ private: i2c_master_bus_handle_t i2c_bus_; Button boot_button_; LcdDisplay *display_; + Esp32Camera* camera_ = nullptr; void InitializeCodecI2c() { // Initialize I2C peripheral @@ -153,6 +158,23 @@ private: lvgl_port_add_touch(&touch_cfg); ESP_LOGI(TAG, "Touch panel initialized successfully"); } + void InitializeCamera() { + esp_video_init_csi_config_t base_csi_config = { + .sccb_config = { + .init_sccb = false, + .i2c_handle = i2c_bus_, + .freq = 400000, + }, + .reset_pin = GPIO_NUM_NC, + .pwdn_pin = GPIO_NUM_NC, + }; + + esp_video_init_config_t cam_config = { + .csi = &base_csi_config, + }; + + camera_ = new Esp32Camera(cam_config); + } void InitializeButtons() { boot_button_.OnClick([this]() { auto& app = Application::GetInstance(); @@ -168,6 +190,7 @@ public: InitializeCodecI2c(); InitializeLCD(); InitializeTouch(); + InitializeCamera(); InitializeButtons(); GetBacklight()->RestoreBrightness(); } @@ -193,6 +216,10 @@ public: return display_; } + virtual Camera* GetCamera() override { + return camera_; + } + virtual Backlight* GetBacklight() override { static PwmBacklight backlight(DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT); return &backlight; diff --git a/main/boards/waveshare-p4-wifi6-touch-lcd-xc/config.json b/main/boards/waveshare-p4-wifi6-touch-lcd-xc/config.json index 6b22e72a..927bb971 100644 --- a/main/boards/waveshare-p4-wifi6-touch-lcd-xc/config.json +++ b/main/boards/waveshare-p4-wifi6-touch-lcd-xc/config.json @@ -6,7 +6,11 @@ "sdkconfig_append": [ "CONFIG_USE_WECHAT_MESSAGE_STYLE=n", "CONFIG_USE_DEVICE_AEC=y", - "CONFIG_LCD_TYPE_800_800_3_4_INCH=y" + "CONFIG_LCD_TYPE_800_800_3_4_INCH=y", + "CONFIG_CAMERA_OV5647=y", + "CONFIG_CAMERA_OV5647_AUTO_DETECT_MIPI_INTERFACE_SENSOR=y", + "CONFIG_CAMERA_OV5647_MIPI_RAW8_800X800_50FPS=y", + "CONFIG_XIAOZHI_ENABLE_CAMERA_ENDIANNESS_SWAP=y" ] }, { @@ -14,7 +18,11 @@ "sdkconfig_append": [ "CONFIG_USE_WECHAT_MESSAGE_STYLE=n", "CONFIG_USE_DEVICE_AEC=y", - "CONFIG_LCD_TYPE_720_720_4_INCH=y" + "CONFIG_LCD_TYPE_720_720_4_INCH=y", + "CONFIG_CAMERA_OV5647=y", + "CONFIG_CAMERA_OV5647_AUTO_DETECT_MIPI_INTERFACE_SENSOR=y", + "CONFIG_CAMERA_OV5647_MIPI_RAW8_800X800_50FPS=y", + "CONFIG_XIAOZHI_ENABLE_CAMERA_ENDIANNESS_SWAP=y" ] } ] diff --git a/main/boards/waveshare-p4-wifi6-touch-lcd-xc/esp32-p4-wifi6-touch-lcd-xc.cc b/main/boards/waveshare-p4-wifi6-touch-lcd-xc/esp32-p4-wifi6-touch-lcd-xc.cc index 2a2b0c9a..94cff602 100644 --- a/main/boards/waveshare-p4-wifi6-touch-lcd-xc/esp32-p4-wifi6-touch-lcd-xc.cc +++ b/main/boards/waveshare-p4-wifi6-touch-lcd-xc/esp32-p4-wifi6-touch-lcd-xc.cc @@ -5,6 +5,10 @@ // #include "display/no_display.h" #include "button.h" +#include "esp32_camera.h" +#include "esp_video_init.h" +#include "esp_cam_sensor_xclk.h" + #include "esp_lcd_panel_ops.h" #include "esp_lcd_mipi_dsi.h" #include "esp_ldo_regulator.h" @@ -24,6 +28,7 @@ private: i2c_master_bus_handle_t i2c_bus_; Button boot_button_; LcdDisplay *display_; + Esp32Camera* camera_ = nullptr; void InitializeCodecI2c() { // Initialize I2C peripheral @@ -151,6 +156,23 @@ private: lvgl_port_add_touch(&touch_cfg); ESP_LOGI(TAG, "Touch panel initialized successfully"); } + void InitializeCamera() { + esp_video_init_csi_config_t base_csi_config = { + .sccb_config = { + .init_sccb = false, + .i2c_handle = i2c_bus_, + .freq = 400000, + }, + .reset_pin = GPIO_NUM_NC, + .pwdn_pin = GPIO_NUM_NC, + }; + + esp_video_init_config_t cam_config = { + .csi = &base_csi_config, + }; + + camera_ = new Esp32Camera(cam_config); + } void InitializeButtons() { boot_button_.OnClick([this]() { auto& app = Application::GetInstance(); @@ -166,6 +188,7 @@ public: InitializeCodecI2c(); InitializeLCD(); InitializeTouch(); + InitializeCamera(); InitializeButtons(); GetBacklight()->RestoreBrightness(); } @@ -191,6 +214,10 @@ public: return display_; } + virtual Camera* GetCamera() override { + return camera_; + } + virtual Backlight* GetBacklight() override { static PwmBacklight backlight(DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT); return &backlight;