diff --git a/components/esp_driver_cam/isp_dvp/src/esp_cam_ctlr_isp_dvp.c b/components/esp_driver_cam/isp_dvp/src/esp_cam_ctlr_isp_dvp.c index f11bfec172..3dd347c7af 100644 --- a/components/esp_driver_cam/isp_dvp/src/esp_cam_ctlr_isp_dvp.c +++ b/components/esp_driver_cam/isp_dvp/src/esp_cam_ctlr_isp_dvp.c @@ -110,12 +110,12 @@ esp_err_t esp_cam_new_isp_dvp_ctlr(isp_proc_handle_t isp_proc, const esp_cam_ctl dvp_ctlr->trans_que = xQueueCreateWithCaps(ctlr_config->queue_items, sizeof(esp_cam_ctlr_trans_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); ESP_GOTO_ON_FALSE(dvp_ctlr->trans_que, ESP_ERR_NO_MEM, err, TAG, "no memory for transaction queue"); //in color type - int in_bits_per_pixel = color_hal_pixel_format_get_bit_depth(isp_proc->in_color_format); + int in_bits_per_pixel = color_hal_pixel_format_fourcc_get_bit_depth(isp_proc->in_color_format); dvp_ctlr->in_bpp = in_bits_per_pixel; ESP_LOGD(TAG, "dvp_ctlr->in_bpp: 0d %d", dvp_ctlr->in_bpp); //out color type - int out_bits_per_pixel = color_hal_pixel_format_get_bit_depth(isp_proc->out_color_format); + int out_bits_per_pixel = color_hal_pixel_format_fourcc_get_bit_depth(isp_proc->out_color_format); dvp_ctlr->out_bpp = out_bits_per_pixel; ESP_LOGD(TAG, "dvp_ctlr->out_bpp: 0d %d", dvp_ctlr->out_bpp); diff --git a/components/esp_driver_isp/include/esp_private/isp_private.h b/components/esp_driver_isp/include/esp_private/isp_private.h index add1139d77..733a8ff671 100644 --- a/components/esp_driver_isp/include/esp_private/isp_private.h +++ b/components/esp_driver_isp/include/esp_private/isp_private.h @@ -68,8 +68,8 @@ typedef struct isp_processor_t { #endif ISP_ATOMIC_TYPE(isp_fsm_t) isp_fsm; DECLARE_CRIT_SECTION_LOCK_IN_STRUCT(spinlock); - color_space_pixel_format_t in_color_format; - color_space_pixel_format_t out_color_format; + isp_color_t in_color_format; + isp_color_t out_color_format; uint32_t h_res; uint32_t v_res; color_raw_element_order_t bayer_order; diff --git a/components/esp_driver_isp/src/isp_core.c b/components/esp_driver_isp/src/isp_core.c index 60c96eeda0..0fcbba9518 100644 --- a/components/esp_driver_isp/src/isp_core.c +++ b/components/esp_driver_isp/src/isp_core.c @@ -132,13 +132,10 @@ esp_err_t esp_isp_new_processor(const esp_isp_processor_cfg_t *proc_config, isp_ INIT_CRIT_SECTION_LOCK_RUNTIME(&proc->spinlock); //Input & Output color format - color_space_pixel_format_t in_color_format = { - .color_type_id = proc_config->input_data_color_type, - }; - color_space_pixel_format_t out_color_format = { - .color_type_id = proc_config->output_data_color_type, - }; - int in_bits_per_pixel = color_hal_pixel_format_get_bit_depth(in_color_format); + isp_color_t in_color_format = proc_config->input_data_color_type; + isp_color_t out_color_format = proc_config->output_data_color_type; + + int in_bits_per_pixel = color_hal_pixel_format_fourcc_get_bit_depth(in_color_format); if (!proc_config->flags.bypass_isp) { bool valid_format = false; @@ -167,11 +164,11 @@ esp_err_t esp_isp_new_processor(const esp_isp_processor_cfg_t *proc_config, isp_ isp_ll_set_intput_data_v_row_num(proc->hal.hw, proc_config->v_res); isp_ll_set_bayer_mode(proc->hal.hw, proc_config->bayer_order); isp_ll_yuv_set_std(proc->hal.hw, proc_config->yuv_std); - if (out_color_format.color_space == COLOR_SPACE_YUV) { + if (out_color_format == ISP_COLOR_YUV422 || out_color_format == ISP_COLOR_YUV420) { isp_ll_yuv_set_range(proc->hal.hw, proc_config->yuv_range); } - if (out_color_format.color_space == COLOR_SPACE_RGB && proc_config->input_data_source == ISP_INPUT_DATA_SOURCE_DVP) { + if ((out_color_format == ISP_COLOR_RGB888 || out_color_format == ISP_COLOR_RGB565) && proc_config->input_data_source == ISP_INPUT_DATA_SOURCE_DVP) { isp_ll_color_enable(proc->hal.hw, true); // workaround for DIG-474 } if (proc_config->flags.byte_swap_en) { diff --git a/components/esp_driver_isp/src/isp_demosaic.c b/components/esp_driver_isp/src/isp_demosaic.c index 71ca8b07fd..219fa2a820 100644 --- a/components/esp_driver_isp/src/isp_demosaic.c +++ b/components/esp_driver_isp/src/isp_demosaic.c @@ -60,7 +60,7 @@ esp_err_t esp_isp_demosaic_disable(isp_proc_handle_t proc) isp_fsm_t expected_fsm = ISP_FSM_ENABLE; ESP_RETURN_ON_FALSE(atomic_compare_exchange_strong(&proc->demosaic_fsm, &expected_fsm, ISP_FSM_INIT), ESP_ERR_INVALID_STATE, TAG, "demosaic isn't enabled yet"); - if (proc->out_color_format.color_space == (uint32_t)COLOR_SPACE_RAW) { + if (proc->out_color_format == ISP_COLOR_RAW8 || proc->out_color_format == ISP_COLOR_RAW10 || proc->out_color_format == ISP_COLOR_RAW12) { // for other out_color_format, demosaic module is needed for rgb interpolation algorithm isp_ll_demosaic_enable(proc->hal.hw, false); } diff --git a/components/esp_hal_cam/esp32p4/include/hal/isp_ll.h b/components/esp_hal_cam/esp32p4/include/hal/isp_ll.h index 174d6ef3df..ed0fe720ca 100644 --- a/components/esp_hal_cam/esp32p4/include/hal/isp_ll.h +++ b/components/esp_hal_cam/esp32p4/include/hal/isp_ll.h @@ -393,31 +393,29 @@ static inline void isp_ll_set_input_data_source(isp_dev_t *hw, isp_input_data_so * @brief Set input data color format * * @param[in] hw Hardware instance address - * @param[in] format color format, see `color_space_pixel_format_t` + * @param[in] format color format, see `isp_color_t` * * @return true for valid format, false for invalid format */ -static inline bool isp_ll_set_input_data_color_format(isp_dev_t *hw, color_space_pixel_format_t format) +static inline bool isp_ll_set_input_data_color_format(isp_dev_t *hw, isp_color_t format) { bool valid = false; - if (format.color_space == COLOR_SPACE_RAW) { - switch (format.pixel_format) { - case COLOR_PIXEL_RAW8: - hw->cntl.isp_data_type = 0; - valid = true; - break; - case COLOR_PIXEL_RAW10: - hw->cntl.isp_data_type = 1; - valid = true; - break; - case COLOR_PIXEL_RAW12: - hw->cntl.isp_data_type = 2; - valid = true; - break; - default: - break; - } + switch (format) { + case ISP_COLOR_RAW8: + hw->cntl.isp_data_type = 0; + valid = true; + break; + case ISP_COLOR_RAW10: + hw->cntl.isp_data_type = 1; + valid = true; + break; + case ISP_COLOR_RAW12: + hw->cntl.isp_data_type = 2; + valid = true; + break; + default: + break; } return valid; @@ -449,64 +447,52 @@ static inline void isp_ll_set_intput_data_v_row_num(isp_dev_t *hw, uint32_t row_ * @brief Set output data color format * * @param[in] hw Hardware instance address - * @param[in] format color format, see `color_space_pixel_format_t` + * @param[in] format color format, see `isp_color_t` * * @return true for valid format, false for invalid format */ -static inline bool isp_ll_set_output_data_color_format(isp_dev_t *hw, color_space_pixel_format_t format) +static inline bool isp_ll_set_output_data_color_format(isp_dev_t *hw, isp_color_t format) { bool valid = false; - if (format.color_space == COLOR_SPACE_RAW) { - switch (format.pixel_format) { - case COLOR_PIXEL_RAW8: - hw->cntl.isp_out_type = 0; - hw->cntl.demosaic_en = 0; - hw->cntl.rgb2yuv_en = 0; - hw->cntl.yuv2rgb_en = 0; - valid = true; - break; - default: - break; - } - } else if (format.color_space == COLOR_SPACE_RGB) { - switch (format.pixel_format) { - case COLOR_PIXEL_RGB888: - hw->cntl.isp_out_type = 2; - hw->cntl.demosaic_en = 1; - hw->cntl.rgb2yuv_en = 1; - hw->cntl.yuv2rgb_en = 1; - valid = true; - break; - case COLOR_PIXEL_RGB565: - hw->cntl.isp_out_type = 4; - hw->cntl.demosaic_en = 1; - hw->cntl.rgb2yuv_en = 1; - hw->cntl.yuv2rgb_en = 1; - valid = true; - break; - default: - break; - } - } else if (format.color_space == COLOR_SPACE_YUV) { - switch (format.pixel_format) { - case COLOR_PIXEL_YUV422: - hw->cntl.isp_out_type = 1; - hw->cntl.demosaic_en = 1; - hw->cntl.rgb2yuv_en = 1; - hw->cntl.yuv2rgb_en = 0; - valid = true; - break; - case COLOR_PIXEL_YUV420: - hw->cntl.isp_out_type = 3; - hw->cntl.demosaic_en = 1; - hw->cntl.rgb2yuv_en = 1; - hw->cntl.yuv2rgb_en = 0; - valid = true; - break; - default: - break; - } + switch (format) { + case ISP_COLOR_RAW8: + hw->cntl.isp_out_type = 0; + hw->cntl.demosaic_en = 0; + hw->cntl.rgb2yuv_en = 0; + hw->cntl.yuv2rgb_en = 0; + valid = true; + break; + case ISP_COLOR_RGB888: + hw->cntl.isp_out_type = 2; + hw->cntl.demosaic_en = 1; + hw->cntl.rgb2yuv_en = 1; + hw->cntl.yuv2rgb_en = 1; + valid = true; + break; + case ISP_COLOR_RGB565: + hw->cntl.isp_out_type = 4; + hw->cntl.demosaic_en = 1; + hw->cntl.rgb2yuv_en = 1; + hw->cntl.yuv2rgb_en = 1; + valid = true; + break; + case ISP_COLOR_YUV422: + hw->cntl.isp_out_type = 1; + hw->cntl.demosaic_en = 1; + hw->cntl.rgb2yuv_en = 1; + hw->cntl.yuv2rgb_en = 0; + valid = true; + break; + case ISP_COLOR_YUV420: + hw->cntl.isp_out_type = 3; + hw->cntl.demosaic_en = 1; + hw->cntl.rgb2yuv_en = 1; + hw->cntl.yuv2rgb_en = 0; + valid = true; + break; + default: + break; } return valid; @@ -1144,31 +1130,29 @@ static inline void isp_ll_color_set_brigntness(isp_dev_t *hw, int8_t color_brigh * @brief Set dvp data color format * * @param[in] hw Hardware instance address - * @param[in] format color format, see `color_space_pixel_format_t` + * @param[in] format color format, see `isp_color_t` * * @return true for valid format, false for invalid format */ -static inline bool isp_ll_dvp_set_data_type(isp_dev_t *hw, color_space_pixel_format_t format) +static inline bool isp_ll_dvp_set_data_type(isp_dev_t *hw, isp_color_t format) { bool valid = false; - if (format.color_space == COLOR_SPACE_RAW) { - switch (format.pixel_format) { - case COLOR_PIXEL_RAW8: - hw->cam_conf.cam_data_type = ISP_LL_DVP_DATA_TYPE_RAW8; - valid = true; - break; - case COLOR_PIXEL_RAW10: - hw->cam_conf.cam_data_type = ISP_LL_DVP_DATA_TYPE_RAW10; - valid = true; - break; - case COLOR_PIXEL_RAW12: - hw->cam_conf.cam_data_type = ISP_LL_DVP_DATA_TYPE_RAW12; - valid = true; - break; - default: - break; - } + switch (format) { + case ISP_COLOR_RAW8: + hw->cam_conf.cam_data_type = ISP_LL_DVP_DATA_TYPE_RAW8; + valid = true; + break; + case ISP_COLOR_RAW10: + hw->cam_conf.cam_data_type = ISP_LL_DVP_DATA_TYPE_RAW10; + valid = true; + break; + case ISP_COLOR_RAW12: + hw->cam_conf.cam_data_type = ISP_LL_DVP_DATA_TYPE_RAW12; + valid = true; + break; + default: + break; } return valid; diff --git a/components/esp_hal_cam/include/hal/isp_types.h b/components/esp_hal_cam/include/hal/isp_types.h index 409350115f..7825976e15 100644 --- a/components/esp_hal_cam/include/hal/isp_types.h +++ b/components/esp_hal_cam/include/hal/isp_types.h @@ -66,13 +66,13 @@ typedef enum { * @brief ISP Color Type */ typedef enum { - ISP_COLOR_RAW8 = COLOR_TYPE_ID(COLOR_SPACE_RAW, COLOR_PIXEL_RAW8), ///< RAW8 - ISP_COLOR_RAW10 = COLOR_TYPE_ID(COLOR_SPACE_RAW, COLOR_PIXEL_RAW10), ///< RAW10 - ISP_COLOR_RAW12 = COLOR_TYPE_ID(COLOR_SPACE_RAW, COLOR_PIXEL_RAW12), ///< RAW12 - ISP_COLOR_RGB888 = COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB888), ///< RGB888 - ISP_COLOR_RGB565 = COLOR_TYPE_ID(COLOR_SPACE_RGB, COLOR_PIXEL_RGB565), ///< RGB565 - ISP_COLOR_YUV422 = COLOR_TYPE_ID(COLOR_SPACE_YUV, COLOR_PIXEL_YUV422), ///< YUV422 - ISP_COLOR_YUV420 = COLOR_TYPE_ID(COLOR_SPACE_YUV, COLOR_PIXEL_YUV420), ///< YUV420 + ISP_COLOR_RAW8 = ESP_COLOR_FOURCC_RAW8, ///< RAW8 + ISP_COLOR_RAW10 = ESP_COLOR_FOURCC_RAW10, ///< RAW10 + ISP_COLOR_RAW12 = ESP_COLOR_FOURCC_RAW12, ///< RAW12 + ISP_COLOR_RGB888 = ESP_COLOR_FOURCC_BGR24, ///< RGB888 + ISP_COLOR_RGB565 = ESP_COLOR_FOURCC_RGB16, ///< RGB565 + ISP_COLOR_YUV422 = ESP_COLOR_FOURCC_UYVY, ///< YUV422 packed in UYVY order + ISP_COLOR_YUV420 = ESP_COLOR_FOURCC_OUYY_EVYY, ///< YUV420 } isp_color_t; /** diff --git a/components/hal/color_hal.c b/components/hal/color_hal.c index ef402c7309..b556f8da48 100644 --- a/components/hal/color_hal.c +++ b/components/hal/color_hal.c @@ -50,7 +50,11 @@ uint32_t color_hal_pixel_format_fourcc_get_bit_depth(esp_color_fourcc_t four_cha return 4; case ESP_COLOR_FOURCC_ALPHA8: case ESP_COLOR_FOURCC_GREY: + case ESP_COLOR_FOURCC_RAW8: return 8; + case ESP_COLOR_FOURCC_RAW10: + return 10; + case ESP_COLOR_FOURCC_RAW12: case ESP_COLOR_FOURCC_OUYY_EVYY: return 12; case ESP_COLOR_FOURCC_YUYV: diff --git a/components/hal/include/hal/color_types.h b/components/hal/include/hal/color_types.h index 6f918ff854..c52fca8d75 100644 --- a/components/hal/include/hal/color_types.h +++ b/components/hal/include/hal/color_types.h @@ -133,6 +133,38 @@ typedef uint32_t esp_color_fourcc_t; */ #define ESP_COLOR_FOURCC_OUYY_EVYY ESP_COLOR_FOURCC('O', 'U', 'E', 'V') /* 12 bpp, Espressif Y-U-V 4:2:0 */ +/** + * RAW8 + * Memory Layout: + * Addr0 Addr1 Addr2 Addr3 + * R0 R1 R2 R3 + */ +#define ESP_COLOR_FOURCC_RAW8 ESP_COLOR_FOURCC('R', 'A', 'W', '8') /* 8 bpp, raw8 */ + +/** + * RAW10 + * Memory Layout: + * Addr0 Addr1 Addr2 Addr3 + * R0[7:0] R0[1:0] R1[7:0] R1[1:0] + */ +#define ESP_COLOR_FOURCC_RAW10 ESP_COLOR_FOURCC('R', 'A', 'W', 'A') /* 10 bpp, raw10 */ + +/** + * RAW12 + * Memory Layout: + * Addr0 Addr1 Addr2 Addr3 + * R0[7:0] R0[3:0] R1[7:0] R1[3:0] + */ +#define ESP_COLOR_FOURCC_RAW12 ESP_COLOR_FOURCC('R', 'A', 'W', 'C') /* 12 bpp, raw12 */ + +/** + * RAW16 + * Memory Layout: + * Addr0 Addr1 Addr2 Addr3 + * R0[7:0] R0[7:0] R1[7:0] R1[7:0] + */ +#define ESP_COLOR_FOURCC_RAW16 ESP_COLOR_FOURCC('R', 'A', 'W', 'G') /* 16 bpp, raw16 */ + /*--------------------------------------------------------------- Color Conversion diff --git a/components/soc/esp32p4/register/hw_ver3/soc/mipi_csi_bridge_struct.h b/components/soc/esp32p4/register/hw_ver3/soc/mipi_csi_bridge_struct.h index 7856dd3740..73c12d26fd 100644 --- a/components/soc/esp32p4/register/hw_ver3/soc/mipi_csi_bridge_struct.h +++ b/components/soc/esp32p4/register/hw_ver3/soc/mipi_csi_bridge_struct.h @@ -354,6 +354,7 @@ typedef union { /** Group: csi host color mode control registers. */ /** Type of host_cm_ctrl register * CSI HOST color mode convert configuration. + * Valid when ISP is bypassed. */ typedef union { struct { @@ -362,23 +363,24 @@ typedef union { */ uint32_t csi_host_cm_en:1; /** csi_host_cm_bypass : R/W; bitpos: [1]; default: 1; - * Configures whether to bypass cm + * Configures whether to bypass cm, input directly to output */ uint32_t csi_host_cm_bypass:1; /** csi_host_cm_rx : R/W; bitpos: [3:2]; default: 0; - * Configures whether to bypass cm + * 0: RGB888, 1: RGB565, 2: YUV422, 3: YUV420 */ uint32_t csi_host_cm_rx:2; /** csi_host_cm_rx_rgb_format : R/W; bitpos: [6:4]; default: 0; - * Configures whether to bypass cm + * 0: RGB, 1: BGR, 2: RBG, 3: BRG, 4: GRB, 5: GBR */ uint32_t csi_host_cm_rx_rgb_format:3; /** csi_host_cm_rx_yuv422_format : R/W; bitpos: [8:7]; default: 0; * Configures whether to bypass cm + * 0: YVYU, 1: YUYV, 2: VYUY, 3: UYVY */ uint32_t csi_host_cm_rx_yuv422_format:2; /** csi_host_cm_tx : R/W; bitpos: [10:9]; default: 0; - * Configures whether to bypass cm + * 0: RGB888, 1: RGB565, 2: YUV422, 3: YUV420 */ uint32_t csi_host_cm_tx:2; /** csi_host_cm_lane_num : R/W; bitpos: [11]; default: 1;