SAILAPIGuide  1_10_00_06
opt3001.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
189 #ifndef OPT3001_H_
190 #define OPT3001_H_
191 
192 #ifdef __cplusplus
193 extern "C" {
194 #endif
195 
196 /* Driver Header files */
197 #include <ti/drivers/I2C.h>
198 #include <ti/drivers/GPIO.h>
199 
200 /* OPT3001 Register Addresses */
201 #define OPT3001_RESULT 0x0000 /* Result Register (Read-Only) */
202 #define OPT3001_CONFIG 0x0001 /* Configuration Register */
203 #define OPT3001_LOLIMIT 0x0002 /* Low-Limit Register */
204 #define OPT3001_HILIMIT 0x0003 /* High-Limit Register */
205 #define OPT3001_MFTID 0x007E /* Manufacturer ID Register */
206 #define OPT3001_DEVICEID 0x007F /* Device ID Register */
207 
208 /* OPT3001 Configuration Register Bits */
209 #define OPT3001_FL 0x0020 /* Flag Low Field */
210 #define OPT3001_FH 0x0040 /* Flag High Field */
211 #define OPT3001_CRF 0x0080 /* Conversion Ready Field */
212 #define OPT3001_OVF 0x0100 /* Overflow Flag Field */
213 
227 #define OPT3001_IGNORE 0xFFFF
228 
239  OPT3001_SHUTDOWN = 0x0000,
243 
258 
271  OPT3001_800MS = 0x0800
273 
274 
283 typedef enum OPT3001_FaultCount {
284  OPT3001_FAULT1 = 0x0000,
285  OPT3001_FAULT2 = 0x0001,
286  OPT3001_FAULT4 = 0x0002,
287  OPT3001_FAULT8 = 0x0003
289 
309 typedef enum OPT3001_FullRange {
310  OPT3001_RANGE0 = 0x0000,
311  OPT3001_RANGE1 = 0x1000,
312  OPT3001_RANGE2 = 0x2000,
313  OPT3001_RANGE3 = 0x3000,
314  OPT3001_RANGE4 = 0x4000,
315  OPT3001_RANGE5 = 0x5000,
316  OPT3001_RANGE6 = 0x6000,
317  OPT3001_RANGE7 = 0x7000,
318  OPT3001_RANGE8 = 0x8000,
319  OPT3001_RANGE9 = 0x9000,
320  OPT3001_RANGE10 = 0xA000,
321  OPT3001_RANGE11 = 0xB000,
322  OPT3001_AUTO = 0xC000
324 
339 typedef enum OPT3001_InterruptMode {
341  OPT3001_LATCH = 0x0010
343 
344 
349 
357 typedef enum OPT3001_SlaveAddress {
358  OPT3001_SA1 = 0x44,
359  OPT3001_SA2 = 0x45,
360  OPT3001_SA3 = 0x46,
361  OPT3001_SA4 = 0x47,
363 
372 typedef struct OPT3001_Config {
374  void const *hwAttrs;
375 
377  void *object;
379 
387 typedef struct OPT3001_HWAttrs {
389  unsigned int gpioIndex;
391 
395 typedef struct OPT3001_Object {
396  I2C_Handle i2cHandle;
397  GPIO_CallbackFxn callback;
400 
413 typedef struct OPT3001_Params {
420  GPIO_CallbackFxn callback;
422 
436 extern bool OPT3001_close(OPT3001_Handle handle);
437 
453 extern bool OPT3001_disableInterrupt(OPT3001_Handle handle);
454 
469 extern bool OPT3001_enableInterrupt(OPT3001_Handle handle);
470 
480 extern bool OPT3001_getLux(OPT3001_Handle handle, float *data);
481 
493 extern bool OPT3001_getLuxLimits(OPT3001_Handle handle,
494  float *high, float *low);
495 
501 extern void OPT3001_init();
502 
534 extern OPT3001_Handle OPT3001_open(unsigned int index,
535  I2C_Handle i2cHandle, OPT3001_Params *params);
536 
553 extern void OPT3001_Params_init(OPT3001_Params *params);
554 
567 extern bool OPT3001_readRegister(OPT3001_Handle handle,
568  uint16_t *data, uint8_t registerAddress);
569 
585 extern bool OPT3001_setConversionMode(OPT3001_Handle handle,
587 
601 extern bool OPT3001_setLuxLimits(OPT3001_Handle handle, float high, float low);
602 
612 extern bool OPT3001_setRange(OPT3001_Handle handle, OPT3001_FullRange range);
613 
651 extern bool OPT3001_writeRegister(OPT3001_Handle handle, uint16_t data,
652  uint8_t registerAddress);
653 
654 #ifdef __cplusplus
655 }
656 #endif
657 
658 #endif /* OPT3001_H_ */
Definition: opt3001.h:239
Hardware specific settings for a OPT3001 sensor.
Definition: opt3001.h:387
Definition: opt3001.h:360
Members should not be accessed by the application.
Definition: opt3001.h:395
Definition: opt3001.h:310
unsigned int gpioIndex
Definition: opt3001.h:389
Definition: opt3001.h:320
Definition: opt3001.h:341
Definition: opt3001.h:241
struct OPT3001_Params OPT3001_Params
OPT3001 Parameters.
struct OPT3001_Config OPT3001_Config
OPT3001 configuration.
Definition: opt3001.h:322
Definition: opt3001.h:340
OPT3001_ConversionMode conversionMode
Definition: opt3001.h:414
Definition: opt3001.h:314
Definition: opt3001.h:286
OPT3001_ConversionTime
OPT3001 Conversion Time.
Definition: opt3001.h:269
bool OPT3001_getLuxLimits(OPT3001_Handle handle, float *high, float *low)
Function to get the sensor&#39;s lux limits.
Definition: opt3001.c:181
Definition: opt3001.h:240
Definition: opt3001.h:287
struct OPT3001_HWAttrs OPT3001_HWAttrs
Hardware specific settings for a OPT3001 sensor.
void OPT3001_init()
Function to initialize OPT3001 driver.
Definition: opt3001.c:201
OPT3001_FaultCount faultCount
Definition: opt3001.h:417
void OPT3001_Params_init(OPT3001_Params *params)
Function to initialize a OPT3001_Params struct to its defaults.
Definition: opt3001.c:269
OPT3001_FaultCount
OPT3001 Fault Count.
Definition: opt3001.h:283
Definition: opt3001.h:311
Definition: opt3001.h:285
Definition: opt3001.h:317
void const * hwAttrs
Definition: opt3001.h:374
Definition: opt3001.h:313
Definition: opt3001.h:321
OPT3001_FullRange
OPT3001 Result Register Range.
Definition: opt3001.h:309
bool OPT3001_setConversionMode(OPT3001_Handle handle, OPT3001_ConversionMode mode)
Function to change the conversion mode.
Definition: opt3001.c:384
OPT3001_InterruptMode
OPT3001 Interrupt Mode.
Definition: opt3001.h:339
OPT3001_ConversionReady
OPT3001 Conversion Ready Interrupt Mode.
Definition: opt3001.h:254
struct OPT3001_Config * OPT3001_Handle
A handle that is returned from a OPT3001_open() call.
Definition: opt3001.h:348
Definition: opt3001.h:256
void * object
Definition: opt3001.h:377
Definition: opt3001.h:284
OPT3001_InterruptMode interruptMode
Definition: opt3001.h:419
bool OPT3001_setRange(OPT3001_Handle handle, OPT3001_FullRange range)
Set the lux measurement result range.
Definition: opt3001.c:360
bool OPT3001_readRegister(OPT3001_Handle handle, uint16_t *data, uint8_t registerAddress)
Read the specified register from a OPT3001 sensor.
Definition: opt3001.c:278
OPT3001_FullRange range
Definition: opt3001.h:398
OPT3001 Parameters.
Definition: opt3001.h:413
Definition: opt3001.h:318
GPIO_CallbackFxn callback
Definition: opt3001.h:397
OPT3001 configuration.
Definition: opt3001.h:372
Definition: opt3001.h:315
OPT3001_ConversionReady conversionReady
Definition: opt3001.h:415
Definition: opt3001.h:358
bool OPT3001_setLuxLimits(OPT3001_Handle handle, float high, float low)
Function to get the sensor&#39;s lux limits.
Definition: opt3001.c:305
OPT3001_SlaveAddress
OPT3001 I2C slave addresses.
Definition: opt3001.h:357
Definition: opt3001.h:271
Definition: opt3001.h:319
OPT3001_SlaveAddress slaveAddress
Definition: opt3001.h:388
Definition: opt3001.h:359
GPIO_CallbackFxn callback
Definition: opt3001.h:420
Definition: opt3001.h:361
bool OPT3001_enableInterrupt(OPT3001_Handle handle)
Enable interrupts from the specified OPT3001.
Definition: opt3001.c:144
OPT3001_ConversionTime conversionTime
Definition: opt3001.h:416
I2C_Handle i2cHandle
Definition: opt3001.h:396
OPT3001_ConversionMode
OPT3001 ADC conversion mode.
Definition: opt3001.h:238
OPT3001_FullRange range
Definition: opt3001.h:418
Definition: opt3001.h:255
bool OPT3001_writeRegister(OPT3001_Handle handle, uint16_t data, uint8_t registerAddress)
Write the specified data to a OPT3001 sensor.
Definition: opt3001.c:409
Definition: opt3001.h:316
Definition: opt3001.h:312
bool OPT3001_disableInterrupt(OPT3001_Handle handle)
Function to disable the GPIO interrupt.
Definition: opt3001.c:128
Definition: opt3001.h:270
bool OPT3001_getLux(OPT3001_Handle handle, float *data)
Function to get the sensor&#39;s lux reading.
Definition: opt3001.c:165
bool OPT3001_close(OPT3001_Handle handle)
Function to close a OPT3001 sensor specified by the OPT3001 handle.
Definition: opt3001.c:105
struct OPT3001_Object OPT3001_Object
Members should not be accessed by the application.
OPT3001_Handle OPT3001_open(unsigned int index, I2C_Handle i2cHandle, OPT3001_Params *params)
Function to open a given OPT3001 sensor.
Definition: opt3001.c:218
Copyright 2017, Texas Instruments Incorporated