Contiki-NG
Files | Macros | Functions

   Due to the time required for the sensor to startup, this driver is
   meant to be used in an asynchronous fashion.
More...

Files

 
 

Macros

#define CFG_RN   0x00F0
 [15..12] Range Number
 
#define CFG_CT   0x0008
 [11] Conversion Time
 
#define CFG_M   0x0006
 [10..9] Mode of Conversion
 
#define CFG_OVF   0x0001
 [8] Overflow
 
#define CFG_CRF   0x8000
 [7] Conversion Ready Field
 
#define CFG_FH   0x4000
 [6] Flag High
 
#define CFG_FL   0x2000
 [5] Flag Low
 
#define CFG_L   0x1000
 [4] Latch
 
#define CFG_POL   0x0800
 [3] Polarity
 
#define CFG_ME   0x0400
 [2] Mask Exponent
 
#define CFG_FC   0x0300
 [1..0] Fault Count
 

Functions

static bool i2c_write_read (void *wbuf, size_t wcount, void *rbuf, size_t rcount)
 Setup and peform an I2C transaction. More...
 
static bool i2c_write (void *wbuf, size_t wcount)
 Peform a write only I2C transaction. More...
 
static bool i2c_read (void *rbuf, size_t rcount)
 Peform a read only I2C transaction. More...
 
static bool sensor_init (void)
 Initialize the OPT-3001 sensor driver. More...
 
static bool sensor_enable (bool enable)
 Turn the sensor on/off. More...
 
static void notify_ready_cb (void *unused)
 Callback when sensor is ready to read data from.
 
static int value (int type)
 Returns a reading from the sensor. More...
 
static int configure (int type, int enable)
 Configuration function for the OPT3001 sensor. More...
 
static int status (int type)
 Returns the status of the sensor. More...
 

Detailed Description

   Due to the time required for the sensor to startup, this driver is
   meant to be used in an asynchronous fashion.

The caller must first activate the sensor by calling SENSORS_ACTIVATE(). This will trigger the sensor's startup sequence, but the call will not wait for it to complete so that the CPU can perform other tasks or drop to a low power mode.

Once the reading and conversion are complete, the driver will generate a sensors_changed event.

We use single-shot readings. In this mode, the hardware automatically goes back to its shutdown mode after the conversion is finished. However, it will still respond to I2C operations, so the last conversion can still be read out.

In order to take a new reading, the caller has to use SENSORS_ACTIVATE again.

Function Documentation

◆ configure()

static int configure ( int  type,
int  enable 
)
static

Configuration function for the OPT3001 sensor.

Parameters
typeActivate, enable or disable the sensor. See below.
enableEnable or disable sensor.
           When type == SENSORS_HW_INIT we turn on the hardware.
           When type == SENSORS_ACTIVE and enable==1 we enable the sensor.
           When type == SENSORS_ACTIVE and enable==0 we disable the sensor.

Definition at line 326 of file opt-3001-sensor.c.

◆ i2c_read()

static bool i2c_read ( void *  rbuf,
size_t  rcount 
)
inlinestatic

Peform a read only I2C transaction.

Parameters
rbufInput buffer during the I2C transation.
rcountHow many bytes to read into rbuf.
Returns
true if the I2C operation was successful; else, return false.

Definition at line 192 of file opt-3001-sensor.c.

References i2c_write_read().

◆ i2c_write()

static bool i2c_write ( void *  wbuf,
size_t  wcount 
)
inlinestatic

Peform a write only I2C transaction.

Parameters
wbufOutput buffer during the I2C transation.
wcountHow many bytes in the wbuf.
Returns
true if the I2C operation was successful; else, return false.

Definition at line 180 of file opt-3001-sensor.c.

References i2c_write_read().

◆ i2c_write_read()

static bool i2c_write_read ( void *  wbuf,
size_t  wcount,
void *  rbuf,
size_t  rcount 
)
static

Setup and peform an I2C transaction.

Parameters
wbufOutput buffer during the I2C transation.
wcountHow many bytes in the wbuf.
rbufInput buffer during the I2C transation.
rcountHow many bytes to read into rbuf.
Returns
true if the I2C operation was successful; else, return false.

Definition at line 160 of file opt-3001-sensor.c.

Referenced by i2c_read(), and i2c_write().

◆ sensor_enable()

static bool sensor_enable ( bool  enable)
static

Turn the sensor on/off.

Parameters
enableEnable sensor if true; else, disable sensor.

Definition at line 229 of file opt-3001-sensor.c.

◆ sensor_init()

static bool sensor_init ( void  )
static

Initialize the OPT-3001 sensor driver.

Returns
true if I2C operation successful; else, return false.

Definition at line 202 of file opt-3001-sensor.c.

◆ status()

static int status ( int  type)
static

Returns the status of the sensor.

Parameters
typeIgnored.
Returns
The state of the sensor SENSOR_STATE_xyz.

Definition at line 364 of file opt-3001-sensor.c.

◆ value()

static int value ( int  type)
static

Returns a reading from the sensor.

Parameters
typeIgnored.
Returns
Illuminance in centilux.

Definition at line 277 of file opt-3001-sensor.c.