|
10 | 10 | #include <zephyr/drivers/video.h>
|
11 | 11 | #include <zephyr/drivers/video-controls.h>
|
12 | 12 | #include <zephyr/logging/log.h>
|
| 13 | +#include <zephyr/sys/util.h> |
13 | 14 |
|
14 | 15 | #include "video_ctrls.h"
|
15 | 16 | #include "video_device.h"
|
@@ -69,23 +70,16 @@ static const struct video_format_cap fmts[] = {
|
69 | 70 | static int video_sw_generator_set_fmt(const struct device *dev, struct video_format *fmt)
|
70 | 71 | {
|
71 | 72 | struct video_sw_generator_data *data = dev->data;
|
72 |
| - int i = 0; |
| 73 | + size_t idx; |
| 74 | + int ret; |
73 | 75 |
|
74 |
| - for (i = 0; i < ARRAY_SIZE(fmts); ++i) { |
75 |
| - if (fmt->pixelformat == fmts[i].pixelformat && fmt->width >= fmts[i].width_min && |
76 |
| - fmt->width <= fmts[i].width_max && fmt->height >= fmts[i].height_min && |
77 |
| - fmt->height <= fmts[i].height_max) { |
78 |
| - break; |
79 |
| - } |
80 |
| - } |
81 |
| - |
82 |
| - if (i == ARRAY_SIZE(fmts)) { |
| 76 | + ret = video_format_caps_index(fmts, fmt, &idx); |
| 77 | + if (ret < 0) { |
83 | 78 | LOG_ERR("Unsupported pixel format or resolution");
|
84 |
| - return -ENOTSUP; |
| 79 | + return ret; |
85 | 80 | }
|
86 | 81 |
|
87 | 82 | data->fmt = *fmt;
|
88 |
| - |
89 | 83 | return 0;
|
90 | 84 | }
|
91 | 85 |
|
@@ -277,17 +271,13 @@ static int video_sw_generator_get_frmival(const struct device *dev, struct video
|
277 | 271 |
|
278 | 272 | static int video_sw_generator_enum_frmival(const struct device *dev, struct video_frmival_enum *fie)
|
279 | 273 | {
|
280 |
| - int i = 0; |
| 274 | + size_t idx; |
| 275 | + int ret; |
281 | 276 |
|
282 |
| - while (fmts[i].pixelformat && (fmts[i].pixelformat != fie->format->pixelformat)) { |
283 |
| - i++; |
284 |
| - } |
285 |
| - |
286 |
| - if ((i == ARRAY_SIZE(fmts)) || (fie->format->width > fmts[i].width_max) || |
287 |
| - (fie->format->width < fmts[i].width_min) || |
288 |
| - (fie->format->height > fmts[i].height_max) || |
289 |
| - (fie->format->height < fmts[i].height_min)) { |
290 |
| - return -EINVAL; |
| 277 | + ret = video_format_caps_index(fmts, fie->format, &idx); |
| 278 | + if (ret < 0) { |
| 279 | + LOG_ERR("Unsupported pixel format or resolution"); |
| 280 | + return ret; |
291 | 281 | }
|
292 | 282 |
|
293 | 283 | fie->type = VIDEO_FRMIVAL_TYPE_STEPWISE;
|
|
0 commit comments