12static uint8_t LPS22DF_readRegister(
LPS22DF_t *, uint8_t);
13static void LPS22DF_readRegisters(
LPS22DF_t *, uint8_t, uint8_t, uint8_t *);
14static void LPS22DF_writeRegister(
LPS22DF_t *, uint8_t, uint8_t);
31 float tempSensitivity,
32 float pressSensitivity
36 baro->tempSensitivity = tempSensitivity;
37 baro->base.sensitivity = pressSensitivity;
47 baro->base.
rawPress = baro->rawPress;
48 baro->base.
rawTemp = baro->rawTemp;
51 LPS22DF_writeRegister(baro, LPS22DF_CTRL_REG2, LPS22DF_CTRL_REG2_BDU);
54 LPS22DF_writeRegister(
57 (LPS22DF_CTRL_REG1_ODR_200
58 | LPS22DF_CTRL_REG1_AVG_32)
62 for (uint32_t i = 0; i < 0x1FFFF; i++);
94 uint8_t bytes[LPS22DF_TEMP_DATA_SIZE];
109 *out = ((
LPS22DF_t *)baro)->tempSensitivity * (int16_t)(((uint16_t)bytes[1] << 8) | bytes[0]);
121 out[0] = LPS22DF_readRegister(((
LPS22DF_t *)baro), LPS22DF_TEMP_OUT_H);
122 out[1] = LPS22DF_readRegister(((
LPS22DF_t *)baro), LPS22DF_TEMP_OUT_L);
134 uint8_t bytes[LPS22DF_PRESS_DATA_SIZE];
148 *out = ((
LPS22DF_t *)baro)->base.sensitivity * (int32_t)(((uint32_t)bytes[0] << 16) | ((uint32_t)bytes[1] << 8) | bytes[0]);
160 uint8_t tmp[LPS22DF_PRESS_DATA_SIZE];
161 LPS22DF_readRegisters(((
LPS22DF_t *)baro), LPS22DF_PRESS_OUT_XL, LPS22DF_PRESS_DATA_SIZE, tmp);
169void LPS22DF_writeRegister(
LPS22DF_t *baro, uint8_t address, uint8_t data) {
170 SPI_t *spi = baro->spi;
176 uint8_t payload = address & 0x7F;
183uint8_t LPS22DF_readRegister(
LPS22DF_t *baro, uint8_t address) {
184 uint8_t response = 0;
185 SPI_t *spi = baro->spi;
191 uint8_t payload = address | 0x80;
192 response = spi->
transmit(spi, payload);
193 response = spi->
transmit(spi, 0xFF);
200void LPS22DF_readRegisters(
LPS22DF_t *baro, uint8_t address, uint8_t count, uint8_t *out) {
201 SPI_t *spi = baro->spi;
207 uint8_t payload = address | 0x80;
211 for (uint8_t i = 0; i < count; i++) {
void(* readPress)(struct Baro *baro, float *out)
Pointer to readPress method.
uint8_t * rawTemp
Pointer to driver defined raw temperature data array.
void(* readTemp)(struct Baro *baro, float *out)
Pointer to readTemp method.
void(* readRawPress)(struct Baro *baro, uint8_t *out)
Pointer to readRawPress method.
float temp
Last read processed temperature value.
uint8_t pressDataSize
Size of raw pressure data in bytes.
float press
Last read processed pressure value.
float groundPress
Stored ground pressure reading.
void(* processRawTemp)(struct Baro *baro, uint8_t *bytes, float *out)
Pointer to processRawTemp method.
void(* processRawPress)(struct Baro *baro, uint8_t *bytes, float *out)
Pointer to processRawPress method.
void(* readRawTemp)(struct Baro *baro, uint8_t *out)
Pointer to readRawTemp method.
uint8_t tempDataSize
Size of raw temperature data in bytes.
uint8_t * rawPress
Pointer to driver defined raw pressure data array.
void(* update)(struct Baro *baro)
Pointer to update method.
void(* set)(struct GPIOpin *)
void(* reset)(struct GPIOpin *)
Struct definition for a GPIO pin.
void LPS22DF_readRawPress(Baro_t *, uint8_t *)
void LPS22DF_readPress(Baro_t *, float *)
void LPS22DF_processRawTemp(Baro_t *, uint8_t *, float *)
Processes raw temperature data from LPS22DF sensor.
void LPS22DF_readTemp(Baro_t *, float *)
Read the temperature from the LPS22DF sensor.
void LPS22DF_processRawPress(Baro_t *, uint8_t *, float *)
void LPS22DF_readRawTemp(Baro_t *, uint8_t *)
LPS22DF_t LPS22DF_init(LPS22DF_t *baro, SPI_t *spi, GPIOpin_t cs, float tempSensitivity, float pressSensitivity)
Initialiser for a LPS22DF barometer.
void LPS22DF_update(Baro_t *)
Updates the LPS22DF barometer readings.
uint16_t(* transmit)(struct SPI *, uint16_t)
SPI transmit method.
Struct definition for SPI interface. Provides the interface for API consumers to interact with the SP...