Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

nikolaptr
Copy link

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.

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]>
Copy link

Hello @nikolaptr, 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. 😊

Comment on lines 72 to 82
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].
Copy link
Member

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

Comment on lines 21 to 27
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;
Copy link
Member

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants