Library for ISL29125 - I2C RGB ambient light sensor

Dependents:   ISL29125_demo FinalProject Final_NSR 4180FinalProject_copy ... more

Device documentation

Detailed information is available at Intersil

Calling the constructor

The constructor can be instantiaded in 3 ways:

Information

The first two pins (SDA and SCL) always need to be declared.

ISR mode

void RGBsensor_irq(void)    // User ISR
{
    ....
}

ISL29125 RGBsensor(PTE0, PTE1, PTD7, &RGBsensor_irq);          // sda, scl, irq, user isr

The user ISR is called whenever the upper/lower threshold is reached and/or when a conversion cycle is finished. The threshold (Threshold function) and end of conversion (IRQonCnvDone function) interrupts can be enabled separately.
In this mode, PTD7 is an interrupt input.

Limitation!

Calling the Read function at a high rate will result in a I2C failure.
Use a Ticker to call the Read function at regular intervals. Example : ISL29125_demo

SYNC mode

ISL29125 RGBsensor(PTE0, PTE1, PTD7);                        // sda, scl, sync input

In this mode, PTD7 is a digital output. Initially, the sensor is idle (no conversions) and can be started by calling the Run function.

Polling mode

ISL29125 RGBsensor(PTE0, PTE1);                              // sda, scl

In this mode, user defined functions are needed to poll the sensor status, read the sensor data, ....

Revision:
4:ae36914adb6d
Parent:
3:400edaa74b7d
--- a/ISL29125.h	Wed May 28 19:36:31 2014 +0000
+++ b/ISL29125.h	Wed May 28 20:15:39 2014 +0000
@@ -49,8 +49,7 @@
      *  \brief Create a ISL29125 object connected to I2C bus, irq or sync pin and user-ISR pointer.\n
      *  \param sda       SDA pin.\n
      *  \param scl       SCL pin.\n
-     *  \param irqsync   (Optional) Interrupt pin when fptr is also declared.\n
-     *                              Sync output when fptr is not declared.\n
+     *  \param irqsync   (Optional) Interrupt pin when fptr is also declared OR Sync output when fptr is not declared.\n
      *  \param fptr      (Optional) Pointer to user-ISR (only used with Interrupt pin).\n
      *  \return none\n
      */
@@ -61,36 +60,38 @@
      *         The interrupt status flag is cleared when the status register is read.\n
      *  \param NONE
      *  \return Content of the entire status register.\n
-     *          bit|Description        |Return value
-     *          ---|-------------------|---------------------------------------
-     *          5,4|RGB conversion     |00: Inactive
-     *             |                   |01: Green
-     *             |                   |10: Red
-     *             |                   |11: Blue
-     *           2 |Brownout status    |0: No brownout
-     *             |                   |1: Power down or brownout occured
-     *           1 | Conversion status |0: Conversion is pending or inactive
-     *             |                   |1: Conversion is completed
-     *           0 | Interrupt status  |0: no interrupt occured
-     *             |                   |1: interrupt occured
+     @verbatim
+     bit  Description
+     ---  ---------------------------------------------------------
+     5,4  RGB conversion     - 00: Inactive
+                               01: Green
+                               10: Red
+                               11: Blue
+      2   Brownout status    - 0: No brownout
+                               1: Power down or brownout occured
+      1   Conversion status  - 0: Conversion is pending or inactive
+                               1: Conversion is completed
+      0   Interrupt status   - 0: no interrupt occured
+                               1: interrupt occured
+     @endverbatim
      */
     uint8_t Status(void);
 
     /**
      *  \brief Read the device identifier.\n
-     *  \param none.\n
-     *  \return 0x7D on success.\n
+     *  \param none.
+     *  \return 0x7D on success.
      */
     uint8_t WhoAmI(void);
     
     /**
      *  \brief Read the channel values (12 or 16-bit - depends on resolution).\n
-     *  \param color\n
-     *         ISL29125_R     Return Red channel.\n
-     *         ISL29125_G     Return Green channel.\n
-     *         ISL29125_B     Return Blue channel.\n
-     *         ISL29125_RGB   Return Red, Green and Blue channels. \n
-     *  \param data\n
+     *  \param color
+     *         ISL29125_R = Red channel.\n
+     *         ISL29125_G = Green channel.\n
+     *         ISL29125_B = Blue channel.\n
+     *         ISL29125_RGB = Red, Green and Blue channels.\n
+     *  \param data
      *         Pointer to 16-bit array for storing the channel value(s).\n
      *         Array size: 1 for a single color (Red, Green or Blue) or 3 for all colors.\n
      *  \return bool  1: new data available - 0: no new data available.\n
@@ -100,11 +101,11 @@
     /**
      *  \brief Read/Write the low/high interrupt threshold value.\n
      *         When setIRQonColor is activated, an interrupt will occur when the low or high threshold is exceeded.\n
-     *  \param reg\n
-     *         ISL29125_LTH_W     Write 16-bit low threshold.\n
-     *         ISL29125_HTH_W     Write 16-bit high threshold.\n
-     *         ISL29125_LTH_R     Read 16-bit low threshold.\n
-     *         ISL29125_HTH_R     Read 16-bit high threshold.\n
+     *  \param reg
+     *         ISL29125_LTH_W = Write 16-bit low threshold.\n
+     *         ISL29125_HTH_W = Write 16-bit high threshold.\n
+     *         ISL29125_LTH_R = Read 16-bit low threshold.\n
+     *         ISL29125_HTH_R = Read 16-bit high threshold.\n
      *  \param thres  16-bit threshold value (only needed when _W parameter is used).\n
      *  \return Written threshold value when called with _W parameter.\n
      *          Stored threshold value when called with _R parameter only.\n
@@ -113,15 +114,15 @@
 
     /**
      *  \brief Read/Write the RGB operating mode value (active ADC channels).\n
-     *  \param mode\n
-     *         ISL29125_G      G channel only.\n
-     *         ISL29125_R      R channel only.\n
-     *         ISL29125_B      B channel only.\n
-     *         ISL29125_RG     R and G channel.\n
-     *         ISL29125_BG     B and G channel.\n
-     *         ISL29125_RGB    R, G and B channel.\n
-     *         ISL29125_STBY   Standby (No ADC conversion).\n
-     *         ISL29125_OFF    Power down ADC conversion.\n
+     *  \param mode
+     *         ISL29125_G = G channel only.\n
+     *         ISL29125_R = R channel only.\n
+     *         ISL29125_B = B channel only.\n
+     *         ISL29125_RG = R and G channel.\n
+     *         ISL29125_BG = B and G channel.\n
+     *         ISL29125_RGB = R, G and B channel.\n
+     *         ISL29125_STBY = Standby (No ADC conversion).\n
+     *         ISL29125_OFF = Power down ADC conversion.\n
      *  \return Written value is returned when called with valid parameter, otherwise 0xff is returned.\n
      *          Stored value is returned when called without parameter.\n
      */
@@ -129,9 +130,9 @@
 
     /**
      *  \brief Read/Write the sensing range parameter.\n
-     *  \param range\n
-     *         ISL29125_375LX     Max. value corresponds to 375 lux.\n
-     *         ISL29125_10KLX     Max. value corresponds to 10000 lux.\n
+     *  \param range
+     *         ISL29125_375LX = Max. value corresponds to 375 lux.\n
+     *         ISL29125_10KLX = Max. value corresponds to 10000 lux.\n
      *  \return Written value is returned when called with valid parameter, otherwise 0xff is returned.\n
      *          Stored value is returned when called without parameter.\n
      */
@@ -139,9 +140,9 @@
 
     /**
      *  \brief Read/Write the ADC resolution parameter.\n
-     *  \param range\n
-     *         ISL29125_16BIT     ADC resolution = 16 bit.\n
-     *         ISL29125_12BIT     ADC resolution = 12 bit.\n
+     *  \param range
+     *         ISL29125_16BIT = 16 bit ADC resolution.\n
+     *         ISL29125_12BIT = 12 bit ADC resolution.\n
      *  \return Written value is returned when called with valid parameter, otherwise 0xff is returned.\n
      *          Stored value is returned when called without parameter.\n
      */
@@ -149,11 +150,11 @@
 
     /**
      *  \brief Read/Write the IRQ persistence parameter.\n
-     *  \param persist\n
-     *         ISL29125_PERS1     IRQ occurs when threshold is exceeded once.\n
-     *         ISL29125_PERS2     IRQ occurs when threshold is exceeded twice.\n
-     *         ISL29125_PERS4     IRQ occurs when threshold is exceeded 4 times.\n
-     *         ISL29125_PERS8     IRQ occurs when threshold is exceeded 8 times.\n
+     *  \param persist
+     *         ISL29125_PERS1 = IRQ occurs when threshold is exceeded once.\n
+     *         ISL29125_PERS2 = IRQ occurs when threshold is exceeded twice.\n
+     *         ISL29125_PERS4 = IRQ occurs when threshold is exceeded 4 times.\n
+     *         ISL29125_PERS8 = IRQ occurs when threshold is exceeded 8 times.\n
      *  \return Written value is returned when called with valid parameter, otherwise 0xff is returned.\n
      *          Stored value is returned when called without parameter.\n
      */
@@ -161,8 +162,8 @@
 
     /**
      *  \brief Read/Write the IRQ on conversion done parameter.\n
-     *  \param true: enabled.\n
-     *         false: disabled.\n
+     *  \param persist true (enabled).\n
+     *                 false (disabled).\n
      *  \return Written value is returned when called with valid parameter, otherwise 0xff is returned.\n
      *          Stored value is returned when called without parameter.\n
      */
@@ -170,10 +171,10 @@
 
     /**
      *  \brief Read/Write the IRQ threshold to color assignment parameter.\n
-     *  \param RGBmode  ISL29125_OFF   No interrupt.\n
-     *                  ISL29125_G     Green interrupt.\n
-     *                  ISL29125_R     Red interrupt.\n
-     *                  ISL29125_B     Blue interrupt.\n
+     *  \param RGBmode  ISL29125_OFF = No interrupt.\n
+     *                  ISL29125_G = Green interrupt.\n
+     *                  ISL29125_R = Red interrupt.\n
+     *                  ISL29125_B = Blue interrupt.\n
      *  \return Written value is returned when called with valid parameter, otherwise 0xff is returned.\n
      *          Stored value is returned when called without parameter.\n
      */