Skip to content

Commit a072f65

Browse files
authored
Merge branch 'master' into feat/add-ov02c10-sensor
2 parents fb9d86b + 21c4017 commit a072f65

File tree

15 files changed

+403
-11
lines changed

15 files changed

+403
-11
lines changed

esp_cam_sensor/include/esp_cam_sensor_types.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ typedef enum {
7474

7575
#define ESP_CAM_SENSOR_STATS_FLAG_WB_GAIN (1 << 0)
7676
#define ESP_CAM_SENSOR_STATS_FLAG_AGC_GAIN (1 << 1)
77+
#define ESP_CAM_SENSOR_STATS_FLAG_EXPOSURE (1 << 2)
7778

7879
#define ESP_CAM_SENSOR_PARAM_TYPE_NUMBER 1
7980
#define ESP_CAM_SENSOR_PARAM_TYPE_BITMASK 2
@@ -437,7 +438,8 @@ typedef struct {
437438
typedef struct {
438439
uint32_t flags;
439440
uint32_t seq;
440-
uint16_t agc_gain; /*!< AGC gain output to sensor */
441+
uint32_t aec_exp; /*!< AEC exposure output to sensor */
442+
volatile float agc_gain; /*!< AGC gain output to sensor */
441443
union {
442444
struct {
443445
uint8_t red_avg;

esp_cam_sensor/sensors/gc0308/gc0308.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,20 @@ static esp_err_t gc0308_query_para_desc(esp_cam_sensor_device_t *dev, esp_cam_se
274274

275275
static esp_err_t gc0308_get_para_value(esp_cam_sensor_device_t *dev, uint32_t id, void *arg, size_t size)
276276
{
277-
return ESP_ERR_NOT_SUPPORTED;
277+
esp_err_t ret = ESP_OK;
278+
279+
switch (id) {
280+
#if CONFIG_CAMERA_SENSOR_SWAP_PIXEL_BYTE_ORDER
281+
case ESP_CAM_SENSOR_DATA_SEQ:
282+
*(uint32_t *)arg = ESP_CAM_SENSOR_DATA_SEQ_BYTE_SWAPPED;
283+
break;
284+
#endif
285+
default:
286+
ret = ESP_ERR_NOT_SUPPORTED;
287+
break;
288+
}
289+
290+
return ret;
278291
}
279292

280293
static esp_err_t gc0308_set_para_value(esp_cam_sensor_device_t *dev, uint32_t id, const void *arg, size_t size)

esp_cam_sensor/sensors/ov2710/cfg/ov2710_default.json

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,23 @@
101101
1, 1, 1, 1, 1,
102102
1, 1, 1, 1, 1
103103
]
104+
},
105+
"env":
106+
{
107+
"k": 250000,
108+
"speed_param":
109+
[
110+
-0.005463, -0.010018, 0.000000, 0.033241, 0.085583, 0.136704, 0.160734, 0.148777,
111+
0.148777, 0.160734, 0.136704, 0.085583, 0.033241, 0.000000, -0.010018, -0.005463
112+
],
113+
"weight":
114+
[
115+
1, 1, 1, 1, 1,
116+
1, 1, 1, 1, 1,
117+
1, 1, 1, 1, 1,
118+
1, 1, 1, 1, 1,
119+
1, 1, 1, 1, 1
120+
]
104121
}
105122
}
106123
},
@@ -415,7 +432,25 @@
415432
},
416433
"atc":
417434
{
418-
"init_value": 48
435+
"model": 0,
436+
"init_value": 48,
437+
"delay_frames": 3,
438+
"luma_env": "env.luma.avg",
439+
"luma_lut":
440+
[
441+
{
442+
"luma": 250,
443+
"ae_value": 48
444+
},
445+
{
446+
"luma": 500,
447+
"ae_value": 60
448+
},
449+
{
450+
"luma": 750,
451+
"ae_value": 75
452+
}
453+
]
419454
}
420455
}
421456
}

esp_cam_sensor/sensors/ov2710/ov2710.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ static const char *TAG = "ov2710";
5454
static portMUX_TYPE s_stats_mutex = portMUX_INITIALIZER_UNLOCKED;
5555
#endif
5656

57+
#define OV2710_GAIN_V(_v, _b) ((uint32_t)(((_v) >> ((_b))) & 0x01) + 1)
58+
5759
static const esp_cam_sensor_isp_info_t ov2710_isp_info[] = {
5860
/* For MIPI */
5961
{
@@ -62,6 +64,7 @@ static const esp_cam_sensor_isp_info_t ov2710_isp_info[] = {
6264
.pclk = 80000000,
6365
.vts = 1322,
6466
.hts = 2420,
67+
.tline_ns = 30222,
6568
.bayer_type = ESP_CAM_SENSOR_BAYER_BGGR,
6669
}
6770
},
@@ -71,6 +74,7 @@ static const esp_cam_sensor_isp_info_t ov2710_isp_info[] = {
7174
.pclk = 80000000,
7275
.vts = 1322,
7376
.hts = 2420,
77+
.tline_ns = 26666,
7478
.bayer_type = ESP_CAM_SENSOR_BAYER_BGGR,
7579
},
7680
},
@@ -161,7 +165,8 @@ static esp_err_t ov2710_set_reg_bits(esp_sccb_io_handle_t sccb_handle, uint16_t
161165
#if CONFIG_CAMERA_OV2710_STATS_UPDATE_EN
162166
static void wb_timer_callback(TimerHandle_t timer)
163167
{
164-
uint8_t read_v[5] = {0};
168+
uint8_t read_v[8] = {0};
169+
uint8_t read_v2 = 0;
165170
esp_cam_sensor_device_t *dev = (esp_cam_sensor_device_t *)pvTimerGetTimerID(timer);
166171
struct ov2710_cam *cam_ov2710 = (struct ov2710_cam *)dev->priv;
167172

@@ -170,14 +175,28 @@ static void wb_timer_callback(TimerHandle_t timer)
170175
ov2710_read(dev->sccb_handle, OV2710_REG_BLUE_BEFORE_GAIN_AVERAGE, &read_v[2]);
171176
ov2710_read(dev->sccb_handle, OV2710_REG_AEC_AGC_ADJ_MSB, &read_v[3]);
172177
ov2710_read(dev->sccb_handle, OV2710_REG_AEC_AGC_ADJ_LSB, &read_v[4]);
178+
ov2710_read(dev->sccb_handle, OV2710_REG_AEC_EXPO_H, &read_v[5]);
179+
ov2710_read(dev->sccb_handle, OV2710_REG_AEC_EXPO_M, &read_v[6]);
180+
ov2710_read(dev->sccb_handle, OV2710_REG_AEC_EXPO_L, &read_v[7]);
181+
// ov2710_read(dev->sccb_handle, 0x568A, &read_v2);
182+
ov2710_read(dev->sccb_handle, 0x5690, &read_v2);
173183

174184
portENTER_CRITICAL(&s_stats_mutex);
175185
cam_ov2710->ov2710_para.stats.wb_avg.red_avg = read_v[0];
176186
cam_ov2710->ov2710_para.stats.wb_avg.green_avg = read_v[1];
177187
cam_ov2710->ov2710_para.stats.wb_avg.blue_avg = read_v[2];
178-
cam_ov2710->ov2710_para.stats.agc_gain = ((read_v[3] & 0x01) + 1) * ((read_v[4] & 0x80) + 1) * ((read_v[4] & 0x40) + 1) * ((read_v[4] & 0x20) + 1) * ((read_v[4] & 0x10) + 1) * ((read_v[4] & 0x0f) / 16 + 1);
188+
cam_ov2710->ov2710_para.stats.agc_gain = ((float)(read_v[4] & 0xf) / 16.0 + 1.0) * \
189+
OV2710_GAIN_V(read_v[3], 0) * \
190+
OV2710_GAIN_V(read_v[4], 7) * \
191+
OV2710_GAIN_V(read_v[4], 6) * \
192+
OV2710_GAIN_V(read_v[4], 5) * \
193+
OV2710_GAIN_V(read_v[4], 4);
194+
195+
cam_ov2710->ov2710_para.stats.aec_exp = ((uint32_t)(read_v[5] & 0x0f) << 16) | ((uint32_t)read_v[6] << 8) | ((uint32_t)read_v[7]);
179196
cam_ov2710->ov2710_para.stats.seq++;
180197
portEXIT_CRITICAL(&s_stats_mutex);
198+
ESP_LOGD(TAG, "_gain=%f, avg=0x%"PRIx8", _exp=0x%" PRIx32, cam_ov2710->ov2710_para.stats.agc_gain, read_v2, cam_ov2710->ov2710_para.stats.aec_exp);
199+
ESP_LOGD(TAG, "_luma=%f", (float)read_v2 * 1000 / cam_ov2710->ov2710_para.stats.agc_gain / cam_ov2710->ov2710_para.stats.aec_exp);
181200
}
182201
#endif
183202

@@ -626,7 +645,7 @@ esp_cam_sensor_device_t *ov2710_detect(esp_cam_sensor_config_t *config)
626645

627646
#if CONFIG_CAMERA_OV2710_STATS_UPDATE_EN
628647
// Init cam privae pata
629-
cam_ov2710->ov2710_para.stats.flags = ESP_CAM_SENSOR_STATS_FLAG_WB_GAIN | ESP_CAM_SENSOR_STATS_FLAG_AGC_GAIN;
648+
cam_ov2710->ov2710_para.stats.flags = ESP_CAM_SENSOR_STATS_FLAG_WB_GAIN | ESP_CAM_SENSOR_STATS_FLAG_AGC_GAIN | ESP_CAM_SENSOR_STATS_FLAG_EXPOSURE;
630649
cam_ov2710->wb_timer_handle = xTimerCreate("wb_t", CONFIG_CAMERA_OV2710_STATS_UPDATE_INTERVAL / portTICK_PERIOD_MS, pdTRUE,
631650
(void *)dev, wb_timer_callback);
632651
if (!cam_ov2710->wb_timer_handle) {

esp_cam_sensor/sensors/ov2710/private_include/ov2710_regs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ extern "C" {
2525
#define OV2710_REG_BLUE_BEFORE_GAIN_AVERAGE 0x5198 /* R Bit[7:0]: Before AWB gain's blue data average*/
2626
#define OV2710_REG_AEC_AGC_ADJ_MSB 0x350A
2727
#define OV2710_REG_AEC_AGC_ADJ_LSB 0x350B
28+
#define OV2710_REG_AEC_EXPO_H 0x3500
29+
#define OV2710_REG_AEC_EXPO_M 0x3501
30+
#define OV2710_REG_AEC_EXPO_L 0x3502
2831

2932
#ifdef __cplusplus
3033
}

esp_video/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
## Unreleased
22

3+
- Add RISC-V software swap byte function for DVP video device
34
- Add the customized video class to call esp_cam_sensor ioctl commands directly
45
- Add the second SPI video device
6+
- Add camera sensor exposure parameter to statistics
57
- Improve AEC controller time precision
68
- Fix the CSI video device initializes twice when starting up
79
- Update to use esp_cam_sensor v1.4.x

esp_video/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ if(CONFIG_IDF_TARGET_ESP32P4)
1919

2020
if(CONFIG_ESP_VIDEO_ENABLE_SWAP_BYTE)
2121
list(APPEND srcs "src/data_reprocessing/esp32p4/esp_video_swap_byte.c")
22+
list(APPEND srcs "src/data_reprocessing/esp32p4/esp_video_swap_byte.S")
2223
endif()
2324
endif()
2425

esp_video/private_include/esp_video_swap_byte.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#include "sdkconfig.h"
1010
#include "esp_err.h"
1111
#include "esp_cam_sensor.h"
12+
#if CONFIG_ESP_VIDEO_ENABLE_SWAP_BYTE_BITSCRAMBLER
1213
#include "driver/bitscrambler.h"
14+
#endif
1315

1416
#ifdef __cplusplus
1517
extern "C" {
@@ -19,7 +21,11 @@ extern "C" {
1921
* @brief Video swap byte object
2022
*/
2123
typedef struct esp_video_swap_byte {
24+
#if CONFIG_ESP_VIDEO_ENABLE_SWAP_BYTE_BITSCRAMBLER
2225
bitscrambler_handle_t bs; /*!< Bitscrambler handle */
26+
#else
27+
void *priv; /*!< Swap short byte data */
28+
#endif
2329
} esp_video_swap_byte_t;
2430

2531
/**
@@ -49,6 +55,23 @@ esp_err_t esp_video_swap_byte_start(esp_video_swap_byte_t *swap_byte);
4955
*/
5056
void esp_video_swap_byte_free(esp_video_swap_byte_t *swap_byte);
5157

58+
/**
59+
* @brief Process video swap byte
60+
*
61+
* @param swap_byte Video swap byte object pointer
62+
* @param src Source buffer pointer
63+
* @param src_size Source buffer size
64+
* @param dst Destination buffer pointer
65+
* @param dst_size Destination buffer size
66+
* @param ret_size Result data size buffer
67+
*
68+
* @return
69+
* - ESP_OK on success
70+
* - Others if failed
71+
*/
72+
esp_err_t esp_video_swap_byte_process(esp_video_swap_byte_t *swap_byte, void *src, size_t src_size,
73+
void *dst, size_t dst_size, size_t *ret_size);
74+
5275
#ifdef __cplusplus
5376
}
5477
#endif

esp_video/src/data_reprocessing/Kconfig.data_reprocessing

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,10 @@ menuconfig ESP_VIDEO_ENABLE_SWAP_SHORT
222222

223223
endif # ESP_VIDEO_ENABLE_SWAP_SHORT
224224

225-
config ESP_VIDEO_ENABLE_SWAP_BYTE
225+
menuconfig ESP_VIDEO_ENABLE_SWAP_BYTE
226226
bool "Enable 8-bit data swapping"
227227
default y
228228
select ESP_VIDEO_ENABLE_DATA_PREPROCESSING
229-
select ESP_VIDEO_ENABLE_BITSCRAMBLER
230229
depends on SOC_BITSCRAMBLER_SUPPORTED && ESP_VIDEO_ENABLE_DVP_VIDEO_DEVICE
231230
help
232231
Enable swapping of 8-bit (byte) data for DVP video streams.
@@ -245,4 +244,54 @@ config ESP_VIDEO_ENABLE_SWAP_BYTE
245244

246245
Required for proper color reproduction with many DVP camera modules.
247246
Uses hardware bitscrambler for efficient processing without CPU overhead.
247+
248+
if ESP_VIDEO_ENABLE_SWAP_BYTE
249+
choice ESP_VIDEO_ENABLE_SWAP_BYTE_IMPL
250+
prompt "8-bit swap implementation method"
251+
default ESP_VIDEO_ENABLE_SWAP_BYTE_RISCV
252+
help
253+
Select the implementation method for 8-bit data swapping.
254+
255+
Performance comparison (typical):
256+
- RISC-V Assembly: Fast, uses CPU cores
257+
- Hardware Bitscrambler: Fastest, offloads CPU but uses peripheral
258+
259+
Choose based on your performance requirements and available peripherals.
260+
261+
config ESP_VIDEO_ENABLE_SWAP_BYTE_RISCV
262+
bool "RISC-V assembly instructions"
263+
help
264+
Use optimized RISC-V assembly instructions for data swapping.
265+
266+
Benefits:
267+
- Fast execution speed
268+
- Low latency processing
269+
- No peripheral dependencies
270+
271+
Trade-offs:
272+
- Uses CPU cycles
273+
- May affect other real-time tasks
274+
275+
Best for: High-performance applications where speed is critical.
276+
277+
config ESP_VIDEO_ENABLE_SWAP_BYTE_BITSCRAMBLER
278+
bool "Hardware bitscrambler - Experimental"
279+
select ESP_VIDEO_ENABLE_BITSCRAMBLER
280+
depends on SOC_BITSCRAMBLER_SUPPORTED
281+
help
282+
Use dedicated hardware bitscrambler peripheral for data swapping.
283+
284+
Benefits:
285+
- Offloads CPU processing
286+
- Allows CPU to handle other tasks
287+
- No impact on real-time performance
288+
289+
Trade-offs:
290+
- Faster than CPU-based methods without latency
291+
- Requires available peripheral
292+
- Experimental feature
293+
294+
Best for: Applications where CPU resources are constrained.
295+
endchoice # ESP_VIDEO_ENABLE_SWAP_BYTE_IMPL
296+
endif #ESP_VIDEO_ENABLE_SWAP_BYTE
248297
endmenu

0 commit comments

Comments
 (0)