当前位置: 首页 > news >正文

andorid之摄像头驱动流程--MTK平台

camera成像原理:

景物通过镜头生产光学图像投射到sensor表面上,然后转为模拟电信号,经过数模变成数字图像信号,在经过DSP加工出来,然后在通过IO接口传输到CPU处理。  由于摄像头满足总线、驱动、设备模型,那么看看andorid是怎么去实现摄像头的流程。

1.  注册Camera的platform平台设备

点击(此处)折叠或打开

  1. CAMERA_HW_i2C_init
  2. platform_driver_register(&g_stCAMERA_HW_Driver)
  3. static struct platform_driver g_stCAMERA_HW_Driver = {
  4. .probe        = CAMERA_HW_probe,
  5. .remove     = CAMERA_HW_remove,
  6. .suspend    = CAMERA_HW_suspend,
  7. .resume     = CAMERA_HW_resume,
  8. .driver        = {
  9. .name    = "image_sensor",
  10. .owner    = THIS_MODULE,
  11. }
  12. };

2.  注册Camera的platform平台设备驱动

点击(此处)折叠或打开

  1. platform_device_register(&sensor_dev);
  2. static struct platform_device sensor_dev = {
  3. .name         = "image_sensor",
  4. .id         = -1,
  5. };

在    在mt6575_board_init这个函数中注册了很多平台设备,包括上面的平台设备。camera的平台设备与平台驱动匹配后,就会调用drv的probe函数,其probe函数主要完成的是i2c平台驱动的注册

点击(此处)折叠或打开

  1. static int CAMERA_HW_probe(struct platform_device *pdev)
  2. {
  3. return i2c_add_driver(&CAMERA_HW_i2c_driver);
  4. }
  5. struct i2c_driver CAMERA_HW_i2c_driver = {
  6. .probe = CAMERA_HW_i2c_probe,
  7. .remove = CAMERA_HW_i2c_remove,
  8. .detect = CAMERA_HW_i2c_detect,
  9. .driver.name = CAMERA_HW_DRVNAME,
  10. .id_table = CAMERA_HW_i2c_id,
  11. .address_data = &addr_data,
  12. };

怎么去做i2c驱动与设备的匹配呢?内核中对于这块有详细的讲解,文件为instantiating-devices,现在i2c的平台驱动已经注册了,下面来分析下是怎么注册平台设备的。应该使用内核的第3种方法,在内核注册i2c驱动的时候,最终会遍历总线设备的driver成员,调用__attach_adapter函数。

点击(此处)折叠或打开

  1. static int __attach_adapter(struct device *dev, void *data)
  2. {
  3. struct i2c_adapter *adapter;
  4. struct i2c_driver *driver = data;
  5. if (dev->type != &i2c_adapter_type)
  6. return 0;
  7. adapter = to_i2c_adapter(dev);
  8. i2c_detect(adapter, driver);
  9. /* Legacy drivers scan i2c busses directly */
  10. if (driver->attach_adapter)
  11. driver->attach_adapter(adapter);
  12. return 0;
  13. }

这个函数最主要的是调用了CAMERA_HW_i2c_driver的detect函数,完成设备与驱动的匹配,最终会调用CAMERA_HW_i2c_probe。

点击(此处)折叠或打开

  1. static int CAMERA_HW_i2c_detect(struct i2c_client *client, int kind, struct i2c_board_info*info)
  2. {
  3. strcpy(info->type, CAMERA_HW_DRVNAME);
  4. return 0;
  5. }

在probe函数中最只做了一件事件RegisterCAMERA_HWCharDrv,这个函数会注册字符设备,注册设备节点,并在设备节点下创建类,重点的东西出现了

点击(此处)折叠或打开

  1. static const struct file_operations g_stCAMERA_HW_fops =
  2. {
  3. .owner = THIS_MODULE,
  4. .open = CAMERA_HW_Open,
  5. .release = CAMERA_HW_Release,
  6. #ifdef USE_NEW_IOCTL
  7. .unlocked_ioctl = CAMERA_HW_Ioctl
  8. #else
  9. .ioctl = CAMERA_HW_Ioctl
  10. #endif
  11. };

Open只是初始化一个原子变量留给系统调用,ioctrl才是核心,CAMERA_HW_Ioctl是上层文件操作底层硬件的方法。以上是andorid上摄像头i2c设备的过程。

http://www.lryc.cn/news/68329.html

相关文章:

  • Android9.0 iptables用INetd实现屏蔽ip黑名单的实现
  • 介绍一下json
  • DI依赖注入环境
  • 《程序员面试金典(第6版)》面试题 16.18. 模式匹配(暴力破解 + 剪枝)
  • 一天吃透SpringCloud面试八股文
  • java生成图片缩略图
  • 《统计学习方法》——隐马尔可夫模型(下)
  • Liunx top 命令详解
  • 基于 SpringBoot 的医院固定资产系统
  • 【企业信息化】第2集 免费开源ERP: Odoo 16 销售管理系统
  • 浅谈数据治理
  • Matlab入门教程003|MATLAB变量|MATLAB命令
  • 【啃书C++Primer5】-编写一个简单C++程序
  • GoView 是一个Vue3搭建的低代码数据可视化开发平台
  • 【面试篇】Redis持久化面试题
  • 哈工大软件过程与工具作业2
  • SDN控制器三平面(软件定义网络、OOB)
  • 嘉兴桐乡会计考证实操-考初级会计真的有用吗?
  • 约翰霍普金斯大学诺奖得主涉嫌造假,撤回5篇PNAS论文
  • React的表单数据绑定
  • Dubbo——微服务框架(单体式->分布式->微服务)
  • 【Spring Cloud】Feign传递HttpServletRequest
  • 烟火识别智能监测系统 yolov5
  • 【Python入门】Python循环语句(while循环的基础语法)
  • JS中 Math 和 Number 内置对象常用的一些方法
  • Docker的使用 (1.什么是docker)
  • ENVI无缝镶嵌Seamless Mosaic工具镶嵌、拼接栅格遥感影像(所有图像需要含有地理信息)
  • Java-API简析_java.lang.Integer类(基于JDK1.8)(浅析源码)
  • WebSocket的那些事(3-STOMP实操篇)
  • 《花雕学AI》WeTab+ChatGPT:让浏览器变成你的智能助手