Skip to content

Commit 26db5c2

Browse files
josuahkartben
authored andcommitted
drivers: video: introduce VIDEO_FOURCC_TO_STR
This adds a macro to generate a C99 compound literal string, which allow to use it in debug log messages, such as: LOG_DBG("The pixel format is '%s'", VIDEO_FOURCC_STR(fmt->pixelformat)); Signed-off-by: Josuah Demangeon <me@josuah.net>
1 parent 4c5f858 commit 26db5c2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

include/zephyr/drivers/video.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,24 @@ void video_closest_frmival(const struct device *dev, enum video_endpoint_id ep,
833833
*/
834834
#define VIDEO_FOURCC_FROM_STR(str) VIDEO_FOURCC((str)[0], (str)[1], (str)[2], (str)[3])
835835

836+
/**
837+
* @brief Convert a four-character-code to a four-character-string
838+
*
839+
* Convert a four-character code as defined by @ref VIDEO_FOURCC into a string that can be used
840+
* anywhere, such as in debug logs with the %s print formatter.
841+
*
842+
* @param fourcc The 32-bit four-character-code integer to be converted, in CPU-native endinaness.
843+
* @return Four-character-string built out of it.
844+
*/
845+
#define VIDEO_FOURCC_TO_STR(fourcc) \
846+
((char[]){ \
847+
(char)((fourcc) & 0xFF), \
848+
(char)(((fourcc) >> 8) & 0xFF), \
849+
(char)(((fourcc) >> 16) & 0xFF), \
850+
(char)(((fourcc) >> 24) & 0xFF), \
851+
'\0' \
852+
})
853+
836854
/**
837855
* @name Bayer formats (R, G, B channels).
838856
*

0 commit comments

Comments
 (0)