From 9278dd17f8add4d2ef1cc9eee484aa90d6e018de Mon Sep 17 00:00:00 2001 From: Josuah Demangeon Date: Fri, 18 Apr 2025 20:43:45 +0000 Subject: [PATCH 1/6] samples: drivers: video: fix board definitions By having an "auto-fallback" mechanism, the VIDEO_SW_GENERATOR did shadow the fact that "platform:mimxrt1064_evk:SHIELD=dvp_fpc24_mt9m114" was missing the full specification, and therefore was not matched at all: the shield was not selected, but the CI still worked. Signed-off-by: Josuah Demangeon --- samples/drivers/video/capture/sample.yaml | 6 +++--- samples/drivers/video/tcpserversink/sample.yaml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/drivers/video/capture/sample.yaml b/samples/drivers/video/capture/sample.yaml index 3c0338daeeb0..40fb38bf46c0 100644 --- a/samples/drivers/video/capture/sample.yaml +++ b/samples/drivers/video/capture/sample.yaml @@ -7,7 +7,7 @@ tests: - shield - samples extra_args: - - platform:mimxrt1064_evk:SHIELD="dvp_fpc24_mt9m114;rk043fn66hs_ctg" + - platform:mimxrt1064_evk/mimxrt1064:SHIELD="dvp_fpc24_mt9m114;rk043fn66hs_ctg" - platform:mimxrt1170_evk/mimxrt1176/cm7:SHIELD="nxp_btb44_ov5640;rk055hdmipi4ma0" - platform:mimxrt1170_evk@B/mimxrt1176/cm7:SHIELD="nxp_btb44_ov5640;rk055hdmipi4ma0" - platform:frdm_mcxn947/mcxn947/cpu0:SHIELD="dvp_20pin_ov7670;lcd_par_s035_8080" @@ -26,7 +26,7 @@ tests: - "Pattern OK" platform_allow: - arduino_nicla_vision/stm32h747xx/m7 - - mimxrt1064_evk + - mimxrt1064_evk/mimxrt1064 - mimxrt1170_evk/mimxrt1176/cm7 - mimxrt1170_evk@B/mimxrt1176/cm7 - frdm_mcxn947/mcxn947/cpu0 @@ -34,7 +34,7 @@ tests: - esp32s3_eye/esp32s3/procpu depends_on: video integration_platforms: - - mimxrt1064_evk + - mimxrt1064_evk/mimxrt1064 - mimxrt1170_evk/mimxrt1176/cm7 sample.video.capture.shell: tags: diff --git a/samples/drivers/video/tcpserversink/sample.yaml b/samples/drivers/video/tcpserversink/sample.yaml index 717923a6fa19..9e9123b48c07 100644 --- a/samples/drivers/video/tcpserversink/sample.yaml +++ b/samples/drivers/video/tcpserversink/sample.yaml @@ -8,11 +8,11 @@ tests: - net - socket - shield - platform_allow: mimxrt1064_evk + platform_allow: mimxrt1064_evk/mimxrt1064 depends_on: - video - netif integration_platforms: - - mimxrt1064_evk + - mimxrt1064_evk/mimxrt1064 extra_args: - - platform:mimxrt1064_evk:SHIELD=dvp_fpc24_mt9m114 + - platform:mimxrt1064_evk/mimxrt1064:SHIELD=dvp_fpc24_mt9m114 From 298de6df0ae80bb04c4cf4a5007e3990d90a9c7d Mon Sep 17 00:00:00 2001 From: Josuah Demangeon Date: Fri, 18 Apr 2025 00:02:43 +0000 Subject: [PATCH 2/6] 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 --- drivers/video/Kconfig.sw_generator | 7 ++--- drivers/video/video_sw_generator.c | 31 ++++++++++--------- .../video/zephyr,video-sw-generator.yaml | 6 ++++ samples/drivers/video/capture/README.rst | 11 +++++-- samples/drivers/video/capture/prj.conf | 1 - samples/drivers/video/capture/sample.yaml | 2 ++ samples/drivers/video/capture/src/main.c | 15 ++------- .../drivers/video/capture_to_lvgl/README.rst | 10 ++++++ .../drivers/video/capture_to_lvgl/prj.conf | 1 - .../drivers/video/capture_to_lvgl/src/main.c | 12 +------ .../drivers/video/tcpserversink/README.rst | 10 ++++++ samples/drivers/video/tcpserversink/prj.conf | 1 - .../drivers/video/tcpserversink/src/main.c | 12 ++----- snippets/video-sw-generator/README.rst | 20 ++++++++++++ snippets/video-sw-generator/snippet.yml | 3 ++ .../video-sw-generator.overlay | 14 +++++++++ 16 files changed, 98 insertions(+), 58 deletions(-) create mode 100644 dts/bindings/video/zephyr,video-sw-generator.yaml create mode 100644 snippets/video-sw-generator/README.rst create mode 100644 snippets/video-sw-generator/snippet.yml create mode 100644 snippets/video-sw-generator/video-sw-generator.overlay diff --git a/drivers/video/Kconfig.sw_generator b/drivers/video/Kconfig.sw_generator index 7675908b4bc1..5090a2f46cf0 100644 --- a/drivers/video/Kconfig.sw_generator +++ b/drivers/video/Kconfig.sw_generator @@ -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). diff --git a/drivers/video/video_sw_generator.c b/drivers/video/video_sw_generator.c index d1db6a18a343..12c871fbc53c 100644 --- a/drivers/video/video_sw_generator.c +++ b/drivers/video/video_sw_generator.c @@ -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 #include @@ -455,14 +455,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; @@ -483,8 +475,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) diff --git a/dts/bindings/video/zephyr,video-sw-generator.yaml b/dts/bindings/video/zephyr,video-sw-generator.yaml new file mode 100644 index 000000000000..4c734c328ce5 --- /dev/null +++ b/dts/bindings/video/zephyr,video-sw-generator.yaml @@ -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" diff --git a/samples/drivers/video/capture/README.rst b/samples/drivers/video/capture/README.rst index 8216fdd46d9f..4acef0d17abe 100644 --- a/samples/drivers/video/capture/README.rst +++ b/samples/drivers/video/capture/README.rst @@ -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: diff --git a/samples/drivers/video/capture/prj.conf b/samples/drivers/video/capture/prj.conf index b96f5f78ed2b..f8b221d5a776 100644 --- a/samples/drivers/video/capture/prj.conf +++ b/samples/drivers/video/capture/prj.conf @@ -1,5 +1,4 @@ CONFIG_VIDEO=y -CONFIG_VIDEO_SW_GENERATOR=y CONFIG_SHELL=y CONFIG_DEVICE_SHELL=y CONFIG_PRINTK=y diff --git a/samples/drivers/video/capture/sample.yaml b/samples/drivers/video/capture/sample.yaml index 40fb38bf46c0..e52f26aa7cd1 100644 --- a/samples/drivers/video/capture/sample.yaml +++ b/samples/drivers/video/capture/sample.yaml @@ -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 diff --git a/samples/drivers/video/capture/src/main.c b/samples/drivers/video/capture/src/main.c index 19ed98e76ac5..295ab185b724 100644 --- a/samples/drivers/video/capture/src/main.c +++ b/samples/drivers/video/capture/src/main.c @@ -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) { 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) 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); diff --git a/samples/drivers/video/capture_to_lvgl/README.rst b/samples/drivers/video/capture_to_lvgl/README.rst index f3fa5e992ad3..7a93e63dccb3 100644 --- a/samples/drivers/video/capture_to_lvgl/README.rst +++ b/samples/drivers/video/capture_to_lvgl/README.rst @@ -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 ============= diff --git a/samples/drivers/video/capture_to_lvgl/prj.conf b/samples/drivers/video/capture_to_lvgl/prj.conf index 4a64bbaad53d..340f0b5a75af 100644 --- a/samples/drivers/video/capture_to_lvgl/prj.conf +++ b/samples/drivers/video/capture_to_lvgl/prj.conf @@ -1,5 +1,4 @@ CONFIG_VIDEO=y -CONFIG_VIDEO_SW_GENERATOR=y CONFIG_PRINTK=y CONFIG_LOG=y diff --git a/samples/drivers/video/capture_to_lvgl/src/main.c b/samples/drivers/video/capture_to_lvgl/src/main.c index b56872dacb76..83d1904f6aeb 100644 --- a/samples/drivers/video/capture_to_lvgl/src/main.c +++ b/samples/drivers/video/capture_to_lvgl/src/main.c @@ -15,17 +15,15 @@ #include 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) 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); diff --git a/samples/drivers/video/tcpserversink/README.rst b/samples/drivers/video/tcpserversink/README.rst index 8245edea4c45..b44d9f3105ad 100644 --- a/samples/drivers/video/tcpserversink/README.rst +++ b/samples/drivers/video/tcpserversink/README.rst @@ -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 ============= diff --git a/samples/drivers/video/tcpserversink/prj.conf b/samples/drivers/video/tcpserversink/prj.conf index 824c424b2fa8..a49aa3de90ff 100644 --- a/samples/drivers/video/tcpserversink/prj.conf +++ b/samples/drivers/video/tcpserversink/prj.conf @@ -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 diff --git a/samples/drivers/video/tcpserversink/src/main.c b/samples/drivers/video/tcpserversink/src/main.c index 05c190013ad0..fe968373b661 100644 --- a/samples/drivers/video/tcpserversink/src/main.c +++ b/samples/drivers/video/tcpserversink/src/main.c @@ -15,7 +15,6 @@ #include 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) 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; diff --git a/snippets/video-sw-generator/README.rst b/snippets/video-sw-generator/README.rst new file mode 100644 index 000000000000..0169cfc2ece3 --- /dev/null +++ b/snippets/video-sw-generator/README.rst @@ -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`. diff --git a/snippets/video-sw-generator/snippet.yml b/snippets/video-sw-generator/snippet.yml new file mode 100644 index 000000000000..3d494e24c4f1 --- /dev/null +++ b/snippets/video-sw-generator/snippet.yml @@ -0,0 +1,3 @@ +name: video-sw-generator +append: + EXTRA_DTC_OVERLAY_FILE: video-sw-generator.overlay diff --git a/snippets/video-sw-generator/video-sw-generator.overlay b/snippets/video-sw-generator/video-sw-generator.overlay new file mode 100644 index 000000000000..29ff28f93e03 --- /dev/null +++ b/snippets/video-sw-generator/video-sw-generator.overlay @@ -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"; + }; +}; From 237512bb670e060ac24fa9eb05774e49b5e5a774 Mon Sep 17 00:00:00 2001 From: Josuah Demangeon Date: Fri, 18 Apr 2025 00:49:44 +0000 Subject: [PATCH 3/6] samples: drivers: video: convert to new LOG_MODULE_REGISTER() syntax Convert the log module declarationto the new syntax introduced in 5e34681 proposing a more compact syntax. This fixes the log level not being updated in the "capture" sample. Signed-off-by: Josuah Demangeon --- samples/drivers/video/capture/src/main.c | 5 ++--- samples/drivers/video/capture_to_lvgl/src/main.c | 5 ++--- samples/drivers/video/tcpserversink/src/main.c | 7 ++----- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/samples/drivers/video/capture/src/main.c b/samples/drivers/video/capture/src/main.c index 295ab185b724..81688fe159f0 100644 --- a/samples/drivers/video/capture/src/main.c +++ b/samples/drivers/video/capture/src/main.c @@ -13,14 +13,13 @@ #include #include -LOG_MODULE_REGISTER(main); #ifdef CONFIG_TEST #include "check_test_pattern.h" -#define LOG_LEVEL LOG_LEVEL_DBG +LOG_MODULE_REGISTER(main, LOG_LEVEL_DBG); #else -#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL +LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL); #endif #if DT_HAS_CHOSEN(zephyr_display) diff --git a/samples/drivers/video/capture_to_lvgl/src/main.c b/samples/drivers/video/capture_to_lvgl/src/main.c index 83d1904f6aeb..55f03d9f2722 100644 --- a/samples/drivers/video/capture_to_lvgl/src/main.c +++ b/samples/drivers/video/capture_to_lvgl/src/main.c @@ -9,11 +9,10 @@ #include #include #include +#include #include -#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL -#include -LOG_MODULE_REGISTER(main); +LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL); int main(void) { diff --git a/samples/drivers/video/tcpserversink/src/main.c b/samples/drivers/video/tcpserversink/src/main.c index fe968373b661..e5da5218d0d2 100644 --- a/samples/drivers/video/tcpserversink/src/main.c +++ b/samples/drivers/video/tcpserversink/src/main.c @@ -6,14 +6,11 @@ #include #include - #include - #include - -#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL #include -LOG_MODULE_REGISTER(main); + +LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL); #define MY_PORT 5000 #define MAX_CLIENT_QUEUE 1 From 0fcc13e1ef287a323d0880c7beae6ab96e690264 Mon Sep 17 00:00:00 2001 From: Josuah Demangeon Date: Mon, 19 May 2025 19:42:08 +0000 Subject: [PATCH 4/6] samples: drivers: video: tcpserversink: sort header alphabetically Since this sample's headers are now grouped it is possible to sort them alphabetically. Signed-off-by: Josuah Demangeon --- samples/drivers/video/tcpserversink/src/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/drivers/video/tcpserversink/src/main.c b/samples/drivers/video/tcpserversink/src/main.c index e5da5218d0d2..b5f1bbe2544c 100644 --- a/samples/drivers/video/tcpserversink/src/main.c +++ b/samples/drivers/video/tcpserversink/src/main.c @@ -4,11 +4,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include #include -#include #include +#include #include +#include LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL); From b79b8740d50d99597be706679af525d71a046c28 Mon Sep 17 00:00:00 2001 From: Josuah Demangeon Date: Fri, 18 Apr 2025 01:02:05 +0000 Subject: [PATCH 5/6] samples: drivers: video: tcpserversink: add _dev suffix to variable Variables that holds pointers to 'const struct device' typically end-up with '_dev'. The tcpserversink video sample did not have it. Add it. Signed-off-by: Josuah Demangeon --- .../drivers/video/tcpserversink/src/main.c | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/samples/drivers/video/tcpserversink/src/main.c b/samples/drivers/video/tcpserversink/src/main.c index b5f1bbe2544c..640a728f64ee 100644 --- a/samples/drivers/video/tcpserversink/src/main.c +++ b/samples/drivers/video/tcpserversink/src/main.c @@ -40,11 +40,11 @@ int main(void) struct video_format fmt; struct video_caps caps; enum video_buf_type type = VIDEO_BUF_TYPE_OUTPUT; - const struct device *video; + const struct device *video_dev; - video = DEVICE_DT_GET(DT_CHOSEN(zephyr_camera)); - if (!device_is_ready(video)) { - LOG_ERR("%s: video device not ready.", video->name); + video_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_camera)); + if (!device_is_ready(video_dev)) { + LOG_ERR("%s: video device not ready.", video_dev->name); return 0; } @@ -75,14 +75,14 @@ int main(void) /* Get capabilities */ caps.type = type; - if (video_get_caps(video, &caps)) { + if (video_get_caps(video_dev, &caps)) { LOG_ERR("Unable to retrieve video capabilities"); return 0; } /* Get default/native format */ fmt.type = type; - if (video_get_format(video, &fmt)) { + if (video_get_format(video_dev, &fmt)) { LOG_ERR("Unable to retrieve video format"); return 0; } @@ -119,11 +119,11 @@ int main(void) /* Enqueue Buffers */ for (i = 0; i < ARRAY_SIZE(buffers); i++) { - video_enqueue(video, buffers[i]); + video_enqueue(video_dev, buffers[i]); } /* Start video capture */ - if (video_stream_start(video, type)) { + if (video_stream_start(video_dev, type)) { LOG_ERR("Unable to start video"); return 0; } @@ -134,7 +134,7 @@ int main(void) i = 0; vbuf->type = type; do { - ret = video_dequeue(video, &vbuf, K_FOREVER); + ret = video_dequeue(video_dev, &vbuf, K_FOREVER); if (ret) { LOG_ERR("Unable to dequeue video buf"); return 0; @@ -150,18 +150,18 @@ int main(void) close(client); } - (void)video_enqueue(video, vbuf); + (void)video_enqueue(video_dev, vbuf); } while (!ret); /* stop capture */ - if (video_stream_stop(video, type)) { + if (video_stream_stop(video_dev, type)) { LOG_ERR("Unable to stop video"); return 0; } /* Flush remaining buffers */ do { - ret = video_dequeue(video, &vbuf, K_NO_WAIT); + ret = video_dequeue(video_dev, &vbuf, K_NO_WAIT); } while (!ret); } while (1); From d845bd22338bda262c75bb5d2b8f18fd705a568b Mon Sep 17 00:00:00 2001 From: Josuah Demangeon Date: Fri, 18 Apr 2025 01:09:37 +0000 Subject: [PATCH 6/6] doc: build: dts: api: document the zephyr,camera chosen node The zephyr,camera was used in several samples, but was not documented. Add the missing documentation entry for it in the list. Signed-off-by: Josuah Demangeon --- doc/build/dts/api/api.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/build/dts/api/api.rst b/doc/build/dts/api/api.rst index 6fe1fb7fd1bc..ffa56e5ce5ae 100644 --- a/doc/build/dts/api/api.rst +++ b/doc/build/dts/api/api.rst @@ -388,6 +388,8 @@ device. - Sets UART device used for the Bluetooth monitor logging * - zephyr,bt-hci - Selects the HCI device used by the Bluetooth host stack + * - zephyr,camera + - Video input device, typically a camera. * - zephyr,canbus - Sets the default CAN controller * - zephyr,ccm