Skip to content

Commit cbb5a7c

Browse files
committed
refactor: migrate boards to esp-video API (2/2)
1 parent f5133d1 commit cbb5a7c

File tree

12 files changed

+482
-400
lines changed

12 files changed

+482
-400
lines changed

main/boards/atk-dnesp32s3/atk_dnesp32s3.cc

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -133,58 +133,53 @@ class atk_dnesp32s3 : public WifiBoard {
133133
// 初始化摄像头:ov2640;
134134
// 根据正点原子官方示例参数
135135
void InitializeCamera() {
136-
137136
xl9555_->SetOutputState(OV_PWDN_IO, 0); // PWDN=低 (上电)
138137
xl9555_->SetOutputState(OV_RESET_IO, 0); // 确保复位
139138
vTaskDelay(pdMS_TO_TICKS(50)); // 延长复位保持时间
140139
xl9555_->SetOutputState(OV_RESET_IO, 1); // 释放复位
141140
vTaskDelay(pdMS_TO_TICKS(50)); // 延长 50ms
142141

143-
camera_config_t config = {};
144-
145-
config.pin_pwdn = CAM_PIN_PWDN; // 实际由 XL9555 控制
146-
config.pin_reset = CAM_PIN_RESET;// 实际由 XL9555 控制
147-
config.pin_xclk = CAM_PIN_XCLK;
148-
config.pin_sccb_sda = CAM_PIN_SIOD;
149-
config.pin_sccb_scl = CAM_PIN_SIOC;
150-
151-
config.pin_d7 = CAM_PIN_D7;
152-
config.pin_d6 = CAM_PIN_D6;
153-
config.pin_d5 = CAM_PIN_D5;
154-
config.pin_d4 = CAM_PIN_D4;
155-
config.pin_d3 = CAM_PIN_D3;
156-
config.pin_d2 = CAM_PIN_D2;
157-
config.pin_d1 = CAM_PIN_D1;
158-
config.pin_d0 = CAM_PIN_D0;
159-
config.pin_vsync = CAM_PIN_VSYNC;
160-
config.pin_href = CAM_PIN_HREF;
161-
config.pin_pclk = CAM_PIN_PCLK;
162-
163-
/* XCLK 20MHz or 10MHz for OV2640 double FPS (Experimental) */
164-
config.xclk_freq_hz = 24000000;
165-
config.ledc_timer = LEDC_TIMER_0;
166-
config.ledc_channel = LEDC_CHANNEL_0;
167-
168-
config.pixel_format = PIXFORMAT_RGB565; /* YUV422,GRAYSCALE,RGB565,JPEG */
169-
config.frame_size = FRAMESIZE_QVGA; /* 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 */
170-
171-
config.jpeg_quality = 12; /* 0-63, for OV series camera sensors, lower number means higher quality */
172-
config.fb_count = 2; /* When jpeg mode is used, if fb_count more than one, the driver will work in continuous mode */
173-
config.fb_location = CAMERA_FB_IN_PSRAM;
174-
config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
175-
176-
esp_err_t err = esp_camera_init(&config); // 测试相机是否存在
177-
if (err != ESP_OK) {
178-
ESP_LOGE(TAG, "Camera is not plugged in or not supported, error: %s", esp_err_to_name(err));
179-
// 如果摄像头初始化失败,设置 camera_ 为 nullptr
180-
camera_ = nullptr;
181-
return;
182-
}else
183-
{
184-
esp_camera_deinit();// 释放之前的摄像头资源,为正确初始化做准备
185-
camera_ = new Esp32Camera(config);
186-
}
187-
142+
static esp_cam_ctlr_dvp_pin_config_t dvp_pin_config = {
143+
.data_width = CAM_CTLR_DATA_WIDTH_8,
144+
.data_io = {
145+
[0] = CAM_PIN_D0,
146+
[1] = CAM_PIN_D1,
147+
[2] = CAM_PIN_D2,
148+
[3] = CAM_PIN_D3,
149+
[4] = CAM_PIN_D4,
150+
[5] = CAM_PIN_D5,
151+
[6] = CAM_PIN_D6,
152+
[7] = CAM_PIN_D7,
153+
},
154+
.vsync_io = CAM_PIN_VSYNC,
155+
.de_io = CAM_PIN_HREF,
156+
.pclk_io = CAM_PIN_PCLK,
157+
.xclk_io = CAM_PIN_XCLK,
158+
};
159+
160+
esp_video_init_sccb_config_t sccb_config = {
161+
.init_sccb = true,
162+
.i2c_config = {
163+
.port = 1,
164+
.scl_pin = CAM_PIN_SIOC,
165+
.sda_pin = CAM_PIN_SIOD,
166+
},
167+
.freq = 100000,
168+
};
169+
170+
esp_video_init_dvp_config_t dvp_config = {
171+
.sccb_config = sccb_config,
172+
.reset_pin = CAM_PIN_RESET, // 实际由 XL9555 控制
173+
.pwdn_pin = CAM_PIN_PWDN, // 实际由 XL9555 控制
174+
.dvp_pin = dvp_pin_config,
175+
.xclk_freq = 24000000,
176+
};
177+
178+
esp_video_init_config_t video_config = {
179+
.dvp = &dvp_config,
180+
};
181+
182+
camera_ = new Esp32Camera(video_config);
188183
}
189184

190185
public:

main/boards/bread-compact-wifi-s3cam/compact_wifi_board_s3cam.cc

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -126,32 +126,47 @@ class CompactWifiBoardS3Cam : public WifiBoard {
126126
}
127127

128128
void InitializeCamera() {
129-
camera_config_t config = {};
130-
config.pin_d0 = CAMERA_PIN_D0;
131-
config.pin_d1 = CAMERA_PIN_D1;
132-
config.pin_d2 = CAMERA_PIN_D2;
133-
config.pin_d3 = CAMERA_PIN_D3;
134-
config.pin_d4 = CAMERA_PIN_D4;
135-
config.pin_d5 = CAMERA_PIN_D5;
136-
config.pin_d6 = CAMERA_PIN_D6;
137-
config.pin_d7 = CAMERA_PIN_D7;
138-
config.pin_xclk = CAMERA_PIN_XCLK;
139-
config.pin_pclk = CAMERA_PIN_PCLK;
140-
config.pin_vsync = CAMERA_PIN_VSYNC;
141-
config.pin_href = CAMERA_PIN_HREF;
142-
config.pin_sccb_sda = CAMERA_PIN_SIOD;
143-
config.pin_sccb_scl = CAMERA_PIN_SIOC;
144-
config.sccb_i2c_port = 0;
145-
config.pin_pwdn = CAMERA_PIN_PWDN;
146-
config.pin_reset = CAMERA_PIN_RESET;
147-
config.xclk_freq_hz = XCLK_FREQ_HZ;
148-
config.pixel_format = PIXFORMAT_RGB565;
149-
config.frame_size = FRAMESIZE_QVGA;
150-
config.jpeg_quality = 12;
151-
config.fb_count = 1;
152-
config.fb_location = CAMERA_FB_IN_PSRAM;
153-
config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
154-
camera_ = new Esp32Camera(config);
129+
static esp_cam_ctlr_dvp_pin_config_t dvp_pin_config = {
130+
.data_width = CAM_CTLR_DATA_WIDTH_8,
131+
.data_io = {
132+
[0] = CAMERA_PIN_D0,
133+
[1] = CAMERA_PIN_D1,
134+
[2] = CAMERA_PIN_D2,
135+
[3] = CAMERA_PIN_D3,
136+
[4] = CAMERA_PIN_D4,
137+
[5] = CAMERA_PIN_D5,
138+
[6] = CAMERA_PIN_D6,
139+
[7] = CAMERA_PIN_D7,
140+
},
141+
.vsync_io = CAMERA_PIN_VSYNC,
142+
.de_io = CAMERA_PIN_HREF,
143+
.pclk_io = CAMERA_PIN_PCLK,
144+
.xclk_io = CAMERA_PIN_XCLK,
145+
};
146+
147+
esp_video_init_sccb_config_t sccb_config = {
148+
.init_sccb = true,
149+
.i2c_config = {
150+
.port = 0,
151+
.scl_pin = CAMERA_PIN_SIOC,
152+
.sda_pin = CAMERA_PIN_SIOD,
153+
},
154+
.freq = 100000,
155+
};
156+
157+
esp_video_init_dvp_config_t dvp_config = {
158+
.sccb_config = sccb_config,
159+
.reset_pin = CAMERA_PIN_RESET,
160+
.pwdn_pin = CAMERA_PIN_PWDN,
161+
.dvp_pin = dvp_pin_config,
162+
.xclk_freq = XCLK_FREQ_HZ,
163+
};
164+
165+
esp_video_init_config_t video_config = {
166+
.dvp = &dvp_config,
167+
};
168+
169+
camera_ = new Esp32Camera(video_config);
155170
camera_->SetHMirror(false);
156171
}
157172

main/boards/df-k10/df_k10_board.cc

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -167,36 +167,43 @@ class Df_K10Board : public WifiBoard {
167167
}
168168

169169
void InitializeCamera() {
170+
static esp_cam_ctlr_dvp_pin_config_t dvp_pin_config = {
171+
.data_width = CAM_CTLR_DATA_WIDTH_8,
172+
.data_io = {
173+
[0] = CAMERA_PIN_D2,
174+
[1] = CAMERA_PIN_D3,
175+
[2] = CAMERA_PIN_D4,
176+
[3] = CAMERA_PIN_D5,
177+
[4] = CAMERA_PIN_D6,
178+
[5] = CAMERA_PIN_D7,
179+
[6] = CAMERA_PIN_D8,
180+
[7] = CAMERA_PIN_D9,
181+
},
182+
.vsync_io = CAMERA_PIN_VSYNC,
183+
.de_io = CAMERA_PIN_HREF,
184+
.pclk_io = CAMERA_PIN_PCLK,
185+
.xclk_io = CAMERA_PIN_XCLK,
186+
};
187+
188+
esp_video_init_sccb_config_t sccb_config = {
189+
.init_sccb = false,
190+
.i2c_handle = i2c_bus_,
191+
.freq = 100000,
192+
};
193+
194+
esp_video_init_dvp_config_t dvp_config = {
195+
.sccb_config = sccb_config,
196+
.reset_pin = CAMERA_PIN_RESET,
197+
.pwdn_pin = CAMERA_PIN_PWDN,
198+
.dvp_pin = dvp_pin_config,
199+
.xclk_freq = XCLK_FREQ_HZ,
200+
};
201+
202+
esp_video_init_config_t video_config = {
203+
.dvp = &dvp_config,
204+
};
170205

171-
camera_config_t config = {};
172-
config.ledc_channel = LEDC_CHANNEL_2; // LEDC通道选择 用于生成XCLK时钟 但是S3不用
173-
config.ledc_timer = LEDC_TIMER_2; // LEDC timer选择 用于生成XCLK时钟 但是S3不用
174-
config.pin_d0 = CAMERA_PIN_D2;
175-
config.pin_d1 = CAMERA_PIN_D3;
176-
config.pin_d2 = CAMERA_PIN_D4;
177-
config.pin_d3 = CAMERA_PIN_D5;
178-
config.pin_d4 = CAMERA_PIN_D6;
179-
config.pin_d5 = CAMERA_PIN_D7;
180-
config.pin_d6 = CAMERA_PIN_D8;
181-
config.pin_d7 = CAMERA_PIN_D9;
182-
config.pin_xclk = CAMERA_PIN_XCLK;
183-
config.pin_pclk = CAMERA_PIN_PCLK;
184-
config.pin_vsync = CAMERA_PIN_VSYNC;
185-
config.pin_href = CAMERA_PIN_HREF;
186-
config.pin_sccb_sda = -1; // 这里如果写-1 表示使用已经初始化的I2C接口
187-
config.pin_sccb_scl = CAMERA_PIN_SIOC;
188-
config.sccb_i2c_port = 1; // 这里如果写1 默认使用I2C1
189-
config.pin_pwdn = CAMERA_PIN_PWDN;
190-
config.pin_reset = CAMERA_PIN_RESET;
191-
config.xclk_freq_hz = XCLK_FREQ_HZ;
192-
config.pixel_format = PIXFORMAT_RGB565;
193-
config.frame_size = FRAMESIZE_VGA;
194-
config.jpeg_quality = 12;
195-
config.fb_count = 1;
196-
config.fb_location = CAMERA_FB_IN_PSRAM;
197-
config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
198-
199-
camera_ = new Esp32Camera(config);
206+
camera_ = new Esp32Camera(video_config);
200207
}
201208

202209
void InitializeIli9341Display() {

main/boards/df-s3-ai-cam/df_s3_ai_cam.cc

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,47 @@ class DfrobotEsp32S3AiCam : public WifiBoard {
3030
}
3131

3232
void InitializeCamera() {
33-
camera_config_t config = {};
34-
config.ledc_channel = LEDC_CHANNEL_2; // LEDC通道选择 用于生成XCLK时钟 但是S3不用
35-
config.ledc_timer = LEDC_TIMER_2; // LEDC timer选择 用于生成XCLK时钟 但是S3不用
36-
config.pin_d0 = CAMERA_PIN_D0;
37-
config.pin_d1 = CAMERA_PIN_D1;
38-
config.pin_d2 = CAMERA_PIN_D2;
39-
config.pin_d3 = CAMERA_PIN_D3;
40-
config.pin_d4 = CAMERA_PIN_D4;
41-
config.pin_d5 = CAMERA_PIN_D5;
42-
config.pin_d6 = CAMERA_PIN_D6;
43-
config.pin_d7 = CAMERA_PIN_D7;
44-
config.pin_xclk = CAMERA_PIN_XCLK;
45-
config.pin_pclk = CAMERA_PIN_PCLK;
46-
config.pin_vsync = CAMERA_PIN_VSYNC;
47-
config.pin_href = CAMERA_PIN_HREF;
48-
config.pin_sccb_sda = CAMERA_PIN_SIOD; // 这里如果写-1 表示使用已经初始化的I2C接口
49-
config.pin_sccb_scl = CAMERA_PIN_SIOC;
50-
config.sccb_i2c_port = 1; // 这里如果写1 默认使用I2C1
51-
config.pin_pwdn = CAMERA_PIN_PWDN;
52-
config.pin_reset = CAMERA_PIN_RESET;
53-
config.xclk_freq_hz = XCLK_FREQ_HZ;
54-
config.pixel_format = PIXFORMAT_RGB565;
55-
config.frame_size = FRAMESIZE_VGA;
56-
config.jpeg_quality = 12;
57-
config.fb_count = 1;
58-
config.fb_location = CAMERA_FB_IN_PSRAM;
59-
config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
33+
static esp_cam_ctlr_dvp_pin_config_t dvp_pin_config = {
34+
.data_width = CAM_CTLR_DATA_WIDTH_8,
35+
.data_io = {
36+
[0] = CAMERA_PIN_D0,
37+
[1] = CAMERA_PIN_D1,
38+
[2] = CAMERA_PIN_D2,
39+
[3] = CAMERA_PIN_D3,
40+
[4] = CAMERA_PIN_D4,
41+
[5] = CAMERA_PIN_D5,
42+
[6] = CAMERA_PIN_D6,
43+
[7] = CAMERA_PIN_D7,
44+
},
45+
.vsync_io = CAMERA_PIN_VSYNC,
46+
.de_io = CAMERA_PIN_HREF,
47+
.pclk_io = CAMERA_PIN_PCLK,
48+
.xclk_io = CAMERA_PIN_XCLK,
49+
};
6050

61-
camera_ = new Esp32Camera(config);
51+
esp_video_init_sccb_config_t sccb_config = {
52+
.init_sccb = true,
53+
.i2c_config = {
54+
.port = 1,
55+
.scl_pin = CAMERA_PIN_SIOC,
56+
.sda_pin = CAMERA_PIN_SIOD,
57+
},
58+
.freq = 100000,
59+
};
60+
61+
esp_video_init_dvp_config_t dvp_config = {
62+
.sccb_config = sccb_config,
63+
.reset_pin = CAMERA_PIN_RESET,
64+
.pwdn_pin = CAMERA_PIN_PWDN,
65+
.dvp_pin = dvp_pin_config,
66+
.xclk_freq = XCLK_FREQ_HZ,
67+
};
68+
69+
esp_video_init_config_t video_config = {
70+
.dvp = &dvp_config,
71+
};
72+
73+
camera_ = new Esp32Camera(video_config);
6274
camera_->SetVFlip(1);
6375
}
6476

0 commit comments

Comments
 (0)