GithubHelp home page GithubHelp logo

stmicroelectronics / st-mems-android-linux-drivers-iio Goto Github PK

View Code? Open in Web Editor NEW
23.0 11.0 1.0 2.28 MB

stm mems iio drivers for Android and Linux platforms.

License: GNU General Public License v2.0

Makefile 0.38% C 99.62%
iio mems sensors android kernel mems-sensors stmicroelectronics

st-mems-android-linux-drivers-iio's Issues

Correct way to implement accel/gyro thresholds on lsm9ds1

Hi,
we're noticing an incredibly high number of raised IRQs (about one every 20ms) in android from the lsm9ds1 accelerometer. This situation causes a fixed 20% usage on the CPU. When testing the gyroscope, the situation is the same. What is the correct way to implement thresholds in the code so that a device in static position doesn't flood the kernel with IRQs? We've tried writing to the various THS registers, enabling FIFO THS on INT1, setting DUR and WAIT... everything to no success. The only thing we managed to reduce the CPU to about 2.5% is setting the Decimation to 8. The documentation doesn't really explain what values the registers expect and/or if there's a correct order to set them. Please help :)

ASM330LHH IIO driver on kernel 5.10

Hi,
I have ported the IIO driver to Kernel5.10 and it should be working fine. But I'm not sure how to read the sensor value from the application layer. I use "cat /sys/bus/iio/devices/iio:device0/in_anglvel_x_raw" to get this error: "The cat: '/ sys/bus/iio/devices/iio: device0 / in_anglvel_x_raw' : Remote I/O error".

If I use the "fread" function in c code to read xxx_raw files, I end up with zero values.

Is there a demo of application layer reading code? Can you provide it for my reference?

Enable Wake-up interrupt with lsm6dsox driver and lsm6dso MEMS.

Hello,
I merged (yesterday) the lsm6dsox driver into my v5.15 Linux Kernel in order to run with lsm6dso MEMS.
I'd like to enable the wake-up functionality (and setting the threshold) in order trigger an interrupt on a certain acceleration value, but I'm not able to find entry on sysfs to manage that functionality.
I mean, for example "in_accel_x_thresh_either_en" "in_accel_x_thresh_either_value" etc

Before, I was using https://github.com/STMicroelectronics/linux/tree/v5.15-stm32mp/drivers/iio/imu/st_lsm6dsx driver with lsm6dsl MEMS, and the wake-up functionality was present and working.

Thanks a lot in advance

lsm9ds1 (st_imu68) irq not triggered on data ready

Hi,
we're using an lsm9ds1 on an Android 10 board with kernel 5.4 and, while the in-kernel magnetormeter driver works correctly and the HAL receives the correct data when an irq is raised, the accel/gyro section doesn't seem to work in the same way. We tried the older driver and this new one to the same result. The triggers are setup correctly and the data readings from sysfs (eg: in_accel_x_raw) return sane values readings via i2c, but no irq is raised at all when the device is moved or rotated. We've tried setting the irq type in the dt as low/high/rising/falling (and related changes in the driver) to no visible results. When we force enable the data-ready irq via i2cset (eg: "i2cset -y -f 2 0x6a 0x0c 0x3" to enable both data-ready for accel/gyro on the 1st irq line), we see the interrupts coming in /proc/interrupts, but no data is received from the HAL (we're using the android hal provided here: https://github.com/STMicroelectronics/st-mems-android-linux-sensors-hal). No changes have been done to the driver itself and all sensors show up in Aida64, including the iNemo virtual sensors, but no data is received.
Any idea what could be going on or if we're missing something ? We've been fighting with this issue for the last week...

Edit: we also tried with the IIO HAL (https://github.com/STMicroelectronics/STMems_Android_Sensor_HAL_IIO) and the result is the same. Magnetometer works fine, accel / gyro are silent.

Licensing

Hi all,

I can see many of the files in this repo are licensed under GPL v2. However, without mention of this in the README, in a licensing file, or on the page on the website for this software, I don't feel safe treating the entire project as GPL v2. Could you please clearly lay out licensing for this repo and software? Thanks

Support of LSM6DSV16X

Hi there, is there any plan to support this IMU (LSM6DSV16X) especially the FIFO, Sensor fusion and MLC.

Support for sensor hub on LSM6DSM

I have a device with an LSM6DSM communicating with my host over SPI and would like to connect an LPS22HH on the downstream I2C pins.

Does this driver support that? I'm not seeing how to configure things to support a downstream device.

How to Stabilize Sensor Output and Achieve Target Frequency for asm330lhhxg1 and lsm6dsox?

Hi ,

I am currently working on porting two sensors, the asm330lhhxg1 and lsm6dsox, to my platform.
However, I have no idea how to stabilize the sensor data and achieve the frequency in Hz as specified in the hardware specifications. Despite searching and trying various tutorials, using the iio_generic_buffer tools yields no results.

# Enable Y-axis acceleration
echo 1 > /sys/bus/iio/devices/iio:device2/scan_elements/in_accel_y_en

# Enable X-axis acceleration
echo 1 > /sys/bus/iio/devices/iio:device2/scan_elements/in_accel_x_en

# Enable timestamp
echo 1 > /sys/bus/iio/devices/iio:device2/scan_elements/in_timestamp_en

# Enable Z-axis acceleration
echo 1 > /sys/bus/iio/devices/iio:device2/scan_elements/in_accel_z_en

# Attempt to enable buffer
echo 1 > /sys/bus/iio/devices/iio:device2/buffer/enable

# Run generic buffer utility
./iio_generic_buffer -a -g -n asm330lhhxg1_accel
# Output from incomplete command
  iio device number being used is 2
  trigger-less mode selected
  Auto-channels selected but some channels are already activated in sysfs
  Proceeding without activating any channels
##stuck here

#Here is my device tree configuration under `i2c0`:

&i2c0 {
   asm330lhhx-imu@0x6b {
        compatible = "st,asm330lhhxg1";
        reg = <0x6b>;
        interrupt-parent = <&gpio0>;
        interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
        /*vddio-supply = <&sensors_vddio>;*/
        /*vdd-supply = <&sensors_vdd>;*/
	    drive-open-drain;
        st,int-pin = <1>;
        st,mlc-int-pin = <2>;
        mount-matrix = "1", "0", "0",
                   "0", "1", "0",
                   "0", "0", "1";
        };
    }
#  ./iio_generic_buffer -a -n asm330lhhxg1_gyro -e -g
iio device number being used is 1
trigger-less mode selected
No channels are enabled, enabling all channels
Enabling: in_anglvel_z_en
Enabling: in_timestamp_en
Enabling: in_raw_en
Enabling: in_anglvel_y_en
Enabling: in_anglvel_x_en
nothing available
nothing available
Disabling: in_anglvel_z_en
Disabling: in_timestamp_en
Disabling: in_raw_en
Disabling: in_anglvel_y_en

Could you please provide any suggestions?

Thanks,
AlysonQ

Slow when keep read value?

I got really slowy speed when read iio node, and some value event not correct.
Is any way I can fix it??
Here is my script and output.

echo "Hello iio test"
cat /sys/bus/iio/devices/iio\:device2/sampling_frequency 
while :
do
        cat /sys/bus/iio/devices/iio:device2/in_accel_x_raw >> /dev/kmsg
        cat /sys/bus/iio/devices/iio:device2/in_accel_y_raw >> /dev/kmsg
        cat /sys/bus/iio/devices/iio:device2/in_accel_z_raw >> /dev/kmsg
        cat /sys/bus/iio/devices/iio:device1/in_anglvel_x_raw >> /dev/kmsg
        cat /sys/bus/iio/devices/iio:device1/in_anglvel_y_raw >> /dev/kmsg
        cat /sys/bus/iio/devices/iio:device1/in_anglvel_z_raw >> /dev/kmsg
    sleep 0.01
done
root@iBox-500:~/kivyT# sh test.sh                                                                                                                                                                              
Hello iio test                                                                                                                                                                                                 
833.000000                                                                                                                                                                                                     
[ 1131.604427] 1548                                                                                                                                                                                            
[ 1131.616635] -368                                                                                                                                                                                            
[ 1131.628900] -16176                                                                                                                                                                                          
[ 1131.956560] 9                                                                                                                                                                                               
[ 1132.283833] -70                                                                                                                                                                                             
[ 1132.558214] -68                                                                                                                                                                                             
[ 1132.584233] 1486                                                                                                                                                                                            
[ 1132.596522] -408                                                                                                                                                                                            
[ 1132.608636] -16095                                                                                                                                                                                          
[ 1132.935723] 7                                                                                                                                                                                               
[ 1133.262978] -70                                                                                                                                                                                             
[ 1133.590466] -67                                                                                                                                                                                             
[ 1133.616815] 1444                                                                                                                                                                                            
[ 1133.628973] -423                                                                                                                                                                                            
[ 1133.641130] -16098                                                                                                                                                                                          
^C                                                                                                                                                                                                             
root@iBox-500:~/kivyT# 

Here is my DTS setting

LSM6DSRTR@6b {
// /sys/bus/iio/devices/iio:device1
// /sys/bus/iio/devices/iio:device2
compatible = "st,lsm6dsr";
reg = <0x6b>;
// interrupt-parent = <&gpio0>;
// interrupts = <0 IRQ_TYPE_EDGE_RISING>;
mount-matrix = "1", "0", "0",
				"0", "1", "0",
				"0", "0", "1";
};

Updated driver AIS2IHTR to read temperature register

Hello,

I use an ais2h chip with spi on a project to have accelerometer and temperature sensors. I use a Linux-imx kernel 5.10 in a Yocto project.
I have no integration problem with the driver but the temperature reading doesn't seem to be implemented.
Do you plan to implement register reading for temperatures on this chip? Or their is a way to have it ?

Thanks

compilation of st_lis2dw12_buffer.c with kernel 5.15 fails

I'm using the Kernel 5.15. and get the following error when I try to compile the driver for the LIS2DW12/IIS2DLPC:

st_lis2dw12_buffer.c:308:18: error: implicit declaration of function 'devm_iio_kfifo_allocate'; did you mean 'iio_kfifo_allocate'? [-Werror=implicit-function-declaration]

The function 'devm_iio_kfifo_allocate' was changed to a private function in kernel 5.13 and replaced by 'devm_iio_kfifo_buffer_setup' in header 'kfifo_buf.h'

Power up fail for lis2dux12/lis2duxs12

Hi,
I'm using LIS2DUX12 accelerometer on a custom PCB with SPI interface in a Linux environment and I was experiencing a failure during the probe of the device with error message [ 0.561627] st_lis2duxs12_spi spi0.0: unsupported whoami [ff]
Reading the datasheet documentation I found out that

When Vdd and Vdd_IO are set, the device enters a deep power-down state

So I read how to exit from a deep power-down state

If the SPI interface is used, the LIS2DUX12 can move from deep power-down to soft power-down by writing the
bit SOFT_PD of EN_DEVICE_CONFIG (3Eh) to 1

and took a look into the implementation of the function st_lis2duxs12_power_up_command(struct st_lis2duxs12_hw *hw) inside the file
st_lis2duxs12_core.c

To my surprise I found out that the code does not implement what's described in the documentation but instead was reading WHO_AM_I (0Fh) register.

regmap_read(hw->regmap, ST_LIS2DUXS12_WHOAMI_ADDR, &data);

To this SPI transaction the accelerometer does not respond and the MISO line stays high.

So, I tried to write EN_DEVICE_CONFIG (3Eh) to 1 instead and by doing so the probe returned with success!
I did this by putting the magic numer 0x3E as an argument to the regmap_write() function because there is no definition of that register address inside st_lis2duxs12.h file. Does this file, as well as others related to LIS2DUX12, need to be updated to reflect the latest changes with this device/documentation?

Thanks

Configuring a hrtimer-trigger or buffered-trigger for iio-device and ODR in driver lower than actual ODR

Hello, I have been having issues with configuring configuring a hrtimer-trigger or buffered-trigger for my iio-device. I am using a ISM330dlc (IMU) and it is connected to a rasberry pi cm4. As a driver I am using the LSM6DSX driver because my IMU is listed as configurable sensor in the Documentation. My problem is that when I load my device tree overlay (dtbo file) the /sys/bus/iio/devices/iio:deviceX/ directory appears but only these files appear.
284557304-52913afb-7326-4841-8317-0c6c70791489
In basically every documentation file, they say that a /sys/bus/iio/devices/iio:deviceX/trigger/ directory should appear and it doesn't matter what I do it doesn't appear. I have checked and the ISM330dlc supports triggers, even 2. Chatgpt has suggested I should change some parameters in the config.txt, but I have checked and every functionality I need.
284559182-2e54f9bb-2852-4d5a-a8cf-f66d86b5caf8
And as you can see everything is set to "m" or "y" so there shouldn't be a problem there.
I have also looked into my dts file:
284560141-6d68a484-2aba-4206-b582-7e0101bdc1ea
And chatgbt suggested I should do it in this fashion:
284560701-376df592-c917-43f3-bd45-cafaac2f757d

Unfortunately I haven't found anything regarding triggers under this Documentation path linux/Documentation/devicetree/bindings/iio/imu /st,lsm6dsx.yaml .

Also just a side question, is the buffered trigger a hardware trigger from the IMU because that is what I need besides the Hrtimer-trigger. What I really need, is to compare:
-polling the Data-ready register to see whether new data is ready which then serves me as an interrupt if the data is ready
-waiting for hardware interrupt when new data is ready
To compare them I need to know if there is any chance I can do this by using iio-devices or moreover iio-triggers.

And also my ODR can just be configured to 433Hz even though I know for a fact that my IMU can be configured to an ODR of even 1.6KHz. I only need it set to 833Hz but the issue remains. I am a newbie linux, the iio-framework and the device tree, so I would be extremely thankful if you could provide some backround information to your answer, if you think you might have a solution for me.
Thank you very much in advance.

LSM6DSO iio errors

I have added your drivers to the current released tag of the Raspberry Pi kernel version 5.15.74 and compiled the modules for st_lsm6dsox. The module is loaded with the following overlay.

/dts-v1/;
/plugin/;
#include <dt-bindings/interrupt-controller/irq.h>

/ {
        compatible = "brcm,bcm2835";

        fragment@0 {
                target = <&i2c1>;
                __overlay__ {
                        #address-cells = <1>;
                        #size-cells = <0>;
                        status = "okay";
                        clock-frequency = <400000>;

                        lsm6dso: lsm6dso@6a {
                                compatible = "st,lsm6dso";
                                reg = <0x6a>;
                                interrupt-parent = <&gpio>;
                                interrupts = <22 IRQ_TYPE_EDGE_FALLING>,
					     <27 IRQ_TYPE_EDGE_FALLING>;
				st,int-pin = <1>;
                        };
                };
        };

};

The following failures are then observed in dmesg

[ 8.657920] st_lsm6dsox: disagrees about version of symbol iio_push_event
[ 8.657955] st_lsm6dsox: Unknown symbol iio_push_event (err -22)
[ 8.657981] st_lsm6dsox: disagrees about version of symbol iio_push_to_buffers
[ 8.657994] st_lsm6dsox: Unknown symbol iio_push_to_buffers (err -22)
[ 8.658021] st_lsm6dsox: disagrees about version of symbol iio_device_release_direct_mode
[ 8.658033] st_lsm6dsox: Unknown symbol iio_device_release_direct_mode (err -22)
[ 8.658073] st_lsm6dsox: disagrees about version of symbol devm_iio_kfifo_buffer_setup_ext
[ 8.658085] st_lsm6dsox: Unknown symbol devm_iio_kfifo_buffer_setup_ext (err -22)
[ 8.658117] st_lsm6dsox: disagrees about version of symbol iio_device_alloc
[ 8.658129] st_lsm6dsox: Unknown symbol iio_device_alloc (err -22)
[ 8.658153] st_lsm6dsox: disagrees about version of symbol iio_device_free
[ 8.658164] st_lsm6dsox: Unknown symbol iio_device_free (err -22)
[ 8.658206] st_lsm6dsox: disagrees about version of symbol iio_show_mount_matrix
[ 8.658217] st_lsm6dsox: Unknown symbol iio_show_mount_matrix (err -22)
[ 8.658235] st_lsm6dsox: disagrees about version of symbol iio_device_claim_direct_mode
[ 8.658246] st_lsm6dsox: Unknown symbol iio_device_claim_direct_mode (err -22)
[ 8.658284] st_lsm6dsox: disagrees about version of symbol __iio_device_register
[ 8.658296] st_lsm6dsox: Unknown symbol __iio_device_register (err -22)
[ 8.658330] st_lsm6dsox: disagrees about version of symbol __devm_iio_device_register
[ 8.658341] st_lsm6dsox: Unknown symbol __devm_iio_device_register (err -22)
[ 8.658372] st_lsm6dsox: disagrees about version of symbol devm_iio_device_alloc
[ 8.658383] st_lsm6dsox: Unknown symbol devm_iio_device_alloc (err -22)
[ 8.658399] st_lsm6dsox: disagrees about version of symbol iio_get_time_ns
[ 8.658410] st_lsm6dsox: Unknown symbol iio_get_time_ns (err -22)
[ 8.658426] st_lsm6dsox: disagrees about version of symbol iio_device_unregister
[ 8.658437] st_lsm6dsox: Unknown symbol iio_device_unregister (err -22)

LIS2DUX12/LIS2DUXS12 driver create badly named event files

Hi,
I'm using LIS2DUX12 accelerometer in a Linux environment with kernel version 5.10 and I'm testing event monitoring with iio_event_monitor tool. I managed to verify the functionality of a few events (TAP, DTAP, FF and MLC) but I couldn't test the behavior of the SIGN_MOTION event because I'm having a hard time trying to enable that event from C code. This is because the file responsible to track the event enable/disable status has a particularly bad name: in my case it is in_???'L0_thresh_rising_en. This made me realize that a few other event files were also incorrect because they are named like in_(null)0_thresh_rising_en.

So I decided to take a look inside the kernel and the driver to better understand what is going on and I found out that the driver is using custom enum type values to initialize the structure struct iio_chan_spec of these sensor.

/* stm_iio_types.h */
/* Linux IIO driver custom types */
enum {
	STM_IIO_LAST = 0x3f,
	STM_IIO_SIGN_MOTION = STM_IIO_LAST - 6,
	STM_IIO_STEP_COUNTER = STM_IIO_LAST - 5,
	STM_IIO_TILT = STM_IIO_LAST - 4,
	STM_IIO_TAP = STM_IIO_LAST - 3,
	STM_IIO_TAP_TAP = STM_IIO_LAST - 2,
	STM_IIO_WRIST_TILT_GESTURE = STM_IIO_LAST - 1,
	STM_IIO_GESTURE = STM_IIO_LAST,
};
/* st_lis2duxs12.h */
#define ST_LIS2DUXS12_EVENT_CHANNEL(ctype, etype)	\
{							\
	.type = ctype,					\
	.modified = 0,					\
	.scan_index = -1,				\
	.indexed = -1,					\
	.event_spec = &st_lis2duxs12_##etype##_event,	\
	.num_event_specs = 1,				\
}
/* st_lis2duxs12_basicfunc.c */
static const struct iio_chan_spec st_lis2duxs12_ff_channels[] = {
	ST_LIS2DUXS12_EVENT_CHANNEL(STM_IIO_GESTURE, thr),
	IIO_CHAN_SOFT_TIMESTAMP(1),
};
static const struct iio_chan_spec st_lis2duxs12_tap_channels[] = {
	ST_LIS2DUXS12_EVENT_CHANNEL(STM_IIO_TAP, thr),
	IIO_CHAN_SOFT_TIMESTAMP(1),
};
static const struct iio_chan_spec st_lis2duxs12_dtap_channels[] = {
	ST_LIS2DUXS12_EVENT_CHANNEL(STM_IIO_TAP_TAP, thr),
	IIO_CHAN_SOFT_TIMESTAMP(1),
};
static const struct iio_chan_spec st_lis2duxs12_ttap_channels[] = {
	ST_LIS2DUXS12_EVENT_CHANNEL(STM_IIO_GESTURE, thr),
	IIO_CHAN_SOFT_TIMESTAMP(1),
};

For my understanding, this is a problem because when the kernel generates the event names for these sensors/devices, it tries to get a char pointer from the iio_chan_type_name_spec[] variable that has only IIO_MASSCONCENTRATION (=34) items which is less than the first STM custom type STM_IIO_SIGN_MOTION (=57). So our index/type is out of bounds.

/* industrial-core.c */
static const char * const iio_chan_type_name_spec[] = {
	[IIO_VOLTAGE] = "voltage",
	[IIO_CURRENT] = "current",
	[IIO_POWER] = "power",
	[IIO_ACCEL] = "accel",
	[IIO_ANGL_VEL] = "anglvel",
	[IIO_MAGN] = "magn",
	[IIO_LIGHT] = "illuminance",
	[IIO_INTENSITY] = "intensity",
	[IIO_PROXIMITY] = "proximity",
	[IIO_TEMP] = "temp",
	[IIO_INCLI] = "incli",
	[IIO_ROT] = "rot",
	[IIO_ANGL] = "angl",
	[IIO_TIMESTAMP] = "timestamp",
	[IIO_CAPACITANCE] = "capacitance",
	[IIO_ALTVOLTAGE] = "altvoltage",
	[IIO_CCT] = "cct",
	[IIO_PRESSURE] = "pressure",
	[IIO_HUMIDITYRELATIVE] = "humidityrelative",
	[IIO_ACTIVITY] = "activity",
	[IIO_STEPS] = "steps",
	[IIO_ENERGY] = "energy",
	[IIO_DISTANCE] = "distance",
	[IIO_VELOCITY] = "velocity",
	[IIO_CONCENTRATION] = "concentration",
	[IIO_RESISTANCE] = "resistance",
	[IIO_PH] = "ph",
	[IIO_UVINDEX] = "uvindex",
	[IIO_ELECTRICALCONDUCTIVITY] = "electricalconductivity",
	[IIO_COUNT] = "count",
	[IIO_INDEX] = "index",
	[IIO_GRAVITY]  = "gravity",
	[IIO_POSITIONRELATIVE]  = "positionrelative",
	[IIO_PHASE] = "phase",
	[IIO_MASSCONCENTRATION] = "massconcentration",
};

I think this is the point where the empty string messes things up:

/* industrial-core.c */
/* int __iio_device_attr_init() */
case IIO_SEPARATE:
	if (chan->indexed)
		name = kasprintf(GFP_KERNEL, "%s_%s%d_%s",
				iio_direction[chan->output],
				iio_chan_type_name_spec[chan->type],
				chan->channel,
				full_postfix);

Am I understanding this behavior correctly? How can we fix this?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.