Skip to content

Commit 88bf76d

Browse files
committed
drivers: video: Add support for controls of menu types
Add support for controls of menu types, standard menu and drivers' defined menu. Rework the ov5640's test pattern and power line frequency controls using this new support. Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
1 parent f806890 commit 88bf76d

File tree

4 files changed

+83
-11
lines changed

4 files changed

+83
-11
lines changed

drivers/video/ov5640.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,15 @@ static const uint8_t test_pattern_val[] = {
956956
TEST_PATTERN_ENABLE | TEST_PATTERN_SQUARE | TEST_PATTERN_ROLLING,
957957
};
958958

959+
static const char *const test_pattern_menu[] = {
960+
"Disabled",
961+
"Color bars",
962+
"Color bars with rolling bar",
963+
"Color squares",
964+
"Color squares with rolling bar",
965+
NULL
966+
};
967+
959968
static int ov5640_set_ctrl_test_pattern(const struct device *dev, int value)
960969
{
961970
const struct ov5640_config *cfg = dev->config;
@@ -1282,20 +1291,14 @@ static int ov5640_init_controls(const struct device *dev)
12821291
return ret;
12831292
}
12841293

1285-
ret = video_init_ctrl(
1286-
&ctrls->light_freq, dev, VIDEO_CID_POWER_LINE_FREQUENCY,
1287-
(struct video_ctrl_range){.min = VIDEO_CID_POWER_LINE_FREQUENCY_DISABLED,
1288-
.max = VIDEO_CID_POWER_LINE_FREQUENCY_AUTO,
1289-
.step = 1,
1290-
.def = VIDEO_CID_POWER_LINE_FREQUENCY_50HZ});
1294+
ret = video_init_menu_ctrl(&ctrls->light_freq, dev, VIDEO_CID_POWER_LINE_FREQUENCY,
1295+
VIDEO_CID_POWER_LINE_FREQUENCY_50HZ, NULL);
12911296
if (ret) {
12921297
return ret;
12931298
}
12941299

1295-
ret = video_init_ctrl(
1296-
&ctrls->test_pattern, dev, VIDEO_CID_TEST_PATTERN,
1297-
(struct video_ctrl_range){
1298-
.min = 0, .max = ARRAY_SIZE(test_pattern_val) - 1, .step = 1, .def = 0});
1300+
ret = video_init_menu_ctrl(&ctrls->test_pattern, dev, VIDEO_CID_TEST_PATTERN, 0,
1301+
test_pattern_menu);
12991302
if (ret) {
13001303
return ret;
13011304
}

drivers/video/video_ctrls.c

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@
1515

1616
LOG_MODULE_REGISTER(video_ctrls, CONFIG_VIDEO_LOG_LEVEL);
1717

18+
static inline const char *const *video_get_std_menu_ctrl(uint32_t id)
19+
{
20+
static const char *const camera_power_line_frequency[] = {"Disabled", "50 Hz", "60 Hz",
21+
"Auto", NULL};
22+
static const char *const camera_exposure_auto[] = {"Auto Mode", "Manual Mode",
23+
"Shutter Priority Mode",
24+
"Aperture Priority Mode", NULL};
25+
26+
switch (id) {
27+
case VIDEO_CID_POWER_LINE_FREQUENCY:
28+
return camera_power_line_frequency;
29+
case VIDEO_CID_EXPOSURE_AUTO:
30+
return camera_exposure_auto;
31+
default:
32+
return NULL;
33+
}
34+
}
35+
1836
static inline int check_range(enum video_ctrl_type type, struct video_ctrl_range range)
1937
{
2038
switch (type) {
@@ -98,6 +116,7 @@ int video_init_ctrl(struct video_ctrl *ctrl, const struct device *dev, uint32_t
98116
ctrl->cluster = NULL;
99117
ctrl->is_auto = false;
100118
ctrl->has_volatiles = false;
119+
ctrl->menu = NULL;
101120
ctrl->vdev = vdev;
102121
ctrl->id = id;
103122
ctrl->type = type;
@@ -123,6 +142,34 @@ int video_init_ctrl(struct video_ctrl *ctrl, const struct device *dev, uint32_t
123142
return 0;
124143
}
125144

145+
int video_init_menu_ctrl(struct video_ctrl *ctrl, const struct device *dev, uint32_t id,
146+
uint8_t def, const char *const menu[])
147+
{
148+
int ret;
149+
uint8_t sz = 0;
150+
const char *const *_menu = menu ? menu : video_get_std_menu_ctrl(id);
151+
152+
if (!_menu) {
153+
return -EINVAL;
154+
}
155+
156+
while (_menu[sz]) {
157+
sz++;
158+
}
159+
160+
ret = video_init_ctrl(
161+
ctrl, dev, id,
162+
(struct video_ctrl_range){.min = 0, .max = sz - 1, .step = 1, .def = def});
163+
164+
if (ret) {
165+
return ret;
166+
}
167+
168+
ctrl->menu = _menu;
169+
170+
return 0;
171+
}
172+
126173
/* By definition, the cluster is in manual mode if the master control value is 0 */
127174
static inline bool is_cluster_manual(const struct video_ctrl *master)
128175
{
@@ -406,7 +453,7 @@ int video_query_ctrl(const struct device *dev, struct video_ctrl_query *cq)
406453
cq->type = ctrl->type;
407454
cq->flags = ctrl->flags;
408455
cq->range = ctrl->range;
409-
456+
cq->menu = ctrl->menu;
410457
cq->name = video_get_ctrl_name(cq->id);
411458

412459
return 0;
@@ -459,4 +506,11 @@ void video_print_ctrl(const struct device *const dev, const struct video_ctrl_qu
459506
cq->name, cq->id, typebuf, cq->flags, cq->range.min, cq->range.max,
460507
cq->range.step, cq->range.def, vc.val);
461508
}
509+
510+
if (cq->menu) {
511+
while (cq->menu[i]) {
512+
LOG_INF("%*s %u: %s", 32, "", i, cq->menu[i]);
513+
i++;
514+
}
515+
}
462516
}

drivers/video/video_ctrls.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,16 @@ struct video_ctrl {
5151
int32_t val;
5252
int64_t val64;
5353
};
54+
const char *const *menu;
5455
sys_dnode_t node;
5556
};
5657

5758
int video_init_ctrl(struct video_ctrl *ctrl, const struct device *dev, uint32_t id,
5859
struct video_ctrl_range range);
5960

61+
int video_init_menu_ctrl(struct video_ctrl *ctrl, const struct device *dev, uint32_t id,
62+
uint8_t def, const char *const menu[]);
63+
6064
void video_cluster_ctrl(struct video_ctrl *ctrls, uint8_t sz);
6165

6266
void video_auto_cluster_ctrl(struct video_ctrl *ctrls, uint8_t sz, bool set_volatile);

include/zephyr/drivers/video-controls.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ enum video_power_line_frequency {
107107
*/
108108
#define VIDEO_CID_CAMERA_CLASS_BASE 0x009a0900
109109

110+
/** Adjustments of exposure time and/or iris aperture. */
111+
#define VIDEO_CID_EXPOSURE_AUTO (VIDEO_CID_CAMERA_CLASS_BASE + 1)
112+
enum video_exposure_auto_type {
113+
VIDEO_EXPOSURE_AUTO = 0,
114+
VIDEO_EXPOSURE_MANUAL = 1,
115+
VIDEO_EXPOSURE_SHUTTER_PRIORITY = 2,
116+
VIDEO_EXPOSURE_APERTURE_PRIORITY = 3
117+
};
118+
110119
/** Amount of optical zoom applied through to the camera optics */
111120
#define VIDEO_CID_ZOOM_ABSOLUTE (VIDEO_CID_CAMERA_CLASS_BASE + 13)
112121

@@ -255,6 +264,8 @@ struct video_ctrl_query {
255264
uint32_t flags;
256265
/** control range */
257266
struct video_ctrl_range range;
267+
/** menu if control is of menu type */
268+
const char *const *menu;
258269
};
259270

260271
/**

0 commit comments

Comments
 (0)