GY_91模块

1.GY-91 简介

GY-91 是MPU9250+BMP280
MPU9250是InvenSense出品的模块九轴传感器,它集成了陀螺仪三轴,加速度三轴,磁感应三轴
MPU9250的I2C从地址为0x68
BMP280:温度气压传感器

2.iio子系统

iio子系统的目录位于drivers/iio
iio子系统全称是Industrial I/O subsystem(工业 I/O 子系统)

3.i2c测试

rk3288:/system/bin # i2cdetect -y 4                                                                                                                     
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- 76 --  

0x76 为BMP280 
0X68 为 MPU9250

mpu6050和mpu9250用I2C通信
6050和9250的程序可以通用,GY-91的INT没有和rk3288相连

4.配置设备信息

--- a/kernel/arch/arm/boot/dts/rk3288-firefly-android.dts
+++ b/kernel/arch/arm/boot/dts/rk3288-firefly-android.dts
@@ -454,6 +454,29 @@
 
 &i2c4 {
        status = "okay";
+       clock-frequency = <400000>; //需要配置为400kHz,要不然的话i2cdetect的时候0x68不稳定
+
+       mpu6500@68 {
+               compatible = "invensense,mpu6500";
+               status = "okay";
+               pinctrl-names = "default";
+               reg = <0x68>;
+               mpu-int_config = <0x10>;
+               mpu-level_shifter = <0>;
+               mpu-orientation = <1 0 0 0 1 0 0 0 1>;
+               orientation-x = <0>;
+               orientation-y = <1>;
+               orientation-z = <1>;
+               support-hw-poweroff = <0>;
+               mpu-debug = <0>;
+       };
+
+       bmp280@76 {
+               compatible = "bmp280";
+               status = "okay";
+               reg = <0x76>;
+       };
+
 };


内核配置 INV_MPU6050_IIO
Device Drivers  --->
<*> Industrial I/O support  ---> 
Inertial measurement units  --->   
  <*> Invensense MPU6050 devices 

内核配置BMP280
Device Drivers  --->
<*> Industrial I/O support  ---> 
 Pressure sensors  ---> 
<*> Bosch Sensortec BMP280 pressure sensor driver

5.测试

rk3288:/ # i2cdetect -y 4                                                       
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f                             
00:          -- -- -- -- -- -- -- -- -- -- -- -- --                             
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                             
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                             
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                             
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                             
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                             
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --                             
70: -- -- -- -- -- -- UU -- 
BMP280 驱动OK,mpu6050驱动失败
rk3288:/ # dmesg | grep mpu6050                                                 
[    1.118957] inv-mpu6050 4-0068: trigger probe fail -22                       
[    1.119047] inv-mpu6050: probe of 4-0068 failed with error -22

fix:是因为驱动中没有注册中断反回错误
--- a/kernel/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
+++ b/kernel/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
@@ -128,8 +128,8 @@ int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev)
                               IRQF_TRIGGER_RISING,
                               "inv_mpu",
                               st->trig);
-       if (ret)
-               return ret;
+//     if (ret)
+//             return ret;

rk3288:/ # i2cdetect -y 4                                                       
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f                             
00:          -- -- -- -- -- -- -- -- -- -- -- -- --                             
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                             
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                             
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                             
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                             
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                             
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --                             
70: -- -- -- -- -- -- UU -- 

rk3288:/ # i2cdump -f -y 4 0x68                                                 
No size specified (using byte-data access)                                      
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef         
00: c1 cc e4 fd ab f8 de 2f f6 ea f0 00 00 69 61 76    ???????/???..iav         
10: d2 cd e0 00 00 00 00 00 00 13 04 18 00 00 00 00    ???......???....         
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................         
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................         
40: 00 0b 60 00 00 00 00 00 00 00 00 00 00 00 00 00    .?`.............         
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................         
60: 00 00 00 00 00 00 00 00 00 00 00 40 3f 00 00 00    ...........@?...         
70: 00 00 00 00 00 73 00 18 34 00 eb 34 00 27 72 00 
读出来的0x75 的 who am i 为 0x73和datasheet上的不一样,但能正常使用

内核测试:
0x3b到0x40 为所测试的加速度
0x43到0x48 为GYRO的值
使能加速度:
rk3288:/ # cd sys/bus/iio/devices/iio\:device1/
echo 1 > scan_elements/in_accel_x_en
echo 1 > scan_elements/in_accel_y_en
echo 1 > scan_elements/in_accel_z_en
echo 1 > scan_elements/in_anglvel_x_en
echo 1 > scan_elements/in_anglvel_y_en
echo 1 > scan_elements/in_anglvel_z_en
echo 1 > scan_elements/in_timestamp_en
echo 1 > buffer/enable

rk3288:/sys/bus/iio/devices/iio:device1 # i2cdump -f -y 4 0x68                               
No size specified (using byte-data access)                                                   
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef                      
00: c1 cc e4 fd ab f8 de 2f f6 ea f0 00 00 69 61 76    ???????/???..iav                      
10: d2 cd e0 00 00 00 00 00 00 13 04 18 00 00 00 00    ???......???....                      
20: 00 00 00 78 00 00 00 00 00 00 00 00 00 00 00 00    ...x............                      
30: 00 00 00 00 00 00 00 00 01 00 15 ea 00 20 b4 33    ........?.??. ?3                      
40: 10 0b e8 ff e8 ff f7 00 08 00 00 00 00 00 00 00    ???.?.?.?.......                      
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................                      
60: 00 00 00 00 00 00 00 00 00 00 40 01 00 00 68 38    ..........@?..h8                      
70: 00 00 02 00 34 73 00 18 34 00 eb 34 00 27 72 00 

内核可以为上层提供传感器的数据了

6.HAL 层接收数据

hardware/invensense/65xx/libsernors_iio/

手动编译后生成
out/target/product/rk3288/system/lib/hw/sensors.rk3288.so

重启系统
06-19 02:13:16.384 228 459 D SensorsHal: Couldn’t open /dev/mma8452_daemon (No such file or directory)
06-19 02:13:16.384 228 459 I SensorsHal: MmaSensor update delay: 20ms
06-19 02:13:16.384 228 459 E SensorsHal: fail to perform GSENSOR_IOCTL_APP_SET_RATE, result = -1, error is 'Bad file ’

fix:更换HAL层的选项
--- a/device/rockchip/rk3288/BoardConfig.mk
+++ b/device/rockchip/rk3288/BoardConfig.mk
@@ -46,8 +46,8 @@ TARGET_USES_64_BIT_BINDER := false
 TARGET_PREFER_32_BIT := true
 
 # Sensors
-BOARD_SENSOR_ST := true
-BOARD_SENSOR_MPU_PAD := false
+BOARD_SENSOR_ST := false
+BOARD_SENSOR_MPU_PAD := true
 
目录为:hardware/rockchip/sensor/
编译后生成:out/target/product/rk3288/vendor/lib/hw/sensors.rk30board.so

更改之后,点击Auto-rote 自动旋转开,则打开驱动里的buffer/enable 为 1
关闭自动旋转,则设置驱动里的buffer/enable 为 0

但是没有收到上报的数据
怀疑和中断有关,因为没有中断所以不会主动上报数据

hardware/rockchip/sensor/mpu_vr/libsensors/MPLSensor.cpp 打印
01-01 12:00:03.889   222   222 V Sensors : ---------GYRO-----200HZ--------------
01-01 12:00:03.889   222   222 V Sensors : ---------ACCEL-----200HZ--------------
hal 层已经适配

7.驱动方案

没有中断,写一个延后处理的工作,触发iio_trigger_poll

fix:
--- a/kernel/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
+++ b/kernel/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
@@ -12,6 +12,10 @@
 */
 
 #include "inv_mpu_iio.h"
+#include 
+#include 
+
+struct delayed_work mpu6050_delayed_work;
 
 static void inv_scan_query(struct iio_dev *indio_dev)
 {
@@ -111,6 +115,12 @@ static const struct iio_trigger_ops inv_mpu_trigger_ops = {
        .set_trigger_state = &inv_mpu_data_rdy_trigger_set_state,
 };
 
+static struct iio_trigger *mpu6050_triger;
+
+static void mpu6050_delayed_workfn(struct work_struct *wrok){
+       iio_trigger_poll(mpu6050_triger);
+       schedule_delayed_work(&mpu6050_delayed_work, msecs_to_jiffies(500));
+}
 int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev)
 {
        int ret;
@@ -128,8 +138,12 @@ int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev)
                               IRQF_TRIGGER_RISING,
                               "inv_mpu",
                               st->trig);
-       if (ret)
-               return ret;
+//     if (ret)
+//             return ret;
+//
+       mpu6050_triger = st->trig;
+       INIT_DELAYED_WORK(&mpu6050_delayed_work, mpu6050_delayed_workfn);
+       schedule_delayed_work(&mpu6050_delayed_work, msecs_to_jiffies(5000));

可以用app获取g_sensor的数据了

9.测试BMP280 温度和压力

rk3288:/sys/bus/iio/devices/iio:device2 # cat in_pressure_input                                                                                         
94.307410156
rk3288:/sys/bus/iio/devices/iio:device2 # cat in_temp_input                                                                                             
30300

--------------------------------------------------------------------
patch:
--- a/device/rockchip/rk3288/BoardConfig.mk
+++ b/device/rockchip/rk3288/BoardConfig.mk
@@ -46,8 +46,8 @@ TARGET_USES_64_BIT_BINDER := false
 TARGET_PREFER_32_BIT := true
 
 # Sensors
-BOARD_SENSOR_ST := true
-BOARD_SENSOR_MPU_PAD := false
+BOARD_SENSOR_ST := false
+BOARD_SENSOR_MPU_PAD := true
--- a/kernel/arch/arm/boot/dts/rk3288-firefly-android.dts
+++ b/kernel/arch/arm/boot/dts/rk3288-firefly-android.dts
@@ -454,6 +454,29 @@
 
 &i2c4 {
        status = "okay";
+       clock-frequency = <400000>;
+
+       mpu6500@68 {
+               compatible = "invensense,mpu6500";
+               status = "okay";
+               pinctrl-names = "default";
+               reg = <0x68>;
+               mpu-int_config = <0x10>;
+               mpu-level_shifter = <0>;
+               mpu-orientation = <1 0 0 0 1 0 0 0 1>;
+               orientation-x = <0>;
+               orientation-y = <1>;
+               orientation-z = <1>;
+               support-hw-poweroff = <0>;
+               mpu-debug = <0>;
+       };
+
+       bmp280@76 {
+               compatible = "bmp280";
+               status = "okay";
+               reg = <0x76>;
+       };
+
 };
--- a/kernel/arch/arm/configs/firefly-rk3288_defconfig
+++ b/kernel/arch/arm/configs/firefly-rk3288_defconfig
@@ -3868,6 +3868,7 @@ CONFIG_IIO=y
 CONFIG_IIO_BUFFER=y
 CONFIG_IIO_BUFFER_CB=y
 CONFIG_IIO_KFIFO_BUF=y
+CONFIG_IIO_TRIGGERED_BUFFER=y
 CONFIG_IIO_TRIGGER=y
 CONFIG_IIO_CONSUMERS_PER_TRIGGER=2
 
@@ -3992,7 +3993,7 @@ CONFIG_ROCKCHIP_SARADC=y
 # CONFIG_ADIS16400 is not set
 # CONFIG_ADIS16480 is not set
 # CONFIG_KMX61 is not set
-# CONFIG_INV_MPU6050_IIO is not set
+CONFIG_INV_MPU6050_IIO=y
 
 #
 # Light sensors
@@ -4049,7 +4050,7 @@ CONFIG_ROCKCHIP_SARADC=y
 #
 # Pressure sensors
 #
-# CONFIG_BMP280 is not set
+CONFIG_BMP280=y
 # CONFIG_MPL115 is not set
 # CONFIG_MPL3115 is not set
 # CONFIG_MS5611 is not set

你可能感兴趣的:(rockchip)