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

sensors: test: Add attribute support to sensor emulator backend #65278

Merged
merged 7 commits into from
Jan 16, 2024

Conversation

yperess
Copy link
Collaborator

@yperess yperess commented Nov 16, 2023

  • Fix BMI160 to align with data sheet
  • Add BMI160 emulator backend so the data collection tests can be done by the generic test
  • Add attribute 'get' support to BMI160 and emulator backend
  • Write custom tests for bus failures on the BMI160

drivers/i2c/i2c_emul.c Outdated Show resolved Hide resolved
drivers/i2c/i2c_emul.c Show resolved Hide resolved
drivers/sensor/akm09918c/akm09918c_emul.c Show resolved Hide resolved
include/zephyr/drivers/i2c_emul.h Show resolved Hide resolved
drivers/sensor/bmi160/bmi160.c Show resolved Hide resolved
@yperess
Copy link
Collaborator Author

yperess commented Dec 12, 2023

Removed C++

teburd
teburd previously approved these changes Dec 12, 2023
alevkoy
alevkoy previously approved these changes Dec 12, 2023
@yperess
Copy link
Collaborator Author

yperess commented Dec 22, 2023

@henrikbrixandersen @MaureenHelm any chance to get another review pass before the end of the year? This is a blocker for us to use upstream drivers

tristan-google
tristan-google previously approved these changes Dec 22, 2023
drivers/sensor/bmi160/emul_bmi160.c Outdated Show resolved Hide resolved
drivers/sensor/bmi160/bmi160.c Show resolved Hide resolved
tests/drivers/sensor/accel/src/main.c Outdated Show resolved Hide resolved
@yperess
Copy link
Collaborator Author

yperess commented Jan 12, 2024

The push above is just a rebase so that the Compare button with @MaureenHelm 's requested changes doesn't show the rebase diff. Changes coming in a few minutes.

Update the backend for sensor emulators to include a function for
setting the offset as well as a function to query an attribute's
metadata such as bounds and increment size. Additionally, add
backend support for setting the _xyz channel values.

Make the appropriate test changes to accomodate.

Signed-off-by: Yuval Peress <[email protected]>
The logic in the driver was not aligned to the datasheet. Also,
temperature reading was not being done in fetch, but in channel_get.
There was also some extra conversions from SI->register->SI when
setting the range, this was causing the register value calculation to
produce an incorrect scale in some cases.

Tests were added to cover these cases.

Signed-off-by: Yuval Peress <[email protected]>
Add support for getting the following attribute values:
- SENSOR_ATTR_OFFSET
- SENSOR_ATTR_SAMPLING_FREQUENCY
- SENSOR_ATTR_FULL_SCALE

Signed-off-by: Yuval Peress <[email protected]>
Adding a hook for tests to inject a mock transport and migrating the
accel test to test bmi160 specific things. The old version of the test
which checks for read values is now covered by the generic test in
the sensor build_all target.

Signed-off-by: Yuval Peress <[email protected]>
Rename the test directory to more accuratly reflect what's being
tested.

Signed-off-by: Yuval Peress <[email protected]>
The range map was sorted wrong since the function
bmi160_range_to_reg_val() that uses it checks for the user value less
than the range component of the bmi160_range struct. This means that
no matter what range is set, the value will always end up 2000dps.

Signed-off-by: Yuval Peress <[email protected]>
As an example, when the gyro range is set to 250 deg/sec the scale
was set to 133 where it really should be 133.160058662. This leads
to a 0.12% error in the value returned. By separating the numerator
and denominator, we're able to drastically reduce the error.

Signed-off-by: Yuval Peress <[email protected]>
@carlescufi carlescufi merged commit 9381e86 into zephyrproject-rtos:main Jan 16, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants