Skip to content

Commit

Permalink
samples: drivers: video: capture: Add format config
Browse files Browse the repository at this point in the history
Add video format Kconfig for proper sample configuration.

Signed-off-by: Lucas Tamborrino <[email protected]>
  • Loading branch information
LucasTambor committed Sep 17, 2024
1 parent ca09a4b commit a5e56fb
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 7 deletions.
55 changes: 55 additions & 0 deletions samples/drivers/video/capture/Kconfig
Original file line number Diff line number Diff line change
@@ -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"
44 changes: 37 additions & 7 deletions samples/drivers/video/capture/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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));

Expand Down

0 comments on commit a5e56fb

Please sign in to comment.