|
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 | LOG_MODULE_REGISTER(video_sw_generator, CONFIG_VIDEO_LOG_LEVEL);
|
15 | 16 |
|
@@ -64,16 +65,16 @@ static int video_sw_generator_set_fmt(const struct device *dev, enum video_endpo
|
64 | 65 | struct video_format *fmt)
|
65 | 66 | {
|
66 | 67 | struct video_sw_generator_data *data = dev->data;
|
67 |
| - int i = 0; |
| 68 | + int i; |
68 | 69 |
|
69 | 70 | if (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL) {
|
70 | 71 | return -EINVAL;
|
71 | 72 | }
|
72 | 73 |
|
73 | 74 | for (i = 0; i < ARRAY_SIZE(fmts); ++i) {
|
74 |
| - if (fmt->pixelformat == fmts[i].pixelformat && fmt->width >= fmts[i].width_min && |
75 |
| - fmt->width <= fmts[i].width_max && fmt->height >= fmts[i].height_min && |
76 |
| - fmt->height <= fmts[i].height_max) { |
| 75 | + if (fmt->pixelformat == fmts[i].pixelformat && |
| 76 | + IN_RANGE(fmt->width, fmts[i].width_min, fmts[i].width_max) && |
| 77 | + IN_RANGE(fmt->height, fmts[i].height_min, fmts[i].height_max)) { |
77 | 78 | break;
|
78 | 79 | }
|
79 | 80 | }
|
@@ -313,18 +314,20 @@ static int video_sw_generator_enum_frmival(const struct device *dev, enum video_
|
313 | 314 | {
|
314 | 315 | int i = 0;
|
315 | 316 |
|
316 |
| - if (ep != VIDEO_EP_OUT || fie->index) { |
| 317 | + if (ep != VIDEO_EP_OUT || fie->index > 0) { |
317 | 318 | return -EINVAL;
|
318 | 319 | }
|
319 | 320 |
|
320 |
| - while (fmts[i].pixelformat && (fmts[i].pixelformat != fie->format->pixelformat)) { |
321 |
| - i++; |
| 321 | + for (i = 0; fmts[i].pixelformat != 0; ++i) { |
| 322 | + if (fie->format->pixelformat == fmts[i].pixelformat && |
| 323 | + IN_RANGE(fie->format->width, fmts[i].width_min, fmts[i].width_max) && |
| 324 | + IN_RANGE(fie->format->height, fmts[i].height_min, fmts[i].height_max)) { |
| 325 | + break; |
| 326 | + } |
322 | 327 | }
|
323 | 328 |
|
324 |
| - if ((i == ARRAY_SIZE(fmts)) || (fie->format->width > fmts[i].width_max) || |
325 |
| - (fie->format->width < fmts[i].width_min) || |
326 |
| - (fie->format->height > fmts[i].height_max) || |
327 |
| - (fie->format->height < fmts[i].height_min)) { |
| 329 | + if (fmts[i].pixelformat == 0) { |
| 330 | + LOG_ERR("Nothing matching the requested format was found"); |
328 | 331 | return -EINVAL;
|
329 | 332 | }
|
330 | 333 |
|
|
0 commit comments