41#include "lib/sensors.h"
50#include <ti/drivers/I2C.h>
58#define PRINTF(...) printf(__VA_ARGS__)
68#if BOARD_SENSORS_ENABLE
70#ifndef Board_BMP280_ADDR
71#error "Board file doesn't define I2C address Board_BMP280_ADDR"
74#define BMP280_I2C_ADDRESS Board_BMP280_ADDR
77#define ADDR_CALIB 0x88
78#define ADDR_PROD_ID 0xD0
79#define ADDR_RESET 0xE0
80#define ADDR_STATUS 0xF3
81#define ADDR_CTRL_MEAS 0xF4
82#define ADDR_CONFIG 0xF5
83#define ADDR_PRESS_MSB 0xF7
84#define ADDR_PRESS_LSB 0xF8
85#define ADDR_PRESS_XLSB 0xF9
86#define ADDR_TEMP_MSB 0xFA
87#define ADDR_TEMP_LSB 0xFB
88#define ADDR_TEMP_XLSB 0xFC
91#define VAL_PROD_ID 0x58
93#define VAL_STATUS 0x00
94#define VAL_CTRL_MEAS 0x00
95#define VAL_CONFIG 0x00
96#define VAL_PRESS_MSB 0x80
97#define VAL_PRESS_LSB 0x00
98#define VAL_TEMP_MSB 0x80
99#define VAL_TEMP_LSB 0x00
102#define VAL_RESET_EXECUTE 0xB6
103#define VAL_CTRL_MEAS_TEST 0x55
106#define SENSOR_DATA_BUF_SIZE 6
109#define RES_ULTRA_LOW_POWER 1
110#define RES_LOW_POWER 2
111#define RES_STANDARD 3
113#define RES_ULTRA_HIGH 6
120#define OSRST(v) ((v) << 5)
121#define OSRSP(v) ((v) << 2)
136} BMP_280_Calibration;
138static BMP_280_Calibration calib_data;
143 SENSOR_STATUS_DISABLED,
144 SENSOR_STATUS_INITIALISED,
145 SENSOR_STATUS_NOT_READY,
149static volatile SENSOR_STATUS sensor_status = SENSOR_STATUS_DISABLED;
152#define SENSOR_STARTUP_DELAY 3
154static struct ctimer startup_timer;
157notify_ready(
void *unused)
161 sensor_status = SENSOR_STATUS_READY;
180 sensor_status = SENSOR_STATUS_DISABLED;
190 &calib_data,
sizeof(calib_data));
214 ? PM_FORCED | OSRSP(1) | OSRST(1)
222 sensor_status = SENSOR_STATUS_DISABLED;
252 sensor_status = SENSOR_STATUS_DISABLED;
276 BMP_280_Calibration *p = &calib_data;
341 uint8_t sensor_value[SENSOR_DATA_BUF_SIZE];
343 if(sensor_status != SENSOR_STATUS_READY) {
344 PRINTF(
"Sensor disabled or starting up (%d)\n", sensor_status);
345 return BMP_280_READING_ERROR;
349 case BMP_280_SENSOR_TYPE_TEMP:
350 case BMP_280_SENSOR_TYPE_PRESS:
351 memset(sensor_value, 0, SENSOR_DATA_BUF_SIZE);
352 if(!
read_data(sensor_value, SENSOR_DATA_BUF_SIZE)) {
353 return BMP_280_READING_ERROR;
356 PRINTF(
"val: %02x%02x%02x %02x%02x%02x\n",
357 sensor_value[0], sensor_value[1], sensor_value[2],
358 sensor_value[3], sensor_value[4], sensor_value[5]);
362 if(type == BMP_280_SENSOR_TYPE_TEMP) {
364 }
else if(type == BMP_280_SENSOR_TYPE_PRESS) {
371 PRINTF(
"Invalid BMP 208 Sensor Type\n");
372 return BMP_280_READING_ERROR;
388 case SENSORS_HW_INIT:
391 sensor_status = SENSOR_STATUS_INITIALISED;
393 sensor_status = SENSOR_STATUS_DISABLED;
399 if(sensor_status == SENSOR_STATUS_DISABLED) {
404 ctimer_set(&startup_timer, SENSOR_STARTUP_DELAY, notify_ready, NULL);
405 sensor_status = SENSOR_STATUS_NOT_READY;
409 sensor_status = SENSOR_STATUS_INITIALISED;
416 return sensor_status;
430 return sensor_status;
432 return SENSOR_STATUS_DISABLED;
Header file for the callback timer.
bool i2c_arch_write_read(I2C_Handle i2c_handle, uint_least8_t slave_addr, void *wbuf, size_t wcount, void *rbuf, size_t rcount)
Setup and peform an I2C transaction.
static bool i2c_arch_write(I2C_Handle i2c_handle, uint_least8_t slave_addr, void *wbuf, size_t wcount)
Perform a write-only I2C transaction.
I2C_Handle i2c_arch_acquire(uint_least8_t index)
Open and lock the I2C Peripheral for use.
void i2c_arch_release(I2C_Handle i2c_handle)
Release the I2C Peripheral for other modules to use.
static volatile uint64_t count
Num.
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 int value(int type)
Returns a reading from the sensor.
static int configure(int type, int enable)
Configuration function for the BMP280 sensor.
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 bool read_data()
Take readings from the sensor.
Implementation of the I2C HAL driver for CC13xx/CC26xx.
Header file with definitions related to the sensors on the Sensortags.
Header file for the Sensortag BMP280 Altimeter / Pressure Sensor.