Loading...
Searching...
No Matches
abp2.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2024 CNRS, France
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
71
72#include "saul.h"
73
74#if defined(MODULE_ABP2_SPI)
75#include "periph/spi.h"
76#include "periph/gpio.h"
77#elif defined(MODULE_ABP2_I2C)
78#include "periph/i2c.h"
79#else
80#error "ABP2 driver >> Please add a valid module: either abp2_spi or abp2_i2c"
81#endif
82
83#ifdef __cplusplus
84extern "C" {
85#endif
86
87#if defined(MODULE_ABP2_I2C)
94#define ABP2_ADDR_DEFAULT (0x28)
95#endif
96
115#define ABP2_STATUS_BUSY 0x20
116#define ABP2_STATUS_MEMERR 0x04
117#define ABP2_STATUS_MATHSAT 0x01
119#define ABP2_STATUS_MASK (ABP2_STATUS_BUSY | ABP2_STATUS_MEMERR | ABP2_STATUS_MATHSAT) /* end of abp2_statusbits */
121
129typedef struct abp2_params {
130#if defined(MODULE_ABP2_SPI)
131 spi_t spi;
132 spi_cs_t cs;
133 spi_clk_t clk;
134#else
136#endif
137 int32_t rangeMin;
138 int32_t rangeMax;
140
144typedef struct abp2 {
147
151typedef struct abp2_raw {
152 uint32_t cntPress;
153 uint32_t cntTemp;
155
173int abp2_init(abp2_t *dev, const abp2_params_t *params);
174
188int abp2_measure(const abp2_t *dev);
189
208int abp2_read(const abp2_t *dev, int32_t *press, int32_t *temp);
209
226int abp2_read_nb(const abp2_t *dev, int32_t *press, int32_t *temp);
227
237uint8_t abp2_getstatus(const abp2_t *dev);
238
255int abp2_read_raw(const abp2_t *dev, abp2_raw_t *raw_values);
256
280int abp2_measure_read(const abp2_t *dev, abp2_raw_t *raw_values);
281
292int32_t abp2_pressure(const abp2_t *dev, const abp2_raw_t *raw_values);
293
302int32_t abp2_temperature(const abp2_t *dev, const abp2_raw_t *raw_values);
303
304#ifdef __cplusplus
305}
306#endif
307
spi_clk_t
Definition periph_cpu.h:348
Definition of the generic [S]ensor [A]ctuator [U]ber [L]ayer.
Low-level GPIO peripheral driver interface definitions.
int abp2_measure(const abp2_t *dev)
Let the sensor make one measurement.
int abp2_init(abp2_t *dev, const abp2_params_t *params)
Initialize the ABP2 sensor.
int abp2_read(const abp2_t *dev, int32_t *press, int32_t *temp)
Measure pressure and temperature (blocking version).
int abp2_read_raw(const abp2_t *dev, abp2_raw_t *raw_values)
Read pressure and temperature raw values.
struct abp2_raw abp2_raw_t
Raw values read from a ABP2 sensor.
uint8_t abp2_getstatus(const abp2_t *dev)
Read the status byte of the sensor.
int abp2_measure_read(const abp2_t *dev, abp2_raw_t *raw_values)
Start measurement and read previous pressure and temperature raw values.
int32_t abp2_pressure(const abp2_t *dev, const abp2_raw_t *raw_values)
Convert ADC counts to pressure.
struct abp2_params abp2_params_t
Parameters for ABP2 sensors.
int abp2_read_nb(const abp2_t *dev, int32_t *press, int32_t *temp)
Measure pressure and temperature (non-blocking version).
struct abp2 abp2_t
Device descriptor for ABP2 sensors.
int32_t abp2_temperature(const abp2_t *dev, const abp2_raw_t *raw_values)
Convert ADC counts to temperature .
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition i2c.h:155
gpio_t spi_cs_t
Chip select pin type overlaps with gpio_t so it can be casted to this.
Definition spi.h:157
Low-level I2C peripheral driver interface definition.
Low-level SPI peripheral driver interface definition.
Parameters for ABP2 sensors.
Definition abp2.h:129
i2c_t i2c
I2C bus the device is connected to.
Definition abp2.h:135
int32_t rangeMax
Maximum pressure range (thousandths of sensor unit).
Definition abp2.h:138
int32_t rangeMin
Minimum pressure range (thousandths of sensor unit).
Definition abp2.h:137
Raw values read from a ABP2 sensor.
Definition abp2.h:151
uint32_t cntTemp
24-bit digital temperature reading (counts).
Definition abp2.h:153
uint32_t cntPress
24-bit digital pressure reading (counts).
Definition abp2.h:152
Device descriptor for ABP2 sensors.
Definition abp2.h:144
const abp2_params_t * params
Sensor parameters.
Definition abp2.h:145