@@ -43,10 +43,6 @@ struct video_stm32_dcmi_data {
43
43
struct video_format fmt ;
44
44
struct k_fifo fifo_in ;
45
45
struct k_fifo fifo_out ;
46
- uint32_t pixel_format ;
47
- uint32_t height ;
48
- uint32_t width ;
49
- uint32_t pitch ;
50
46
struct video_buffer * vbuf ;
51
47
};
52
48
@@ -127,7 +123,7 @@ static int stm32_dma_init(const struct device *dev)
127
123
128
124
/*
129
125
* DMA configuration
130
- * Due to use of QSPI HAL API in current driver,
126
+ * Due to use of DMA HAL API in current driver,
131
127
* both HAL and Zephyr DMA drivers should be configured.
132
128
* The required configuration for Zephyr DMA driver should only provide
133
129
* the minimum information to inform the DMA slot will be in used and
@@ -179,18 +175,22 @@ static int stm32_dcmi_enable_clock(const struct device *dev)
179
175
{
180
176
const struct video_stm32_dcmi_config * config = dev -> config ;
181
177
const struct device * dcmi_clock = DEVICE_DT_GET (STM32_CLOCK_CONTROL_NODE );
182
- int err ;
183
178
184
179
if (!device_is_ready (dcmi_clock )) {
185
180
LOG_ERR ("clock control device not ready" );
186
181
return - ENODEV ;
187
182
}
188
183
189
184
/* Turn on DCMI peripheral clock */
190
- err = clock_control_on (dcmi_clock , (clock_control_subsys_t * ) & config -> pclken );
191
- if (err < 0 ) {
192
- LOG_ERR ("Failed to enable DCMI clock. Error %d" , err );
193
- return err ;
185
+ return clock_control_on (dcmi_clock , (clock_control_subsys_t * )& config -> pclken );
186
+ }
187
+
188
+ static inline int video_stm32_dcmi_is_fmt_valid (uint32_t pixelformat , uint32_t pitch ,
189
+ uint32_t height )
190
+ {
191
+ if (video_bits_per_pixel (pixelformat ) / BITS_PER_BYTE == 0 ||
192
+ pitch * height > CONFIG_VIDEO_BUFFER_POOL_SZ_MAX ) {
193
+ return - EINVAL ;
194
194
}
195
195
196
196
return 0 ;
@@ -202,25 +202,24 @@ static int video_stm32_dcmi_set_fmt(const struct device *dev,
202
202
{
203
203
const struct video_stm32_dcmi_config * config = dev -> config ;
204
204
struct video_stm32_dcmi_data * data = dev -> data ;
205
- unsigned int bpp = video_bits_per_pixel ( fmt -> pixelformat ) / BITS_PER_BYTE ;
205
+ int ret ;
206
206
207
- if (bpp == 0 || ( ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL ) ) {
207
+ if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL ) {
208
208
return - EINVAL ;
209
209
}
210
210
211
- if ((fmt -> pitch * fmt -> height ) > CONFIG_VIDEO_BUFFER_POOL_SZ_MAX ) {
212
- return - EINVAL ;
211
+ ret = video_stm32_dcmi_is_fmt_valid (fmt -> pixelformat , fmt -> pitch , fmt -> height );
212
+ if (ret < 0 ) {
213
+ return ret ;
213
214
}
214
215
215
- data -> pixel_format = fmt -> pixelformat ;
216
- data -> pitch = fmt -> pitch ;
217
- data -> height = fmt -> height ;
218
- data -> width = fmt -> width ;
219
-
220
- if (video_set_format (config -> sensor_dev , ep , fmt )) {
221
- return - EIO ;
216
+ ret = video_set_format (config -> sensor_dev , ep , fmt );
217
+ if (ret < 0 ) {
218
+ return ret ;
222
219
}
223
220
221
+ data -> fmt = * fmt ;
222
+
224
223
return 0 ;
225
224
}
226
225
@@ -230,33 +229,38 @@ static int video_stm32_dcmi_get_fmt(const struct device *dev,
230
229
{
231
230
struct video_stm32_dcmi_data * data = dev -> data ;
232
231
const struct video_stm32_dcmi_config * config = dev -> config ;
232
+ int ret ;
233
233
234
234
if (fmt == NULL || (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL )) {
235
235
return - EINVAL ;
236
236
}
237
237
238
- if (!video_get_format (config -> sensor_dev , ep , fmt )) {
239
- /* align DCMI with sensor fmt */
240
- return video_stm32_dcmi_set_fmt (dev , ep , fmt );
238
+ /* Align DCMI format with the one provided by the sensor */
239
+ ret = video_get_format (config -> sensor_dev , ep , fmt );
240
+ if (ret < 0 ) {
241
+ return ret ;
242
+ }
243
+
244
+ ret = video_stm32_dcmi_is_fmt_valid (fmt -> pixelformat , fmt -> pitch , fmt -> height );
245
+ if (ret < 0 ) {
246
+ return ret ;
241
247
}
242
248
243
- fmt -> pixelformat = data -> pixel_format ;
244
- fmt -> height = data -> height ;
245
- fmt -> width = data -> width ;
246
- fmt -> pitch = data -> pitch ;
249
+ data -> fmt = * fmt ;
247
250
248
251
return 0 ;
249
252
}
250
253
251
254
static int video_stm32_dcmi_set_stream (const struct device * dev , bool enable )
252
255
{
253
- int err ;
254
256
struct video_stm32_dcmi_data * data = dev -> data ;
255
257
const struct video_stm32_dcmi_config * config = dev -> config ;
258
+ int err ;
256
259
257
260
if (!enable ) {
258
- if (video_stream_stop (config -> sensor_dev )) {
259
- return - EIO ;
261
+ err = video_stream_stop (config -> sensor_dev );
262
+ if (err < 0 ) {
263
+ return err ;
260
264
}
261
265
262
266
err = HAL_DCMI_Stop (& data -> hdcmi );
@@ -285,19 +289,15 @@ static int video_stm32_dcmi_set_stream(const struct device *dev, bool enable)
285
289
return - EIO ;
286
290
}
287
291
288
- if (video_stream_start (config -> sensor_dev )) {
289
- return - EIO ;
290
- }
291
-
292
- return 0 ;
292
+ return video_stream_start (config -> sensor_dev );
293
293
}
294
294
295
295
static int video_stm32_dcmi_enqueue (const struct device * dev ,
296
296
enum video_endpoint_id ep ,
297
297
struct video_buffer * vbuf )
298
298
{
299
299
struct video_stm32_dcmi_data * data = dev -> data ;
300
- const uint32_t buffer_size = data -> pitch * data -> height ;
300
+ const uint32_t buffer_size = data -> fmt . pitch * data -> fmt . height ;
301
301
302
302
if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL ) {
303
303
return - EINVAL ;
@@ -339,7 +339,6 @@ static int video_stm32_dcmi_get_caps(const struct device *dev,
339
339
struct video_caps * caps )
340
340
{
341
341
const struct video_stm32_dcmi_config * config = dev -> config ;
342
- int ret = - ENODEV ;
343
342
344
343
if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL ) {
345
344
return - EINVAL ;
@@ -349,9 +348,7 @@ static int video_stm32_dcmi_get_caps(const struct device *dev,
349
348
caps -> min_line_count = caps -> max_line_count = LINE_COUNT_HEIGHT ;
350
349
351
350
/* Forward the message to the sensor device */
352
- ret = video_get_caps (config -> sensor_dev , ep , caps );
353
-
354
- return ret ;
351
+ return video_get_caps (config -> sensor_dev , ep , caps );
355
352
}
356
353
357
354
static DEVICE_API (video , video_stm32_dcmi_driver_api ) = {
@@ -479,7 +476,7 @@ static int video_stm32_dcmi_init(const struct device *dev)
479
476
err = stm32_dcmi_enable_clock (dev );
480
477
if (err < 0 ) {
481
478
LOG_ERR ("Clock enabling failed." );
482
- return - EIO ;
479
+ return err ;
483
480
}
484
481
485
482
data -> dev = dev ;
0 commit comments