Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
video.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Linaro Limited.
3 * Copyright 2025 NXP
4 * Copyright (c) 2025 STMicroelectronics
5 * SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
14
15#ifndef ZEPHYR_INCLUDE_DRIVERS_VIDEO_H
16#define ZEPHYR_INCLUDE_DRIVERS_VIDEO_H
17
26
27#include <stddef.h>
28#include <stdint.h>
29
30#include <zephyr/device.h>
31#include <zephyr/kernel.h>
32#include <zephyr/sys/dlist.h>
33#include <zephyr/types.h>
34#include <zephyr/video/video.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
48 const struct device *dev;
50 const struct device *src_dev;
53};
54
62struct video_device *video_find_vdev(const struct device *dev);
63
70
72#define VIDEO_CTRL_FLAG_READ_ONLY BIT(0)
74#define VIDEO_CTRL_FLAG_WRITE_ONLY BIT(1)
76#define VIDEO_CTRL_FLAG_VOLATILE BIT(2)
78#define VIDEO_CTRL_FLAG_INACTIVE BIT(3)
80#define VIDEO_CTRL_FLAG_UPDATE BIT(4)
81
101
118
120 const struct video_device *vdev;
126 unsigned long flags;
130 union {
135 };
137 union {
139 const char *const *menu;
142 };
145};
146
150
155
160typedef int (*video_api_format_t)(const struct device *dev, struct video_format *fmt);
161
166typedef int (*video_api_frmival_t)(const struct device *dev, struct video_frmival *frmival);
167
172typedef int (*video_api_enum_frmival_t)(const struct device *dev, struct video_frmival_enum *fie);
173
178typedef int (*video_api_enqueue_t)(const struct device *dev, struct video_buffer *buf);
179
184typedef int (*video_api_dequeue_t)(const struct device *dev, struct video_buffer **buf,
185 k_timeout_t timeout);
186
191typedef int (*video_api_flush_t)(const struct device *dev, bool cancel);
192
197typedef int (*video_api_set_stream_t)(const struct device *dev, bool enable,
198 enum video_buf_type type);
199
204typedef int (*video_api_ctrl_t)(const struct device *dev, uint32_t cid);
205
210typedef int (*video_api_get_caps_t)(const struct device *dev, struct video_caps *caps);
211
216typedef int (*video_api_transform_cap_t)(const struct device *const dev,
217 const struct video_format_cap *const cap,
218 struct video_format_cap *const res_cap,
219 enum video_buf_type type, uint16_t ind);
220
225typedef int (*video_api_set_signal_t)(const struct device *dev, struct k_poll_signal *sig);
226
231typedef int (*video_api_selection_t)(const struct device *dev, struct video_selection *sel);
232
302
306
319static inline int video_driver_set_format(const struct device *dev, struct video_format *fmt)
320{
321 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
322
323 if (api->set_format == NULL) {
324 return -ENOSYS;
325 }
326
327 return api->set_format(dev, fmt);
328}
329
341static inline int video_driver_get_format(const struct device *dev, struct video_format *fmt)
342{
343 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
344
345 if (api->get_format == NULL) {
346 return -ENOSYS;
347 }
348
349 return api->get_format(dev, fmt);
350}
351
364static inline int video_driver_set_frmival(const struct device *dev, struct video_frmival *frmival)
365{
366 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
367
368 if (api->set_frmival == NULL) {
369 return -ENOSYS;
370 }
371
372 return api->set_frmival(dev, frmival);
373}
374
386static inline int video_driver_get_frmival(const struct device *dev, struct video_frmival *frmival)
387{
388 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
389
390 if (api->get_frmival == NULL) {
391 return -ENOSYS;
392 }
393
394 return api->get_frmival(dev, frmival);
395}
396
412static inline int video_driver_enum_frmival(const struct device *dev,
413 struct video_frmival_enum *fie)
414{
415 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
416
417 if (api->enum_frmival == NULL) {
418 return -ENOSYS;
419 }
420
421 return api->enum_frmival(dev, fie);
422}
423
436static inline int video_driver_enqueue(const struct device *dev, struct video_buffer *vbuf)
437{
438 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
439
440 if (api->enqueue == NULL) {
441 return -ENOSYS;
442 }
443
444 return api->enqueue(dev, vbuf);
445}
446
460static inline int video_driver_dequeue(const struct device *dev, struct video_buffer **vbuf,
461 k_timeout_t timeout)
462{
463 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
464
465 if (api->dequeue == NULL) {
466 return -ENOSYS;
467 }
468
469 return api->dequeue(dev, vbuf, timeout);
470}
471
486static inline int video_driver_flush(const struct device *dev, bool cancel)
487{
488 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
489
490 if (api->flush == NULL) {
491 return -ENOSYS;
492 }
493
494 return api->flush(dev, cancel);
495}
496
509static inline int video_driver_set_stream(const struct device *dev, bool enable,
510 enum video_buf_type type)
511{
512 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
513
514 if (api->set_stream == NULL) {
515 return -ENOSYS;
516 }
517
518 return api->set_stream(dev, enable, type);
519}
520
533static inline int video_driver_get_volatile_ctrl(const struct device *dev, uint32_t cid)
534{
535 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
536
537 if (api->get_volatile_ctrl == NULL) {
538 return -ENOSYS;
539 }
540
541 return api->get_volatile_ctrl(dev, cid);
542}
543
556static inline int video_driver_set_ctrl(const struct device *dev, uint32_t cid)
557{
558 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
559
560 if (api->set_ctrl == NULL) {
561 return -ENOSYS;
562 }
563
564 return api->set_ctrl(dev, cid);
565}
566
576static inline int video_driver_get_caps(const struct device *dev, struct video_caps *caps)
577{
578 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
579
580 if (api->get_caps == NULL) {
581 return -ENOSYS;
582 }
583
584 return api->get_caps(dev, caps);
585}
586
602static inline int video_driver_transform_cap(const struct device *const dev,
603 const struct video_format_cap *const cap,
604 struct video_format_cap *const res_cap,
605 enum video_buf_type type, uint16_t ind)
606{
607 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
608
609 if (api->transform_cap == NULL) {
610 return -ENOSYS;
611 }
612
613 return api->transform_cap(dev, cap, res_cap, type, ind);
614}
615
629static inline int video_driver_set_signal(const struct device *dev, struct k_poll_signal *sig)
630{
631 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
632
633 if (api->set_signal == NULL) {
634 return -ENOSYS;
635 }
636
637 return api->set_signal(dev, sig);
638}
639
657static inline int video_driver_set_selection(const struct device *dev, struct video_selection *sel)
658{
659 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
660
661 if (api->set_selection == NULL) {
662 return -ENOSYS;
663 }
664
665 return api->set_selection(dev, sel);
666}
667
684static inline int video_driver_get_selection(const struct device *dev, struct video_selection *sel)
685{
686 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
687
688 if (api->get_selection == NULL) {
689 return -ENOSYS;
690 }
691
692 return api->get_selection(dev, sel);
693}
694
705
707#define VIDEO_MIPI_CSI2_DT_NULL 0x10
709#define VIDEO_MIPI_CSI2_DT_BLANKING 0x11
711#define VIDEO_MIPI_CSI2_DT_EMBEDDED_8 0x12
713#define VIDEO_MIPI_CSI2_DT_YUV420_8 0x18
715#define VIDEO_MIPI_CSI2_DT_YUV420_10 0x19
717#define VIDEO_MIPI_CSI2_DT_YUV420_CSPS_8 0x1c
719#define VIDEO_MIPI_CSI2_DT_YUV420_CSPS_10 0x1d
721#define VIDEO_MIPI_CSI2_DT_YUV422_8 0x1e
723#define VIDEO_MIPI_CSI2_DT_YUV422_10 0x1f
725#define VIDEO_MIPI_CSI2_DT_RGB444 0x20
727#define VIDEO_MIPI_CSI2_DT_RGB555 0x21
729#define VIDEO_MIPI_CSI2_DT_RGB565 0x22
731#define VIDEO_MIPI_CSI2_DT_RGB666 0x23
733#define VIDEO_MIPI_CSI2_DT_RGB888 0x24
735#define VIDEO_MIPI_CSI2_DT_RAW6 0x28
737#define VIDEO_MIPI_CSI2_DT_RAW7 0x29
739#define VIDEO_MIPI_CSI2_DT_RAW8 0x2a
741#define VIDEO_MIPI_CSI2_DT_RAW10 0x2b
743#define VIDEO_MIPI_CSI2_DT_RAW12 0x2c
745#define VIDEO_MIPI_CSI2_DT_RAW14 0x2d
746
797
809#define VIDEO_MIPI_CSI2_DT_USER(n) (0x30 + (n))
810
814
815#ifdef __cplusplus
816}
817#endif
818
822
823#endif /* ZEPHYR_INCLUDE_DRIVERS_VIDEO_H */
APIs and macros for the Zephyr device model.
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1505
Header file for the doubly-linked list API.
struct _dnode sys_dnode_t
Doubly-linked list node structure.
Definition dlist.h:59
struct _dnode sys_dlist_t
Doubly-linked list structure.
Definition dlist.h:55
#define ENOSYS
Function not implemented.
Definition errno.h:83
#define VIDEO_PIX_FMT_SGRBG12P
Definition formats.h:323
#define VIDEO_PIX_FMT_RGB24
24 bit RGB format with 8 bit per component
Definition formats.h:842
#define VIDEO_PIX_FMT_SGRBG8
Definition formats.h:469
#define VIDEO_PIX_FMT_Y12P
Definition formats.h:746
#define VIDEO_PIX_FMT_SRGGB12P
Definition formats.h:332
#define VIDEO_PIX_FMT_SBGGR10P
Definition formats.h:269
#define VIDEO_PIX_FMT_Y10P
Definition formats.h:737
#define VIDEO_PIX_FMT_SRGGB10P
Definition formats.h:296
#define VIDEO_PIX_FMT_SRGGB14P
Definition formats.h:368
#define VIDEO_PIX_FMT_SGBRG14P
Definition formats.h:350
#define VIDEO_PIX_FMT_SGRBG10P
Definition formats.h:287
#define VIDEO_PIX_FMT_GREY
Same as Y8 (8-bit luma-only) following the standard FOURCC naming, or L8 in some graphics libraries.
Definition formats.h:659
#define VIDEO_PIX_FMT_SGBRG8
Definition formats.h:460
#define VIDEO_PIX_FMT_SBGGR12P
Definition formats.h:305
#define VIDEO_PIX_FMT_SBGGR8
Definition formats.h:451
#define VIDEO_PIX_FMT_SRGGB8
Definition formats.h:478
#define VIDEO_PIX_FMT_SBGGR14P
Definition formats.h:341
#define VIDEO_PIX_FMT_SGBRG10P
Definition formats.h:278
#define VIDEO_PIX_FMT_Y14P
Definition formats.h:755
#define VIDEO_PIX_FMT_UYVY
Definition formats.h:1038
#define VIDEO_PIX_FMT_SGRBG14P
Definition formats.h:359
#define VIDEO_PIX_FMT_SGBRG12P
Definition formats.h:314
#define VIDEO_PIX_FMT_RGB565
5 red bits [15:11], 6 green bits [10:5], 5 blue bits [4:0].
Definition formats.h:812
int(* video_api_enum_frmival_t)(const struct device *dev, struct video_frmival_enum *fie)
Callback API to enumerate supported frame intervals for a format.
Definition video.h:172
int(* video_api_get_caps_t)(const struct device *dev, struct video_caps *caps)
Callback API to get capabilities of a video endpoint.
Definition video.h:210
int(* video_api_transform_cap_t)(const struct device *const dev, const struct video_format_cap *const cap, struct video_format_cap *const res_cap, enum video_buf_type type, uint16_t ind)
Callback API to transform a format capability across m2m device endpoints.
Definition video.h:216
int(* video_api_dequeue_t)(const struct device *dev, struct video_buffer **buf, k_timeout_t timeout)
Callback API to dequeue a buffer from the driver outgoing queue.
Definition video.h:184
int(* video_api_ctrl_t)(const struct device *dev, uint32_t cid)
Callback API to set or get a video control value.
Definition video.h:204
int(* video_api_format_t)(const struct device *dev, struct video_format *fmt)
Callback API to set or get video format.
Definition video.h:160
int(* video_api_flush_t)(const struct device *dev, bool cancel)
Callback API to flush endpoint buffers.
Definition video.h:191
int(* video_api_selection_t)(const struct device *dev, struct video_selection *sel)
Callback API to set or get video selection (crop/compose).
Definition video.h:231
int(* video_api_set_stream_t)(const struct device *dev, bool enable, enum video_buf_type type)
Callback API to control stream status.
Definition video.h:197
int(* video_api_set_signal_t)(const struct device *dev, struct k_poll_signal *sig)
Callback API to register or unregister poll signal for buffer events.
Definition video.h:225
int(* video_api_enqueue_t)(const struct device *dev, struct video_buffer *buf)
Callback API to enqueue a buffer in the driver incoming queue.
Definition video.h:178
int(* video_api_frmival_t)(const struct device *dev, struct video_frmival *frmival)
Callback API to set or get video frame interval.
Definition video.h:166
video_ctrl_type
Type of video control.
Definition video.h:87
@ VIDEO_CTRL_TYPE_MENU
Menu string type, standard or driver-defined menu.
Definition video.h:95
@ VIDEO_CTRL_TYPE_STRING
String type.
Definition video.h:97
@ VIDEO_CTRL_TYPE_INTEGER
Integer type.
Definition video.h:91
@ VIDEO_CTRL_TYPE_INTEGER_MENU
Menu integer type, standard or driver-defined menu.
Definition video.h:99
@ VIDEO_CTRL_TYPE_BOOLEAN
Boolean type.
Definition video.h:89
@ VIDEO_CTRL_TYPE_INTEGER64
64-bit integer type
Definition video.h:93
#define VIDEO_MIPI_CSI2_DT_RGB888
RGB format with 8 bits per color component.
Definition video.h:733
static int video_driver_get_volatile_ctrl(const struct device *dev, uint32_t cid)
Get a volatile video control value of a driver.
Definition video.h:533
#define VIDEO_MIPI_CSI2_DT_YUV422_8
YUV 4:2:2 format with 8 bits per component.
Definition video.h:721
static int video_driver_get_selection(const struct device *dev, struct video_selection *sel)
Get video selection (crop/compose).
Definition video.h:684
static int video_driver_set_ctrl(const struct device *dev, uint32_t cid)
Set a video control value of a driver.
Definition video.h:556
static int video_driver_transform_cap(const struct device *const dev, const struct video_format_cap *const cap, struct video_format_cap *const res_cap, enum video_buf_type type, uint16_t ind)
Transform a video format capability from one end to the other end of a m2m video device.
Definition video.h:602
static int video_driver_enum_frmival(const struct device *dev, struct video_frmival_enum *fie)
List video frame intervals.
Definition video.h:412
#define VIDEO_MIPI_CSI2_DT_RAW14
Raw sensor data with 14 bits per pixel.
Definition video.h:745
struct video_device * video_find_vdev(const struct device *dev)
Find the video_device associated with a video device.
static int video_driver_get_frmival(const struct device *dev, struct video_frmival *frmival)
Get video frame interval of a driver.
Definition video.h:386
static int video_driver_set_frmival(const struct device *dev, struct video_frmival *frmival)
Apply a video frame interval to a driver.
Definition video.h:364
#define VIDEO_MIPI_CSI2_DT_NULL
NULL data type - used for padding or synchronization.
Definition video.h:707
#define VIDEO_MIPI_CSI2_DT_RAW10
Raw sensor data with 10 bits per pixel.
Definition video.h:741
#define VIDEO_MIPI_CSI2_DT_RAW8
Raw sensor data with 8 bits per pixel.
Definition video.h:739
static int video_driver_set_signal(const struct device *dev, struct k_poll_signal *sig)
Register/Unregister k_poll signal for a video endpoint.
Definition video.h:629
static int video_driver_get_caps(const struct device *dev, struct video_caps *caps)
Get the capabilities of a video driver endpoint.
Definition video.h:576
static int video_driver_set_stream(const struct device *dev, bool enable, enum video_buf_type type)
Start or stop the video driver function.
Definition video.h:509
static int video_driver_flush(const struct device *dev, bool cancel)
Flush endpoint buffers from a driver.
Definition video.h:486
static int video_driver_set_format(const struct device *dev, struct video_format *fmt)
Set video format of a driver.
Definition video.h:319
static int video_driver_dequeue(const struct device *dev, struct video_buffer **vbuf, k_timeout_t timeout)
Dequeue a video buffer from a driver.
Definition video.h:460
static int video_driver_get_format(const struct device *dev, struct video_format *fmt)
Get video format of a driver.
Definition video.h:341
static uint8_t video_mipi_data_type(uint32_t pixfmt)
Map pixel formats to their MIPI data type equivalent.
Definition video.h:760
#define VIDEO_MIPI_CSI2_DT_RGB565
RGB format with 5-6-5 bits per R-G-B components.
Definition video.h:729
#define VIDEO_MIPI_CSI2_DT_RAW12
Raw sensor data with 12 bits per pixel.
Definition video.h:743
static int video_driver_enqueue(const struct device *dev, struct video_buffer *vbuf)
Pass a video buffer to a driver.
Definition video.h:436
static int video_driver_set_selection(const struct device *dev, struct video_selection *sel)
Set video selection (crop/compose).
Definition video.h:657
video_buf_type
video_buf_type enum
Definition types.h:42
Public kernel APIs.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
__INT64_TYPE__ int64_t
Definition stdint.h:75
Runtime device structure (in ROM) per driver instance.
Definition device.h:543
Poll signal object.
Definition kernel.h:7064
Kernel timeout type.
Definition clock.h:65
Video buffer structure.
Definition types.h:66
Video format capabilities.
Definition types.h:157
Video control range structure.
Definition types.h:175
Storage type for video controls.
Definition video.h:107
bool is_auto
Internal use for auto control handling.
Definition video.h:113
enum video_ctrl_type type
Type of the control.
Definition video.h:124
unsigned long flags
Flags associated with this control.
Definition video.h:126
uint8_t cluster_sz
Internal use for video control grouping.
Definition video.h:111
int64_t val64
Used for 64-bit control types.
Definition video.h:134
uint32_t id
Control ID, see Video Control IDs.
Definition video.h:122
const char *const * menu
Used for menu control types.
Definition video.h:139
int32_t val
Used for 32-bit control types.
Definition video.h:132
struct video_ctrl_range range
Acceptable range of values for this control.
Definition video.h:128
const int64_t * int_menu
Used for integer menu control types.
Definition video.h:141
const struct video_device * vdev
Video device associated with this control.
Definition video.h:120
bool has_volatiles
Internal use for volatile control handling.
Definition video.h:117
sys_dnode_t node
Node place this control in a list.
Definition video.h:144
struct video_ctrl * cluster
Internal use for video control grouping.
Definition video.h:109
int32_t manual_val
Internal use: value of the primary control that selects manual mode.
Definition video.h:115
Storage type for a wrapper type around a video device.
Definition video.h:46
const struct device * dev
Device held by this video device.
Definition video.h:48
const struct device * src_dev
Source device up in the chain, and providing the data.
Definition video.h:50
sys_dlist_t ctrls
List of video controls supported by this device.
Definition video.h:52
<span class="mlabel">Driver Operations</span> Video driver operations
Definition video.h:236
video_api_transform_cap_t transform_cap
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition video.h:300
video_api_format_t set_format
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition video.h:240
video_api_ctrl_t set_ctrl
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition video.h:268
video_api_enqueue_t enqueue
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition video.h:256
video_api_set_signal_t set_signal
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition video.h:276
video_api_enum_frmival_t enum_frmival
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition video.h:288
video_api_get_caps_t get_caps
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition video.h:252
video_api_selection_t get_selection
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition video.h:296
video_api_selection_t set_selection
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition video.h:292
video_api_format_t get_format
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition video.h:244
video_api_flush_t flush
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition video.h:264
video_api_dequeue_t dequeue
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition video.h:260
video_api_frmival_t get_frmival
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition video.h:284
video_api_frmival_t set_frmival
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition video.h:280
video_api_set_stream_t set_stream
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition video.h:248
video_api_ctrl_t get_volatile_ctrl
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition video.h:272
Video format capability.
Definition types.h:135
Video format structure.
Definition types.h:100
Video frame interval enumeration structure.
Definition types.h:341
Video frame interval structure.
Definition types.h:315
Video selection (crop / compose) structure.
Definition types.h:291
Public APIs for video.