linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Add private controls to ctrl_handler
@ 2014-01-06 14:30 Tom
  2014-01-06 14:36 ` Tom
  2014-01-06 14:39 ` Hans Verkuil
  0 siblings, 2 replies; 4+ messages in thread
From: Tom @ 2014-01-06 14:30 UTC (permalink / raw)
  To: linux-media

Hello,

I want to add some driver specific ctrls to my ctrl-handler which are not
defined in the "/include/uapi/linux/v4l2-controls.h".
I read that I would need the "V4L2_CID_PRIVATE_BASE" to define the new IDs,
but I don't get how I can add them to my ctrl-handler so that they are
accessible by calling VIDIOC_S_CTRL. 

Can someone give me a hint how I can add my own controls to my ctrl-handler?

what I tried:

#define V4L2_SENS_TEST1			(V4L2_CID_PRIVATE_BASE + 1)
#define V4L2_SENS_TEST2			(V4L2_CID_PRIVATE_BASE + 2)
#define V4L2_SENS_TEST3			(V4L2_CID_PRIVATE_BASE + 3)

static int ov3640_probe(struct i2c_client *client,
			const struct i2c_device_id *id)
{
				.
				.
				.
//I can add the standard controls as usual...

	v4l2_ctrl_handler_init(&ov3640->ctrl_handler, 19);

	v4l2_ctrl_new_std(&ov3640->ctrl_handler, &ov3640_ctrl_ops,
			V4L2_CID_BRIGHTNESS, -48, 48, 1, 0);
	v4l2_ctrl_new_std(&ov3640->ctrl_handler, &ov3640_ctrl_ops,
			V4L2_CID_CONTRAST, -12, 12, 1, 0);
	v4l2_ctrl_new_std(&ov3640->ctrl_handler, &ov3640_ctrl_ops,
			V4L2_CID_SATURATION, -32, 32, 1, 0);
				.
				.
				.
//so far so good...

	v4l2_ctrl_new_std(&ov3640->ctrl_handler, &ov3640_ctrl_ops,
			V4L2_SENS_TEST1, 0, 1, 1, 0);
	v4l2_ctrl_new_std(&ov3640->ctrl_handler, &ov3640_ctrl_ops,
			V4L2_SENS_TEST2, 0, 1, 1, 0);
	v4l2_ctrl_new_std(&ov3640->ctrl_handler, &ov3640_ctrl_ops,
			V4L2_SENS_TEST3, 0, 1, 1, 0);

//but I cannot add these three controls like this. 

	if (ov3640->ctrl_handler.error) {
		dev_err(&client->dev, "control initialization error %d\n",
			ov3640->ctrl_handler.error);
		ret = ov3640->ctrl_handler.error;
		goto done;
	}

//the ctrl-handler will give me an ERROR back when adding these 3 controls

}

static int ov3640_ctrl(struct v4l2_ctrl *ctrl, int command)
{
	struct ov3640 *ov3640 = container_of(ctrl->handler, struct ov3640,
ctrl_handler);
	int ret = 0;

	switch (ctrl->id) {
	case V4L2_CID_BRIGHTNESS:
		ret = ov3640_set_brightness(ov3640, ctrl->val, command);
		break;
	case V4L2_CID_CONTRAST:
		ret = ov3640_set_contrast(ov3640, ctrl->val, command);
		break;
	case V4L2_CID_SATURATION:
		ret = ov3640_set_saturation(ov3640, ctrl->val, command);
		break;
	case V4L2_SENS_TEST1://!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	case V4L2_SENS_TEST2://!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	case V4L2_SENS_TEST3://!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
		ret = ov3640_test(ov3640, ctrl->val, ctrl->id, command);
		break;
	}

	return ret;
}

static int ov3640_set_ctrl(struct v4l2_ctrl *ctrl)
{
	int ret;
	int command = SET_DATA;

	ret = ov3640_ctrl(ctrl, command);
	return ret;
}

static int ov3640_get_ctrl(struct v4l2_ctrl *ctrl)
{
	int ret;
	int command = GET_DATA;

	ret = ov3640_ctrl(ctrl, command);
	return ret;
}

static struct v4l2_ctrl_ops ov3640_ctrl_ops = {
	.s_ctrl = ov3640_set_ctrl,
	.g_volatile_ctrl = ov3640_get_ctrl,
};

Best Regards, Tom


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Add private controls to ctrl_handler
  2014-01-06 14:30 Add private controls to ctrl_handler Tom
@ 2014-01-06 14:36 ` Tom
  2014-01-06 14:39 ` Hans Verkuil
  1 sibling, 0 replies; 4+ messages in thread
From: Tom @ 2014-01-06 14:36 UTC (permalink / raw)
  To: linux-media

Tom <Bassai_Dai <at> gmx.net> writes:

sorry I forgot to tell that I am using linux version 3.10.

Best Regards, Tom



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Add private controls to ctrl_handler
  2014-01-06 14:30 Add private controls to ctrl_handler Tom
  2014-01-06 14:36 ` Tom
@ 2014-01-06 14:39 ` Hans Verkuil
  2014-01-07  8:15   ` Tom
  1 sibling, 1 reply; 4+ messages in thread
From: Hans Verkuil @ 2014-01-06 14:39 UTC (permalink / raw)
  To: Tom; +Cc: linux-media

On 01/06/2014 03:30 PM, Tom wrote:
> Hello,
> 
> I want to add some driver specific ctrls to my ctrl-handler which are not
> defined in the "/include/uapi/linux/v4l2-controls.h".
> I read that I would need the "V4L2_CID_PRIVATE_BASE" to define the new IDs,
> but I don't get how I can add them to my ctrl-handler so that they are
> accessible by calling VIDIOC_S_CTRL. 

Don't use V4L2_CID_PRIVATE_BASE, that doesn't work with the control framework
(for good but somewhat obscure reasons).

Instead use (V4L2_CID_USER_BASE | 0x1000) as the base for your private controls.
If you want to upstream the code, then you should define a range for the private
controls of this driver in v4l2-controls.h. Search for e.g. V4L2_CID_USER_S2255_BASE
in that header to see how it is done.

Regards,

	Hans

> 
> Can someone give me a hint how I can add my own controls to my ctrl-handler?
> 
> what I tried:
> 
> #define V4L2_SENS_TEST1			(V4L2_CID_PRIVATE_BASE + 1)
> #define V4L2_SENS_TEST2			(V4L2_CID_PRIVATE_BASE + 2)
> #define V4L2_SENS_TEST3			(V4L2_CID_PRIVATE_BASE + 3)
> 
> static int ov3640_probe(struct i2c_client *client,
> 			const struct i2c_device_id *id)
> {
> 				.
> 				.
> 				.
> //I can add the standard controls as usual...
> 
> 	v4l2_ctrl_handler_init(&ov3640->ctrl_handler, 19);
> 
> 	v4l2_ctrl_new_std(&ov3640->ctrl_handler, &ov3640_ctrl_ops,
> 			V4L2_CID_BRIGHTNESS, -48, 48, 1, 0);
> 	v4l2_ctrl_new_std(&ov3640->ctrl_handler, &ov3640_ctrl_ops,
> 			V4L2_CID_CONTRAST, -12, 12, 1, 0);
> 	v4l2_ctrl_new_std(&ov3640->ctrl_handler, &ov3640_ctrl_ops,
> 			V4L2_CID_SATURATION, -32, 32, 1, 0);
> 				.
> 				.
> 				.
> //so far so good...
> 
> 	v4l2_ctrl_new_std(&ov3640->ctrl_handler, &ov3640_ctrl_ops,
> 			V4L2_SENS_TEST1, 0, 1, 1, 0);
> 	v4l2_ctrl_new_std(&ov3640->ctrl_handler, &ov3640_ctrl_ops,
> 			V4L2_SENS_TEST2, 0, 1, 1, 0);
> 	v4l2_ctrl_new_std(&ov3640->ctrl_handler, &ov3640_ctrl_ops,
> 			V4L2_SENS_TEST3, 0, 1, 1, 0);
> 
> //but I cannot add these three controls like this. 
> 
> 	if (ov3640->ctrl_handler.error) {
> 		dev_err(&client->dev, "control initialization error %d\n",
> 			ov3640->ctrl_handler.error);
> 		ret = ov3640->ctrl_handler.error;
> 		goto done;
> 	}
> 
> //the ctrl-handler will give me an ERROR back when adding these 3 controls
> 
> }
> 
> static int ov3640_ctrl(struct v4l2_ctrl *ctrl, int command)
> {
> 	struct ov3640 *ov3640 = container_of(ctrl->handler, struct ov3640,
> ctrl_handler);
> 	int ret = 0;
> 
> 	switch (ctrl->id) {
> 	case V4L2_CID_BRIGHTNESS:
> 		ret = ov3640_set_brightness(ov3640, ctrl->val, command);
> 		break;
> 	case V4L2_CID_CONTRAST:
> 		ret = ov3640_set_contrast(ov3640, ctrl->val, command);
> 		break;
> 	case V4L2_CID_SATURATION:
> 		ret = ov3640_set_saturation(ov3640, ctrl->val, command);
> 		break;
> 	case V4L2_SENS_TEST1://!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
> 	case V4L2_SENS_TEST2://!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
> 	case V4L2_SENS_TEST3://!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
> 		ret = ov3640_test(ov3640, ctrl->val, ctrl->id, command);
> 		break;
> 	}
> 
> 	return ret;
> }
> 
> static int ov3640_set_ctrl(struct v4l2_ctrl *ctrl)
> {
> 	int ret;
> 	int command = SET_DATA;
> 
> 	ret = ov3640_ctrl(ctrl, command);
> 	return ret;
> }
> 
> static int ov3640_get_ctrl(struct v4l2_ctrl *ctrl)
> {
> 	int ret;
> 	int command = GET_DATA;
> 
> 	ret = ov3640_ctrl(ctrl, command);
> 	return ret;
> }
> 
> static struct v4l2_ctrl_ops ov3640_ctrl_ops = {
> 	.s_ctrl = ov3640_set_ctrl,
> 	.g_volatile_ctrl = ov3640_get_ctrl,
> };
> 
> Best Regards, Tom
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Add private controls to ctrl_handler
  2014-01-06 14:39 ` Hans Verkuil
@ 2014-01-07  8:15   ` Tom
  0 siblings, 0 replies; 4+ messages in thread
From: Tom @ 2014-01-07  8:15 UTC (permalink / raw)
  To: linux-media

Hans Verkuil <hverkuil <at> xs4all.nl> writes:

> 
> Don't use V4L2_CID_PRIVATE_BASE, that doesn't work with the control framework
> (for good but somewhat obscure reasons).
> 
> Instead use (V4L2_CID_USER_BASE | 0x1000) as the base for your private
controls.
> If you want to upstream the code, then you should define a range for the
private
> controls of this driver in v4l2-controls.h. Search for e.g.
V4L2_CID_USER_S2255_BASE
> in that header to see how it is done.
> 
> Regards,
> 
> 	Hans
> 

thanks for your help. It worked for me with "(V4L2_CID_USER_BASE | 0x1000)"
base and the "v4l2_ctrl_new_custom" function.

Regards, Tom


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-01-07  8:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-06 14:30 Add private controls to ctrl_handler Tom
2014-01-06 14:36 ` Tom
2014-01-06 14:39 ` Hans Verkuil
2014-01-07  8:15   ` Tom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).