InetrfaceProducts NXP / PCA962x

Dependencies:   CompLedDvr

Dependents:   PCA9626_Hello PCA9624_Hello PCA9622_Hello

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PCA9624.h Source File

PCA9624.h

00001 /** PCA9624 PWM control LED driver
00002  *
00003  *  An operation sample of PCA9624 8-channel Fm+ I2C-bus 100mA/40V LED driver.
00004  *  mbed accesses the PCA9624 registers through I2C.
00005  *
00006  *  @class   PCA9624
00007  *  @author  Akifumi (Tedd) OKANO, NXP Semiconductors
00008  *  @version 0.6
00009  *  @date    04-Mar-2015
00010  *
00011  *  Released under the Apache 2 license License
00012  *
00013  *  About PCA9624:
00014  *    http://www.nxp.com/products/lighting_driver_and_controller_ics/i2c_led_display_control/series/PCA9624.html
00015  */
00016 
00017 #ifndef     MBED_PCA9624
00018 #define     MBED_PCA9624
00019 
00020 #include    "mbed.h"
00021 #include    "PCA962x.h"
00022 #include    "CompLedDvrAPI.h"
00023 
00024 /** PCA9624 class
00025  *
00026  *  This is a driver code for the PCA9624 8-channel Fm+ I2C-bus 100mA/40V PWM control LED driver.
00027  *  This class provides interface for PCA9624 operation and accessing its registers.
00028  *  Detail information is available on next URL.
00029  *    http://www.nxp.com/products/lighting_driver_and_controller_ics/i2c_led_display_control/series/PCA9624.html
00030  *
00031  *  Next sample code shows operation based on low-level-API (operated by just device instane)
00032  *
00033  *  Example:
00034  *  @code
00035  *  //  PCA9624 operation sample using its device instance
00036  *  
00037  *  #include "mbed.h"
00038  *  #include "PCA9624.h"
00039  *  
00040  *  PCA9624    led_cntlr( p28, p27, 0x3E );    //  SDA, SCL, Slave_address(option)
00041  *  
00042  *  int main()
00043  *  {
00044  *      while(1) {
00045  *          for ( int port = 0; port < led_cntlr.number_of_ports(); port++ ) {
00046  *              for ( int i = 1; i <= 100; i++ ) {
00047  *                  led_cntlr.pwm(  port, (float)i / 100.0 );
00048  *                  wait( 0.01 );
00049  *              }
00050  *          }
00051  *          led_cntlr.pwm( ALLPORTS, 0.0 );
00052  *      }
00053  *  }
00054  *  @endcode
00055  *  
00056  *  The high-level-API:LedPwmOutCC is also available.
00057  *  It can be used like next sample code.
00058  *  
00059  *  @code
00060  *  //  PCA9624 operation sample using high-level-API
00061  *
00062  *  #include "mbed.h"
00063  *  #include "PCA9624.h"
00064  *
00065  *  PCA9624     led_cntlr( p28, p27, 0x3E );    //  SDA, SCL, Slave_address(option)
00066  *  LedPwmOut   led0( led_cntlr, L0  );         //  Instance for LED0 pin
00067  *  LedPwmOut   led1( led_cntlr, L1  );         //  Instance for LED1 pin
00068  *  LedPwmOut   led2( led_cntlr, L2  );         //  Instance for LED2 pin
00069  *
00070  *  int main()
00071  *  {
00072  *      while(1) {
00073  *
00074  *          for ( float p = 1.0; p >= 0.0; p -= 0.01 ) {
00075  *              led0    = p;    //  Set LED0 output PWM dutycycle as 'p'
00076  *              wait( 0.01 );
00077  *          }
00078  *
00079  *          for ( float p = 1.0; p >= 0.0; p -= 0.01 ) {
00080  *              led1    = p;    //  Set LED1 output PWM dutycycle as 'p'
00081  *              wait( 0.01 );
00082  *          }
00083  *
00084  *          for ( float p = 1.0; p >= 0.0; p -= 0.01 ) {
00085  *              led2    = p;    //  Set LED2 output PWM dutycycle as 'p'
00086  *              wait( 0.01 );
00087  *          }
00088  *      }
00089  *  }
00090  *  @endcode
00091  */
00092 
00093 class PCA9624 : public PCA962x
00094 {
00095 public:
00096 
00097 #if DOXYGEN_ONLY
00098     /** PCA9624 pin names high-level API i.e. LedPwmOut */
00099     typedef enum {
00100         L0,            /**< LED0 pin                               */
00101         L1,            /**< LED2 pin                               */
00102         L2,            /**< LED2 pin                               */
00103         L3,            /**< LED2 pin                               */
00104         L4,            /**< LED2 pin                               */
00105         L5,            /**< LED2 pin                               */
00106         L6,            /**< LED2 pin                               */
00107         L7,            /**< LED2 pin                               */
00108         L_NC = ~0x0L   /**< for when the pin is left no-connection */
00109     } LedPinName;
00110 #endif // DOXYGEN_ONLY
00111 
00112     /** Name of the PCA9624 registers (for direct register access) */
00113     enum command_reg {
00114         MODE1,      /**< MODE1 register      */
00115         MODE2,      /**< MODE2 register      */
00116         PWM0,       /**< PWM0 register       */
00117         PWM1,       /**< PWM1 register       */
00118         PWM2,       /**< PWM2 register       */
00119         PWM3,       /**< PWM3 register       */
00120         PWM4,       /**< PWM4 register       */
00121         PWM5,       /**< PWM5 register       */
00122         PWM6,       /**< PWM6 register       */
00123         PWM7,       /**< PWM7 register       */
00124         GRPPWM,     /**< GRPPWM register     */
00125         GRPFREQ,    /**< GRPFREQ register    */
00126         LEDOUT0,    /**< LEDOUT0 register    */
00127         LEDOUT1,    /**< LEDOUT1 register    */
00128         SUBADR1,    /**< SUBADR1 register    */
00129         SUBADR2,    /**< SUBADR2 register    */
00130         SUBADR3,    /**< SUBADR3 register    */
00131         ALLCALLADR, /**< ALLCALLADR register */
00132 
00133 
00134         REGISTER_START          = MODE1,
00135         LEDOUT_REGISTER_START   = LEDOUT0,
00136         PWM_REGISTER_START      = PWM0,
00137     };
00138 
00139     /** Create a PCA9626 instance connected to specified I2C pins with specified address
00140      *
00141      * @param i2c_sda       I2C-bus SDA pin
00142      * @param i2c_sda       I2C-bus SCL pin
00143      * @param i2c_address   I2C-bus address (default: 0xC0)
00144      */
00145     PCA9624( PinName i2c_sda, PinName i2c_scl, char i2c_address = PCA962x::DEFAULT_I2C_ADDR );
00146 
00147     /** Create a PCA9626 instance connected to specified I2C pins with specified address
00148      *
00149      * @param i2c_obj       I2C object (instance)
00150      * @param i2c_address   I2C-bus address (default: 0xC0)
00151      */
00152     PCA9624( I2C &i2c_obj, char i2c_address = PCA962x::DEFAULT_I2C_ADDR );
00153 
00154     /** Destractor
00155      *
00156      */
00157     virtual         ~PCA9624();
00158     
00159     /** Returns the number of output ports
00160      *
00161      *  @returns
00162      *    The number of output ports
00163      */
00164      virtual int     number_of_ports( void );
00165 
00166 #if DOXYGEN_ONLY
00167     /** Set the output duty-cycle, specified as a percentage (float)
00168      *
00169      * @param port  Selecting output port
00170      *    'ALLPORTS' can be used to set all port duty-cycle same value.
00171      * @param v     A floating-point value representing the output duty-cycle,
00172      *    specified as a percentage. The value should lie between
00173      *    0.0f (representing on 0%) and 1.0f (representing on 100%).
00174      *    Values outside this range will have undefined behavior.
00175      */
00176     void            pwm( int port, float v );
00177     
00178     /** Set all output port duty-cycle, specified as a percentage (array of float)
00179      *
00180      * @param vp    Aray to floating-point values representing the output duty-cycle,
00181      *    specified as a percentage. The value should lie between
00182      *    0.0f (representing on 0%) and 1.0f (representing on 100%).
00183      *
00184      *  @note
00185      *    The aray should have length of 8
00186      */
00187     void            pwm( float *vp );
00188     
00189     /** Register write (single byte) : Low level access to device register
00190      *
00191      * @param reg_addr  Register address
00192      * @param data      Value for setting into the register
00193      */    
00194     void            write( char reg_addr, char data );
00195 
00196     /** Register write (multiple bytes) : Low level access to device register
00197      *
00198      * @param data      Pointer to an array. First 1 byte should be the writing start register address
00199      * @param length    Length of data
00200      */    
00201     void            write( char *data, int length );
00202 
00203     /** Register read (single byte) : Low level access to device register
00204      *
00205      * @param reg_addr  Register address
00206      * @return          Read value from register
00207      */    
00208     char            read( char reg_addr );
00209 
00210     /** Register write (multiple bytes) : Low level access to device register
00211      *
00212      * @param reg_addr  Register address
00213      * @param data      Pointer to an array. The values are stored in this array.
00214      * @param length    Length of data
00215      */    
00216     void            read( char reg_addr, char *data, int length );
00217 #endif
00218 
00219 private:
00220     virtual void    initialize( void );
00221     virtual char    pwm_register_access( int port );
00222 
00223     const int       n_of_ports;
00224 }
00225 ;
00226 
00227 #endif  //  MBED_PCA9624