common/csi: Fix CSI detection & init logic.

Simplify the detection logic and handle the case where
all detected sensors (one or more) are auxiliary.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This commit is contained in:
iabdalkader 2025-06-30 16:36:02 +02:00
parent a290081efd
commit b3832b86c1
2 changed files with 15 additions and 17 deletions

View File

@ -447,6 +447,7 @@ int omv_csi_probe(omv_i2c_t *i2c) {
// Initialize detected sensors.
for (size_t i=0; i<dev_count; i++) {
omv_csi_t *csi = &csi_all[i];
sensor_init_t init_fun = NULL;
csi->detected = true;
csi->power_on = true;
@ -455,15 +456,12 @@ int omv_csi_probe(omv_i2c_t *i2c) {
csi->chip_id = dev_list[i].chip_id;
csi->slv_addr = dev_list[i].slv_addr;
uint32_t clk_hz = 0;
sensor_init_t init_fun = NULL;
// Find the sensors init function.
for (size_t i=0; i<OMV_ARRAY_SIZE(sensor_config_table); i++) {
const sensor_config_t *config = &sensor_config_table[i];
if (csi->chip_id == config->chip_id) {
clk_hz = config->clk_hz;
init_fun = config->init_fun;
csi->clk_hz = config->clk_hz;
break;
}
}
@ -477,35 +475,34 @@ int omv_csi_probe(omv_i2c_t *i2c) {
// Special case for OV5640.
#if (OMV_OV5640_REV_Y_CHECK == 1)
if (csi->chip_id == OV5640_ID && HAL_GetREVID() < 0x2003) {
clk_hz = OMV_OV5640_REV_Y_FREQ;
csi->clk_hz = OMV_OV5640_REV_Y_FREQ;
}
#endif
// Allow reconfiguring (or disabling) the external clock
// if just one sensor is detected, or for main sensors.
if (dev_count == 1 || !csi->auxiliary) {
omv_csi_set_clk_frequency(clk_hz);
omv_csi_set_clk_frequency(csi->clk_hz);
}
// Count aux devices.
aux_count += csi->auxiliary;
}
// Special case: A single aux sensor was detected, clear
// the auxiliary flag so it gets used as the main sensor.
if (dev_count == 1 && csi_all[0].auxiliary) {
csi_all[0].auxiliary = 0;
aux_count--;
}
// Special case: Soft-CSI and another aux sensor detected,
// (Lepton for example). Use Soft-CSI for the main sensor.
// Special case: all detected sensors are aux (e.g., Soft-CSI or
// Soft-CSI + Lepton). If only one is found, use it as main. If
// multiple, pick the first non-Soft-CSI sensor as main.
if (dev_count == aux_count) {
for (size_t i=0; i<dev_count; i++) {
omv_csi_t *csi = &csi_all[i];
if (csi->chip_id == SOFTCSI_ID) {
csi->auxiliary = 0;
if (dev_count == 1 || csi->chip_id != SOFTCSI_ID) {
aux_count--;
csi->auxiliary = 0;
// If more than one aux sensor was detected, the clock
// hasn't been changed, so reconfigure using this freq.
if (dev_count > 1) {
omv_csi_set_clk_frequency(csi->clk_hz);
}
break;
}
}

View File

@ -339,6 +339,7 @@ typedef struct _omv_csi {
bool auto_rotation; // Rotate Image Automatically
bool detected; // Set to true when the sensor is initialized.
bool power_on; // Set to true when the sensor is active.
uint32_t clk_hz; // Clock frequency requested by the driver.
omv_i2c_t *i2c; // SCCB/I2C bus.
framebuffer_t *fb; // Frame buffer pointer