mirror of
https://github.com/78/xiaozhi-esp32.git
synced 2026-01-13 16:57:17 +08:00
* refactor: migrate camera module to esp-video library * refactor: migrate boards to esp-video API (1/2) * refactor: migrate boards to esp-video API (2/2) * fix: use ESP-IDF 5.5 * refactor: migrate the JPEG encoder to `esp_new_jpeg` * feat: add YUV422 support * feat: improve pixelformat and device selection process * feat: use ESP32-P4 Hardware JPEG Encoder
104 lines
2.8 KiB
C++
104 lines
2.8 KiB
C++
#include "wifi_board.h"
|
|
#include "codecs/no_audio_codec.h"
|
|
#include "system_reset.h"
|
|
#include "application.h"
|
|
#include "button.h"
|
|
#include "config.h"
|
|
#include "esp32_camera.h"
|
|
|
|
#include "led/gpio_led.h"
|
|
#include <wifi_station.h>
|
|
#include <esp_log.h>
|
|
#include <driver/i2c_master.h>
|
|
#include <driver/gpio.h>
|
|
|
|
#define TAG "DfrobotEsp32S3AiCam"
|
|
|
|
class DfrobotEsp32S3AiCam : public WifiBoard {
|
|
private:
|
|
Button boot_button_;
|
|
Esp32Camera* camera_;
|
|
|
|
void InitializeButtons() {
|
|
boot_button_.OnClick([this]() {
|
|
auto& app = Application::GetInstance();
|
|
if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) {
|
|
ResetWifiConfiguration();
|
|
}
|
|
app.ToggleChatState();
|
|
});
|
|
}
|
|
|
|
void InitializeCamera() {
|
|
static esp_cam_ctlr_dvp_pin_config_t dvp_pin_config = {
|
|
.data_width = CAM_CTLR_DATA_WIDTH_8,
|
|
.data_io = {
|
|
[0] = CAMERA_PIN_D0,
|
|
[1] = CAMERA_PIN_D1,
|
|
[2] = CAMERA_PIN_D2,
|
|
[3] = CAMERA_PIN_D3,
|
|
[4] = CAMERA_PIN_D4,
|
|
[5] = CAMERA_PIN_D5,
|
|
[6] = CAMERA_PIN_D6,
|
|
[7] = CAMERA_PIN_D7,
|
|
},
|
|
.vsync_io = CAMERA_PIN_VSYNC,
|
|
.de_io = CAMERA_PIN_HREF,
|
|
.pclk_io = CAMERA_PIN_PCLK,
|
|
.xclk_io = CAMERA_PIN_XCLK,
|
|
};
|
|
|
|
esp_video_init_sccb_config_t sccb_config = {
|
|
.init_sccb = true,
|
|
.i2c_config = {
|
|
.port = 1,
|
|
.scl_pin = CAMERA_PIN_SIOC,
|
|
.sda_pin = CAMERA_PIN_SIOD,
|
|
},
|
|
.freq = 100000,
|
|
};
|
|
|
|
esp_video_init_dvp_config_t dvp_config = {
|
|
.sccb_config = sccb_config,
|
|
.reset_pin = CAMERA_PIN_RESET,
|
|
.pwdn_pin = CAMERA_PIN_PWDN,
|
|
.dvp_pin = dvp_pin_config,
|
|
.xclk_freq = XCLK_FREQ_HZ,
|
|
};
|
|
|
|
esp_video_init_config_t video_config = {
|
|
.dvp = &dvp_config,
|
|
};
|
|
|
|
camera_ = new Esp32Camera(video_config);
|
|
camera_->SetVFlip(1);
|
|
}
|
|
|
|
public:
|
|
DfrobotEsp32S3AiCam() :
|
|
boot_button_(BOOT_BUTTON_GPIO) {
|
|
InitializeButtons();
|
|
InitializeCamera();
|
|
}
|
|
|
|
// Wakenet model only
|
|
|
|
virtual Led* GetLed() override {
|
|
static GpioLed led(BUILTIN_LED_GPIO, 0);
|
|
return &led;
|
|
}
|
|
|
|
virtual AudioCodec* GetAudioCodec() override {
|
|
static NoAudioCodecSimplexPdm audio_codec(AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
|
|
AUDIO_I2S_SPK_GPIO_BCLK, AUDIO_I2S_SPK_GPIO_LRCK, AUDIO_I2S_SPK_GPIO_DOUT,
|
|
AUDIO_I2S_MIC_GPIO_SCK, AUDIO_I2S_MIC_GPIO_DIN);
|
|
return &audio_codec;
|
|
}
|
|
|
|
virtual Camera* GetCamera() override {
|
|
return camera_;
|
|
}
|
|
};
|
|
|
|
DECLARE_BOARD(DfrobotEsp32S3AiCam);
|