diff --git a/samples/drivers/video/capture/Kconfig b/samples/drivers/video/capture/Kconfig new file mode 100644 index 000000000000000..20c373d53c46216 --- /dev/null +++ b/samples/drivers/video/capture/Kconfig @@ -0,0 +1,55 @@ +mainmenu "Video capture sample application" + +menu "Video capture configuration" + +config VIDEO_FORMAT_HEIGHT + int "Height of the video format" + default 0 + help + Height of the video format. If set to 0, the default height is used. + +config VIDEO_FORMAT_WIDTH + int "Width of the video format" + default 0 + help + Width of the video format. If set to 0, the default width is used. + +choice VIDEO_PIXEL_FORMAT + prompt "Pixel format of the video format" + default VIDEO_PIXEL_FORMAT_DEFAULT + + config VIDEO_PIXEL_FORMAT_DEFAULT + bool "Default" + + config VIDEO_PIXEL_FORMAT_BGGR8 + bool "BGGR8" + + config VIDEO_PIXEL_FORMAT_GBRG8 + bool "GBRG8" + + config VIDEO_PIXEL_FORMAT_GRBG8 + bool "GRBG8" + + config VIDEO_PIXEL_FORMAT_RGGB8 + bool "RGGB8" + + config VIDEO_PIXEL_FORMAT_RGB565 + bool "RGB565" + + config VIDEO_PIXEL_FORMAT_XRGB32 + bool "XRGB32" + + config VIDEO_PIXEL_FORMAT_YUYV + bool "YUYV" + + config VIDEO_PIXEL_FORMAT_XYUV32 + bool "XYUV32" + + config VIDEO_PIXEL_FORMAT_JPEG + bool "JPEG" + +endchoice + +endmenu + +source "Kconfig.zephyr" diff --git a/samples/drivers/video/capture/src/main.c b/samples/drivers/video/capture/src/main.c index 862dff287f7aa5e..75adbeeafc29c48 100644 --- a/samples/drivers/video/capture/src/main.c +++ b/samples/drivers/video/capture/src/main.c @@ -22,11 +22,6 @@ static inline int display_setup(const struct device *const display_dev, const ui struct display_capabilities capabilities; int ret = 0; - if (!device_is_ready(display_dev)) { - LOG_ERR("Device %s not found", display_dev->name); - return -ENODEV; - } - printk("\nDisplay device: %s\n", display_dev->name); display_get_capabilities(display_dev, &capabilities); @@ -41,7 +36,7 @@ static inline int display_setup(const struct device *const display_dev, const ui /* Set display pixel format to match the one in use by the camera */ switch (pixfmt) { case VIDEO_PIX_FMT_RGB565: - ret = display_set_pixel_format(display_dev, PIXEL_FORMAT_BGR_565); + ret = display_set_pixel_format(display_dev, PIXEL_FORMAT_RGB_565); break; case VIDEO_PIX_FMT_XRGB32: ret = display_set_pixel_format(display_dev, PIXEL_FORMAT_ARGB_8888); @@ -125,10 +120,45 @@ int main(void) return 0; } - printk("- Default format: %c%c%c%c %ux%u\n", (char)fmt.pixelformat, + if (CONFIG_VIDEO_FORMAT_HEIGHT) { + fmt.height = CONFIG_VIDEO_FORMAT_HEIGHT; + } + + if (CONFIG_VIDEO_FORMAT_WIDTH) { + fmt.width = CONFIG_VIDEO_FORMAT_WIDTH; + fmt.pitch = fmt.width * 2; + } + + +#if defined(CONFIG_VIDEO_PIXEL_FORMAT_BGGR8) + fmt.pixelformat = VIDEO_PIX_FMT_BGGR8; +#elif defined(CONFIG_VIDEO_PIXEL_FORMAT_GBRG8) + fmt.pixelformat = VIDEO_PIX_FMT_GBRG8; +#elif defined(CONFIG_VIDEO_PIXEL_FORMAT_GRBG8) + fmt.pixelformat = VIDEO_PIX_FMT_GRBG8; +#elif defined(CONFIG_VIDEO_PIXEL_FORMAT_RGGB8) + fmt.pixelformat = VIDEO_PIX_FMT_RGGB8; +#elif defined(CONFIG_VIDEO_PIXEL_FORMAT_RGB565) + fmt.pixelformat = VIDEO_PIX_FMT_RGB565; +#elif defined(CONFIG_VIDEO_PIXEL_FORMAT_XRGB32) + fmt.pixelformat = VIDEO_PIX_FMT_XRGB32; +#elif defined(CONFIG_VIDEO_PIXEL_FORMAT_YUYV) + fmt.pixelformat = VIDEO_PIX_FMT_YUYV; +#elif defined(CONFIG_VIDEO_PIXEL_FORMAT_XYUV32) + fmt.pixelformat = VIDEO_PIX_FMT_XYUV32; +#elif defined(CONFIG_VIDEO_PIXEL_FORMAT_JPEG) + fmt.pixelformat = VIDEO_PIX_FMT_JPEG; +#endif + + printk("- Video 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); + if (video_set_format(video_dev, VIDEO_EP_OUT, &fmt)) { + LOG_ERR("Unable to set format"); + return 0; + } + #if DT_HAS_CHOSEN(zephyr_display) const struct device *const display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));