我使用的是vl的psensor,给的驱动是基于Linux的,先调试通,调过cta得到数据,把数据调试正常,但是这样是在android陈煤化工不会通,找不到sensor,需要走android的框架
1.我是首先不管框架,调试通snesor
2.然后按照一个例子,我使用ps_ap321xx.c,驱动中让他去匹配这个,然后配置proximity_ap321xx_ops结构体里面的成员,按照寄存器,写对应的值,后面读取的时候
struct sensor_operate proximity_ap321xx_ops = { .name = "ps_ap321xx", .type = SENSOR_TYPE_PROXIMITY, //sensor type and it should be correct .id_i2c = PROXIMITY_ID_AP321XX, //i2c id number .read_reg = 0x14, //read data //there are two regs, we fix them in code. .read_len = 1, //data length .id_reg = 0xc0, //read device id from this register //there are 3 regs, we fix them in code. .id_data = 0xee, //device id ------- .precision = 8, //8 bits .ctrl_reg = AP3212B_MODE_COMMAND, //enable or disable .int_status_reg = 0x13, //intterupt status register .range = {0,256}, //range .brightness ={10,255}, // brightness .trig = IRQF_TRIGGER_FALLING | IRQF_ONESHOT | IRQF_SHARED, .active = sensor_active, .init = sensor_init, .report = sensor_report_value, };
rk的框架在 drivers/input/sensors/psensor/ 里面整体的按照那个框架来写 就可以,
会根据这个Id寄存器 读取,然后校验id,我的0xc0寄存器读取的是oxee,所以就会根据这个判断是否正确,才能下面的匹配,这里走完了,正常识别id,就可以上层找到sensor了,至于数据,下面的才做,但是rk要使用框架,还需要配置一下,驱动做完Inpt节点就会有了
1.input event 节点生成说明驱动加载成功了。
add device 1: /dev/input/event5 name: "proximity"
2.psensor 需要正常用起来,BoardConfig.mk 中需要将 BOARD_PROXIMITY_SENSOR_SUPPORT 打开,并且看下你们sdk的 device/rockchip/common 目录是否这个提交,没有的话需要打上附件补丁。
diff --git a/sepolicy/vendor/file_contexts b/sepolicy/vendor/file_contexts index 0c5830a2..4b186c1f 100644 --- a/sepolicy/vendor/file_contexts +++ b/sepolicy/vendor/file_contexts @@ -22,6 +22,11 @@ /dev/mma8452_daemon u:object_r:sensor_device:s0 /dev/compass u:object_r:sensor_dev:s0 /dev/gyrosensor u:object_r:sensor_dev:s0 +/dev/lightsensor u:object_r:sensor_dev:s0 +/dev/psensor u:object_r:sensor_dev:s0 +/dev/temperature u:object_r:sensor_dev:s0 +/dev/pressure u:object_r:sensor_dev:s0 +/dev/angle u:object_r:sensor_dev:s0 /dev/stune(/.*)? u:object_r:cgroup:s0 /dev/akm8963_dev u:object_r:akmd_device:s0
这里正确了,就能找到sensor了,网上随便找一个sensor的app,就可以测试,我下载了sensortest_yxdown.com.apk
dts配置
vl53l0x@29 { compatible = "ps_ap321xx"; i2c_num = <1>; i2c_addr = <0x29 0 0 0>; reg = <0x29>; pinctrl-names = "default"; pinctrl-0 = <&vl53l0_irq>; //---这里是走rk标准框架 type = <SENSOR_TYPE_PROXIMITY>; irq_enable = <0>; //0轮询 -- > 1中断 reprobe_en = <1>; irq-gpio = <&gpio3 19 GPIO_ACTIVE_HIGH>; power-gpio = <&gpio3 18 GPIO_ACTIVE_HIGH>; poll_delay_ms = <200>; //20ms读取一次 //---- ////// interrupt-parent = <&vl53l0_irq>; status = "okay" ; //interrupts = <14 IRQ_TYPE_LEVEL_LOW 14 0>; }
dts可以配置为使用中断或者轮询方式查询,如果是中断,就是在中断的时候调用sensor_report_value,如果是轮询,会做一个工作队列,轮询调用sensor_report_value
主要框架在drivers/input/sensors/sensor-dev.c中
sensor_active:
-->ready_to_start_config(vl53l0x_data) ;
--> stmvl53l0x_start(vl53l0x_data, 3, 0)
sensor_init:
-->stmvl53l0x_setup(vl53l0x_data);
-->2c_object->power_up = 1 ;
上报函数就是获取得到数据以后,上报就行了,其他sensor 差不多就这样了,如果是在rk列表里面的 那就更简单了