rk android11 gsensor 距离感应传感器调试(Commissioning of RK android11 gsensor distance sensor)

我使用的是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列表里面的 那就更简单了

————————

I use VL Psensor. The driver given is based on Linux. I debug it first, get the data through CTA, and debug the data normally. However, in Android, Chen coal chemical can’t get through, can’t find the sensor, and need to follow the Android framework

1. I first ignore the framework and debug snesor

2. Then, according to an example, I use PS_ ap321xx. c. In the driver, let it match this, and then configure proximity_ ap321xx_ The members in the OPS structure write the corresponding value according to the register, and then read it later

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,
};  

The framework of RK can be written as a whole according to the framework in {drivers / input / sensors / Psensor /,

I will read the ID register and then verify the ID. my 0xc0 register reads oxee, so I will judge whether it is correct to match the following. After this, I can identify the ID normally, and then I can find the sensor on the upper layer. As for the data, I can only do the following. However, rk to use the framework, I still need to configure it, and the inpt node will be available after the driver is completed

1. The input event node generates a description that the driver is loaded successfully.

add device 1: /dev/input/event5
name: "proximity" 

2. Psensor needs to be used normally, boardconfig MK needs to add board_ PROXIMITY_ SENSOR_ Open support and check whether the device / rockchip / common directory of your SDK is submitted. If not, you need to apply an attachment patch.

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 configuration

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 can be configured to use interrupt or polling to query. If it is an interrupt, the sensor is called when the interrupt occurs_ report_ Value, if it is polling, it will create a work queue and call 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 ;

The report function is to report after obtaining the data. It is almost the same for other sensors. It is easier if it is in the RK list