40#include "lib/sensors.h"
54#define PRINTF(...) printf(__VA_ARGS__)
60#define SENSOR_I2C_ADDRESS 0x44
63#define TMP007_REG_ADDR_VOLTAGE 0x00
64#define TMP007_REG_ADDR_LOCAL_TEMP 0x01
65#define TMP007_REG_ADDR_CONFIG 0x02
66#define TMP007_REG_ADDR_OBJ_TEMP 0x03
67#define TMP007_REG_ADDR_STATUS 0x04
68#define TMP007_REG_PROD_ID 0x1F
71#define TMP007_VAL_CONFIG_ON 0x1000
72#define TMP007_VAL_CONFIG_OFF 0x0000
73#define TMP007_VAL_CONFIG_RESET 0x8000
74#define TMP007_VAL_PROD_ID 0x0078
77#define CONV_RDY_BIT 0x4000
80#define REGISTER_LENGTH 2
86#define HI_UINT16(a) (((a) >> 8) & 0xFF)
87#define LO_UINT16(a) ((a) & 0xFF)
89#define SWAP(v) ((LO_UINT16(v) << 8) | HI_UINT16(v))
91#define SELECT() board_i2c_select(BOARD_I2C_INTERFACE_0, SENSOR_I2C_ADDRESS)
96#define SENSOR_STATUS_DISABLED 0
97#define SENSOR_STATUS_INITIALISED 1
98#define SENSOR_STATUS_NOT_READY 2
99#define SENSOR_STATUS_READY 3
101static int enabled = SENSOR_STATUS_DISABLED;
104#define SENSOR_STARTUP_DELAY 36
106static struct ctimer startup_timer;
109static int obj_temp_latched;
110static int amb_temp_latched;
115 enabled = SENSOR_STATUS_READY;
116 sensors_changed(&tmp_007_sensor);
130 val = TMP007_VAL_CONFIG_ON;
132 val = TMP007_VAL_CONFIG_OFF;
160 success = val & CONV_RDY_BIT;
177 *raw_temp = buf[0] << 8 | buf[1];
201 it = (
int)((raw_temp) >> 2);
220 if(enabled != SENSOR_STATUS_READY) {
221 PRINTF(
"Sensor disabled or starting up (%d)\n", enabled);
222 return CC26XX_SENSOR_READING_ERROR;
225 if((type & TMP_007_SENSOR_TYPE_ALL) == 0) {
226 PRINTF(
"Invalid type\n");
227 return CC26XX_SENSOR_READING_ERROR;
230 rv = CC26XX_SENSOR_READING_ERROR;
232 if(type == TMP_007_SENSOR_TYPE_ALL) {
236 return CC26XX_SENSOR_READING_ERROR;
240 PRINTF(
"TMP: %04X %04X o=%d a=%d\n", raw_temp,
raw_obj_temp,
246 }
else if(type == TMP_007_SENSOR_TYPE_OBJECT) {
247 rv = obj_temp_latched;
248 }
else if(type == TMP_007_SENSOR_TYPE_AMBIENT) {
249 rv = amb_temp_latched;
269 case SENSORS_HW_INIT:
275 enabled = SENSOR_STATUS_INITIALISED;
279 if(enabled == SENSOR_STATUS_DISABLED) {
280 return SENSOR_STATUS_DISABLED;
284 ctimer_set(&startup_timer, SENSOR_STARTUP_DELAY, notify_ready, NULL);
285 enabled = SENSOR_STATUS_NOT_READY;
289 enabled = SENSOR_STATUS_INITIALISED;
314 return SENSOR_STATUS_DISABLED;
317SENSORS_SENSOR(tmp_007_sensor,
"TMP007",
value, configure,
status);
Header file for the Sensortag I2C Driver.
Header file for the Sensortag TI TMP007 infrared thermophile 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.
#define BOARD_IOID_TMP_RDY
TMP Sensor.
static bool read_data()
Take readings from the sensor.
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.
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 configure(int type, int enable)
Configuration function for the TMP007 sensor.
Header file for the Sensortag Common sensor utilities.
Header file with macros which rename TI CC26xxware functions.