2

我正在尝试在 i.MX6 板上连接 LSM330 加速度计/陀螺仪模块。模块连接I2C总线,设备树文件相关部分如下:

&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_rawetc 获取传感器读数。但是,运行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

This should set the channels, enable the buffer and get some readings into the buffer. As far as I know, cat /dev/iio:device0 should display the buffer, but it is giving me Device or resource busy. Further reads from the kernel with cat /sys/bus/iio/devices/iio:device0/in_accel_x_raw no longer works and give the same error message.

I am very new to the linux kernel, my goal is to expose the sensor data to the Android system so the user can rotate the screen etc. How do I get Android to obtain sensor readings from the module?

4

1 回答 1

2

查看 android logcat 后发现,Android HAL 没有权限读取或写入 sysfs 中的目录。chmod我最终在 init.rc 文件中放置了一堆命令,以便 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

希望这可以帮助某人。

于 2017-07-31T16:18:26.017 回答