diff --git a/drivers/video/video_stm32_dcmi.c b/drivers/video/video_stm32_dcmi.c index 88013b5309734..532214dc259e1 100644 --- a/drivers/video/video_stm32_dcmi.c +++ b/drivers/video/video_stm32_dcmi.c @@ -65,8 +65,10 @@ void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi) struct video_stm32_dcmi_data *dev_data = CONTAINER_OF(hdcmi, struct video_stm32_dcmi_data, hdcmi); struct video_buffer *vbuf; + HAL_StatusTypeDef __maybe_unused hal_ret; - HAL_DCMI_Suspend(hdcmi); + hal_ret = HAL_DCMI_Suspend(hdcmi); + __ASSERT_NO_MSG(hal_ret == HAL_OK); vbuf = k_fifo_get(&dev_data->fifo_in, K_NO_WAIT); @@ -81,7 +83,8 @@ void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi) k_fifo_put(&dev_data->fifo_out, vbuf); resume: - HAL_DCMI_Resume(hdcmi); + hal_ret = HAL_DCMI_Resume(hdcmi); + __ASSERT_NO_MSG(hal_ret == HAL_OK); } static void stm32_dcmi_isr(const struct device *dev) @@ -231,6 +234,7 @@ static int video_stm32_dcmi_set_stream(const struct device *dev, bool enable, { struct video_stm32_dcmi_data *data = dev->data; const struct video_stm32_dcmi_config *config = dev->config; + HAL_StatusTypeDef hal_ret; int err; if (!enable) { @@ -239,8 +243,8 @@ static int video_stm32_dcmi_set_stream(const struct device *dev, bool enable, return err; } - err = HAL_DCMI_Stop(&data->hdcmi); - if (err != HAL_OK) { + hal_ret = HAL_DCMI_Stop(&data->hdcmi); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to stop DCMI"); return -EIO; } @@ -262,9 +266,9 @@ static int video_stm32_dcmi_set_stream(const struct device *dev, bool enable, data->hdcmi.Instance->CR &= ~(DCMI_CR_FCRC_0 | DCMI_CR_FCRC_1); data->hdcmi.Instance->CR |= STM32_DCMI_GET_CAPTURE_RATE(data->capture_rate); - err = HAL_DCMI_Start_DMA(&data->hdcmi, DCMI_MODE_CONTINUOUS, - (uint32_t)data->vbuf->buffer, data->vbuf->bytesused / 4); - if (err != HAL_OK) { + hal_ret = HAL_DCMI_Start_DMA(&data->hdcmi, DCMI_MODE_CONTINUOUS, + (uint32_t)data->vbuf->buffer, data->vbuf->bytesused / 4); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to start DCMI DMA"); return -EIO; } @@ -543,8 +547,7 @@ static int video_stm32_dcmi_init(const struct device *dev) config->irq_config(dev); /* Initialize DCMI peripheral */ - err = HAL_DCMI_Init(&data->hdcmi); - if (err != HAL_OK) { + if (HAL_DCMI_Init(&data->hdcmi) != HAL_OK) { LOG_ERR("DCMI initialization failed."); return -EIO; } diff --git a/drivers/video/video_stm32_dcmipp.c b/drivers/video/video_stm32_dcmipp.c index d8608fc22f15f..b2755cd5f5843 100644 --- a/drivers/video/video_stm32_dcmipp.c +++ b/drivers/video/video_stm32_dcmipp.c @@ -196,15 +196,15 @@ void HAL_DCMIPP_PIPE_FrameEventCallback(DCMIPP_HandleTypeDef *hdcmipp, uint32_t struct stm32_dcmipp_data *dcmipp = CONTAINER_OF(hdcmipp, struct stm32_dcmipp_data, hdcmipp); struct stm32_dcmipp_pipe_data *pipe = dcmipp->pipe[Pipe]; + HAL_StatusTypeDef hal_ret; uint32_t bytesused; - int ret; __ASSERT(pipe->active, "Unexpected behavior, active_buf must not be NULL"); /* Counter is only available on Pipe0 */ if (Pipe == DCMIPP_PIPE0) { - ret = HAL_DCMIPP_PIPE_GetDataCounter(hdcmipp, Pipe, &bytesused); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_PIPE_GetDataCounter(hdcmipp, Pipe, &bytesused); + if (hal_ret != HAL_OK) { LOG_WRN("Failed to read counter - buffer in error"); pipe->active->bytesused = 0; } else { @@ -324,7 +324,7 @@ static int stm32_dcmipp_conf_parallel(const struct device *dev, struct stm32_dcmipp_data *dcmipp = dev->data; const struct stm32_dcmipp_config *config = dev->config; DCMIPP_ParallelConfTypeDef parallel_cfg = { 0 }; - int ret; + HAL_StatusTypeDef hal_ret; parallel_cfg.Format = input_fmt->dcmipp_format; parallel_cfg.SwapCycles = DCMIPP_SWAPCYCLES_DISABLE; @@ -334,8 +334,8 @@ static int stm32_dcmipp_conf_parallel(const struct device *dev, parallel_cfg.ExtendedDataMode = DCMIPP_INTERFACE_8BITS; parallel_cfg.SynchroMode = DCMIPP_SYNCHRO_HARDWARE; - ret = HAL_DCMIPP_PARALLEL_SetConfig(&dcmipp->hdcmipp, ¶llel_cfg); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_PARALLEL_SetConfig(&dcmipp->hdcmipp, ¶llel_cfg); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to configure DCMIPP Parallel interface"); return -EIO; } @@ -381,8 +381,9 @@ static int stm32_dcmipp_conf_csi(const struct device *dev, uint32_t dcmipp_csi_b const struct stm32_dcmipp_config *config = dev->config; struct stm32_dcmipp_data *dcmipp = dev->data; DCMIPP_CSI_ConfTypeDef csiconf = { 0 }; + HAL_StatusTypeDef hal_ret; int64_t phy_bitrate; - int err, i; + int i; csiconf.NumberOfLanes = config->csi.nb_lanes == 2 ? DCMIPP_CSI_TWO_DATA_LANES : DCMIPP_CSI_ONE_DATA_LANE; @@ -411,17 +412,17 @@ static int stm32_dcmipp_conf_csi(const struct device *dev, uint32_t dcmipp_csi_b } csiconf.PHYBitrate = stm32_dcmipp_bitrate[i].PHYBitrate; - err = HAL_DCMIPP_CSI_SetConfig(&dcmipp->hdcmipp, &csiconf); - if (err != HAL_OK) { + hal_ret = HAL_DCMIPP_CSI_SetConfig(&dcmipp->hdcmipp, &csiconf); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to configure DCMIPP CSI"); return -EIO; } /* Set Virtual Channel config */ /* TODO - need to be able to use an alternate VC, info coming from the source */ - err = HAL_DCMIPP_CSI_SetVCConfig(&dcmipp->hdcmipp, DCMIPP_VIRTUAL_CHANNEL0, - dcmipp_csi_bpp); - if (err != HAL_OK) { + hal_ret = HAL_DCMIPP_CSI_SetVCConfig(&dcmipp->hdcmipp, DCMIPP_VIRTUAL_CHANNEL0, + dcmipp_csi_bpp); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to set CSI configuration"); return -EIO; } @@ -691,7 +692,7 @@ static int stm32_dcmipp_set_crop(struct stm32_dcmipp_pipe_data *pipe) DCMIPP_CropConfTypeDef crop_cfg; uint32_t frame_width = dcmipp->source_fmt.width; uint32_t frame_height = dcmipp->source_fmt.height; - int ret; + HAL_StatusTypeDef hal_ret; #if defined(STM32_DCMIPP_HAS_PIXEL_PIPES) if (pipe->id == DCMIPP_PIPE1 || pipe->id == DCMIPP_PIPE2) { @@ -702,8 +703,8 @@ static int stm32_dcmipp_set_crop(struct stm32_dcmipp_pipe_data *pipe) /* If crop area is equal to frame size, disable the crop */ if (pipe->crop.width == frame_width && pipe->crop.height == frame_height) { - ret = HAL_DCMIPP_PIPE_DisableCrop(&dcmipp->hdcmipp, pipe->id); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_PIPE_DisableCrop(&dcmipp->hdcmipp, pipe->id); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to disable pipe crop"); return -EIO; } @@ -731,14 +732,14 @@ static int stm32_dcmipp_set_crop(struct stm32_dcmipp_pipe_data *pipe) } #endif - ret = HAL_DCMIPP_PIPE_SetCropConfig(&dcmipp->hdcmipp, pipe->id, &crop_cfg); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_PIPE_SetCropConfig(&dcmipp->hdcmipp, pipe->id, &crop_cfg); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to configure pipe crop"); return -EIO; } - ret = HAL_DCMIPP_PIPE_EnableCrop(&dcmipp->hdcmipp, pipe->id); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_PIPE_EnableCrop(&dcmipp->hdcmipp, pipe->id); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to enable pipe crop"); return -EIO; } @@ -760,17 +761,17 @@ static int stm32_dcmipp_set_downscale(struct stm32_dcmipp_pipe_data *pipe) DCMIPP_DownsizeTypeDef downsize_cfg; struct video_rect *compose = &pipe->compose; uint32_t hdec = 1, vdec = 1; - int ret; + HAL_StatusTypeDef hal_ret; if (compose->width == pipe->crop.width && compose->height == pipe->crop.height) { - ret = HAL_DCMIPP_PIPE_DisableDecimation(&dcmipp->hdcmipp, pipe->id); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_PIPE_DisableDecimation(&dcmipp->hdcmipp, pipe->id); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to disable the pipe decimation"); return -EIO; } - ret = HAL_DCMIPP_PIPE_DisableDownsize(&dcmipp->hdcmipp, pipe->id); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_PIPE_DisableDownsize(&dcmipp->hdcmipp, pipe->id); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to disable the pipe downsize"); return -EIO; } @@ -789,8 +790,8 @@ static int stm32_dcmipp_set_downscale(struct stm32_dcmipp_pipe_data *pipe) } if (hdec == 1 && vdec == 1) { - ret = HAL_DCMIPP_PIPE_DisableDecimation(&dcmipp->hdcmipp, pipe->id); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_PIPE_DisableDecimation(&dcmipp->hdcmipp, pipe->id); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to disable the pipe decimation"); return -EIO; } @@ -799,13 +800,13 @@ static int stm32_dcmipp_set_downscale(struct stm32_dcmipp_pipe_data *pipe) dec_cfg.HRatio = __builtin_ctz(hdec) << DCMIPP_P1DECR_HDEC_Pos; dec_cfg.VRatio = __builtin_ctz(vdec) << DCMIPP_P1DECR_VDEC_Pos; - ret = HAL_DCMIPP_PIPE_SetDecimationConfig(&dcmipp->hdcmipp, pipe->id, &dec_cfg); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_PIPE_SetDecimationConfig(&dcmipp->hdcmipp, pipe->id, &dec_cfg); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to disable the pipe decimation"); return -EIO; } - ret = HAL_DCMIPP_PIPE_EnableDecimation(&dcmipp->hdcmipp, pipe->id); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_PIPE_EnableDecimation(&dcmipp->hdcmipp, pipe->id); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to enable the pipe decimation"); return -EIO; } @@ -835,14 +836,14 @@ static int stm32_dcmipp_set_downscale(struct stm32_dcmipp_pipe_data *pipe) downsize_cfg.HSize = compose->width; downsize_cfg.VSize = compose->height; - ret = HAL_DCMIPP_PIPE_SetDownsizeConfig(&dcmipp->hdcmipp, pipe->id, &downsize_cfg); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_PIPE_SetDownsizeConfig(&dcmipp->hdcmipp, pipe->id, &downsize_cfg); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to configure the pipe downsize"); return -EIO; } - ret = HAL_DCMIPP_PIPE_EnableDownsize(&dcmipp->hdcmipp, pipe->id); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_PIPE_EnableDownsize(&dcmipp->hdcmipp, pipe->id); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to enable the pipe downsize"); return -EIO; } @@ -871,7 +872,7 @@ static int stm32_dcmipp_set_yuv_conversion(struct stm32_dcmipp_pipe_data *pipe, { struct stm32_dcmipp_data *dcmipp = pipe->dcmipp; const DCMIPP_ColorConversionConfTypeDef *cfg = NULL; - int ret; + HAL_StatusTypeDef hal_ret; /* No YUV conversion on pipe 2 */ if (pipe->id == DCMIPP_PIPE2) { @@ -889,8 +890,8 @@ static int stm32_dcmipp_set_yuv_conversion(struct stm32_dcmipp_pipe_data *pipe, /* Need to perform YUV to RGB conversion */ cfg = &stm32_dcmipp_yuv_to_rgb; } else { - ret = HAL_DCMIPP_PIPE_DisableYUVConversion(&dcmipp->hdcmipp, pipe->id); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_PIPE_DisableYUVConversion(&dcmipp->hdcmipp, pipe->id); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to disable YUV conversion"); return -EIO; } @@ -898,14 +899,14 @@ static int stm32_dcmipp_set_yuv_conversion(struct stm32_dcmipp_pipe_data *pipe, return 0; } - ret = HAL_DCMIPP_PIPE_SetYUVConversionConfig(&dcmipp->hdcmipp, pipe->id, cfg); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_PIPE_SetYUVConversionConfig(&dcmipp->hdcmipp, pipe->id, cfg); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to setup YUV conversion"); return -EIO; } - ret = HAL_DCMIPP_PIPE_EnableYUVConversion(&dcmipp->hdcmipp, pipe->id); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_PIPE_EnableYUVConversion(&dcmipp->hdcmipp, pipe->id); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to disable YUV conversion"); return -EIO; } @@ -922,7 +923,7 @@ static int stm32_dcmipp_start_pipeline(const struct device *dev, #if defined(STM32_DCMIPP_HAS_PIXEL_PIPES) struct video_format *fmt = &pipe->fmt; #endif - int ret; + HAL_StatusTypeDef hal_ret; #if defined(STM32_DCMIPP_HAS_PIXEL_PIPES) if (VIDEO_FMT_IS_PLANAR(fmt)) { @@ -935,20 +936,21 @@ static int stm32_dcmipp_start_pipeline(const struct device *dev, }; if (config->bus_type == VIDEO_BUS_TYPE_PARALLEL) { - ret = HAL_DCMIPP_PIPE_FullPlanarStart(&dcmipp->hdcmipp, pipe->id, - &planar_addr, DCMIPP_MODE_CONTINUOUS); + hal_ret = HAL_DCMIPP_PIPE_FullPlanarStart(&dcmipp->hdcmipp, pipe->id, + &planar_addr, + DCMIPP_MODE_CONTINUOUS); } #if defined(STM32_DCMIPP_HAS_CSI) else if (config->bus_type == VIDEO_BUS_TYPE_CSI2_DPHY) { - ret = HAL_DCMIPP_CSI_PIPE_FullPlanarStart(&dcmipp->hdcmipp, pipe->id, - DCMIPP_VIRTUAL_CHANNEL0, - &planar_addr, - DCMIPP_MODE_CONTINUOUS); + hal_ret = HAL_DCMIPP_CSI_PIPE_FullPlanarStart(&dcmipp->hdcmipp, pipe->id, + DCMIPP_VIRTUAL_CHANNEL0, + &planar_addr, + DCMIPP_MODE_CONTINUOUS); } #endif else { LOG_ERR("Invalid bus_type"); - ret = -EINVAL; + hal_ret = HAL_ERROR; } } else if (VIDEO_FMT_IS_SEMI_PLANAR(fmt)) { uint8_t *uv_addr = pipe->next->buffer + VIDEO_FMT_PLANAR_Y_PLANE_SIZE(fmt); @@ -958,45 +960,45 @@ static int stm32_dcmipp_start_pipeline(const struct device *dev, }; if (config->bus_type == VIDEO_BUS_TYPE_PARALLEL) { - ret = HAL_DCMIPP_PIPE_SemiPlanarStart(&dcmipp->hdcmipp, pipe->id, - &semiplanar_addr, - DCMIPP_MODE_CONTINUOUS); + hal_ret = HAL_DCMIPP_PIPE_SemiPlanarStart(&dcmipp->hdcmipp, pipe->id, + &semiplanar_addr, + DCMIPP_MODE_CONTINUOUS); } #if defined(STM32_DCMIPP_HAS_CSI) else if (config->bus_type == VIDEO_BUS_TYPE_CSI2_DPHY) { - ret = HAL_DCMIPP_CSI_PIPE_SemiPlanarStart(&dcmipp->hdcmipp, pipe->id, - DCMIPP_VIRTUAL_CHANNEL0, - &semiplanar_addr, - DCMIPP_MODE_CONTINUOUS); + hal_ret = HAL_DCMIPP_CSI_PIPE_SemiPlanarStart(&dcmipp->hdcmipp, pipe->id, + DCMIPP_VIRTUAL_CHANNEL0, + &semiplanar_addr, + DCMIPP_MODE_CONTINUOUS); } #endif else { LOG_ERR("Invalid bus_type"); - ret = -EINVAL; + hal_ret = HAL_ERROR; } } else { #endif if (config->bus_type == VIDEO_BUS_TYPE_PARALLEL) { - ret = HAL_DCMIPP_PIPE_Start(&dcmipp->hdcmipp, pipe->id, - (uint32_t)pipe->next->buffer, - DCMIPP_MODE_CONTINUOUS); + hal_ret = HAL_DCMIPP_PIPE_Start(&dcmipp->hdcmipp, pipe->id, + (uint32_t)pipe->next->buffer, + DCMIPP_MODE_CONTINUOUS); } #if defined(STM32_DCMIPP_HAS_CSI) else if (config->bus_type == VIDEO_BUS_TYPE_CSI2_DPHY) { - ret = HAL_DCMIPP_CSI_PIPE_Start(&dcmipp->hdcmipp, pipe->id, - DCMIPP_VIRTUAL_CHANNEL0, - (uint32_t)pipe->next->buffer, - DCMIPP_MODE_CONTINUOUS); + hal_ret = HAL_DCMIPP_CSI_PIPE_Start(&dcmipp->hdcmipp, pipe->id, + DCMIPP_VIRTUAL_CHANNEL0, + (uint32_t)pipe->next->buffer, + DCMIPP_MODE_CONTINUOUS); } #endif else { LOG_ERR("Invalid bus_type"); - ret = -EINVAL; + hal_ret = HAL_ERROR; } #if defined(STM32_DCMIPP_HAS_PIXEL_PIPES) } #endif - if (ret != HAL_OK) { + if (hal_ret != HAL_OK) { return -EIO; } @@ -1015,6 +1017,7 @@ static int stm32_dcmipp_stream_enable(const struct device *dev) DCMIPP_CSI_PIPE_ConfTypeDef csi_pipe_cfg = { 0 }; #endif DCMIPP_PipeConfTypeDef pipe_cfg = { 0 }; + HAL_StatusTypeDef hal_ret; int ret; k_mutex_lock(&pipe->lock, K_FOREVER); @@ -1069,10 +1072,10 @@ static int stm32_dcmipp_stream_enable(const struct device *dev) /* Configure the Pipe input */ csi_pipe_cfg.DataTypeMode = DCMIPP_DTMODE_DTIDA; csi_pipe_cfg.DataTypeIDA = input_fmt->dcmipp_csi_dt; - ret = HAL_DCMIPP_CSI_PIPE_SetConfig(&dcmipp->hdcmipp, - pipe->id == DCMIPP_PIPE2 ? DCMIPP_PIPE1 : pipe->id, - &csi_pipe_cfg); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_CSI_PIPE_SetConfig(&dcmipp->hdcmipp, + pipe->id == DCMIPP_PIPE2 ? DCMIPP_PIPE1 : pipe->id, + &csi_pipe_cfg); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to configure pipe #%d input", pipe->id); ret = -EIO; goto out; @@ -1094,8 +1097,8 @@ static int stm32_dcmipp_stream_enable(const struct device *dev) pipe_cfg.PixelPackerFormat = mapping->pixels.dcmipp_format; } #endif - ret = HAL_DCMIPP_PIPE_SetConfig(&dcmipp->hdcmipp, pipe->id, &pipe_cfg); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_PIPE_SetConfig(&dcmipp->hdcmipp, pipe->id, &pipe_cfg); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to configure pipe #%d", pipe->id); ret = -EIO; goto out; @@ -1110,9 +1113,9 @@ static int stm32_dcmipp_stream_enable(const struct device *dev) /* Only the PIPE0 has a limiter */ /* Set Limiter to avoid buffer overflow, in number of 32 bits words */ - ret = HAL_DCMIPP_PIPE_EnableLimitEvent(&dcmipp->hdcmipp, DCMIPP_PIPE0, - (fmt->pitch * fmt->height) / 4); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_PIPE_EnableLimitEvent(&dcmipp->hdcmipp, DCMIPP_PIPE0, + (fmt->pitch * fmt->height) / 4); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to set limiter"); ret = -EIO; goto out; @@ -1125,15 +1128,15 @@ static int stm32_dcmipp_stream_enable(const struct device *dev) /* Enable / disable SWAPRB if necessary */ if (mapping->pixels.swap_uv) { - ret = HAL_DCMIPP_PIPE_EnableRedBlueSwap(&dcmipp->hdcmipp, pipe->id); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_PIPE_EnableRedBlueSwap(&dcmipp->hdcmipp, pipe->id); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to enable Red-Blue swap"); ret = -EIO; goto out; } } else { - ret = HAL_DCMIPP_PIPE_DisableRedBlueSwap(&dcmipp->hdcmipp, pipe->id); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_PIPE_DisableRedBlueSwap(&dcmipp->hdcmipp, pipe->id); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to disable Red-Blue swap"); ret = -EIO; goto out; @@ -1142,17 +1145,18 @@ static int stm32_dcmipp_stream_enable(const struct device *dev) if (source_colorspace == VIDEO_COLORSPACE_RAW) { /* Enable demosaicing if input format is Bayer */ - ret = HAL_DCMIPP_PIPE_EnableISPRawBayer2RGB(&dcmipp->hdcmipp, DCMIPP_PIPE1); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_PIPE_EnableISPRawBayer2RGB(&dcmipp->hdcmipp, + DCMIPP_PIPE1); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to enable demosaicing"); ret = -EIO; goto out; } } else { /* Disable demosaicing */ - ret = HAL_DCMIPP_PIPE_DisableISPRawBayer2RGB(&dcmipp->hdcmipp, - DCMIPP_PIPE1); - if (ret != HAL_OK) { + hal_ret = HAL_DCMIPP_PIPE_DisableISPRawBayer2RGB(&dcmipp->hdcmipp, + DCMIPP_PIPE1); + if (hal_ret != HAL_OK) { LOG_ERR("Failed to disable demosaicing"); ret = -EIO; goto out; @@ -1198,12 +1202,18 @@ static int stm32_dcmipp_stream_enable(const struct device *dev) if (ret < 0) { LOG_ERR("Failed to start the source"); if (config->bus_type == VIDEO_BUS_TYPE_PARALLEL) { - HAL_DCMIPP_PIPE_Stop(&dcmipp->hdcmipp, pipe->id); + if (HAL_DCMIPP_PIPE_Stop(&dcmipp->hdcmipp, pipe->id) != HAL_OK) { + ret = -EIO; + goto out; + } } #if defined(STM32_DCMIPP_HAS_CSI) else if (config->bus_type == VIDEO_BUS_TYPE_CSI2_DPHY) { - HAL_DCMIPP_CSI_PIPE_Stop(&dcmipp->hdcmipp, pipe->id, - DCMIPP_VIRTUAL_CHANNEL0); + if (HAL_DCMIPP_CSI_PIPE_Stop(&dcmipp->hdcmipp, pipe->id, + DCMIPP_VIRTUAL_CHANNEL0) != HAL_OK) { + ret = -EIO; + goto out; + } } #endif else { @@ -1255,12 +1265,18 @@ static int stm32_dcmipp_stream_disable(const struct device *dev) #endif /* Disable the DCMIPP Pipeline */ + ret = 0; if (config->bus_type == VIDEO_BUS_TYPE_PARALLEL) { - ret = HAL_DCMIPP_PIPE_Stop(&dcmipp->hdcmipp, pipe->id); + if (HAL_DCMIPP_PIPE_Stop(&dcmipp->hdcmipp, pipe->id) != HAL_OK) { + ret = -EIO; + } } #if defined(STM32_DCMIPP_HAS_CSI) else if (config->bus_type == VIDEO_BUS_TYPE_CSI2_DPHY) { - ret = HAL_DCMIPP_CSI_PIPE_Stop(&dcmipp->hdcmipp, pipe->id, DCMIPP_VIRTUAL_CHANNEL0); + if (HAL_DCMIPP_CSI_PIPE_Stop(&dcmipp->hdcmipp, pipe->id, + DCMIPP_VIRTUAL_CHANNEL0) != HAL_OK) { + ret = -EIO; + } } #endif else { @@ -1268,9 +1284,8 @@ static int stm32_dcmipp_stream_disable(const struct device *dev) ret = -EIO; goto out; } - if (ret != HAL_OK) { + if (ret < 0) { LOG_ERR("Failed to stop the pipeline"); - ret = -EIO; goto out; }