7
7
8
8
#include <zephyr/drivers/video.h>
9
9
10
+ #define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
11
+ #include <zephyr/logging/log.h>
12
+ LOG_MODULE_REGISTER (video_sw_generator );
13
+
10
14
#define VIDEO_PATTERN_COLOR_BAR 0
11
15
#define VIDEO_PATTERN_FPS 30
12
16
@@ -23,15 +27,48 @@ struct video_sw_generator_data {
23
27
struct k_poll_signal * signal ;
24
28
};
25
29
30
+ static const struct video_format_cap fmts [] = {{
31
+ .pixelformat = VIDEO_PIX_FMT_RGB565 ,
32
+ .width_min = 64 ,
33
+ .width_max = 1920 ,
34
+ .height_min = 64 ,
35
+ .height_max = 1080 ,
36
+ .width_step = 1 ,
37
+ .height_step = 1 ,
38
+ }, {
39
+ .pixelformat = VIDEO_PIX_FMT_XRGB32 ,
40
+ .width_min = 64 ,
41
+ .width_max = 1920 ,
42
+ .height_min = 64 ,
43
+ .height_max = 1080 ,
44
+ .width_step = 1 ,
45
+ .height_step = 1 ,
46
+ },
47
+ {0 }};
48
+
26
49
static int video_sw_generator_set_fmt (const struct device * dev , enum video_endpoint_id ep ,
27
50
struct video_format * fmt )
28
51
{
29
52
struct video_sw_generator_data * data = dev -> data ;
53
+ int i = 0 ;
30
54
31
55
if (ep != VIDEO_EP_OUT ) {
32
56
return - EINVAL ;
33
57
}
34
58
59
+ for (i = 0 ; i < ARRAY_SIZE (fmts ); ++ i ) {
60
+ if (fmt -> pixelformat == fmts [i ].pixelformat && fmt -> width >= fmts [i ].width_min &&
61
+ fmt -> width <= fmts [i ].width_max && fmt -> height >= fmts [i ].height_min &&
62
+ fmt -> height <= fmts [i ].height_max ) {
63
+ break ;
64
+ }
65
+ }
66
+
67
+ if (i == ARRAY_SIZE (fmts )) {
68
+ LOG_ERR ("Unsupported pixel format or resolution" );
69
+ return - ENOTSUP ;
70
+ }
71
+
35
72
data -> fmt = * fmt ;
36
73
37
74
return 0 ;
@@ -183,25 +220,6 @@ static int video_sw_generator_flush(const struct device *dev, enum video_endpoin
183
220
return 0 ;
184
221
}
185
222
186
- static const struct video_format_cap fmts [] = {{
187
- .pixelformat = VIDEO_PIX_FMT_RGB565 ,
188
- .width_min = 64 ,
189
- .width_max = 1920 ,
190
- .height_min = 64 ,
191
- .height_max = 1080 ,
192
- .width_step = 1 ,
193
- .height_step = 1 ,
194
- }, {
195
- .pixelformat = VIDEO_PIX_FMT_XRGB32 ,
196
- .width_min = 64 ,
197
- .width_max = 1920 ,
198
- .height_min = 64 ,
199
- .height_max = 1080 ,
200
- .width_step = 1 ,
201
- .height_step = 1 ,
202
- },
203
- {0 }};
204
-
205
223
static int video_sw_generator_get_caps (const struct device * dev , enum video_endpoint_id ep ,
206
224
struct video_caps * caps )
207
225
{
0 commit comments