Skip to content

Commit b5d8aee

Browse files
Alain Volmatkartben
authored andcommitted
video: common: addition of INTEGER_MENU control type
Add a new INTEGER_MENU type allowing to store signed 64bits integer into a menu. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
1 parent a459f1d commit b5d8aee

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
@@ -70,6 +70,7 @@ static inline int check_range(enum video_ctrl_type type, struct video_ctrl_range
7070
}
7171
return 0;
7272
case VIDEO_CTRL_TYPE_MENU:
73+
case VIDEO_CTRL_TYPE_INTEGER_MENU:
7374
if (!IN_RANGE(range.min, 0, range.max) ||
7475
!IN_RANGE(range.def, range.min, range.max)) {
7576
return -ERANGE;
@@ -200,6 +201,28 @@ int video_init_menu_ctrl(struct video_ctrl *ctrl, const struct device *dev, uint
200201
return 0;
201202
}
202203

204+
int video_init_int_menu_ctrl(struct video_ctrl *ctrl, const struct device *dev, uint32_t id,
205+
uint8_t def, const int64_t menu[], size_t menu_len)
206+
{
207+
int ret;
208+
209+
if (!menu) {
210+
return -EINVAL;
211+
}
212+
213+
ret = video_init_ctrl(
214+
ctrl, dev, id,
215+
(struct video_ctrl_range){.min = 0, .max = menu_len - 1, .step = 1, .def = def});
216+
217+
if (ret) {
218+
return ret;
219+
}
220+
221+
ctrl->int_menu = menu;
222+
223+
return 0;
224+
}
225+
203226
/* By definition, the cluster is in manual mode if the master control value is 0 */
204227
static inline bool is_cluster_manual(const struct video_ctrl *master)
205228
{
@@ -554,7 +577,11 @@ int video_query_ctrl(const struct device *dev, struct video_ctrl_query *cq)
554577
cq->type = ctrl->type;
555578
cq->flags = ctrl->flags;
556579
cq->range = ctrl->range;
557-
cq->menu = ctrl->menu;
580+
if (cq->type == VIDEO_CTRL_TYPE_MENU) {
581+
cq->menu = ctrl->menu;
582+
} else if (cq->type == VIDEO_CTRL_TYPE_INTEGER_MENU) {
583+
cq->int_menu = ctrl->int_menu;
584+
}
558585
cq->name = video_get_ctrl_name(cq->id);
559586

560587
return 0;
@@ -583,6 +610,9 @@ void video_print_ctrl(const struct device *const dev, const struct video_ctrl_qu
583610
case VIDEO_CTRL_TYPE_MENU:
584611
type = "menu";
585612
break;
613+
case VIDEO_CTRL_TYPE_INTEGER_MENU:
614+
type = "integer menu";
615+
break;
586616
case VIDEO_CTRL_TYPE_STRING:
587617
type = "string";
588618
break;
@@ -609,10 +639,15 @@ void video_print_ctrl(const struct device *const dev, const struct video_ctrl_qu
609639
cq->range.step, cq->range.def, vc.val);
610640
}
611641

612-
if (cq->menu) {
642+
if (cq->type == VIDEO_CTRL_TYPE_MENU && cq->menu) {
613643
while (cq->menu[i]) {
614644
LOG_INF("%*s %u: %s", 32, "", i, cq->menu[i]);
615645
i++;
616646
}
647+
} else if (cq->type == VIDEO_CTRL_TYPE_INTEGER_MENU && cq->int_menu) {
648+
while (cq->int_menu[i]) {
649+
LOG_INF("%*s %u: %lld", 12, "", i, cq->int_menu[i]);
650+
i++;
651+
}
617652
}
618653
}

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_INTEGER_MENU = 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
@@ -463,7 +463,10 @@ struct video_ctrl_query {
463463
/** control range */
464464
struct video_ctrl_range range;
465465
/** menu if control is of menu type */
466-
const char *const *menu;
466+
union {
467+
const char *const *menu;
468+
const int64_t *int_menu;
469+
};
467470
};
468471

469472
/**

0 commit comments

Comments
 (0)