-
Notifications
You must be signed in to change notification settings - Fork 8.2k
drivers: Lsm9ds1 driver #73141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers: Lsm9ds1 driver #73141
Conversation
|
Hello @miggazElquez, and thank you very much for your first pull request to the Zephyr project! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing justification
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
fc337be to
1601cfc
Compare
jeppenodgaard
left a comment
There was a problem hiding this 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?
drivers/sensor/st/lsm9ds1/lsm9ds1.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #if defined(CONFIG_LSM9DS1_ENABLE_TEMP) | |
| #if IS_ENABLED(CONFIG_LSM9DS1_ENABLE_TEMP) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
drivers/sensor/st/lsm9ds1/lsm9ds1.c
Outdated
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ?
drivers/sensor/st/lsm9ds1/lsm9ds1.c
Outdated
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
drivers/sensor/st/lsm9ds1/lsm9ds1.c
Outdated
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
drivers/sensor/st/lsm9ds1/lsm9ds1.c
Outdated
There was a problem hiding this comment.
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.
3fe7f13 to
c1c17a6
Compare
Done, the mag part is now on #73530 |
jeppenodgaard
left a comment
There was a problem hiding this 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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
I didn't know this tool, thanks for the recommendation. |
52c8808 to
71ffa5f
Compare
MaureenHelm
left a comment
There was a problem hiding this 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
drivers/sensor/st/lsm9ds1/lsm9ds1.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we sleep instead?
There was a problem hiding this comment.
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.
71ffa5f to
6f15e19
Compare
This commit adds a description for the lsm9ds1 sensor, with a .h file containing all configuration options. Signed-off-by: Miguel Gazquez <[email protected]>
76a2890 to
3041044
Compare
avisconti
left a comment
There was a problem hiding this 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
3041044 to
d71bab4
Compare
avisconti
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job.
|
@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]>
d71bab4 to
5d50211
Compare
|
I just fixed some typos I saw in comments, the driver didn't change otherwise. |
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.