41#include "lib/sensors.h"
50#include <ti/drivers/I2C.h>
51#include <ti/drivers/PIN.h>
59#define PRINTF(...) printf(__VA_ARGS__)
69#if BOARD_SENSORS_ENABLE
73#error "Board file doesn't define I2C address Board_TMP_ADDR"
75#define TMP_007_I2C_ADDRESS Board_TMP_ADDR
79#error "Board file doesn't define interrupt pin Board_TMP_RDY"
81#define TMP_007_TMP_RDY Board_TMP_RDY
84#define REG_VOLTAGE 0x00
85#define REG_LOCAL_TEMP 0x01
86#define REG_CONFIG 0x02
87#define REG_OBJ_TEMP 0x03
88#define REG_STATUS 0x04
89#define REG_PROD_ID 0x1F
92#define VAL_CONFIG_ON 0x1000
93#define VAL_CONFIG_OFF 0x0000
94#define VAL_CONFIG_RESET 0x8000
95#define VAL_PROD_ID 0x0078
98#define CONV_RDY_BIT 0x4000
101#define REGISTER_LENGTH 2
107#define HI_UINT16(a) (((a) >> 8) & 0xFF)
108#define LO_UINT16(a) (((a) >> 0) & 0xFF)
110#define SWAP16(v) ((LO_UINT16(v) << 8) | (HI_UINT16(v) << 0))
112#define LSB16(v) (HI_UINT16(v)), (LO_UINT16(v))
113#define MSB16(v) (LO_UINT16(v)), (HI_UINT16(v))
127 volatile TMP_007_STATUS
status;
132static TMP_007_Object tmp_007;
135#define SENSOR_STARTUP_DELAY 36
137static struct ctimer startup_timer;
146 if(pin_handle && i2c_handle) {
150 pin_handle =
PIN_open(&pin_state, pin_table);
155 tmp_007.status = TMP_007_STATUS_DISABLED;
166 tmp_007.status = TMP_007_STATUS_READY;
167 sensors_changed(&tmp_007_sensor);
276 obj = (obj >> 2) * 3125 / 100;
293 if(tmp_007.status != TMP_007_STATUS_READY) {
294 PRINTF(
"Sensor disabled or starting up (%d)\n", tmp_007.status);
295 return TMP_007_READING_ERROR;
299 case TMP_007_TYPE_OBJECT:
return tmp_007.obj_tmp_latched;
300 case TMP_007_TYPE_AMBIENT:
return tmp_007.local_tmp_latched;
302 case TMP_007_TYPE_ALL:
304 PRINTF(
"TMP: Read failed\n");
305 return TMP_007_READING_ERROR;
321 PRINTF(
"Invalid type (%d)\n", type);
322 return TMP_007_READING_ERROR;
339 case SENSORS_HW_INIT:
341 return TMP_007_STATUS_DISABLED;
346 tmp_007.status = TMP_007_STATUS_INITIALIZED;
351 if(tmp_007.status == TMP_007_STATUS_DISABLED) {
352 return TMP_007_STATUS_DISABLED;
357 tmp_007.status = TMP_007_STATUS_NOT_READY;
361 tmp_007.status = TMP_007_STATUS_INITIALIZED;
369 return tmp_007.status;
382 return tmp_007.status;
385SENSORS_SENSOR(tmp_007_sensor,
"TMP-007",
value, configure,
status);
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.
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 bool read_data()
Take readings from the sensor.
static int value(int type)
Returns a reading from the sensor.
static int status(int type)
Returns the status of the sensor.
static bool enable_sensor(bool enable)
Turn the sensor on/off.
static void convert(uint16_t raw_temp, uint16_t raw_obj_temp, float *obj, float *amb)
Convert raw data to values in degrees C.
static int value(int type)
Returns a reading from the sensor.
#define VAL_CONFIG_OFF
Sensor off state.
static void notify_ready_cb(void *not_used)
Callback when sensor is ready to read data from.
static bool sensor_init(void)
Initialize the TMP-007 sensor driver.
static int configure(int type, int enable)
Configuration function for the TMP-007 sensor.
#define VAL_CONFIG_ON
Sensor on state.
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 TMP-007 IR Thermophile sensor.