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 BMP581_readRegister(baro, 0x01);
54 BMP581_writeRegister(baro, BMP581_CMD, 0xB6);
56 while (BMP581_readRegister(baro, BMP581_CHIP_ID) == 0x00);
57 while (BMP581_readRegister(baro, BMP581_INT_STATUS) != 0x10);
58 while (!(BMP581_readRegister(baro, BMP581_STATUS) & BMP581_STATUS_NVM_RDY));
59 while ((BMP581_readRegister(baro, BMP581_STATUS) & BMP581_STATUS_NVM_ERR));
61 BMP581_writeRegister(baro, BMP581_ODR_CFG, BMP581_ODR_CFG_DEEP_DIS);
62 for (uint32_t i = 0; i < 0x1FFFF; i++);
63 BMP581_writeRegister(baro, BMP581_ODR_CFG, BMP581_ODR_CFG_DEEP_DIS | BMP581_ODR_CFG_PWR_CONTINUOUS);
66 uint8_t OSRCFG = BMP581_readRegister(baro, BMP581_OSR_CFG);
67 BMP581_writeRegister(baro, BMP581_OSR_CFG, (BMP581_OSR_CFG_RESERVED & OSRCFG) | BMP581_OSR_CFG_PRESS_EN | BMP581_OSR_CFG_OSR_P_16);
70 for (uint32_t i = 0; i < 0x1FFFF; i++);
102 uint8_t bytes[BMP581_DATA_TOTAL];
117 *out = ((
BMP581_t *)baro)->tempSensitivity * (int32_t)(((uint32_t)bytes[0] << 16) | ((uint32_t)bytes[1] << 8) | bytes[0]);
129 out[0] = BMP581_readRegister((
BMP581_t *)baro, BMP581_TEMPERATURE_MSB);
130 out[1] = BMP581_readRegister((
BMP581_t *)baro, BMP581_TEMPERATURE_LSB);
131 out[2] = BMP581_readRegister((
BMP581_t *)baro, BMP581_TEMPERATURE_XLSB);
143 uint8_t bytes[BMP581_DATA_TOTAL];
157 *out = ((
BMP581_t *)baro)->base.sensitivity * (int32_t)(((uint32_t)bytes[0] << 16) | ((uint32_t)bytes[1] << 8) | bytes[0]);
169 uint8_t tmp[BMP581_DATA_SIZE];
170 BMP581_readRegisters((
BMP581_t *)baro, BMP581_PRESSURE_XLSB, BMP581_DATA_SIZE, tmp);
178void BMP581_writeRegister(
BMP581_t *baro, uint8_t address, uint8_t data) {
179 SPI_t *spi = baro->spi;
185 uint8_t payload = address & 0x7F;
192uint8_t BMP581_readRegister(
BMP581_t *baro, uint8_t address) {
193 uint8_t response = 0;
194 SPI_t *spi = baro->spi;
200 uint8_t payload = address | 0x80;
201 response = spi->
transmit(spi, payload);
202 response = spi->
transmit(spi, 0xFF);
209void BMP581_readRegisters(
BMP581_t *baro, uint8_t address, uint8_t count, uint8_t *out) {
210 SPI_t *spi = baro->spi;
216 uint8_t payload = address | 0x80;
220 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 BMP581_readTemp(Baro_t *, float *)
Read the temperature from the BMP581 sensor.
void BMP581_processRawTemp(Baro_t *, uint8_t *, float *)
Processes raw temperature data from BMP581 sensor.
void BMP581_readRawTemp(Baro_t *, uint8_t *)
BMP581_t BMP581_init(BMP581_t *baro, SPI_t *spi, GPIOpin_t cs, float tempSensitivity, float pressSensitivity)
Initialiser for a BMP581 barometer.
void BMP581_readPress(Baro_t *, float *)
void BMP581_readRawPress(Baro_t *, uint8_t *)
void BMP581_update(Baro_t *)
Updates the BMP581 barometer readings.
void BMP581_processRawPress(Baro_t *, uint8_t *, float *)
void(* set)(struct GPIOpin *)
void(* reset)(struct GPIOpin *)
Struct definition for a GPIO pin.
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...