Skip to contentSkip to conversation

Add private controls to ctrl_handler

DISCUSSION Tom 2 participants 4 messages Jan 6, 2014 – Jan 7, 2014 Media (V4L/DVB)

lore
Share & tools
lore

Tom

author
#0 lore raw

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

author
#1 lore raw

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

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

Best Regards, Tom

#2 lore raw
In reply to Tom
Quoted 7 lines · Tom

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

Quoted 106 lines

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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#3 lore raw
Quoted 5 lines · 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.

Quoted 1 line

If you want to upstream the code, then you should define a range for the

private

Quoted 1 line

controls of this driver in v4l2-controls.h. Search for e.g.

V4L2_CID_USER_S2255_BASE

Quoted 6 lines

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