mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
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:
parent
a290081efd
commit
b3832b86c1
@ -447,6 +447,7 @@ int omv_csi_probe(omv_i2c_t *i2c) {
|
|||||||
// Initialize detected sensors.
|
// Initialize detected sensors.
|
||||||
for (size_t i=0; i<dev_count; i++) {
|
for (size_t i=0; i<dev_count; i++) {
|
||||||
omv_csi_t *csi = &csi_all[i];
|
omv_csi_t *csi = &csi_all[i];
|
||||||
|
sensor_init_t init_fun = NULL;
|
||||||
|
|
||||||
csi->detected = true;
|
csi->detected = true;
|
||||||
csi->power_on = 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->chip_id = dev_list[i].chip_id;
|
||||||
csi->slv_addr = dev_list[i].slv_addr;
|
csi->slv_addr = dev_list[i].slv_addr;
|
||||||
|
|
||||||
uint32_t clk_hz = 0;
|
|
||||||
sensor_init_t init_fun = NULL;
|
|
||||||
|
|
||||||
// Find the sensors init function.
|
// Find the sensors init function.
|
||||||
for (size_t i=0; i<OMV_ARRAY_SIZE(sensor_config_table); i++) {
|
for (size_t i=0; i<OMV_ARRAY_SIZE(sensor_config_table); i++) {
|
||||||
const sensor_config_t *config = &sensor_config_table[i];
|
const sensor_config_t *config = &sensor_config_table[i];
|
||||||
if (csi->chip_id == config->chip_id) {
|
if (csi->chip_id == config->chip_id) {
|
||||||
clk_hz = config->clk_hz;
|
|
||||||
init_fun = config->init_fun;
|
init_fun = config->init_fun;
|
||||||
|
csi->clk_hz = config->clk_hz;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -477,35 +475,34 @@ int omv_csi_probe(omv_i2c_t *i2c) {
|
|||||||
// Special case for OV5640.
|
// Special case for OV5640.
|
||||||
#if (OMV_OV5640_REV_Y_CHECK == 1)
|
#if (OMV_OV5640_REV_Y_CHECK == 1)
|
||||||
if (csi->chip_id == OV5640_ID && HAL_GetREVID() < 0x2003) {
|
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
|
#endif
|
||||||
|
|
||||||
// Allow reconfiguring (or disabling) the external clock
|
// Allow reconfiguring (or disabling) the external clock
|
||||||
// if just one sensor is detected, or for main sensors.
|
// if just one sensor is detected, or for main sensors.
|
||||||
if (dev_count == 1 || !csi->auxiliary) {
|
if (dev_count == 1 || !csi->auxiliary) {
|
||||||
omv_csi_set_clk_frequency(clk_hz);
|
omv_csi_set_clk_frequency(csi->clk_hz);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Count aux devices.
|
// Count aux devices.
|
||||||
aux_count += csi->auxiliary;
|
aux_count += csi->auxiliary;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special case: A single aux sensor was detected, clear
|
// Special case: all detected sensors are aux (e.g., Soft-CSI or
|
||||||
// the auxiliary flag so it gets used as the main sensor.
|
// Soft-CSI + Lepton). If only one is found, use it as main. If
|
||||||
if (dev_count == 1 && csi_all[0].auxiliary) {
|
// multiple, pick the first non-Soft-CSI sensor as main.
|
||||||
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.
|
|
||||||
if (dev_count == aux_count) {
|
if (dev_count == aux_count) {
|
||||||
for (size_t i=0; i<dev_count; i++) {
|
for (size_t i=0; i<dev_count; i++) {
|
||||||
omv_csi_t *csi = &csi_all[i];
|
omv_csi_t *csi = &csi_all[i];
|
||||||
if (csi->chip_id == SOFTCSI_ID) {
|
if (dev_count == 1 || csi->chip_id != SOFTCSI_ID) {
|
||||||
csi->auxiliary = 0;
|
|
||||||
aux_count--;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -339,6 +339,7 @@ typedef struct _omv_csi {
|
|||||||
bool auto_rotation; // Rotate Image Automatically
|
bool auto_rotation; // Rotate Image Automatically
|
||||||
bool detected; // Set to true when the sensor is initialized.
|
bool detected; // Set to true when the sensor is initialized.
|
||||||
bool power_on; // Set to true when the sensor is active.
|
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.
|
omv_i2c_t *i2c; // SCCB/I2C bus.
|
||||||
framebuffer_t *fb; // Frame buffer pointer
|
framebuffer_t *fb; // Frame buffer pointer
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user