40#include "lib/sensors.h"
53#define PRINTF(...) printf(__VA_ARGS__)
58#define BMP280_I2C_ADDRESS 0x77
61#define ADDR_CALIB 0x88
62#define ADDR_PROD_ID 0xD0
63#define ADDR_RESET 0xE0
64#define ADDR_STATUS 0xF3
65#define ADDR_CTRL_MEAS 0xF4
66#define ADDR_CONFIG 0xF5
67#define ADDR_PRESS_MSB 0xF7
68#define ADDR_PRESS_LSB 0xF8
69#define ADDR_PRESS_XLSB 0xF9
70#define ADDR_TEMP_MSB 0xFA
71#define ADDR_TEMP_LSB 0xFB
72#define ADDR_TEMP_XLSB 0xFC
75#define VAL_PROD_ID 0x58
77#define VAL_STATUS 0x00
78#define VAL_CTRL_MEAS 0x00
79#define VAL_CONFIG 0x00
80#define VAL_PRESS_MSB 0x80
81#define VAL_PRESS_LSB 0x00
82#define VAL_TEMP_MSB 0x80
83#define VAL_TEMP_LSB 0x00
86#define VAL_RESET_EXECUTE 0xB6
87#define VAL_CTRL_MEAS_TEST 0x55
90#define MEAS_DATA_SIZE 6
93#define RES_ULTRA_LOW_POWER 1
94#define RES_LOW_POWER 2
97#define RES_ULTRA_HIGH 6
104#define OSRST(v) ((v) << 5)
105#define OSRSP(v) ((v) << 2)
107typedef struct bmp_280_calibration {
121} bmp_280_calibration_t;
123static bmp_280_calibration_t calibration_data;
125#define SENSOR_STATUS_DISABLED 0
126#define SENSOR_STATUS_INITIALISED 1
127#define SENSOR_STATUS_NOT_READY 2
128#define SENSOR_STATUS_READY 3
130static int enabled = SENSOR_STATUS_DISABLED;
133#define SENSOR_DATA_BUF_SIZE 6
135static uint8_t sensor_value[SENSOR_DATA_BUF_SIZE];
138#define SENSOR_STARTUP_DELAY 3
140static struct ctimer startup_timer;
145 enabled = SENSOR_STATUS_READY;
168 sizeof(calibration_data));
171 val = VAL_RESET_EXECUTE;
188 val = PM_FORCED | OSRSP(1) | OSRST(1);
228 bmp_280_calibration_t *p = &calibration_data;
297 if(enabled != SENSOR_STATUS_READY) {
298 PRINTF(
"Sensor disabled or starting up (%d)\n", enabled);
299 return CC26XX_SENSOR_READING_ERROR;
302 if((type != BMP_280_SENSOR_TYPE_TEMP) && type != BMP_280_SENSOR_TYPE_PRESS) {
303 PRINTF(
"Invalid type\n");
304 return CC26XX_SENSOR_READING_ERROR;
306 memset(sensor_value, 0, SENSOR_DATA_BUF_SIZE);
311 return CC26XX_SENSOR_READING_ERROR;
314 PRINTF(
"val: %02x%02x%02x %02x%02x%02x\n",
315 sensor_value[0], sensor_value[1], sensor_value[2],
316 sensor_value[3], sensor_value[4], sensor_value[5]);
320 if(type == BMP_280_SENSOR_TYPE_TEMP) {
322 }
else if(type == BMP_280_SENSOR_TYPE_PRESS) {
343 case SENSORS_HW_INIT:
344 enabled = SENSOR_STATUS_INITIALISED;
350 if(enabled == SENSOR_STATUS_DISABLED) {
351 return SENSOR_STATUS_DISABLED;
355 ctimer_set(&startup_timer, SENSOR_STARTUP_DELAY, notify_ready, NULL);
356 enabled = SENSOR_STATUS_NOT_READY;
360 enabled = SENSOR_STATUS_INITIALISED;
385 return SENSOR_STATUS_DISABLED;
Header file for the Sensortag I2C Driver.
Header file for the Sensortag BMP280 Altimeter / Pressure Sensor.
Header file for the callback timer.
void ctimer_stop(struct ctimer *c)
Stop a pending callback timer.
static void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
static void init(void)
Initalise the sensor.
const struct sensors_sensor bmp_280_sensor
Exports a global symbol to be used by the sensor API.
static int value(int type)
Returns a reading from the sensor.
static int status(int type)
Returns the status of the sensor.
static void enable_sensor(bool enable)
Enable/disable measurements.
static void convert(uint8_t *data, int32_t *temp, uint32_t *press)
Convert raw data to values in degrees C (temp) and Pascal (pressure)
static int configure(int type, int enable)
Configuration function for the BMP280 sensor.
static bool read_data()
Take readings from the sensor.
void board_i2c_select(uint8_t new_interface, uint8_t address)
Select an I2C slave.
void sensor_common_set_error_data(uint8_t *buf, uint8_t len)
Fill a result buffer with dummy error data.
bool sensor_common_read_reg(uint8_t addr, uint8_t *buf, uint8_t len)
Reads a sensor's register over I2C.
bool sensor_common_write_reg(uint8_t addr, uint8_t *buf, uint8_t len)
Write to a sensor's register over I2C.
Header file for the Sensortag Common sensor utilities.
Header file with macros which rename TI CC26xxware functions.