diff --git a/ports/stm32/omv_csi.c b/ports/stm32/omv_csi.c index 3b2710c13..5cb9b140a 100644 --- a/ports/stm32/omv_csi.c +++ b/ports/stm32/omv_csi.c @@ -179,6 +179,14 @@ static int stm_csi_config(omv_csi_t *csi, omv_csi_config_t config) { NVIC_SetPriority(DCMI_IRQn, IRQ_PRI_DCMI); HAL_NVIC_EnableIRQ(DCMI_IRQn); #endif + } else if (config == OMV_CSI_CONFIG_DEINIT) { + #if USE_DCMI + HAL_NVIC_DisableIRQ(DCMI_IRQn); + HAL_DCMI_DeInit(&csi->dcmi); + #else + HAL_NVIC_DisableIRQ(DCMIPP_IRQn); + HAL_DCMIPP_DeInit(&csi->dcmi); + #endif } else if (config == OMV_CSI_CONFIG_PIXFORMAT) { #if USE_DCMI DCMI->CR &= ~(DCMI_CR_JPEG_Msk << DCMI_CR_JPEG_Pos); @@ -354,6 +362,16 @@ static int stm_csi_abort(omv_csi_t *csi, bool fifo_flush, bool in_irq) { return 0; } +static int stm_csi_shutdown(omv_csi_t *csi, int enable) { + int ret = 0; + if (enable) { + ret = omv_csi_config(csi, OMV_CSI_CONFIG_DEINIT); + } else { + ret = omv_csi_config(csi, OMV_CSI_CONFIG_INIT); + } + return ret; +} + uint32_t omv_csi_get_clk_frequency() { omv_csi_t *csi = omv_csi_get(-1); @@ -429,37 +447,6 @@ int omv_csi_set_clk_frequency(uint32_t frequency) { return 0; } -int omv_csi_shutdown(omv_csi_t *csi, int enable) { - int ret = 0; - omv_csi_abort(csi, true, false); - - if (enable) { - #if defined(OMV_CSI_POWER_PIN) - if (csi->power_pol == OMV_CSI_ACTIVE_HIGH) { - omv_gpio_write(OMV_CSI_POWER_PIN, 1); - } else { - omv_gpio_write(OMV_CSI_POWER_PIN, 0); - } - #endif - #if USE_DCMI - HAL_NVIC_DisableIRQ(DCMI_IRQn); - HAL_DCMI_DeInit(&csi->dcmi); - #endif - } else { - #if defined(OMV_CSI_POWER_PIN) - if (csi->power_pol == OMV_CSI_ACTIVE_HIGH) { - omv_gpio_write(OMV_CSI_POWER_PIN, 0); - } else { - omv_gpio_write(OMV_CSI_POWER_PIN, 1); - } - #endif - ret = omv_csi_config(csi, OMV_CSI_CONFIG_INIT); - } - - mp_hal_delay_ms(10); - return ret; -} - int omv_csi_set_vsync_callback(omv_csi_t *csi, omv_csi_cb_t cb) { if (cb.fun == NULL) { #if (DCMI_VSYNC_EXTI_SHARED == 0) @@ -1093,6 +1080,7 @@ int omv_csi_init() { csi->fb = framebuffer_get(-1); csi->abort = stm_csi_abort; csi->config = stm_csi_config; + csi->shutdown = stm_csi_shutdown; csi->snapshot = stm_csi_snapshot; csi->color_palette = rainbow_table; }