diff --git a/include/zephyr/drivers/video.h b/include/zephyr/drivers/video.h index ed2d353011c9ea1..5595a740c35207f 100644 --- a/include/zephyr/drivers/video.h +++ b/include/zephyr/drivers/video.h @@ -32,6 +32,30 @@ extern "C" { #endif +/** + * @brief Print formatter to use in printf() style format strings. + * + * This prints a video format in the form of "{fourcc} {width}x{height}" format + * string for use along with @ref PRIvfmt_arg. + * + * @code{.c} + * LOG_DBG("Setting format to " PRIvfmt " at %u FPS", PRIvfmt_arg(fmt), fps); + * @endcode + */ +#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 + /** * @struct video_format * @brief Video format structure diff --git a/samples/drivers/video/capture/src/main.c b/samples/drivers/video/capture/src/main.c index 352eb9ec6101378..4936e8c34061189 100644 --- a/samples/drivers/video/capture/src/main.c +++ b/samples/drivers/video/capture/src/main.c @@ -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"); diff --git a/samples/drivers/video/capture_to_lvgl/src/main.c b/samples/drivers/video/capture_to_lvgl/src/main.c index 1c50163d1afc440..103d4d14cdfd385 100644 --- a/samples/drivers/video/capture_to_lvgl/src/main.c +++ b/samples/drivers/video/capture_to_lvgl/src/main.c @@ -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; diff --git a/samples/drivers/video/tcpserversink/src/main.c b/samples/drivers/video/tcpserversink/src/main.c index 90946be44bd88a8..13890cbb85091b2 100644 --- a/samples/drivers/video/tcpserversink/src/main.c +++ b/samples/drivers/video/tcpserversink/src/main.c @@ -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++) {