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 c39d83f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
27 changes: 27 additions & 0 deletions samples/drivers/video/capture/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
# SPDX-License-Identifier: Apache-2.0

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.

config VIDEO_PIXEL_FORMAT
string "Pixel format of the video format"
help
Pixel format of the video format. If not set, the default pixel format is used.

endmenu

source "Kconfig.zephyr"
29 changes: 22 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,30 @@ 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 (strcmp(CONFIG_VIDEO_PIXEL_FORMAT, "")) {
fmt.pixelformat =
video_fourcc(CONFIG_VIDEO_PIXEL_FORMAT[0], CONFIG_VIDEO_PIXEL_FORMAT[1],
CONFIG_VIDEO_PIXEL_FORMAT[2], CONFIG_VIDEO_PIXEL_FORMAT[3]);
}

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 c39d83f

Please sign in to comment.