Initial commit of Adafruit BMP5xx library
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
commit
d5c35e955d
12 changed files with 4838 additions and 0 deletions
13
.clang-format
Normal file
13
.clang-format
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
Language: Cpp
|
||||
BasedOnStyle: Google
|
||||
IndentWidth: 2
|
||||
ColumnLimit: 80
|
||||
AllowShortFunctionsOnASingleLine: Empty
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BreakBeforeBraces: Attach
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Left
|
||||
SpacesBeforeTrailingComments: 1
|
||||
37
.github/workflows/githubci.yml
vendored
Normal file
37
.github/workflows/githubci.yml
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
name: Arduino Library CI
|
||||
|
||||
on: [pull_request, push, repository_dispatch]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
arduino-platform: ["uno", "leonardo", "zero", "esp8266", "esp32", "metro_m4"]
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.x'
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
repository: adafruit/ci-arduino
|
||||
path: ci
|
||||
|
||||
- name: pre-install
|
||||
run: bash ci/actions_install.sh
|
||||
|
||||
- name: test platforms
|
||||
run: python3 ci/build_platform.py ${{ matrix.arduino-platform }}
|
||||
|
||||
- name: clang
|
||||
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .
|
||||
|
||||
- name: doxygen
|
||||
env:
|
||||
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
|
||||
PRETTYNAME : "Adafruit BMP5xx Library"
|
||||
run: bash ci/doxy_gen_and_deploy.sh
|
||||
17
.gitignore
vendored
Normal file
17
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# Datasheet files
|
||||
*.pdf
|
||||
*.txt
|
||||
|
||||
# Build artifacts
|
||||
*.o
|
||||
*.hex
|
||||
*.elf
|
||||
|
||||
# IDE files
|
||||
.vscode/
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# System files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
29
LICENSE
Normal file
29
LICENSE
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2024 Adafruit Industries
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
36
README.md
Normal file
36
README.md
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# Adafruit BMP5xx Library [](https://github.com/adafruit/Adafruit_BMP5xx/actions)[](http://adafruit.github.io/Adafruit_BMP5xx/html/index.html)
|
||||
|
||||
Arduino library for the BMP5xx (BMP580/BMP581) pressure and temperature sensors.
|
||||
|
||||
## About the BMP5xx
|
||||
|
||||
The BMP5xx series (BMP580/BMP581) are high-precision barometric pressure sensors from Bosch Sensortec featuring:
|
||||
|
||||
- High-resolution 24-bit pressure and temperature measurements
|
||||
- I2C and SPI interface support
|
||||
- Built-in digital signal processing with IIR filter
|
||||
- Multiple power modes for optimized power consumption
|
||||
- Configurable oversampling and output data rates
|
||||
- Wide operating temperature range: -40°C to +85°C
|
||||
- Pressure range: 300-1250 hPa
|
||||
- Low power consumption
|
||||
- FIFO buffer support
|
||||
|
||||
## Installation
|
||||
|
||||
To install, use the Arduino Library Manager and search for "Adafruit BMP5xx", and install the library.
|
||||
|
||||
### Dependencies
|
||||
|
||||
This library depends on:
|
||||
|
||||
- [Adafruit Unified Sensor](https://github.com/adafruit/Adafruit_Sensor)
|
||||
- [Adafruit BusIO](https://github.com/adafruit/Adafruit_BusIO)
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome! Please read our [Code of Conduct](https://github.com/adafruit/Adafruit_BMP5xx/blob/main/CODE_OF_CONDUCT.md) before contributing to help this project stay welcoming.
|
||||
|
||||
## License
|
||||
|
||||
BSD license, all text above must be included in any redistribution. See LICENSE file for details.
|
||||
226
examples/bmp5xx_test/bmp5xx_test.ino
Normal file
226
examples/bmp5xx_test/bmp5xx_test.ino
Normal file
|
|
@ -0,0 +1,226 @@
|
|||
/*!
|
||||
* @file bmp5xx_test.ino
|
||||
*
|
||||
* This is a comprehensive test sketch for the BMP5xx pressure and temperature sensor.
|
||||
* It demonstrates all settings with pretty-printed output and continuous mode operation.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Limor "ladyada" Fried for Adafruit Industries.
|
||||
* BSD license, all text above must be included in any redistribution
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include "Adafruit_BMP5xx.h"
|
||||
|
||||
#define SEALEVELPRESSURE_HPA (1013.25)
|
||||
|
||||
Adafruit_BMP5xx bmp; // Create BMP5xx object
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while (!Serial) delay(10); // Wait for Serial Monitor to open
|
||||
|
||||
Serial.println(F("Adafruit BMP5xx Comprehensive Test!"));
|
||||
|
||||
// Try to initialize the sensor
|
||||
// bmp.begin(address, &Wire) - address defaults to 0x46, Wire peripheral defaults to &Wire
|
||||
if (!bmp.begin(BMP5XX_ALTERNATIVE_ADDRESS, &Wire)) {
|
||||
Serial.println(F("Could not find a valid BMP5xx sensor, check wiring or "
|
||||
"try a different address!"));
|
||||
while (1) delay(10);
|
||||
}
|
||||
|
||||
Serial.println(F("BMP5xx found!"));
|
||||
Serial.println();
|
||||
|
||||
// Demonstrate all setter functions with range documentation
|
||||
Serial.println(F("=== Setting Up Sensor Configuration ==="));
|
||||
|
||||
/* Temperature Oversampling Settings:
|
||||
* BMP5XX_OVERSAMPLING_1X - 1x oversampling (fastest, least accurate)
|
||||
* BMP5XX_OVERSAMPLING_2X - 2x oversampling
|
||||
* BMP5XX_OVERSAMPLING_4X - 4x oversampling
|
||||
* BMP5XX_OVERSAMPLING_8X - 8x oversampling
|
||||
* BMP5XX_OVERSAMPLING_16X - 16x oversampling
|
||||
* BMP5XX_OVERSAMPLING_32X - 32x oversampling
|
||||
* BMP5XX_OVERSAMPLING_64X - 64x oversampling
|
||||
* BMP5XX_OVERSAMPLING_128X - 128x oversampling (slowest, most accurate)
|
||||
*/
|
||||
Serial.println(F("Setting temperature oversampling to 2X..."));
|
||||
bmp.setTemperatureOversampling(BMP5XX_OVERSAMPLING_2X);
|
||||
|
||||
/* Pressure Oversampling Settings (same options as temperature):
|
||||
* Higher oversampling = better accuracy but slower readings
|
||||
* Recommended: 16X for good balance of speed/accuracy
|
||||
*/
|
||||
Serial.println(F("Setting pressure oversampling to 16X..."));
|
||||
bmp.setPressureOversampling(BMP5XX_OVERSAMPLING_16X);
|
||||
|
||||
/* IIR Filter Coefficient Settings:
|
||||
* BMP5XX_IIR_FILTER_BYPASS - No filtering (fastest response)
|
||||
* BMP5XX_IIR_FILTER_COEFF_1 - Light filtering
|
||||
* BMP5XX_IIR_FILTER_COEFF_3 - Medium filtering
|
||||
* BMP5XX_IIR_FILTER_COEFF_7 - More filtering
|
||||
* BMP5XX_IIR_FILTER_COEFF_15 - Heavy filtering
|
||||
* BMP5XX_IIR_FILTER_COEFF_31 - Very heavy filtering
|
||||
* BMP5XX_IIR_FILTER_COEFF_63 - Maximum filtering
|
||||
* BMP5XX_IIR_FILTER_COEFF_127- Maximum filtering (slowest response)
|
||||
*/
|
||||
Serial.println(F("Setting IIR filter to coefficient 3..."));
|
||||
bmp.setIIRFilterCoeff(BMP5XX_IIR_FILTER_COEFF_3);
|
||||
|
||||
/* Output Data Rate Settings (Hz):
|
||||
* BMP5XX_ODR_240_HZ, BMP5XX_ODR_218_5_HZ, BMP5XX_ODR_199_1_HZ
|
||||
* BMP5XX_ODR_179_2_HZ, BMP5XX_ODR_160_HZ, BMP5XX_ODR_149_3_HZ
|
||||
* BMP5XX_ODR_140_HZ, BMP5XX_ODR_129_8_HZ, BMP5XX_ODR_120_HZ
|
||||
* BMP5XX_ODR_110_1_HZ, BMP5XX_ODR_100_2_HZ, BMP5XX_ODR_89_6_HZ
|
||||
* BMP5XX_ODR_80_HZ, BMP5XX_ODR_70_HZ, BMP5XX_ODR_60_HZ, BMP5XX_ODR_50_HZ
|
||||
* BMP5XX_ODR_45_HZ, BMP5XX_ODR_40_HZ, BMP5XX_ODR_35_HZ, BMP5XX_ODR_30_HZ
|
||||
* BMP5XX_ODR_25_HZ, BMP5XX_ODR_20_HZ, BMP5XX_ODR_15_HZ, BMP5XX_ODR_10_HZ
|
||||
* BMP5XX_ODR_05_HZ, BMP5XX_ODR_04_HZ, BMP5XX_ODR_03_HZ, BMP5XX_ODR_02_HZ
|
||||
* BMP5XX_ODR_01_HZ, BMP5XX_ODR_0_5_HZ, BMP5XX_ODR_0_250_HZ, BMP5XX_ODR_0_125_HZ
|
||||
*/
|
||||
Serial.println(F("Setting output data rate to 50 Hz..."));
|
||||
bmp.setOutputDataRate(BMP5XX_ODR_50_HZ);
|
||||
|
||||
/* Power Mode Settings:
|
||||
* BMP5XX_POWERMODE_STANDBY - Standby mode (no measurements)
|
||||
* BMP5XX_POWERMODE_NORMAL - Normal mode (periodic measurements)
|
||||
* BMP5XX_POWERMODE_FORCED - Forced mode (single measurement then standby)
|
||||
* BMP5XX_POWERMODE_CONTINOUS - Continuous mode (fastest measurements)
|
||||
* BMP5XX_POWERMODE_DEEP_STANDBY - Deep standby (lowest power)
|
||||
*/
|
||||
Serial.println(F("Setting power mode to continuous..."));
|
||||
bmp.setPowerMode(BMP5XX_POWERMODE_CONTINOUS);
|
||||
|
||||
/* Enable/Disable Pressure Measurement:
|
||||
* true - Enable pressure measurement (default)
|
||||
* false - Disable pressure measurement (temperature only)
|
||||
*/
|
||||
Serial.println(F("Enabling pressure measurement..."));
|
||||
bmp.enablePressure(true);
|
||||
|
||||
Serial.println();
|
||||
Serial.println(F("=== Current Sensor Configuration ==="));
|
||||
|
||||
// Pretty print temperature oversampling inline
|
||||
Serial.print(F("Temperature Oversampling: "));
|
||||
switch(bmp.getTemperatureOversampling()) {
|
||||
case BMP5XX_OVERSAMPLING_1X: Serial.println(F("1X")); break;
|
||||
case BMP5XX_OVERSAMPLING_2X: Serial.println(F("2X")); break;
|
||||
case BMP5XX_OVERSAMPLING_4X: Serial.println(F("4X")); break;
|
||||
case BMP5XX_OVERSAMPLING_8X: Serial.println(F("8X")); break;
|
||||
case BMP5XX_OVERSAMPLING_16X: Serial.println(F("16X")); break;
|
||||
case BMP5XX_OVERSAMPLING_32X: Serial.println(F("32X")); break;
|
||||
case BMP5XX_OVERSAMPLING_64X: Serial.println(F("64X")); break;
|
||||
case BMP5XX_OVERSAMPLING_128X: Serial.println(F("128X")); break;
|
||||
default: Serial.println(F("Unknown")); break;
|
||||
}
|
||||
|
||||
// Pretty print pressure oversampling inline
|
||||
Serial.print(F("Pressure Oversampling: "));
|
||||
switch(bmp.getPressureOversampling()) {
|
||||
case BMP5XX_OVERSAMPLING_1X: Serial.println(F("1X")); break;
|
||||
case BMP5XX_OVERSAMPLING_2X: Serial.println(F("2X")); break;
|
||||
case BMP5XX_OVERSAMPLING_4X: Serial.println(F("4X")); break;
|
||||
case BMP5XX_OVERSAMPLING_8X: Serial.println(F("8X")); break;
|
||||
case BMP5XX_OVERSAMPLING_16X: Serial.println(F("16X")); break;
|
||||
case BMP5XX_OVERSAMPLING_32X: Serial.println(F("32X")); break;
|
||||
case BMP5XX_OVERSAMPLING_64X: Serial.println(F("64X")); break;
|
||||
case BMP5XX_OVERSAMPLING_128X: Serial.println(F("128X")); break;
|
||||
default: Serial.println(F("Unknown")); break;
|
||||
}
|
||||
|
||||
// Pretty print IIR filter coefficient inline
|
||||
Serial.print(F("IIR Filter Coefficient: "));
|
||||
switch(bmp.getIIRFilterCoeff()) {
|
||||
case BMP5XX_IIR_FILTER_BYPASS: Serial.println(F("Bypass (No filtering)")); break;
|
||||
case BMP5XX_IIR_FILTER_COEFF_1: Serial.println(F("1 (Light filtering)")); break;
|
||||
case BMP5XX_IIR_FILTER_COEFF_3: Serial.println(F("3 (Medium filtering)")); break;
|
||||
case BMP5XX_IIR_FILTER_COEFF_7: Serial.println(F("7 (More filtering)")); break;
|
||||
case BMP5XX_IIR_FILTER_COEFF_15: Serial.println(F("15 (Heavy filtering)")); break;
|
||||
case BMP5XX_IIR_FILTER_COEFF_31: Serial.println(F("31 (Very heavy filtering)")); break;
|
||||
case BMP5XX_IIR_FILTER_COEFF_63: Serial.println(F("63 (Maximum filtering)")); break;
|
||||
case BMP5XX_IIR_FILTER_COEFF_127:Serial.println(F("127 (Maximum filtering)")); break;
|
||||
default: Serial.println(F("Unknown")); break;
|
||||
}
|
||||
|
||||
// Pretty print output data rate inline
|
||||
Serial.print(F("Output Data Rate: "));
|
||||
switch(bmp.getOutputDataRate()) {
|
||||
case BMP5XX_ODR_240_HZ: Serial.println(F("240 Hz")); break;
|
||||
case BMP5XX_ODR_218_5_HZ: Serial.println(F("218.5 Hz")); break;
|
||||
case BMP5XX_ODR_199_1_HZ: Serial.println(F("199.1 Hz")); break;
|
||||
case BMP5XX_ODR_179_2_HZ: Serial.println(F("179.2 Hz")); break;
|
||||
case BMP5XX_ODR_160_HZ: Serial.println(F("160 Hz")); break;
|
||||
case BMP5XX_ODR_149_3_HZ: Serial.println(F("149.3 Hz")); break;
|
||||
case BMP5XX_ODR_140_HZ: Serial.println(F("140 Hz")); break;
|
||||
case BMP5XX_ODR_129_8_HZ: Serial.println(F("129.8 Hz")); break;
|
||||
case BMP5XX_ODR_120_HZ: Serial.println(F("120 Hz")); break;
|
||||
case BMP5XX_ODR_110_1_HZ: Serial.println(F("110.1 Hz")); break;
|
||||
case BMP5XX_ODR_100_2_HZ: Serial.println(F("100.2 Hz")); break;
|
||||
case BMP5XX_ODR_89_6_HZ: Serial.println(F("89.6 Hz")); break;
|
||||
case BMP5XX_ODR_80_HZ: Serial.println(F("80 Hz")); break;
|
||||
case BMP5XX_ODR_70_HZ: Serial.println(F("70 Hz")); break;
|
||||
case BMP5XX_ODR_60_HZ: Serial.println(F("60 Hz")); break;
|
||||
case BMP5XX_ODR_50_HZ: Serial.println(F("50 Hz")); break;
|
||||
case BMP5XX_ODR_45_HZ: Serial.println(F("45 Hz")); break;
|
||||
case BMP5XX_ODR_40_HZ: Serial.println(F("40 Hz")); break;
|
||||
case BMP5XX_ODR_35_HZ: Serial.println(F("35 Hz")); break;
|
||||
case BMP5XX_ODR_30_HZ: Serial.println(F("30 Hz")); break;
|
||||
case BMP5XX_ODR_25_HZ: Serial.println(F("25 Hz")); break;
|
||||
case BMP5XX_ODR_20_HZ: Serial.println(F("20 Hz")); break;
|
||||
case BMP5XX_ODR_15_HZ: Serial.println(F("15 Hz")); break;
|
||||
case BMP5XX_ODR_10_HZ: Serial.println(F("10 Hz")); break;
|
||||
case BMP5XX_ODR_05_HZ: Serial.println(F("5 Hz")); break;
|
||||
case BMP5XX_ODR_04_HZ: Serial.println(F("4 Hz")); break;
|
||||
case BMP5XX_ODR_03_HZ: Serial.println(F("3 Hz")); break;
|
||||
case BMP5XX_ODR_02_HZ: Serial.println(F("2 Hz")); break;
|
||||
case BMP5XX_ODR_01_HZ: Serial.println(F("1 Hz")); break;
|
||||
case BMP5XX_ODR_0_5_HZ: Serial.println(F("0.5 Hz")); break;
|
||||
case BMP5XX_ODR_0_250_HZ: Serial.println(F("0.25 Hz")); break;
|
||||
case BMP5XX_ODR_0_125_HZ: Serial.println(F("0.125 Hz")); break;
|
||||
default: Serial.println(F("Unknown")); break;
|
||||
}
|
||||
|
||||
// Pretty print power mode inline
|
||||
Serial.print(F("Power Mode: "));
|
||||
switch(bmp.getPowerMode()) {
|
||||
case BMP5XX_POWERMODE_STANDBY: Serial.println(F("Standby")); break;
|
||||
case BMP5XX_POWERMODE_NORMAL: Serial.println(F("Normal")); break;
|
||||
case BMP5XX_POWERMODE_FORCED: Serial.println(F("Forced")); break;
|
||||
case BMP5XX_POWERMODE_CONTINOUS: Serial.println(F("Continuous")); break;
|
||||
case BMP5XX_POWERMODE_DEEP_STANDBY:Serial.println(F("Deep Standby")); break;
|
||||
default: Serial.println(F("Unknown")); break;
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// In continuous mode, try reading data directly (sensor should be continuously measuring)
|
||||
if (!bmp.performReading()) {
|
||||
Serial.println(F("Failed to perform reading :("));
|
||||
delay(1000);
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.print(F("Temperature = "));
|
||||
Serial.print(bmp.temperature);
|
||||
Serial.println(F(" °C"));
|
||||
|
||||
Serial.print(F("Pressure = "));
|
||||
Serial.print(bmp.pressure);
|
||||
Serial.println(F(" hPa"));
|
||||
|
||||
Serial.print(F("Approx. Altitude = "));
|
||||
Serial.print(bmp.readAltitude(SEALEVELPRESSURE_HPA));
|
||||
Serial.println(F(" m"));
|
||||
|
||||
Serial.println(F("---"));
|
||||
delay(500); // Small delay between readings
|
||||
}
|
||||
10
library.properties
Normal file
10
library.properties
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
name=Adafruit BMP5xx Library
|
||||
version=1.0.0
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Arduino library for BMP580 and BMP581 pressure and temperature sensors.
|
||||
paragraph=Arduino library for Bosch BMP580 and BMP581 pressure and temperature sensors with I2C and SPI support. Uses Bosch Sensortec API for reliable operation.
|
||||
category=Sensors
|
||||
url=https://github.com/adafruit/Adafruit_BMP5xx
|
||||
architectures=*
|
||||
depends=Adafruit Unified Sensor, Adafruit BusIO
|
||||
529
src/Adafruit_BMP5xx.cpp
Normal file
529
src/Adafruit_BMP5xx.cpp
Normal file
|
|
@ -0,0 +1,529 @@
|
|||
/*!
|
||||
* @file Adafruit_BMP5xx.cpp
|
||||
*
|
||||
* @mainpage Adafruit BMP5xx pressure and temperature sensor library
|
||||
*
|
||||
* @section intro_sec Introduction
|
||||
*
|
||||
* I2C Driver for BMP5xx pressure and temperature sensor
|
||||
*
|
||||
* This is a library for the Adafruit BMP5xx breakout:
|
||||
* https://www.adafruit.com/products/xxxx
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing products from
|
||||
* Adafruit!
|
||||
*
|
||||
* @section author Author
|
||||
*
|
||||
* Limor "ladyada" Fried (Adafruit Industries)
|
||||
*
|
||||
* @section license License
|
||||
*
|
||||
* BSD license, all text above must be included in any redistribution
|
||||
*/
|
||||
|
||||
#include "Adafruit_BMP5xx.h"
|
||||
|
||||
/*!
|
||||
* @brief BMP5xx constructor
|
||||
*/
|
||||
Adafruit_BMP5xx::Adafruit_BMP5xx(void) {
|
||||
_temp_sensor = new Adafruit_BMP5xx_Temp(this);
|
||||
_pressure_sensor = new Adafruit_BMP5xx_Pressure(this);
|
||||
temperature = 0.0;
|
||||
pressure = 0.0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief BMP5xx destructor
|
||||
*/
|
||||
Adafruit_BMP5xx::~Adafruit_BMP5xx(void) {
|
||||
if (_i2c_dev) {
|
||||
delete _i2c_dev;
|
||||
}
|
||||
if (_spi_dev) {
|
||||
delete _spi_dev;
|
||||
}
|
||||
if (_temp_sensor) {
|
||||
delete _temp_sensor;
|
||||
}
|
||||
if (_pressure_sensor) {
|
||||
delete _pressure_sensor;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Initializes the sensor
|
||||
* @param addr Optional I2C address the sensor can be found on. Default is 0x46
|
||||
* @param theWire Optional Wire interface the sensor is connected to. Default is &Wire
|
||||
* @return True if initialization was successful, otherwise false.
|
||||
*/
|
||||
bool Adafruit_BMP5xx::begin(uint8_t addr, TwoWire *theWire) {
|
||||
if (_i2c_dev) {
|
||||
delete _i2c_dev;
|
||||
}
|
||||
_i2c_dev = new Adafruit_I2CDevice(addr, theWire);
|
||||
|
||||
if (!_i2c_dev->begin()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Setup Bosch API callbacks
|
||||
_bmp5_dev.intf_ptr = _i2c_dev;
|
||||
_bmp5_dev.intf = BMP5_I2C_INTF;
|
||||
_bmp5_dev.read = i2c_read;
|
||||
_bmp5_dev.write = i2c_write;
|
||||
_bmp5_dev.delay_us = delay_usec;
|
||||
|
||||
return _init();
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Initializes the sensor over SPI
|
||||
* @param cspin The pin to use for CS/Chip Select
|
||||
* @param theSPI Optional SPI interface the sensor is connected to. Default is &SPI
|
||||
* @return True if initialization was successful, otherwise false.
|
||||
*/
|
||||
bool Adafruit_BMP5xx::begin(int8_t cspin, SPIClass *theSPI) {
|
||||
if (_spi_dev) {
|
||||
delete _spi_dev;
|
||||
}
|
||||
_spi_dev = new Adafruit_SPIDevice(cspin, 1000000, SPI_BITORDER_MSBFIRST,
|
||||
SPI_MODE0, theSPI);
|
||||
|
||||
if (!_spi_dev->begin()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Setup Bosch API callbacks
|
||||
_bmp5_dev.intf_ptr = _spi_dev;
|
||||
_bmp5_dev.intf = BMP5_SPI_INTF;
|
||||
_bmp5_dev.read = spi_read;
|
||||
_bmp5_dev.write = spi_write;
|
||||
_bmp5_dev.delay_us = delay_usec;
|
||||
|
||||
return _init();
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Performs the actual initialization using Bosch API
|
||||
* @return True if initialization was successful, otherwise false.
|
||||
*/
|
||||
bool Adafruit_BMP5xx::_init(void) {
|
||||
// Reset the sensor first
|
||||
int8_t rslt = bmp5_soft_reset(&_bmp5_dev);
|
||||
if (rslt != BMP5_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Now initialize the sensor
|
||||
rslt = bmp5_init(&_bmp5_dev);
|
||||
if (rslt != BMP5_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set default configuration
|
||||
_osr_odr_config.osr_t = BMP5_OVERSAMPLING_2X;
|
||||
_osr_odr_config.osr_p = BMP5_OVERSAMPLING_16X;
|
||||
_osr_odr_config.odr = BMP5_ODR_50_HZ;
|
||||
_osr_odr_config.press_en = BMP5_ENABLE;
|
||||
|
||||
rslt = bmp5_set_osr_odr_press_config(&_osr_odr_config, &_bmp5_dev);
|
||||
if (rslt != BMP5_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set default IIR filter
|
||||
_iir_config.set_iir_t = BMP5_IIR_FILTER_COEFF_1;
|
||||
_iir_config.set_iir_p = BMP5_IIR_FILTER_COEFF_1;
|
||||
_iir_config.shdw_set_iir_t = BMP5_ENABLE;
|
||||
_iir_config.shdw_set_iir_p = BMP5_ENABLE;
|
||||
_iir_config.iir_flush_forced_en = BMP5_ENABLE;
|
||||
|
||||
rslt = bmp5_set_iir_config(&_iir_config, &_bmp5_dev);
|
||||
if (rslt != BMP5_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set to normal mode
|
||||
rslt = bmp5_set_power_mode(BMP5_POWERMODE_NORMAL, &_bmp5_dev);
|
||||
return rslt == BMP5_OK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Performs a reading of both temperature and pressure and stores values in class instance variables
|
||||
* @return True if the reading was successful, otherwise false.
|
||||
*/
|
||||
bool Adafruit_BMP5xx::performReading(void) {
|
||||
struct bmp5_sensor_data sensor_data;
|
||||
|
||||
int8_t rslt = bmp5_get_sensor_data(&sensor_data, &_osr_odr_config, &_bmp5_dev);
|
||||
if (rslt != BMP5_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
temperature = sensor_data.temperature;
|
||||
pressure = sensor_data.pressure / 100.0; // Convert Pa to hPa
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Returns the temperature from the last reading
|
||||
* @return Temperature in degrees Celsius
|
||||
*/
|
||||
float Adafruit_BMP5xx::readTemperature(void) {
|
||||
performReading();
|
||||
return temperature;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Returns the pressure from the last reading
|
||||
* @return Pressure in hPa
|
||||
*/
|
||||
float Adafruit_BMP5xx::readPressure(void) {
|
||||
performReading();
|
||||
return pressure;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Calculates the approximate altitude using barometric pressure
|
||||
* @param seaLevel Sea level pressure in hPa (default = 1013.25)
|
||||
* @return Altitude in meters
|
||||
*/
|
||||
float Adafruit_BMP5xx::readAltitude(float seaLevel) {
|
||||
float atmospheric = readPressure();
|
||||
return 44330.0 * (1.0 - pow(atmospheric / seaLevel, 0.1903));
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Set temperature oversampling
|
||||
* @param oversampling Oversampling setting
|
||||
* @return True on success, False on failure
|
||||
*/
|
||||
bool Adafruit_BMP5xx::setTemperatureOversampling(bmp5xx_oversampling_t oversampling) {
|
||||
_osr_odr_config.osr_t = (uint8_t)oversampling;
|
||||
int8_t rslt = bmp5_set_osr_odr_press_config(&_osr_odr_config, &_bmp5_dev);
|
||||
return rslt == BMP5_OK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Set pressure oversampling
|
||||
* @param oversampling Oversampling setting
|
||||
* @return True on success, False on failure
|
||||
*/
|
||||
bool Adafruit_BMP5xx::setPressureOversampling(bmp5xx_oversampling_t oversampling) {
|
||||
_osr_odr_config.osr_p = (uint8_t)oversampling;
|
||||
int8_t rslt = bmp5_set_osr_odr_press_config(&_osr_odr_config, &_bmp5_dev);
|
||||
return rslt == BMP5_OK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Set IIR filter coefficient
|
||||
* @param filtercoeff IIR filter coefficient
|
||||
* @return True on success, False on failure
|
||||
*/
|
||||
bool Adafruit_BMP5xx::setIIRFilterCoeff(bmp5xx_iir_filter_t filtercoeff) {
|
||||
_iir_config.set_iir_t = (uint8_t)filtercoeff;
|
||||
_iir_config.set_iir_p = (uint8_t)filtercoeff;
|
||||
int8_t rslt = bmp5_set_iir_config(&_iir_config, &_bmp5_dev);
|
||||
return rslt == BMP5_OK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Set output data rate
|
||||
* @param odr Output data rate setting
|
||||
* @return True on success, False on failure
|
||||
*/
|
||||
bool Adafruit_BMP5xx::setOutputDataRate(bmp5xx_odr_t odr) {
|
||||
_osr_odr_config.odr = (uint8_t)odr;
|
||||
int8_t rslt = bmp5_set_osr_odr_press_config(&_osr_odr_config, &_bmp5_dev);
|
||||
return rslt == BMP5_OK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Set power mode
|
||||
* @param powermode Power mode setting
|
||||
* @return True on success, False on failure
|
||||
*/
|
||||
bool Adafruit_BMP5xx::setPowerMode(bmp5xx_powermode_t powermode) {
|
||||
int8_t rslt = bmp5_set_power_mode((enum bmp5_powermode)powermode, &_bmp5_dev);
|
||||
return rslt == BMP5_OK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Get temperature oversampling setting
|
||||
* @return Current temperature oversampling
|
||||
*/
|
||||
bmp5xx_oversampling_t Adafruit_BMP5xx::getTemperatureOversampling(void) {
|
||||
struct bmp5_osr_odr_press_config config;
|
||||
bmp5_get_osr_odr_press_config(&config, &_bmp5_dev);
|
||||
return (bmp5xx_oversampling_t)config.osr_t;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Get pressure oversampling setting
|
||||
* @return Current pressure oversampling
|
||||
*/
|
||||
bmp5xx_oversampling_t Adafruit_BMP5xx::getPressureOversampling(void) {
|
||||
struct bmp5_osr_odr_press_config config;
|
||||
bmp5_get_osr_odr_press_config(&config, &_bmp5_dev);
|
||||
return (bmp5xx_oversampling_t)config.osr_p;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Get IIR filter coefficient
|
||||
* @return Current IIR filter coefficient
|
||||
*/
|
||||
bmp5xx_iir_filter_t Adafruit_BMP5xx::getIIRFilterCoeff(void) {
|
||||
struct bmp5_iir_config config;
|
||||
bmp5_get_iir_config(&config, &_bmp5_dev);
|
||||
return (bmp5xx_iir_filter_t)config.set_iir_p;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Get output data rate
|
||||
* @return Current output data rate
|
||||
*/
|
||||
bmp5xx_odr_t Adafruit_BMP5xx::getOutputDataRate(void) {
|
||||
struct bmp5_osr_odr_press_config config;
|
||||
bmp5_get_osr_odr_press_config(&config, &_bmp5_dev);
|
||||
return (bmp5xx_odr_t)config.odr;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Get power mode
|
||||
* @return Current power mode
|
||||
*/
|
||||
bmp5xx_powermode_t Adafruit_BMP5xx::getPowerMode(void) {
|
||||
enum bmp5_powermode powermode;
|
||||
bmp5_get_power_mode(&powermode, &_bmp5_dev);
|
||||
return (bmp5xx_powermode_t)powermode;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Enable/disable pressure measurement
|
||||
* @param enable True to enable pressure, false to disable
|
||||
* @return True on success, False on failure
|
||||
*/
|
||||
bool Adafruit_BMP5xx::enablePressure(bool enable) {
|
||||
_osr_odr_config.press_en = enable ? BMP5_ENABLE : BMP5_DISABLE;
|
||||
int8_t rslt = bmp5_set_osr_odr_press_config(&_osr_odr_config, &_bmp5_dev);
|
||||
return rslt == BMP5_OK;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Gets an Adafruit Unified Sensor object for the temp sensor component
|
||||
* @return Adafruit_Sensor pointer to temperature sensor
|
||||
*/
|
||||
Adafruit_Sensor *Adafruit_BMP5xx::getTemperatureSensor(void) {
|
||||
return _temp_sensor;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Gets an Adafruit Unified Sensor object for the pressure sensor component
|
||||
* @return Adafruit_Sensor pointer to pressure sensor
|
||||
*/
|
||||
Adafruit_Sensor *Adafruit_BMP5xx::getPressureSensor(void) {
|
||||
return _pressure_sensor;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Check if new sensor data is ready
|
||||
* @return True if new data is available, false otherwise
|
||||
*/
|
||||
bool Adafruit_BMP5xx::dataReady(void) {
|
||||
uint8_t int_status = 0;
|
||||
int8_t rslt = bmp5_get_interrupt_status(&int_status, &_bmp5_dev);
|
||||
if (rslt != BMP5_OK) {
|
||||
return false;
|
||||
}
|
||||
// Check if data ready interrupt is asserted
|
||||
return (int_status & BMP5_INT_ASSERTED_DRDY) != 0;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief I2C read callback for Bosch API
|
||||
@param reg_addr Register address to read from
|
||||
@param reg_data Buffer to store read data
|
||||
@param len Number of bytes to read
|
||||
@param intf_ptr Pointer to interface (I2C device)
|
||||
@return 0 on success, negative on error
|
||||
*/
|
||||
/**************************************************************************/
|
||||
int8_t Adafruit_BMP5xx::i2c_read(uint8_t reg_addr, uint8_t *reg_data,
|
||||
uint32_t len, void *intf_ptr) {
|
||||
Adafruit_I2CDevice *i2c_dev = (Adafruit_I2CDevice *)intf_ptr;
|
||||
|
||||
if (!i2c_dev->write_then_read(®_addr, 1, reg_data, len)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief I2C write callback for Bosch API
|
||||
@param reg_addr Register address to write to
|
||||
@param reg_data Buffer containing data to write
|
||||
@param len Number of bytes to write
|
||||
@param intf_ptr Pointer to interface (I2C device)
|
||||
@return 0 on success, negative on error
|
||||
*/
|
||||
/**************************************************************************/
|
||||
int8_t Adafruit_BMP5xx::i2c_write(uint8_t reg_addr, const uint8_t *reg_data,
|
||||
uint32_t len, void *intf_ptr) {
|
||||
Adafruit_I2CDevice *i2c_dev = (Adafruit_I2CDevice *)intf_ptr;
|
||||
|
||||
// Create buffer with register address + data
|
||||
uint8_t buffer[len + 1];
|
||||
buffer[0] = reg_addr;
|
||||
memcpy(&buffer[1], reg_data, len);
|
||||
|
||||
if (!i2c_dev->write(buffer, len + 1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief SPI read callback for Bosch API
|
||||
@param reg_addr Register address to read from
|
||||
@param reg_data Buffer to store read data
|
||||
@param len Number of bytes to read
|
||||
@param intf_ptr Pointer to interface (SPI device)
|
||||
@return 0 on success, negative on error
|
||||
*/
|
||||
/**************************************************************************/
|
||||
int8_t Adafruit_BMP5xx::spi_read(uint8_t reg_addr, uint8_t *reg_data,
|
||||
uint32_t len, void *intf_ptr) {
|
||||
Adafruit_SPIDevice *spi_dev = (Adafruit_SPIDevice *)intf_ptr;
|
||||
|
||||
// Set read bit for SPI
|
||||
reg_addr |= 0x80;
|
||||
|
||||
if (!spi_dev->write_then_read(®_addr, 1, reg_data, len)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief SPI write callback for Bosch API
|
||||
@param reg_addr Register address to write to
|
||||
@param reg_data Buffer containing data to write
|
||||
@param len Number of bytes to write
|
||||
@param intf_ptr Pointer to interface (SPI device)
|
||||
@return 0 on success, negative on error
|
||||
*/
|
||||
/**************************************************************************/
|
||||
int8_t Adafruit_BMP5xx::spi_write(uint8_t reg_addr, const uint8_t *reg_data,
|
||||
uint32_t len, void *intf_ptr) {
|
||||
Adafruit_SPIDevice *spi_dev = (Adafruit_SPIDevice *)intf_ptr;
|
||||
|
||||
// Create buffer with register address + data
|
||||
uint8_t buffer[len + 1];
|
||||
buffer[0] = reg_addr & 0x7F; // Clear read bit for write
|
||||
memcpy(&buffer[1], reg_data, len);
|
||||
|
||||
if (!spi_dev->write(buffer, len + 1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Delay callback for Bosch API
|
||||
@param us Microseconds to delay
|
||||
@param intf_ptr Pointer to interface (unused)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_BMP5xx::delay_usec(uint32_t us, void *intf_ptr) {
|
||||
(void)intf_ptr; // Unused parameter
|
||||
delayMicroseconds(us);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/* Adafruit_BMP5xx_Temp */
|
||||
/**************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief Gets the temperature as a standard sensor event
|
||||
* @param event Sensor event object that will be populated
|
||||
* @returns True
|
||||
*/
|
||||
bool Adafruit_BMP5xx_Temp::getEvent(sensors_event_t *event) {
|
||||
_theBMP5xx->readTemperature();
|
||||
|
||||
event->version = sizeof(sensors_event_t);
|
||||
event->sensor_id = _sensorID;
|
||||
event->type = SENSOR_TYPE_AMBIENT_TEMPERATURE;
|
||||
event->timestamp = millis();
|
||||
event->temperature = _theBMP5xx->temperature;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Gets the sensor_t device data
|
||||
* @param sensor Sensor description that will be populated
|
||||
*/
|
||||
void Adafruit_BMP5xx_Temp::getSensor(sensor_t *sensor) {
|
||||
memset(sensor, 0, sizeof(sensor_t));
|
||||
strncpy(sensor->name, "BMP5xx", sizeof(sensor->name) - 1);
|
||||
sensor->name[sizeof(sensor->name) - 1] = 0;
|
||||
sensor->version = 1;
|
||||
sensor->sensor_id = _sensorID;
|
||||
sensor->type = SENSOR_TYPE_AMBIENT_TEMPERATURE;
|
||||
sensor->min_delay = 0;
|
||||
sensor->min_value = -40.0; // Datasheet minimum
|
||||
sensor->max_value = 85.0; // Datasheet maximum
|
||||
sensor->resolution = 0.01; // Datasheet resolution
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/* Adafruit_BMP5xx_Pressure */
|
||||
/**************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief Gets the pressure as a standard sensor event
|
||||
* @param event Sensor event object that will be populated
|
||||
* @returns True
|
||||
*/
|
||||
bool Adafruit_BMP5xx_Pressure::getEvent(sensors_event_t *event) {
|
||||
_theBMP5xx->readPressure();
|
||||
|
||||
event->version = sizeof(sensors_event_t);
|
||||
event->sensor_id = _sensorID;
|
||||
event->type = SENSOR_TYPE_PRESSURE;
|
||||
event->timestamp = millis();
|
||||
event->pressure = _theBMP5xx->pressure;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Gets the sensor_t device data
|
||||
* @param sensor Sensor description that will be populated
|
||||
*/
|
||||
void Adafruit_BMP5xx_Pressure::getSensor(sensor_t *sensor) {
|
||||
memset(sensor, 0, sizeof(sensor_t));
|
||||
strncpy(sensor->name, "BMP5xx", sizeof(sensor->name) - 1);
|
||||
sensor->name[sizeof(sensor->name) - 1] = 0;
|
||||
sensor->version = 1;
|
||||
sensor->sensor_id = _sensorID;
|
||||
sensor->type = SENSOR_TYPE_PRESSURE;
|
||||
sensor->min_delay = 0;
|
||||
sensor->min_value = 300.0; // Datasheet minimum 30kPa
|
||||
sensor->max_value = 1250.0; // Datasheet maximum 125kPa
|
||||
sensor->resolution = 0.016; // Datasheet RMS noise
|
||||
}
|
||||
238
src/Adafruit_BMP5xx.h
Normal file
238
src/Adafruit_BMP5xx.h
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
/*!
|
||||
* @file Adafruit_BMP5xx.h
|
||||
*
|
||||
* I2C Driver for BMP5xx pressure and temperature sensor
|
||||
*
|
||||
* This is a library for the Adafruit BMP5xx breakout:
|
||||
* https://www.adafruit.com/products/xxxx
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing products from
|
||||
* Adafruit!
|
||||
*
|
||||
* @author Limor "ladyada" Fried (Adafruit Industries)
|
||||
*
|
||||
* BSD license, all text above must be included in any redistribution
|
||||
*/
|
||||
|
||||
#ifndef ADAFRUIT_BMP5XX_H
|
||||
#define ADAFRUIT_BMP5XX_H
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <Adafruit_I2CDevice.h>
|
||||
#include <Adafruit_SPIDevice.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <Wire.h>
|
||||
|
||||
extern "C" {
|
||||
#include "bmp5.h"
|
||||
}
|
||||
|
||||
/*=========================================================================
|
||||
I2C ADDRESS/BITS
|
||||
-----------------------------------------------------------------------*/
|
||||
/**! Default I2C address */
|
||||
#define BMP5XX_DEFAULT_ADDRESS (0x46)
|
||||
/**! Alternative I2C address */
|
||||
#define BMP5XX_ALTERNATIVE_ADDRESS (0x47)
|
||||
|
||||
/**! Chip ID for BMP580 */
|
||||
#define BMP580_CHIP_ID (0x50)
|
||||
/**! Chip ID for BMP581 */
|
||||
#define BMP581_CHIP_ID (0x51)
|
||||
|
||||
/*=========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Sampling rate enum
|
||||
*/
|
||||
typedef enum {
|
||||
BMP5XX_OVERSAMPLING_1X = BMP5_OVERSAMPLING_1X, ///< 1x oversampling
|
||||
BMP5XX_OVERSAMPLING_2X = BMP5_OVERSAMPLING_2X, ///< 2x oversampling
|
||||
BMP5XX_OVERSAMPLING_4X = BMP5_OVERSAMPLING_4X, ///< 4x oversampling
|
||||
BMP5XX_OVERSAMPLING_8X = BMP5_OVERSAMPLING_8X, ///< 8x oversampling
|
||||
BMP5XX_OVERSAMPLING_16X = BMP5_OVERSAMPLING_16X, ///< 16x oversampling
|
||||
BMP5XX_OVERSAMPLING_32X = BMP5_OVERSAMPLING_32X, ///< 32x oversampling
|
||||
BMP5XX_OVERSAMPLING_64X = BMP5_OVERSAMPLING_64X, ///< 64x oversampling
|
||||
BMP5XX_OVERSAMPLING_128X = BMP5_OVERSAMPLING_128X, ///< 128x oversampling
|
||||
} bmp5xx_oversampling_t;
|
||||
|
||||
/**
|
||||
* @brief IIR filter coefficients
|
||||
*/
|
||||
typedef enum {
|
||||
BMP5XX_IIR_FILTER_BYPASS = BMP5_IIR_FILTER_BYPASS, ///< No filtering
|
||||
BMP5XX_IIR_FILTER_COEFF_1 = BMP5_IIR_FILTER_COEFF_1, ///< Filter coeff 1
|
||||
BMP5XX_IIR_FILTER_COEFF_3 = BMP5_IIR_FILTER_COEFF_3, ///< Filter coeff 3
|
||||
BMP5XX_IIR_FILTER_COEFF_7 = BMP5_IIR_FILTER_COEFF_7, ///< Filter coeff 7
|
||||
BMP5XX_IIR_FILTER_COEFF_15 = BMP5_IIR_FILTER_COEFF_15, ///< Filter coeff 15
|
||||
BMP5XX_IIR_FILTER_COEFF_31 = BMP5_IIR_FILTER_COEFF_31, ///< Filter coeff 31
|
||||
BMP5XX_IIR_FILTER_COEFF_63 = BMP5_IIR_FILTER_COEFF_63, ///< Filter coeff 63
|
||||
BMP5XX_IIR_FILTER_COEFF_127 = BMP5_IIR_FILTER_COEFF_127, ///< Filter coeff 127
|
||||
} bmp5xx_iir_filter_t;
|
||||
|
||||
/**
|
||||
* @brief Output Data Rate settings
|
||||
*/
|
||||
typedef enum {
|
||||
BMP5XX_ODR_240_HZ = BMP5_ODR_240_HZ, ///< 240 Hz
|
||||
BMP5XX_ODR_218_5_HZ = BMP5_ODR_218_5_HZ, ///< 218.5 Hz
|
||||
BMP5XX_ODR_199_1_HZ = BMP5_ODR_199_1_HZ, ///< 199.1 Hz
|
||||
BMP5XX_ODR_179_2_HZ = BMP5_ODR_179_2_HZ, ///< 179.2 Hz
|
||||
BMP5XX_ODR_160_HZ = BMP5_ODR_160_HZ, ///< 160 Hz
|
||||
BMP5XX_ODR_149_3_HZ = BMP5_ODR_149_3_HZ, ///< 149.3 Hz
|
||||
BMP5XX_ODR_140_HZ = BMP5_ODR_140_HZ, ///< 140 Hz
|
||||
BMP5XX_ODR_129_8_HZ = BMP5_ODR_129_8_HZ, ///< 129.8 Hz
|
||||
BMP5XX_ODR_120_HZ = BMP5_ODR_120_HZ, ///< 120 Hz
|
||||
BMP5XX_ODR_110_1_HZ = BMP5_ODR_110_1_HZ, ///< 110.1 Hz
|
||||
BMP5XX_ODR_100_2_HZ = BMP5_ODR_100_2_HZ, ///< 100.2 Hz
|
||||
BMP5XX_ODR_89_6_HZ = BMP5_ODR_89_6_HZ, ///< 89.6 Hz
|
||||
BMP5XX_ODR_80_HZ = BMP5_ODR_80_HZ, ///< 80 Hz
|
||||
BMP5XX_ODR_70_HZ = BMP5_ODR_70_HZ, ///< 70 Hz
|
||||
BMP5XX_ODR_60_HZ = BMP5_ODR_60_HZ, ///< 60 Hz
|
||||
BMP5XX_ODR_50_HZ = BMP5_ODR_50_HZ, ///< 50 Hz
|
||||
BMP5XX_ODR_45_HZ = BMP5_ODR_45_HZ, ///< 45 Hz
|
||||
BMP5XX_ODR_40_HZ = BMP5_ODR_40_HZ, ///< 40 Hz
|
||||
BMP5XX_ODR_35_HZ = BMP5_ODR_35_HZ, ///< 35 Hz
|
||||
BMP5XX_ODR_30_HZ = BMP5_ODR_30_HZ, ///< 30 Hz
|
||||
BMP5XX_ODR_25_HZ = BMP5_ODR_25_HZ, ///< 25 Hz
|
||||
BMP5XX_ODR_20_HZ = BMP5_ODR_20_HZ, ///< 20 Hz
|
||||
BMP5XX_ODR_15_HZ = BMP5_ODR_15_HZ, ///< 15 Hz
|
||||
BMP5XX_ODR_10_HZ = BMP5_ODR_10_HZ, ///< 10 Hz
|
||||
BMP5XX_ODR_05_HZ = BMP5_ODR_05_HZ, ///< 5 Hz
|
||||
BMP5XX_ODR_04_HZ = BMP5_ODR_04_HZ, ///< 4 Hz
|
||||
BMP5XX_ODR_03_HZ = BMP5_ODR_03_HZ, ///< 3 Hz
|
||||
BMP5XX_ODR_02_HZ = BMP5_ODR_02_HZ, ///< 2 Hz
|
||||
BMP5XX_ODR_01_HZ = BMP5_ODR_01_HZ, ///< 1 Hz
|
||||
BMP5XX_ODR_0_5_HZ = BMP5_ODR_0_5_HZ, ///< 0.5 Hz
|
||||
BMP5XX_ODR_0_250_HZ = BMP5_ODR_0_250_HZ, ///< 0.25 Hz
|
||||
BMP5XX_ODR_0_125_HZ = BMP5_ODR_0_125_HZ, ///< 0.125 Hz
|
||||
} bmp5xx_odr_t;
|
||||
|
||||
/**
|
||||
* @brief Power mode settings
|
||||
*/
|
||||
typedef enum {
|
||||
BMP5XX_POWERMODE_STANDBY = BMP5_POWERMODE_STANDBY, ///< Standby mode
|
||||
BMP5XX_POWERMODE_NORMAL = BMP5_POWERMODE_NORMAL, ///< Normal mode
|
||||
BMP5XX_POWERMODE_FORCED = BMP5_POWERMODE_FORCED, ///< Forced mode
|
||||
BMP5XX_POWERMODE_CONTINOUS = BMP5_POWERMODE_CONTINOUS, ///< Continuous mode
|
||||
BMP5XX_POWERMODE_DEEP_STANDBY = BMP5_POWERMODE_DEEP_STANDBY, ///< Deep standby mode
|
||||
} bmp5xx_powermode_t;
|
||||
|
||||
/**
|
||||
* @brief Adafruit Unified Sensor interface for temperature component of BMP5xx
|
||||
*/
|
||||
class Adafruit_BMP5xx_Temp : public Adafruit_Sensor {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Adafruit_BMP5xx_Temp object
|
||||
*
|
||||
* @param parent A pointer to the BMP5xx class
|
||||
*/
|
||||
Adafruit_BMP5xx_Temp(class Adafruit_BMP5xx *parent) { _theBMP5xx = parent; }
|
||||
|
||||
bool getEvent(sensors_event_t *event);
|
||||
void getSensor(sensor_t *sensor);
|
||||
|
||||
private:
|
||||
int _sensorID = 0x580; /**< ID number for temperature sensor */
|
||||
class Adafruit_BMP5xx *_theBMP5xx = NULL; /**< Pointer to BMP5xx instance */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Adafruit Unified Sensor interface for pressure component of BMP5xx
|
||||
*/
|
||||
class Adafruit_BMP5xx_Pressure : public Adafruit_Sensor {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Adafruit_BMP5xx_Pressure object
|
||||
*
|
||||
* @param parent A pointer to the BMP5xx class
|
||||
*/
|
||||
Adafruit_BMP5xx_Pressure(class Adafruit_BMP5xx *parent) { _theBMP5xx = parent; }
|
||||
|
||||
bool getEvent(sensors_event_t *event);
|
||||
void getSensor(sensor_t *sensor);
|
||||
|
||||
private:
|
||||
int _sensorID = 0x581; /**< ID number for pressure sensor */
|
||||
class Adafruit_BMP5xx *_theBMP5xx = NULL; /**< Pointer to BMP5xx instance */
|
||||
};
|
||||
|
||||
/**
|
||||
* Driver for the Adafruit BMP5xx barometric pressure sensor.
|
||||
*/
|
||||
class Adafruit_BMP5xx {
|
||||
public:
|
||||
|
||||
Adafruit_BMP5xx();
|
||||
~Adafruit_BMP5xx(void);
|
||||
|
||||
bool begin(uint8_t addr = BMP5XX_DEFAULT_ADDRESS, TwoWire *theWire = &Wire);
|
||||
bool begin(int8_t cspin, SPIClass *theSPI = &SPI);
|
||||
|
||||
float readTemperature(void);
|
||||
float readPressure(void);
|
||||
float readAltitude(float seaLevel = 1013.25);
|
||||
|
||||
bool performReading(void);
|
||||
|
||||
bool setTemperatureOversampling(bmp5xx_oversampling_t oversampling);
|
||||
bool setPressureOversampling(bmp5xx_oversampling_t oversampling);
|
||||
bool setIIRFilterCoeff(bmp5xx_iir_filter_t filtercoeff);
|
||||
bool setOutputDataRate(bmp5xx_odr_t odr);
|
||||
bool setPowerMode(bmp5xx_powermode_t powermode);
|
||||
|
||||
bmp5xx_oversampling_t getTemperatureOversampling(void);
|
||||
bmp5xx_oversampling_t getPressureOversampling(void);
|
||||
bmp5xx_iir_filter_t getIIRFilterCoeff(void);
|
||||
bmp5xx_odr_t getOutputDataRate(void);
|
||||
bmp5xx_powermode_t getPowerMode(void);
|
||||
|
||||
Adafruit_Sensor *getTemperatureSensor(void);
|
||||
Adafruit_Sensor *getPressureSensor(void);
|
||||
|
||||
bool enablePressure(bool enable = true);
|
||||
bool dataReady(void);
|
||||
|
||||
/**! Temperature (Celsius) assigned after calling performReading() */
|
||||
float temperature;
|
||||
/**! Pressure (hPa) assigned after calling performReading() */
|
||||
float pressure;
|
||||
|
||||
private:
|
||||
bool _init(void);
|
||||
|
||||
/**! BMP5xx device struct from Bosch API */
|
||||
struct bmp5_dev _bmp5_dev;
|
||||
|
||||
/**! Configuration struct for OSR/ODR settings */
|
||||
struct bmp5_osr_odr_press_config _osr_odr_config;
|
||||
|
||||
/**! Configuration struct for IIR filter settings */
|
||||
struct bmp5_iir_config _iir_config;
|
||||
|
||||
/**! I2C interface object */
|
||||
Adafruit_I2CDevice *_i2c_dev = NULL;
|
||||
/**! SPI interface object */
|
||||
Adafruit_SPIDevice *_spi_dev = NULL;
|
||||
|
||||
/**! Adafruit unified sensor interface for temperature */
|
||||
Adafruit_BMP5xx_Temp *_temp_sensor = NULL;
|
||||
/**! Adafruit unified sensor interface for pressure */
|
||||
Adafruit_BMP5xx_Pressure *_pressure_sensor = NULL;
|
||||
|
||||
// Static callback functions for Bosch API
|
||||
static int8_t i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len,
|
||||
void *intf_ptr);
|
||||
static int8_t i2c_write(uint8_t reg_addr, const uint8_t *reg_data,
|
||||
uint32_t len, void *intf_ptr);
|
||||
static int8_t spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len,
|
||||
void *intf_ptr);
|
||||
static int8_t spi_write(uint8_t reg_addr, const uint8_t *reg_data,
|
||||
uint32_t len, void *intf_ptr);
|
||||
static void delay_usec(uint32_t us, void *intf_ptr);
|
||||
};
|
||||
|
||||
#endif // ADAFRUIT_BMP5XX_H
|
||||
2123
src/bmp5.c
Normal file
2123
src/bmp5.c
Normal file
File diff suppressed because it is too large
Load diff
631
src/bmp5.h
Normal file
631
src/bmp5.h
Normal file
|
|
@ -0,0 +1,631 @@
|
|||
/**
|
||||
* Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* BSD-3-Clause
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @file bmp5.h
|
||||
* @date 2021-08-27
|
||||
* @version v1.0.5
|
||||
*
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @defgroup bmp5 BMP5
|
||||
* @brief Sensor driver for BMP5 sensor
|
||||
*/
|
||||
|
||||
#ifndef BMP5_H_
|
||||
#define BMP5_H_
|
||||
|
||||
/*! CPP guard */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
/*! Header files
|
||||
****************************************************************************/
|
||||
#include "bmp5_defs.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
/*! BMP5 User Interface function prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* \ingroup bmp5
|
||||
* \defgroup bmp5ApiInit Initialization
|
||||
* @brief Initialize the sensor and device structure
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiInit
|
||||
* \page bmp5_api_bmp5_init bmp5_init
|
||||
* \code
|
||||
* int8_t bmp5_init(struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API is the entry point. Call this API before using all other APIs.
|
||||
* This API reads the chip-id of the sensor and sets the resolution, feature
|
||||
* length and the type of variant.
|
||||
*
|
||||
* @param[in,out] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*
|
||||
*/
|
||||
int8_t bmp5_init(struct bmp5_dev *dev);
|
||||
|
||||
/**
|
||||
* \ingroup bmp5
|
||||
* \defgroup bmp5ApiRegister Registers
|
||||
* @brief Generic API for accessing sensor registers
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiRegister
|
||||
* \page bmp5_api_bmp5_get_regs bmp5_get_regs
|
||||
* \code
|
||||
* int8_t bmp5_get_regs(uint8_t reg_addr, uint8_t *data, uint32_t len, struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API reads the data from the given register address of sensor.
|
||||
*
|
||||
* @param[in] reg_addr : Register address from where the data to be read.
|
||||
* @param[out] data : Pointer to data buffer to store the read data.
|
||||
* @param[in] len : No of bytes of data to be read.
|
||||
* @param[in,out] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_get_regs(uint8_t reg_addr, uint8_t *data, uint32_t len, struct bmp5_dev *dev);
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiRegister
|
||||
* \page bmp5_api_bmp5_set_regs bmp5_set_regs
|
||||
* \code
|
||||
* int8_t bmp5_set_regs(uint8_t reg_addr, const uint8_t *data, uint32_t len, struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API writes the given data to the register address of sensor.
|
||||
*
|
||||
* @param[in] reg_addr : Register address where the data is to be written.
|
||||
* @param[in] data : Pointer to data buffer, whose data is to be written
|
||||
* in the sensor.
|
||||
* @param[in] len : No of bytes of data to be writen.
|
||||
* @param[in,out] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @return Result of API execution status
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_set_regs(uint8_t reg_addr, const uint8_t *data, uint32_t len, struct bmp5_dev *dev);
|
||||
|
||||
/**
|
||||
* \ingroup bmp5
|
||||
* \defgroup bmp5ApiSystem System
|
||||
* @brief API that performs system-level operations
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiSystem
|
||||
* \page bmp5_api_bmp5_soft_reset bmp5_soft_reset
|
||||
* \code
|
||||
* int8_t bmp5_soft_reset(struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API is used to soft-reset the sensor where all the registers are reset to their default values.
|
||||
*
|
||||
* @note If this register is set using I2C, an ACK will NOT be transmitted to
|
||||
* the host.
|
||||
*
|
||||
* @param[in] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_soft_reset(struct bmp5_dev *dev);
|
||||
|
||||
/**
|
||||
* \ingroup bmp5
|
||||
* \defgroup bmp5ApiStatus NVM and Interrupt status
|
||||
* @brief NVM and Interrupt status API
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiStatus
|
||||
* \page bmp5_api_bmp5_get_interrupt_status bmp5_get_interrupt_status
|
||||
* \code
|
||||
* int8_t bmp5_get_interrupt_status(uint8_t *int_status, struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API is used to get the interrupt status (data ready interrupt, fifo full interrupt,
|
||||
* fifo threshold interrupt, pressure out of range interrupt and power-on reset/software reset complete interrupt).
|
||||
*
|
||||
* @param[out] int_status : Variable to store interrupt status.
|
||||
* @param[in] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @note : Below are values of int_status possible.
|
||||
*
|
||||
*@verbatim
|
||||
* Macros | Functionality
|
||||
* -----------------------------------------|----------------------------
|
||||
* BMP5_INT_ASSERTED_DRDY | Data ready interrupt asserted
|
||||
* BMP5_INT_ASSERTED_FIFO_FULL | Fifo full interrupt asserted
|
||||
* BMP5_INT_ASSERTED_FIFO_THRES | Fifo threshold interrupt asserted
|
||||
* BMP5_INT_ASSERTED_PRESSURE_OOR | Pressure out of range interrupt asserted
|
||||
* BMP5_INT_ASSERTED_POR_SOFTRESET_COMPLETE | Power-on reset/Software reset complete interrupt asserted
|
||||
*@endverbatim
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_get_interrupt_status(uint8_t *int_status, struct bmp5_dev *dev);
|
||||
|
||||
/**
|
||||
* \ingroup bmp5
|
||||
* \defgroup bmp5ApiPowermode Powermode
|
||||
* @brief Powermode of the sensor API
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiPowermode
|
||||
* \page bmp5_api_bmp5_set_power_mode bmp5_set_power_mode
|
||||
* \code
|
||||
* int8_t bmp5_set_power_mode(enum bmp5_powermode powermode, struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API sets the power mode of the sensor.
|
||||
*
|
||||
* @param[in] powermode : Select powermode.
|
||||
* @param[in] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @note Below mentioned are the possible powermode that can be set by the user.
|
||||
*
|
||||
*@verbatim
|
||||
* powermode | Macros
|
||||
* -----------------|-------------------
|
||||
* 0 | BMP5_POWERMODE_STANBY
|
||||
* 1 | BMP5_POWERMODE_NORMAL
|
||||
* 2 | BMP5_POWERMODE_FORCED
|
||||
* 3 | BMP5_POWERMODE_CONTINOUS
|
||||
* 4 | BMP5_POWERMODE_DEEP_STANBY
|
||||
*@endverbatim
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_set_power_mode(enum bmp5_powermode powermode, struct bmp5_dev *dev);
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiPowermode
|
||||
* \page bmp5_api_bmp5_get_power_mode bmp5_get_power_mode
|
||||
* \code
|
||||
* int8_t bmp5_get_power_mode(enum bmp5_powermode *powermode, struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API gets the power mode of the sensor.
|
||||
*
|
||||
* @param[out] powermode : To store the power mode.
|
||||
* @param[in] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @note Below mentioned are the possible powermode from the sensor
|
||||
*
|
||||
*@verbatim
|
||||
* powermode | Macros
|
||||
* -----------------|-------------------
|
||||
* 0 | BMP5_POWERMODE_STANBY
|
||||
* 1 | BMP5_POWERMODE_NORMAL
|
||||
* 2 | BMP5_POWERMODE_FORCED
|
||||
* 3 | BMP5_POWERMODE_CONTINOUS
|
||||
* 4 | BMP5_POWERMODE_DEEP_STANBY
|
||||
*@endverbatim
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_get_power_mode(enum bmp5_powermode *powermode, struct bmp5_dev *dev);
|
||||
|
||||
/**
|
||||
* \ingroup bmp5
|
||||
* \defgroup bmp5ApiData Sensor Data
|
||||
* @brief Get Sensor data
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiData
|
||||
* \page bmp5_api_bmp5_get_sensor_data bmp5_get_sensor_data
|
||||
* \code
|
||||
* int8_t bmp5_get_sensor_data(struct bmp5_sensor_data *sensor_data,
|
||||
* const struct bmp5_osr_odr_press_config *osr_odr_press_cfg, struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API reads the temperature(deg C) or both pressure(Pa) and temperature(deg C) data from the
|
||||
* sensor and store it in the bmp5_sensor_data structure instance passed by the user.
|
||||
*
|
||||
* @param[out] sensor_data : Structure instance of bmp5_sensor_data.
|
||||
* @param[in] osr_odr_press_cfg : Structure instance of bmp5_osr_odr_press_config.
|
||||
* @param[in] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @note If fixed point(BMP5_USE_FIXED_POINT) is selected then data return type is uin64_t for pressure
|
||||
* and int64_t for temperature. While for floating point(BMP5_USE_FLOATING_POINT) data return type is float for
|
||||
* pressure and temperature.
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_get_sensor_data(struct bmp5_sensor_data *sensor_data,
|
||||
const struct bmp5_osr_odr_press_config *osr_odr_press_cfg,
|
||||
struct bmp5_dev *dev);
|
||||
|
||||
/**
|
||||
* \ingroup bmp5
|
||||
* \defgroup bmp5ApiInterrupt Interrupt
|
||||
* @brief Interrupt API
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiInterrupt
|
||||
* \page bmp5_api_bmp5_int_source_select bmp5_int_source_select
|
||||
* \code
|
||||
* int8_t bmp5_int_source_select(const struct bmp5_int_source_select *int_source_select, struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API is used to enable the interrupts(drdy interrupt, fifo full interrupt,
|
||||
* fifo threshold enable and pressure data out of range interrupt).
|
||||
*
|
||||
* @param[in] int_source_select : Structure instance of bmp5_int_enable.
|
||||
* @param[in] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_int_source_select(const struct bmp5_int_source_select *int_source_select, struct bmp5_dev *dev);
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiInterrupt
|
||||
* \page bmp5_api_bmp5_configure_interrupt bmp5_configure_interrupt
|
||||
* \code
|
||||
* int8_t bmp5_configure_interrupt(enum bmp5_intr_mode int_mode,
|
||||
* enum bmp5_intr_polarity int_pol,
|
||||
* enum bmp5_intr_drive int_od,
|
||||
* enum bmp5_intr_en_dis int_en,
|
||||
* struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API is used to configure the interrupt settings.
|
||||
*
|
||||
* @param[in] int_mode : Sets either latched or pulsed.
|
||||
* @param[in] int_pol : Sets either polarity high or low.
|
||||
* @param[in] int_od : Sets either open drain or push pull.
|
||||
* @param[in] int_en : Enable/ Disable interrupt pin.
|
||||
* @param[in] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_configure_interrupt(enum bmp5_intr_mode int_mode,
|
||||
enum bmp5_intr_polarity int_pol,
|
||||
enum bmp5_intr_drive int_od,
|
||||
enum bmp5_intr_en_dis int_en,
|
||||
struct bmp5_dev *dev);
|
||||
|
||||
/**
|
||||
* \ingroup bmp5
|
||||
* \defgroup bmp5ApiSettings Settings
|
||||
* @brief Get/set sensor settings APIs
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiSettings
|
||||
* \page bmp5_api_bmp5_get_osr_odr_press_config bmp5_get_osr_odr_press_config
|
||||
* \code
|
||||
* int8_t bmp5_get_osr_odr_press_config(struct bmp5_osr_odr_press_config *osr_odr_press_cfg, struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API gets the configuration for oversampling of temperature, oversampling of
|
||||
* pressure and ODR configuration for normal mode along with pressure enable.
|
||||
*
|
||||
* @param[out] osr_odr_press_cfg : Structure instance of bmp5_osr_odr_press_config.
|
||||
* @param[in] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_get_osr_odr_press_config(struct bmp5_osr_odr_press_config *osr_odr_press_cfg, struct bmp5_dev *dev);
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiSettings
|
||||
* \page bmp5_api_bmp5_set_osr_odr_press_config bmp5_set_osr_odr_press_config
|
||||
* \code
|
||||
* int8_t bmp5_set_osr_odr_press_config(const struct bmp5_osr_odr_press_config *osr_odr_press_cfg, struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API sets the configuration for oversampling of temperature, oversampling of
|
||||
* pressure and ODR configuration along with pressure enable.
|
||||
*
|
||||
* @param[in] osr_odr_press_cfg : Structure instance of bmp5_osr_odr_press_config.
|
||||
* @param[in] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @note If ODR is set to a value higher than 5Hz then powermode is set as standby mode, as ODR value greater than 5HZ
|
||||
* without disabling deep-standby mode makes powermode invalid.
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_set_osr_odr_press_config(const struct bmp5_osr_odr_press_config *osr_odr_press_cfg, struct bmp5_dev *dev);
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiSettings
|
||||
* \page bmp5_api_bmp5_get_iir_config bmp5_get_iir_config
|
||||
* \code
|
||||
* int8_t bmp5_get_iir_config(struct bmp5_iir_config *iir_cfg, struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API gets the configuration for IIR of temperature and pressure.
|
||||
*
|
||||
* @param[out] iir_cfg : Structure instance of bmp5_iir_config.
|
||||
* @param[in] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_get_iir_config(struct bmp5_iir_config *iir_cfg, struct bmp5_dev *dev);
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiSettings
|
||||
* \page bmp5_api_bmp5_set_iir_config bmp5_set_iir_config
|
||||
* \code
|
||||
* int8_t bmp5_set_iir_config(const struct bmp5_iir_config *iir_cfg, struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API sets the configuration for IIR of temperature and pressure.
|
||||
*
|
||||
* @note
|
||||
* 1. The IIR configuration can be performed only in standby mode. So in this API before updating IIR
|
||||
* configuration powermode is switched to standby mode and reverted back to earlier powermode after
|
||||
* IIR configuration is updated.
|
||||
* 2. If IIR value for both temperature and pressure is set a value other than bypass then powermode is set
|
||||
* as standby mode, as IIR with value other than bypass without disabling deep-standby mode makes powermode invalid.
|
||||
*
|
||||
* @param[in] iir_cfg : Structure instance of bmp5_iir_config.
|
||||
* @param[in] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_set_iir_config(const struct bmp5_iir_config *iir_cfg, struct bmp5_dev *dev);
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiSettings
|
||||
* \page bmp5_api_bmp5_get_osr_odr_eff bmp5_get_osr_odr_eff
|
||||
* \code
|
||||
* int8_t bmp5_get_osr_odr_eff(struct bmp5_osr_odr_eff *osr_odr_eff, struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API gets the configuration for effective OSR of temperature,
|
||||
* effective OSR of pressure and ODR valid status.
|
||||
*
|
||||
* @param[out] osr_odr_eff : Structure instance of bmp5_osr_odr_eff.
|
||||
* @param[in] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_get_osr_odr_eff(struct bmp5_osr_odr_eff *osr_odr_eff, struct bmp5_dev *dev);
|
||||
|
||||
/**
|
||||
* \ingroup bmp5
|
||||
* \defgroup bmp5ApiFIFO FIFO
|
||||
* @brief FIFO operations of the sensor
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiFIFO
|
||||
* \page bmp5_api_bmp5_get_fifo_configuration bmp5_get_fifo_configuration
|
||||
* \code
|
||||
* int8_t bmp5_get_fifo_configuration(struct bmp5_fifo *fifo, struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API used to get the configurations of fifo from the sensor.
|
||||
*
|
||||
* @param[out] fifo : Structure instance of bmp5_fifo.
|
||||
* @param[in] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_get_fifo_configuration(struct bmp5_fifo *fifo, struct bmp5_dev *dev);
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiFIFO
|
||||
* \page bmp5_api_bmp5_set_fifo_configuration bmp5_set_fifo_configuration
|
||||
* \code
|
||||
* int8_t bmp5_set_fifo_configuration(const struct bmp5_fifo *fifo, struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API used to set the configurations of fifo in the sensor.
|
||||
*
|
||||
* @param[in] fifo : Structure instance of bmp5_fifo.
|
||||
* @param[in] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @note If Fifo frame selection is enabled then powermode is set as standby mode, as fifo frame selection
|
||||
* enabled without disabling deep-standby mode makes powermode invalid.
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_set_fifo_configuration(const struct bmp5_fifo *fifo, struct bmp5_dev *dev);
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiFIFO
|
||||
* \page bmp5_api_bmp5_get_fifo_len bmp5_get_fifo_len
|
||||
* \code
|
||||
* int8_t bmp5_get_fifo_len(uint8_t *fifo_len, struct bmp5_fifo *fifo, struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API is used to get the length of fifo from the sensor.
|
||||
*
|
||||
* @param[out] fifo_len : Variable to store fifo length.
|
||||
* @param[out] fifo : Structure instance of bmp5_fifo.
|
||||
* @param[in] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_get_fifo_len(uint16_t *fifo_len, struct bmp5_fifo *fifo, struct bmp5_dev *dev);
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiFIFO
|
||||
* \page bmp5_api_bmp5_get_fifo_data bmp5_get_fifo_data
|
||||
* \code
|
||||
* int8_t bmp5_get_fifo_data(struct bmp5_fifo *fifo, struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API is used to get the fifo data from the sensor.
|
||||
*
|
||||
* @param[out] fifo : Structure instance of bmp5_fifo.
|
||||
* @param[in] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_get_fifo_data(struct bmp5_fifo *fifo, struct bmp5_dev *dev);
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiFIFO
|
||||
* \page bmp5_api_bmp5_extract_fifo_data bmp5_extract_fifo_data
|
||||
* \code
|
||||
* int8_t bmp5_extract_fifo_data(const struct bmp5_fifo *fifo, struct bmp5_sensor_data *sensor_data);
|
||||
* \endcode
|
||||
* @details This API extract the temperature and/or pressure data from the fifo data which is
|
||||
* already read from the fifo.
|
||||
*
|
||||
* @param[in] fifo : Structure instance of bmp5_fifo.
|
||||
* @param[out] sensor_data : Structure instance of bmp5_sensor_data.
|
||||
* @param[in] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_extract_fifo_data(const struct bmp5_fifo *fifo, struct bmp5_sensor_data *sensor_data);
|
||||
|
||||
/**
|
||||
* \ingroup bmp5
|
||||
* \defgroup bmp5ApiOOR OOR pressure
|
||||
* @brief OOR pressure API
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiOOR
|
||||
* \page bmp5_api_bmp5_get_oor_configuration bmp5_get_oor_configuration
|
||||
* \code
|
||||
* int8_t bmp5_get_oor_configuration(struct bmp5_oor_press_configuration *oor_press_config, struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API gets the configuration for out-of-range pressure threshold, range
|
||||
* count limit and IIR.
|
||||
*
|
||||
* @param[out] oor_press_config : Structure instance of bmp5_oor_press_configuration.
|
||||
* @param[in] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_get_oor_configuration(struct bmp5_oor_press_configuration *oor_press_config, struct bmp5_dev *dev);
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiOOR
|
||||
* \page bmp5_api_bmp5_set_oor_configuration bmp5_set_oor_configuration
|
||||
* \code
|
||||
* int8_t bmp5_set_oor_configuration(const struct bmp5_oor_press_configuration *oor_press_config, struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API sets the configuration for out-of-range pressure threshold, range
|
||||
* count limit and IIR.
|
||||
*
|
||||
* @param[in] oor_press_config : Structure instance of bmp5_oor_press_configuration.
|
||||
* @param[in] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_set_oor_configuration(const struct bmp5_oor_press_configuration *oor_press_config, struct bmp5_dev *dev);
|
||||
|
||||
/**
|
||||
* \ingroup bmp5
|
||||
* \defgroup bmp5ApiNVM NVM
|
||||
* @brief NVM operation of the sensor
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiNVM
|
||||
* \page bmp5_api_bmp5_nvm_read bmp5_nvm_read
|
||||
* \code
|
||||
* int8_t bmp5_nvm_read(uint8_t nvm_addr, uint16_t *nvm_data, struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API is used to perform NVM read.
|
||||
*
|
||||
* @param[in] nvm_addr : Variable that holds the nvm address.
|
||||
* @param[out] nvm_data : Variable to store nvm data.
|
||||
* @param[in] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_nvm_read(uint8_t nvm_addr, uint16_t *nvm_data, struct bmp5_dev *dev);
|
||||
|
||||
/*!
|
||||
* \ingroup bmp5ApiNVM
|
||||
* \page bmp5_api_bmp5_nvm_write bmp5_nvm_write
|
||||
* \code
|
||||
* int8_t bmp5_nvm_write(uint8_t nvm_addr, const uint16_t *nvm_data, struct bmp5_dev *dev);
|
||||
* \endcode
|
||||
* @details This API used to perform NVM write.
|
||||
*
|
||||
* @param[in] nvm_addr : Variable that holds the nvm address.
|
||||
* @param[in] nvm_data : Variable that holds the nvm data.
|
||||
* @param[in] dev : Structure instance of bmp5_dev.
|
||||
*
|
||||
* @return Result of API execution status.
|
||||
* @return 0 -> Success
|
||||
* @return < 0 -> Fail
|
||||
*/
|
||||
int8_t bmp5_nvm_write(uint8_t nvm_addr, const uint16_t *nvm_data, struct bmp5_dev *dev);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* End of CPP guard */
|
||||
|
||||
#endif /* End of header guard macro */
|
||||
949
src/bmp5_defs.h
Normal file
949
src/bmp5_defs.h
Normal file
|
|
@ -0,0 +1,949 @@
|
|||
/**
|
||||
* Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved.
|
||||
*
|
||||
* BSD-3-Clause
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @file bmp5_defs.h
|
||||
* @date 2021-08-27
|
||||
* @version v1.0.5
|
||||
*
|
||||
*/
|
||||
|
||||
/*! @file bmp5_defs.h
|
||||
* @brief Sensor Driver for BMP5 sensor
|
||||
*/
|
||||
#ifndef _BMP5_DEFS_H
|
||||
#define _BMP5_DEFS_H
|
||||
|
||||
/******************************************************************************/
|
||||
/*! @name HEADER INCLUDES */
|
||||
/******************************************************************************/
|
||||
#ifdef __KERNEL__
|
||||
#include <linux/types.h>
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
/******************************************************************************/
|
||||
/*! @name COMMON MACROS */
|
||||
/******************************************************************************/
|
||||
#ifdef __KERNEL__
|
||||
|
||||
#if (!defined(UINT8_C) && !defined(INT8_C))
|
||||
#define INT8_C(x) S8_C(x)
|
||||
#define UINT8_C(x) U8_C(x)
|
||||
#endif
|
||||
|
||||
#if (!defined(UINT16_C) && !defined(INT16_C))
|
||||
#define INT16_C(x) S16_C(x)
|
||||
#define UINT16_C(x) U16_C(x)
|
||||
#endif
|
||||
|
||||
#if (!defined(INT32_C) && !defined(UINT32_C))
|
||||
#define INT32_C(x) S32_C(x)
|
||||
#define UINT32_C(x) U32_C(x)
|
||||
#endif
|
||||
|
||||
#if (!defined(INT64_C) && !defined(UINT64_C))
|
||||
#define INT64_C(x) S64_C(x)
|
||||
#define UINT64_C(x) U64_C(x)
|
||||
#endif
|
||||
|
||||
#else /* __KERNEL__ */
|
||||
|
||||
#if (!defined(UINT8_C) && !defined(INT8_C))
|
||||
#define INT8_C(x) (x)
|
||||
#define UINT8_C(x) (x##U)
|
||||
#endif
|
||||
|
||||
#if (!defined(UINT16_C) && !defined(INT16_C))
|
||||
#define INT16_C(x) (x)
|
||||
#define UINT16_C(x) (x##U)
|
||||
#endif
|
||||
|
||||
#if (!defined(INT32_C) && !defined(UINT32_C))
|
||||
#define INT32_C(x) (x)
|
||||
#define UINT32_C(x) (x##U)
|
||||
#endif
|
||||
|
||||
#if (!defined(INT64_C) && !defined(UINT64_C))
|
||||
#define INT64_C(x) (x##LL)
|
||||
#define UINT64_C(x) (x##ULL)
|
||||
#endif
|
||||
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
/*! @name C standard macros */
|
||||
#ifndef NULL
|
||||
#ifdef __cplusplus
|
||||
#define NULL 0
|
||||
#else
|
||||
#define NULL ((void *) 0)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/******************************************************************************/
|
||||
/*! @name Compiler switch macros Definitions */
|
||||
/******************************************************************************/
|
||||
#ifndef BMP5_USE_FIXED_POINT /*< Check if floating point (using BMP5_USE_FIXED_POINT) is enabled */
|
||||
#ifndef BMP5_USE_FLOATING_POINT /*< If fixed point is not enabled then enable BMP5_USE_FLOATING_POINT */
|
||||
#define BMP5_USE_FLOATING_POINT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef BMP5_USE_FIXED_POINT /*< If Fixed point is defined set BMP5_FIXED_POINT_DIGIT_PRECISION */
|
||||
#ifdef BMP5_FIXED_POINT_DIGIT_PRECISION
|
||||
#if BMP5_FIXED_POINT_DIGIT_PRECISION > 6 /* If BMP5_FIXED_POINT_DIGIT_PRECISION(provided by user) is greater than 6 then
|
||||
* set precision value to 6 digits */
|
||||
#undef BMP5_FIXED_POINT_DIGIT_PRECISION
|
||||
#define BMP5_FIXED_POINT_DIGIT_PRECISION UINT8_C(6)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* By default BMP5_FIXED_POINT_DIGIT_PRECISION will be 6 digits */
|
||||
/* User can vary the precision between 0 to 6 digits */
|
||||
#ifndef BMP5_FIXED_POINT_DIGIT_PRECISION
|
||||
#define BMP5_FIXED_POINT_DIGIT_PRECISION UINT8_C(6)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/******************************************************************************/
|
||||
/*! @name GENERAL MACRO DEFINITIONS */
|
||||
/******************************************************************************/
|
||||
|
||||
/*!
|
||||
* BMP5_INTF_RET_TYPE is the read/write interface return type which can be overwritten by the build system.
|
||||
*/
|
||||
#ifndef BMP5_INTF_RET_TYPE
|
||||
#define BMP5_INTF_RET_TYPE int8_t
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* The last error code from read/write interface is stored in the device structure as intf_rslt.
|
||||
*/
|
||||
#ifndef BMP5_INTF_RET_SUCCESS
|
||||
#define BMP5_INTF_RET_SUCCESS INT8_C(0)
|
||||
#endif
|
||||
|
||||
/*! @name BOOLEAN TYPES */
|
||||
#ifndef TRUE
|
||||
#define TRUE UINT8_C(0x01)
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE UINT8_C(0x00)
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL UINT8_C(0x00)
|
||||
#endif
|
||||
|
||||
#ifndef ABS
|
||||
#define ABS(a) ((a) > 0 ? (a) : -(a)) /*!< Absolute value */
|
||||
#endif
|
||||
|
||||
/*! @name UTILITY MACROS */
|
||||
#define BMP5_SET_LOW_BYTE UINT16_C(0x00FF)
|
||||
#define BMP5_SET_HIGH_BYTE UINT16_C(0xFF00)
|
||||
|
||||
/*! @name BIT SLICE GET AND SET FUNCTIONS */
|
||||
#define BMP5_GET_BITSLICE(regvar, bitname) \
|
||||
((regvar & bitname##_MSK) >> bitname##_POS)
|
||||
|
||||
#define BMP5_SET_BITSLICE(regvar, bitname, val) \
|
||||
((regvar & ~bitname##_MSK) | \
|
||||
((val << bitname##_POS) & bitname##_MSK))
|
||||
|
||||
#define BMP5_GET_LSB(var) (uint8_t)(var & BMP5_SET_LOW_BYTE)
|
||||
#define BMP5_GET_MSB(var) (uint8_t)((var & BMP5_SET_HIGH_BYTE) >> 8)
|
||||
|
||||
#define BMP5_SET_BIT_VAL_0(reg_data, bitname) (reg_data & ~(bitname##_MSK))
|
||||
|
||||
#define BMP5_SET_BITS_POS_0(reg_data, bitname, data) \
|
||||
((reg_data & ~(bitname##_MSK)) | \
|
||||
(data & bitname##_MSK))
|
||||
|
||||
#define BMP5_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK))
|
||||
|
||||
/*! @name Chip id of BMP5 */
|
||||
#define BMP5_CHIP_ID UINT8_C(0x50)
|
||||
|
||||
/*! @name API success code */
|
||||
#define BMP5_OK INT8_C(0)
|
||||
|
||||
/*! @name API error codes */
|
||||
#define BMP5_E_NULL_PTR INT8_C(-1)
|
||||
#define BMP5_E_COM_FAIL INT8_C(-2)
|
||||
#define BMP5_E_DEV_NOT_FOUND INT8_C(-3)
|
||||
#define BMP5_E_INVALID_CHIP_ID INT8_C(-4)
|
||||
#define BMP5_E_POWER_UP INT8_C(-5)
|
||||
#define BMP5_E_POR_SOFTRESET INT8_C(-6)
|
||||
#define BMP5_E_INVALID_POWERMODE INT8_C(-7)
|
||||
#define BMP5_E_INVALID_THRESHOLD INT8_C(-8)
|
||||
#define BMP5_E_FIFO_FRAME_EMPTY INT8_C(-9)
|
||||
#define BMP5_E_NVM_INVALID_ADDR INT8_C(-10)
|
||||
#define BMP5_E_NVM_NOT_READY INT8_C(-11)
|
||||
|
||||
#define BMP5_ENABLE UINT8_C(0x01)
|
||||
#define BMP5_DISABLE UINT8_C(0x00)
|
||||
|
||||
/*! @name Register addresses */
|
||||
#define BMP5_REG_CHIP_ID UINT8_C(0x01)
|
||||
#define BMP5_REG_REV_ID UINT8_C(0x02)
|
||||
#define BMP5_REG_CHIP_STATUS UINT8_C(0x11)
|
||||
#define BMP5_REG_DRIVE_CONFIG UINT8_C(0x13)
|
||||
#define BMP5_REG_INT_CONFIG UINT8_C(0x14)
|
||||
#define BMP5_REG_INT_SOURCE UINT8_C(0x15)
|
||||
#define BMP5_REG_FIFO_CONFIG UINT8_C(0x16)
|
||||
#define BMP5_REG_FIFO_COUNT UINT8_C(0x17)
|
||||
#define BMP5_REG_FIFO_SEL UINT8_C(0x18)
|
||||
#define BMP5_REG_TEMP_DATA_XLSB UINT8_C(0x1D)
|
||||
#define BMP5_REG_TEMP_DATA_LSB UINT8_C(0x1E)
|
||||
#define BMP5_REG_TEMP_DATA_MSB UINT8_C(0x1F)
|
||||
#define BMP5_REG_PRESS_DATA_XLSB UINT8_C(0x20)
|
||||
#define BMP5_REG_PRESS_DATA_LSB UINT8_C(0x21)
|
||||
#define BMP5_REG_PRESS_DATA_MSB UINT8_C(0x22)
|
||||
#define BMP5_REG_INT_STATUS UINT8_C(0x27)
|
||||
#define BMP5_REG_STATUS UINT8_C(0x28)
|
||||
#define BMP5_REG_FIFO_DATA UINT8_C(0x29)
|
||||
#define BMP5_REG_NVM_ADDR UINT8_C(0x2B)
|
||||
#define BMP5_REG_NVM_DATA_LSB UINT8_C(0x2C)
|
||||
#define BMP5_REG_NVM_DATA_MSB UINT8_C(0x2D)
|
||||
#define BMP5_REG_DSP_CONFIG UINT8_C(0x30)
|
||||
#define BMP5_REG_DSP_IIR UINT8_C(0x31)
|
||||
#define BMP5_REG_OOR_THR_P_LSB UINT8_C(0x32)
|
||||
#define BMP5_REG_OOR_THR_P_MSB UINT8_C(0x33)
|
||||
#define BMP5_REG_OOR_RANGE UINT8_C(0x34)
|
||||
#define BMP5_REG_OOR_CONFIG UINT8_C(0x35)
|
||||
#define BMP5_REG_OSR_CONFIG UINT8_C(0x36)
|
||||
#define BMP5_REG_ODR_CONFIG UINT8_C(0x37)
|
||||
#define BMP5_REG_OSR_EFF UINT8_C(0x38)
|
||||
#define BMP5_REG_CMD UINT8_C(0x7E)
|
||||
|
||||
/*! @name I2C addresses */
|
||||
#define BMP5_I2C_ADDR_PRIM UINT8_C(0x46)
|
||||
#define BMP5_I2C_ADDR_SEC UINT8_C(0x47)
|
||||
|
||||
/*! @name NVM addresses */
|
||||
#define BMP5_NVM_START_ADDR UINT8_C(0x20)
|
||||
#define BMP5_NVM_END_ADDR UINT8_C(0x22)
|
||||
|
||||
/*! @name Interface settings */
|
||||
#define BMP5_SPI_RD_MASK UINT8_C(0x80)
|
||||
|
||||
/*! @name Delay definition */
|
||||
#define BMP5_DELAY_US_SOFT_RESET UINT16_C(2000)
|
||||
#define BMP5_DELAY_US_STANDBY UINT16_C(2500)
|
||||
#define BMP5_DELAY_US_NVM_READY_READ UINT8_C(800)
|
||||
#define BMP5_DELAY_US_NVM_READY_WRITE UINT16_C(10000)
|
||||
|
||||
/*! @name Soft reset command */
|
||||
#define BMP5_SOFT_RESET_CMD UINT8_C(0xB6)
|
||||
|
||||
/*! NVM command */
|
||||
#define BMP5_NVM_FIRST_CMND UINT8_C(0x5D)
|
||||
#define BMP5_NVM_READ_ENABLE_CMND UINT8_C(0xA5)
|
||||
#define BMP5_NVM_WRITE_ENABLE_CMND UINT8_C(0xA0)
|
||||
|
||||
/*! @name Deepstandby enable/disable */
|
||||
#define BMP5_DEEP_ENABLED UINT8_C(0)
|
||||
#define BMP5_DEEP_DISABLED UINT8_C(1)
|
||||
|
||||
/*! @name ODR settings */
|
||||
#define BMP5_ODR_240_HZ UINT8_C(0x00)
|
||||
#define BMP5_ODR_218_5_HZ UINT8_C(0x01)
|
||||
#define BMP5_ODR_199_1_HZ UINT8_C(0x02)
|
||||
#define BMP5_ODR_179_2_HZ UINT8_C(0x03)
|
||||
#define BMP5_ODR_160_HZ UINT8_C(0x04)
|
||||
#define BMP5_ODR_149_3_HZ UINT8_C(0x05)
|
||||
#define BMP5_ODR_140_HZ UINT8_C(0x06)
|
||||
#define BMP5_ODR_129_8_HZ UINT8_C(0x07)
|
||||
#define BMP5_ODR_120_HZ UINT8_C(0x08)
|
||||
#define BMP5_ODR_110_1_HZ UINT8_C(0x09)
|
||||
#define BMP5_ODR_100_2_HZ UINT8_C(0x0A)
|
||||
#define BMP5_ODR_89_6_HZ UINT8_C(0x0B)
|
||||
#define BMP5_ODR_80_HZ UINT8_C(0x0C)
|
||||
#define BMP5_ODR_70_HZ UINT8_C(0x0D)
|
||||
#define BMP5_ODR_60_HZ UINT8_C(0x0E)
|
||||
#define BMP5_ODR_50_HZ UINT8_C(0x0F)
|
||||
#define BMP5_ODR_45_HZ UINT8_C(0x10)
|
||||
#define BMP5_ODR_40_HZ UINT8_C(0x11)
|
||||
#define BMP5_ODR_35_HZ UINT8_C(0x12)
|
||||
#define BMP5_ODR_30_HZ UINT8_C(0x13)
|
||||
#define BMP5_ODR_25_HZ UINT8_C(0x14)
|
||||
#define BMP5_ODR_20_HZ UINT8_C(0x15)
|
||||
#define BMP5_ODR_15_HZ UINT8_C(0x16)
|
||||
#define BMP5_ODR_10_HZ UINT8_C(0x17)
|
||||
#define BMP5_ODR_05_HZ UINT8_C(0x18)
|
||||
#define BMP5_ODR_04_HZ UINT8_C(0x19)
|
||||
#define BMP5_ODR_03_HZ UINT8_C(0x1A)
|
||||
#define BMP5_ODR_02_HZ UINT8_C(0x1B)
|
||||
#define BMP5_ODR_01_HZ UINT8_C(0x1C)
|
||||
#define BMP5_ODR_0_5_HZ UINT8_C(0x1D)
|
||||
#define BMP5_ODR_0_250_HZ UINT8_C(0x1E)
|
||||
#define BMP5_ODR_0_125_HZ UINT8_C(0x1F)
|
||||
|
||||
/*! @name Oversampling for temperature and pressure */
|
||||
#define BMP5_OVERSAMPLING_1X UINT8_C(0x00)
|
||||
#define BMP5_OVERSAMPLING_2X UINT8_C(0x01)
|
||||
#define BMP5_OVERSAMPLING_4X UINT8_C(0x02)
|
||||
#define BMP5_OVERSAMPLING_8X UINT8_C(0x03)
|
||||
#define BMP5_OVERSAMPLING_16X UINT8_C(0x04)
|
||||
#define BMP5_OVERSAMPLING_32X UINT8_C(0x05)
|
||||
#define BMP5_OVERSAMPLING_64X UINT8_C(0x06)
|
||||
#define BMP5_OVERSAMPLING_128X UINT8_C(0x07)
|
||||
|
||||
/*! @name IIR filter for temperature and pressure */
|
||||
#define BMP5_IIR_FILTER_BYPASS UINT8_C(0x00)
|
||||
#define BMP5_IIR_FILTER_COEFF_1 UINT8_C(0x01)
|
||||
#define BMP5_IIR_FILTER_COEFF_3 UINT8_C(0x02)
|
||||
#define BMP5_IIR_FILTER_COEFF_7 UINT8_C(0x03)
|
||||
#define BMP5_IIR_FILTER_COEFF_15 UINT8_C(0x04)
|
||||
#define BMP5_IIR_FILTER_COEFF_31 UINT8_C(0x05)
|
||||
#define BMP5_IIR_FILTER_COEFF_63 UINT8_C(0x06)
|
||||
#define BMP5_IIR_FILTER_COEFF_127 UINT8_C(0x07)
|
||||
|
||||
/*! Fifo frame configuration */
|
||||
#define BMP5_FIFO_EMPTY UINT8_C(0X7F)
|
||||
#define BMP5_FIFO_MAX_THRESHOLD_P_T_MODE UINT8_C(0x0F)
|
||||
#define BMP5_FIFO_MAX_THRESHOLD_P_MODE UINT8_C(0x1F)
|
||||
|
||||
/*! @name Macro is used to bypass both iir_t and iir_p together */
|
||||
#define BMP5_IIR_BYPASS UINT8_C(0xC0)
|
||||
|
||||
/*! @name Pressure Out-of-range count limit */
|
||||
#define BMP5_OOR_COUNT_LIMIT_1 UINT8_C(0x00)
|
||||
#define BMP5_OOR_COUNT_LIMIT_3 UINT8_C(0x01)
|
||||
#define BMP5_OOR_COUNT_LIMIT_7 UINT8_C(0x02)
|
||||
#define BMP5_OOR_COUNT_LIMIT_15 UINT8_C(0x03)
|
||||
|
||||
/*! @name Interrupt configurations */
|
||||
#define BMP5_INT_MODE_PULSED UINT8_C(0)
|
||||
#define BMP5_INT_MODE_LATCHED UINT8_C(1)
|
||||
|
||||
#define BMP5_INT_POL_ACTIVE_LOW UINT8_C(0)
|
||||
#define BMP5_INT_POL_ACTIVE_HIGH UINT8_C(1)
|
||||
|
||||
#define BMP5_INT_OD_PUSHPULL UINT8_C(0)
|
||||
#define BMP5_INT_OD_OPENDRAIN UINT8_C(1)
|
||||
|
||||
/*! @name NVM and Interrupt status asserted macros */
|
||||
#define BMP5_INT_ASSERTED_DRDY UINT8_C(0x01)
|
||||
#define BMP5_INT_ASSERTED_FIFO_FULL UINT8_C(0x02)
|
||||
#define BMP5_INT_ASSERTED_FIFO_THRES UINT8_C(0x04)
|
||||
#define BMP5_INT_ASSERTED_PRESSURE_OOR UINT8_C(0x08)
|
||||
#define BMP5_INT_ASSERTED_POR_SOFTRESET_COMPLETE UINT8_C(0x10)
|
||||
#define BMP5_INT_NVM_RDY UINT8_C(0x02)
|
||||
#define BMP5_INT_NVM_ERR UINT8_C(0x04)
|
||||
#define BMP5_INT_NVM_CMD_ERR UINT8_C(0x08)
|
||||
|
||||
/*! @name Interrupt configurations */
|
||||
#define BMP5_INT_MODE_MSK UINT8_C(0x01)
|
||||
|
||||
#define BMP5_INT_POL_MSK UINT8_C(0x02)
|
||||
#define BMP5_INT_POL_POS UINT8_C(1)
|
||||
|
||||
#define BMP5_INT_OD_MSK UINT8_C(0x04)
|
||||
#define BMP5_INT_OD_POS UINT8_C(2)
|
||||
|
||||
#define BMP5_INT_EN_MSK UINT8_C(0x08)
|
||||
#define BMP5_INT_EN_POS UINT8_C(3)
|
||||
|
||||
#define BMP5_INT_DRDY_EN_MSK UINT8_C(0x01)
|
||||
|
||||
#define BMP5_INT_FIFO_FULL_EN_MSK UINT8_C(0x02)
|
||||
#define BMP5_INT_FIFO_FULL_EN_POS UINT8_C(1)
|
||||
|
||||
#define BMP5_INT_FIFO_THRES_EN_MSK UINT8_C(0x04)
|
||||
#define BMP5_INT_FIFO_THRES_EN_POS UINT8_C(2)
|
||||
|
||||
#define BMP5_INT_OOR_PRESS_EN_MSK UINT8_C(0x08)
|
||||
#define BMP5_INT_OOR_PRESS_EN_POS UINT8_C(3)
|
||||
|
||||
/*! @name ODR configuration */
|
||||
#define BMP5_ODR_MSK UINT8_C(0x7C)
|
||||
#define BMP5_ODR_POS UINT8_C(2)
|
||||
|
||||
/*! @name OSR configurations */
|
||||
#define BMP5_TEMP_OS_MSK UINT8_C(0x07)
|
||||
|
||||
#define BMP5_PRESS_OS_MSK UINT8_C(0x38)
|
||||
#define BMP5_PRESS_OS_POS UINT8_C(3)
|
||||
|
||||
/*! @name Pressure enable */
|
||||
#define BMP5_PRESS_EN_MSK UINT8_C(0x40)
|
||||
#define BMP5_PRESS_EN_POS UINT8_C(6)
|
||||
|
||||
/*! @name IIR configurations */
|
||||
#define BMP5_SET_IIR_TEMP_MSK UINT8_C(0x07)
|
||||
|
||||
#define BMP5_SET_IIR_PRESS_MSK UINT8_C(0x38)
|
||||
#define BMP5_SET_IIR_PRESS_POS UINT8_C(3)
|
||||
|
||||
#define BMP5_OOR_SEL_IIR_PRESS_MSK UINT8_C(0x80)
|
||||
#define BMP5_OOR_SEL_IIR_PRESS_POS UINT8_C(7)
|
||||
|
||||
#define BMP5_SHDW_SET_IIR_TEMP_MSK UINT8_C(0x08)
|
||||
#define BMP5_SHDW_SET_IIR_TEMP_POS UINT8_C(3)
|
||||
|
||||
#define BMP5_SHDW_SET_IIR_PRESS_MSK UINT8_C(0x20)
|
||||
#define BMP5_SHDW_SET_IIR_PRESS_POS UINT8_C(5)
|
||||
|
||||
#define BMP5_SET_FIFO_IIR_TEMP_MSK UINT8_C(0x10)
|
||||
#define BMP5_SET_FIFO_IIR_TEMP_POS UINT8_C(4)
|
||||
|
||||
#define BMP5_SET_FIFO_IIR_PRESS_MSK UINT8_C(0x40)
|
||||
#define BMP5_SET_FIFO_IIR_PRESS_POS UINT8_C(6)
|
||||
|
||||
#define BMP5_IIR_FLUSH_FORCED_EN_MSK UINT8_C(0x04)
|
||||
#define BMP5_IIR_FLUSH_FORCED_EN_POS UINT8_C(2)
|
||||
|
||||
/*! @name Effective OSR configurations and ODR valid status */
|
||||
#define BMP5_OSR_TEMP_EFF_MSK UINT8_C(0x07)
|
||||
|
||||
#define BMP5_OSR_PRESS_EFF_MSK UINT8_C(0x38)
|
||||
#define BMP5_OSR_PRESS_EFF_POS UINT8_C(3)
|
||||
|
||||
#define BMP5_ODR_IS_VALID_MSK UINT8_C(0x80)
|
||||
#define BMP5_ODR_IS_VALID_POS UINT8_C(7)
|
||||
|
||||
/*! @name Powermode */
|
||||
#define BMP5_POWERMODE_MSK UINT8_C(0x03)
|
||||
|
||||
#define BMP5_DEEP_DISABLE_MSK UINT8_C(0x80)
|
||||
#define BMP5_DEEP_DISABLE_POS UINT8_C(7)
|
||||
|
||||
/*! @name Fifo configurations */
|
||||
#define BMP5_FIFO_THRESHOLD_MSK UINT8_C(0x1F)
|
||||
|
||||
#define BMP5_FIFO_MODE_MSK UINT8_C(0x20)
|
||||
#define BMP5_FIFO_MODE_POS UINT8_C(5)
|
||||
|
||||
#define BMP5_FIFO_DEC_SEL_MSK UINT8_C(0x1C)
|
||||
#define BMP5_FIFO_DEC_SEL_POS UINT8_C(2)
|
||||
|
||||
#define BMP5_FIFO_COUNT_MSK UINT8_C(0x3F)
|
||||
|
||||
#define BMP5_FIFO_FRAME_SEL_MSK UINT8_C(0x03)
|
||||
|
||||
/*! @name Out-of-range configuration */
|
||||
#define BMP5_OOR_THR_P_LSB_MSK UINT32_C(0x0000FF)
|
||||
|
||||
#define BMP5_OOR_THR_P_MSB_MSK UINT32_C(0x00FF00)
|
||||
|
||||
#define BMP5_OOR_THR_P_XMSB_MSK UINT32_C(0x010000)
|
||||
#define BMP5_OOR_THR_P_XMSB_POS UINT16_C(16)
|
||||
|
||||
/* Macro to mask xmsb value of oor threshold from register(0x35) value */
|
||||
#define BMP5_OOR_THR_P_XMSB_REG_MSK UINT8_C(0x01)
|
||||
|
||||
#define BMP5_OOR_COUNT_LIMIT_MSK UINT8_C(0xC0)
|
||||
#define BMP5_OOR_COUNT_LIMIT_POS UINT8_C(6)
|
||||
|
||||
/*! @name NVM configuration */
|
||||
#define BMP5_NVM_ADDR_MSK UINT8_C(0x3F)
|
||||
|
||||
#define BMP5_NVM_PROG_EN_MSK UINT8_C(0x40)
|
||||
#define BMP5_NVM_PROG_EN_POS UINT8_C(6)
|
||||
|
||||
#define BMP5_NVM_DATA_LSB_MSK UINT16_C(0x00FF)
|
||||
|
||||
#define BMP5_NVM_DATA_MSB_MSK UINT16_C(0xFF00)
|
||||
|
||||
/******************************************************************************/
|
||||
/*! @name TYPEDEF DEFINITIONS */
|
||||
/******************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief Bus communication function pointer which should be mapped to
|
||||
* the platform specific read functions of the user
|
||||
*
|
||||
* @param[in] reg_addr : Register address from which data is read.
|
||||
* @param[out] read_data : Pointer to data buffer where read data is stored.
|
||||
* @param[in] len : Number of bytes of data to be read.
|
||||
* @param[in, out] intf_ptr : Void pointer that can enable the linking of descriptors
|
||||
* for interface related call backs.
|
||||
*
|
||||
* @retval 0 for Success
|
||||
* @retval Non-zero for Failure
|
||||
*/
|
||||
typedef BMP5_INTF_RET_TYPE (*bmp5_read_fptr_t)(uint8_t reg_addr, uint8_t *read_data, uint32_t len, void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief Bus communication function pointer which should be mapped to
|
||||
* the platform specific write functions of the user
|
||||
*
|
||||
* @param[in] reg_addr : Register address to which the data is written.
|
||||
* @param[in] read_data : Pointer to data buffer in which data to be written
|
||||
* is stored.
|
||||
* @param[in] len : Number of bytes of data to be written.
|
||||
* @param[in, out] intf_ptr : Void pointer that can enable the linking of descriptors
|
||||
* for interface related call backs
|
||||
*
|
||||
* @retval 0 for Success
|
||||
* @retval Non-zero for Failure
|
||||
*/
|
||||
typedef BMP5_INTF_RET_TYPE (*bmp5_write_fptr_t)(uint8_t reg_addr, const uint8_t *read_data, uint32_t len,
|
||||
void *intf_ptr);
|
||||
|
||||
/*!
|
||||
* @brief Delay function pointer which should be mapped to
|
||||
* delay function of the user
|
||||
*
|
||||
* @param[in] period : Delay in microseconds.
|
||||
* @param[in, out] intf_ptr : Void pointer that can enable the linking of descriptors
|
||||
* for interface related call backs
|
||||
*
|
||||
*/
|
||||
typedef void (*bmp5_delay_us_fptr_t)(uint32_t period, void *intf_ptr);
|
||||
|
||||
/******************************************************************************/
|
||||
/*! @name ENUMERATION DEFINITIONS */
|
||||
/******************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief Enumerator for interface selection
|
||||
*/
|
||||
enum bmp5_intf {
|
||||
/*! SPI interface */
|
||||
BMP5_SPI_INTF,
|
||||
/*! I2C interface */
|
||||
BMP5_I2C_INTF,
|
||||
/*! I3C interface */
|
||||
BMP5_I3C_INTF
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Enumerator for powermode selection
|
||||
*/
|
||||
enum bmp5_powermode {
|
||||
/*! Standby powermode */
|
||||
BMP5_POWERMODE_STANDBY,
|
||||
/*! Normal powermode */
|
||||
BMP5_POWERMODE_NORMAL,
|
||||
/*! Forced powermode */
|
||||
BMP5_POWERMODE_FORCED,
|
||||
/*! Continous powermode */
|
||||
BMP5_POWERMODE_CONTINOUS,
|
||||
/*! Deep standby powermode */
|
||||
BMP5_POWERMODE_DEEP_STANDBY
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Enumerator for interrupt enable disable
|
||||
*/
|
||||
enum bmp5_intr_en_dis {
|
||||
/*! Interrupt diable */
|
||||
BMP5_INTR_DISABLE = BMP5_DISABLE,
|
||||
/*! Interrupt enable */
|
||||
BMP5_INTR_ENABLE = BMP5_ENABLE
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Enumerator for interrupt mode
|
||||
*/
|
||||
enum bmp5_intr_mode {
|
||||
/*! Interrupt mode - pulsed */
|
||||
BMP5_PULSED = BMP5_INT_MODE_PULSED,
|
||||
/*! Interrupt mode - latched */
|
||||
BMP5_LATCHED = BMP5_INT_MODE_LATCHED
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Enumerator for interrupt polarity
|
||||
*/
|
||||
enum bmp5_intr_polarity {
|
||||
/*! Interrupt polarity - active low */
|
||||
BMP5_ACTIVE_LOW = BMP5_INT_POL_ACTIVE_LOW,
|
||||
/*! Interrupt polarity - active high */
|
||||
BMP5_ACTIVE_HIGH = BMP5_INT_POL_ACTIVE_HIGH
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Enumerator for interrupt drive
|
||||
*/
|
||||
enum bmp5_intr_drive {
|
||||
/*! Interrupt drive - push-pull */
|
||||
BMP5_INTR_PUSH_PULL = BMP5_INT_OD_PUSHPULL,
|
||||
/*! Interrupt drive - open drain */
|
||||
BMP5_INTR_OPEN_DRAIN = BMP5_INT_OD_OPENDRAIN
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Enumerator for fifo frame selection
|
||||
*/
|
||||
enum bmp5_fifo_frame_sel {
|
||||
/*! Fifo disabled */
|
||||
BMP5_FIFO_NOT_ENABLED,
|
||||
/*! Fifo temperature data only enabled */
|
||||
BMP5_FIFO_TEMPERATURE_DATA,
|
||||
/*! Fifo pressure data only enabled */
|
||||
BMP5_FIFO_PRESSURE_DATA,
|
||||
/*! Fifo pressure and temperature data enabled */
|
||||
BMP5_FIFO_PRESS_TEMP_DATA
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Enumerator for fifo decimation factor(downsampling) selection
|
||||
*/
|
||||
enum bmp5_fifo_dec_sel {
|
||||
/*! Fifo downsampling disabled */
|
||||
BMP5_FIFO_NO_DOWNSAMPLING,
|
||||
/*! Fifo 2X downsampling */
|
||||
BMP5_FIFO_DOWNSAMPLING_2X,
|
||||
/*! Fifo 4X downsampling */
|
||||
BMP5_FIFO_DOWNSAMPLING_4X,
|
||||
/*! Fifo 8X downsampling */
|
||||
BMP5_FIFO_DOWNSAMPLING_8X,
|
||||
/*! Fifo 16X downsampling */
|
||||
BMP5_FIFO_DOWNSAMPLING_16X,
|
||||
/*! Fifo 32X downsampling */
|
||||
BMP5_FIFO_DOWNSAMPLING_32X,
|
||||
/*! Fifo 64X downsampling */
|
||||
BMP5_FIFO_DOWNSAMPLING_64X,
|
||||
/*! Fifo 128X downsampling */
|
||||
BMP5_FIFO_DOWNSAMPLING_128X
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Enumerator for fifo mode selection
|
||||
*/
|
||||
enum bmp5_fifo_mode {
|
||||
/*! Fifo mode - streaming */
|
||||
BMP5_FIFO_MODE_STREAMING,
|
||||
/*! Fifo mode - stop on full */
|
||||
BMP5_FIFO_MODE_STOP_ON_FULL
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
/*! @name STRUCTURE DEFINITIONS */
|
||||
/******************************************************************************/
|
||||
|
||||
/*!
|
||||
* @brief OSR, ODR and pressure configuration structure
|
||||
*/
|
||||
struct bmp5_osr_odr_press_config
|
||||
{
|
||||
/*! Temperature oversampling
|
||||
* Assignable macros :
|
||||
* - BMP5_OVERSAMPLING_1X
|
||||
* - BMP5_OVERSAMPLING_2X
|
||||
* - BMP5_OVERSAMPLING_4X
|
||||
* - BMP5_OVERSAMPLING_8X
|
||||
* - BMP5_OVERSAMPLING_16X
|
||||
* - BMP5_OVERSAMPLING_32X
|
||||
* - BMP5_OVERSAMPLING_64X
|
||||
* - BMP5_OVERSAMPLING_128X
|
||||
*/
|
||||
uint8_t osr_t;
|
||||
|
||||
/*! Pressure oversampling
|
||||
* Assignable macros :
|
||||
* - BMP5_OVERSAMPLING_1X
|
||||
* - BMP5_OVERSAMPLING_2X
|
||||
* - BMP5_OVERSAMPLING_4X
|
||||
* - BMP5_OVERSAMPLING_8X
|
||||
* - BMP5_OVERSAMPLING_16X
|
||||
* - BMP5_OVERSAMPLING_32X
|
||||
* - BMP5_OVERSAMPLING_64X
|
||||
* - BMP5_OVERSAMPLING_128X
|
||||
*/
|
||||
uint8_t osr_p;
|
||||
|
||||
/*! Enable pressure
|
||||
* BMP5_ENABLE = Enables pressure data
|
||||
* BMP5_DISABLE = Disables pressure data
|
||||
*/
|
||||
uint8_t press_en;
|
||||
|
||||
/*! Output Data Rate */
|
||||
uint8_t odr;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief IIR configuration structure
|
||||
*/
|
||||
struct bmp5_iir_config
|
||||
{
|
||||
/*! Temperature IIR
|
||||
* Assignable macros :
|
||||
* - BMP5_IIR_FILTER_BYPASS
|
||||
* - BMP5_IIR_FILTER_0_20980
|
||||
* - BMP5_IIR_FILTER_0_08045
|
||||
* - BMP5_IIR_FILTER_0_03695
|
||||
* - BMP5_IIR_FILTER_0_01785
|
||||
* - BMP5_IIR_FILTER_0_00880
|
||||
* - BMP5_IIR_FILTER_0_00435
|
||||
* - BMP5_IIR_FILTER_0_00220
|
||||
*/
|
||||
uint8_t set_iir_t;
|
||||
|
||||
/*! Pressure IIR
|
||||
* Assignable macros :
|
||||
* - BMP5_IIR_FILTER_BYPASS
|
||||
* - BMP5_IIR_FILTER_0_20980
|
||||
* - BMP5_IIR_FILTER_0_08045
|
||||
* - BMP5_IIR_FILTER_0_03695
|
||||
* - BMP5_IIR_FILTER_0_01785
|
||||
* - BMP5_IIR_FILTER_0_00880
|
||||
* - BMP5_IIR_FILTER_0_00435
|
||||
* - BMP5_IIR_FILTER_0_00220
|
||||
*/
|
||||
uint8_t set_iir_p;
|
||||
|
||||
/*! Shadow IIR selection for temperature
|
||||
* Assignable macros :
|
||||
* - BMP5_ENABLE
|
||||
* - BMP5_DISABLE
|
||||
*/
|
||||
uint8_t shdw_set_iir_t;
|
||||
|
||||
/*! Shadow IIR selection for pressure
|
||||
* Assignable macros :
|
||||
* - BMP5_ENABLE
|
||||
* - BMP5_DISABLE
|
||||
*/
|
||||
uint8_t shdw_set_iir_p;
|
||||
|
||||
/*! IIR flush in forced mode enable
|
||||
* Assignable macros :
|
||||
* - BMP5_ENABLE
|
||||
* - BMP5_DISABLE
|
||||
*/
|
||||
uint8_t iir_flush_forced_en;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Effective OSR configuration and ODR valid status structure
|
||||
*/
|
||||
struct bmp5_osr_odr_eff
|
||||
{
|
||||
/*! Effective temperature OSR */
|
||||
uint8_t osr_t_eff;
|
||||
|
||||
/*! Effective pressure OSR */
|
||||
uint8_t osr_p_eff;
|
||||
|
||||
/*! If asserted, the ODR parametrization is valid */
|
||||
uint8_t odr_is_valid;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief BMP5 interrupt source selection.
|
||||
*/
|
||||
struct bmp5_int_source_select
|
||||
{
|
||||
/*! Data ready interrupt enable
|
||||
* BMP5_ENABLE = Enables data ready interrupt
|
||||
* BMP5_DISABLE = Disables data ready interrupt
|
||||
*/
|
||||
uint8_t drdy_en;
|
||||
|
||||
/*! Fifo full interrupt enable
|
||||
* BMP5_ENABLE = Enables fifo full interrupt
|
||||
* BMP5_DISABLE = Disables fifo full interrupt
|
||||
*/
|
||||
uint8_t fifo_full_en;
|
||||
|
||||
/*! Fifo threshold interrupt enable
|
||||
* BMP5_ENABLE = Enables fifo threshold interrupt
|
||||
* BMP5_DISABLE = Disables fifo threshold interrupt
|
||||
*/
|
||||
uint8_t fifo_thres_en;
|
||||
|
||||
/*! Pressure out of range interrupt enable
|
||||
* BMP5_ENABLE = Enables pressure out of range interrupt
|
||||
* BMP5_DISABLE = Disables pressure out of range interrupt
|
||||
*/
|
||||
uint8_t oor_press_en;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief BMP5 fifo configurations.
|
||||
*/
|
||||
struct bmp5_fifo
|
||||
{
|
||||
/*! Pointer to fifo data */
|
||||
uint8_t *data;
|
||||
|
||||
/*! Length of user defined bytes of fifo to be read */
|
||||
uint16_t length;
|
||||
|
||||
/*! Fifo frame data source selection
|
||||
* Assignable macros :
|
||||
* - BMP5_FIFO_NOT_ENABLED
|
||||
* - BMP5_FIFO_TEMPERATURE_DATA
|
||||
* - BMP5_FIFO_PRESSURE_DATA
|
||||
* - BMP5_FIFO_PRESS_TEMP_DATA
|
||||
*/
|
||||
uint8_t frame_sel;
|
||||
|
||||
/*! Fifo decimation factor(downsampling) selection
|
||||
* Assignable macros :
|
||||
* - BMP5_FIFO_NO_DOWNSAMPLING
|
||||
* - BMP5_FIFO_DOWNSAMPLING_2X
|
||||
* - BMP5_FIFO_DOWNSAMPLING_4X
|
||||
* - BMP5_FIFO_DOWNSAMPLING_8X
|
||||
* - BMP5_FIFO_DOWNSAMPLING_16X
|
||||
* - BMP5_FIFO_DOWNSAMPLING_32X
|
||||
* - BMP5_FIFO_DOWNSAMPLING_64X
|
||||
* - BMP5_FIFO_DOWNSAMPLING_128X
|
||||
*/
|
||||
uint8_t dec_sel;
|
||||
|
||||
/*! Fifo frame count */
|
||||
uint8_t fifo_count;
|
||||
|
||||
/*! Fifo mode selection
|
||||
* Assignable macros :
|
||||
* - BMP5_FIFO_MODE_STREAMING
|
||||
* - BMP5_FIFO_MODE_STOP_ON_FULL
|
||||
*/
|
||||
uint8_t mode;
|
||||
|
||||
/*! Threshold for fifo */
|
||||
uint8_t threshold;
|
||||
|
||||
/*! Fifo temperature IIR
|
||||
* Assignable macros :
|
||||
* - BMP5_ENABLE
|
||||
* - BMP5_DISABLE
|
||||
*/
|
||||
uint8_t set_fifo_iir_t;
|
||||
|
||||
/*! Fifo pressure IIR
|
||||
* Assignable macros :
|
||||
* - BMP5_ENABLE
|
||||
* - BMP5_DISABLE
|
||||
*/
|
||||
uint8_t set_fifo_iir_p;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief BMP5 Out-of-range pressure configuration.
|
||||
*/
|
||||
struct bmp5_oor_press_configuration
|
||||
{
|
||||
/*! Out-of-range pressure threshold */
|
||||
uint32_t oor_thr_p;
|
||||
|
||||
/*! Out-of-range pressure range
|
||||
* Range can span up to +/- 255 Pa around the threshold value.
|
||||
*/
|
||||
uint8_t oor_range_p;
|
||||
|
||||
/*! Out-of-range pressure count limit
|
||||
* Assignable macros :
|
||||
* - BMP5_OOR_COUNT_LIMIT_1
|
||||
* - BMP5_OOR_COUNT_LIMIT_3
|
||||
* - BMP5_OOR_COUNT_LIMIT_7
|
||||
* - BMP5_OOR_COUNT_LIMIT_15
|
||||
*/
|
||||
uint8_t cnt_lim;
|
||||
|
||||
/*! Out-of-range pressure IIR
|
||||
* Assignable macros :
|
||||
* - BMP5_ENABLE
|
||||
* - BMP5_DISABLE
|
||||
*/
|
||||
uint8_t oor_sel_iir_p;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief BMP5 sensor data structure which comprises of temperature and pressure.
|
||||
*/
|
||||
|
||||
#ifdef BMP5_USE_FIXED_POINT
|
||||
|
||||
/*!
|
||||
* @brief BMP5 sensor data structure which comprises of temperature and pressure in fixed point with data type as
|
||||
* uint64_t for pressure and int64_t for temperature.
|
||||
*/
|
||||
struct bmp5_sensor_data
|
||||
{
|
||||
/*! Pressure data */
|
||||
uint64_t pressure;
|
||||
|
||||
/*! Temperature data */
|
||||
int64_t temperature;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
/*!
|
||||
* @brief BMP5 sensor data structure which comprises of temperature and pressure in floating point with data type as
|
||||
* float for pressure and temperature.
|
||||
*/
|
||||
struct bmp5_sensor_data
|
||||
{
|
||||
/*! Pressure data */
|
||||
float pressure;
|
||||
|
||||
/*! Temperature data */
|
||||
float temperature;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief API device structure
|
||||
*/
|
||||
struct bmp5_dev
|
||||
{
|
||||
/*! Chip ID */
|
||||
uint8_t chip_id;
|
||||
|
||||
/*!
|
||||
* The interface pointer is used to enable the user
|
||||
* to link their interface descriptors for reference during the
|
||||
* implementation of the read and write interfaces to the
|
||||
* hardware.
|
||||
*/
|
||||
void *intf_ptr;
|
||||
|
||||
/*! Read function pointer */
|
||||
bmp5_read_fptr_t read;
|
||||
|
||||
/*! Write function pointer */
|
||||
bmp5_write_fptr_t write;
|
||||
|
||||
/*! Delay function pointer */
|
||||
bmp5_delay_us_fptr_t delay_us;
|
||||
|
||||
/*! To store interface pointer error */
|
||||
BMP5_INTF_RET_TYPE intf_rslt;
|
||||
|
||||
/*! Type of Interface */
|
||||
enum bmp5_intf intf;
|
||||
};
|
||||
|
||||
#endif /* End of _BMP5_DEFS_H */
|
||||
Loading…
Reference in a new issue