Skip to content

Conversation

@miggazElquez
Copy link
Contributor

This patch add a driver for the st lsm9ds1 sensor (https://www.st.com/en/mems-and-sensors/lsm9ds1.html).

It also fix a bug in the accel_polling sample.

@miggazElquez miggazElquez requested a review from avisconti as a code owner May 22, 2024 10:04
@zephyrbot zephyrbot added area: Samples Samples area: Devicetree Binding PR modifies or adds a Device Tree binding area: Sensors Sensors labels May 22, 2024
@github-actions
Copy link

Hello @miggazElquez, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing justification

Copy link
Contributor

@kartben kartben May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I added the justification

@miggazElquez miggazElquez force-pushed the lsm9ds1_driver branch 3 times, most recently from fc337be to 1601cfc Compare May 29, 2024 08:08
Copy link

@jeppenodgaard jeppenodgaard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost got through the lsm9ds1 part. Can the lsm9ds1_mac part be split into another PR?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if defined(CONFIG_LSM9DS1_ENABLE_TEMP)
#if IS_ENABLED(CONFIG_LSM9DS1_ENABLE_TEMP)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the 0 be 4?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The raw odr value (index of the array) can only be 0,1 or 3. I added a comment to explain it, but maybe I should put another value than 0 ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably LOG_ERR since accel and gyro probably have non-matching values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, the sensor will still work but the code will break.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if 15 is chosen here when accel seems to want 10? Would it make sense to check for equal values before changing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the gyroscope is on, the frequencies of the gyroscope are the one that matters.
So if the gyroscope is off, accel can be at 10 Hz, if the gyroscope is on, accel will be at 15 Hz (or another frequency on the gyroscope list), and can't be at 10 Hz as long as the gyroscope is on.
In fact, if the gyroscope is on, the value of the odr register of the accel is ignored, but the documentation and the HAL wants to have the same value in both registers, so I set it to the right value.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0x7 probably needs a define.

@miggazElquez miggazElquez force-pushed the lsm9ds1_driver branch 2 times, most recently from 3fe7f13 to c1c17a6 Compare May 30, 2024 14:28
@miggazElquez
Copy link
Contributor Author

Almost got through the lsm9ds1 part. Can the lsm9ds1_mac part be split into another PR?

Done, the mag part is now on #73530

@miggazElquez miggazElquez changed the title Lsm9ds1 driver drivers: Lsm9ds1 driver May 31, 2024
Copy link

@jeppenodgaard jeppenodgaard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The header could benefit from clang-format and probably also the source.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to return if device return -ENOTSUP?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a lot of drivers the "attr_get" function is not implemented, so if we return here the sample will not work for these sensors. My idea was that in the case we don't get an answer, we just assume that the frequency isn't correct, and try to set one. If the frequency was set, and we change it to another frequency than the default one, it's not really a problem, as we just need to fetch samples every second.

@miggazElquez
Copy link
Contributor Author

The header could benefit from clang-format and probably also the source.

I didn't know this tool, thanks for the recommendation.

@miggazElquez miggazElquez force-pushed the lsm9ds1_driver branch 2 times, most recently from 52c8808 to 71ffa5f Compare June 10, 2024 12:25
Copy link
Member

@MaureenHelm MaureenHelm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to rebase and resolve conflicts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we sleep instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like it work. I did a busy wait because I saw that other similar drivers did the same, and I didn't checked.

This commit adds a description for the lsm9ds1 sensor,
with a .h file containing all configuration options.

Signed-off-by: Miguel Gazquez <[email protected]>
@miggazElquez miggazElquez force-pushed the lsm9ds1_driver branch 2 times, most recently from 76a2890 to 3041044 Compare June 17, 2024 11:53
Copy link
Contributor

@avisconti avisconti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but maybe it's better to add few comments in the commit message:

  • no trigger support
  • only I2C
  • no mag support

avisconti
avisconti previously approved these changes Jun 20, 2024
Copy link
Contributor

@avisconti avisconti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job.

@miggazElquez
Copy link
Contributor Author

@MaureenHelm does this look good to you now ?

The LSM9DS1 is a system-in-package featuring
a 3D digital linear acceleration sensor, a 3D digital angular rate
sensor and a 3D digital magnetic sensor.

This driver implements only the linear acceleration sensor and the
angular rate sensor, on the I2C bus.

This driver is without trigger support.

The driver is based on the stmemsc HAL.

link: https://www.st.com/resource/en/datasheet/lsm9ds1.pdf

Signed-off-by: Miguel Gazquez <[email protected]>
Describe the lsm9ds1 sensor available in the Arduino Nano 33 BLE through
I2C.
Set the accel0 alias.

Signed-off-by: Miguel Gazquez <[email protected]>
The accel_polling sample uses various sensor, but doesn't set a sampling
rate. But some sensors (like st,lsm6dso) have a default sampling
frequency of 0. So, depending on the sensor, the sample may not always
work.

There are two ways to fix this: either all drivers must set a valid
sampling rate, or the sample shall at least try to set a value if there
is none.

We propose here the second approach, wich should allow the sample to
work on more sensors out of the box.

Signed-off-by: Miguel Gazquez <[email protected]>
@miggazElquez
Copy link
Contributor Author

I just fixed some typos I saw in comments, the driver didn't change otherwise.

@MaureenHelm MaureenHelm added this to the v4.0.0 milestone Jul 9, 2024
@aescolar aescolar merged commit f6f0386 into zephyrproject-rtos:main Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Devicetree Binding PR modifies or adds a Device Tree binding area: Samples Samples area: Sensors Sensors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants