电子说
前言
加速度和陀螺仪传感器可用于运动跟踪及设备姿态检测等功能,本文基于IDO-SBC3566智能主板介绍MPU6500六轴传感器在Android11系统的适配方法。
IDO-SBC3566基于瑞芯微RK3566研发的一款高性能低功耗的智能主板,采用四核A55,主频高达1.8GHz,专为个人移动互联网设备和AIOT设备而设计,内置了多种功能强大的嵌入式硬件引擎,为高端应用提供了优异的性能,支持几乎全格式的4K编解码,内置3DGPU,能够完全兼容OpenGL ES1.1/2.0/3.2、OpenCL2.0和Vulkan1.0.特殊的MMU2D硬件引擎,此外,凭借其强大的兼容性,可以轻松地转换基于TensorFlow/MXNet/PyTorch/Caffe等一系列框架的网络模型。
支持Android,Linux,OpenHarmony,麒麟OS等多种操作系统,可广泛应用于平板、教育平板、带屏音箱、词典笔、云终端、视频会议系统等安卓/Linux类应用方案,以及其他带屏消费类、或轻量级AI应用场景。
产品规格书:IDO-SBC3566-V1B 产品手册
硬件分析
根据硬件原理图设计确认PMU6500通过I2C与CPU连接。
内核配置
按照硬件I2C总线号及中断引脚信息,配置dts
&i2c3 { status = "okay"; mpu6500_acc: mpu_acc@68 { compatible = "mpu6500_acc"; reg = <0x68>; pinctrl-0 = <&mpu6500_irq_gpio>; irq-gpio = <&gpio1 RK_PB0 IRQ_TYPE_EDGE_RISING>; irq_enable = <0>; poll_delay_ms = <30>; type = ; layout = <2>; status = "okay"; }; mpu6500_gyro: mpu_gyro@68 { compatible = "mpu6500_gyro"; reg = <0x68>; irq_enable = <0>; poll_delay_ms = <30>; type = ; layout = <2>; status = "okay"; }; }; &pinctrl { mpu6500 { mpu6500_irq_gpio: mpu6500-irq-gpio { rockchip,pins = <3 RK_PD0 RK_FUNC_GPIO &pcfg_pull_none>; }; }; };
内核配置中开启以下配置
GYRO_MPU6500 [=y] MPU6500_ACC [=y]
编译内核烧录镜像至主板可看到以下打印日志,则说明驱动加载成功并识别到设备。
console:/ # dmesg | grep mpu [ 1.321088] gsensor_mpu6500 3-0068: sensor_register_device: mpu6500_acc, id = 29 [ 1.321111] i2c i2c-3: sensor_probe: mpu6500_acc,000000002d6ea1c1 [ 1.321151] gsensor_mpu6500 3-0068: sensor_chip_init:mpu6500_acc:devid=0x0,ops=0x000000000903c4c1 [ 1.517448] gsensor_mpu6500 3-0068: sensor_irq_init:use polling,delay=30 ms [ 1.517564] gsensor_mpu6500 3-0068: sensor_misc_device_register mma8452_daemon [ 1.517583] gsensor_mpu6500 3-0068: sensor_probe:initialized ok,sensor name:mpu6500_acc,type:2,id=29x0a [ 2.672631] gyro_mpu6500 3-0068-1: sensor_register_device: mpu6500_gyro, id = 58 [ 2.672647] i2c i2c-3: sensor_probe: mpu6500_gyro,0000000058545d17 [ 2.672670] gyro_mpu6500 3-0068-1: sensor_chip_init:mpu6500_gyro:devid=0x0,ops=0x00000000608437a5 [ 2.757813] gyro_mpu6500 3-0068-1: sensor_irq_init:use polling,delay=30 ms [ 2.758046] gyro_mpu6500 3-0068-1: sensor_misc_device_register gyrosensor [ 2.758071] gyro_mpu6500 3-0068-1: sensor_probe:initialized ok,sensor name:mpu6500_gyro,type:4,id=58x0a [ 4.788677] wait_for_keymaster: Computing HMAC with params { (seed: , nonce: 0811b2df836030705cced8b1a949fdd6c9896eeda9c5ea7253d514cfd7d6b72) } [ 4.788697] wait_for_keymaster: Computing HMAC for OpteeKeymasterDevice from Rockchip SecurityLevel: TRUSTED_ENVIRONMENT HAL: android.hardware.keymaster@4.1::IKeymasterDevice/default [ 10.072684] gsensor_mpu6500 3-0068: failed to read accel offset data from storage [ 10.073214] gyro_mpu6500 3-0068-1: failed to read gyro offset data from storage [ 36.442413] gsensor_mpu6500 3-0068: set sensor poll time to 66ms [ 36.533897] gsensor_mpu6500 3-0068: sensor on: starting poll sensor data 62ms
查看input设备
# cat /proc/bus/input/devices
从上面的内核启动日志中可以看到以下提示,因为芯片还没经过校准无法从存储器中读取加速度偏移数据。
[ 10.072684] gsensor_mpu6500 3-0068: failed to read accel offset data from storage [ 10.073214] gyro_mpu6500 3-0068-1: failed to read gyro offset data from storage
命令行校准方法如下:
#Gsensor echo 1 > /sys/class/sensor_class/accel_calibration #GYRO echo 1 > /sys/class/sensor_class/gyro_calibration
查看校准值:
cat /sys/class/sensor_class/accel_calibration cat /sys/class/sensor_class/gyro_calibration
如果无法查看校准值,则说明校准失败,可以打印 kernel log 确定失败原因。校准成功后,校准的值会保存到emmc 的 vendor storage 里面,不会被擦除,下次开机自动生效。
Android配置开启Sensor支持
需要修改Android编译设备配置,添加加速度计和陀螺仪的支持。
RK356X配置文件为:device/rockchip/rk356x/BoardConfig.mk
BOARD_GRAVITY_SENSOR_SUPPORT := true BOARD_GYROSCOPE_SENSOR_SUPPORT := true加速度和陀螺仪测试
可使用Sensor Sense软件来测试传感器的数据
如下为重力变化测试,翻转硬件,重力曲线随之变化
安装Gyroscope Test_1.0.5_Apkpure软件,运行模拟画面来确定当前主板传感器的坐标系,测试界面如下图所示。在内核驱动 drivers/input/sensors/sensor-dev.c 中定义了9个坐标系,在软件模拟确认后,修改dts中的layout值来选择坐标系矩阵。
审核编辑:刘清
全部0条评论
快来发表一下你的评论吧 !