简体   繁体   English

如何从/ dev / iio:deviceX中的LSM330读取数据?

[英]How to read data from LSM330 in /dev/iio:deviceX?

I am trying to interface a LSM330 accelerometer/gyroscope module on an i.MX6 board. 我正在尝试在i.MX6板上连接LSM330加速度计/陀螺仪模块。 The module is connected to an I2C bus, the relevant parts of the device tree file are as follows: 该模块连接到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>;
    };
};

The module shows up as /dev/iio:device0 for the accelerometer and /dev/iio:device1 for the gyroscope. 该模块显示为/dev/iio:device0的加速度计和/dev/iio:device1的陀螺仪。 They also show up as /sys/bus/iio/devices/iio:device0 and /sys/bus/iio/devices/iio:device1 . 它们还显示为/sys/bus/iio/devices/iio:device0/sys/bus/iio/devices/iio:device1 /sys/bus/iio/devices/iio:device0 I can get the sensor readings via cat in_accel_x_raw etc. However, running cat /dev/iio:device0 immediately returns and produce no output. 我可以通过cat in_accel_x_raw等获取传感器读数。但是,运行cat /dev/iio:device0立即返回并且不产生任何输出。

After searching around the Internet, I also tried the commands: 在Internet上搜索之后,我还尝试了以下命令:

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 . 据我所知, cat /dev/iio:device0应该显示缓冲区,但是它给我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. 使用cat /sys/bus/iio/devices/iio:device0/in_accel_x_raw从内核进行的进一步读取不再起作用,并给出相同的错误消息。

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? 我是Linux内核的新手,我的目标是将传感器数据公开给Android系统,以便用户可以旋转屏幕等。如何获得Android以从模块中获取传感器读数?

After looking at the android logcat, it turns out the Android HAL does not have permissions to read or write to the directories in the sysfs. 查看android logcat之后,事实证明Android HAL没有读取或写入sysfs中目录的权限。 I ended up putting a bunch of chmod commands in the init.rc file so Android can access the sensor data. 最后,我在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

Hope this helps someone. 希望这对某人有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM