From a6d68d2166195d1dc73c056d26c906fa7b606a9d Mon Sep 17 00:00:00 2001 From: Josuah Demangeon Date: Sun, 6 Oct 2024 18:19:44 +0000 Subject: [PATCH] drivers: video: Make VIDEO_FOURCC() a documented API Rename video_fourcc() to VIDEO_FOURCC(), differing from the Linux implementation, but more compliant with the coding style. Also introduce a VIDEO_FOURCC_FROM_STR() to generate a FOURCC format code out of a 4-characters string. Signed-off-by: Josuah Demangeon --- include/zephyr/drivers/video.h | 17 +++++++++++++++-- samples/drivers/video/capture/src/main.c | 4 +--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/zephyr/drivers/video.h b/include/zephyr/drivers/video.h index a3aa05bc051e..6eac2336bf4b 100644 --- a/include/zephyr/drivers/video.h +++ b/include/zephyr/drivers/video.h @@ -812,10 +812,23 @@ void video_closest_frmival_stepwise(const struct video_frmival_stepwise *stepwis void video_closest_frmival(const struct device *dev, enum video_endpoint_id ep, struct video_frmival_enum *match); -/* fourcc - four-character-code */ -#define video_fourcc(a, b, c, d) \ +/** + * @brief Four-character-code uniquely identifying the pixel format + */ +#define VIDEO_FOURCC(a, b, c, d) \ ((uint32_t)(a) | ((uint32_t)(b) << 8) | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24)) +/** + * @brief Convert a four-character-string to a four-character-code + * + * Convert a string literal or variable into a four-character-code + * as defined by @ref VIDEO_FOURCC. + * + * @param str String to be converted + * @return Four-character-code. + */ +#define VIDEO_FOURCC_FROM_STR(str) VIDEO_FOURCC((str)[0], (str)[1], (str)[2], (str)[3]) + /** * @defgroup video_pixel_formats Video pixel formats * The @c | characters separate the pixels, and spaces separate the bytes. diff --git a/samples/drivers/video/capture/src/main.c b/samples/drivers/video/capture/src/main.c index 10af7ef7d9ea..59f200b94d8d 100644 --- a/samples/drivers/video/capture/src/main.c +++ b/samples/drivers/video/capture/src/main.c @@ -144,9 +144,7 @@ int main(void) #endif if (strcmp(CONFIG_VIDEO_PIXEL_FORMAT, "")) { - fmt.pixelformat = - video_fourcc(CONFIG_VIDEO_PIXEL_FORMAT[0], CONFIG_VIDEO_PIXEL_FORMAT[1], - CONFIG_VIDEO_PIXEL_FORMAT[2], CONFIG_VIDEO_PIXEL_FORMAT[3]); + fmt.pixelformat = VIDEO_FOURCC_FROM_STR(CONFIG_VIDEO_PIXEL_FORMAT); } LOG_INF("- Video format: %c%c%c%c %ux%u", (char)fmt.pixelformat,