Zephyr Project API 4.4.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
116
118 const struct video_device *vdev;
124 unsigned long flags;
128 union {
133 };
135 union {
137 const char *const *menu;
140 };
143};
144
148
153
158typedef int (*video_api_format_t)(const struct device *dev, struct video_format *fmt);
159
164typedef int (*video_api_frmival_t)(const struct device *dev, struct video_frmival *frmival);
165
170typedef int (*video_api_enum_frmival_t)(const struct device *dev, struct video_frmival_enum *fie);
171
176typedef int (*video_api_enqueue_t)(const struct device *dev, struct video_buffer *buf);
177
182typedef int (*video_api_dequeue_t)(const struct device *dev, struct video_buffer **buf,
183 k_timeout_t timeout);
184
189typedef int (*video_api_flush_t)(const struct device *dev, bool cancel);
190
195typedef int (*video_api_set_stream_t)(const struct device *dev, bool enable,
196 enum video_buf_type type);
197
202typedef int (*video_api_ctrl_t)(const struct device *dev, uint32_t cid);
203
208typedef int (*video_api_get_caps_t)(const struct device *dev, struct video_caps *caps);
209
214typedef int (*video_api_transform_cap_t)(const struct device *const dev,
215 const struct video_format_cap *const cap,
216 struct video_format_cap *const res_cap,
217 enum video_buf_type type, uint16_t ind);
218
223typedef int (*video_api_set_signal_t)(const struct device *dev, struct k_poll_signal *sig);
224
229typedef int (*video_api_selection_t)(const struct device *dev, struct video_selection *sel);
230
300
304
317static inline int video_driver_set_format(const struct device *dev, struct video_format *fmt)
318{
319 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
320
321 if (api->set_format == NULL) {
322 return -ENOSYS;
323 }
324
325 return api->set_format(dev, fmt);
326}
327
339static inline int video_driver_get_format(const struct device *dev, struct video_format *fmt)
340{
341 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
342
343 if (api->get_format == NULL) {
344 return -ENOSYS;
345 }
346
347 return api->get_format(dev, fmt);
348}
349
362static inline int video_driver_set_frmival(const struct device *dev, struct video_frmival *frmival)
363{
364 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
365
366 if (api->set_frmival == NULL) {
367 return -ENOSYS;
368 }
369
370 return api->set_frmival(dev, frmival);
371}
372
384static inline int video_driver_get_frmival(const struct device *dev, struct video_frmival *frmival)
385{
386 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
387
388 if (api->get_frmival == NULL) {
389 return -ENOSYS;
390 }
391
392 return api->get_frmival(dev, frmival);
393}
394
410static inline int video_driver_enum_frmival(const struct device *dev,
411 struct video_frmival_enum *fie)
412{
413 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
414
415 if (api->enum_frmival == NULL) {
416 return -ENOSYS;
417 }
418
419 return api->enum_frmival(dev, fie);
420}
421
434static inline int video_driver_enqueue(const struct device *dev, struct video_buffer *vbuf)
435{
436 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
437
438 if (api->enqueue == NULL) {
439 return -ENOSYS;
440 }
441
442 return api->enqueue(dev, vbuf);
443}
444
458static inline int video_driver_dequeue(const struct device *dev, struct video_buffer **vbuf,
459 k_timeout_t timeout)
460{
461 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
462
463 if (api->dequeue == NULL) {
464 return -ENOSYS;
465 }
466
467 return api->dequeue(dev, vbuf, timeout);
468}
469
484static inline int video_driver_flush(const struct device *dev, bool cancel)
485{
486 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
487
488 if (api->flush == NULL) {
489 return -ENOSYS;
490 }
491
492 return api->flush(dev, cancel);
493}
494
507static inline int video_driver_set_stream(const struct device *dev, bool enable,
508 enum video_buf_type type)
509{
510 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
511
512 if (api->set_stream == NULL) {
513 return -ENOSYS;
514 }
515
516 return api->set_stream(dev, enable, type);
517}
518
531static inline int video_driver_get_volatile_ctrl(const struct device *dev, uint32_t cid)
532{
533 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
534
535 if (api->get_volatile_ctrl == NULL) {
536 return -ENOSYS;
537 }
538
539 return api->get_volatile_ctrl(dev, cid);
540}
541
554static inline int video_driver_set_ctrl(const struct device *dev, uint32_t cid)
555{
556 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
557
558 if (api->set_ctrl == NULL) {
559 return -ENOSYS;
560 }
561
562 return api->set_ctrl(dev, cid);
563}
564
574static inline int video_driver_get_caps(const struct device *dev, struct video_caps *caps)
575{
576 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
577
578 if (api->get_caps == NULL) {
579 return -ENOSYS;
580 }
581
582 return api->get_caps(dev, caps);
583}
584
600static inline int video_driver_transform_cap(const struct device *const dev,
601 const struct video_format_cap *const cap,
602 struct video_format_cap *const res_cap,
603 enum video_buf_type type, uint16_t ind)
604{
605 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
606
607 if (api->transform_cap == NULL) {
608 return -ENOSYS;
609 }
610
611 return api->transform_cap(dev, cap, res_cap, type, ind);
612}
613
627static inline int video_driver_set_signal(const struct device *dev, struct k_poll_signal *sig)
628{
629 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
630
631 if (api->set_signal == NULL) {
632 return -ENOSYS;
633 }
634
635 return api->set_signal(dev, sig);
636}
637
655static inline int video_driver_set_selection(const struct device *dev, struct video_selection *sel)
656{
657 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
658
659 if (api->set_selection == NULL) {
660 return -ENOSYS;
661 }
662
663 return api->set_selection(dev, sel);
664}
665
682static inline int video_driver_get_selection(const struct device *dev, struct video_selection *sel)
683{
684 const struct video_driver_api *api = DEVICE_API_GET(video, dev);
685
686 if (api->get_selection == NULL) {
687 return -ENOSYS;
688 }
689
690 return api->get_selection(dev, sel);
691}
692
703
705#define VIDEO_MIPI_CSI2_DT_NULL 0x10
707#define VIDEO_MIPI_CSI2_DT_BLANKING 0x11
709#define VIDEO_MIPI_CSI2_DT_EMBEDDED_8 0x12
711#define VIDEO_MIPI_CSI2_DT_YUV420_8 0x18
713#define VIDEO_MIPI_CSI2_DT_YUV420_10 0x19
715#define VIDEO_MIPI_CSI2_DT_YUV420_CSPS_8 0x1c
717#define VIDEO_MIPI_CSI2_DT_YUV420_CSPS_10 0x1d
719#define VIDEO_MIPI_CSI2_DT_YUV422_8 0x1e
721#define VIDEO_MIPI_CSI2_DT_YUV422_10 0x1f
723#define VIDEO_MIPI_CSI2_DT_RGB444 0x20
725#define VIDEO_MIPI_CSI2_DT_RGB555 0x21
727#define VIDEO_MIPI_CSI2_DT_RGB565 0x22
729#define VIDEO_MIPI_CSI2_DT_RGB666 0x23
731#define VIDEO_MIPI_CSI2_DT_RGB888 0x24
733#define VIDEO_MIPI_CSI2_DT_RAW6 0x28
735#define VIDEO_MIPI_CSI2_DT_RAW7 0x29
737#define VIDEO_MIPI_CSI2_DT_RAW8 0x2a
739#define VIDEO_MIPI_CSI2_DT_RAW10 0x2b
741#define VIDEO_MIPI_CSI2_DT_RAW12 0x2c
743#define VIDEO_MIPI_CSI2_DT_RAW14 0x2d
744
795
807#define VIDEO_MIPI_CSI2_DT_USER(n) (0x30 + (n))
808
812
813#ifdef __cplusplus
814}
815#endif
816
820
821#endif /* ZEPHYR_INCLUDE_DRIVERS_VIDEO_H */
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1425
Header file for the doubly-linked list API.
struct _dnode sys_dnode_t
Doubly-linked list node structure.
Definition dlist.h:57
struct _dnode sys_dlist_t
Doubly-linked list structure.
Definition dlist.h:53
#define ENOSYS
Function not implemented.
Definition errno.h:83
#define VIDEO_PIX_FMT_SGRBG12P
Definition formats.h:233
#define VIDEO_PIX_FMT_RGB24
24 bit RGB format with 8 bit per component
Definition formats.h:706
#define VIDEO_PIX_FMT_SGRBG8
Definition formats.h:334
#define VIDEO_PIX_FMT_Y12P
Definition formats.h:611
#define VIDEO_PIX_FMT_SRGGB12P
Definition formats.h:242
#define VIDEO_PIX_FMT_SBGGR10P
Definition formats.h:179
#define VIDEO_PIX_FMT_Y10P
Definition formats.h:602
#define VIDEO_PIX_FMT_SRGGB10P
Definition formats.h:206
#define VIDEO_PIX_FMT_SRGGB14P
Definition formats.h:278
#define VIDEO_PIX_FMT_SGBRG14P
Definition formats.h:260
#define VIDEO_PIX_FMT_SGRBG10P
Definition formats.h:197
#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:524
#define VIDEO_PIX_FMT_SGBRG8
Definition formats.h:325
#define VIDEO_PIX_FMT_SBGGR12P
Definition formats.h:215
#define VIDEO_PIX_FMT_SBGGR8
Definition formats.h:316
#define VIDEO_PIX_FMT_SRGGB8
Definition formats.h:343
#define VIDEO_PIX_FMT_SBGGR14P
Definition formats.h:251
#define VIDEO_PIX_FMT_SGBRG10P
Definition formats.h:188
#define VIDEO_PIX_FMT_Y14P
Definition formats.h:620
#define VIDEO_PIX_FMT_UYVY
Definition formats.h:877
#define VIDEO_PIX_FMT_SGRBG14P
Definition formats.h:269
#define VIDEO_PIX_FMT_SGBRG12P
Definition formats.h:224
#define VIDEO_PIX_FMT_RGB565
5 red bits [15:11], 6 green bits [10:5], 5 blue bits [4:0].
Definition formats.h:676
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
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:170
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:208
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:214
#define VIDEO_MIPI_CSI2_DT_RGB888
RGB format with 8 bits per color component.
Definition video.h:731
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:531
#define VIDEO_MIPI_CSI2_DT_YUV422_8
YUV 4:2:2 format with 8 bits per component.
Definition video.h:719
static int video_driver_get_selection(const struct device *dev, struct video_selection *sel)
Get video selection (crop/compose).
Definition video.h:682
static int video_driver_set_ctrl(const struct device *dev, uint32_t cid)
Set a video control value of a driver.
Definition video.h:554
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:600
static int video_driver_enum_frmival(const struct device *dev, struct video_frmival_enum *fie)
List video frame intervals.
Definition video.h:410
#define VIDEO_MIPI_CSI2_DT_RAW14
Raw sensor data with 14 bits per pixel.
Definition video.h:743
struct video_device * video_find_vdev(const struct device *dev)
Find the video_device associated with a video device.
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:182
static int video_driver_get_frmival(const struct device *dev, struct video_frmival *frmival)
Get video frame interval of a driver.
Definition video.h:384
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:202
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:362
#define VIDEO_MIPI_CSI2_DT_NULL
NULL data type - used for padding or synchronization.
Definition video.h:705
#define VIDEO_MIPI_CSI2_DT_RAW10
Raw sensor data with 10 bits per pixel.
Definition video.h:739
#define VIDEO_MIPI_CSI2_DT_RAW8
Raw sensor data with 8 bits per pixel.
Definition video.h:737
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:627
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:574
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:507
static int video_driver_flush(const struct device *dev, bool cancel)
Flush endpoint buffers from a driver.
Definition video.h:484
int(* video_api_format_t)(const struct device *dev, struct video_format *fmt)
@def_driverbackendgroup{Video,video_interface}
Definition video.h:158
int(* video_api_flush_t)(const struct device *dev, bool cancel)
Callback API to flush endpoint buffers.
Definition video.h:189
static int video_driver_set_format(const struct device *dev, struct video_format *fmt)
Set video format of a driver.
Definition video.h:317
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:458
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:229
static int video_driver_get_format(const struct device *dev, struct video_format *fmt)
Get video format of a driver.
Definition video.h:339
static uint8_t video_mipi_data_type(uint32_t pixfmt)
Map pixel formats to their MIPI data type equivalent.
Definition video.h:758
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:195
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:223
#define VIDEO_MIPI_CSI2_DT_RGB565
RGB format with 5-6-5 bits per R-G-B components.
Definition video.h:727
#define VIDEO_MIPI_CSI2_DT_RAW12
Raw sensor data with 12 bits per pixel.
Definition video.h:741
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:176
static int video_driver_enqueue(const struct device *dev, struct video_buffer *vbuf)
Pass a video buffer to a driver.
Definition video.h:434
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:164
static int video_driver_set_selection(const struct device *dev, struct video_selection *sel)
Set video selection (crop/compose).
Definition video.h:655
video_buf_type
video_buf_type enum
Definition types.h:42
#define NULL
Definition iar_missing_defs.h:20
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:513
Poll signal object.
Definition kernel.h:6798
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:122
unsigned long flags
Flags associated with this control.
Definition video.h:124
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:132
uint32_t id
Control ID, see Video Control IDs.
Definition video.h:120
const char *const * menu
Used for menu control types.
Definition video.h:137
int32_t val
Used for 32-bit control types.
Definition video.h:130
struct video_ctrl_range range
Acceptable range of values for this control.
Definition video.h:126
const int64_t * int_menu
Used for integer menu control types.
Definition video.h:139
const struct video_device * vdev
Video device associated with this control.
Definition video.h:118
bool has_volatiles
Internal use for volatile control handling.
Definition video.h:115
sys_dnode_t node
Node place this control in a list.
Definition video.h:142
struct video_ctrl * cluster
Internal use for video control grouping.
Definition video.h:109
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
@driver_ops{Video}
Definition video.h:234
video_api_transform_cap_t transform_cap
@driver_ops_optional Transform a video format capability from one end to the other end of a m2m vid...
Definition video.h:298
video_api_format_t set_format
@driver_ops_mandatory Set video format of a driver.
Definition video.h:238
video_api_ctrl_t set_ctrl
@driver_ops_optional Set a video control value of a driver.
Definition video.h:266
video_api_enqueue_t enqueue
@driver_ops_optional Pass a video buffer to a driver.
Definition video.h:254
video_api_set_signal_t set_signal
@driver_ops_optional Register/Unregister k_poll signal for a video endpoint.
Definition video.h:274
video_api_enum_frmival_t enum_frmival
@driver_ops_optional List video frame intervals.
Definition video.h:286
video_api_get_caps_t get_caps
@driver_ops_mandatory Get the capabilities of a video driver endpoint.
Definition video.h:250
video_api_selection_t get_selection
@driver_ops_optional Get video selection (crop/compose).
Definition video.h:294
video_api_selection_t set_selection
@driver_ops_optional Set video selection (crop/compose).
Definition video.h:290
video_api_format_t get_format
@driver_ops_mandatory Get video format of a driver.
Definition video.h:242
video_api_flush_t flush
@driver_ops_optional Flush endpoint buffers from a driver.
Definition video.h:262
video_api_dequeue_t dequeue
@driver_ops_optional Dequeue a video buffer from a driver.
Definition video.h:258
video_api_frmival_t get_frmival
@driver_ops_optional Get video frame interval of a driver.
Definition video.h:282
video_api_frmival_t set_frmival
@driver_ops_optional Apply a video frame interval to a driver.
Definition video.h:278
video_api_set_stream_t set_stream
@driver_ops_mandatory Start or stop the video driver function.
Definition video.h:246
video_api_ctrl_t get_volatile_ctrl
@driver_ops_optional Get a volatile video control value of a driver.
Definition video.h:270
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.