diff --git a/include/zephyr/drivers/video.h b/include/zephyr/drivers/video.h index 7b65a02dd98ac09..c16392f9573fc40 100644 --- a/include/zephyr/drivers/video.h +++ b/include/zephyr/drivers/video.h @@ -753,10 +753,23 @@ struct video_buffer *video_buffer_alloc(size_t size); */ void video_buffer_release(struct video_buffer *buf); -/* 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 6134b7e56d01a2c..13b167fe1e2096e 100644 --- a/samples/drivers/video/capture/src/main.c +++ b/samples/drivers/video/capture/src/main.c @@ -145,9 +145,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,