|
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,25 +70,18 @@ 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 | fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
|
88 | 83 |
|
89 | 84 | data->fmt = *fmt;
|
90 |
| - |
91 | 85 | return 0;
|
92 | 86 | }
|
93 | 87 |
|
@@ -279,17 +273,13 @@ static int video_sw_generator_get_frmival(const struct device *dev, struct video
|
279 | 273 |
|
280 | 274 | static int video_sw_generator_enum_frmival(const struct device *dev, struct video_frmival_enum *fie)
|
281 | 275 | {
|
282 |
| - int i = 0; |
| 276 | + size_t idx; |
| 277 | + int ret; |
283 | 278 |
|
284 |
| - while (fmts[i].pixelformat && (fmts[i].pixelformat != fie->format->pixelformat)) { |
285 |
| - i++; |
286 |
| - } |
287 |
| - |
288 |
| - if ((i == ARRAY_SIZE(fmts)) || (fie->format->width > fmts[i].width_max) || |
289 |
| - (fie->format->width < fmts[i].width_min) || |
290 |
| - (fie->format->height > fmts[i].height_max) || |
291 |
| - (fie->format->height < fmts[i].height_min)) { |
292 |
| - return -EINVAL; |
| 279 | + ret = video_format_caps_index(fmts, fie->format, &idx); |
| 280 | + if (ret < 0) { |
| 281 | + LOG_ERR("Unsupported pixel format or resolution"); |
| 282 | + return ret; |
293 | 283 | }
|
294 | 284 |
|
295 | 285 | fie->type = VIDEO_FRMIVAL_TYPE_STEPWISE;
|
|
0 commit comments