清空記錄
歷史記錄
取消
清空記錄
歷史記錄
加速度和陀螺儀傳感器可用于運(yùn)動(dòng)跟蹤及設(shè)備姿態(tài)檢測(cè)等功能,本文基于IDO-SBC3566智能主板介紹MPU6500六軸傳感器在Android11系統(tǒng)的適配方法。
IDO-SBC3566基于瑞芯微RK3566研發(fā)的一款高性能低功耗的智能主板,采用四核A55,主頻高達(dá)1.8GHz,專(zhuān)為個(gè)人移動(dòng)互聯(lián)網(wǎng)設(shè)備和AIOT設(shè)備而設(shè)計(jì),內(nèi)置了多種功能強(qiáng)大的嵌入式硬件引擎,為高端應(yīng)用提供了優(yōu)異的性能,支持幾乎全格式的4K編解碼,內(nèi)置3DGPU,能夠完全兼容OpenGL ES1.1/2.0/3.2、OpenCL2.0和Vulkan1.0.特殊的MMU2D硬件引擎,此外,憑借其強(qiáng)大的兼容性,可以輕松地轉(zhuǎn)換基于TensorFlow/MXNet/PyTorch/Caffe等一系列框架的網(wǎng)絡(luò)模型。
支持Android,Linux,OpenHarmony,麒麟OS等多種操作系統(tǒng),可廣泛應(yīng)用于平板、教育平板、帶屏音箱、詞典筆、云終端、視頻會(huì)議系統(tǒng)等安卓/Linux類(lèi)應(yīng)用方案,以及其他帶屏消費(fèi)類(lèi)、或輕量級(jí)AI應(yīng)用場(chǎng)景。
產(chǎn)品規(guī)格書(shū):IDO-SBC3566-V1B 產(chǎn)品手冊(cè)
根據(jù)硬件原理圖設(shè)計(jì)確認(rèn)PMU6500通過(guò)I2C與CPU連接。
按照硬件I2C總線號(hào)及中斷引腳信息,配置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>;
};
};
};
內(nèi)核配置中開(kāi)啟以下配置
GYRO_MPU6500 [=y]
MPU6500_ACC [=y]
編譯內(nèi)核燒錄鏡像至主板可看到以下打印日志,則說(shuō)明驅(qū)動(dòng)加載成功并識(shí)別到設(shè)備。
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:miscdevice: mma8452_daemon
[ 1.517583] gsensor_mpu6500 3-0068: sensor_probe:initialized ok,sensor name:mpu6500_acc,type:2,id=29\x0a
[ 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:miscdevice: gyrosensor
[ 2.758071] gyro_mpu6500 3-0068-1: sensor_probe:initialized ok,sensor name:mpu6500_gyro,type:4,id=58\x0a
[ 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設(shè)備
# cat /proc/bus/input/devices
從上面的內(nèi)核啟動(dòng)日志中可以看到以下提示,因?yàn)樾酒€沒(méi)經(jīng)過(guò)校準(zhǔn)無(wú)法從存儲(chǔ)器中讀取加速度偏移數(shù)據(jù)。
[ 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
命令行校準(zhǔn)方法如下:
#Gsensor
echo 1 > /sys/class/sensor_class/accel_calibration
#GYRO
echo 1 > /sys/class/sensor_class/gyro_calibration
查看校準(zhǔn)值:
cat /sys/class/sensor_class/accel_calibration
cat /sys/class/sensor_class/gyro_calibration
如果無(wú)法查看校準(zhǔn)值,則說(shuō)明校準(zhǔn)失敗,可以打印 kernel log 確定失敗原因。校準(zhǔn)成功后,校準(zhǔn)的值會(huì)保存到emmc 的 vendor storage 里面,不會(huì)被擦除,下次開(kāi)機(jī)自動(dòng)生效。
需要修改Android編譯設(shè)備配置,添加加速度計(jì)和陀螺儀的支持。
RK356X配置文件為:device/rockchip/rk356x/BoardConfig.mk
BOARD_GRAVITY_SENSOR_SUPPORT := true
BOARD_GYROSCOPE_SENSOR_SUPPORT := true
可使用Sensor Sense軟件來(lái)測(cè)試傳感器的數(shù)據(jù)
如下為重力變化測(cè)試,翻轉(zhuǎn)硬件,重力曲線隨之變化
安裝Gyroscope Test_1.0.5_Apkpure軟件,運(yùn)行模擬畫(huà)面來(lái)確定當(dāng)前主板傳感器的坐標(biāo)系,測(cè)試界面如下圖所示。在內(nèi)核驅(qū)動(dòng) drivers/input/sensors/sensor-dev.c 中定義了9個(gè)坐標(biāo)系,在軟件模擬確認(rèn)后,修改dts中的layout值來(lái)選擇坐標(biāo)系矩陣。