![]() |
![]() |
|
SAILAPIGuide
1_20_00_02
|
#include <ti/drivers/GPIO.h>#include <ti/drivers/I2C.h>#include <ti/sail/opt3001/opt3001.h>#include <stdint.h>#include <stdbool.h>#include <unistd.h>Macros | |
| #define | LUX_BASE_RES 00.01F |
| #define | RANGE_BASE 00040.95F |
| #define | RANGE_MAX 83865.60F |
| #define | RANGE_BITS 0xF000 |
| #define | READ_BUF_SIZE 2 |
| #define | WRITE_BUF_SIZE 3 |
| #define | CONVERSION_MODE 0xC000 |
Functions | |
| bool | OPT3001_close (OPT3001_Handle handle) |
| Function to close a OPT3001 sensor specified by the OPT3001 handle. More... | |
| bool | OPT3001_disableInterrupt (OPT3001_Handle handle) |
| Function to disable the GPIO interrupt. More... | |
| bool | OPT3001_enableInterrupt (OPT3001_Handle handle) |
| Enable interrupts from the specified OPT3001. More... | |
| bool | OPT3001_getLux (OPT3001_Handle handle, float *data) |
| Function to get the sensor's lux reading. More... | |
| bool | OPT3001_getLuxLimits (OPT3001_Handle handle, float *high, float *low) |
| Function to get the sensor's lux limits. More... | |
| void | OPT3001_init () |
| Function to initialize OPT3001 driver. More... | |
| OPT3001_Handle | OPT3001_open (unsigned int index, I2C_Handle i2cHandle, OPT3001_Params *params) |
| Function to open a given OPT3001 sensor. More... | |
| void | OPT3001_Params_init (OPT3001_Params *params) |
| Function to initialize a OPT3001_Params struct to its defaults. More... | |
| bool | OPT3001_readRegister (OPT3001_Handle handle, uint16_t *data, uint8_t registerAddress) |
| Read the specified register from a OPT3001 sensor. More... | |
| bool | OPT3001_setLuxLimits (OPT3001_Handle handle, float high, float low) |
| Function to get the sensor's lux limits. More... | |
| bool | OPT3001_setRange (OPT3001_Handle handle, OPT3001_FullRange range) |
| Set the lux measurement result range. More... | |
| bool | OPT3001_setConversionMode (OPT3001_Handle handle, OPT3001_ConversionMode mode) |
| Function to change the conversion mode. More... | |
| bool | OPT3001_writeRegister (OPT3001_Handle handle, uint16_t data, uint8_t registerAddress) |
| Write the specified data to a OPT3001 sensor. More... | |
Variables | |
| const OPT3001_Params | OPT3001_defaultParams |
| OPT3001_Config | OPT3001_config [] |
| #define LUX_BASE_RES 00.01F |
Referenced by OPT3001_setLuxLimits().
| #define RANGE_BASE 00040.95F |
Referenced by OPT3001_setLuxLimits().
| #define RANGE_MAX 83865.60F |
Referenced by OPT3001_close(), and OPT3001_setLuxLimits().
| #define RANGE_BITS 0xF000 |
Referenced by OPT3001_setRange().
| #define READ_BUF_SIZE 2 |
Referenced by OPT3001_readRegister().
| #define WRITE_BUF_SIZE 3 |
Referenced by OPT3001_writeRegister().
| #define CONVERSION_MODE 0xC000 |
| bool OPT3001_close | ( | OPT3001_Handle | handle | ) |
Function to close a OPT3001 sensor specified by the OPT3001 handle.
The OPT3001 hardware will be placed in a low power state in which ADC conversions are disabled. If the pin is configured to interrupt, the GPIO pin interrupts will be disabled. The I2C handle is not affected.
| handle | A OPT3001_Handle returned from OPT3001_open() |
References OPT3001_Object::callback, OPT3001_Object::i2cHandle, OPT3001_Config::object, OPT3001_disableInterrupt(), OPT3001_setConversionMode(), OPT3001_setLuxLimits(), OPT3001_SHUTDOWN, and RANGE_MAX.
| bool OPT3001_disableInterrupt | ( | OPT3001_Handle | handle | ) |
Function to disable the GPIO interrupt.
Interrupts on the OPT3001 specific GPIO index will be disabled. The lux limits set are unaffected.
| handle | A OPT3001_Handle |
References OPT3001_Config::hwAttrs, and OPT3001_Config::object.
Referenced by OPT3001_close().
| bool OPT3001_enableInterrupt | ( | OPT3001_Handle | handle | ) |
Enable interrupts from the specified OPT3001.
Interrupts on the OPT3001 specific GPIO index will be enabled.
| handle | A OPT3001_Handle |
References OPT3001_Config::hwAttrs, OPT3001_Config::object, OPT3001_CONFIG, and OPT3001_readRegister().
| bool OPT3001_getLux | ( | OPT3001_Handle | handle, |
| float * | data | ||
| ) |
Function to get the sensor's lux reading.
| handle | A OPT3001_Handle |
| data | A pointer to a float to store the lux value. |
References OPT3001_readRegister(), and OPT3001_RESULT.
| bool OPT3001_getLuxLimits | ( | OPT3001_Handle | handle, |
| float * | high, | ||
| float * | low | ||
| ) |
Function to get the sensor's lux limits.
| handle | A OPT3001_Handle |
| high | A pointer to a float to store the high limit |
| low | A pointer to a float to store the low limit |
References OPT3001_HILIMIT, and OPT3001_readRegister().
| void OPT3001_init | ( | ) |
Function to initialize OPT3001 driver.
This function will initialize the OPT3001 driver.
References OPT3001_Config::object.
| OPT3001_Handle OPT3001_open | ( | unsigned int | index, |
| I2C_Handle | i2cHandle, | ||
| OPT3001_Params * | params | ||
| ) |
Function to open a given OPT3001 sensor.
Function to initialize a given OPT3001 sensor specified by the particular index value. This function must be called from a task context. If one intends to use the INT pin, a callback function must be specified in the OPT3001_Params structure. Additionally, a gpioIndex must be setup and specified in the OPT3001_HWAttrs structure.
The I2C controller must be operating in BLOCKING mode. Failure to ensure the I2C_Handle is in BLOCKING mode will result in undefined behavior.
The user should ensure that each sensor has its own slaveAddress, gpioIndex (if alarming) and OPT3001Index.
| OPT3001Index | Logical sensor number for the OPT3001 indexed into the OPT3001_config table |
| i2cHandle | An I2C_Handle opened in BLOCKING mode |
| params | A pointer to OPT3001_Params structure. If NULL, it will use default values. |
References OPT3001_Object::callback, OPT3001_Params::callback, OPT3001_Params::conversionMode, OPT3001_Params::conversionReady, OPT3001_Params::conversionTime, OPT3001_Params::faultCount, OPT3001_HWAttrs::gpioIndex, OPT3001_Object::i2cHandle, OPT3001_Params::interruptMode, OPT3001_CONFIG, OPT3001_LOLIMIT, OPT3001_writeRegister(), and OPT3001_Params::range.
| void OPT3001_Params_init | ( | OPT3001_Params * | params | ) |
Function to initialize a OPT3001_Params struct to its defaults.
| params | A pointer to OPT3001_Params structure for initialization. |
Default values are:
conversionMode = OPT3001_CONTINUOUS conversionReady = OPT3001_CONVRD_DIS conversionTime = OPT3001_800MS faultCount = OPT3001_FAULT1 range = OPT3001_AUTO interruptMode = OPT3001_LATCH callback = NULL
References OPT3001_defaultParams.
| bool OPT3001_readRegister | ( | OPT3001_Handle | handle, |
| uint16_t * | data, | ||
| uint8_t | registerAddress | ||
| ) |
Read the specified register from a OPT3001 sensor.
| handle | A OPT3001_Handle |
| registerAddress | Register address |
| data | A pointer to a data register in which received data will be written to. Must be 16 bits. |
References OPT3001_Config::hwAttrs, and READ_BUF_SIZE.
Referenced by OPT3001_enableInterrupt(), OPT3001_getLux(), OPT3001_getLuxLimits(), OPT3001_setConversionMode(), and OPT3001_setRange().
| bool OPT3001_setLuxLimits | ( | OPT3001_Handle | handle, |
| float | high, | ||
| float | low | ||
| ) |
Function to get the sensor's lux limits.
| handle | A OPT3001_Handle |
| high | A float specifying the high limit. Use OPT3001_IGNORE if high limit is not desired. |
| low | A float specifying the low limit. Use OPT3001_IGNORE if a low limit is not desired. |
References LUX_BASE_RES, OPT3001_HILIMIT, OPT3001_IGNORE, OPT3001_LOLIMIT, OPT3001_writeRegister(), RANGE_BASE, and RANGE_MAX.
Referenced by OPT3001_close().
| bool OPT3001_setRange | ( | OPT3001_Handle | handle, |
| OPT3001_FullRange | range | ||
| ) |
Set the lux measurement result range.
| handle | A OPT3001_Handle |
| OPT3001_FullRange | A range value specifying max possible result |
References OPT3001_CONFIG, OPT3001_readRegister(), OPT3001_writeRegister(), and RANGE_BITS.
| bool OPT3001_setConversionMode | ( | OPT3001_Handle | handle, |
| OPT3001_ConversionMode | mode | ||
| ) |
Function to change the conversion mode.
This function will set the OPT3001 hardware to operate in the conversion mode specified by OPT3001_ConversionMode.
| handle | A OPT3001_Handle |
| mode | A OPT3001_ConversionMode specifying the mode to operate in. |
References OPT3001_CONFIG, OPT3001_readRegister(), OPT3001_SINGLESHOT, and OPT3001_writeRegister().
Referenced by OPT3001_close().
| bool OPT3001_writeRegister | ( | OPT3001_Handle | handle, |
| uint16_t | data, | ||
| uint8_t | registerAddress | ||
| ) |
Write the specified data to a OPT3001 sensor.
This function is not thread safe. When writing to a handle, it is possible to overwrite data written by another task.
For example: Task A and B are writing to the configuration register. Task A has a higher priority than Task B. Task B is running and reads the configuration register. Task A then preempts Task B and reads the configuration register, performs a logical OR and writes to the configuration register. Task B then resumes execution and performs its logical OR and writes to the configuration register–overwriting the data written by Task A.
Such instances can be prevented through the use of Semaphores. Below is an example which utilizes an initialized Semaphore_handle, OPT3001Lock.
| handle | A OPT3001_Handle |
| data | A uint16_t to be written to the OPT3001 sensor |
| registerAddress | OPT3001 register address |
References OPT3001_Config::hwAttrs, and WRITE_BUF_SIZE.
Referenced by OPT3001_open(), OPT3001_setConversionMode(), OPT3001_setLuxLimits(), and OPT3001_setRange().
| const OPT3001_Params OPT3001_defaultParams |
Referenced by OPT3001_Params_init().
| OPT3001_Config OPT3001_config[] |