Skip to content

Commit 86a5d96

Browse files
committed
driver: video: esp32: add video_flush() callback
Adding missing `video_flush()` callback to driver. Signed-off-by: Armin Kessler <ake@espros.com>
1 parent 7823374 commit 86a5d96

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

drivers/video/video_esp32_dvp.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,37 @@ static int video_esp32_get_ctrl(const struct device *dev, unsigned int cid, void
339339
return video_get_ctrl(cfg->source_dev, cid, value);
340340
}
341341

342+
static int video_esp32_flush(const struct device *dev, enum video_endpoint_id ep, bool cancel)
343+
{
344+
struct video_esp32_data *data = dev->data;
345+
struct video_buffer *vbuf = NULL;
346+
347+
if (cancel) {
348+
if (data->is_streaming) {
349+
video_esp32_set_stream(dev, false);
350+
}
351+
if (data->active_vbuf) {
352+
k_fifo_put(&data->fifo_out, data->active_vbuf);
353+
data->active_vbuf = NULL;
354+
}
355+
while (vbuf = k_fifo_get(&data->fifo_in, K_NO_WAIT) != NULL) {
356+
k_fifo_put(&data->fifo_out, vbuf);
357+
#ifdef CONFIG_POLL
358+
if (data->signal_out) {
359+
k_poll_signal_raise(data->signal_out, VIDEO_BUF_ABORTED);
360+
}
361+
#endif
362+
}
363+
}
364+
} else {
365+
while (!k_fifo_is_empty(&data->fifo_in)) {
366+
k_sleep(K_MSEC(1));
367+
}
368+
}
369+
370+
return 0;
371+
}
372+
342373
#ifdef CONFIG_POLL
343374
int video_esp32_set_signal(const struct device *dev, enum video_endpoint_id ep,
344375
struct k_poll_signal *sig)
@@ -401,7 +432,7 @@ static DEVICE_API(video, esp32_driver_api) = {
401432
/* optional callbacks */
402433
.enqueue = video_esp32_enqueue,
403434
.dequeue = video_esp32_dequeue,
404-
.flush = NULL,
435+
.flush = video_esp32_flush,
405436
.set_ctrl = video_esp32_set_ctrl,
406437
.get_ctrl = video_esp32_get_ctrl,
407438
#ifdef CONFIG_POLL

0 commit comments

Comments
 (0)