Skip to content

Commit 2621976

Browse files
author
Alain Volmat
committed
video: common: addition of MENU_INTEGER control type
Add a new MENU_INTEGER type allowing to store signed 64bits integer into a menu. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
1 parent cee61e3 commit 2621976

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

drivers/video/video_ctrls.c

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ static inline int check_range(enum video_ctrl_type type, struct video_ctrl_range
5454
}
5555
return 0;
5656
case VIDEO_CTRL_TYPE_MENU:
57+
case VIDEO_CTRL_TYPE_MENU_INTEGER:
5758
if (!IN_RANGE(range.min, 0, range.max) ||
5859
!IN_RANGE(range.def, range.min, range.max)) {
5960
return -ERANGE;
@@ -170,6 +171,28 @@ int video_init_menu_ctrl(struct video_ctrl *ctrl, const struct device *dev, uint
170171
return 0;
171172
}
172173

174+
int video_init_int_menu_ctrl(struct video_ctrl *ctrl, const struct device *dev, uint32_t id,
175+
uint8_t def, const int64_t menu[], size_t menu_len)
176+
{
177+
int ret;
178+
179+
if (!menu) {
180+
return -EINVAL;
181+
}
182+
183+
ret = video_init_ctrl(
184+
ctrl, dev, id,
185+
(struct video_ctrl_range){.min = 0, .max = menu_len - 1, .step = 1, .def = def});
186+
187+
if (ret) {
188+
return ret;
189+
}
190+
191+
ctrl->int_menu = menu;
192+
193+
return 0;
194+
}
195+
173196
/* By definition, the cluster is in manual mode if the master control value is 0 */
174197
static inline bool is_cluster_manual(const struct video_ctrl *master)
175198
{
@@ -451,7 +474,11 @@ int video_query_ctrl(const struct device *dev, struct video_ctrl_query *cq)
451474
cq->type = ctrl->type;
452475
cq->flags = ctrl->flags;
453476
cq->range = ctrl->range;
454-
cq->menu = ctrl->menu;
477+
if (cq->type == VIDEO_CTRL_TYPE_MENU) {
478+
cq->menu = ctrl->menu;
479+
} else if (cq->type == VIDEO_CTRL_TYPE_MENU_INTEGER) {
480+
cq->int_menu = ctrl->int_menu;
481+
}
455482
cq->name = video_get_ctrl_name(cq->id);
456483

457484
return 0;
@@ -479,6 +506,9 @@ void video_print_ctrl(const struct device *const dev, const struct video_ctrl_qu
479506
case VIDEO_CTRL_TYPE_MENU:
480507
type = "menu";
481508
break;
509+
case VIDEO_CTRL_TYPE_MENU_INTEGER:
510+
type = "menu integer";
511+
break;
482512
case VIDEO_CTRL_TYPE_STRING:
483513
type = "string";
484514
break;
@@ -505,10 +535,15 @@ void video_print_ctrl(const struct device *const dev, const struct video_ctrl_qu
505535
cq->range.step, cq->range.def, vc.val);
506536
}
507537

508-
if (cq->menu) {
538+
if (cq->type == VIDEO_CTRL_TYPE_MENU && cq->menu) {
509539
while (cq->menu[i]) {
510540
LOG_INF("%*s %u: %s", 32, "", i, cq->menu[i]);
511541
i++;
512542
}
543+
} else if (cq->type == VIDEO_CTRL_TYPE_MENU_INTEGER && cq->int_menu) {
544+
while (cq->int_menu[i]) {
545+
LOG_INF("%*s %u: %lld", 12, "", i, cq->int_menu[i]);
546+
i++;
547+
}
513548
}
514549
}

drivers/video/video_ctrls.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ enum video_ctrl_type {
2727
VIDEO_CTRL_TYPE_INTEGER = 2,
2828
/** 64-bit integer type */
2929
VIDEO_CTRL_TYPE_INTEGER64 = 3,
30-
/** Menu type, standard or driver-defined menu */
30+
/** Menu string type, standard or driver-defined menu */
3131
VIDEO_CTRL_TYPE_MENU = 4,
3232
/** String type */
3333
VIDEO_CTRL_TYPE_STRING = 5,
34+
/** Menu integer type, standard or driver-defined menu */
35+
VIDEO_CTRL_TYPE_MENU_INTEGER = 6,
3436
};
3537

3638
struct video_device;
@@ -54,7 +56,10 @@ struct video_ctrl {
5456
int32_t val;
5557
int64_t val64;
5658
};
57-
const char *const *menu;
59+
union {
60+
const char *const *menu;
61+
const int64_t *int_menu;
62+
};
5863
sys_dnode_t node;
5964
};
6065

@@ -64,6 +69,9 @@ int video_init_ctrl(struct video_ctrl *ctrl, const struct device *dev, uint32_t
6469
int video_init_menu_ctrl(struct video_ctrl *ctrl, const struct device *dev, uint32_t id,
6570
uint8_t def, const char *const menu[]);
6671

72+
int video_init_int_menu_ctrl(struct video_ctrl *ctrl, const struct device *dev, uint32_t id,
73+
uint8_t def, const int64_t menu[], size_t menu_len);
74+
6775
void video_cluster_ctrl(struct video_ctrl *ctrls, uint8_t sz);
6876

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

include/zephyr/drivers/video-controls.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,10 @@ struct video_ctrl_query {
266266
/** control range */
267267
struct video_ctrl_range range;
268268
/** menu if control is of menu type */
269-
const char *const *menu;
269+
union {
270+
const char *const *menu;
271+
const int64_t *int_menu;
272+
};
270273
};
271274

272275
/**

0 commit comments

Comments
 (0)