41#include "lib/sensors.h"
55#define PRINTF(...) printf(__VA_ARGS__)
61#define SENSOR_I2C_ADDRESS 0x43
64#define HDC1000_REG_TEMP 0x00
65#define HDC1000_REG_HUM 0x01
66#define HDC1000_REG_CONFIG 0x02
67#define HDC1000_REG_SERID_H 0xFB
68#define HDC1000_REG_SERID_M 0xFC
69#define HDC1000_REG_SERID_L 0xFD
70#define HDC1000_REG_MANF_ID 0xFE
71#define HDC1000_REG_DEV_ID 0xFF
74#define HDC1000_VAL_MANF_ID 0x5449
75#define HDC1000_VAL_DEV_ID 0x1000
76#define HDC1000_VAL_CONFIG 0x1000
79#define SENSOR_SELECT() board_i2c_select(BOARD_I2C_INTERFACE_0, SENSOR_I2C_ADDRESS)
80#define SENSOR_DESELECT() board_i2c_deselect()
83#define HI_UINT16(a) (((a) >> 8) & 0xFF)
84#define LO_UINT16(a) ((a) & 0xFF)
86#define SWAP(v) ((LO_UINT16(v) << 8) | HI_UINT16(v))
89typedef struct sensor_data {
95static uint16_t raw_temp;
96static uint16_t raw_hum;
99static sensor_data_t data;
108#define MEASUREMENT_DURATION 2
114#define SENSOR_STARTUP_DELAY 3
116static struct ctimer startup_timer;
130 val = SWAP(HDC1000_VAL_CONFIG);
168 raw_temp = SWAP(data.temp);
171 raw_hum = SWAP(data.hum);
189 *temp = ((double)raw_temp / 65536) * 165 - 40;
192 *hum = ((double)raw_hum / 65536) * 100;
203 sensors_changed(&hdc_1000_sensor);
215 PRINTF(
"Sensor disabled or starting up (%d)\n", enabled);
216 return CC26XX_SENSOR_READING_ERROR;
219 if((type != HDC_1000_SENSOR_TYPE_TEMP) &&
220 type != HDC_1000_SENSOR_TYPE_HUMID) {
221 PRINTF(
"Invalid type\n");
222 return CC26XX_SENSOR_READING_ERROR;
228 PRINTF(
"HDC: %04X %04X t=%d h=%d\n", raw_temp, raw_hum,
229 (
int)(temp * 100), (
int)(hum * 100));
232 if(type == HDC_1000_SENSOR_TYPE_TEMP) {
233 rv = (int)(temp * 100);
234 }
else if(type == HDC_1000_SENSOR_TYPE_HUMID) {
235 rv = (int)(hum * 100);
254 case SENSORS_HW_INIT:
257 memset(&data, 0,
sizeof(data));
Header file for the Sensortag I2C Driver.
Header file for the callback timer.
void ctimer_stop(struct ctimer *c)
Stop a pending callback timer.
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 void start(void)
Start measurement.
static void convert(float *temp, float *hum)
Convert raw data to temperature and humidity.
static bool sensor_init(void)
Initialise the humidity sensor driver.
static int configure(int type, int enable)
Configuration function for the HDC1000 sensor.
bool board_i2c_write_single(uint8_t data)
Single write to an I2C device.
bool board_i2c_read(uint8_t *data, uint8_t len)
Burst read from an I2C device.
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.
@ HDC_1000_SENSOR_STATUS_INITIALISED
Initialised but idle.
@ HDC_1000_SENSOR_STATUS_TAKING_READINGS
Readings in progress.
@ HDC_1000_SENSOR_STATUS_READINGS_READY
Both readings ready.
@ HDC_1000_SENSOR_STATUS_DISABLED
Not initialised.
Header file for the Sensortag Common sensor utilities.
Header file for the Sensortag HDC1000 sensor.
Header file with macros which rename TI CC26xxware functions.