Skip to content

Commit

Permalink
fix: we2 chip version c compatibility issue with imx series camera
Browse files Browse the repository at this point in the history
* fix: we2 chip version c compatibility issue with imx series camera

* fix: treat frame timeout as internal initialization failure
  • Loading branch information
iChizer0 authored Apr 28, 2024
1 parent 25054dc commit eda3b56
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 1 deletion.
11 changes: 11 additions & 0 deletions porting/himax/we2/drivers/drv_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@ 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);

switch (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;
Expand All @@ -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);
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions porting/himax/we2/drivers/drv_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
53 changes: 53 additions & 0 deletions porting/himax/we2/drivers/drv_imx219.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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!");
Expand Down
56 changes: 55 additions & 1 deletion porting/himax/we2/drivers/drv_imx708.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
};
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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!");
Expand Down
3 changes: 3 additions & 0 deletions porting/himax/we2/drivers/drv_ov5647.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit eda3b56

Please sign in to comment.