diff options
author | Sylwester Nawrocki <s.nawrocki@samsung.com> | 2012-05-06 14:30:44 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-05-14 13:03:21 -0400 |
commit | 515f32879a05bdb69f9b3f86f53db4c04b95e845 (patch) | |
tree | 9a090c658d1dc1c96286cb9359cbfd13b42f5db3 | |
parent | 6491d1adfbf0e2ffbdfcda8cef60edc01b6700b3 (diff) |
[media] V4L: Add helper function for standard integer menu controls
This patch adds v4l2_ctrl_new_int_menu() helper function which can be used
in drivers for creating standard integer menu control with driver-specific
menu item list. It is similar to v4l2_ctrl_new_std_menu(), except it doesn't
have a mask parameter and an additional qmenu parameter allows passing
an array of signed 64-bit integers as the menu item list.
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Sakari Ailus <sakari.ailus@iki.fi>
Tested-by: Sakari Ailus <sakari.ailus@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | Documentation/video4linux/v4l2-controls.txt | 21 | ||||
-rw-r--r-- | drivers/media/video/v4l2-ctrls.c | 21 | ||||
-rw-r--r-- | include/media/v4l2-ctrls.h | 17 |
3 files changed, 59 insertions, 0 deletions
diff --git a/Documentation/video4linux/v4l2-controls.txt b/Documentation/video4linux/v4l2-controls.txt index e2492a9d1027..43da22b89728 100644 --- a/Documentation/video4linux/v4l2-controls.txt +++ b/Documentation/video4linux/v4l2-controls.txt | |||
@@ -130,8 +130,18 @@ Menu controls are added by calling v4l2_ctrl_new_std_menu: | |||
130 | const struct v4l2_ctrl_ops *ops, | 130 | const struct v4l2_ctrl_ops *ops, |
131 | u32 id, s32 max, s32 skip_mask, s32 def); | 131 | u32 id, s32 max, s32 skip_mask, s32 def); |
132 | 132 | ||
133 | Or alternatively for integer menu controls, by calling v4l2_ctrl_new_int_menu: | ||
134 | |||
135 | struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl, | ||
136 | const struct v4l2_ctrl_ops *ops, | ||
137 | u32 id, s32 max, s32 def, const s64 *qmenu_int); | ||
138 | |||
133 | These functions are typically called right after the v4l2_ctrl_handler_init: | 139 | These functions are typically called right after the v4l2_ctrl_handler_init: |
134 | 140 | ||
141 | static const s64 exp_bias_qmenu[] = { | ||
142 | -2, -1, 0, 1, 2 | ||
143 | }; | ||
144 | |||
135 | v4l2_ctrl_handler_init(&foo->ctrl_handler, nr_of_controls); | 145 | v4l2_ctrl_handler_init(&foo->ctrl_handler, nr_of_controls); |
136 | v4l2_ctrl_new_std(&foo->ctrl_handler, &foo_ctrl_ops, | 146 | v4l2_ctrl_new_std(&foo->ctrl_handler, &foo_ctrl_ops, |
137 | V4L2_CID_BRIGHTNESS, 0, 255, 1, 128); | 147 | V4L2_CID_BRIGHTNESS, 0, 255, 1, 128); |
@@ -141,6 +151,11 @@ These functions are typically called right after the v4l2_ctrl_handler_init: | |||
141 | V4L2_CID_POWER_LINE_FREQUENCY, | 151 | V4L2_CID_POWER_LINE_FREQUENCY, |
142 | V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0, | 152 | V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0, |
143 | V4L2_CID_POWER_LINE_FREQUENCY_DISABLED); | 153 | V4L2_CID_POWER_LINE_FREQUENCY_DISABLED); |
154 | v4l2_ctrl_new_int_menu(&foo->ctrl_handler, &foo_ctrl_ops, | ||
155 | V4L2_CID_EXPOSURE_BIAS, | ||
156 | ARRAY_SIZE(exp_bias_qmenu) - 1, | ||
157 | ARRAY_SIZE(exp_bias_qmenu) / 2 - 1, | ||
158 | exp_bias_qmenu); | ||
144 | ... | 159 | ... |
145 | if (foo->ctrl_handler.error) { | 160 | if (foo->ctrl_handler.error) { |
146 | int err = foo->ctrl_handler.error; | 161 | int err = foo->ctrl_handler.error; |
@@ -164,6 +179,12 @@ controls. There is no min argument since that is always 0 for menu controls, | |||
164 | and instead of a step there is a skip_mask argument: if bit X is 1, then menu | 179 | and instead of a step there is a skip_mask argument: if bit X is 1, then menu |
165 | item X is skipped. | 180 | item X is skipped. |
166 | 181 | ||
182 | The v4l2_ctrl_new_int_menu function creates a new standard integer menu | ||
183 | control with driver-specific items in the menu. It differs from | ||
184 | v4l2_ctrl_new_std_menu in that it doesn't have the mask argument and takes | ||
185 | as the last argument an array of signed 64-bit integers that form an exact | ||
186 | menu item list. | ||
187 | |||
167 | Note that if something fails, the function will return NULL or an error and | 188 | Note that if something fails, the function will return NULL or an error and |
168 | set ctrl_handler->error to the error code. If ctrl_handler->error was already | 189 | set ctrl_handler->error to the error code. If ctrl_handler->error was already |
169 | set, then it will just return and do nothing. This is also true for | 190 | set, then it will just return and do nothing. This is also true for |
diff --git a/drivers/media/video/v4l2-ctrls.c b/drivers/media/video/v4l2-ctrls.c index 9bd8a92419e1..fdcb9e21d9d3 100644 --- a/drivers/media/video/v4l2-ctrls.c +++ b/drivers/media/video/v4l2-ctrls.c | |||
@@ -1544,6 +1544,27 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl, | |||
1544 | } | 1544 | } |
1545 | EXPORT_SYMBOL(v4l2_ctrl_new_std_menu); | 1545 | EXPORT_SYMBOL(v4l2_ctrl_new_std_menu); |
1546 | 1546 | ||
1547 | /* Helper function for standard integer menu controls */ | ||
1548 | struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl, | ||
1549 | const struct v4l2_ctrl_ops *ops, | ||
1550 | u32 id, s32 max, s32 def, const s64 *qmenu_int) | ||
1551 | { | ||
1552 | const char *name; | ||
1553 | enum v4l2_ctrl_type type; | ||
1554 | s32 min; | ||
1555 | s32 step; | ||
1556 | u32 flags; | ||
1557 | |||
1558 | v4l2_ctrl_fill(id, &name, &type, &min, &max, &step, &def, &flags); | ||
1559 | if (type != V4L2_CTRL_TYPE_INTEGER_MENU) { | ||
1560 | handler_set_err(hdl, -EINVAL); | ||
1561 | return NULL; | ||
1562 | } | ||
1563 | return v4l2_ctrl_new(hdl, ops, id, name, type, | ||
1564 | 0, max, 0, def, flags, NULL, qmenu_int, NULL); | ||
1565 | } | ||
1566 | EXPORT_SYMBOL(v4l2_ctrl_new_int_menu); | ||
1567 | |||
1547 | /* Add a control from another handler to this handler */ | 1568 | /* Add a control from another handler to this handler */ |
1548 | struct v4l2_ctrl *v4l2_ctrl_add_ctrl(struct v4l2_ctrl_handler *hdl, | 1569 | struct v4l2_ctrl *v4l2_ctrl_add_ctrl(struct v4l2_ctrl_handler *hdl, |
1549 | struct v4l2_ctrl *ctrl) | 1570 | struct v4l2_ctrl *ctrl) |
diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h index 5edd64daa425..776605f1cbe2 100644 --- a/include/media/v4l2-ctrls.h +++ b/include/media/v4l2-ctrls.h | |||
@@ -351,6 +351,23 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl, | |||
351 | const struct v4l2_ctrl_ops *ops, | 351 | const struct v4l2_ctrl_ops *ops, |
352 | u32 id, s32 max, s32 mask, s32 def); | 352 | u32 id, s32 max, s32 mask, s32 def); |
353 | 353 | ||
354 | /** v4l2_ctrl_new_int_menu() - Create a new standard V4L2 integer menu control. | ||
355 | * @hdl: The control handler. | ||
356 | * @ops: The control ops. | ||
357 | * @id: The control ID. | ||
358 | * @max: The control's maximum value. | ||
359 | * @def: The control's default value. | ||
360 | * @qmenu_int: The control's menu entries. | ||
361 | * | ||
362 | * Same as v4l2_ctrl_new_std_menu(), but @mask is set to 0 and it additionaly | ||
363 | * takes as an argument an array of integers determining the menu items. | ||
364 | * | ||
365 | * If @id refers to a non-integer-menu control, then this function will return NULL. | ||
366 | */ | ||
367 | struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl, | ||
368 | const struct v4l2_ctrl_ops *ops, | ||
369 | u32 id, s32 max, s32 def, const s64 *qmenu_int); | ||
370 | |||
354 | /** v4l2_ctrl_add_ctrl() - Add a control from another handler to this handler. | 371 | /** v4l2_ctrl_add_ctrl() - Add a control from another handler to this handler. |
355 | * @hdl: The control handler. | 372 | * @hdl: The control handler. |
356 | * @ctrl: The control to add. | 373 | * @ctrl: The control to add. |