我正在尝试在i.MX6板上连接LSM330加速度计/陀螺仪模块。模块连接到I2C总线,设备树文件的相关部分如下:
SELECT x, Y, count(*) AS Amount FROM Table1
UNION ALL
SELECT X, Y, count(*) AS Amount FROM Table2
GROUP BY x, y;
模块显示加速度计&i2c1 {
clock-frequency = <100000>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_i2c1_2>;
status = "okay";
/* LSM330 motion detector (accelerometer) */
lsm330_accel: lsm330_accel@0x1e {
compatible = "st,lsm330-accel";
st,drdy-int-pin = <1>;
reg = <0x1e>;
};
/* LSM330 motion detector (gyroscope) */
lsm330_gyro: lsm330_gyro@0x6a {
compatible = "st,lsm330-gyro";
st,drdy-int-pin = <2>;
reg = <0x6a>;
};
};
和陀螺仪/dev/iio:device0
。它们还会显示为/dev/iio:device1
和/sys/bus/iio/devices/iio:device0
。我可以通过/sys/bus/iio/devices/iio:device1
等获取传感器读数。但是,运行cat in_accel_x_raw
会立即返回并且不会产生任何输出。
在互联网上搜索后,我也尝试了命令:
cat /dev/iio:device0
这应该设置通道,启用缓冲区并获取一些读数到缓冲区。据我所知,cd /sys/bus/iio/devices/iio_sysfs_trigger
echo 0 > add_trigger
cd /sys/bus/iio/devices/iio:device0
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_timestamp_en
echo sysfstrig0 > trigger/current_trigger
echo 100 > buffer/length
echo 1 > buffer/enable
echo 1 > /sys/bus/iio/devices/trigger0/trigger_now
应显示缓冲区,但它会给我cat /dev/iio:device0
。使用Device or resource busy
从内核进一步读取不再有效并提供相同的错误消息。
我是linux内核的新手,我的目标是将传感器数据暴露给Android系统,以便用户可以旋转屏幕等。如何让Android从模块中获取传感器读数?
答案 0 :(得分:2)
在查看android logcat之后,事实证明Android HAL没有读取或写入sysfs目录的权限。我最终在init.rc文件中放了一堆chmod
命令,以便Android可以访问传感器数据。
# Change permissions for the LSM330 sysfs entries (accelerometer)
chmod 0666 /sys/bus/iio/devices/iio\:device0/sampling_frequency
chmod 0666 /sys/bus/iio/devices/iio\:device0/buffer/enable
chmod 0666 /sys/bus/iio/devices/iio\:device0/buffer/length
chmod 0666 /sys/bus/iio/devices/iio\:device0/trigger/current_trigger
chmod 0666 /sys/bus/iio/devices/iio\:device0/scan_elements/in_accel_x_en
chmod 0666 /sys/bus/iio/devices/iio\:device0/scan_elements/in_accel_y_en
chmod 0666 /sys/bus/iio/devices/iio\:device0/scan_elements/in_accel_z_en
chmod 0666 /sys/bus/iio/devices/iio\:device0/scan_elements/in_timestamp_en
chmod 0666 /dev/iio\:device0
希望这有助于某人。