From eda3b5690644508b9f12c360063092cd48e25f25 Mon Sep 17 00:00:00 2001 From: iChizer0 <62390647+iChizer0@users.noreply.github.com> Date: Sun, 28 Apr 2024 15:03:43 +0800 Subject: [PATCH] fix: we2 chip version c compatibility issue with imx series camera * fix: we2 chip version c compatibility issue with imx series camera * fix: treat frame timeout as internal initialization failure --- porting/himax/we2/drivers/drv_common.c | 11 +++++ porting/himax/we2/drivers/drv_common.h | 3 ++ porting/himax/we2/drivers/drv_imx219.c | 53 ++++++++++++++++++++++++ porting/himax/we2/drivers/drv_imx708.c | 56 +++++++++++++++++++++++++- porting/himax/we2/drivers/drv_ov5647.c | 3 ++ 5 files changed, 125 insertions(+), 1 deletion(-) diff --git a/porting/himax/we2/drivers/drv_common.c b/porting/himax/we2/drivers/drv_common.c index 96071f02..76739828 100644 --- a/porting/himax/we2/drivers/drv_common.c +++ b/porting/himax/we2/drivers/drv_common.c @@ -44,6 +44,9 @@ void _reset_all_wdma_buffer() { memset((void*)_jpegsize_baseaddr, 0, JPEG_FILL_SIZE); } +void (*_drv_dp_event_cb_on_frame_ready)() = NULL; +void (*_drv_dp_on_stop_stream)() = NULL; + void _drv_dp_event_cb(SENSORDPLIB_STATUS_E event) { EL_LOGD("event: %d", event); @@ -51,6 +54,9 @@ void _drv_dp_event_cb(SENSORDPLIB_STATUS_E event) { case SENSORDPLIB_STATUS_XDMA_FRAME_READY: _frame_ready = true; ++_frame_count; + if (_drv_dp_event_cb_on_frame_ready != NULL) { + _drv_dp_event_cb_on_frame_ready(); + } break; default: _initiated_before = false; @@ -65,6 +71,7 @@ el_err_code_t _drv_capture(uint32_t timeout) { while (!_frame_ready) { if (el_get_time_ms() - time >= timeout) { EL_LOGD("frame timeout\n"); + _initiated_before = false; return EL_ETIMOUT; } el_sleep(3); @@ -76,6 +83,10 @@ el_err_code_t _drv_capture(uint32_t timeout) { el_err_code_t _drv_capture_stop() { _frame_ready = false; + if (_drv_dp_on_stop_stream != NULL) { + _drv_dp_on_stop_stream(); + } + sensordplib_retrigger_capture(); return EL_OK; diff --git a/porting/himax/we2/drivers/drv_common.h b/porting/himax/we2/drivers/drv_common.h index 9d463d18..f03188f7 100644 --- a/porting/himax/we2/drivers/drv_common.h +++ b/porting/himax/we2/drivers/drv_common.h @@ -30,6 +30,9 @@ extern volatile uint32_t _jpegsize_baseaddr; extern el_img_t _frame; extern el_img_t _jpeg; +extern void (*_drv_dp_event_cb_on_frame_ready)(); +extern void (*_drv_dp_on_stop_stream)(); + el_err_code_t _drv_capture(uint32_t timeout); el_err_code_t _drv_capture_stop(); el_img_t _drv_get_frame(); diff --git a/porting/himax/we2/drivers/drv_imx219.c b/porting/himax/we2/drivers/drv_imx219.c index 47fb8c56..66c63b43 100644 --- a/porting/himax/we2/drivers/drv_imx219.c +++ b/porting/himax/we2/drivers/drv_imx219.c @@ -16,6 +16,8 @@ #define SENCTRL_SENSOR_HEIGHT IMX219_SENSOR_HEIGHT #define SENCTRL_SENSOR_CH 3 +static bool _is_version_c = false; + static HX_CIS_SensorSetting_t IMX219_init_setting[] = { #include "IMX219_mipi_2lane_3280x2464.i" }; @@ -236,7 +238,41 @@ static void set_mipi_csirx_disable() { EL_LOGD("0x%08X = 0x%08X", csi_stream0_control_reg, *csi_stream0_control_reg); } +#define WE2_CHIP_VERSION_C 0x8538000c + +static void _on_frame_ready_cb() { + // stream off + if (hx_drv_cis_setRegTable(IMX219_stream_off, HX_CIS_SIZE_N(IMX219_stream_off, HX_CIS_SensorSetting_t)) != + HX_CIS_NO_ERROR) { + EL_LOGW("stream off fail"); + } + set_mipi_csirx_disable(); +} + +static void _on_stop_capture_cb() { + set_mipi_csirx_enable(); + // stream on + if (hx_drv_cis_setRegTable(IMX219_stream_on, HX_CIS_SIZE_N(IMX219_stream_on, HX_CIS_SensorSetting_t)) != + HX_CIS_NO_ERROR) { + EL_LOGW("stream on fail"); + } +} + el_err_code_t drv_imx219_init(uint16_t width, uint16_t height) { + uint32_t chipid; + uint32_t version; + hx_drv_scu_get_version(&chipid, &version); + if (chipid == WE2_CHIP_VERSION_C) { + _is_version_c = true; + _initiated_before = false; + + _drv_dp_event_cb_on_frame_ready = _on_frame_ready_cb; + _drv_dp_on_stop_stream = _on_stop_capture_cb; + } else { + _is_version_c = false; + _drv_dp_event_cb_on_frame_ready = NULL; + _drv_dp_on_stop_stream = NULL; + } el_err_code_t ret = EL_OK; HW5x5_CFG_T hw5x5_cfg; JPEG_CFG_T jpeg_cfg; @@ -469,11 +505,28 @@ el_err_code_t drv_imx219_init(uint16_t width, uint16_t height) { } #endif + if (_is_version_c) { + _on_stop_capture_cb(); + } + sensordplib_set_sensorctrl_start(); _frame_ready = false; sensordplib_retrigger_capture(); + if (_is_version_c) { + auto last_time = el_get_time_ms(); + while (!_frame_ready) { + el_sleep(3); + if (el_get_time_ms() - last_time > 1000) { + ret = EL_ETIMOUT; + EL_LOGD("wait frame ready timeout"); + goto err; + } + } + _on_stop_capture_cb(); + } + _initiated_before = true; EL_LOGD("imx219 init success!"); diff --git a/porting/himax/we2/drivers/drv_imx708.c b/porting/himax/we2/drivers/drv_imx708.c index ae0f4494..60de0225 100644 --- a/porting/himax/we2/drivers/drv_imx708.c +++ b/porting/himax/we2/drivers/drv_imx708.c @@ -10,6 +10,8 @@ #define CIS_MIPI_LANE_NUMBER (0x02) #define CIS_ENABLE_HX_AUTOI2C (0x00) // 0x00: off / 0x01: on / 0x2: on and XSLEEP KEEP HIGH +static bool _is_version_c = false; + static HX_CIS_SensorSetting_t IMX708_common_setting[] = { #include "IMX708_common_setting.i" }; @@ -159,7 +161,7 @@ static void set_mipi_csirx_enable() { hscnt_cfg.mipirx_dphy_hscnt_clk_val = 0x03; hscnt_cfg.mipirx_dphy_hscnt_ln0_val = 0x10; hscnt_cfg.mipirx_dphy_hscnt_ln1_val = 0x10; - + sensordplib_csirx_set_hscnt(hscnt_cfg); if (pixel_dpp == 10 || pixel_dpp == 8) { @@ -242,7 +244,42 @@ el_err_code_t drv_imx708_probe() { return EL_OK; } +#define WE2_CHIP_VERSION_C 0x8538000c + +static void _on_frame_ready_cb() { + // stream off + if (hx_drv_cis_setRegTable(IMX708_stream_off, HX_CIS_SIZE_N(IMX708_stream_off, HX_CIS_SensorSetting_t)) != + HX_CIS_NO_ERROR) { + EL_LOGW("stream off fail"); + } + set_mipi_csirx_disable(); +} + +static void _on_stop_capture_cb() { + set_mipi_csirx_enable(); + // stream on + if (hx_drv_cis_setRegTable(IMX708_stream_on, HX_CIS_SIZE_N(IMX708_stream_on, HX_CIS_SensorSetting_t)) != + HX_CIS_NO_ERROR) { + EL_LOGW("stream on fail"); + } +} + el_err_code_t drv_imx708_init(uint16_t width, uint16_t height) { + uint32_t chipid; + uint32_t version; + hx_drv_scu_get_version(&chipid, &version); + if (chipid == WE2_CHIP_VERSION_C) { + _is_version_c = true; + _initiated_before = false; + + _drv_dp_event_cb_on_frame_ready = _on_frame_ready_cb; + _drv_dp_on_stop_stream = _on_stop_capture_cb; + } else { + _is_version_c = false; + _drv_dp_event_cb_on_frame_ready = NULL; + _drv_dp_on_stop_stream = NULL; + } + el_err_code_t ret = EL_OK; HW5x5_CFG_T hw5x5_cfg; JPEG_CFG_T jpeg_cfg; @@ -505,11 +542,28 @@ el_err_code_t drv_imx708_init(uint16_t width, uint16_t height) { } #endif + if (_is_version_c) { + _on_stop_capture_cb(); + } + sensordplib_set_sensorctrl_start(); _frame_ready = false; sensordplib_retrigger_capture(); + if (_is_version_c) { + auto last_time = el_get_time_ms(); + while (!_frame_ready) { + el_sleep(3); + if (el_get_time_ms() - last_time > 1000) { + ret = EL_ETIMOUT; + EL_LOGD("wait frame ready timeout"); + goto err; + } + } + _on_stop_capture_cb(); + } + _initiated_before = true; EL_LOGD("imx708 init success!"); diff --git a/porting/himax/we2/drivers/drv_ov5647.c b/porting/himax/we2/drivers/drv_ov5647.c index 2f99aa81..1472c2f9 100644 --- a/porting/himax/we2/drivers/drv_ov5647.c +++ b/porting/himax/we2/drivers/drv_ov5647.c @@ -193,6 +193,9 @@ static void set_mipi_csirx_disable() { } el_err_code_t drv_ov5647_init(uint16_t width, uint16_t height) { + _drv_dp_event_cb_on_frame_ready = NULL; + _drv_dp_on_stop_stream = NULL; + el_err_code_t ret = EL_OK; HW5x5_CFG_T hw5x5_cfg; JPEG_CFG_T jpeg_cfg;