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