Browse Source

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>
pull/88753/merge
Josuah Demangeon 3 months ago committed by Benjamin Cabé
parent
commit
a3465f8f4d
  1. 7
      drivers/video/Kconfig.sw_generator
  2. 31
      drivers/video/video_sw_generator.c
  3. 6
      dts/bindings/video/zephyr,video-sw-generator.yaml
  4. 11
      samples/drivers/video/capture/README.rst
  5. 1
      samples/drivers/video/capture/prj.conf
  6. 2
      samples/drivers/video/capture/sample.yaml
  7. 15
      samples/drivers/video/capture/src/main.c
  8. 10
      samples/drivers/video/capture_to_lvgl/README.rst
  9. 1
      samples/drivers/video/capture_to_lvgl/prj.conf
  10. 12
      samples/drivers/video/capture_to_lvgl/src/main.c
  11. 10
      samples/drivers/video/tcpserversink/README.rst
  12. 1
      samples/drivers/video/tcpserversink/prj.conf
  13. 12
      samples/drivers/video/tcpserversink/src/main.c
  14. 20
      snippets/video-sw-generator/README.rst
  15. 3
      snippets/video-sw-generator/snippet.yml
  16. 14
      snippets/video-sw-generator/video-sw-generator.overlay

7
drivers/video/Kconfig.sw_generator

@ -1,12 +1,9 @@ @@ -1,12 +1,9 @@
# MT9m114
# Copyright (c) 2016 Linaro Limited
# SPDX-License-Identifier: Apache-2.0
DT_CHOSEN_ZEPHYR_CAMERA := zephyr,camera
config VIDEO_SW_GENERATOR
bool "Video Software Generator"
depends on !$(dt_chosen_enabled,$(DT_CHOSEN_ZEPHYR_CAMERA))
depends on DT_HAS_ZEPHYR_VIDEO_SW_GENERATOR_ENABLED
default y
help
Enable video pattern generator (for testing purposes).

31
drivers/video/video_sw_generator.c

@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT zephyr_sw_generator
#define DT_DRV_COMPAT zephyr_video_sw_generator
#include <zephyr/drivers/video-controls.h>
#include <zephyr/drivers/video.h>
@ -451,14 +451,6 @@ static DEVICE_API(video, video_sw_generator_driver_api) = { @@ -451,14 +451,6 @@ static DEVICE_API(video, video_sw_generator_driver_api) = {
#endif
};
static struct video_sw_generator_data video_sw_generator_data_0 = {
.fmt.width = 320,
.fmt.height = 160,
.fmt.pitch = 320 * 2,
.fmt.pixelformat = VIDEO_PIX_FMT_RGB565,
.frame_rate = DEFAULT_FRAME_RATE,
};
static int video_sw_generator_init_controls(const struct device *dev)
{
struct video_sw_generator_data *data = dev->data;
@ -479,8 +471,19 @@ static int video_sw_generator_init(const struct device *dev) @@ -479,8 +471,19 @@ static int video_sw_generator_init(const struct device *dev)
return video_sw_generator_init_controls(dev);
}
DEVICE_DEFINE(video_sw_generator, "VIDEO_SW_GENERATOR", &video_sw_generator_init, NULL,
&video_sw_generator_data_0, NULL, POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY,
&video_sw_generator_driver_api);
VIDEO_DEVICE_DEFINE(video_sw_generator, DEVICE_GET(video_sw_generator), NULL);
#define VIDEO_SW_GENERATOR_DEFINE(n) \
static struct video_sw_generator_data video_sw_generator_data_##n = { \
.fmt.width = 320, \
.fmt.height = 160, \
.fmt.pitch = 320 * 2, \
.fmt.pixelformat = VIDEO_PIX_FMT_RGB565, \
.frame_rate = DEFAULT_FRAME_RATE, \
}; \
\
DEVICE_DT_INST_DEFINE(n, &video_sw_generator_init, NULL, &video_sw_generator_data_##n, \
NULL, POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, \
&video_sw_generator_driver_api); \
\
VIDEO_DEVICE_DEFINE(video_sw_generator_##n, DEVICE_DT_INST_GET(n), NULL);
DT_INST_FOREACH_STATUS_OKAY(VIDEO_SW_GENERATOR_DEFINE)

6
dts/bindings/video/zephyr,video-sw-generator.yaml

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
# Copyright 2025 tinyVision.ai Inc.
# SPDX-License-Identifier: Apache-2.0
description: Emulated Video test pattern generator
compatible: "zephyr,video-sw-generator"

11
samples/drivers/video/capture/README.rst

@ -91,9 +91,16 @@ For :ref:`native_sim`, build this sample application with the following commands @@ -91,9 +91,16 @@ For :ref:`native_sim`, build this sample application with the following commands
:goals: build
:compact:
For testing purpose without the need of any real video capture and/or display hardwares,
For testing purpose and without the need of any real video capture and/or display hardwares,
a video software pattern generator is supported by the above build commands without
specifying the shields.
specifying the shields, and using :ref:`snippet-video-sw-generator`:
.. zephyr-app-commands::
:zephyr-app: samples/drivers/video/capture
:board: native_sim/native/64
:snippets: video-sw-generator
:goals: build
:compact:
For controlling the camera device using shell commands instead of continuously capturing the data,
append ``-DCONFIG_VIDEO_SHELL=y`` to the build command:

1
samples/drivers/video/capture/prj.conf

@ -1,5 +1,4 @@ @@ -1,5 +1,4 @@
CONFIG_VIDEO=y
CONFIG_VIDEO_SW_GENERATOR=y
CONFIG_SHELL=y
CONFIG_DEVICE_SHELL=y
CONFIG_PRINTK=y

2
samples/drivers/video/capture/sample.yaml

@ -45,6 +45,8 @@ tests: @@ -45,6 +45,8 @@ tests:
- CONFIG_VIDEO_SHELL=y
- CONFIG_FPU=y
- CONFIG_DISPLAY=n
extra_args:
- platform:native_sim/native/64:SNIPPET="video-sw-generator"
harness: console
harness_config:
type: one_line

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

@ -23,8 +23,6 @@ LOG_MODULE_REGISTER(main); @@ -23,8 +23,6 @@ LOG_MODULE_REGISTER(main);
#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
#endif
#define VIDEO_DEV_SW "VIDEO_SW_GENERATOR"
#if DT_HAS_CHOSEN(zephyr_display)
static inline int display_setup(const struct device *const display_dev, const uint32_t pixfmt)
{
@ -92,6 +90,7 @@ int main(void) @@ -92,6 +90,7 @@ int main(void)
{
struct video_buffer *buffers[CONFIG_VIDEO_BUFFER_POOL_NUM_MAX];
struct video_buffer *vbuf = &(struct video_buffer){};
const struct device *video_dev;
struct video_format fmt;
struct video_caps caps;
struct video_frmival frmival;
@ -108,21 +107,11 @@ int main(void) @@ -108,21 +107,11 @@ int main(void)
return 0;
}
#if DT_HAS_CHOSEN(zephyr_camera)
const struct device *const video_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_camera));
video_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_camera));
if (!device_is_ready(video_dev)) {
LOG_ERR("%s: video device is not ready", video_dev->name);
return 0;
}
#else
const struct device *const video_dev = device_get_binding(VIDEO_DEV_SW);
if (video_dev == NULL) {
LOG_ERR("%s: video device not found or failed to initialized", VIDEO_DEV_SW);
return 0;
}
#endif
LOG_INF("Video device: %s", video_dev->name);

10
samples/drivers/video/capture_to_lvgl/README.rst

@ -37,6 +37,16 @@ For :zephyr:board:`mini_stm32h743`, build this sample application with the follo @@ -37,6 +37,16 @@ For :zephyr:board:`mini_stm32h743`, build this sample application with the follo
:gen-args: -DCONFIG_BOOT_DELAY=2000
:compact:
For testing purpose and without the need of any real video capture hardware,
a video software pattern generator is supported by using :ref:`snippet-video-sw-generator`:
.. zephyr-app-commands::
:zephyr-app: samples/drivers/video/capture
:board: native_sim/native/64
:snippets: video-sw-generator
:goals: build
:compact:
Sample Output
=============

1
samples/drivers/video/capture_to_lvgl/prj.conf

@ -1,5 +1,4 @@ @@ -1,5 +1,4 @@
CONFIG_VIDEO=y
CONFIG_VIDEO_SW_GENERATOR=y
CONFIG_PRINTK=y
CONFIG_LOG=y

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

@ -15,17 +15,15 @@ @@ -15,17 +15,15 @@
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(main);
#define VIDEO_DEV_SW "VIDEO_SW_GENERATOR"
int main(void)
{
struct video_buffer *buffers[2];
struct video_buffer *vbuf = &(struct video_buffer){};
const struct device *display_dev;
const struct device *video_dev;
struct video_format fmt;
struct video_caps caps;
enum video_buf_type type = VIDEO_BUF_TYPE_OUTPUT;
const struct device *video_dev;
size_t bsize;
int i = 0;
@ -35,19 +33,11 @@ int main(void) @@ -35,19 +33,11 @@ int main(void)
return 0;
}
#if DT_HAS_CHOSEN(zephyr_camera)
video_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_camera));
if (!device_is_ready(video_dev)) {
LOG_ERR("%s device is not ready", video_dev->name);
return 0;
}
#else
video_dev = device_get_binding(VIDEO_DEV_SW);
if (video_dev == NULL) {
LOG_ERR("%s device not found", VIDEO_DEV_SW);
return 0;
}
#endif
LOG_INF("- Device name: %s", video_dev->name);

10
samples/drivers/video/tcpserversink/README.rst

@ -39,6 +39,16 @@ If a mt9m114 camera shield is missing, video software generator will be used ins @@ -39,6 +39,16 @@ If a mt9m114 camera shield is missing, video software generator will be used ins
:goals: build
:compact:
For testing purpose and without the need of any real video capture hardware,
a video software pattern generator is supported by using :ref:`snippet-video-sw-generator`:
.. zephyr-app-commands::
:zephyr-app: samples/drivers/video/capture
:board: native_sim/native/64
:snippets: video-sw-generator
:goals: build
:compact:
Sample Output
=============

1
samples/drivers/video/tcpserversink/prj.conf

@ -40,4 +40,3 @@ CONFIG_NET_CONFIG_SETTINGS=y @@ -40,4 +40,3 @@ CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
CONFIG_VIDEO=y
CONFIG_VIDEO_SW_GENERATOR=y

12
samples/drivers/video/tcpserversink/src/main.c

@ -15,7 +15,6 @@ @@ -15,7 +15,6 @@
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(main);
#define VIDEO_DEV_SW "VIDEO_SW_GENERATOR"
#define MY_PORT 5000
#define MAX_CLIENT_QUEUE 1
@ -44,21 +43,14 @@ int main(void) @@ -44,21 +43,14 @@ int main(void)
struct video_format fmt;
struct video_caps caps;
enum video_buf_type type = VIDEO_BUF_TYPE_OUTPUT;
#if DT_HAS_CHOSEN(zephyr_camera)
const struct device *const video = DEVICE_DT_GET(DT_CHOSEN(zephyr_camera));
const struct device *video;
video = DEVICE_DT_GET(DT_CHOSEN(zephyr_camera));
if (!device_is_ready(video)) {
LOG_ERR("%s: video device not ready.", video->name);
return 0;
}
#else
const struct device *const video = device_get_binding(VIDEO_DEV_SW);
if (video == NULL) {
LOG_ERR("%s: video device not found or failed to initialized.", VIDEO_DEV_SW);
return 0;
}
#endif
/* Prepare Network */
(void)memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;

20
snippets/video-sw-generator/README.rst

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
.. _snippet-video-sw-generator:
Video Software Generator Snippet (video-sw-generator)
#####################################################
.. code-block:: console
west build -S video-sw-generator [...]
Overview
********
This snippet instantiate a fake video source generating a test pattern continuously
for test purpose. It is selected as the ``zephyr,camera`` :ref:`devicetree` chosen node.
Requirements
************
No hardware support is required besides sufficient memory for the video resolution
declared by :kconfig:option:`CONFIG_VIDEO_BUFFER_POOL_SZ_MAX`.

3
snippets/video-sw-generator/snippet.yml

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
name: video-sw-generator
append:
EXTRA_DTC_OVERLAY_FILE: video-sw-generator.overlay

14
snippets/video-sw-generator/video-sw-generator.overlay

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
/*
* Copyright The Zephyr Project Contributors
* SPDX-License-Identifier: Apache-2.0
*/
/ {
chosen {
zephyr,camera = &video_sw_generator;
};
video_sw_generator: video-sw-generator {
compatible = "zephyr,video-sw-generator";
};
};
Loading…
Cancel
Save