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
If this is correct, you can find the sensor. You can test it by looking for a sensor app on the Internet. I downloaded 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>; //---Here is the standard framework type = <SENSOR_TYPE_PROXIMITY>; irq_enable = <0>; //0 polling -- > 1 interrupt reprobe_en = <1>; irq-gpio = <&gpio3 19 GPIO_ACTIVE_HIGH>; power-gpio = <&gpio3 18 GPIO_ACTIVE_HIGH>; poll_delay_ms = <200>; //Read once in 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
The main framework is in 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 sensor s. It is easier if it is in the rk list