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) 93 static uint8_t buf[DATA_SIZE];
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 101 static int enabled = SENSOR_STATUS_DISABLED;
104 #define SENSOR_STARTUP_DELAY 36 106 static struct ctimer startup_timer;
109 static int obj_temp_latched;
110 static 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];
178 *raw_obj_temp = buf[2] << 8 | buf[3];
191 convert(uint16_t raw_temp, uint16_t raw_obj_temp,
float *obj,
float *amb)
193 const float SCALE_LSB = 0.03125;
197 it = (int)((raw_obj_temp) >> 2);
198 t = ((float)(it)) * SCALE_LSB;
201 it = (int)((raw_temp) >> 2);
203 *amb = t * SCALE_LSB;
216 uint16_t raw_obj_temp;
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) {
233 rv =
read_data(&raw_temp, &raw_obj_temp);
236 return CC26XX_SENSOR_READING_ERROR;
239 convert(raw_temp, raw_obj_temp, &obj_temp, &amb_temp);
240 PRINTF(
"TMP: %04X %04X o=%d a=%d\n", raw_temp, raw_obj_temp,
241 (
int)(obj_temp * 1000), (
int)(amb_temp * 1000));
243 obj_temp_latched = (int)(obj_temp * 1000);
244 amb_temp_latched = (int)(amb_temp * 1000);
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;
285 enabled = SENSOR_STATUS_NOT_READY;
289 enabled = SENSOR_STATUS_INITIALISED;
314 return SENSOR_STATUS_DISABLED;
void ctimer_stop(struct ctimer *c)
Stop a pending callback timer.
Header file with macros which rename TI CC26xxware functions.
Header file for the Sensortag I2C Driver.
static bool enable_sensor(bool enable)
Turn the sensor on/off.
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.
Header file for the callback timer
Header file for the Sensortag Common sensor utilities.
static int status(int type)
Returns the status of the sensor.
static int configure(int type, int enable)
Configuration function for the TMP007 sensor.
static void convert(uint16_t raw_temp, uint16_t raw_obj_temp, float *obj, float *amb)
Convert raw data to values in degrees C.
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.
bool sensor_common_write_reg(uint8_t addr, uint8_t *buf, uint8_t len)
Write to a sensor's register over I2C.
static void notify_ready(void *unused)
Callback when sensor is ready to read data from.
Header file for the Sensortag TI TMP007 infrared thermophile sensor.
static int value(int type)
Returns a reading from the sensor.
static bool read_data(uint16_t *raw_temp, uint16_t *raw_obj_temp)
Read the sensor value registers.