InetrfaceProducts NXP / PCA962x

Dependencies:   CompLedDvr

Dependents:   PCA9626_Hello PCA9624_Hello PCA9622_Hello

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PCA9626.h Source File

PCA9626.h

00001 /** PCA9626 PWM control LED driver
00002  *
00003  *  An operation sample of PCA9626 24-channel Fm+ I2C-bus 100mA/40 V LED driver.
00004  *  mbed accesses the PCA9626 registers through I2C.
00005  *
00006  *  @class   PCA9626
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 PCA9626:
00014  *    http://www.nxp.com/products/lighting_driver_and_controller_ics/i2c_led_display_control/series/PCA9626.html
00015  */
00016 
00017 #ifndef     MBED_PCA9626
00018 #define     MBED_PCA9626
00019 
00020 #include    "mbed.h"
00021 #include    "PCA962x.h"
00022 #include    "CompLedDvrAPI.h"
00023 
00024 /** PCA9626 class
00025  *
00026  *  This is a driver code for the PCA9626 24-channel Fm+ I2C-bus 100mA/40V PWM control LED driver.
00027  *  This class provides interface for PCA9626 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/PCA9626.html
00030  *
00031  *  Next sample code shows operation based on low-level-API (operated by just device instane)
00032  *
00033  *  Example:
00034  *  @code
00035  *  //  PCA9626 operation sample using its device instance
00036  *  
00037  *  #include "mbed.h"
00038  *  #include "PCA9626.h"
00039  *
00040  *  PCA9626    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  *  //  PCA9626 operation sample using high-level-API
00061  *
00062  *  #include "mbed.h"
00063  *  #include "PCA9626.h"
00064  *
00065  *  PCA9626     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 PCA9626 : public PCA962x
00094 {
00095 public:
00096 
00097 #if DOXYGEN_ONLY
00098     /** PCA9626 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         L8,            /**< LED2 pin                               */
00109         L9,            /**< LED2 pin                               */
00110         L10,           /**< LED2 pin                               */
00111         L11,           /**< LED2 pin                               */
00112         L12,           /**< LED2 pin                               */
00113         L13,           /**< LED2 pin                               */
00114         L14,           /**< LED2 pin                               */
00115         L15,           /**< LED2 pin                               */
00116         L16,           /**< LED2 pin                               */
00117         L17,           /**< LED2 pin                               */
00118         L18,           /**< LED2 pin                               */
00119         L19,           /**< LED2 pin                               */
00120         L20,           /**< LED2 pin                               */
00121         L21,           /**< LED2 pin                               */
00122         L22,           /**< LED2 pin                               */
00123         L23,           /**< LED23 pin                               */
00124         L_NC = ~0x0L   /**< for when the pin is left no-connection */
00125     } LedPinName;
00126 #endif // DOXYGEN_ONLY
00127 
00128     /** Name of the PCA9626 registers (for direct register access) */
00129     enum command_reg {
00130         MODE1,      /**< MODE1 register      */
00131         MODE2,      /**< MODE2 register      */
00132         PWM0,       /**< PWM0 register       */
00133         PWM1,       /**< PWM1 register       */
00134         PWM2,       /**< PWM2 register       */
00135         PWM3,       /**< PWM3 register       */
00136         PWM4,       /**< PWM4 register       */
00137         PWM5,       /**< PWM5 register       */
00138         PWM6,       /**< PWM6 register       */
00139         PWM7,       /**< PWM7 register       */
00140         PWM8,       /**< PWM8 register       */
00141         PWM9,       /**< PWM9 register       */
00142         PWM10,      /**< PWM10 register      */
00143         PWM11,      /**< PWM11 register      */
00144         PWM12,      /**< PWM12 register      */
00145         PWM13,      /**< PWM13 register      */
00146         PWM14,      /**< PWM14 register      */
00147         PWM15,      /**< PWM15 register      */
00148         PWM16,      /**< PWM16 register      */
00149         PWM17,      /**< PWM17 register      */
00150         PWM18,      /**< PWM18 register      */
00151         PWM19,      /**< PWM19 register      */
00152         PWM20,      /**< PWM20 register      */
00153         PWM21,      /**< PWM21 register      */
00154         PWM22,      /**< PWM22 register      */
00155         PWM23,      /**< PWM23 register      */
00156         GRPPWM,     /**< GRPPWM register     */
00157         GRPFREQ,    /**< GRPFREQ register    */
00158         CHASE,      /**< CHASE register      */
00159         LEDOUT0,    /**< LEDOUT0 register    */
00160         LEDOUT1,    /**< LEDOUT1 register    */
00161         LEDOUT2,    /**< LEDOUT2 register    */
00162         LEDOUT3,    /**< LEDOUT3 register    */
00163         LEDOUT4,    /**< LEDOUT4 register    */
00164         LEDOUT5,    /**< LEDOUT5 register    */
00165         SUBADR1,    /**< SUBADR1 register    */
00166         SUBADR2,    /**< SUBADR2 register    */
00167         SUBADR3,    /**< SUBADR3 register    */
00168         ALLCALLADR, /**< ALLCALLADR register */
00169 
00170         REGISTER_START          = MODE1,
00171         LEDOUT_REGISTER_START   = LEDOUT0,
00172         PWM_REGISTER_START      = PWM0,
00173     };
00174 
00175     /** Create a PCA9626 instance connected to specified I2C pins with specified address
00176      *
00177      * @param i2c_sda       I2C-bus SDA pin
00178      * @param i2c_sda       I2C-bus SCL pin
00179      * @param i2c_address   I2C-bus address (default: 0xC0)
00180      */
00181     PCA9626( PinName i2c_sda, PinName i2c_scl, char i2c_address = PCA962x::DEFAULT_I2C_ADDR );
00182 
00183     /** Create a PCA9626 instance connected to specified I2C pins with specified address
00184      *
00185      * @param i2c_obj       I2C object (instance)
00186      * @param i2c_address   I2C-bus address (default: 0xC0)
00187      */
00188     PCA9626( I2C &i2c_obj, char i2c_address = PCA962x::DEFAULT_I2C_ADDR );
00189 
00190     /** Destractor
00191      *
00192      */
00193     virtual         ~PCA9626();
00194 
00195     /** Returns the number of output ports
00196      *
00197      *  @returns
00198      *    The number of output ports
00199      */
00200     virtual int     number_of_ports( void );
00201 
00202 #if DOXYGEN_ONLY
00203     /** Set the output duty-cycle, specified as a percentage (float)
00204      *
00205      * @param port  Selecting output port
00206      *    'ALLPORTS' can be used to set all port duty-cycle same value.
00207      * @param v     A floating-point value representing the output duty-cycle,
00208      *    specified as a percentage. The value should lie between
00209      *    0.0f (representing on 0%) and 1.0f (representing on 100%).
00210      *    Values outside this range will have undefined behavior.
00211      */
00212     void            pwm( int port, float v );
00213 
00214     /** Set all output port duty-cycle, specified as a percentage (array of float)
00215      *
00216      * @param vp    Aray to floating-point values representing the output duty-cycle,
00217      *    specified as a percentage. The value should lie between
00218      *    0.0f (representing on 0%) and 1.0f (representing on 100%).
00219      *
00220      *  @note
00221      *    The aray should have length of 24
00222      */
00223     void            pwm( float *vp );
00224 
00225     /** Register write (single byte) : Low level access to device register
00226      *
00227      * @param reg_addr  Register address
00228      * @param data      Value for setting into the register
00229      */
00230     void            write( char reg_addr, char data );
00231 
00232     /** Register write (multiple bytes) : Low level access to device register
00233      *
00234      * @param data      Pointer to an array. First 1 byte should be the writing start register address
00235      * @param length    Length of data
00236      */
00237     void            write( char *data, int length );
00238 
00239     /** Register read (single byte) : Low level access to device register
00240      *
00241      * @param reg_addr  Register address
00242      * @return          Read value from register
00243      */
00244     char            read( char reg_addr );
00245 
00246     /** Register write (multiple bytes) : Low level access to device register
00247      *
00248      * @param reg_addr  Register address
00249      * @param data      Pointer to an array. The values are stored in this array.
00250      * @param length    Length of data
00251      */
00252     void            read( char reg_addr, char *data, int length );
00253 #endif
00254 
00255 private:
00256     virtual void    initialize( void );
00257     virtual char    pwm_register_access( int port );
00258 
00259     const int       n_of_ports;
00260 }
00261 ;
00262 
00263 #endif  //  MBED_PCA9626