From 9bcef8e17c5270fdf8caaa979b96fc1d88d7bef6 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sun, 27 Jul 2025 15:01:45 +0200 Subject: [PATCH 1/2] common/csi: Add power-on time. Can be used by driver to check for elapsed time since power-on. Signed-off-by: iabdalkader --- common/omv_csi.c | 4 ++++ common/omv_csi.h | 1 + 2 files changed, 5 insertions(+) diff --git a/common/omv_csi.c b/common/omv_csi.c index 676148138..cae4cbd28 100644 --- a/common/omv_csi.c +++ b/common/omv_csi.c @@ -501,6 +501,9 @@ int omv_csi_probe(omv_i2c_t *i2c) { dev_count = omv_csi_detect(i2c, dev_list); } + // Set the current ms for tracking elapsed time since power-on. + uint32_t power_time_ms = mp_hal_ticks_ms(); + // Add special devices, such as SPI sensors, soft-CSI etc... #if OMV_SOFTCSI_ENABLE if (dev_count < OMV_CSI_MAX_DEVICES) { @@ -533,6 +536,7 @@ int omv_csi_probe(omv_i2c_t *i2c) { csi->reset_pol = reset_pol; csi->chip_id = dev_list[i].chip_id; csi->slv_addr = dev_list[i].slv_addr; + csi->power_time_ms = power_time_ms; // Find the sensors init function. for (size_t i=0; i Date: Sun, 27 Jul 2025 15:26:52 +0200 Subject: [PATCH 2/2] common/vospi: make vospi_restart() non-blocking. Check if VOSPI_SYNC_MS has elapsed since the last abort instead of delaying on every call. This avoids blocking other CSIs on back-to-back resync's. Signed-off-by: iabdalkader --- common/vospi.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/common/vospi.c b/common/vospi.c index a9f588a7f..37de340cb 100644 --- a/common/vospi.c +++ b/common/vospi.c @@ -46,7 +46,7 @@ #define VOSPI_BUFFER_SIZE (VOSPI_PACKET_SIZE * 2) // 16-bits #define VOSPI_CLOCK_SPEED 20000000 // hz -#define VOSPI_SYNC_MS 250 // ms +#define VOSPI_SYNC_MS 200 // ms #define VOSPI_DONT_CARE_PACKET (0x0F00) #define VOSPI_HEADER_DONT_CARE(x) (((x) & VOSPI_DONT_CARE_PACKET) == VOSPI_DONT_CARE_PACKET) @@ -66,6 +66,7 @@ typedef struct _vospi_state { bool lepton_3; omv_spi_t spi_bus; volatile uint32_t flags; + uint32_t resync_ms; } vospi_state_t; static vospi_state_t vospi; @@ -182,7 +183,8 @@ int vospi_deinit() { } bool vospi_active(void) { - return vospi.flags & VOSPI_FLAG_CAPTURE; + return (vospi.flags & VOSPI_FLAG_CAPTURE) && + (vospi.flags & VOSPI_FLAG_STREAM); } int vospi_abort(void) { @@ -190,6 +192,7 @@ int vospi_abort(void) { int ret = omv_spi_transfer_abort(&vospi.spi_bus); vospi.pid = 0; vospi.sid = 0; + vospi.resync_ms = mp_hal_ticks_ms(); return ret; } @@ -204,8 +207,8 @@ void vospi_restart(void) { // Resume streaming. vospi.flags |= VOSPI_FLAG_CAPTURE; - if (!(vospi.flags & VOSPI_FLAG_STREAM)) { - mp_hal_delay_ms(VOSPI_SYNC_MS); + if (!(vospi.flags & VOSPI_FLAG_STREAM) && + (mp_hal_ticks_ms() - vospi.resync_ms) >= VOSPI_SYNC_MS) { omv_spi_transfer_start(&vospi.spi_bus, &spi_xfer); vospi.flags |= VOSPI_FLAG_STREAM; }