Skip to content

Commit 85ad69d

Browse files
epc-akefabiobaltieri
authored andcommitted
drivers: video: esp32: add selection api
Forward get/set selection to the camera source and update the driver's video_format on set so buffer sizing and streaming follow the selected region. Signed-off-by: Armin Kessler <[email protected]>
1 parent 84373c4 commit 85ad69d

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

drivers/video/video_esp32_dvp.c

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ static int video_esp32_reload_dma(struct video_esp32_data *data)
8888

8989
ret = dma_reload(cfg->dma_dev, cfg->rx_dma_channel, 0, (uint32_t)data->active_vbuf->buffer,
9090
data->active_vbuf->bytesused);
91-
if (ret) {
91+
if (ret < 0) {
9292
LOG_ERR("Unable to reload DMA (%d)", ret);
9393
return ret;
9494
}
9595

9696
ret = dma_start(cfg->dma_dev, cfg->rx_dma_channel);
97-
if (ret) {
97+
if (ret < 0) {
9898
LOG_ERR("Unable to start DMA (%d)", ret);
9999
return ret;
100100
}
@@ -260,7 +260,7 @@ static int video_esp32_get_fmt(const struct device *dev, struct video_format *fm
260260
LOG_DBG("Get format");
261261

262262
ret = video_get_format(cfg->source_dev, fmt);
263-
if (ret) {
263+
if (ret < 0) {
264264
LOG_ERR("Failed to get format from source");
265265
return ret;
266266
}
@@ -389,6 +389,34 @@ static int video_esp32_init(const struct device *dev)
389389
return 0;
390390
}
391391

392+
int video_esp32_set_selection(const struct device *dev, struct video_selection *sel)
393+
{
394+
struct video_esp32_data *data = dev->data;
395+
const struct video_esp32_config *cfg = dev->config;
396+
int ret;
397+
398+
ret = video_set_selection(cfg->source_dev, sel);
399+
if (ret < 0) {
400+
LOG_ERR("Failed to set selection on source device");
401+
return ret;
402+
}
403+
404+
ret = video_get_format(cfg->source_dev, &data->video_format);
405+
if (ret < 0) {
406+
LOG_ERR("Failed to get format from source device");
407+
return ret;
408+
}
409+
410+
return 0;
411+
}
412+
413+
int video_esp32_get_selection(const struct device *dev, struct video_selection *sel)
414+
{
415+
const struct video_esp32_config *cfg = dev->config;
416+
417+
return video_get_selection(cfg->source_dev, sel);
418+
}
419+
392420
static DEVICE_API(video, esp32_driver_api) = {
393421
/* mandatory callbacks */
394422
.set_format = video_esp32_set_fmt,
@@ -399,6 +427,8 @@ static DEVICE_API(video, esp32_driver_api) = {
399427
.enqueue = video_esp32_enqueue,
400428
.dequeue = video_esp32_dequeue,
401429
.flush = video_esp32_flush,
430+
.set_selection = video_esp32_set_selection,
431+
.get_selection = video_esp32_get_selection,
402432
#ifdef CONFIG_POLL
403433
.set_signal = video_esp32_set_signal,
404434
#endif

0 commit comments

Comments
 (0)