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, ....

Files at this revision

API Documentation at this revision

Comitter:
frankvnk
Date:
Wed May 28 19:19:06 2014 +0000
Parent:
1:1c1ded8d719e
Child:
3:400edaa74b7d
Commit message:
Doxygen update

Changed in this revision

ISL29125.h Show annotated file Show diff for this revision Revisions of this file
--- a/ISL29125.h	Wed May 28 18:44:54 2014 +0000
+++ b/ISL29125.h	Wed May 28 19:19:06 2014 +0000
@@ -46,146 +46,146 @@
 class ISL29125 {
 public:
     /**
-     *  \brief Create a ISL29125 object connected to I2C bus, irq or sync pin and user-ISR pointer.
-     *  \param sda       SDA pin.
-     *  \param scl       SCL pin.
-     *  \param irqsync   (Optional) Interrupt pin when fptr is also declared.
-     *                              Sync output when fptr is not declared.
-     *  \param fptr      (Optional) Pointer to user-ISR (only used with Interrupt pin).
-     *  \return none
+     *  \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 fptr      (Optional) Pointer to user-ISR (only used with Interrupt pin).\n
+     *  \return none\n
      */
     ISL29125(PinName sda, PinName scl, PinName irqsync = NC, void (*fptr)(void) = NULL);
 
     /**
-     *  \brief Read status register.
-     *         The interrupt status flag is cleared when the status register is read.
+     *  \brief Read status register.\n
+     *         The interrupt status flag is cleared when the status register is read.\n
      *  \param NONE
-     *  \return Content of the entire status register.
-     *          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
+     *  \return Content of the entire status register.\n
+     *          bit  Description\n
+     *          ---  ---------------------------------------------------------\n
+     *          5,4  RGB conversion     - 00: Inactive\n
+     *                                    01: Green\n
+     *                                    10: Red\n
+     *                                    11: Blue\n
+     *           2   Brownout status    - 0: No brownout\n
+     *                                    1: Power down or brownout occured \n
+     *           1   Conversion status  - 0: Conversion is pending or inactive\n
+     *                                    1: Conversion is completed\n
+     *           0   Interrupt status   - 0: no interrupt occured\n
+     *                                    1: interrupt occured\n
      */
     uint8_t Status(void);
 
     /**
-     *  \brief Read the device identifier.
-     *  \param none.
-     *  \return 0x7D on success.
+     *  \brief Read the device identifier.\n
+     *  \param none.\n
+     *  \return 0x7D on success.\n
      */
     uint8_t WhoAmI(void);
     
     /**
-     *  \brief Read the channel values (12 or 16-bit - depends on resolution).
-     *  \param color  ISL29125_R     Return Red channel.
-     *                ISL29125_G     Return Green channel.
-     *                ISL29125_B     Return Blue channel.
-     *                ISL29125_RGB   Return Red, Green and Blue channels. 
-     *  \param data   Pointer to 16-bit array for storing the channel value(s).
-     *  \             Array size: 1 for a single color (Red, Green or Blue).
-     *  \                         3 for all colors.
-     *  \return bool  1: new data available - 0: no new data available.
+     *  \brief Read the channel values (12 or 16-bit - depends on resolution).\n
+     *  \param color  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   Pointer to 16-bit array for storing the channel value(s).\n
+     *  \             Array size: 1 for a single color (Red, Green or Blue).\n
+     *  \                         3 for all colors.\n
+     *  \return bool  1: new data available - 0: no new data available.\n
      */
     bool Read(uint8_t color, uint16_t * data);
 
     /**
-     *  \brief Read/Write the low/high interrupt threshold value.
-     *         When setIRQonColor is activated, an interrupt will occur when the low or high threshold is exceeded.
-     *  \param reg    ISL29125_LTH_W     Write 16-bit low threshold.
-     *                ISL29125_HTH_W     Write 16-bit high threshold.
-     *                ISL29125_LTH_R     Read 16-bit low threshold.
-     *                ISL29125_HTH_R     Read 16-bit high threshold.
-     *  \param thres  16-bit threshold value (only needed when _W parameter is used).
-     *  \return Written threshold value when called with _W parameter.
-     *          Stored threshold value when called with _R parameter only.
+     *  \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    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
      */
     uint16_t Threshold(uint8_t reg, uint16_t thres=0);
 
     /**
-     *  \brief Read/Write the RGB operating mode value (active ADC channels).
-     *  \param mode   ISL29125_G      G channel only.
-     *                ISL29125_R      R channel only.
-     *                ISL29125_B      B channel only.
-     *                ISL29125_RG     R and G channel.
-     *                ISL29125_BG     B and G channel.
-     *                ISL29125_RGB    R, G and B channel.
-     *                ISL29125_STBY   Standby (No ADC conversion).
-     *                ISL29125_OFF    Power down ADC conversion.
-     *  \return Written value is returned when called with valid parameter, otherwise 0xff is returned.
-     *          Stored value is returned when called without parameter.
+     *  \brief Read/Write the RGB operating mode value (active ADC channels).\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
      */
     uint8_t RGBmode(uint8_t mode=0xff);
 
     /**
-     *  \brief Read/Write the sensing range parameter.
-     *  \param range  ISL29125_375LX     Max. value corresponds to 375 lux.
-     *                ISL29125_10KLX     Max. value corresponds to 10000 lux.
-     *  \return Written value is returned when called with valid parameter, otherwise 0xff is returned.
-     *          Stored value is returned when called without parameter.
+     *  \brief Read/Write the sensing range parameter.\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
      */
     uint8_t Range(uint8_t range=0xff);
 
     /**
-     *  \brief Read/Write the ADC resolution parameter.
-     *  \param range  ISL29125_16BIT     ADC resolution = 16 bit.
-     *                ISL29125_12BIT     ADC resolution = 12 bit.
-     *  \return Written value is returned when called with valid parameter, otherwise 0xff is returned.
-     *          Stored value is returned when called without parameter.
+     *  \brief Read/Write the ADC resolution parameter.\n
+     *  \param range  ISL29125_16BIT     ADC resolution = 16 bit.\n
+     *                ISL29125_12BIT     ADC resolution = 12 bit.\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
      */
     uint8_t Resolution(uint8_t resol=0xff);
 
     /**
-     *  \brief Read/Write the IRQ persistence parameter.
-     *  \param persist  ISL29125_PERS1     IRQ occurs when threshold is exceeded once.
-     *                  ISL29125_PERS2     IRQ occurs when threshold is exceeded twice.
-     *                  ISL29125_PERS4     IRQ occurs when threshold is exceeded 4 times.
-     *                  ISL29125_PERS8     IRQ occurs when threshold is exceeded 8 times.
-     *  \return Written value is returned when called with valid parameter, otherwise 0xff is returned.
-     *          Stored value is returned when called without parameter.
+     *  \brief Read/Write the IRQ persistence parameter.\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
      */
     uint8_t Persist(uint8_t persist=0xff);
 
     /**
-     *  \brief Read/Write the IRQ on conversion done parameter.
-     *  \param true: enabled.
-     *         false: disabled.
-     *  \return Written value is returned when called with valid parameter, otherwise 0xff is returned.
-     *          Stored value is returned when called without parameter.
+     *  \brief Read/Write the IRQ on conversion done parameter.\n
+     *  \param 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
      */
     uint8_t IRQonCnvDone(uint8_t irqen=0xff);
 
     /**
-     *  \brief Read/Write the IRQ threshold to color assignment parameter.
-     *  \param RGBmode  ISL29125_OFF   No interrupt.
-     *                  ISL29125_G     Green interrupt.
-     *                  ISL29125_R     Red interrupt.
-     *                  ISL29125_B     Blue interrupt.
-     *  \return Written value is returned when called with valid parameter, otherwise 0xff is returned.
-     *          Stored value is returned when called without parameter.
+     *  \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
+     *  \return Written value is returned when called with valid parameter, otherwise 0xff is returned.\n
+     *          Stored value is returned when called without parameter.\n
      */
     uint8_t IRQonColor(uint8_t RGBmode=0xff);
 
     /**
-     *  \brief Read/Write the active IR compensation parameter.
-     *  \param ircomp  valid range: between 0..63 or 128..191.
-     *  \return Written value is returned when called with valid parameter, otherwise 0xff is returned.
-     *          Stored value is returned when called without parameter.
+     *  \brief Read/Write the active IR compensation parameter.\n
+     *  \param ircomp  valid range: between 0..63 or 128..191.\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
      */
     uint8_t IRcomp(uint8_t ircomp=0xff);
 
     /**
-     *  \brief Start ADC conversion.
-     *         Only possible when SyncMode is activated.
-     *  \param None.
-     *  \return bool  1: success - 0: fail.
+     *  \brief Start ADC conversion.\n
+     *         Only possible when SyncMode is activated.\n
+     *  \param None.\n
+     *  \return bool  1: success - 0: fail.\n
      */
     bool Run(void);