Skip to content

Commit 2ac4900

Browse files
committed
drivers: video: sw_generator: convert to use the devicetree
Make the video software generator a devicetree node, which allows enabling several instances, and select it as chosen { zephyr,camera = &... }; node. It can be enabled via a `video-sw-generator` snippet. Signed-off-by: Josuah Demangeon <me@josuah.net>
1 parent 225015a commit 2ac4900

File tree

15 files changed

+96
-58
lines changed

15 files changed

+96
-58
lines changed

drivers/video/Kconfig.sw_generator

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
# MT9m114
2-
31
# Copyright (c) 2016 Linaro Limited
42
# SPDX-License-Identifier: Apache-2.0
53

6-
DT_CHOSEN_ZEPHYR_CAMERA := zephyr,camera
7-
84
config VIDEO_SW_GENERATOR
95
bool "Video Software Generator"
10-
depends on !$(dt_chosen_enabled,$(DT_CHOSEN_ZEPHYR_CAMERA))
6+
depends on DT_HAS_ZEPHYR_VIDEO_SW_GENERATOR_ENABLED
7+
default y
118
help
129
Enable video pattern generator (for testing purposes).

drivers/video/video_sw_generator.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#define DT_DRV_COMPAT zephyr_sw_generator
7+
#define DT_DRV_COMPAT zephyr_video_sw_generator
88

99
#include <zephyr/kernel.h>
1010
#include <zephyr/drivers/video.h>
@@ -312,14 +312,6 @@ static DEVICE_API(video, video_sw_generator_driver_api) = {
312312
#endif
313313
};
314314

315-
static struct video_sw_generator_data video_sw_generator_data_0 = {
316-
.fmt.width = 320,
317-
.fmt.height = 160,
318-
.fmt.pitch = 320 * 2,
319-
.fmt.pixelformat = VIDEO_PIX_FMT_RGB565,
320-
.frame_rate = DEFAULT_FRAME_RATE,
321-
};
322-
323315
static int video_sw_generator_init_controls(const struct device *dev)
324316
{
325317
struct video_sw_generator_data *data = dev->data;
@@ -340,8 +332,19 @@ static int video_sw_generator_init(const struct device *dev)
340332
return video_sw_generator_init_controls(dev);
341333
}
342334

343-
DEVICE_DEFINE(video_sw_generator, "VIDEO_SW_GENERATOR", &video_sw_generator_init, NULL,
344-
&video_sw_generator_data_0, NULL, POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY,
345-
&video_sw_generator_driver_api);
346-
347-
VIDEO_DEVICE_DEFINE(video_sw_generator, DEVICE_GET(video_sw_generator), NULL);
335+
#define VIDEO_SW_GENERATOR_DEFINE(n) \
336+
static struct video_sw_generator_data video_sw_generator_data_##n = { \
337+
.fmt.width = 320, \
338+
.fmt.height = 160, \
339+
.fmt.pitch = 320 * 2, \
340+
.fmt.pixelformat = VIDEO_PIX_FMT_RGB565, \
341+
.frame_rate = DEFAULT_FRAME_RATE, \
342+
}; \
343+
\
344+
DEVICE_DT_INST_DEFINE(n, &video_sw_generator_init, NULL, &video_sw_generator_data_##n, \
345+
NULL, POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, \
346+
&video_sw_generator_driver_api); \
347+
\
348+
VIDEO_DEVICE_DEFINE(video_sw_generator_##n, DEVICE_DT_INST_GET(n), NULL);
349+
350+
DT_INST_FOREACH_STATUS_OKAY(VIDEO_SW_GENERATOR_DEFINE)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright 2025 tinyVision.ai Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: Emulated Video test pattern generator
5+
6+
compatible: "zephyr,video-sw-generator"

samples/drivers/video/capture/README.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,16 @@ For :ref:`native_sim`, build this sample application with the following commands
9191
:goals: build
9292
:compact:
9393

94-
For testing purpose without the need of any real video capture and/or display hardwares,
94+
For testing purpose and without the need of any real video capture and/or display hardwares,
9595
a video software pattern generator is supported by the above build commands without
96-
specifying the shields.
96+
specifying the shields, and using :ref:`snippet-video-sw-generator`:
97+
98+
.. zephyr-app-commands::
99+
:zephyr-app: samples/drivers/video/capture
100+
:board: native_sim/native/64
101+
:snippets: video-sw-generator
102+
:goals: build
103+
:compact:
97104

98105
For controlling the camera device using shell commands instead of continuously capturing the data,
99106
append ``-DCONFIG_VIDEO_SHELL=y`` to the build command:

samples/drivers/video/capture/prj.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
CONFIG_VIDEO=y
2-
CONFIG_VIDEO_SW_GENERATOR=y
32
CONFIG_SHELL=y
43
CONFIG_DEVICE_SHELL=y
54
CONFIG_PRINTK=y

samples/drivers/video/capture/src/main.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ LOG_MODULE_REGISTER(main);
2323
#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
2424
#endif
2525

26-
#define VIDEO_DEV_SW "VIDEO_SW_GENERATOR"
27-
2826
#if DT_HAS_CHOSEN(zephyr_display)
2927
static inline int display_setup(const struct device *const display_dev, const uint32_t pixfmt)
3028
{
@@ -90,6 +88,7 @@ static inline void video_display_frame(const struct device *const display_dev,
9088

9189
int main(void)
9290
{
91+
const struct device *video_dev;
9392
struct video_buffer *buffers[CONFIG_VIDEO_BUFFER_POOL_NUM_MAX], *vbuf;
9493
struct video_format fmt;
9594
struct video_caps caps;
@@ -107,21 +106,11 @@ int main(void)
107106
return 0;
108107
}
109108

110-
#if DT_HAS_CHOSEN(zephyr_camera)
111-
const struct device *const video_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_camera));
112-
109+
video_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_camera));
113110
if (!device_is_ready(video_dev)) {
114111
LOG_ERR("%s: video device is not ready", video_dev->name);
115112
return 0;
116113
}
117-
#else
118-
const struct device *const video_dev = device_get_binding(VIDEO_DEV_SW);
119-
120-
if (video_dev == NULL) {
121-
LOG_ERR("%s: video device not found or failed to initialized", VIDEO_DEV_SW);
122-
return 0;
123-
}
124-
#endif
125114

126115
LOG_INF("Video device: %s", video_dev->name);
127116

samples/drivers/video/capture_to_lvgl/README.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ For :zephyr:board:`mini_stm32h743`, build this sample application with the follo
3737
:gen-args: -DCONFIG_BOOT_DELAY=2000
3838
:compact:
3939

40+
For testing purpose and without the need of any real video capture hardware,
41+
a video software pattern generator is supported by using :ref:`snippet-video-sw-generator`:
42+
43+
.. zephyr-app-commands::
44+
:zephyr-app: samples/drivers/video/capture
45+
:board: native_sim/native/64
46+
:snippets: video-sw-generator
47+
:goals: build
48+
:compact:
49+
4050
Sample Output
4151
=============
4252

samples/drivers/video/capture_to_lvgl/prj.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
CONFIG_VIDEO=y
2-
CONFIG_VIDEO_SW_GENERATOR=y
32

43
CONFIG_PRINTK=y
54
CONFIG_LOG=y

samples/drivers/video/capture_to_lvgl/src/main.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@
1515
#include <zephyr/logging/log.h>
1616
LOG_MODULE_REGISTER(main);
1717

18-
#define VIDEO_DEV_SW "VIDEO_SW_GENERATOR"
19-
2018
int main(void)
2119
{
2220
struct video_buffer *buffers[2], *vbuf;
2321
const struct device *display_dev;
22+
const struct device *video_dev;
2423
struct video_format fmt;
2524
struct video_caps caps;
2625
enum video_buf_type type = VIDEO_BUF_TYPE_OUTPUT;
27-
const struct device *video_dev;
2826
size_t bsize;
2927
int i = 0;
3028

@@ -34,19 +32,11 @@ int main(void)
3432
return 0;
3533
}
3634

37-
#if DT_HAS_CHOSEN(zephyr_camera)
3835
video_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_camera));
3936
if (!device_is_ready(video_dev)) {
4037
LOG_ERR("%s device is not ready", video_dev->name);
4138
return 0;
4239
}
43-
#else
44-
video_dev = device_get_binding(VIDEO_DEV_SW);
45-
if (video_dev == NULL) {
46-
LOG_ERR("%s device not found", VIDEO_DEV_SW);
47-
return 0;
48-
}
49-
#endif
5040

5141
LOG_INF("- Device name: %s", video_dev->name);
5242

samples/drivers/video/tcpserversink/README.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ If a mt9m114 camera shield is missing, video software generator will be used ins
3939
:goals: build
4040
:compact:
4141

42+
For testing purpose and without the need of any real video capture hardware,
43+
a video software pattern generator is supported by using :ref:`snippet-video-sw-generator`:
44+
45+
.. zephyr-app-commands::
46+
:zephyr-app: samples/drivers/video/capture
47+
:board: native_sim/native/64
48+
:snippets: video-sw-generator
49+
:goals: build
50+
:compact:
51+
4252
Sample Output
4353
=============
4454

0 commit comments

Comments
 (0)