42#include "lib/sensors.h"
50#include <ti/drivers/I2C.h>
59#define PRINTF(...) printf(__VA_ARGS__)
69#if BOARD_SENSORS_ENABLE
71#ifndef Board_HDC1000_ADDR
72#error "Board file doesn't define the I2C address Board_HDC1000_ADDR"
75#define HDC1000_I2C_ADDRESS Board_HDC1000_ADDR
78#define HDC1000_REG_TEMP 0x00
79#define HDC1000_REG_HUM 0x01
80#define HDC1000_REG_CONFIG 0x02
82#if CONTIKI_BOARD_SENSORTAG_CC1352R1
83#define HDC2080_REG_CONFIG 0x0e
84#define HDC2080_MEA_CONFIG 0x0f
87#define HDC1000_REG_SERID_H 0xFB
88#define HDC1000_REG_SERID_M 0xFC
89#define HDC1000_REG_SERID_L 0xFD
90#define HDC1000_REG_MANF_ID 0xFE
91#define HDC1000_REG_DEV_ID 0xFF
94#define HDC1000_VAL_MANF_ID 0x5449
95#define HDC1000_VAL_DEV_ID 0x1000
96#define HDC1000_VAL_CONFIG 0x1000
99#define HI_UINT16(a) (((a) >> 8) & 0xFF)
100#define LO_UINT16(a) ((a) & 0xFF)
102#define SWAP16(v) ((LO_UINT16(v) << 8) | HI_UINT16(v))
104#define LSB16(v) (HI_UINT16(v)), (LO_UINT16(v))
106static I2C_Handle i2c_handle;
109#if CONTIKI_BOARD_SENSORTAG_CC1352R1
115} HDC_1000_SensorData;
120} HDC_1000_SensorData;
123static HDC_1000_SensorData sensor_data;
132#define MEASUREMENT_DURATION 2
138#define SENSOR_STARTUP_DELAY 3
140static struct ctimer startup_timer;
158#if CONTIKI_BOARD_SENSORTAG_CC1352R1
160 uint8_t config_data[] = { HDC2080_REG_CONFIG, 0x00 };
162 uint8_t config_data[] = { HDC1000_REG_CONFIG, LSB16(HDC1000_VAL_CONFIG) };
166 sizeof(config_data));
181#if CONTIKI_BOARD_SENSORTAG_CC1352R1
182 uint8_t temp_reg[] = { HDC2080_MEA_CONFIG, 0x01 };
184 uint8_t temp_reg[] = { HDC1000_REG_TEMP };
209#if CONTIKI_BOARD_SENSORTAG_CC1352R1
210 int32_t raw_temp = sensor_data.temp_high * 256 + sensor_data.temp_low;
211 int32_t raw_hum = sensor_data.hum_high * 256 + sensor_data.hum_low;
213 int32_t raw_temp = SWAP16(sensor_data.temp);
214 int32_t raw_hum = SWAP16(sensor_data.hum);
218 *temp = (raw_temp * 100 * 165) / 65536 - 4000;
220 *hum = (raw_hum * 100 * 100) / 65536;
239#if CONTIKI_BOARD_SENSORTAG_CC1352R1
240 uint8_t temp_reg[] = { HDC1000_REG_TEMP };
242 sizeof(temp_reg), &sensor_data,
sizeof(sensor_data))) {
244 if(
i2c_arch_read(i2c_handle, HDC1000_I2C_ADDRESS, &sensor_data,
245 sizeof(sensor_data))) {
254 sensors_changed(&hdc_1000_sensor);
269 PRINTF(
"Sensor disabled or starting up (%d)\n", sensor_status);
270 return HDC_1000_READING_ERROR;
274 case HDC_1000_SENSOR_TYPE_TEMP:
275 case HDC_1000_SENSOR_TYPE_HUMID:
277 PRINTF(
"HDC: t=%d h=%d\n", (
int)temp, (
int)hum);
279 if(type == HDC_1000_SENSOR_TYPE_TEMP) {
281 }
else if(type == HDC_1000_SENSOR_TYPE_HUMID) {
284 return HDC_1000_READING_ERROR;
288 PRINTF(
"Invalid type\n");
289 return HDC_1000_READING_ERROR;
305 case SENSORS_HW_INIT:
306 memset(&sensor_data, 0,
sizeof(sensor_data));
337 return sensor_status;
351 return sensor_status;
Header file for the callback timer.
static bool i2c_arch_read(I2C_Handle i2c_handle, uint_least8_t slave_addr, void *rbuf, size_t rcount)
Perform a read-only I2C transaction.
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.
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 bool start(void)
Start measurement.
static int status(int type)
Returns the status of the sensor.
static bool sensor_init(void)
Initialize the HDC-1000 sensor driver.
static void notify_ready(void *unused)
Callback when sensor is ready to read data from.
static int configure(int type, int enable)
Configuration function for the HDC1000 sensor.
static void convert(int32_t *temp, int32_t *hum)
Convert raw data to temperature and humidity.
@ HDC_1000_SENSOR_STATUS_I2C_ERROR
I2C transaction failed.
@ 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.
Implementation of the I2C HAL driver for CC13xx/CC26xx.
Header file for the Sensortag HDC1000 sensor.
Header file with definitions related to SmartRF06 EB boards.