-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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: sensor: mpu6050: support for choosing sample rate divider #81649
base: main
Are you sure you want to change the base?
drivers: sensor: mpu6050: support for choosing sample rate divider #81649
Conversation
The mpu6050 sensor driver defaults sensor sample rate to 8KHz which leads to issues on I2C, which cannot support such high sample rates. Fix it by adding sample rate divider to Kconfig, which allows users to lower sensor sample rate. Signed-off-by: Nikola Petrovic <[email protected]>
Hello @nikolaptr, and thank you very much for your first pull request to the Zephyr project! |
drivers/sensor/tdk/mpu6050/Kconfig
Outdated
config MPU6050_SAMPLE_RATE_DIVIDER | ||
int "Data Sample Rate Divider" | ||
range 4 255 | ||
default 7 | ||
help | ||
Sensor Data Sample Rate Divider. | ||
Sensor data Sample Rate = 8000Hz / (1 + Sample Rate Divider). | ||
While using I2C minimal Data Sample Rate Divider is 4, which results in | ||
1600Hz Sensor Data Sample Rate. Sample Rates higher than this are not | ||
recommended while using I2C. | ||
Valid values: X = [4, 255]. |
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.
This should be a devicetree property so it can be configured on a per-instance basis
drivers/sensor/tdk/mpu6050/mpu6050.c
Outdated
uint16_t sensitivity_shift) | ||
uint16_t sensitivity_shift) | ||
{ | ||
int64_t conv_val; | ||
int64_t conv_val; | ||
|
||
conv_val = ((int64_t)raw_val * SENSOR_G) >> sensitivity_shift; | ||
val->val1 = conv_val / 1000000; | ||
val->val2 = conv_val % 1000000; | ||
conv_val = ((int64_t)raw_val * SENSOR_G) >> sensitivity_shift; | ||
val->val1 = conv_val / 1000000; | ||
val->val2 = conv_val % 1000000; |
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.
Please revert this and all of the other whitespace changes that are unrelated to adding the new sample rate divider
Revert whitespace changes which are unrelated to adding new sample rate divider Signed-off-by: Nikola Petrovic <[email protected]>
Configuration of sample rate divider using Kconfig doesn't allow device configuration on a per-instance basis. Sample rate divider is added as sensor devicetree property. Signed-off-by: Nikola Petrovic <[email protected]>
Code is failing compliance check. Fix by running clang-format and adressing compliance check issues. Signed-off-by: Nikola Petrovic <[email protected]>
0d4df16
to
031a929
Compare
The mpu6050 sensor driver defaults sensor sample rate to 8KHz which leads to issues on I2C, which cannot support such high sample rates. Fix it by adding sample rate divider to Kconfig, which allows users to lower sensor sample rate.