Skip to content

Commit

Permalink
drivers: video: add a printf() formatter for video formats
Browse files Browse the repository at this point in the history
Help with logging the video format selected directly from a
struct video_format.

Signed-off-by: Josuah Demangeon <[email protected]>
  • Loading branch information
josuah committed Oct 14, 2024
1 parent c4ab20f commit 6762ced
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
22 changes: 22 additions & 0 deletions include/zephyr/drivers/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@
extern "C" {
#endif

/**
* @brief Print formatter to use in printf() style format strings.
*
* This prints a video format in the form of "{width}x{height} {fourcc}" format
* string for use along with @ref PRIvfmt_arg.
*
* @example "LOG_DBG(\"Setting format to \"PRIvfmt, PRIvfmt_arg(fmt));"
*/
#define PRIvfmt "%c%c%c%c %ux%u"

/**
* @brief Argument formatter for use in printf() style format strings.
*
* This conditions a video format argument for use with @ref PRIvfmt.
*
* @param fmt Pointer to a @ref video_format that will be formatted
* @return list of parameters that match @ref PRIvfmt specification
*/
#define PRIvfmt_arg(fmt) \
(fmt)->pixelformat, (fmt)->pixelformat >> 8, (fmt)->pixelformat >> 16, \
(fmt)->pixelformat >> 24, (fmt)->width, (fmt)->height

Check notice on line 56 in include/zephyr/drivers/video.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/drivers/video.h:56 - (fmt)->pixelformat >> 24, (fmt)->width, (fmt)->height + (fmt)->pixelformat >> 24, (fmt)->width, (fmt)->height
/**
* @struct video_format
* @brief Video format structure
Expand Down
4 changes: 1 addition & 3 deletions samples/drivers/video/capture/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ int main(void)
fmt.pixelformat = VIDEO_FOURCC_FROM_STR(CONFIG_VIDEO_PIXEL_FORMAT);
}

LOG_INF("- Video format: %c%c%c%c %ux%u", (char)fmt.pixelformat,
(char)(fmt.pixelformat >> 8), (char)(fmt.pixelformat >> 16),
(char)(fmt.pixelformat >> 24), fmt.width, fmt.height);
LOG_INF("- Video format: " PRIvfmt, PRIvfmt_arg(&fmt));

if (video_set_format(video_dev, VIDEO_EP_OUT, &fmt)) {
LOG_ERR("Unable to set format");
Expand Down
6 changes: 2 additions & 4 deletions samples/drivers/video/capture_to_lvgl/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,11 @@ int main(void)
fmt.pixelformat = VIDEO_PIX_FMT_RGB565;

if (video_set_format(video_dev, VIDEO_EP_OUT, &fmt)) {
LOG_ERR("Unable to set up video format");
LOG_ERR("Unable to set video format to " PRIvfmt, PRIvfmt_arg(&fmt));
return 0;
}

LOG_INF("- Format: %c%c%c%c %ux%u %u", (char)fmt.pixelformat, (char)(fmt.pixelformat >> 8),
(char)(fmt.pixelformat >> 16), (char)(fmt.pixelformat >> 24), fmt.width, fmt.height,
fmt.pitch);
LOG_INF("- Format: " PRIvfmt " %u", PRIvfmt_arg(&fmt), fmt.pitch);

/* Size to allocate for each buffer */
bsize = fmt.pitch * fmt.height;
Expand Down
4 changes: 1 addition & 3 deletions samples/drivers/video/tcpserversink/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ int main(void)
return 0;
}

printk("Video device detected, format: %c%c%c%c %ux%u\n", (char)fmt.pixelformat,
(char)(fmt.pixelformat >> 8), (char)(fmt.pixelformat >> 16),
(char)(fmt.pixelformat >> 24), fmt.width, fmt.height);
printk("Video device detected, format: " PRIvfmt "\n", PRIvfmt_arg(&fmt));

/* Alloc Buffers */
for (i = 0; i < ARRAY_SIZE(buffers); i++) {
Expand Down

0 comments on commit 6762ced

Please sign in to comment.