diff --git a/main/boards/df-k10/config.h b/main/boards/df-k10/config.h index a0eaa648..c61c86f5 100644 --- a/main/boards/df-k10/config.h +++ b/main/boards/df-k10/config.h @@ -41,5 +41,36 @@ #define DISPLAY_BACKLIGHT_PIN GPIO_NUM_NC #define DISPLAY_BACKLIGHT_OUTPUT_INVERT false +/* DFRobot K10 Camera pins */ +#define PWDN_GPIO_NUM -1 +#define RESET_GPIO_NUM -1 +#define XCLK_GPIO_NUM 7 + +#define VSYNC_GPIO_NUM 4 +#define HREF_GPIO_NUM 5 +#define PCLK_GPIO_NUM 17 +#define SIOD_GPIO_NUM 20 +#define SIOC_GPIO_NUM 19 + +/* Camera pins */ +#define CAMERA_PIN_PWDN PWDN_GPIO_NUM +#define CAMERA_PIN_RESET RESET_GPIO_NUM +#define CAMERA_PIN_XCLK XCLK_GPIO_NUM +#define CAMERA_PIN_SIOD SIOD_GPIO_NUM +#define CAMERA_PIN_SIOC SIOC_GPIO_NUM + +#define CAMERA_PIN_D9 6 +#define CAMERA_PIN_D8 15 +#define CAMERA_PIN_D7 16 +#define CAMERA_PIN_D6 18 +#define CAMERA_PIN_D5 9 +#define CAMERA_PIN_D4 11 +#define CAMERA_PIN_D3 10 +#define CAMERA_PIN_D2 8 +#define CAMERA_PIN_VSYNC VSYNC_GPIO_NUM +#define CAMERA_PIN_HREF HREF_GPIO_NUM +#define CAMERA_PIN_PCLK PCLK_GPIO_NUM + +#define XCLK_FREQ_HZ 20000000 #endif // _BOARD_CONFIG_H_ diff --git a/main/boards/df-k10/config.json b/main/boards/df-k10/config.json index 55137d40..0ead8f10 100644 --- a/main/boards/df-k10/config.json +++ b/main/boards/df-k10/config.json @@ -4,7 +4,8 @@ { "name": "df-k10", "sdkconfig_append": [ - "CONFIG_SPIRAM_MODE_OCT=y" + "CONFIG_SPIRAM_MODE_OCT=y", + "CONFIG_IOT_PROTOCOL_MCP=y" ] } ] diff --git a/main/boards/df-k10/df_k10_board.cc b/main/boards/df-k10/df_k10_board.cc index c6d27f5b..f5543840 100644 --- a/main/boards/df-k10/df_k10_board.cc +++ b/main/boards/df-k10/df_k10_board.cc @@ -7,6 +7,8 @@ #include "button.h" #include "config.h" #include "iot/thing_manager.h" +#include "esp32_camera.h" + #include "led/circular_strip.h" #include "assets/lang_config.h" @@ -30,6 +32,8 @@ private: LcdDisplay *display_; button_handle_t btn_a; button_handle_t btn_b; + Esp32Camera* camera_; + button_driver_t* btn_a_driver_ = nullptr; button_driver_t* btn_b_driver_ = nullptr; @@ -163,6 +167,40 @@ private: }, this); } + void InitializeCamera() { + + camera_config_t config = {}; + config.ledc_channel = LEDC_CHANNEL_2; // LEDC通道选择 用于生成XCLK时钟 但是S3不用 + config.ledc_timer = LEDC_TIMER_2; // LEDC timer选择 用于生成XCLK时钟 但是S3不用 + config.pin_d0 = CAMERA_PIN_D2; + config.pin_d1 = CAMERA_PIN_D3; + config.pin_d2 = CAMERA_PIN_D4; + config.pin_d3 = CAMERA_PIN_D5; + config.pin_d4 = CAMERA_PIN_D6; + config.pin_d5 = CAMERA_PIN_D7; + config.pin_d6 = CAMERA_PIN_D8; + config.pin_d7 = CAMERA_PIN_D9; + config.pin_xclk = CAMERA_PIN_XCLK; + config.pin_pclk = CAMERA_PIN_PCLK; + config.pin_vsync = CAMERA_PIN_VSYNC; + config.pin_href = CAMERA_PIN_HREF; + config.pin_sccb_sda = -1; // 这里如果写-1 表示使用已经初始化的I2C接口 + config.pin_sccb_scl = CAMERA_PIN_SIOC; + config.sccb_i2c_port = 1; // 这里如果写1 默认使用I2C1 + config.pin_pwdn = CAMERA_PIN_PWDN; + config.pin_reset = CAMERA_PIN_RESET; + config.xclk_freq_hz = XCLK_FREQ_HZ; + config.pixel_format = PIXFORMAT_RGB565; + config.frame_size = FRAMESIZE_VGA; + config.jpeg_quality = 12; + config.fb_count = 1; + config.fb_location = CAMERA_FB_IN_PSRAM; + config.grab_mode = CAMERA_GRAB_WHEN_EMPTY; + + camera_ = new Esp32Camera(config); + camera_->SetVFlip(1); + } + void InitializeIli9341Display() { esp_lcd_panel_io_handle_t panel_io = nullptr; esp_lcd_panel_handle_t panel = nullptr; @@ -217,6 +255,12 @@ public: InitializeIli9341Display(); InitializeButtons(); InitializeIot(); + InitializeCamera(); + +#if CONFIG_IOT_PROTOCOL_XIAOZHI + auto& thing_manager = iot::ThingManager::GetInstance(); + thing_manager.AddThing(iot::CreateThing("Speaker")); +#endif } virtual Led* GetLed() override { @@ -241,6 +285,10 @@ public: return &audio_codec; } + virtual Camera* GetCamera() override { + return camera_; + } + virtual Display *GetDisplay() override { return display_; }