diff --git a/doc/releases/migration-guide-4.2.rst b/doc/releases/migration-guide-4.2.rst index 028b3dad45ce..7e32f9ad927a 100644 --- a/doc/releases/migration-guide-4.2.rst +++ b/doc/releases/migration-guide-4.2.rst @@ -508,6 +508,14 @@ Video :c:func:`video_set_frmival`. See (:github:`89627`). +* video_endpoint_id enum has been dropped. It is no longer a parameter in any video API. + +* video_buf_type enum has been added. It is a required parameter in the following video APIs: + + ``set_stream`` + ``video_stream_start`` + ``video_stream_stop`` + Other subsystems **************** diff --git a/drivers/video/gc2145.c b/drivers/video/gc2145.c index 3b6596453ee2..ad724a98983b 100644 --- a/drivers/video/gc2145.c +++ b/drivers/video/gc2145.c @@ -1040,8 +1040,7 @@ static uint8_t gc2145_check_connection(const struct device *dev) return 0; } -static int gc2145_set_fmt(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt) +static int gc2145_set_fmt(const struct device *dev, struct video_format *fmt) { struct gc2145_data *drv_data = dev->data; size_t res = ARRAY_SIZE(fmts); @@ -1085,8 +1084,7 @@ static int gc2145_set_fmt(const struct device *dev, enum video_endpoint_id ep, return 0; } -static int gc2145_get_fmt(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt) +static int gc2145_get_fmt(const struct device *dev, struct video_format *fmt) { struct gc2145_data *drv_data = dev->data; @@ -1095,7 +1093,7 @@ static int gc2145_get_fmt(const struct device *dev, enum video_endpoint_id ep, return 0; } -static int gc2145_set_stream(const struct device *dev, bool enable) +static int gc2145_set_stream(const struct device *dev, bool enable, enum video_buf_type type) { const struct gc2145_config *cfg = dev->config; @@ -1103,8 +1101,7 @@ static int gc2145_set_stream(const struct device *dev, bool enable) : gc2145_write_reg(&cfg->i2c, 0xf2, 0x00); } -static int gc2145_get_caps(const struct device *dev, enum video_endpoint_id ep, - struct video_caps *caps) +static int gc2145_get_caps(const struct device *dev, struct video_caps *caps) { caps->format_caps = fmts; return 0; @@ -1188,7 +1185,7 @@ static int gc2145_init(const struct device *dev) fmt.height = RESOLUTION_QVGA_H; fmt.pitch = RESOLUTION_QVGA_W * 2; - ret = gc2145_set_fmt(dev, VIDEO_EP_OUT, &fmt); + ret = gc2145_set_fmt(dev, &fmt); if (ret) { LOG_ERR("Unable to configure default format"); return ret; diff --git a/drivers/video/mt9m114.c b/drivers/video/mt9m114.c index 16d4e61bb391..ec855474409d 100644 --- a/drivers/video/mt9m114.c +++ b/drivers/video/mt9m114.c @@ -397,8 +397,7 @@ static int mt9m114_set_output_format(const struct device *dev, int pixel_format) return ret; } -static int mt9m114_set_fmt(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt) +static int mt9m114_set_fmt(const struct device *dev, struct video_format *fmt) { struct mt9m114_data *drv_data = dev->data; int ret; @@ -450,8 +449,7 @@ static int mt9m114_set_fmt(const struct device *dev, enum video_endpoint_id ep, return mt9m114_set_state(dev, MT9M114_SYS_STATE_ENTER_CONFIG_CHANGE); } -static int mt9m114_get_fmt(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt) +static int mt9m114_get_fmt(const struct device *dev, struct video_format *fmt) { struct mt9m114_data *drv_data = dev->data; @@ -460,14 +458,13 @@ static int mt9m114_get_fmt(const struct device *dev, enum video_endpoint_id ep, return 0; } -static int mt9m114_set_stream(const struct device *dev, bool enable) +static int mt9m114_set_stream(const struct device *dev, bool enable, enum video_buf_type type) { return enable ? mt9m114_set_state(dev, MT9M114_SYS_STATE_START_STREAMING) : mt9m114_set_state(dev, MT9M114_SYS_STATE_ENTER_SUSPEND); } -static int mt9m114_get_caps(const struct device *dev, enum video_endpoint_id ep, - struct video_caps *caps) +static int mt9m114_get_caps(const struct device *dev, struct video_caps *caps) { caps->format_caps = fmts; return 0; @@ -563,7 +560,7 @@ static int mt9m114_init(const struct device *dev) fmt.height = 272; fmt.pitch = fmt.width * 2; - ret = mt9m114_set_fmt(dev, VIDEO_EP_OUT, &fmt); + ret = mt9m114_set_fmt(dev, &fmt); if (ret) { LOG_ERR("Unable to configure default format"); return -EIO; diff --git a/drivers/video/ov2640.c b/drivers/video/ov2640.c index 5da0c2d504e1..7a660cbb6439 100644 --- a/drivers/video/ov2640.c +++ b/drivers/video/ov2640.c @@ -829,8 +829,7 @@ uint8_t ov2640_check_connection(const struct device *dev) return ret; } -static int ov2640_set_fmt(const struct device *dev, - enum video_endpoint_id ep, struct video_format *fmt) +static int ov2640_set_fmt(const struct device *dev, struct video_format *fmt) { struct ov2640_data *drv_data = dev->data; uint16_t width, height; @@ -872,8 +871,7 @@ static int ov2640_set_fmt(const struct device *dev, return -ENOTSUP; } -static int ov2640_get_fmt(const struct device *dev, - enum video_endpoint_id ep, struct video_format *fmt) +static int ov2640_get_fmt(const struct device *dev, struct video_format *fmt) { struct ov2640_data *drv_data = dev->data; @@ -882,14 +880,12 @@ static int ov2640_get_fmt(const struct device *dev, return 0; } -static int ov2640_set_stream(const struct device *dev, bool enable) +static int ov2640_set_stream(const struct device *dev, bool enable, enum video_buf_type type) { return 0; } -static int ov2640_get_caps(const struct device *dev, - enum video_endpoint_id ep, - struct video_caps *caps) +static int ov2640_get_caps(const struct device *dev, struct video_caps *caps) { caps->format_caps = fmts; return 0; @@ -1037,7 +1033,7 @@ static int ov2640_init(const struct device *dev) fmt.width = SVGA_HSIZE; fmt.height = SVGA_VSIZE; fmt.pitch = SVGA_HSIZE * 2; - ret = ov2640_set_fmt(dev, VIDEO_EP_OUT, &fmt); + ret = ov2640_set_fmt(dev, &fmt); if (ret) { LOG_ERR("Unable to configure default format"); return -EIO; diff --git a/drivers/video/ov5640.c b/drivers/video/ov5640.c index c70908a24348..9610a9ccaa46 100644 --- a/drivers/video/ov5640.c +++ b/drivers/video/ov5640.c @@ -767,8 +767,7 @@ static int ov5640_set_fmt_dvp(const struct ov5640_config *cfg) return 0; } -static int ov5640_set_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival *frmival) +static int ov5640_set_frmival(const struct device *dev, struct video_frmival *frmival) { const struct ov5640_config *cfg = dev->config; struct ov5640_data *drv_data = dev->data; @@ -823,8 +822,7 @@ static int ov5640_set_frmival(const struct device *dev, enum video_endpoint_id e return 0; } -static int ov5640_set_fmt(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt) +static int ov5640_set_fmt(const struct device *dev, struct video_format *fmt) { struct ov5640_data *drv_data = dev->data; const struct ov5640_config *cfg = dev->config; @@ -906,11 +904,10 @@ static int ov5640_set_fmt(const struct device *dev, enum video_endpoint_id ep, def_frmival.denominator = drv_data->cur_mode->def_frmrate; def_frmival.numerator = 1; - return ov5640_set_frmival(dev, ep, &def_frmival); + return ov5640_set_frmival(dev, &def_frmival); } -static int ov5640_get_fmt(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt) +static int ov5640_get_fmt(const struct device *dev, struct video_format *fmt) { struct ov5640_data *drv_data = dev->data; @@ -919,14 +916,13 @@ static int ov5640_get_fmt(const struct device *dev, enum video_endpoint_id ep, return 0; } -static int ov5640_get_caps(const struct device *dev, enum video_endpoint_id ep, - struct video_caps *caps) +static int ov5640_get_caps(const struct device *dev, struct video_caps *caps) { caps->format_caps = ov5640_is_dvp(dev) ? dvp_fmts : csi2_fmts; return 0; } -static int ov5640_set_stream(const struct device *dev, bool enable) +static int ov5640_set_stream(const struct device *dev, bool enable, enum video_buf_type type) { const struct ov5640_config *cfg = dev->config; @@ -1177,8 +1173,7 @@ static int ov5640_get_volatile_ctrl(const struct device *dev, uint32_t id) return 0; } -static int ov5640_get_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival *frmival) +static int ov5640_get_frmival(const struct device *dev, struct video_frmival *frmival) { struct ov5640_data *drv_data = dev->data; @@ -1192,8 +1187,7 @@ static int ov5640_get_frmival(const struct device *dev, enum video_endpoint_id e return 0; } -static int ov5640_enum_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival_enum *fie) +static int ov5640_enum_frmival(const struct device *dev, struct video_frmival_enum *fie) { uint8_t i = 0; @@ -1430,7 +1424,7 @@ static int ov5640_init(const struct device *dev) fmt.height = 720; } fmt.pitch = fmt.width * 2; - ret = ov5640_set_fmt(dev, VIDEO_EP_OUT, &fmt); + ret = ov5640_set_fmt(dev, &fmt); if (ret) { LOG_ERR("Unable to configure default format"); return -EIO; diff --git a/drivers/video/ov7670.c b/drivers/video/ov7670.c index 17fce01cd5a1..3b6ad6ac288f 100644 --- a/drivers/video/ov7670.c +++ b/drivers/video/ov7670.c @@ -353,15 +353,13 @@ static const struct ov7670_reg ov7670_init_regtbl[] = { {0xb8, 0x0a}, }; -static int ov7670_get_caps(const struct device *dev, enum video_endpoint_id ep, - struct video_caps *caps) +static int ov7670_get_caps(const struct device *dev, struct video_caps *caps) { caps->format_caps = fmts; return 0; } -static int ov7670_set_fmt(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt) +static int ov7670_set_fmt(const struct device *dev, struct video_format *fmt) { const struct ov7670_config *config = dev->config; struct ov7670_data *data = dev->data; @@ -446,8 +444,7 @@ static int ov7670_set_fmt(const struct device *dev, enum video_endpoint_id ep, return -ENOTSUP; } -static int ov7670_get_fmt(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt) +static int ov7670_get_fmt(const struct device *dev, struct video_format *fmt) { struct ov7670_data *data = dev->data; @@ -558,7 +555,7 @@ static int ov7670_init(const struct device *dev) fmt.width = 640; fmt.height = 480; fmt.pitch = fmt.width * 2; - ret = ov7670_set_fmt(dev, VIDEO_EP_OUT, &fmt); + ret = ov7670_set_fmt(dev, &fmt); if (ret < 0) { return ret; } @@ -576,7 +573,7 @@ static int ov7670_init(const struct device *dev) return ov7670_init_controls(dev); } -static int ov7670_set_stream(const struct device *dev, bool enable) +static int ov7670_set_stream(const struct device *dev, bool enable, enum video_buf_type type) { return 0; } diff --git a/drivers/video/ov7725.c b/drivers/video/ov7725.c index 9297d4a401d5..1f9834c79100 100644 --- a/drivers/video/ov7725.c +++ b/drivers/video/ov7725.c @@ -417,9 +417,7 @@ static int ov7725_set_clock(const struct device *dev, return -1; } -static int ov7725_set_fmt(const struct device *dev, - enum video_endpoint_id ep, - struct video_format *fmt) +static int ov7725_set_fmt(const struct device *dev, struct video_format *fmt) { struct ov7725_data *drv_data = dev->data; const struct ov7725_config *cfg = dev->config; @@ -508,9 +506,7 @@ static int ov7725_set_fmt(const struct device *dev, ((width & 3U) << 0U)); } -static int ov7725_get_fmt(const struct device *dev, - enum video_endpoint_id ep, - struct video_format *fmt) +static int ov7725_get_fmt(const struct device *dev, struct video_format *fmt) { struct ov7725_data *drv_data = dev->data; @@ -519,7 +515,7 @@ static int ov7725_get_fmt(const struct device *dev, return 0; } -static int ov7725_set_stream(const struct device *dev, bool enable) +static int ov7725_set_stream(const struct device *dev, bool enable, enum video_buf_type type) { return 0; } @@ -537,9 +533,7 @@ static const struct video_format_cap fmts[] = { { 0 } }; -static int ov7725_get_caps(const struct device *dev, - enum video_endpoint_id ep, - struct video_caps *caps) +static int ov7725_get_caps(const struct device *dev, struct video_caps *caps) { caps->format_caps = fmts; return 0; @@ -599,7 +593,7 @@ static int ov7725_init(const struct device *dev) fmt.width = 640; fmt.height = 480; fmt.pitch = 640 * 2; - ret = ov7725_set_fmt(dev, VIDEO_EP_OUT, &fmt); + ret = ov7725_set_fmt(dev, &fmt); if (ret) { LOG_ERR("Unable to configure default format"); return -EIO; diff --git a/drivers/video/video_common.c b/drivers/video/video_common.c index 64d838a4febd..7ae75932ccdf 100644 --- a/drivers/video/video_common.c +++ b/drivers/video/video_common.c @@ -125,8 +125,7 @@ void video_closest_frmival_stepwise(const struct video_frmival_stepwise *stepwis stepwise->step.denominator * desired->denominator; } -void video_closest_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival_enum *match) +void video_closest_frmival(const struct device *dev, struct video_frmival_enum *match) { struct video_frmival desired = match->discrete; struct video_frmival_enum fie = {.format = match->format}; @@ -136,7 +135,7 @@ void video_closest_frmival(const struct device *dev, enum video_endpoint_id ep, __ASSERT(match->type != VIDEO_FRMIVAL_TYPE_STEPWISE, "cannot find range matching the range, only a value matching the range"); - for (fie.index = 0; video_enum_frmival(dev, ep, &fie) == 0; fie.index++) { + for (fie.index = 0; video_enum_frmival(dev, &fie) == 0; fie.index++) { struct video_frmival tmp = {0}; uint64_t diff_nsec = 0; uint64_t tmp_nsec; diff --git a/drivers/video/video_emul_imager.c b/drivers/video/video_emul_imager.c index f4a74559b1bc..43b4982a89f9 100644 --- a/drivers/video/video_emul_imager.c +++ b/drivers/video/video_emul_imager.c @@ -227,46 +227,31 @@ static int emul_imager_set_mode(const struct device *dev, const struct emul_imag return ret; } -static int emul_imager_set_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival *frmival) +static int emul_imager_set_frmival(const struct device *dev, struct video_frmival *frmival) { struct emul_imager_data *data = dev->data; struct video_frmival_enum fie = {.format = &data->fmt, .discrete = *frmival}; - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - - video_closest_frmival(dev, ep, &fie); + video_closest_frmival(dev, &fie); LOG_DBG("Applying frame interval number %u", fie.index); return emul_imager_set_mode(dev, &emul_imager_modes[data->fmt_id][fie.index]); } -static int emul_imager_get_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival *frmival) +static int emul_imager_get_frmival(const struct device *dev, struct video_frmival *frmival) { struct emul_imager_data *data = dev->data; - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - frmival->numerator = 1; frmival->denominator = data->mode->fps; return 0; } -static int emul_imager_enum_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival_enum *fie) +static int emul_imager_enum_frmival(const struct device *dev, struct video_frmival_enum *fie) { const struct emul_imager_mode *mode; size_t fmt_id; int ret; - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - ret = video_format_caps_index(fmts, fie->format, &fmt_id); if (ret < 0) { return ret; @@ -281,17 +266,12 @@ static int emul_imager_enum_frmival(const struct device *dev, enum video_endpoin return mode->fps == 0; } -static int emul_imager_set_fmt(const struct device *const dev, enum video_endpoint_id ep, - struct video_format *fmt) +static int emul_imager_set_fmt(const struct device *const dev, struct video_format *fmt) { struct emul_imager_data *data = dev->data; size_t fmt_id; int ret; - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - if (memcmp(&data->fmt, fmt, sizeof(data->fmt)) == 0) { return 0; } @@ -323,31 +303,21 @@ static int emul_imager_set_fmt(const struct device *const dev, enum video_endpoi return 0; } -static int emul_imager_get_fmt(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt) +static int emul_imager_get_fmt(const struct device *dev, struct video_format *fmt) { struct emul_imager_data *data = dev->data; - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - *fmt = data->fmt; return 0; } -static int emul_imager_get_caps(const struct device *dev, enum video_endpoint_id ep, - struct video_caps *caps) +static int emul_imager_get_caps(const struct device *dev, struct video_caps *caps) { - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - caps->format_caps = fmts; return 0; } -static int emul_imager_set_stream(const struct device *dev, bool enable) +static int emul_imager_set_stream(const struct device *dev, bool enable, enum video_buf_type type) { return emul_imager_write_reg(dev, EMUL_IMAGER_REG_CTRL, enable ? 1 : 0); } @@ -400,7 +370,7 @@ int emul_imager_init(const struct device *dev) fmt.height = fmts[0].height_min; fmt.pitch = fmt.width * 2; - ret = emul_imager_set_fmt(dev, VIDEO_EP_OUT, &fmt); + ret = emul_imager_set_fmt(dev, &fmt); if (ret < 0) { LOG_ERR("Failed to set to default format %x %ux%u", fmt.pixelformat, fmt.width, fmt.height); diff --git a/drivers/video/video_emul_rx.c b/drivers/video/video_emul_rx.c index 7b7d1f580a72..2a67559cb44a 100644 --- a/drivers/video/video_emul_rx.c +++ b/drivers/video/video_emul_rx.c @@ -31,56 +31,35 @@ struct emul_rx_data { struct k_fifo fifo_out; }; -static int emul_rx_set_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival *frmival) +static int emul_rx_set_frmival(const struct device *dev, struct video_frmival *frmival) { const struct emul_rx_config *cfg = dev->config; - /* Input/output timing is driven by the source */ - if (ep != VIDEO_EP_IN && ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - return video_set_frmival(cfg->source_dev, VIDEO_EP_OUT, frmival); + return video_set_frmival(cfg->source_dev, frmival); } -static int emul_rx_get_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival *frmival) +static int emul_rx_get_frmival(const struct device *dev, struct video_frmival *frmival) { const struct emul_rx_config *cfg = dev->config; - /* Input/output timing is driven by the source */ - if (ep != VIDEO_EP_IN && ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - return video_get_frmival(cfg->source_dev, VIDEO_EP_OUT, frmival); + return video_get_frmival(cfg->source_dev, frmival); } -static int emul_rx_enum_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival_enum *fie) +static int emul_rx_enum_frmival(const struct device *dev, struct video_frmival_enum *fie) { const struct emul_rx_config *cfg = dev->config; - /* Input/output timing is driven by the source */ - if (ep != VIDEO_EP_IN && ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - return video_enum_frmival(cfg->source_dev, VIDEO_EP_OUT, fie); + return video_enum_frmival(cfg->source_dev, fie); } -static int emul_rx_set_fmt(const struct device *const dev, enum video_endpoint_id ep, - struct video_format *fmt) +static int emul_rx_set_fmt(const struct device *const dev, struct video_format *fmt) { const struct emul_rx_config *cfg = dev->config; struct emul_rx_data *data = dev->data; int ret; - /* The same format is shared between input and output: data is just passed through */ - if (ep != VIDEO_EP_IN && ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - /* Propagate the format selection to the source */ - ret = video_set_format(cfg->source_dev, VIDEO_EP_OUT, fmt); + ret = video_set_format(cfg->source_dev, fmt); if (ret < 0) { LOG_DBG("Failed to set %s format to %x %ux%u", cfg->source_dev->name, fmt->pixelformat, fmt->width, fmt->height); @@ -92,37 +71,28 @@ static int emul_rx_set_fmt(const struct device *const dev, enum video_endpoint_i return 0; } -static int emul_rx_get_fmt(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt) +static int emul_rx_get_fmt(const struct device *dev, struct video_format *fmt) { struct emul_rx_data *data = dev->data; - /* Input/output caps are the same as the source: data is just passed through */ - if (ep != VIDEO_EP_IN && ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } *fmt = data->fmt; return 0; } -static int emul_rx_get_caps(const struct device *dev, enum video_endpoint_id ep, - struct video_caps *caps) +static int emul_rx_get_caps(const struct device *dev, struct video_caps *caps) { const struct emul_rx_config *cfg = dev->config; - /* Input/output caps are the same as the source: data is just passed through */ - if (ep != VIDEO_EP_IN && ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - return video_get_caps(cfg->source_dev, VIDEO_EP_OUT, caps); + return video_get_caps(cfg->source_dev, caps); } -static int emul_rx_set_stream(const struct device *dev, bool enable) +static int emul_rx_set_stream(const struct device *dev, bool enable, enum video_buf_type type) { const struct emul_rx_config *cfg = dev->config; /* A real hardware driver would first start / stop its own peripheral */ - return enable ? video_stream_start(cfg->source_dev) : video_stream_stop(cfg->source_dev); + return enable ? video_stream_start(cfg->source_dev, type) + : video_stream_stop(cfg->source_dev, type); } static void emul_rx_worker(struct k_work *work) @@ -155,17 +125,11 @@ static void emul_rx_worker(struct k_work *work) } } -static int emul_rx_enqueue(const struct device *dev, enum video_endpoint_id ep, - struct video_buffer *vbuf) +static int emul_rx_enqueue(const struct device *dev, struct video_buffer *vbuf) { struct emul_rx_data *data = dev->data; struct video_format *fmt = &data->fmt; - /* Can only enqueue a buffer to get data out, data input is from hardware */ - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - if (vbuf->size < fmt->pitch * fmt->height) { LOG_ERR("Buffer too small for a full frame"); return -ENOMEM; @@ -181,16 +145,11 @@ static int emul_rx_enqueue(const struct device *dev, enum video_endpoint_id ep, return 0; } -static int emul_rx_dequeue(const struct device *dev, enum video_endpoint_id ep, - struct video_buffer **vbufp, k_timeout_t timeout) +static int emul_rx_dequeue(const struct device *dev, struct video_buffer **vbufp, + k_timeout_t timeout) { struct emul_rx_data *data = dev->data; - /* Can only dequeue a buffer to get data out, data input is from hardware */ - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - /* All the processing is expected to happen in the worker */ *vbufp = k_fifo_get(&data->fifo_out, timeout); if (*vbufp == NULL) { @@ -200,16 +159,11 @@ static int emul_rx_dequeue(const struct device *dev, enum video_endpoint_id ep, return 0; } -static int emul_rx_flush(const struct device *dev, enum video_endpoint_id ep, bool cancel) +static int emul_rx_flush(const struct device *dev, bool cancel) { struct emul_rx_data *data = dev->data; struct k_work_sync sync; - /* Can only flush the buffer going out, data input is from hardware */ - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - if (cancel) { struct video_buffer *vbuf; @@ -257,7 +211,7 @@ int emul_rx_init(const struct device *dev) return -ENODEV; } - ret = video_get_format(cfg->source_dev, VIDEO_EP_OUT, &data->fmt); + ret = video_get_format(cfg->source_dev, &data->fmt); if (ret < 0) { return ret; } diff --git a/drivers/video/video_esp32_dvp.c b/drivers/video/video_esp32_dvp.c index 07d60d85c965..d0eebe40b13a 100644 --- a/drivers/video/video_esp32_dvp.c +++ b/drivers/video/video_esp32_dvp.c @@ -136,7 +136,7 @@ void video_esp32_dma_rx_done(const struct device *dev, void *user_data, uint32_t video_esp32_reload_dma(data); } -static int video_esp32_set_stream(const struct device *dev, bool enable) +static int video_esp32_set_stream(const struct device *dev, bool enable, enum video_buf_type type) { const struct video_esp32_config *cfg = dev->config; struct video_esp32_data *data = dev->data; @@ -149,7 +149,7 @@ static int video_esp32_set_stream(const struct device *dev, bool enable) if (!enable) { LOG_DBG("Stop streaming"); - if (video_stream_stop(cfg->source_dev)) { + if (video_stream_stop(cfg->source_dev, type)) { return -EIO; } @@ -233,7 +233,7 @@ static int video_esp32_set_stream(const struct device *dev, bool enable) cam_hal_start_streaming(&data->hal); - if (video_stream_start(cfg->source_dev)) { + if (video_stream_start(cfg->source_dev, type)) { return -EIO; } data->is_streaming = true; @@ -241,15 +241,10 @@ static int video_esp32_set_stream(const struct device *dev, bool enable) return 0; } -static int video_esp32_get_caps(const struct device *dev, enum video_endpoint_id ep, - struct video_caps *caps) +static int video_esp32_get_caps(const struct device *dev, struct video_caps *caps) { const struct video_esp32_config *config = dev->config; - if (ep != VIDEO_EP_OUT) { - return -EINVAL; - } - /* ESP32 produces full frames */ caps->min_line_count = caps->max_line_count = LINE_COUNT_HEIGHT; @@ -257,19 +252,18 @@ static int video_esp32_get_caps(const struct device *dev, enum video_endpoint_id return video_get_caps(config->source_dev, ep, caps); } -static int video_esp32_get_fmt(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt) +static int video_esp32_get_fmt(const struct device *dev, struct video_format *fmt) { const struct video_esp32_config *cfg = dev->config; int ret = 0; LOG_DBG("Get format"); - if (fmt == NULL || ep != VIDEO_EP_OUT) { + if (fmt == NULL) { return -EINVAL; } - ret = video_get_format(cfg->source_dev, ep, fmt); + ret = video_get_format(cfg->source_dev, fmt); if (ret) { LOG_ERR("Failed to get format from source"); return ret; @@ -278,30 +272,24 @@ static int video_esp32_get_fmt(const struct device *dev, enum video_endpoint_id return 0; } -static int video_esp32_set_fmt(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt) +static int video_esp32_set_fmt(const struct device *dev, struct video_format *fmt) { const struct video_esp32_config *cfg = dev->config; struct video_esp32_data *data = dev->data; - if (fmt == NULL || ep != VIDEO_EP_OUT) { + if (fmt == NULL) { return -EINVAL; } data->video_format = *fmt; - return video_set_format(cfg->source_dev, ep, fmt); + return video_set_format(cfg->source_dev, fmt); } -static int video_esp32_enqueue(const struct device *dev, enum video_endpoint_id ep, - struct video_buffer *vbuf) +static int video_esp32_enqueue(const struct device *dev, struct video_buffer *vbuf) { struct video_esp32_data *data = dev->data; - if (ep != VIDEO_EP_OUT) { - return -EINVAL; - } - vbuf->bytesused = data->video_format.pitch * data->video_format.height; vbuf->line_offset = 0; @@ -310,15 +298,11 @@ static int video_esp32_enqueue(const struct device *dev, enum video_endpoint_id return 0; } -static int video_esp32_dequeue(const struct device *dev, enum video_endpoint_id ep, - struct video_buffer **vbuf, k_timeout_t timeout) +static int video_esp32_dequeue(const struct device *dev, struct video_buffer **vbuf, + k_timeout_t timeout) { struct video_esp32_data *data = dev->data; - if (ep != VIDEO_EP_OUT) { - return -EINVAL; - } - *vbuf = k_fifo_get(&data->fifo_out, timeout); LOG_DBG("Dequeue done, vbuf = %p", *vbuf); if (*vbuf == NULL) { @@ -328,15 +312,12 @@ static int video_esp32_dequeue(const struct device *dev, enum video_endpoint_id return 0; } -static int video_esp32_flush(const struct device *dev, enum video_endpoint_id ep, bool cancel) +static int video_esp32_flush(const struct device *dev, bool cancel) { struct video_esp32_data *data = dev->data; struct video_buffer *vbuf = NULL; if (cancel) { - if (data->is_streaming) { - video_esp32_set_stream(dev, false); - } if (data->active_vbuf) { k_fifo_put(&data->fifo_out, data->active_vbuf); data->active_vbuf = NULL; @@ -359,15 +340,10 @@ static int video_esp32_flush(const struct device *dev, enum video_endpoint_id ep } #ifdef CONFIG_POLL -int video_esp32_set_signal(const struct device *dev, enum video_endpoint_id ep, - struct k_poll_signal *sig) +int video_esp32_set_signal(const struct device *dev, struct k_poll_signal *sig) { struct video_esp32_data *data = dev->data; - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - LOG_ERR("Invalid endpoint id"); - return -EINVAL; - } data->signal_out = sig; return 0; } diff --git a/drivers/video/video_mcux_csi.c b/drivers/video/video_mcux_csi.c index 4c9675ee2beb..866f58844de5 100644 --- a/drivers/video/video_mcux_csi.c +++ b/drivers/video/video_mcux_csi.c @@ -32,7 +32,7 @@ struct video_mcux_csi_data { csi_handle_t csi_handle; struct k_fifo fifo_in; struct k_fifo fifo_out; - struct k_poll_signal *signal; + struct k_poll_signal *sig; }; static void __frame_done_cb(CSI_Type *base, csi_handle_t *handle, status_t status, void *user_data) @@ -92,8 +92,8 @@ static void __frame_done_cb(CSI_Type *base, csi_handle_t *handle, status_t statu done: /* Trigger Event */ - if (IS_ENABLED(CONFIG_POLL) && data->signal) { - k_poll_signal_raise(data->signal, result); + if (IS_ENABLED(CONFIG_POLL) && data->sig) { + k_poll_signal_raise(data->sig, result); } return; @@ -129,8 +129,7 @@ static inline void video_pix_fmt_convert(struct video_format *fmt, bool isGetFmt } #endif -static int video_mcux_csi_set_fmt(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt) +static int video_mcux_csi_set_fmt(const struct device *dev, struct video_format *fmt) { const struct video_mcux_csi_config *config = dev->config; struct video_mcux_csi_data *data = dev->data; @@ -138,7 +137,7 @@ static int video_mcux_csi_set_fmt(const struct device *dev, enum video_endpoint_ status_t ret; struct video_format format = *fmt; - if (bpp == 0 || (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL)) { + if (bpp == 0) { return -EINVAL; } @@ -169,34 +168,34 @@ static int video_mcux_csi_set_fmt(const struct device *dev, enum video_endpoint_ return -EIO; } - if (config->source_dev && video_set_format(config->source_dev, ep, &format)) { + if (config->source_dev && video_set_format(config->source_dev, &format)) { return -EIO; } return 0; } -static int video_mcux_csi_get_fmt(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt) +static int video_mcux_csi_get_fmt(const struct device *dev, struct video_format *fmt) { const struct video_mcux_csi_config *config = dev->config; - if (fmt == NULL || (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL)) { + if (fmt == NULL) { return -EINVAL; } - if (config->source_dev && !video_get_format(config->source_dev, ep, fmt)) { + if (config->source_dev && !video_get_format(config->source_dev, fmt)) { #if defined(CONFIG_VIDEO_MCUX_MIPI_CSI2RX) video_pix_fmt_convert(fmt, true); #endif /* align CSI with source fmt */ - return video_mcux_csi_set_fmt(dev, ep, fmt); + return video_mcux_csi_set_fmt(dev, fmt); } return -EIO; } -static int video_mcux_csi_set_stream(const struct device *dev, bool enable) +static int video_mcux_csi_set_stream(const struct device *dev, bool enable, + enum video_buf_type type) { const struct video_mcux_csi_config *config = dev->config; struct video_mcux_csi_data *data = dev->data; @@ -208,11 +207,11 @@ static int video_mcux_csi_set_stream(const struct device *dev, bool enable) return -EIO; } - if (config->source_dev && video_stream_start(config->source_dev)) { + if (config->source_dev && video_stream_start(config->source_dev, type)) { return -EIO; } } else { - if (config->source_dev && video_stream_stop(config->source_dev)) { + if (config->source_dev && video_stream_stop(config->source_dev, type)) { return -EIO; } @@ -225,7 +224,7 @@ static int video_mcux_csi_set_stream(const struct device *dev, bool enable) return 0; } -static int video_mcux_csi_flush(const struct device *dev, enum video_endpoint_id ep, bool cancel) +static int video_mcux_csi_flush(const struct device *dev, bool cancel) { const struct video_mcux_csi_config *config = dev->config; struct video_mcux_csi_data *data = dev->data; @@ -247,8 +246,8 @@ static int video_mcux_csi_flush(const struct device *dev, enum video_endpoint_id while ((vbuf = k_fifo_get(&data->fifo_in, K_NO_WAIT))) { k_fifo_put(&data->fifo_out, vbuf); - if (IS_ENABLED(CONFIG_POLL) && data->signal) { - k_poll_signal_raise(data->signal, VIDEO_BUF_ABORTED); + if (IS_ENABLED(CONFIG_POLL) && data->sig) { + k_poll_signal_raise(data->sig, VIDEO_BUF_ABORTED); } } } @@ -256,18 +255,13 @@ static int video_mcux_csi_flush(const struct device *dev, enum video_endpoint_id return 0; } -static int video_mcux_csi_enqueue(const struct device *dev, enum video_endpoint_id ep, - struct video_buffer *vbuf) +static int video_mcux_csi_enqueue(const struct device *dev, struct video_buffer *vbuf) { const struct video_mcux_csi_config *config = dev->config; struct video_mcux_csi_data *data = dev->data; unsigned int to_read; status_t ret; - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - to_read = data->csi_config.linePitch_Bytes * data->csi_config.height; vbuf->bytesused = to_read; vbuf->line_offset = 0; @@ -283,15 +277,11 @@ static int video_mcux_csi_enqueue(const struct device *dev, enum video_endpoint_ return 0; } -static int video_mcux_csi_dequeue(const struct device *dev, enum video_endpoint_id ep, - struct video_buffer **vbuf, k_timeout_t timeout) +static int video_mcux_csi_dequeue(const struct device *dev, struct video_buffer **vbuf, + k_timeout_t timeout) { struct video_mcux_csi_data *data = dev->data; - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - *vbuf = k_fifo_get(&data->fifo_out, timeout); if (*vbuf == NULL) { return -EAGAIN; @@ -300,19 +290,14 @@ static int video_mcux_csi_dequeue(const struct device *dev, enum video_endpoint_ return 0; } -static int video_mcux_csi_get_caps(const struct device *dev, enum video_endpoint_id ep, - struct video_caps *caps) +static int video_mcux_csi_get_caps(const struct device *dev, struct video_caps *caps) { const struct video_mcux_csi_config *config = dev->config; int err = -ENODEV; - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - /* Just forward to source dev for now */ if (config->source_dev) { - err = video_get_caps(config->source_dev, ep, caps); + err = video_get_caps(config->source_dev, caps); #if defined(CONFIG_VIDEO_MCUX_MIPI_CSI2RX) /* * On i.MX RT11xx SoCs which have MIPI CSI-2 Rx, image data from the camera sensor @@ -386,39 +371,35 @@ static int video_mcux_csi_init(const struct device *dev) } #ifdef CONFIG_POLL -static int video_mcux_csi_set_signal(const struct device *dev, enum video_endpoint_id ep, - struct k_poll_signal *signal) +static int video_mcux_csi_set_signal(const struct device *dev, struct k_poll_signal *sig) { struct video_mcux_csi_data *data = dev->data; - if (data->signal && signal != NULL) { + if (data->sig && sig != NULL) { return -EALREADY; } - data->signal = signal; + data->sig = sig; return 0; } #endif -static int video_mcux_csi_set_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival *frmival) +static int video_mcux_csi_set_frmival(const struct device *dev, struct video_frmival *frmival) { const struct video_mcux_csi_config *config = dev->config; - return video_set_frmival(config->source_dev, ep, frmival); + return video_set_frmival(config->source_dev, frmival); } -static int video_mcux_csi_get_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival *frmival) +static int video_mcux_csi_get_frmival(const struct device *dev, struct video_frmival *frmival) { const struct video_mcux_csi_config *config = dev->config; - return video_get_frmival(config->source_dev, ep, frmival); + return video_get_frmival(config->source_dev, frmival); } -static int video_mcux_csi_enum_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival_enum *fie) +static int video_mcux_csi_enum_frmival(const struct device *dev, struct video_frmival_enum *fie) { const struct video_mcux_csi_config *config = dev->config; const struct video_format *fie_fmt = fie->format; @@ -431,7 +412,7 @@ static int video_mcux_csi_enum_frmival(const struct device *dev, enum video_endp fie->format = &converted_fmt; #endif - ret = video_enum_frmival(config->source_dev, ep, fie); + ret = video_enum_frmival(config->source_dev, fie); fie->format = fie_fmt; return ret; diff --git a/drivers/video/video_mcux_mipi_csi2rx.c b/drivers/video/video_mcux_mipi_csi2rx.c index fb3cf5efa1e9..2e7bdd32a201 100644 --- a/drivers/video/video_mcux_mipi_csi2rx.c +++ b/drivers/video/video_mcux_mipi_csi2rx.c @@ -48,7 +48,7 @@ const struct mipi_csi2rx_tHsSettleEscClk_config tHsSettleEscClk_configs[] = { {MHZ(96), 0x09}, }; -static int mipi_csi2rx_update_settings(const struct device *dev, enum video_endpoint_id ep) +static int mipi_csi2rx_update_settings(const struct device *dev) { const struct mipi_csi2rx_config *config = dev->config; struct mipi_csi2rx_data *drv_data = dev->data; @@ -58,7 +58,7 @@ static int mipi_csi2rx_update_settings(const struct device *dev, enum video_endp struct video_format fmt; struct video_control sensor_rate = {.id = VIDEO_CID_PIXEL_RATE, .val64 = -1}; - ret = video_get_format(config->sensor_dev, ep, &fmt); + ret = video_get_format(config->sensor_dev, &fmt); if (ret) { LOG_ERR("Cannot get sensor_dev pixel format"); return ret; @@ -115,35 +115,33 @@ static int mipi_csi2rx_update_settings(const struct device *dev, enum video_endp return ret; } -static int mipi_csi2rx_set_fmt(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt) +static int mipi_csi2rx_set_fmt(const struct device *dev, struct video_format *fmt) { const struct mipi_csi2rx_config *config = dev->config; - if (video_set_format(config->sensor_dev, ep, fmt)) { + if (video_set_format(config->sensor_dev, fmt)) { return -EIO; } - return mipi_csi2rx_update_settings(dev, ep); + return mipi_csi2rx_update_settings(dev); } -static int mipi_csi2rx_get_fmt(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt) +static int mipi_csi2rx_get_fmt(const struct device *dev, struct video_format *fmt) { const struct mipi_csi2rx_config *config = dev->config; - if (fmt == NULL || (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL)) { + if (fmt == NULL) { return -EINVAL; } - if (video_get_format(config->sensor_dev, ep, fmt)) { + if (video_get_format(config->sensor_dev, fmt)) { return -EIO; } return 0; } -static int mipi_csi2rx_set_stream(const struct device *dev, bool enable) +static int mipi_csi2rx_set_stream(const struct device *dev, bool enable, enum video_buf_type type) { const struct mipi_csi2rx_config *config = dev->config; @@ -151,11 +149,11 @@ static int mipi_csi2rx_set_stream(const struct device *dev, bool enable) struct mipi_csi2rx_data *drv_data = dev->data; CSI2RX_Init((MIPI_CSI2RX_Type *)config->base, &drv_data->csi2rxConfig); - if (video_stream_start(config->sensor_dev)) { + if (video_stream_start(config->sensor_dev, type)) { return -EIO; } } else { - if (video_stream_stop(config->sensor_dev)) { + if (video_stream_stop(config->sensor_dev, type)) { return -EIO; } CSI2RX_Deinit((MIPI_CSI2RX_Type *)config->base); @@ -164,42 +162,35 @@ static int mipi_csi2rx_set_stream(const struct device *dev, bool enable) return 0; } -static int mipi_csi2rx_get_caps(const struct device *dev, enum video_endpoint_id ep, - struct video_caps *caps) +static int mipi_csi2rx_get_caps(const struct device *dev, struct video_caps *caps) { const struct mipi_csi2rx_config *config = dev->config; - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - /* Just forward to sensor dev for now */ - return video_get_caps(config->sensor_dev, ep, caps); + return video_get_caps(config->sensor_dev, caps); } -static int mipi_csi2rx_set_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival *frmival) +static int mipi_csi2rx_set_frmival(const struct device *dev, struct video_frmival *frmival) { const struct mipi_csi2rx_config *config = dev->config; int ret; - ret = video_set_frmival(config->sensor_dev, ep, frmival); + ret = video_set_frmival(config->sensor_dev, frmival); if (ret) { LOG_ERR("Cannot set sensor_dev frmival"); return ret; } - ret = mipi_csi2rx_update_settings(dev, ep); + ret = mipi_csi2rx_update_settings(dev); return ret; } -static int mipi_csi2rx_get_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival *frmival) +static int mipi_csi2rx_get_frmival(const struct device *dev, struct video_frmival *frmival) { const struct mipi_csi2rx_config *config = dev->config; - return video_get_frmival(config->sensor_dev, ep, frmival); + return video_get_frmival(config->sensor_dev, frmival); } static uint64_t mipi_csi2rx_cal_frame_size(const struct video_format *fmt) @@ -219,8 +210,7 @@ static uint64_t mipi_csi2rx_estimate_pixel_rate(const struct video_frmival *cur_ cur_fmival->denominator); } -static int mipi_csi2rx_enum_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival_enum *fie) +static int mipi_csi2rx_enum_frmival(const struct device *dev, struct video_frmival_enum *fie) { const struct mipi_csi2rx_config *config = dev->config; struct mipi_csi2rx_data *drv_data = dev->data; @@ -230,18 +220,18 @@ static int mipi_csi2rx_enum_frmival(const struct device *dev, enum video_endpoin struct video_format cur_fmt; struct video_control sensor_rate = {.id = VIDEO_CID_PIXEL_RATE, .val64 = -1}; - ret = video_enum_frmival(config->sensor_dev, ep, fie); + ret = video_enum_frmival(config->sensor_dev, fie); if (ret) { return ret; } - ret = video_get_frmival(config->sensor_dev, ep, &cur_frmival); + ret = video_get_frmival(config->sensor_dev, &cur_frmival); if (ret) { LOG_ERR("Cannot get sensor_dev frame rate"); return ret; } - ret = video_get_format(config->sensor_dev, ep, &cur_fmt); + ret = video_get_format(config->sensor_dev, &cur_fmt); if (ret) { LOG_ERR("Cannot get sensor_dev format"); return ret; @@ -317,7 +307,7 @@ static int mipi_csi2rx_init(const struct device *dev) return ret; } - return mipi_csi2rx_update_settings(dev, VIDEO_EP_ALL); + return mipi_csi2rx_update_settings(dev); } #define SOURCE_DEV(n) DEVICE_DT_GET(DT_NODE_REMOTE_DEVICE(DT_INST_ENDPOINT_BY_ID(n, 1, 0))) diff --git a/drivers/video/video_mcux_smartdma.c b/drivers/video/video_mcux_smartdma.c index bf624ecb47a1..5a6e65f6ebfa 100644 --- a/drivers/video/video_mcux_smartdma.c +++ b/drivers/video/video_mcux_smartdma.c @@ -95,7 +95,8 @@ static void nxp_video_sdma_callback(const struct device *dev, void *user_data, data->buf_reload_flag = !data->buf_reload_flag; } -static int nxp_video_sdma_set_stream(const struct device *dev, bool enable) +static int nxp_video_sdma_set_stream(const struct device *dev, bool enable, + enum video_buf_type type) { const struct nxp_video_sdma_config *config = dev->config; struct nxp_video_sdma_data *data = dev->data; @@ -148,16 +149,10 @@ static int nxp_video_sdma_set_stream(const struct device *dev, bool enable) return 0; } -static int nxp_video_sdma_enqueue(const struct device *dev, - enum video_endpoint_id ep, - struct video_buffer *vbuf) +static int nxp_video_sdma_enqueue(const struct device *dev, struct video_buffer *vbuf) { struct nxp_video_sdma_data *data = dev->data; - if (ep != VIDEO_EP_OUT) { - return -EINVAL; - } - /* SmartDMA will read 30 lines of RGB565 video data into framebuffer */ vbuf->bytesused = SDMA_VBUF_WIDTH * SDMA_LINE_COUNT * sizeof(uint16_t); if (vbuf->size < vbuf->bytesused) { @@ -168,22 +163,16 @@ static int nxp_video_sdma_enqueue(const struct device *dev, k_fifo_put(&data->fifo_in, vbuf); if (data->stream_starved) { /* Kick SmartDMA off */ - nxp_video_sdma_set_stream(dev, true); + nxp_video_sdma_set_stream(dev, true, vbuf->type); } return 0; } -static int nxp_video_sdma_dequeue(const struct device *dev, - enum video_endpoint_id ep, - struct video_buffer **vbuf, +static int nxp_video_sdma_dequeue(const struct device *dev, struct video_buffer **vbuf, k_timeout_t timeout) { struct nxp_video_sdma_data *data = dev->data; - if (ep != VIDEO_EP_OUT) { - return -EINVAL; - } - *vbuf = k_fifo_get(&data->fifo_out, timeout); if (*vbuf == NULL) { return -EAGAIN; @@ -192,9 +181,7 @@ static int nxp_video_sdma_dequeue(const struct device *dev, return 0; } -static int nxp_video_sdma_flush(const struct device *dev, - enum video_endpoint_id ep, - bool cancel) +static int nxp_video_sdma_flush(const struct device *dev, bool cancel) { const struct nxp_video_sdma_config *config = dev->config; struct nxp_video_sdma_data *data = dev->data; @@ -228,13 +215,11 @@ static const struct video_format_cap fmts[] = { { 0 }, }; -static int nxp_video_sdma_set_format(const struct device *dev, - enum video_endpoint_id ep, - struct video_format *fmt) +static int nxp_video_sdma_set_format(const struct device *dev, struct video_format *fmt) { const struct nxp_video_sdma_config *config = dev->config; - if (fmt == NULL || ep != VIDEO_EP_OUT) { + if (fmt == NULL) { return -EINVAL; } @@ -252,17 +237,15 @@ static int nxp_video_sdma_set_format(const struct device *dev, } /* Forward format to sensor device */ - return video_set_format(config->sensor_dev, ep, fmt); + return video_set_format(config->sensor_dev, fmt); } -static int nxp_video_sdma_get_format(const struct device *dev, - enum video_endpoint_id ep, - struct video_format *fmt) +static int nxp_video_sdma_get_format(const struct device *dev, struct video_format *fmt) { const struct nxp_video_sdma_config *config = dev->config; int ret; - if (fmt == NULL || ep != VIDEO_EP_OUT) { + if (fmt == NULL) { return -EINVAL; } @@ -276,7 +259,7 @@ static int nxp_video_sdma_get_format(const struct device *dev, * reconfigure the sensor, * as this is the only format supported. */ - ret = video_get_format(config->sensor_dev, VIDEO_EP_OUT, fmt); + ret = video_get_format(config->sensor_dev, fmt); if (ret < 0) { return ret; } @@ -291,7 +274,7 @@ static int nxp_video_sdma_get_format(const struct device *dev, fmt->width = fmts[0].width_min; fmt->height = fmts[0].height_min; fmt->pitch = fmts[0].width_min * 2; - ret = video_set_format(config->sensor_dev, VIDEO_EP_OUT, fmt); + ret = video_set_format(config->sensor_dev, fmt); if (ret < 0) { LOG_ERR("Sensor device does not support RGB565"); return ret; @@ -301,14 +284,8 @@ static int nxp_video_sdma_get_format(const struct device *dev, return 0; } -static int nxp_video_sdma_get_caps(const struct device *dev, - enum video_endpoint_id ep, - struct video_caps *caps) +static int nxp_video_sdma_get_caps(const struct device *dev, struct video_caps *caps) { - if (ep != VIDEO_EP_OUT) { - return -EINVAL; - } - /* SmartDMA needs at least two buffers allocated before starting */ caps->min_vbuf_count = 2; /* Firmware reads 30 lines per queued vbuf */ diff --git a/drivers/video/video_stm32_dcmi.c b/drivers/video/video_stm32_dcmi.c index 70de70e6d4be..f27a06da16b4 100644 --- a/drivers/video/video_stm32_dcmi.c +++ b/drivers/video/video_stm32_dcmi.c @@ -197,24 +197,18 @@ static inline int video_stm32_dcmi_is_fmt_valid(uint32_t pixelformat, uint32_t p return 0; } -static int video_stm32_dcmi_set_fmt(const struct device *dev, - enum video_endpoint_id ep, - struct video_format *fmt) +static int video_stm32_dcmi_set_fmt(const struct device *dev, struct video_format *fmt) { const struct video_stm32_dcmi_config *config = dev->config; struct video_stm32_dcmi_data *data = dev->data; int ret; - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - ret = video_stm32_dcmi_is_fmt_valid(fmt->pixelformat, fmt->pitch, fmt->height); if (ret < 0) { return ret; } - ret = video_set_format(config->sensor_dev, ep, fmt); + ret = video_set_format(config->sensor_dev, fmt); if (ret < 0) { return ret; } @@ -224,20 +218,18 @@ static int video_stm32_dcmi_set_fmt(const struct device *dev, return 0; } -static int video_stm32_dcmi_get_fmt(const struct device *dev, - enum video_endpoint_id ep, - struct video_format *fmt) +static int video_stm32_dcmi_get_fmt(const struct device *dev, struct video_format *fmt) { struct video_stm32_dcmi_data *data = dev->data; const struct video_stm32_dcmi_config *config = dev->config; int ret; - if (fmt == NULL || (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL)) { + if (fmt == NULL) { return -EINVAL; } /* Align DCMI format with the one provided by the sensor */ - ret = video_get_format(config->sensor_dev, ep, fmt); + ret = video_get_format(config->sensor_dev, fmt); if (ret < 0) { return ret; } @@ -258,14 +250,15 @@ static int video_stm32_dcmi_get_fmt(const struct device *dev, (capture_rate) == 4 ? DCMI_CR_ALTERNATE_4_FRAME : \ DCMI_CR_ALL_FRAME) -static int video_stm32_dcmi_set_stream(const struct device *dev, bool enable) +static int video_stm32_dcmi_set_stream(const struct device *dev, bool enable, + enum video_buf_type type) { struct video_stm32_dcmi_data *data = dev->data; const struct video_stm32_dcmi_config *config = dev->config; int err; if (!enable) { - err = video_stream_stop(config->sensor_dev); + err = video_stream_stop(config->sensor_dev, type); if (err < 0) { return err; } @@ -300,20 +293,14 @@ static int video_stm32_dcmi_set_stream(const struct device *dev, bool enable) return -EIO; } - return video_stream_start(config->sensor_dev); + return video_stream_start(config->sensor_dev, type); } -static int video_stm32_dcmi_enqueue(const struct device *dev, - enum video_endpoint_id ep, - struct video_buffer *vbuf) +static int video_stm32_dcmi_enqueue(const struct device *dev, struct video_buffer *vbuf) { struct video_stm32_dcmi_data *data = dev->data; const uint32_t buffer_size = data->fmt.pitch * data->fmt.height; - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - if (buffer_size > vbuf->size) { return -EINVAL; } @@ -326,17 +313,11 @@ static int video_stm32_dcmi_enqueue(const struct device *dev, return 0; } -static int video_stm32_dcmi_dequeue(const struct device *dev, - enum video_endpoint_id ep, - struct video_buffer **vbuf, - k_timeout_t timeout) +static int video_stm32_dcmi_dequeue(const struct device *dev, struct video_buffer **vbuf, + k_timeout_t timeout) { struct video_stm32_dcmi_data *data = dev->data; - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - *vbuf = k_fifo_get(&data->fifo_out, timeout); if (*vbuf == NULL) { return -EAGAIN; @@ -345,40 +326,29 @@ static int video_stm32_dcmi_dequeue(const struct device *dev, return 0; } -static int video_stm32_dcmi_get_caps(const struct device *dev, - enum video_endpoint_id ep, - struct video_caps *caps) +static int video_stm32_dcmi_get_caps(const struct device *dev, struct video_caps *caps) { const struct video_stm32_dcmi_config *config = dev->config; - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - /* DCMI produces full frames */ caps->min_line_count = caps->max_line_count = LINE_COUNT_HEIGHT; /* Forward the message to the sensor device */ - return video_get_caps(config->sensor_dev, ep, caps); + return video_get_caps(config->sensor_dev, caps); } -static int video_stm32_dcmi_enum_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival_enum *fie) +static int video_stm32_dcmi_enum_frmival(const struct device *dev, struct video_frmival_enum *fie) { const struct video_stm32_dcmi_config *config = dev->config; int ret; - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - ret = video_stm32_dcmi_is_fmt_valid(fie->format->pixelformat, fie->format->pitch, fie->format->height); if (ret < 0) { return ret; } - ret = video_enum_frmival(config->sensor_dev, ep, fie); + ret = video_enum_frmival(config->sensor_dev, fie); if (ret < 0) { return ret; } @@ -402,8 +372,7 @@ static int video_stm32_dcmi_enum_frmival(const struct device *dev, enum video_en } #define STM32_DCMI_MAX_FRAME_DROP 4 -static int video_stm32_dcmi_set_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival *frmival) +static int video_stm32_dcmi_set_frmival(const struct device *dev, struct video_frmival *frmival) { const struct video_stm32_dcmi_config *config = dev->config; struct video_stm32_dcmi_data *data = dev->data; @@ -415,10 +384,6 @@ static int video_stm32_dcmi_set_frmival(const struct device *dev, enum video_end uint64_t diff_nsec = 0, a, b; int best_capture_rate = 1; - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - /* * Try to figure out a frameinterval setting allow to reach as close as * possible to the request. At first without relying on DCMI frame control, @@ -433,7 +398,7 @@ static int video_stm32_dcmi_set_frmival(const struct device *dev, enum video_end fie.discrete.denominator = frmival->denominator * capture_rate; a = video_frmival_nsec(&fie.discrete); - video_closest_frmival(config->sensor_dev, ep, &fie); + video_closest_frmival(config->sensor_dev, &fie); b = video_frmival_nsec(&fie.discrete); diff_nsec = a > b ? a - b : b - a; if (diff_nsec < best_diff_nsec) { @@ -455,17 +420,16 @@ static int video_stm32_dcmi_set_frmival(const struct device *dev, enum video_end data->capture_rate = best_capture_rate; - return video_set_frmival(config->sensor_dev, ep, &best_sensor_frmival); + return video_set_frmival(config->sensor_dev, &best_sensor_frmival); } -static int video_stm32_dcmi_get_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival *frmival) +static int video_stm32_dcmi_get_frmival(const struct device *dev, struct video_frmival *frmival) { const struct video_stm32_dcmi_config *config = dev->config; struct video_stm32_dcmi_data *data = dev->data; int ret; - ret = video_get_frmival(config->sensor_dev, ep, frmival); + ret = video_get_frmival(config->sensor_dev, frmival); if (ret < 0) { return ret; } diff --git a/drivers/video/video_sw_generator.c b/drivers/video/video_sw_generator.c index ed8ade5270ca..40ba10011bea 100644 --- a/drivers/video/video_sw_generator.c +++ b/drivers/video/video_sw_generator.c @@ -40,7 +40,7 @@ struct video_sw_generator_data { struct k_work_delayable buf_work; struct k_work_sync work_sync; int pattern; - struct k_poll_signal *signal; + struct k_poll_signal *sig; uint32_t frame_rate; }; @@ -63,16 +63,11 @@ static const struct video_format_cap fmts[] = {{ }, {0}}; -static int video_sw_generator_set_fmt(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt) +static int video_sw_generator_set_fmt(const struct device *dev, struct video_format *fmt) { struct video_sw_generator_data *data = dev->data; int i = 0; - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - for (i = 0; i < ARRAY_SIZE(fmts); ++i) { if (fmt->pixelformat == fmts[i].pixelformat && fmt->width >= fmts[i].width_min && fmt->width <= fmts[i].width_max && fmt->height >= fmts[i].height_min && @@ -91,21 +86,17 @@ static int video_sw_generator_set_fmt(const struct device *dev, enum video_endpo return 0; } -static int video_sw_generator_get_fmt(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt) +static int video_sw_generator_get_fmt(const struct device *dev, struct video_format *fmt) { struct video_sw_generator_data *data = dev->data; - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - *fmt = data->fmt; return 0; } -static int video_sw_generator_set_stream(const struct device *dev, bool enable) +static int video_sw_generator_set_stream(const struct device *dev, bool enable, + enum video_buf_type type) { struct video_sw_generator_data *data = dev->data; @@ -172,36 +163,27 @@ static void __buffer_work(struct k_work *work) k_fifo_put(&data->fifo_out, vbuf); - if (IS_ENABLED(CONFIG_POLL) && data->signal) { - k_poll_signal_raise(data->signal, VIDEO_BUF_DONE); + if (IS_ENABLED(CONFIG_POLL) && data->sig) { + k_poll_signal_raise(data->sig, VIDEO_BUF_DONE); } k_yield(); } -static int video_sw_generator_enqueue(const struct device *dev, enum video_endpoint_id ep, - struct video_buffer *vbuf) +static int video_sw_generator_enqueue(const struct device *dev, struct video_buffer *vbuf) { struct video_sw_generator_data *data = dev->data; - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - k_fifo_put(&data->fifo_in, vbuf); return 0; } -static int video_sw_generator_dequeue(const struct device *dev, enum video_endpoint_id ep, - struct video_buffer **vbuf, k_timeout_t timeout) +static int video_sw_generator_dequeue(const struct device *dev, struct video_buffer **vbuf, + k_timeout_t timeout) { struct video_sw_generator_data *data = dev->data; - if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) { - return -EINVAL; - } - *vbuf = k_fifo_get(&data->fifo_out, timeout); if (*vbuf == NULL) { return -EAGAIN; @@ -210,8 +192,7 @@ static int video_sw_generator_dequeue(const struct device *dev, enum video_endpo return 0; } -static int video_sw_generator_flush(const struct device *dev, enum video_endpoint_id ep, - bool cancel) +static int video_sw_generator_flush(const struct device *dev, bool cancel) { struct video_sw_generator_data *data = dev->data; struct video_buffer *vbuf; @@ -224,8 +205,8 @@ static int video_sw_generator_flush(const struct device *dev, enum video_endpoin } else { while ((vbuf = k_fifo_get(&data->fifo_in, K_NO_WAIT))) { k_fifo_put(&data->fifo_out, vbuf); - if (IS_ENABLED(CONFIG_POLL) && data->signal) { - k_poll_signal_raise(data->signal, VIDEO_BUF_ABORTED); + if (IS_ENABLED(CONFIG_POLL) && data->sig) { + k_poll_signal_raise(data->sig, VIDEO_BUF_ABORTED); } } } @@ -233,8 +214,7 @@ static int video_sw_generator_flush(const struct device *dev, enum video_endpoin return 0; } -static int video_sw_generator_get_caps(const struct device *dev, enum video_endpoint_id ep, - struct video_caps *caps) +static int video_sw_generator_get_caps(const struct device *dev, struct video_caps *caps) { caps->format_caps = fmts; caps->min_vbuf_count = 0; @@ -246,23 +226,21 @@ static int video_sw_generator_get_caps(const struct device *dev, enum video_endp } #ifdef CONFIG_POLL -static int video_sw_generator_set_signal(const struct device *dev, enum video_endpoint_id ep, - struct k_poll_signal *signal) +static int video_sw_generator_set_signal(const struct device *dev, struct k_poll_signal *sig) { struct video_sw_generator_data *data = dev->data; - if (data->signal && signal != NULL) { + if (data->sig && sig != NULL) { return -EALREADY; } - data->signal = signal; + data->sig = sig; return 0; } #endif -static int video_sw_generator_set_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival *frmival) +static int video_sw_generator_set_frmival(const struct device *dev, struct video_frmival *frmival) { struct video_sw_generator_data *data = dev->data; @@ -279,8 +257,7 @@ static int video_sw_generator_set_frmival(const struct device *dev, enum video_e return 0; } -static int video_sw_generator_get_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival *frmival) +static int video_sw_generator_get_frmival(const struct device *dev, struct video_frmival *frmival) { struct video_sw_generator_data *data = dev->data; @@ -290,15 +267,10 @@ static int video_sw_generator_get_frmival(const struct device *dev, enum video_e return 0; } -static int video_sw_generator_enum_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival_enum *fie) +static int video_sw_generator_enum_frmival(const struct device *dev, struct video_frmival_enum *fie) { int i = 0; - if (ep != VIDEO_EP_OUT || fie->index) { - return -EINVAL; - } - while (fmts[i].pixelformat && (fmts[i].pixelformat != fie->format->pixelformat)) { i++; } diff --git a/include/zephyr/drivers/video.h b/include/zephyr/drivers/video.h index 39414e1d0d2f..b5a706752589 100644 --- a/include/zephyr/drivers/video.h +++ b/include/zephyr/drivers/video.h @@ -40,6 +40,21 @@ extern "C" { struct video_control; +/** + * @brief video_buf_type enum + * + * Supported video buffer types of a video device. + * The direction (input or output) is defined from the device's point of view. + * Devices like cameras support only output type, encoders support only input + * types while m2m devices like ISP, PxP support both input and output types. + */ +enum video_buf_type { + /** input buffer type */ + VIDEO_BUF_TYPE_INPUT, + /** output buffer type */ + VIDEO_BUF_TYPE_OUTPUT, +}; + /** * @struct video_format * @brief Video format structure @@ -47,6 +62,8 @@ struct video_control; * Used to configure frame format. */ struct video_format { + /** type of the buffer */ + enum video_buf_type type; /** FourCC pixel format value (\ref video_pixel_formats) */ uint32_t pixelformat; /** frame width in pixels. */ @@ -93,6 +110,8 @@ struct video_format_cap { * Used to describe video endpoint capabilities. */ struct video_caps { + /** type of the buffer */ + enum video_buf_type type; /** list of video format capabilities (zero terminated). */ const struct video_format_cap *format_caps; /** minimal count of video buffers to enqueue before being able to start @@ -124,6 +143,8 @@ struct video_caps { * Represent a video frame. */ struct video_buffer { + /** type of the buffer */ + enum video_buf_type type; /** pointer to driver specific data. */ void *driver_data; /** pointer to the start of the buffer. */ @@ -205,22 +226,6 @@ struct video_frmival_enum { }; }; -/** - * @brief video_endpoint_id enum - * - * Identify the video device endpoint. - */ -enum video_endpoint_id { - /** Targets some part of the video device not bound to an endpoint */ - VIDEO_EP_NONE = -1, - /** Targets all input or output endpoints of the device */ - VIDEO_EP_ALL = -2, - /** Targets all input endpoints of the device: those consuming data */ - VIDEO_EP_IN = -3, - /** Targets all output endpoints of the device: those producing data */ - VIDEO_EP_OUT = -4, -}; - /** * @brief video_event enum * @@ -238,8 +243,7 @@ enum video_signal_result { * * See video_set_format() for argument descriptions. */ -typedef int (*video_api_set_format_t)(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt); +typedef int (*video_api_set_format_t)(const struct device *dev, struct video_format *fmt); /** * @typedef video_api_get_format_t @@ -247,8 +251,7 @@ typedef int (*video_api_set_format_t)(const struct device *dev, enum video_endpo * * See video_get_format() for argument descriptions. */ -typedef int (*video_api_get_format_t)(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt); +typedef int (*video_api_get_format_t)(const struct device *dev, struct video_format *fmt); /** * @typedef video_api_set_frmival_t @@ -256,8 +259,7 @@ typedef int (*video_api_get_format_t)(const struct device *dev, enum video_endpo * * See video_set_frmival() for argument descriptions. */ -typedef int (*video_api_set_frmival_t)(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival *frmival); +typedef int (*video_api_set_frmival_t)(const struct device *dev, struct video_frmival *frmival); /** * @typedef video_api_get_frmival_t @@ -265,8 +267,7 @@ typedef int (*video_api_set_frmival_t)(const struct device *dev, enum video_endp * * See video_get_frmival() for argument descriptions. */ -typedef int (*video_api_get_frmival_t)(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival *frmival); +typedef int (*video_api_get_frmival_t)(const struct device *dev, struct video_frmival *frmival); /** * @typedef video_api_enum_frmival_t @@ -274,8 +275,7 @@ typedef int (*video_api_get_frmival_t)(const struct device *dev, enum video_endp * * See video_enum_frmival() for argument descriptions. */ -typedef int (*video_api_enum_frmival_t)(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival_enum *fie); +typedef int (*video_api_enum_frmival_t)(const struct device *dev, struct video_frmival_enum *fie); /** * @typedef video_api_enqueue_t @@ -283,8 +283,7 @@ typedef int (*video_api_enum_frmival_t)(const struct device *dev, enum video_end * * See video_enqueue() for argument descriptions. */ -typedef int (*video_api_enqueue_t)(const struct device *dev, enum video_endpoint_id ep, - struct video_buffer *buf); +typedef int (*video_api_enqueue_t)(const struct device *dev, struct video_buffer *buf); /** * @typedef video_api_dequeue_t @@ -292,8 +291,8 @@ typedef int (*video_api_enqueue_t)(const struct device *dev, enum video_endpoint * * See video_dequeue() for argument descriptions. */ -typedef int (*video_api_dequeue_t)(const struct device *dev, enum video_endpoint_id ep, - struct video_buffer **buf, k_timeout_t timeout); +typedef int (*video_api_dequeue_t)(const struct device *dev, struct video_buffer **buf, + k_timeout_t timeout); /** * @typedef video_api_flush_t @@ -302,7 +301,7 @@ typedef int (*video_api_dequeue_t)(const struct device *dev, enum video_endpoint * * See video_flush() for argument descriptions. */ -typedef int (*video_api_flush_t)(const struct device *dev, enum video_endpoint_id ep, bool cancel); +typedef int (*video_api_flush_t)(const struct device *dev, bool cancel); /** * @typedef video_api_set_stream_t @@ -312,10 +311,12 @@ typedef int (*video_api_flush_t)(const struct device *dev, enum video_endpoint_i * * @param dev Pointer to the device structure. * @param enable If true, start streaming, otherwise stop streaming. + * @param type The type of the buffers stream to start or stop. * * @retval 0 on success, otherwise a negative errno code. */ -typedef int (*video_api_set_stream_t)(const struct device *dev, bool enable); +typedef int (*video_api_set_stream_t)(const struct device *dev, bool enable, + enum video_buf_type type); /** * @typedef video_api_ctrl_t @@ -332,8 +333,7 @@ typedef int (*video_api_ctrl_t)(const struct device *dev, uint32_t cid); * * See video_get_caps() for argument descriptions. */ -typedef int (*video_api_get_caps_t)(const struct device *dev, enum video_endpoint_id ep, - struct video_caps *caps); +typedef int (*video_api_get_caps_t)(const struct device *dev, struct video_caps *caps); /** * @typedef video_api_set_signal_t @@ -341,8 +341,7 @@ typedef int (*video_api_get_caps_t)(const struct device *dev, enum video_endpoin * * See video_set_signal() for argument descriptions. */ -typedef int (*video_api_set_signal_t)(const struct device *dev, enum video_endpoint_id ep, - struct k_poll_signal *signal); +typedef int (*video_api_set_signal_t)(const struct device *dev, struct k_poll_signal *sig); __subsystem struct video_driver_api { /* mandatory callbacks */ @@ -368,7 +367,6 @@ __subsystem struct video_driver_api { * Configure video device with a specific format. * * @param dev Pointer to the device structure for the driver instance. - * @param ep Endpoint ID. * @param fmt Pointer to a video format struct. * * @retval 0 Is successful. @@ -376,8 +374,7 @@ __subsystem struct video_driver_api { * @retval -ENOTSUP If format is not supported. * @retval -EIO General input / output error. */ -static inline int video_set_format(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt) +static inline int video_set_format(const struct device *dev, struct video_format *fmt) { const struct video_driver_api *api = (const struct video_driver_api *)dev->api; @@ -385,7 +382,7 @@ static inline int video_set_format(const struct device *dev, enum video_endpoint return -ENOSYS; } - return api->set_format(dev, ep, fmt); + return api->set_format(dev, fmt); } /** @@ -394,13 +391,11 @@ static inline int video_set_format(const struct device *dev, enum video_endpoint * Get video device current video format. * * @param dev Pointer to the device structure for the driver instance. - * @param ep Endpoint ID. * @param fmt Pointer to video format struct. * * @retval pointer to video format */ -static inline int video_get_format(const struct device *dev, enum video_endpoint_id ep, - struct video_format *fmt) +static inline int video_get_format(const struct device *dev, struct video_format *fmt) { const struct video_driver_api *api = (const struct video_driver_api *)dev->api; @@ -408,7 +403,7 @@ static inline int video_get_format(const struct device *dev, enum video_endpoint return -ENOSYS; } - return api->get_format(dev, ep, fmt); + return api->get_format(dev, fmt); } /** @@ -420,7 +415,6 @@ static inline int video_get_format(const struct device *dev, enum video_endpoint * capabilities. They must instead modify the interval to match what the hardware can provide. * * @param dev Pointer to the device structure for the driver instance. - * @param ep Endpoint ID. * @param frmival Pointer to a video frame interval struct. * * @retval 0 If successful. @@ -428,8 +422,7 @@ static inline int video_get_format(const struct device *dev, enum video_endpoint * @retval -EINVAL If parameters are invalid. * @retval -EIO General input / output error. */ -static inline int video_set_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival *frmival) +static inline int video_set_frmival(const struct device *dev, struct video_frmival *frmival) { const struct video_driver_api *api = (const struct video_driver_api *)dev->api; @@ -437,7 +430,7 @@ static inline int video_set_frmival(const struct device *dev, enum video_endpoin return -ENOSYS; } - return api->set_frmival(dev, ep, frmival); + return api->set_frmival(dev, frmival); } /** @@ -446,7 +439,6 @@ static inline int video_set_frmival(const struct device *dev, enum video_endpoin * Get current frame interval of the video device. * * @param dev Pointer to the device structure for the driver instance. - * @param ep Endpoint ID. * @param frmival Pointer to a video frame interval struct. * * @retval 0 If successful. @@ -454,8 +446,7 @@ static inline int video_set_frmival(const struct device *dev, enum video_endpoin * @retval -EINVAL If parameters are invalid. * @retval -EIO General input / output error. */ -static inline int video_get_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival *frmival) +static inline int video_get_frmival(const struct device *dev, struct video_frmival *frmival) { const struct video_driver_api *api = (const struct video_driver_api *)dev->api; @@ -463,7 +454,7 @@ static inline int video_get_frmival(const struct device *dev, enum video_endpoin return -ENOSYS; } - return api->get_frmival(dev, ep, frmival); + return api->get_frmival(dev, frmival); } /** @@ -476,7 +467,6 @@ static inline int video_get_frmival(const struct device *dev, enum video_endpoin * used to iterate through the supported frame intervals list. * * @param dev Pointer to the device structure for the driver instance. - * @param ep Endpoint ID. * @param fie Pointer to a video frame interval enumeration struct. * * @retval 0 If successful. @@ -484,8 +474,7 @@ static inline int video_get_frmival(const struct device *dev, enum video_endpoin * @retval -EINVAL If parameters are invalid. * @retval -EIO General input / output error. */ -static inline int video_enum_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival_enum *fie) +static inline int video_enum_frmival(const struct device *dev, struct video_frmival_enum *fie) { const struct video_driver_api *api = (const struct video_driver_api *)dev->api; @@ -493,7 +482,7 @@ static inline int video_enum_frmival(const struct device *dev, enum video_endpoi return -ENOSYS; } - return api->enum_frmival(dev, ep, fie); + return api->enum_frmival(dev, fie); } /** @@ -503,15 +492,13 @@ static inline int video_enum_frmival(const struct device *dev, enum video_endpoi * endpoint incoming queue. * * @param dev Pointer to the device structure for the driver instance. - * @param ep Endpoint ID. * @param buf Pointer to the video buffer. * * @retval 0 Is successful. * @retval -EINVAL If parameters are invalid. * @retval -EIO General input / output error. */ -static inline int video_enqueue(const struct device *dev, enum video_endpoint_id ep, - struct video_buffer *buf) +static inline int video_enqueue(const struct device *dev, struct video_buffer *buf) { const struct video_driver_api *api = (const struct video_driver_api *)dev->api; @@ -519,7 +506,7 @@ static inline int video_enqueue(const struct device *dev, enum video_endpoint_id return -ENOSYS; } - return api->enqueue(dev, ep, buf); + return api->enqueue(dev, buf); } /** @@ -529,7 +516,6 @@ static inline int video_enqueue(const struct device *dev, enum video_endpoint_id * endpoint outgoing queue. * * @param dev Pointer to the device structure for the driver instance. - * @param ep Endpoint ID. * @param buf Pointer a video buffer pointer. * @param timeout Timeout * @@ -537,8 +523,8 @@ static inline int video_enqueue(const struct device *dev, enum video_endpoint_id * @retval -EINVAL If parameters are invalid. * @retval -EIO General input / output error. */ -static inline int video_dequeue(const struct device *dev, enum video_endpoint_id ep, - struct video_buffer **buf, k_timeout_t timeout) +static inline int video_dequeue(const struct device *dev, struct video_buffer **buf, + k_timeout_t timeout) { const struct video_driver_api *api = (const struct video_driver_api *)dev->api; @@ -546,7 +532,7 @@ static inline int video_dequeue(const struct device *dev, enum video_endpoint_id return -ENOSYS; } - return api->dequeue(dev, ep, buf, timeout); + return api->dequeue(dev, buf, timeout); } /** @@ -557,13 +543,12 @@ static inline int video_dequeue(const struct device *dev, enum video_endpoint_id * through the video function. * * @param dev Pointer to the device structure for the driver instance. - * @param ep Endpoint ID. * @param cancel If true, cancel buffer processing instead of waiting for * completion. * * @retval 0 Is successful, -ERRNO code otherwise. */ -static inline int video_flush(const struct device *dev, enum video_endpoint_id ep, bool cancel) +static inline int video_flush(const struct device *dev, bool cancel) { const struct video_driver_api *api = (const struct video_driver_api *)dev->api; @@ -571,7 +556,7 @@ static inline int video_flush(const struct device *dev, enum video_endpoint_id e return -ENOSYS; } - return api->flush(dev, ep, cancel); + return api->flush(dev, cancel); } /** @@ -583,10 +568,13 @@ static inline int video_flush(const struct device *dev, enum video_endpoint_id e * able to start streaming, then driver set the min_vbuf_count to the related * endpoint capabilities. * + * @param dev Pointer to the device structure. + * @param type The type of the buffers stream to start. + * * @retval 0 Is successful. * @retval -EIO General input / output error. */ -static inline int video_stream_start(const struct device *dev) +static inline int video_stream_start(const struct device *dev, enum video_buf_type type) { const struct video_driver_api *api = (const struct video_driver_api *)dev->api; @@ -594,7 +582,7 @@ static inline int video_stream_start(const struct device *dev) return -ENOSYS; } - return api->set_stream(dev, true); + return api->set_stream(dev, true, type); } /** @@ -603,10 +591,13 @@ static inline int video_stream_start(const struct device *dev) * On video_stream_stop, driver must stop any transactions or wait until they * finish. * + * @param dev Pointer to the device structure. + * @param type The type of the buffers stream to stop. + * * @retval 0 Is successful. * @retval -EIO General input / output error. */ -static inline int video_stream_stop(const struct device *dev) +static inline int video_stream_stop(const struct device *dev, enum video_buf_type type) { const struct video_driver_api *api = (const struct video_driver_api *)dev->api; int ret; @@ -615,8 +606,8 @@ static inline int video_stream_stop(const struct device *dev) return -ENOSYS; } - ret = api->set_stream(dev, false); - video_flush(dev, VIDEO_EP_ALL, true); + ret = api->set_stream(dev, false, type); + video_flush(dev, true); return ret; } @@ -625,13 +616,11 @@ static inline int video_stream_stop(const struct device *dev) * @brief Get the capabilities of a video endpoint. * * @param dev Pointer to the device structure for the driver instance. - * @param ep Endpoint ID. * @param caps Pointer to the video_caps struct to fill. * * @retval 0 Is successful, -ERRNO code otherwise. */ -static inline int video_get_caps(const struct device *dev, enum video_endpoint_id ep, - struct video_caps *caps) +static inline int video_get_caps(const struct device *dev, struct video_caps *caps) { const struct video_driver_api *api = (const struct video_driver_api *)dev->api; @@ -639,7 +628,7 @@ static inline int video_get_caps(const struct device *dev, enum video_endpoint_i return -ENOSYS; } - return api->get_caps(dev, ep, caps); + return api->get_caps(dev, caps); } /** @@ -717,13 +706,11 @@ void video_print_ctrl(const struct device *const dev, const struct video_ctrl_qu * unregisters any previously registered signal. * * @param dev Pointer to the device structure for the driver instance. - * @param ep Endpoint ID. - * @param signal Pointer to k_poll_signal + * @param sig Pointer to k_poll_signal * * @retval 0 Is successful, -ERRNO code otherwise. */ -static inline int video_set_signal(const struct device *dev, enum video_endpoint_id ep, - struct k_poll_signal *signal) +static inline int video_set_signal(const struct device *dev, struct k_poll_signal *sig) { const struct video_driver_api *api = (const struct video_driver_api *)dev->api; @@ -731,7 +718,7 @@ static inline int video_set_signal(const struct device *dev, enum video_endpoint return -ENOSYS; } - return api->set_signal(dev, ep, signal); + return api->set_signal(dev, sig); } /** @@ -813,11 +800,9 @@ void video_closest_frmival_stepwise(const struct video_frmival_stepwise *stepwis * - @c match->index to the index of the closest frame interval. * * @param dev Video device to query. - * @param ep Video endpoint ID to query. * @param match Frame interval enumerator with the query, and loaded with the result. */ -void video_closest_frmival(const struct device *dev, enum video_endpoint_id ep, - struct video_frmival_enum *match); +void video_closest_frmival(const struct device *dev, struct video_frmival_enum *match); /** * @defgroup video_pixel_formats Video pixel formats diff --git a/samples/drivers/video/capture/src/main.c b/samples/drivers/video/capture/src/main.c index 6f115f39e23b..f5afea592542 100644 --- a/samples/drivers/video/capture/src/main.c +++ b/samples/drivers/video/capture/src/main.c @@ -95,6 +95,7 @@ int main(void) struct video_caps caps; struct video_frmival frmival; struct video_frmival_enum fie; + enum video_buf_type type = VIDEO_BUF_TYPE_OUTPUT; unsigned int frame = 0; size_t bsize; int i = 0; @@ -119,7 +120,8 @@ int main(void) LOG_INF("Video device: %s", video_dev->name); /* Get capabilities */ - if (video_get_caps(video_dev, VIDEO_EP_OUT, &caps)) { + caps.type = type; + if (video_get_caps(video_dev, &caps)) { LOG_ERR("Unable to retrieve video capabilities"); return 0; } @@ -136,7 +138,8 @@ int main(void) } /* Get default/native format */ - if (video_get_format(video_dev, VIDEO_EP_OUT, &fmt)) { + fmt.type = type; + if (video_get_format(video_dev, &fmt)) { LOG_ERR("Unable to retrieve video format"); return 0; } @@ -157,12 +160,12 @@ int main(void) LOG_INF("- Video format: %s %ux%u", VIDEO_FOURCC_TO_STR(fmt.pixelformat), fmt.width, fmt.height); - if (video_set_format(video_dev, VIDEO_EP_OUT, &fmt)) { + if (video_set_format(video_dev, &fmt)) { LOG_ERR("Unable to set format"); return 0; } - if (!video_get_frmival(video_dev, VIDEO_EP_OUT, &frmival)) { + if (!video_get_frmival(video_dev, &frmival)) { LOG_INF("- Default frame rate : %f fps", 1.0 * frmival.denominator / frmival.numerator); } @@ -170,7 +173,7 @@ int main(void) LOG_INF("- Supported frame intervals for the default format:"); memset(&fie, 0, sizeof(fie)); fie.format = &fmt; - while (video_enum_frmival(video_dev, VIDEO_EP_OUT, &fie) == 0) { + while (video_enum_frmival(video_dev, &fie) == 0) { if (fie.type == VIDEO_FRMIVAL_TYPE_DISCRETE) { LOG_INF(" %u/%u ", fie.discrete.numerator, fie.discrete.denominator); } else { @@ -238,12 +241,12 @@ int main(void) LOG_ERR("Unable to alloc video buffer"); return 0; } - - video_enqueue(video_dev, VIDEO_EP_OUT, buffers[i]); + buffers[i]->type = type; + video_enqueue(video_dev, buffers[i]); } /* Start video capture */ - if (video_stream_start(video_dev)) { + if (video_stream_start(video_dev, type)) { LOG_ERR("Unable to start capture (interface)"); return 0; } @@ -251,8 +254,9 @@ int main(void) LOG_INF("Capture started"); /* Grab video frames */ + vbuf->type = type; while (1) { - err = video_dequeue(video_dev, VIDEO_EP_OUT, &vbuf, K_FOREVER); + err = video_dequeue(video_dev, &vbuf, K_FOREVER); if (err) { LOG_ERR("Unable to dequeue video buf"); return 0; @@ -271,7 +275,7 @@ int main(void) video_display_frame(display_dev, vbuf, fmt); #endif - err = video_enqueue(video_dev, VIDEO_EP_OUT, vbuf); + err = video_enqueue(video_dev, vbuf); if (err) { LOG_ERR("Unable to requeue video buf"); return 0; diff --git a/samples/drivers/video/capture_to_lvgl/src/main.c b/samples/drivers/video/capture_to_lvgl/src/main.c index 201e0a8bed90..81883577ad8f 100644 --- a/samples/drivers/video/capture_to_lvgl/src/main.c +++ b/samples/drivers/video/capture_to_lvgl/src/main.c @@ -23,6 +23,7 @@ int main(void) const struct device *display_dev; struct video_format fmt; struct video_caps caps; + enum video_buf_type type = VIDEO_BUF_TYPE_OUTPUT; const struct device *video_dev; size_t bsize; int i = 0; @@ -50,7 +51,8 @@ int main(void) LOG_INF("- Device name: %s", video_dev->name); /* Get capabilities */ - if (video_get_caps(video_dev, VIDEO_EP_OUT, &caps)) { + caps.type = type; + if (video_get_caps(video_dev, &caps)) { LOG_ERR("Unable to retrieve video capabilities"); return 0; } @@ -68,7 +70,8 @@ int main(void) } /* Get default/native format */ - if (video_get_format(video_dev, VIDEO_EP_OUT, &fmt)) { + fmt.type = type; + if (video_get_format(video_dev, &fmt)) { LOG_ERR("Unable to retrieve video format"); return 0; } @@ -79,7 +82,7 @@ int main(void) fmt.pitch = fmt.width * 2; fmt.pixelformat = VIDEO_PIX_FMT_RGB565; - if (video_set_format(video_dev, VIDEO_EP_OUT, &fmt)) { + if (video_set_format(video_dev, &fmt)) { LOG_ERR("Unable to set up video format"); return 0; } @@ -102,8 +105,8 @@ int main(void) LOG_ERR("Unable to alloc video buffer"); return 0; } - - video_enqueue(video_dev, VIDEO_EP_OUT, buffers[i]); + buffers[i]->type = type; + video_enqueue(video_dev, buffers[i]); } /* Set controls */ @@ -119,7 +122,7 @@ int main(void) } /* Start video capture */ - if (video_stream_start(video_dev)) { + if (video_stream_start(video_dev, type)) { LOG_ERR("Unable to start capture (interface)"); return 0; } @@ -139,10 +142,11 @@ int main(void) LOG_INF("- Capture started"); /* Grab video frames */ + vbuf->type = type; while (1) { int err; - err = video_dequeue(video_dev, VIDEO_EP_OUT, &vbuf, K_FOREVER); + err = video_dequeue(video_dev, &vbuf, K_FOREVER); if (err) { LOG_ERR("Unable to dequeue video buf"); return 0; @@ -153,7 +157,7 @@ int main(void) lv_task_handler(); - err = video_enqueue(video_dev, VIDEO_EP_OUT, vbuf); + err = video_enqueue(video_dev, vbuf); if (err) { LOG_ERR("Unable to requeue video buf"); return 0; diff --git a/samples/drivers/video/tcpserversink/src/main.c b/samples/drivers/video/tcpserversink/src/main.c index da3f9e4a8319..85d321bf8e7a 100644 --- a/samples/drivers/video/tcpserversink/src/main.c +++ b/samples/drivers/video/tcpserversink/src/main.c @@ -42,6 +42,7 @@ int main(void) int i, ret, sock, client; struct video_format fmt; struct video_caps caps; + enum video_buf_type type = VIDEO_BUF_TYPE_OUTPUT; #if DT_HAS_CHOSEN(zephyr_camera) const struct device *const video = DEVICE_DT_GET(DT_CHOSEN(zephyr_camera)); @@ -83,13 +84,15 @@ int main(void) } /* Get capabilities */ - if (video_get_caps(video, VIDEO_EP_OUT, &caps)) { + caps.type = type; + if (video_get_caps(video, &caps)) { LOG_ERR("Unable to retrieve video capabilities"); return 0; } /* Get default/native format */ - if (video_get_format(video, VIDEO_EP_OUT, &fmt)) { + fmt.type = type; + if (video_get_format(video, &fmt)) { LOG_ERR("Unable to retrieve video format"); return 0; } @@ -109,6 +112,7 @@ int main(void) LOG_ERR("Unable to alloc video buffer"); return 0; } + buffers[i]->type = type; } /* Connection loop */ @@ -125,11 +129,11 @@ int main(void) /* Enqueue Buffers */ for (i = 0; i < ARRAY_SIZE(buffers); i++) { - video_enqueue(video, VIDEO_EP_OUT, buffers[i]); + video_enqueue(video, buffers[i]); } /* Start video capture */ - if (video_stream_start(video)) { + if (video_stream_start(video, type)) { LOG_ERR("Unable to start video"); return 0; } @@ -138,8 +142,9 @@ int main(void) /* Capture loop */ i = 0; + vbuf->type = type; do { - ret = video_dequeue(video, VIDEO_EP_OUT, &vbuf, K_FOREVER); + ret = video_dequeue(video, &vbuf, K_FOREVER); if (ret) { LOG_ERR("Unable to dequeue video buf"); return 0; @@ -155,18 +160,18 @@ int main(void) close(client); } - (void)video_enqueue(video, VIDEO_EP_OUT, vbuf); + (void)video_enqueue(video, vbuf); } while (!ret); /* stop capture */ - if (video_stream_stop(video)) { + if (video_stream_stop(video, type)) { LOG_ERR("Unable to stop video"); return 0; } /* Flush remaining buffers */ do { - ret = video_dequeue(video, VIDEO_EP_OUT, &vbuf, K_NO_WAIT); + ret = video_dequeue(video, &vbuf, K_NO_WAIT); } while (!ret); } while (1); diff --git a/tests/drivers/video/api/src/video_emul.c b/tests/drivers/video/api/src/video_emul.c index 374619e230c5..3013ea84befb 100644 --- a/tests/drivers/video/api/src/video_emul.c +++ b/tests/drivers/video/api/src/video_emul.c @@ -16,11 +16,11 @@ ZTEST(video_common, test_video_device) zexpect_true(device_is_ready(rx_dev)); zexpect_true(device_is_ready(imager_dev)); - zexpect_ok(video_stream_start(imager_dev)); - zexpect_ok(video_stream_stop(imager_dev)); + zexpect_ok(video_stream_start(imager_dev, VIDEO_BUF_TYPE_OUTPUT)); + zexpect_ok(video_stream_stop(imager_dev, VIDEO_BUF_TYPE_OUTPUT)); - zexpect_ok(video_stream_start(rx_dev)); - zexpect_ok(video_stream_stop(rx_dev)); + zexpect_ok(video_stream_start(rx_dev, VIDEO_BUF_TYPE_OUTPUT)); + zexpect_ok(video_stream_stop(rx_dev, VIDEO_BUF_TYPE_OUTPUT)); } ZTEST(video_common, test_video_format) @@ -28,7 +28,7 @@ ZTEST(video_common, test_video_format) struct video_caps caps = {0}; struct video_format fmt = {0}; - zexpect_ok(video_get_caps(imager_dev, VIDEO_EP_OUT, &caps)); + zexpect_ok(video_get_caps(imager_dev, &caps)); /* Test all the formats listed in the caps, the min and max values */ for (size_t i = 0; caps.format_caps[i].pixelformat != 0; i++) { @@ -36,40 +36,40 @@ ZTEST(video_common, test_video_format) fmt.height = caps.format_caps[i].height_min; fmt.width = caps.format_caps[i].width_min; - zexpect_ok(video_set_format(imager_dev, VIDEO_EP_OUT, &fmt)); - zexpect_ok(video_get_format(imager_dev, VIDEO_EP_OUT, &fmt)); + zexpect_ok(video_set_format(imager_dev, &fmt)); + zexpect_ok(video_get_format(imager_dev, &fmt)); zexpect_equal(fmt.pixelformat, caps.format_caps[i].pixelformat); zexpect_equal(fmt.width, caps.format_caps[i].width_min); zexpect_equal(fmt.height, caps.format_caps[i].height_min); fmt.height = caps.format_caps[i].height_max; fmt.width = caps.format_caps[i].width_min; - zexpect_ok(video_set_format(imager_dev, VIDEO_EP_OUT, &fmt)); - zexpect_ok(video_get_format(imager_dev, VIDEO_EP_OUT, &fmt)); + zexpect_ok(video_set_format(imager_dev, &fmt)); + zexpect_ok(video_get_format(imager_dev, &fmt)); zexpect_equal(fmt.pixelformat, caps.format_caps[i].pixelformat); zexpect_equal(fmt.width, caps.format_caps[i].width_max); zexpect_equal(fmt.height, caps.format_caps[i].height_min); fmt.height = caps.format_caps[i].height_min; fmt.width = caps.format_caps[i].width_max; - zexpect_ok(video_set_format(imager_dev, VIDEO_EP_OUT, &fmt)); - zexpect_ok(video_get_format(imager_dev, VIDEO_EP_OUT, &fmt)); + zexpect_ok(video_set_format(imager_dev, &fmt)); + zexpect_ok(video_get_format(imager_dev, &fmt)); zexpect_equal(fmt.pixelformat, caps.format_caps[i].pixelformat); zexpect_equal(fmt.width, caps.format_caps[i].width_min); zexpect_equal(fmt.height, caps.format_caps[i].height_max); fmt.height = caps.format_caps[i].height_max; fmt.width = caps.format_caps[i].width_max; - zexpect_ok(video_set_format(imager_dev, VIDEO_EP_OUT, &fmt)); - zexpect_ok(video_get_format(imager_dev, VIDEO_EP_OUT, &fmt)); + zexpect_ok(video_set_format(imager_dev, &fmt)); + zexpect_ok(video_get_format(imager_dev, &fmt)); zexpect_equal(fmt.pixelformat, caps.format_caps[i].pixelformat); zexpect_equal(fmt.width, caps.format_caps[i].width_max); zexpect_equal(fmt.height, caps.format_caps[i].height_max); } fmt.pixelformat = 0x00000000; - zexpect_not_ok(video_set_format(imager_dev, VIDEO_EP_OUT, &fmt)); - zexpect_ok(video_get_format(imager_dev, VIDEO_EP_OUT, &fmt)); + zexpect_not_ok(video_set_format(imager_dev, &fmt)); + zexpect_ok(video_get_format(imager_dev, &fmt)); zexpect_not_equal(fmt.pixelformat, 0x00000000, "should not store wrong formats"); } @@ -79,14 +79,14 @@ ZTEST(video_common, test_video_frmival) struct video_frmival_enum fie = {.format = &fmt}; /* Pick the current format for testing the frame interval enumeration */ - zexpect_ok(video_get_format(imager_dev, VIDEO_EP_OUT, &fmt)); + zexpect_ok(video_get_format(imager_dev, &fmt)); /* Do a first enumeration of frame intervals, expected to work */ - zexpect_ok(video_enum_frmival(imager_dev, VIDEO_EP_OUT, &fie)); + zexpect_ok(video_enum_frmival(imager_dev, &fie)); zexpect_equal(fie.index, 0, "fie's index should not increment on its own"); /* Test that every value of the frame interval enumerator can be applied */ - for (fie.index = 0; video_enum_frmival(imager_dev, VIDEO_EP_OUT, &fie) == 0; fie.index++) { + for (fie.index = 0; video_enum_frmival(imager_dev, &fie) == 0; fie.index++) { struct video_frmival q, a; uint32_t min, max, step; @@ -109,8 +109,8 @@ ZTEST(video_common, test_video_frmival) /* Test every supported frame interval */ for (q.numerator = min; q.numerator <= max; q.numerator += step) { - zexpect_ok(video_set_frmival(imager_dev, VIDEO_EP_OUT, &q)); - zexpect_ok(video_get_frmival(imager_dev, VIDEO_EP_OUT, &a)); + zexpect_ok(video_set_frmival(imager_dev, &q)); + zexpect_ok(video_get_frmival(imager_dev, &a)); zexpect_equal(video_frmival_nsec(&q), video_frmival_nsec(&a), "query %u/%u (%u nsec) answer %u/%u (%u nsec, sw)", q.numerator, q.denominator, video_frmival_nsec(&q), @@ -120,8 +120,8 @@ ZTEST(video_common, test_video_frmival) case VIDEO_FRMIVAL_TYPE_DISCRETE: /* There is just one frame interval to test */ memcpy(&q, &fie.discrete, sizeof(q)); - zexpect_ok(video_set_frmival(imager_dev, VIDEO_EP_OUT, &q)); - zexpect_ok(video_get_frmival(imager_dev, VIDEO_EP_OUT, &a)); + zexpect_ok(video_set_frmival(imager_dev, &q)); + zexpect_ok(video_get_frmival(imager_dev, &a)); zexpect_equal(video_frmival_nsec(&fie.discrete), video_frmival_nsec(&a), "query %u/%u (%u nsec) answer %u/%u (%u nsec, discrete)", @@ -148,45 +148,50 @@ ZTEST(video_common, test_video_vbuf) struct video_caps caps; struct video_format fmt; struct video_buffer *vbuf = NULL; + enum video_buf_type type = VIDEO_BUF_TYPE_OUTPUT; /* Get a list of supported format */ - zexpect_ok(video_get_caps(rx_dev, VIDEO_EP_OUT, &caps)); + caps.type = type; + zexpect_ok(video_get_caps(rx_dev, &caps)); /* Pick set first format, just to use something supported */ fmt.pixelformat = caps.format_caps[0].pixelformat; fmt.width = caps.format_caps[0].width_max; fmt.height = caps.format_caps[0].height_max; fmt.pitch = fmt.width * 2; - zexpect_ok(video_set_format(rx_dev, VIDEO_EP_OUT, &fmt)); + fmt.type = type; + zexpect_ok(video_set_format(rx_dev, &fmt)); /* Allocate a buffer, assuming prj.conf gives enough memory for it */ vbuf = video_buffer_alloc(fmt.pitch * fmt.height, K_NO_WAIT); zexpect_not_null(vbuf); /* Start the virtual hardware */ - zexpect_ok(video_stream_start(rx_dev)); + zexpect_ok(video_stream_start(rx_dev, type)); + + vbuf->type = type; /* Enqueue a first buffer */ - zexpect_ok(video_enqueue(rx_dev, VIDEO_EP_OUT, vbuf)); + zexpect_ok(video_enqueue(rx_dev, vbuf)); /* Receive the completed buffer */ - zexpect_ok(video_dequeue(rx_dev, VIDEO_EP_OUT, &vbuf, K_FOREVER)); + zexpect_ok(video_dequeue(rx_dev, &vbuf, K_FOREVER)); zexpect_not_null(vbuf); zexpect_equal(vbuf->bytesused, vbuf->size); /* Enqueue back the same buffer */ - zexpect_ok(video_enqueue(rx_dev, VIDEO_EP_OUT, vbuf)); + zexpect_ok(video_enqueue(rx_dev, vbuf)); /* Process the remaining buffers */ - zexpect_ok(video_flush(rx_dev, VIDEO_EP_OUT, false)); + zexpect_ok(video_flush(rx_dev, false)); /* Expect the buffer to immediately be available */ - zexpect_ok(video_dequeue(rx_dev, VIDEO_EP_OUT, &vbuf, K_FOREVER)); + zexpect_ok(video_dequeue(rx_dev, &vbuf, K_FOREVER)); zexpect_not_null(vbuf); zexpect_equal(vbuf->bytesused, vbuf->size); /* Nothing left in the queue, possible to stop */ - zexpect_ok(video_stream_stop(rx_dev)); + zexpect_ok(video_stream_stop(rx_dev, type)); /* Nothing tested, but this should not crash */ video_buffer_release(vbuf);