40#include "lib/sensors.h"
55#define PRINTF(...) printf(__VA_ARGS__)
61#define OPT3001_I2C_ADDRESS 0x45
64#define REG_RESULT 0x00
65#define REG_CONFIGURATION 0x01
66#define REG_LOW_LIMIT 0x02
67#define REG_HIGH_LIMIT 0x03
69#define REG_MANUFACTURER_ID 0x7E
70#define REG_DEVICE_ID 0x7F
77#define CONFIG_RN 0x00F0
78#define CONFIG_CT 0x0008
79#define CONFIG_M 0x0006
80#define CONFIG_OVF 0x0001
81#define CONFIG_CRF 0x8000
82#define CONFIG_FH 0x4000
83#define CONFIG_FL 0x2000
84#define CONFIG_L 0x1000
85#define CONFIG_POL 0x0800
86#define CONFIG_ME 0x0400
87#define CONFIG_FC 0x0300
90#define CONFIG_CT_100 0x0000
91#define CONFIG_CT_800 CONFIG_CT
94#define CONFIG_M_CONTI 0x0004
95#define CONFIG_M_SINGLE 0x0002
96#define CONFIG_M_SHUTDOWN 0x0000
99#define CONFIG_RN_RESET 0x00C0
100#define CONFIG_CT_RESET CONFIG_CT_800
101#define CONFIG_L_RESET 0x1000
102#define CONFIG_DEFAULTS (CONFIG_RN_RESET | CONFIG_CT_100 | CONFIG_L_RESET)
105#define CONFIG_ENABLE_CONTINUOUS (CONFIG_M_CONTI | CONFIG_DEFAULTS)
106#define CONFIG_ENABLE_SINGLE_SHOT (CONFIG_M_SINGLE | CONFIG_DEFAULTS)
107#define CONFIG_DISABLE CONFIG_DEFAULTS
110#define REGISTER_LENGTH 2
120#define SENSOR_STATE_SLEEPING 0
121#define SENSOR_STATE_ACTIVE 1
122#define SENSOR_STATE_DATA_READY 2
124static int state = SENSOR_STATE_SLEEPING;
127#define SENSOR_STARTUP_DELAY (CLOCK_SECOND >> 3)
129static struct ctimer startup_timer;
155 if(val & CONFIG_CRF) {
156 sensors_changed(&opt_3001_sensor);
157 state = SENSOR_STATE_DATA_READY;
159 ctimer_set(&startup_timer, SENSOR_STARTUP_DELAY, notify_ready, NULL);
176 val = CONFIG_ENABLE_SINGLE_SHOT;
179 state = SENSOR_STATE_ACTIVE;
181 val = CONFIG_DISABLE;
201 if((state & SENSOR_STATE_DATA_READY) != SENSOR_STATE_DATA_READY) {
216 *
raw_data = (val << 8) | (val >> 8 & 0xFF);
237 return m * (0.01 *
exp2(e));
255 return CC26XX_SENSOR_READING_ERROR;
259 PRINTF(
"OPT: %04X r=%d (centilux)\n",
raw_val,
283 case SENSORS_HW_INIT:
294 ctimer_set(&startup_timer, SENSOR_STARTUP_DELAY, notify_ready, NULL);
325SENSORS_SENSOR(opt_3001_sensor,
"OPT3001",
value, configure,
status);
Header file for the Sensortag I2C Driver.
Header file for the Sensortag Opt3001 light 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.
static bool read_data()
Take readings from the sensor.
void board_i2c_select(uint8_t new_interface, uint8_t address)
Select an I2C slave.
static int value(int type)
Returns a reading from the sensor.
static float convert(uint16_t raw_data)
Convert raw data to a value in lux.
static int status(int type)
Returns the status of the sensor.
static void enable_sensor(bool enable)
Turn the sensor on/off.
static void select_on_bus(void)
Select the sensor on the I2C bus.
static int configure(int type, int enable)
Configuration function for the OPT3001 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.
Header file for the Sensortag Common sensor utilities.
Header file with macros which rename TI CC26xxware functions.