Skip to content

Commit 6164497

Browse files
LucasTamboraescolar
authored andcommitted
samples: drivers: video: capture: Add format config
Add video format Kconfig for proper sample configuration. Signed-off-by: Lucas Tamborrino <[email protected]>
1 parent d5b6539 commit 6164497

File tree

3 files changed

+63
-20
lines changed

3 files changed

+63
-20
lines changed

samples/drivers/video/capture/Kconfig

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
mainmenu "Video capture sample application"
5+
6+
menu "Video capture configuration"
7+
8+
config VIDEO_FRAME_HEIGHT
9+
int "Height of the video frame"
10+
default 0
11+
help
12+
Height of the video frame. If set to 0, the default height is used.
13+
14+
config VIDEO_FRAME_WIDTH
15+
int "Width of the video frame"
16+
default 0
17+
help
18+
Width of the video frame. If set to 0, the default width is used.
19+
20+
config VIDEO_PIXEL_FORMAT
21+
string "Pixel format of the video frame"
22+
help
23+
Pixel format of the video frame. If not set, the default pixel format is used.
24+
25+
endmenu
26+
27+
source "Kconfig.zephyr"

samples/drivers/video/capture/sample.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ tests:
2424
- mimxrt1064_evk
2525
- mimxrt1170_evk/mimxrt1176/cm7
2626
- mm_swiftio
27+
- esp32s3_eye/esp32s3/procpu
2728
depends_on: video
2829
integration_platforms:
2930
- mimxrt1064_evk

samples/drivers/video/capture/src/main.c

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,21 @@ static inline int display_setup(const struct device *const display_dev, const ui
2222
struct display_capabilities capabilities;
2323
int ret = 0;
2424

25-
if (!device_is_ready(display_dev)) {
26-
LOG_ERR("Device %s not found", display_dev->name);
27-
return -ENODEV;
28-
}
29-
30-
printk("\nDisplay device: %s\n", display_dev->name);
25+
LOG_INF("Display device: %s", display_dev->name);
3126

3227
display_get_capabilities(display_dev, &capabilities);
3328

34-
printk("- Capabilities:\n");
35-
printk(" x_resolution = %u, y_resolution = %u, supported_pixel_formats = %u\n"
36-
" current_pixel_format = %u, current_orientation = %u\n\n",
29+
LOG_INF("- Capabilities:");
30+
LOG_INF(" x_resolution = %u, y_resolution = %u, supported_pixel_formats = %u"
31+
" current_pixel_format = %u, current_orientation = %u",
3732
capabilities.x_resolution, capabilities.y_resolution,
3833
capabilities.supported_pixel_formats, capabilities.current_pixel_format,
3934
capabilities.current_orientation);
4035

4136
/* Set display pixel format to match the one in use by the camera */
4237
switch (pixfmt) {
4338
case VIDEO_PIX_FMT_RGB565:
44-
ret = display_set_pixel_format(display_dev, PIXEL_FORMAT_BGR_565);
39+
ret = display_set_pixel_format(display_dev, PIXEL_FORMAT_RGB_565);
4540
break;
4641
case VIDEO_PIX_FMT_XRGB32:
4742
ret = display_set_pixel_format(display_dev, PIXEL_FORMAT_ARGB_8888);
@@ -101,19 +96,19 @@ int main(void)
10196
}
10297
#endif
10398

104-
printk("Video device: %s\n", video_dev->name);
99+
LOG_INF("Video device: %s", video_dev->name);
105100

106101
/* Get capabilities */
107102
if (video_get_caps(video_dev, VIDEO_EP_OUT, &caps)) {
108103
LOG_ERR("Unable to retrieve video capabilities");
109104
return 0;
110105
}
111106

112-
printk("- Capabilities:\n");
107+
LOG_INF("- Capabilities:");
113108
while (caps.format_caps[i].pixelformat) {
114109
const struct video_format_cap *fcap = &caps.format_caps[i];
115110
/* fourcc to string */
116-
printk(" %c%c%c%c width [%u; %u; %u] height [%u; %u; %u]\n",
111+
LOG_INF(" %c%c%c%c width [%u; %u; %u] height [%u; %u; %u]",
117112
(char)fcap->pixelformat, (char)(fcap->pixelformat >> 8),
118113
(char)(fcap->pixelformat >> 16), (char)(fcap->pixelformat >> 24),
119114
fcap->width_min, fcap->width_max, fcap->width_step, fcap->height_min,
@@ -127,23 +122,43 @@ int main(void)
127122
return 0;
128123
}
129124

130-
printk("- Default format: %c%c%c%c %ux%u\n", (char)fmt.pixelformat,
125+
#if CONFIG_VIDEO_FRAME_HEIGHT
126+
fmt.height = CONFIG_VIDEO_FRAME_HEIGHT;
127+
#endif
128+
129+
#if CONFIG_VIDEO_FRAME_WIDTH
130+
fmt.width = CONFIG_VIDEO_FRAME_WIDTH;
131+
fmt.pitch = fmt.width * 2;
132+
#endif
133+
134+
if (strcmp(CONFIG_VIDEO_PIXEL_FORMAT, "")) {
135+
fmt.pixelformat =
136+
video_fourcc(CONFIG_VIDEO_PIXEL_FORMAT[0], CONFIG_VIDEO_PIXEL_FORMAT[1],
137+
CONFIG_VIDEO_PIXEL_FORMAT[2], CONFIG_VIDEO_PIXEL_FORMAT[3]);
138+
}
139+
140+
LOG_INF("- Video format: %c%c%c%c %ux%u", (char)fmt.pixelformat,
131141
(char)(fmt.pixelformat >> 8), (char)(fmt.pixelformat >> 16),
132142
(char)(fmt.pixelformat >> 24), fmt.width, fmt.height);
133143

144+
if (video_set_format(video_dev, VIDEO_EP_OUT, &fmt)) {
145+
LOG_ERR("Unable to set format");
146+
return 0;
147+
}
148+
134149
if (!video_get_frmival(video_dev, VIDEO_EP_OUT, &frmival)) {
135-
printk("- Default frame rate : %f fps\n",
150+
LOG_INF("- Default frame rate : %f fps",
136151
1.0 * frmival.denominator / frmival.numerator);
137152
}
138153

139-
printk("- Supported frame intervals for the default format:\n");
154+
LOG_INF("- Supported frame intervals for the default format:");
140155
memset(&fie, 0, sizeof(fie));
141156
fie.format = &fmt;
142157
while (video_enum_frmival(video_dev, VIDEO_EP_OUT, &fie) == 0) {
143158
if (fie.type == VIDEO_FRMIVAL_TYPE_DISCRETE) {
144-
printk(" %u/%u ", fie.discrete.numerator, fie.discrete.denominator);
159+
LOG_INF(" %u/%u ", fie.discrete.numerator, fie.discrete.denominator);
145160
} else {
146-
printk(" [min = %u/%u; max = %u/%u; step = %u/%u]\n",
161+
LOG_INF(" [min = %u/%u; max = %u/%u; step = %u/%u]",
147162
fie.stepwise.min.numerator, fie.stepwise.min.denominator,
148163
fie.stepwise.max.numerator, fie.stepwise.max.denominator,
149164
fie.stepwise.step.numerator, fie.stepwise.step.denominator);
@@ -190,7 +205,7 @@ int main(void)
190205
return 0;
191206
}
192207

193-
printk("Capture started\n");
208+
LOG_INF("Capture started");
194209

195210
/* Grab video frames */
196211
while (1) {
@@ -200,7 +215,7 @@ int main(void)
200215
return 0;
201216
}
202217

203-
printk("Got frame %u! size: %u; timestamp %u ms\n", frame++, vbuf->bytesused,
218+
LOG_DBG("Got frame %u! size: %u; timestamp %u ms", frame++, vbuf->bytesused,
204219
vbuf->timestamp);
205220

206221
#if DT_HAS_CHOSEN(zephyr_display)

0 commit comments

Comments
 (0)