From 90a568fde5b676856bb281deb3b19f623a8962a2 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sun, 29 Jun 2025 10:26:05 +0200 Subject: [PATCH] common/csi: Add power-on flag. Signed-off-by: iabdalkader --- common/omv_csi.c | 23 ++++++++++++++--------- common/omv_csi.h | 1 + 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/common/omv_csi.c b/common/omv_csi.c index 21492a57a..3a9e609bc 100644 --- a/common/omv_csi.c +++ b/common/omv_csi.c @@ -204,7 +204,9 @@ __weak int omv_csi_abort(omv_csi_t *csi, bool fifo_flush, bool in_irq) { __weak int omv_csi_reset(omv_csi_t *csi, bool hard) { // Disable any ongoing frame capture. - omv_csi_abort(csi, true, false); + if (csi->power_on) { + omv_csi_abort(csi, true, false); + } // Reset the csi state csi->sde = 0; @@ -224,16 +226,15 @@ __weak int omv_csi_reset(omv_csi_t *csi, bool hard) { #else csi->auto_rotation = false; #endif // MICROPY_PY_IMU - - csi->vsync_cb = (omv_csi_cb_t) { NULL, NULL }; - csi->frame_cb = (omv_csi_cb_t) { NULL, NULL }; - - // Reset default color palette. csi->color_palette = rainbow_table; csi->disable_full_flush = false; - + csi->vsync_cb = (omv_csi_cb_t) { NULL, NULL }; + csi->frame_cb = (omv_csi_cb_t) { NULL, NULL }; + // Restore shutdown state on reset. - omv_csi_shutdown(csi, false); + if (!csi->power_on) { + omv_csi_shutdown(csi, false); + } if (hard) { // Disable the bus before reset. @@ -438,11 +439,12 @@ int omv_csi_probe(omv_i2c_t *i2c) { for (size_t i=0; idetected = true; + csi->power_on = true; csi->power_pol = power_pol; csi->reset_pol = reset_pol; csi->chip_id = dev_list[i].chip_id; csi->slv_addr = dev_list[i].slv_addr; - csi->detected = true; uint32_t clk_hz = 0; sensor_init_t init_fun = NULL; @@ -586,6 +588,9 @@ __weak int omv_csi_shutdown(omv_csi_t *csi, int enable) { return OMV_CSI_ERROR_CTL_FAILED; } + // Update power-on flag. + csi->power_on = !enable; + return ret; } diff --git a/common/omv_csi.h b/common/omv_csi.h index 4ff86e731..404d99b01 100644 --- a/common/omv_csi.h +++ b/common/omv_csi.h @@ -337,6 +337,7 @@ typedef struct _omv_csi { bool transpose; // Transpose Image 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. omv_i2c_t *i2c; // SCCB/I2C bus. framebuffer_t *fb; // Frame buffer pointer