本文共 6752 字,大约阅读时间需要 22 分钟。
转自http://blog.csdn.net/yushuang20140403/article/details/23907159
前言
8926平台的sensor架构与之前的平台完全不同,实际上已经脱离了linux。此平台所有的sensor由adsp芯片控制,代码在modem端,编译和烧录也完全不同,下面以TSL2581为例进行说明。 一、 驱动 集成光传感器TSL2581 1. 驱动程序结构可以参考高通默认的光感驱动文件sns_dd_als_bh1721.c或sns_dd_als_max44009.c或sns_dd_alsprx_tmd277x.c,主要是填充结构体 sns_ddf_driver_if_s;其成员: init, reset, get_data, set_attrib, get_attrib, 必须填充,因为sns_smgr_dd_init()对这它们进行检查; 另外probe成员也要填充,因为sns_smgr_parse_reg_devinfo_resp()中代码逻辑有问题,当probe为NULL时,只会填充第一个此类型的sensor的配置。 2. 寄存器配置,电路参考设计要查看 TSL2581的数据手册; 3. TSL2581 和 TMD277X都是TAOS公司的,参考它写最好。如果可以从fae获取驱动代码更好,基本不需要修改,改正编译错误之后就可以使用。 由于芯片在电路板的方向不同,G-sensor,gyro和compass需要调换x、y、z轴的映射,只需在sensor_def_qcomdev.conf文件中修改。 二、 移植 参考高通文档“80-N7635-1_E_Snapdragon_Sensors_Core_New_Sensor_Driver_Integration_LA.pdf” 1. Add the entry function for the new driver in adsp_proc\sensors\dd\qcom\inc\sns_dd.h: extern sns_ddf_driver_if_s sns_als_tsl2581_driver_fn_list; 2. Add the new driver files in adsp_proc\sensors\dd\qcom\src in the ADSP build sns_dd_als_tsl2581.h sns_dd_als_tsl2581.c 3. update the adsp_proc\sensors\dd\qcom\build\dd_qcom.scons file; "${BUILDPATH}/sns_dd_als_tsl2581.c", 4. Configure Sensors.scons to compile the new files. To include the driver, in adsp_proc\sensors\build\Sensors.scons, add: env.Append(CPPDEFINES = ["CONFIG_SUPPORT_TSL2581"]) 5.Update the sns_reg_common.h files on both the ADSP and APSS builds to add UUID: UUID可以使用在终端使用命令生成:uuidgen ADSP – adsp_proc\Sensors\common\inc\sns_reg_common.h APSS – android\vendor\qcom\proprietary\sensors\dsps\sensordaemon\common\inc\ sns_reg_common.h #define SNS_REG_UUID_TSL2581 \ {0x84,0x2a,0xad,0xa7,0xc5,0x9b,0x4c,0x07,0xa2,0xf9,0xc8,0x2a,0xe4,0x03,0x43,0xa6} APSS端主要是为了调试使用,实际的驱动中不加也可以。 6. Update the SMGR function pointer map so that the SMGR can associate the new UUID with the new DD function pointer. In adsp_proc/Sensors/smgr/src/common/sns_smgr_init.c,update smgr_sensor_fn_ptr_map[]: #ifdef CONFIG_SUPPORT_TSL2581 { SNS_REG_UUID_TSL2581, &sns_als_tsl2581_driver_fn_list}, #endif 7. Update the configuration file "sensor_def_qcomdev.conf": 在对应的硬件、平台后面修改,1966,1967是ALS/PROX sensor的UUID,1976是从设备地址,一般添加新sensor只修改这三项,其它项使用默认值。 1967 0xa64303e42ac8f9a2 0x00010001 1966 0x074c9bc5a7ad2a84 0x00010001 1976 0x39 0x00010001 例如:sensor_def_qcomdev.conf的内容形如: ######################################################################## :hardware 8974 :platform :property :soc_id 1903 0x8d79ae42524820ad 0x00010001 1902 0xcc4575757b462d60 0x00010001 1906 12 0x00010001 :hardware 8226 :platform 1903 0x8d79ae42524820ad 0x00010001 1902 0xcc4575757b462d60 0x00010001 1906 12 0x00010001 :platform SKUG 1903 0x8d79ae42524820ad 0x00010001 1902 0xcc4575757b462d60 0x00010001 1906 12 0x00010001 ######################################################################## 我的hardware 属于8226,platform属于 SKUG,我就要在最下面添加。 关于sensor_def_qcomdev.conf中每一项代表的内容定义在vendor/qcom/proprietary/sensors/dsps/api/sns_reg_api_v02.h中。 下面列举常用项: 700,701,702 G-sensor的轴映射 800,801,802 gyro的轴映射 900,901,902 compass的轴映射 3801 是否使用高通compass校准库,1表示使用,0表示不使用 1900 是否支持兼容,0表示支持,1表示不支持 不支持兼容时的配置起始地址: 1902 Accelerometer 1918 Gyroscope 1934 Magnetometer 1950 Pressure 1966 Proximity/Ambient Light 兼容时的配置起始地址: 以ALS/PROX为例: 2300 1 //这一项配置为1,表示支持距离光感兼容功能 2301 2 //这一项配置为2,表示支持两种距离光感芯片 2302-2312 这是第一种芯片的配置 2313-2323 这是第二种芯片的配置 注意:这里的选项顺序和只支持一个芯片的顺序的不同 可以参看vendor/qcom/proprietary/sensors/dsps/api/sns_reg_api_v02.h,里面的代码比较易懂。 三、编译下载 0. 只需要在modem端编译,先编译adsp_proc,再编译NON-HLOS。 1. Push the updated sensor_def_qcomdev.conf file to the /etc/ directory of the hardware: >>adb push sensor_def_qcomdev.conf /etc/ >>adb shell chmod 644 /etc/sensor_def_qcomdev.conf 2. remove the existing registry file "sns.reg" from the /data/misc/sensors/ directory >>adb shell rm /data/misc/sensors/sns.reg >>adb shell sync >>adb reboot 3. compilation completes successfully, (1)To load the ADSP image(adsp.b00...adsp.mdt) to the /firmware/image/ directory of the hardware >>adb root >>adb remount >>adb shell mount -o remount rw /firmware >>adb push adsp.b00 firmware/image : : >>adb push adsp.mdt firmware/image 开始我按照高通文档下载到/etc/frimware/,也起作用,后来高通工程师告诉我应该下载到firmware/image/ 需要强制修改权限: >>adb shell mount -o remount rw /firmware (2)第一种下载方法太麻烦,直接下载NON-HLOS.bin: >>adb reboot bootloader >>fastboot flash modem NON-HLOS.bin >>fastboot reboot 四、调试 1.调试主要依靠QXDM抓取log,由于init函数和probe函数是在手机与QXDM建立连接之前完成的,QXDM无法打印里面的log,所以我们一般加入全局变量,然后在其他已确定肯定会执行的函数中打印出来,比如其它已正常工作的sensor的get data函数,记得打开打印log的宏。 2. 编译下载完成后开机,先导出sns.reg, >>adb pull data/misc/sensors/sns.reg 然后使用 Ultraedit 打开sns.reg查看是否将sensor_def_qcomdev.conf中添加的UUID解析成功。 对应关系如下: sensor sensor_def_qcomdev.conf sns.reg accel 1903 1902 1710h gyro 1918 1919 1740h Magnetometer 1934 1935 1770h Pressure 1951 1950 17a0h als+prox 1967 1966 17d0h 没成功的原因: 1. sensor_def_qcomdev.conf的权限没有修改。 请重新执行步骤三的2和3 2. 在移植第7步中添加位置错误,请确认硬件,平台 3. 使用sns_cm_test工具测试: >>adb shell >>cd /system/bin/ >>sns_cm_test -r 20 -d 1 -s 40 -t 1 参数说明: -r代表rate, 其它sensor测试命令: sns_cm_test -r 20 -d 1 -s 40 -t 0 测试prox sns_cm_test -r 20 -d 1 -s 0 测试G-sensor sns_cm_test -r 20 -d 1 -s 10 测试GYRO sns_cm_test -r 20 -d 1 -s 20 测试MAG sns_cm_test -r 20 -d 1 -s 30 测试PRESS (1) 如果提示没有sns_cm_test命令,可能是被你们公司去掉默认编译了,可以手动编译,然后倒入手机的/system/bin/ 执行如下命令: >>. build/envsetup.sh >>choosecombo 1 1 2 >>make sns_cm_test -j4 其中第二条命令是我们公司这个项目的选项,没有可以不执行 (2) 如果提示参数不正确,那就需要修改vendor/qcom/proprietary/sensors/dsps/test/src/sns_cm_test.c 文件,将光感的测试添加进去,按下面修改,重新编译即可,然后执行(1) int main( int argc, char * const argv[]) { sensor1_handle_s *hndl1; int rate = 30; int duration = 1; int sensor_id = SNS_SMGR_ID_ACCEL_V01; int data_type = SNS_SMGR_DATA_TYPE_PRIMARY_V01; int opt; // socketpair( AF_UNIX, SOCK_SEQPACKET, 0, socket_pair ); while( (opt = getopt(argc, argv, "r:h:d:s:t:" ))!= -1 ) { switch(opt) { ... case 's': sensor_id = atoi(optarg); break; case 't': data_type = atoi(optarg); break; case '?': fprintf(stderr, usage_fmt, argv[0]); exit(0); default: break; } } ... smgr_req->Item[0].SensorId = sensor_id; printf("Asking sensor data with type %d",data_type); smgr_req->Item[0].DataType = data_type; ... (3)此命令 会测试光sensor,打印出ID,TYPE和数值等,如果没有说明集成失败。可能原因,硬件或驱动代码问题。 (4)软件检查: a.初始化是否成功; b.i2c地址冲突; c.读写寄存器是否成功,数值是否正确; d.相关函数是否调用,执行; (5)硬件检查,根据datasheet检查电路图,测量相应引脚电压,测量I2C引脚波形,光和距离传感器的探头是否因为装机不适被遮挡。 实例: 调试GYRO mpu3050时,初始化成功,读写寄存器也全部返回成功,但是读取的测量数据全是0。最后发现硬件供电电压偏低,原因是缺少上拉电阻。 五、其它 1. snesor_def_qcomdev.conf解析可以查看ap端代码 sns_reg_la.c 2. compass使用供应商提供的校准库,conf文件中3801置0,然后把供应商提供的校准库(形如libAKM8975.so)放到手机/system/vendor/lib/ 3. 开启CIT菜单中gyro,compass测试项: 修改: device/qcom/br01/overlay/packages/odm/apps/Tools/res/values/config_cit.xml 编译: make clean-Tools; make Tools; push: adb push Tools.apk /system/app 4. 使用AndroSensor测试sensor: 安装:>>adb install AndroSensor_com.fivasim.androsensor_45.apk 5. 没有屏幕时,使用神器调试 打开神器:>>python arobot3.1.py