赞
踩
V4L2 PCI驱动实例控制框架
译注:在图像传输开始后,会有各种各样的控制参数需要下发给硬件,譬如brightness, contrast等。
首先,要增加如下的控制处理回调函数,一些芯片厂商把kernel驱动做小,很多就依赖event机制在userspace侧处理。
- #include <media/v4l2-ctrls.h>
- #include <media/v4l2-event.h>
- struct skeleton {
- ...
- struct v4l2_ctrl_handler ctrl_handler;
- ...
- };
- static const struct v4l2_ctrl_ops skel_ctrl_ops = {
- .s_ctrl = skeleton_s_ctrl,
- };
- static const struct v4l2_ioctl_ops skel_ioctl_ops = {
- ...
- .vidioc_log_status = v4l2_ctrl_log_status,
- .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
- .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
- };
- static int skeleton_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
- {
- ...
- struct v4l2_ctrl_handler *hdl;
- ...
- hdl = &skel->ctrl_handler;
- v4l2_ctrl_handler_init(hdl, 4);
- v4l2_ctrl_new_std(hdl, &skel_ctrl_ops,
- V4L2_CID_BRIGHTNESS, 0, 255, 1, 127);
- v4l2_ctrl_new_std(hdl, &skel_ctrl_ops,
- V4L2_CID_CONTRAST, 0, 255, 1, 16);
- v4l2_ctrl_new_std(hdl, &skel_ctrl_ops,
- V4L2_CID_SATURATION, 0, 255, 1, 127);
- v4l2_ctrl_new_std(hdl, &skel_ctrl_ops,
- V4L2_CID_HUE, -128, 127, 1, 0);
- if (hdl->error) {
- ret = hdl->error;
- goto free_hdl;
- }
- skel->v4l2_dev.ctrl_handler = hdl;
- ...
- free_hdl:
- v4l2_ctrl_handler_free(&skel->ctrl_handler);
- v4l2_device_unregister(&skel->v4l2_dev);
- disable_pci:
- pci_disable_device(pdev);
- return ret;
- }
- static int skeleton_s_ctrl(struct v4l2_ctrl *ctrl)
- {
- struct skeleton *skel =
- container_of(ctrl->handler, struct skeleton, ctrl_handler);
- switch (ctrl->id) {
- case V4L2_CID_BRIGHTNESS:
- /* TODO: set brightness to ctrl->val */
- break;
- case V4L2_CID_CONTRAST:
- /* TODO: set contrast to ctrl->val */
- break;
- case V4L2_CID_SATURATION:
- /* TODO: set saturation to ctrl->val */
- break;
- case V4L2_CID_HUE:
- /* TODO: set hue to ctrl->val */
- break;
- default:
- return -EINVAL;
- }
- return 0;
- }
控制框架总结
●可以继承其他控制处理程序的控件,特别是从子设备v4l2_subdev继承。
●如果必须将控件设置在一起,则控件可以组合到集群。
●验证和原子性由v4l2框架处理。
●与事件处理集成以允许控制事件(即,当控件更改值或状态时获取事件)。
●当子设备的控制更改时,可以通知桥接驱动程序。
●支持自动群集。例如:AUTOGAIN和GAIN控件。
●可以在v4l2_device级别,在video_device级别或v4l2_fh级别设置控制处理程序。 在子设备中,控制处理程序总是处于v4l2_subdev级别。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。