camera成像原理:
景物通过镜头生产光学图像投射到sensor表面上,然后转为模拟电信号,经过数模变成数字图像信号,在经过DSP加工出来,然后在通过IO接口传输到CPU处理。 由于摄像头满足总线、驱动、设备模型,那么看看andorid是怎么去实现摄像头的流程。
1. 注册Camera的platform平台设备
点击(
此处)折叠或打开
- CAMERA_HW_i2C_init
- platform_driver_register(&g_stCAMERA_HW_Driver)
- static struct platform_driver g_stCAMERA_HW_Driver = {
- .probe = CAMERA_HW_probe,
- .remove = CAMERA_HW_remove,
- .suspend = CAMERA_HW_suspend,
- .resume = CAMERA_HW_resume,
- .driver = {
- .name = "image_sensor",
- .owner = THIS_MODULE,
- }
- };
2. 注册Camera的platform平台设备驱动
点击(
此处)折叠或打开
- platform_device_register(&sensor_dev);
- static struct platform_device sensor_dev = {
- .name = "image_sensor",
- .id = -1,
- };
在 在mt6575_board_init这个函数中注册了很多平台设备,包括上面的平台设备。camera的平台设备与平台驱动匹配后,就会调用drv的probe函数,其probe函数主要完成的是i2c平台驱动的注册
点击(
此处)折叠或打开
- static int CAMERA_HW_probe(struct platform_device *pdev)
- {
- return i2c_add_driver(&CAMERA_HW_i2c_driver);
- }
- struct i2c_driver CAMERA_HW_i2c_driver = {
- .probe = CAMERA_HW_i2c_probe,
- .remove = CAMERA_HW_i2c_remove,
- .detect = CAMERA_HW_i2c_detect,
- .driver.name = CAMERA_HW_DRVNAME,
- .id_table = CAMERA_HW_i2c_id,
- .address_data = &addr_data,
- };
怎么去做i2c驱动与设备的匹配呢?内核中对于这块有详细的讲解,文件为instantiating-devices,现在i2c的平台驱动已经注册了,下面来分析下是怎么注册平台设备的。应该使用内核的第3种方法,在内核注册i2c驱动的时候,最终会遍历总线设备的driver成员,调用__attach_adapter函数。
点击(
此处)折叠或打开
- static int __attach_adapter(struct device *dev, void *data)
- {
- struct i2c_adapter *adapter;
- struct i2c_driver *driver = data;
- if (dev->type != &i2c_adapter_type)
- return 0;
- adapter = to_i2c_adapter(dev);
- i2c_detect(adapter, driver);
- /* Legacy drivers scan i2c busses directly */
- if (driver->attach_adapter)
- driver->attach_adapter(adapter);
- return 0;
- }
这个函数最主要的是调用了CAMERA_HW_i2c_driver的detect函数,完成设备与驱动的匹配,最终会调用CAMERA_HW_i2c_probe
。
点击(
此处)折叠或打开
- static int CAMERA_HW_i2c_detect(struct i2c_client *client, int kind, struct
i2c_board_info *info)
- {
- strcpy(info->type, CAMERA_HW_DRVNAME);
- return 0;
- }
在probe函数中最只做了一件事件RegisterCAMERA_HWCharDrv,这个函数会注册字符设备,注册设备节点,并在设备节点下创建类,重点的东西出现了
点击(
此处)折叠或打开
- static const struct file_operations g_stCAMERA_HW_fops =
- {
- .owner = THIS_MODULE,
- .open = CAMERA_HW_Open,
- .release = CAMERA_HW_Release,
- #ifdef USE_NEW_IOCTL
- .unlocked_ioctl = CAMERA_HW_Ioctl
- #else
- .ioctl = CAMERA_HW_Ioctl
- #endif
- };
Open只是初始化一个原子变量留给系统调用,ioctrl才是核心,CAMERA_HW_Ioctl是上层文件操作底层硬件的方法。以上是andorid上摄像头i2c设备的过程。