Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
bmp280.c File Reference

Sensor driver for BMP280 sensor. More...

+ Include dependency graph for bmp280.c:

Go to the source code of this file.

Functions

static void parse_sensor_data (struct bmp280_t *bmp, uint8_t *data)
 local function to extract raw data from i2c buffer and compute compensation with selected precision More...
 
static void parse_calib_data (struct bmp280_t *bmp, uint8_t *data)
 This internal API is used to parse the calibration data, compensates it and store it in device structure (float version) More...
 
static double compensate_pressure (struct bmp280_t *bmp)
 This internal API is used to compensate the raw pressure data and return the compensated pressure data in integer data type. More...
 
static double compensate_temperature (struct bmp280_t *bmp)
 This internal API is used to compensate the raw temperature data and return the compensated temperature data in float data type. More...
 
static bool bmp280_config (struct bmp280_t *bmp)
 Configure the BMP280 device register by register. More...
 
static void bmp280_register_write (struct bmp280_t *bmp, uint8_t reg, uint8_t value)
 Write a register with a value. More...
 
static void bmp280_register_read (struct bmp280_t *bmp, uint8_t reg, uint16_t size)
 Read a register. More...
 
void bmp280_init (struct bmp280_t *bmp)
 Initialize the bmp280 sensor instance. More...
 
void bmp280_periodic (struct bmp280_t *bmp)
 Should be called periodically to request sensor readings. More...
 
void bmp280_event (struct bmp280_t *bmp)
 Should be called in the event thread. More...
 

Detailed Description

Sensor driver for BMP280 sensor.

Definition in file bmp280.c.

Function Documentation

◆ bmp280_config()

static bool bmp280_config ( struct bmp280_t bmp)
static

Configure the BMP280 device register by register.

Parameters
bmpThe bmp280 instance
Returns
true When the configuration is completed
false Still busy configuring

Definition at line 329 of file bmp280.c.

References BMP280_CONFIG_REG_ADDR, BMP280_CTRL_MEAS_REG_ADDR, BMP280_IIR_FILTER_COEFF_16, BMP280_INACTIVITY_HALF_MS, BMP280_OVERSAMPLING_16X_P, BMP280_OVERSAMPLING_2X_T, BMP280_POWER_NORMAL_MODE, bmp280_register_write(), and bmp280_t::config_idx.

Referenced by bmp280_event(), and bmp280_periodic().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bmp280_event()

void bmp280_event ( struct bmp280_t bmp)

Should be called in the event thread.

  • Configures the sensor and reads the responses
  • Parse and request the sensor data
Parameters
bmpThe bmp280 instance

Definition at line 157 of file bmp280.c.

References bmp280_config(), BMP280_EOC_BIT, BMP280_I2C, BMP280_ID_NB, BMP280_NVRAM_COPY_BIT, BMP280_SPI, BMP280_STATUS_CONFIGURE, BMP280_STATUS_GET_CALIB, BMP280_STATUS_IDLE, BMP280_STATUS_READ_DATA_REGS, BMP280_STATUS_READ_STATUS_REG, BMP280_STATUS_UNINIT, BMP_280, bmp280_t::bus, compensate_pressure(), compensate_temperature(), bmp280_t::data_available, bmp280_t::device, I2CTransDone, I2CTransFailed, I2CTransSuccess, bmp280_t::initialized, parse_calib_data(), parse_sensor_data(), bmp280_t::rx_buffer, SPITransDone, SPITransFailed, SPITransSuccess, and bmp280_t::status.

Referenced by baro_bmp280_event().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bmp280_init()

void bmp280_init ( struct bmp280_t bmp)

Initialize the bmp280 sensor instance.

Parameters
bmpThe structure containing the configuration of the bmp280 instance

Definition at line 48 of file bmp280.c.

References BMP280_SPI, BMP280_STATUS_UNINIT, I2CTransDone, SPICphaEdge2, SPICpolIdleHigh, SPIDiv16, SPIDss8bit, SPIMSBFirst, SPISelectUnselect, and SPITransDone.

Referenced by baro_bmp280_init().

+ Here is the caller graph for this function:

◆ bmp280_periodic()

void bmp280_periodic ( struct bmp280_t bmp)

Should be called periodically to request sensor readings.

  • First detects the sensor using WHO_AM_I reading
  • Configures the sensor according the users requested configuration
  • Requests a sensor reading
Parameters
bmpThe bmp280 instance

Definition at line 101 of file bmp280.c.

References BMP280_CALIB_DATA_LEN, BMP280_CALIB_LSB_DATA_ADDR, BMP280_CHIP_ID_REG_ADDR, bmp280_config(), BMP280_DATA_START_REG_ADDR, BMP280_I2C, BMP280_P_T_DATA_LEN, bmp280_register_read(), BMP280_SPI, BMP280_STATUS_CONFIGURE, BMP280_STATUS_GET_CALIB, BMP280_STATUS_IDLE, BMP280_STATUS_READ_DATA_REGS, BMP280_STATUS_READ_STATUS_REG, BMP280_STATUS_REG_ADDR, BMP280_STATUS_UNINIT, bmp280_t::bus, bmp280_t::data_available, I2CTransDone, bmp280_t::initialized, SPITransDone, and bmp280_t::status.

Referenced by baro_bmp280_periodic().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bmp280_register_read()

static void bmp280_register_read ( struct bmp280_t bmp,
uint8_t  reg,
uint16_t  size 
)
static

Read a register.

Parameters
bmpThe bmp280 instance
regThe register address
sizeThe size to read (already 1 is added for the transmission of the register to read)

Definition at line 384 of file bmp280.c.

References BMP280_READ_FLAG, BMP280_SPI, bmp280_t::bus, i2c_transceive(), spi_submit(), and bmp280_t::tx_buffer.

Referenced by bmp280_periodic().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bmp280_register_write()

static void bmp280_register_write ( struct bmp280_t bmp,
uint8_t  reg,
uint8_t  value 
)
static

Write a register with a value.

Parameters
bmpThe bmp280 instance
regThe register address
valueThe value to write to the register

Definition at line 359 of file bmp280.c.

References BMP280_SPI, bmp280_t::bus, i2c_transmit(), spi_submit(), and bmp280_t::tx_buffer.

Referenced by bmp280_config().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compensate_pressure()

static double compensate_pressure ( struct bmp280_t bmp)
static

This internal API is used to compensate the raw pressure data and return the compensated pressure data in integer data type.

Definition at line 300 of file bmp280.c.

References bmp280_t::calib, bmp280_reg_calib_data_t::dig_p1, bmp280_reg_calib_data_t::dig_p2, bmp280_reg_calib_data_t::dig_p3, bmp280_reg_calib_data_t::dig_p4, bmp280_reg_calib_data_t::dig_p5, bmp280_reg_calib_data_t::dig_p7, bmp280_reg_calib_data_t::dig_p8, bmp280_reg_calib_data_t::dig_p9, p, bmp280_t::pressure, bmp280_t::raw_pressure, and bmp280_reg_calib_data_t::t_fine.

Referenced by bmp280_event().

+ Here is the caller graph for this function:

◆ compensate_temperature()

static double compensate_temperature ( struct bmp280_t bmp)
static

This internal API is used to compensate the raw temperature data and return the compensated temperature data in float data type.

Definition at line 281 of file bmp280.c.

References bmp280_t::calib, bmp280_reg_calib_data_t::dig_t1, bmp280_reg_calib_data_t::dig_t2, bmp280_reg_calib_data_t::dig_t3, bmp280_t::raw_temperature, bmp280_reg_calib_data_t::t_fine, and bmp280_t::temperature.

Referenced by bmp280_event().

+ Here is the caller graph for this function:

◆ parse_calib_data()

static void parse_calib_data ( struct bmp280_t bmp,
uint8_t data 
)
static

◆ parse_sensor_data()

static void parse_sensor_data ( struct bmp280_t bmp,
uint8_t data 
)
static

local function to extract raw data from i2c buffer and compute compensation with selected precision

Definition at line 231 of file bmp280.c.

References bmp280_t::raw_pressure, and bmp280_t::raw_temperature.

Referenced by bmp280_event().

+ Here is the caller graph for this function: