-
Notifications
You must be signed in to change notification settings - Fork 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
Add Tdk invensense icp201xx pressure sensor support #83914
base: main
Are you sure you want to change the base?
Add Tdk invensense icp201xx pressure sensor support #83914
Conversation
The following west manifest projects have changed revision in this Pull Request:
✅ All manifest checks OK Note: This message is automatically posted and updated by the Manifest GitHub Action. |
92248ff
to
4e866f3
Compare
4e866f3
to
90baab8
Compare
Hi @MaureenHelm , |
#ifdef CONFIG_CPU_HAS_FPU | ||
#include <math.h> | ||
#define ATMOSPHERICAL_PRESSURE_KPA ((float)101.325) | ||
#define TO_KELVIN(temp_C) (((float)273.15) + temp_C) | ||
/* Constant in altitude formula: | ||
* M*g/R = (0,0289644 * 9,80665 / 8,31432) | ||
* with M the molar mass of air. | ||
* with g the gravitational force acceleration. | ||
* with R the universal gaz constant. | ||
*/ | ||
#define HEIGHT_TO_PRESSURE_COEFF ((float)0.03424) | ||
|
||
/* Constant in altitude formula: | ||
* R / (M*g) = 8,31432 / (0,0289644 * 9,80665) | ||
* with M the molar mass of air. | ||
* with g the gravitational force acceleration. | ||
* with R the universal gaz constant. | ||
*/ | ||
#define PRESSURE_TO_HEIGHT_COEFF ((float)29.27127) | ||
/* Constant for altitude formula: | ||
* logarithm of pressure at 0m | ||
* ln(101.325) | ||
*/ | ||
#define LOG_ATMOSPHERICAL_PRESSURE ((float)4.61833) | ||
#endif |
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 consider using the dsp.h
q31_t
here
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.
At some point, it requires pure floats to compute logarithm.
I don't think dsp.h provides such support.
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.
Does it? The DSP header provide mechanism for multiplying fixed points which can be just as accurate. I'm OK with you using floats, but it does make the driver much more compute header when CONFIG_FPU=n
.
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.
I still don't think you actually need a float, you should be able to use a fixed point API.
90baab8
to
aedacd0
Compare
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 also add relevant entries to build_all/sensors dtsi's and conf files as this is the only way to be certain we'll have coverage independently of the existence of samples and respective overlays.
Thanks!
sample.sensor.pressure_sensor: | ||
build_only: true | ||
tags: sensors | ||
filter: dt_alias_exists("pressure_sensor") |
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 currently doesn't run. Needs the following change, but also keep only of the two overlay and name it nrf52dk_nrf52832.overlay
(otherwise neither gets picked up, hence no pressure-sensor alias is found, hence test is filtered :) )
filter: dt_alias_exists("pressure_sensor") | |
filter: dt_alias_exists("pressure-sensor") |
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, fixed.
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 currently doesn't run. Needs the following change, but also keep only of the two overlays and name it nrf52dk_nrf52832.overlay (otherwise neither gets picked up, hence no pressure-sensor alias is found, hence test is filtered :) )
not addressed and therefore test would effectively still not run
sample.sensor.pressure_interrupt: | ||
build_only: true | ||
tags: sensors | ||
filter: dt_alias_exists("pressure_sensor") |
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.
ditto :)
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, fixed.
@@ -0,0 +1,72 @@ | |||
.. zephyr:code-sample: pressure_interrupt |
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.
doesn't show up in samples listing due to typo
Also, varisou formatting issues with the file, please check https://builds.zephyrproject.io/zephyr/pr/83914/docs/samples/sensor/pressure_interrupt/README.html -- applies to the other README too :)
.. zephyr:code-sample: pressure_interrupt | |
.. :zephyr:code-sample: pressure_interrupt |
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 colon is probably not the suggested one :), but it was actually missing!
Thanks, fixed.
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.
lol oops
This sample application uses a pressure sensor interrupt line to: | ||
** Inform when a measure is available in the sensor FIFO. | ||
Temperature and pressure data are read and displayed in terminal. | ||
If floats are supported, estimated altitude is also displayed. | ||
** Inform when the pressure value crosses a specified threshold. | ||
Threshold corresponds to around a 50cm altitude increase. | ||
A message is displayed in the terminal. | ||
** Inform when the pressure value changed more than the specified | ||
value between two consecutive samples. | ||
Change value corresponds to a finger pressing the sensor. | ||
A message is displayed in the terminal. |
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 sample application uses a pressure sensor interrupt line to: | |
** Inform when a measure is available in the sensor FIFO. | |
Temperature and pressure data are read and displayed in terminal. | |
If floats are supported, estimated altitude is also displayed. | |
** Inform when the pressure value crosses a specified threshold. | |
Threshold corresponds to around a 50cm altitude increase. | |
A message is displayed in the terminal. | |
** Inform when the pressure value changed more than the specified | |
value between two consecutive samples. | |
Change value corresponds to a finger pressing the sensor. | |
A message is displayed in the terminal. | |
This sample application uses a pressure sensor interrupt line to: | |
* Inform when a measure is available in the sensor FIFO. | |
Temperature and pressure data are read and displayed in terminal. | |
If floats are supported, estimated altitude is also displayed. | |
* Inform when the pressure value crosses a specified threshold. | |
Threshold corresponds to around a 50cm altitude increase. | |
A message is displayed in the terminal. | |
* Inform when the pressure value changed more than the specified | |
value between two consecutive samples. | |
Change value corresponds to a finger pressing the sensor. | |
A message is displayed in the terminal. |
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, fixed.
## Default configuration | ||
|
||
[00:00:00.266,479] <inf> PRESS_INT_SAMPLE: Starting ICP201xx sample. | ||
[00:00:00.273,803] <inf> PRESS_INT_SAMPLE: temp 25.49 Cel, pressure 96.271438 kPa, altitude 447.208465 m | ||
[00:00:00.280,914] <inf> PRESS_INT_SAMPLE: temp 25.50 Cel, pressure 96.271331 kPa, altitude 447.234161 m | ||
[00:00:00.288,024] <inf> PRESS_INT_SAMPLE: temp 25.49 Cel, pressure 96.266685 kPa, altitude 447.636077 m | ||
[00:00:00.295,135] <inf> PRESS_INT_SAMPLE: temp 25.50 Cel, pressure 96.267951 kPa, altitude 447.537078 m | ||
[00:00:00.302,246] <inf> PRESS_INT_SAMPLE: temp 25.51 Cel, pressure 96.268577 kPa, altitude 447.488281 m | ||
[00:00:00.309,356] <inf> PRESS_INT_SAMPLE: temp 25.50 Cel, pressure 96.269340 kPa, altitude 447.414978 m | ||
[00:00:00.316,467] <inf> PRESS_INT_SAMPLE: temp 25.50 Cel, pressure 96.268562 kPa, altitude 447.473663 m | ||
[00:00:00.323,547] <inf> PRESS_INT_SAMPLE: temp 25.50 Cel, pressure 96.267341 kPa, altitude 447.596496 m | ||
<repeats endlessly> | ||
|
||
<when sensor is pressed> | ||
[00:00:09.819,061] <inf> PRESS_INT_SAMPLE: PRESSURE CHANGE INTERRUPT | ||
|
||
<when the sensor pressure crosses defined threhold> | ||
[00:00:09.859,039] <inf> PRESS_INT_SAMPLE: PRESSURE THRESHOLD INTERRUPT |
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.
needs 3-space indenting
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, fixed.
/ { | ||
aliases { | ||
pressure-sensor = &icp201xx; | ||
}; | ||
}; |
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.
/ { | |
aliases { | |
pressure-sensor = &icp201xx; | |
}; | |
}; | |
/ { | |
aliases { | |
pressure-sensor = &icp201xx; | |
}; | |
}; |
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, fixed.
444d9aa
to
52640a9
Compare
icp201xx_reg_write_fn write; | ||
}; | ||
|
||
#if CONFIG_SPI |
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.
Ping
#ifdef CONFIG_CPU_HAS_FPU | ||
#include <math.h> | ||
#define ATMOSPHERICAL_PRESSURE_KPA ((float)101.325) | ||
#define TO_KELVIN(temp_C) (((float)273.15) + temp_C) | ||
/* Constant in altitude formula: | ||
* M*g/R = (0,0289644 * 9,80665 / 8,31432) | ||
* with M the molar mass of air. | ||
* with g the gravitational force acceleration. | ||
* with R the universal gaz constant. | ||
*/ | ||
#define HEIGHT_TO_PRESSURE_COEFF ((float)0.03424) | ||
|
||
/* Constant in altitude formula: | ||
* R / (M*g) = 8,31432 / (0,0289644 * 9,80665) | ||
* with M the molar mass of air. | ||
* with g the gravitational force acceleration. | ||
* with R the universal gaz constant. | ||
*/ | ||
#define PRESSURE_TO_HEIGHT_COEFF ((float)29.27127) | ||
/* Constant for altitude formula: | ||
* logarithm of pressure at 0m | ||
* ln(101.325) | ||
*/ | ||
#define LOG_ATMOSPHERICAL_PRESSURE ((float)4.61833) | ||
#endif |
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.
I still don't think you actually need a float, you should be able to use a fixed point API.
52640a9
to
a37bc76
Compare
@yperess, it's not clear to me how I could compute a logarithm only using fixed points. |
this part hasn't been addressed - thanks! |
I see we haven't ported this part of the math functions to the DSP subsystem yet. I'll get on that for the next release. The API will look like https://github.com/zephyrproject-rtos/cmsis-dsp/blob/main/Include/dsp/fast_math_functions.h#L158. Please address the issue in #83914 (comment) and I'll be happy to approve as is. |
1c54338
to
e4607ac
Compare
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.
looks great, thank you! Just a final nit
<&test_gpio 0 0>; | ||
<&test_gpio 0 0>; /* 0x31 */ |
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.
I think the original intent here is to give a visual clue every 10 lines, so probably needs to be:
<&test_gpio 0 0>; | |
<&test_gpio 0 0>; /* 0x31 */ | |
<&test_gpio 0 0>; /* 0x30 */ | |
<&test_gpio 0 0>; |
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.
I think the original intent here is to give a visual clue every 10 lines, so probably needs to be:
Thanks for active follow up ;)
I'll fix.
e4607ac
to
8815ad9
Compare
Sure, it's now done. |
icp201xx are barometric pressure and temperature sensors. https://invensense.tdk.com/smartpressure Signed-off-by: Remi Buisson <remi.buisson@tdk.com>
Use official TDK Invensense driver for icp201xx sensor in tdk_hal module. Signed-off-by: Remi Buisson <remi.buisson@tdk.com>
Add I2C and SPI variants for icp201xx. Signed-off-by: Remi Buisson <remi.buisson@tdk.com>
Polls and reports pressure, temperature and altitude data Signed-off-by: Remi Buisson <remi.buisson@tdk.com>
Reports generic barometric sensor interrupts * Data ready interrupt * Pressure threshold interrupt * Pressure changed interrupt Signed-off-by: Remi Buisson <remi.buisson@tdk.com>
8815ad9
to
39f0118
Compare
drivers: sensor: icp201xx: supports icp201xx sensors
dts: supports icp201xx invn pressure sensor
samples: sensor: pressure_polling: barometric pressure, temperature and altitude generic sample
samples: sensor: pressure_interrupt: barometric pressure sensor interrupts generic sample
module: HAL TDK module
Adds official TDK Invensense Inc. driver in TDK HAL module for icp201xx sensor.
Add generic samples supporting this driver.
Validated with custom setup: nrf52dk_nrf52832 + icp201xx EVB board
Build ok by running:
west twister -T samples\sensor\pressure_polling -T samples\sensor\pressure_interrupt -p nrf52dk/nrf52832
Signed-off-by: Remi Buisson remi.buisson@tdk.com