Loading...
Searching...
No Matches
abp2.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024 CNRS, France
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
9#pragma once
10
74
75#include "saul.h"
76
77#if defined(MODULE_ABP2_SPI)
78#include "periph/spi.h"
79#include "periph/gpio.h"
80#elif defined(MODULE_ABP2_I2C)
81#include "periph/i2c.h"
82#else
83#error "ABP2 driver >> Please add a valid module: either abp2_spi or abp2_i2c"
84#endif
85
86#ifdef __cplusplus
87extern "C" {
88#endif
89
90#if defined(MODULE_ABP2_I2C)
97#define ABP2_ADDR_DEFAULT (0x28)
98#endif
99
118#define ABP2_STATUS_BUSY 0x20
119#define ABP2_STATUS_MEMERR 0x04
120#define ABP2_STATUS_MATHSAT 0x01
122#define ABP2_STATUS_MASK (ABP2_STATUS_BUSY | ABP2_STATUS_MEMERR | ABP2_STATUS_MATHSAT) /* end of abp2_statusbits */
124
132typedef struct abp2_params {
133#if defined(MODULE_ABP2_SPI)
134 spi_t spi;
135 spi_cs_t cs;
136 spi_clk_t clk;
137#else
139#endif
140 int32_t rangeMin;
141 int32_t rangeMax;
143
147typedef struct abp2 {
150
154typedef struct abp2_raw {
155 uint32_t cntPress;
156 uint32_t cntTemp;
158
176int abp2_init(abp2_t *dev, const abp2_params_t *params);
177
191int abp2_measure(const abp2_t *dev);
192
211int abp2_read(const abp2_t *dev, int32_t *press, int32_t *temp);
212
229int abp2_read_nb(const abp2_t *dev, int32_t *press, int32_t *temp);
230
240uint8_t abp2_getstatus(const abp2_t *dev);
241
258int abp2_read_raw(const abp2_t *dev, abp2_raw_t *raw_values);
259
283int abp2_measure_read(const abp2_t *dev, abp2_raw_t *raw_values);
284
295int32_t abp2_pressure(const abp2_t *dev, const abp2_raw_t *raw_values);
296
305int32_t abp2_temperature(const abp2_t *dev, const abp2_raw_t *raw_values);
306
307#ifdef __cplusplus
308}
309#endif
310
spi_clk_t
Definition periph_cpu.h:351
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:144
gpio_t spi_cs_t
Chip select pin type overlaps with gpio_t so it can be casted to this.
Definition spi.h:135
Low-level I2C peripheral driver interface definition.
Low-level SPI peripheral driver interface definition.
Parameters for ABP2 sensors.
Definition abp2.h:132
i2c_t i2c
I2C bus the device is connected to.
Definition abp2.h:138
int32_t rangeMax
Maximum pressure range (thousandths of sensor unit).
Definition abp2.h:141
int32_t rangeMin
Minimum pressure range (thousandths of sensor unit).
Definition abp2.h:140
Raw values read from a ABP2 sensor.
Definition abp2.h:154
uint32_t cntTemp
24-bit digital temperature reading (counts).
Definition abp2.h:156
uint32_t cntPress
24-bit digital pressure reading (counts).
Definition abp2.h:155
Device descriptor for ABP2 sensors.
Definition abp2.h:147
const abp2_params_t * params
Sensor parameters.
Definition abp2.h:148