Skip to content

Commit d610492

Browse files
committed
Merge branch 'feature/isp_output_raw8_ran10' into 'master'
feat(esp_video): ISP supports to output RAW10 and RAW12 Closes AEG-2215 See merge request espressif/esp-video-components!252
2 parents 889ba25 + 51f9e1e commit d610492

File tree

4 files changed

+59
-49
lines changed

4 files changed

+59
-49
lines changed

esp_video/private_include/esp_video_device_internal.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ typedef struct esp_video_csi_state {
3333
cam_ctlr_color_t in_color; /*!< MIPI-CSI input(from camera sensor) data color format */
3434
cam_ctlr_color_t out_color; /*!< MIPI-CSI output(based on ISP output) data color format */
3535
uint8_t out_bpp; /*!< MIPI-CSI output data color format bit per pixel */
36+
uint32_t in_fmt; /*!< MIPI-CSI input V4L2 format from sensor */
3637
bool line_sync; /*!< true: line has start and end packet; false. line has no start and end packet */
3738
bool bypass_isp; /*!< true: ISP directly output data from input port with processing. false: ISP output processed data by pipeline */
3839
color_raw_element_order_t bayer_order; /*!< Bayer order of raw data */
@@ -186,25 +187,27 @@ esp_err_t esp_video_isp_stop(const esp_video_csi_state_t *state);
186187
/**
187188
* @brief Enumerate ISP supported output pixel format
188189
*
190+
* @param state MIPI-CSI state object
189191
* @param index Enumerated number index
190192
* @param pixel_format Supported output pixel format
191193
*
192194
* @return
193195
* - ESP_OK on success
194196
* - Others if failed
195197
*/
196-
esp_err_t esp_video_isp_enum_format(uint32_t index, uint32_t *pixel_format);
198+
esp_err_t esp_video_isp_enum_format(esp_video_csi_state_t *state, uint32_t index, uint32_t *pixel_format);
197199

198200
/**
199201
* @brief Check if input format is valid
200202
*
203+
* @param state MIPI-CSI state object
201204
* @param format V4L2 format object
202205
*
203206
* @return
204207
* - ESP_OK on success
205208
* - Others if failed
206209
*/
207-
esp_err_t esp_video_isp_check_format(const struct v4l2_format *format);
210+
esp_err_t esp_video_isp_check_format(esp_video_csi_state_t *state, const struct v4l2_format *format);
208211

209212
#if CONFIG_ESP_VIDEO_ENABLE_ISP_VIDEO_DEVICE
210213
/**

esp_video/src/device/esp_video_csi_device.c

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -53,37 +53,44 @@ struct csi_video {
5353

5454
static const char *TAG = "csi_video";
5555

56-
static esp_err_t csi_get_input_frame_type(uint32_t sensor_fmt, cam_ctlr_color_t *csi_color, uint8_t *csi_in_bpp)
56+
static esp_err_t csi_get_input_frame_type(uint32_t sensor_fmt, cam_ctlr_color_t *csi_color, uint8_t *csi_in_bpp, uint32_t *in_fmt)
5757
{
5858
esp_err_t ret = ESP_OK;
5959

6060
switch (sensor_fmt) {
6161
case ESP_CAM_SENSOR_PIXFORMAT_RAW8:
6262
*csi_color = CAM_CTLR_COLOR_RAW8;
63+
*in_fmt = V4L2_PIX_FMT_SBGGR8;
6364
*csi_in_bpp = 8;
6465
break;
6566
case ESP_CAM_SENSOR_PIXFORMAT_RAW10:
6667
*csi_color = CAM_CTLR_COLOR_RAW10;
68+
*in_fmt = V4L2_PIX_FMT_SBGGR10;
6769
*csi_in_bpp = 10;
6870
break;
6971
case ESP_CAM_SENSOR_PIXFORMAT_RAW12:
7072
*csi_color = CAM_CTLR_COLOR_RAW12;
73+
*in_fmt = V4L2_PIX_FMT_SBGGR12;
7174
*csi_in_bpp = 12;
7275
break;
7376
case ESP_CAM_SENSOR_PIXFORMAT_RGB565:
7477
*csi_color = CAM_CTLR_COLOR_RGB565;
78+
*in_fmt = V4L2_PIX_FMT_RGB565;
7579
*csi_in_bpp = 16;
7680
break;
7781
case ESP_CAM_SENSOR_PIXFORMAT_RGB888:
7882
*csi_color = CAM_CTLR_COLOR_RGB888;
83+
*in_fmt = V4L2_PIX_FMT_RGB24;
7984
*csi_in_bpp = 24;
8085
break;
8186
case ESP_CAM_SENSOR_PIXFORMAT_YUV420:
8287
*csi_color = CAM_CTLR_COLOR_YUV420;
88+
*in_fmt = V4L2_PIX_FMT_YUV420;
8389
*csi_in_bpp = 12;
8490
break;
8591
case ESP_CAM_SENSOR_PIXFORMAT_YUV422:
8692
*csi_color = CAM_CTLR_COLOR_YUV422;
93+
*in_fmt = V4L2_PIX_FMT_YUV422P;
8794
*csi_in_bpp = 16;
8895
break;
8996
default:
@@ -103,6 +110,14 @@ static esp_err_t csi_get_output_frame_type_from_v4l2(uint32_t output_fmt, cam_ct
103110
*csi_color = CAM_CTLR_COLOR_RAW8;
104111
*out_bpp = 8;
105112
break;
113+
case V4L2_PIX_FMT_SBGGR10:
114+
*csi_color = CAM_CTLR_COLOR_RAW10;
115+
*out_bpp = 10;
116+
break;
117+
case V4L2_PIX_FMT_SBGGR12:
118+
*csi_color = CAM_CTLR_COLOR_RAW12;
119+
*out_bpp = 12;
120+
break;
106121
case V4L2_PIX_FMT_RGB565:
107122
*csi_color = CAM_CTLR_COLOR_RGB565;
108123
*out_bpp = 16;
@@ -265,7 +280,7 @@ static esp_err_t init_config(struct esp_video *video)
265280
ESP_RETURN_ON_ERROR(esp_cam_sensor_get_format(cam_dev, &sensor_format), TAG, "failed to get sensor format");
266281
ESP_RETURN_ON_FALSE(sensor_format.mipi_info.mipi_clk, ESP_ERR_NOT_SUPPORTED, TAG, "camera sensor mipi_clk is 0");
267282
ESP_RETURN_ON_ERROR(csi_get_data_lane(sensor_format.mipi_info.lane_num, &csi_video->state.lane_num), TAG, "failed to get CSI data lane number");
268-
ESP_RETURN_ON_ERROR(csi_get_input_frame_type(sensor_format.format, &csi_video->state.in_color, &csi_in_bpp), TAG, "failed to get CSI input frame format");
283+
ESP_RETURN_ON_ERROR(csi_get_input_frame_type(sensor_format.format, &csi_video->state.in_color, &csi_in_bpp, &csi_video->state.in_fmt), TAG, "failed to get CSI input frame format");
269284
ESP_RETURN_ON_ERROR(csi_get_input_bayer_order(sensor_format.isp_info, &csi_video->state.bayer_order), TAG, "failed to get bayer order");
270285

271286
csi_video->state.lane_bitrate_mbps = sensor_format.mipi_info.mipi_clk / (1000 * 1000);
@@ -412,60 +427,37 @@ static esp_err_t csi_video_enum_format(struct esp_video *video, uint32_t type, u
412427
esp_err_t ret = ESP_OK;
413428
struct csi_video *csi_video = VIDEO_PRIV_DATA(struct csi_video *, video);
414429

415-
if (csi_video->state.bypass_isp) {
416-
if (index == 0) {
417-
*pixel_format = CAPTURE_VIDEO_GET_FORMAT_PIXEL_FORMAT(video);
418-
} else {
419-
ret = ESP_ERR_NOT_SUPPORTED;
420-
}
421-
} else {
422-
ret = esp_video_isp_enum_format(index, pixel_format);
423-
}
430+
ret = esp_video_isp_enum_format(&csi_video->state, index, pixel_format);
424431

425432
return ret;
426433
}
427434

428435
static esp_err_t csi_video_set_format(struct esp_video *video, const struct v4l2_format *format)
429436
{
437+
uint8_t out_bpp;
438+
cam_ctlr_color_t out_color;
430439
const struct v4l2_pix_format *pix = &format->fmt.pix;
431440
struct csi_video *csi_video = VIDEO_PRIV_DATA(struct csi_video *, video);
432441

433-
if (csi_video->state.bypass_isp) {
434-
if (pix->width != CAPTURE_VIDEO_GET_FORMAT_WIDTH(video) ||
435-
pix->height != CAPTURE_VIDEO_GET_FORMAT_HEIGHT(video) ||
436-
pix->pixelformat != CAPTURE_VIDEO_GET_FORMAT_PIXEL_FORMAT(video)) {
437-
ESP_LOGE(TAG, "width or height or format is not supported");
438-
return ESP_ERR_INVALID_ARG;
439-
}
440-
441-
if ((format->fmt.pix.pixelformat == V4L2_PIX_FMT_YUV420) ||
442-
(format->fmt.pix.pixelformat == V4L2_PIX_FMT_YUV422P)) {
443-
if (format->fmt.pix.ycbcr_enc != V4L2_YCBCR_ENC_DEFAULT) {
444-
return ESP_ERR_NOT_SUPPORTED;
445-
}
442+
ESP_RETURN_ON_ERROR(csi_get_output_frame_type_from_v4l2(pix->pixelformat, &out_color, &out_bpp),
443+
TAG, "CSI does not support format=%" PRIx32, pix->pixelformat);
446444

447-
if (format->fmt.pix.quantization != V4L2_QUANTIZATION_DEFAULT) {
448-
return ESP_ERR_NOT_SUPPORTED;
449-
}
450-
}
445+
if (esp_video_isp_check_format(&csi_video->state, format) == ESP_OK) {
446+
csi_video->state.bypass_isp = false;
451447
} else {
452-
if (pix->width != CAPTURE_VIDEO_GET_FORMAT_WIDTH(video) ||
453-
pix->height != CAPTURE_VIDEO_GET_FORMAT_HEIGHT(video)) {
454-
ESP_LOGE(TAG, "width or height is not supported");
455-
return ESP_ERR_INVALID_ARG;
456-
}
457-
458-
ESP_RETURN_ON_ERROR(esp_video_isp_check_format(format), TAG, "ISP does not support format=%" PRIx32, pix->pixelformat);
448+
ESP_RETURN_ON_FALSE(csi_video->state.in_color == out_color, ESP_ERR_NOT_SUPPORTED,
449+
TAG, "ISP does not support format=%" PRIx32, pix->pixelformat);
450+
csi_video->state.bypass_isp = true;
451+
}
459452

460-
ESP_RETURN_ON_ERROR(csi_get_output_frame_type_from_v4l2(pix->pixelformat, &csi_video->state.out_color, &csi_video->state.out_bpp),
461-
TAG, "CSI does not support format=%" PRIx32, pix->pixelformat);
453+
csi_video->state.out_color = out_color;
454+
csi_video->state.out_bpp = out_bpp;
462455

463-
uint32_t buf_size = CAPTURE_VIDEO_GET_FORMAT_WIDTH(video) * CAPTURE_VIDEO_GET_FORMAT_HEIGHT(video) * csi_video->state.out_bpp / 8;
456+
uint32_t buf_size = CAPTURE_VIDEO_GET_FORMAT_WIDTH(video) * CAPTURE_VIDEO_GET_FORMAT_HEIGHT(video) * out_bpp / 8;
464457

465-
ESP_LOGD(TAG, "buffer size=%" PRIu32, buf_size);
458+
ESP_LOGD(TAG, "buffer size=%" PRIu32, buf_size);
466459

467-
CAPTURE_VIDEO_SET_BUF_INFO(video, buf_size, CSI_DMA_ALIGN_BYTES, CSI_MEM_CAPS);
468-
}
460+
CAPTURE_VIDEO_SET_BUF_INFO(video, buf_size, CSI_DMA_ALIGN_BYTES, CSI_MEM_CAPS);
469461

470462
return ESP_OK;
471463
}

esp_video/src/device/esp_video_isp_device.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,7 +1844,7 @@ esp_err_t esp_video_isp_start_by_csi(const esp_video_csi_state_t *state, const s
18441844
* IDF-9706
18451845
*/
18461846

1847-
ISP.frame_cfg.hadr_num = ceil((float)(isp_config.h_res * 16) / 32.0) - 1;
1847+
ISP.frame_cfg.hadr_num = ceil((float)(isp_config.h_res * state->out_bpp) / 32.0) - 1;
18481848
ISP.frame_cfg.vadr_num = isp_config.v_res - 1;
18491849
ISP.cntl.isp_en = 0;
18501850
} else {
@@ -1924,36 +1924,45 @@ esp_err_t esp_video_isp_stop(const esp_video_csi_state_t *state)
19241924
/**
19251925
* @brief Enumerate ISP supported output pixel format
19261926
*
1927+
* @param state MIPI-CSI state object
19271928
* @param index Enumerated number index
19281929
* @param pixel_format Supported output pixel format
19291930
*
19301931
* @return
19311932
* - ESP_OK on success
19321933
* - Others if failed
19331934
*/
1934-
esp_err_t esp_video_isp_enum_format(uint32_t index, uint32_t *pixel_format)
1935+
esp_err_t esp_video_isp_enum_format(esp_video_csi_state_t *state, uint32_t index, uint32_t *pixel_format)
19351936
{
1936-
if (index >= s_isp_isp_format_nums) {
1937+
if (index < s_isp_isp_format_nums) {
1938+
*pixel_format = s_isp_isp_format[index];
1939+
} else if (index == s_isp_isp_format_nums) {
1940+
*pixel_format = state->in_fmt;
1941+
} else {
19371942
return ESP_ERR_INVALID_ARG;
19381943
}
19391944

1940-
*pixel_format = s_isp_isp_format[index];
1941-
19421945
return ESP_OK;
19431946
}
19441947

19451948
/**
19461949
* @brief Check if input format is valid
19471950
*
1951+
* @param state MIPI-CSI state object
19481952
* @param format V4L2 format object
19491953
*
19501954
* @return
19511955
* - ESP_OK on success
19521956
* - Others if failed
19531957
*/
1954-
esp_err_t esp_video_isp_check_format(const struct v4l2_format *format)
1958+
esp_err_t esp_video_isp_check_format(esp_video_csi_state_t *state, const struct v4l2_format *format)
19551959
{
19561960
bool found = false;
1961+
isp_color_t isp_in_color;
1962+
1963+
if (isp_get_input_frame_type(state->in_color, &isp_in_color) != ESP_OK) {
1964+
return ESP_ERR_NOT_SUPPORTED;
1965+
}
19571966

19581967
for (int i = 0; i < s_isp_isp_format_nums; i++) {
19591968
if (format->fmt.pix.pixelformat == s_isp_isp_format[i]) {

esp_video/src/esp_video.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ static const struct esp_video_format_desc_map esp_video_format_desc_maps[] = {
4646
{
4747
V4L2_PIX_FMT_SBGGR8, "RAW8 BGGR",
4848
},
49+
{
50+
V4L2_PIX_FMT_SBGGR10, "RAW10 BGGR",
51+
},
52+
{
53+
V4L2_PIX_FMT_SBGGR12, "RAW12 BGGR",
54+
},
4955
{
5056
V4L2_PIX_FMT_RGB565, "RGB 5-6-5",
5157
},

0 commit comments

Comments
 (0)