InetrfaceProducts NXP / PCA995xA

Dependencies:   CompLedDvrCC

Dependents:   PCA9956A_Hello pca9956b_two_demoboards PCA9955A_Gradation_control PCA9955A_Gradation_control ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PCA9956A.h Source File

PCA9956A.h

00001 /** PCA9956A constant current LED driver
00002  *
00003  *  An operation sample of PCA9956A 24-channel Fm+ I2C-bus 57mA/20V constant current LED driver.
00004  *  mbed accesses the PCA9956A registers through I2C.
00005  *
00006  *  @class   PCA9956A
00007  *  @author  Akifumi (Tedd) OKANO, NXP Semiconductors
00008  *  @version 0.6
00009  *  @date    19-Mar-2015 (minor fix on 17-Jun-2022)
00010  *
00011  *  Released under the Apache 2 license
00012  *
00013  *  About PCA9956A:
00014  *    http://www.nxp.com/products/interface_and_connectivity/i2c/i2c_led_display_control/PCA9956ATW.html
00015  */
00016 
00017 #ifndef     MBED_PCA9956A
00018 #define     MBED_PCA9956A
00019 
00020 #include    "mbed.h"
00021 #include    "PCA995xA.h"
00022 #include    "LedPwmOutCC.h"
00023 
00024 /** PCA9956A class
00025  *
00026  *  This is a driver code for the PCA9956A 24-channel Fm+ I2C-bus 57mA/20V constant current LED driver.
00027  *  This class provides interface for PCA9956A operation and accessing its registers.
00028  *  Detail information is available on next URL.
00029  *    http://www.nxp.com/products/interface_and_connectivity/i2c/i2c_led_display_control/PCA9956ATW.html
00030  *
00031  *  Next sample code shows operation based on low-level-API (operated by just device instane)
00032  *
00033  *  Example:
00034  *  @code
00035  *  //  PCA9956A operation sample using its device instance
00036  *  
00037  *  #include "mbed.h"
00038  *  #include "PCA9956A.h"
00039  *  
00040  *  PCA9956A    led_cntlr( p28, p27, 0x02 );    //  SDA, SCL, Slave_address(option)
00041  *  
00042  *  int main()
00043  *  {
00044  *      led_cntlr.current( ALLPORTS, 1.0 ); //  Set all ports output current 100%
00045  *      
00046  *      while(1) {
00047  *          for ( int port = 0; port < led_cntlr.number_of_ports(); port++ ) {
00048  *              for ( int i = 1; i <= 100; i++ ) {
00049  *                  led_cntlr.pwm(  port, (float)i / 100.0 );
00050  *                  wait( 0.01 );
00051  *              }
00052  *          }
00053  *          led_cntlr.pwm( ALLPORTS, 0.0 );
00054  *      }
00055  *  }
00056  *  @endcode
00057  *  
00058  *  The high-level-API:LedPwmOutCC is also available.
00059  *  It can be used like next sample code.
00060  *  
00061  *  @code
00062  *  //  PCA9956A operation sample using high-level-API
00063  *  
00064  *  #include "mbed.h"
00065  *  #include "PCA9956A.h"
00066  *  
00067  *  PCA9956A    led_cntlr( p28, p27, 0x02 );    //  SDA, SCL, Slave_address(option)
00068  *  LedPwmOutCC led0( led_cntlr, L0  );         //  Instance for LED0 pin
00069  *  LedPwmOutCC led1( led_cntlr, L1  );         //  Instance for LED1 pin
00070  *  LedPwmOutCC led2( led_cntlr, L2  );         //  Instance for LED2 pin
00071  *  
00072  *  int main()
00073  *  {
00074  *      led0.current( 0.5 );    //  LED0 pin current output setting to 50%
00075  *      led1.current( 0.5 );    //  LED1 pin current output setting to 50%
00076  *      led2.current( 0.5 );    //  LED2 pin current output setting to 50%
00077  *  
00078  *      while(1) {
00079  *          
00080  *          for ( float p = 1.0; p >= 0.0; p -= 0.01 ) {
00081  *              led0    = p;    //  Set LED0 output PWM dutycycle as 'p'
00082  *              wait( 0.01 );
00083  *          }
00084  *          
00085  *          for ( float p = 1.0; p >= 0.0; p -= 0.01 ) {
00086  *              led1    = p;    //  Set LED1 output PWM dutycycle as 'p'
00087  *              wait( 0.01 );
00088  *          }
00089  *          
00090  *          for ( float p = 1.0; p >= 0.0; p -= 0.01 ) {
00091  *              led2    = p;    //  Set LED2 output PWM dutycycle as 'p'
00092  *              wait( 0.01 );
00093  *          }
00094  *      }
00095  *  }
00096  *  @endcode
00097  */
00098 class PCA9956A : public PCA995xA
00099 {
00100 public:
00101 
00102 #if DOXYGEN_ONLY
00103     /** PCA9956A pin names high-level API i.e. LedPwmOutCC */
00104     typedef enum {
00105         L0,            /**< LED0  pin                              */
00106         L1,            /**< LED1  pin                              */
00107         L2,            /**< LED2  pin                              */
00108         L3,            /**< LED3  pin                              */
00109         L4,            /**< LED4  pin                              */
00110         L5,            /**< LED5  pin                              */
00111         L6,            /**< LED6  pin                              */
00112         L7,            /**< LED7  pin                              */
00113         L8,            /**< LED8  pin                              */
00114         L9,            /**< LED9  pin                              */
00115         L10,           /**< LED10 pin                              */
00116         L11,           /**< LED11 pin                              */
00117         L12,           /**< LED12 pin                              */
00118         L13,           /**< LED13 pin                              */
00119         L14,           /**< LED14 pin                              */
00120         L15,           /**< LED15 pin                              */
00121         L16,           /**< LED16 pin                              */
00122         L17,           /**< LED17 pin                              */
00123         L18,           /**< LED18 pin                              */
00124         L19,           /**< LED19 pin                              */
00125         L20,           /**< LED20 pin                              */
00126         L21,           /**< LED21 pin                              */
00127         L22,           /**< LED22 pin                              */
00128         L23,           /**< LED23 pin                              */
00129         L_NC = ~0x0L   /**< for when the pin is left no-connection */
00130     } LedPinName;
00131 #endif // DOXYGEN_ONLY
00132 
00133     /** Name of the PCA9956A registers (for direct register access) */
00134     enum command_reg {
00135         MODE1,          /**< MODE1 register      */
00136         MODE2,          /**< MODE2 register      */
00137         LEDOUT0,        /**< LEDOUT0 register    */
00138         LEDOUT1,        /**< LEDOUT1 register    */
00139         LEDOUT2,        /**< LEDOUT2 register    */
00140         LEDOUT3,        /**< LEDOUT3 register    */
00141         LEDOUT4,        /**< LEDOUT4 register    */
00142         LEDOUT5,        /**< LEDOUT5 register    */
00143         GRPPWM,         /**< GRPPWM register     */
00144         GRPFREQ,        /**< GRPFREQ register    */
00145         PWM0,           /**< PWM0 register       */
00146         PWM1,           /**< PWM1 register       */
00147         PWM2,           /**< PWM2 register       */
00148         PWM3,           /**< PWM3 register       */
00149         PWM4,           /**< PWM4 register       */
00150         PWM5,           /**< PWM5 register       */
00151         PWM6,           /**< PWM6 register       */
00152         PWM7,           /**< PWM7 register       */
00153         PWM8,           /**< PWM8 register       */
00154         PWM9,           /**< PWM9 register       */
00155         PWM10,          /**< PWM10 register      */
00156         PWM11,          /**< PWM11 register      */
00157         PWM12,          /**< PWM12 register      */
00158         PWM13,          /**< PWM13 register      */
00159         PWM14,          /**< PWM14 register      */
00160         PWM15,          /**< PWM15 register      */
00161         PWM16,          /**< PWM16 register      */
00162         PWM17,          /**< PWM17 register      */
00163         PWM18,          /**< PWM18 register      */
00164         PWM19,          /**< PWM19 register      */
00165         PWM20,          /**< PWM20 register      */
00166         PWM21,          /**< PWM21 register      */
00167         PWM22,          /**< PWM22 register      */
00168         PWM23,          /**< PWM23 register      */
00169         IREF0,          /**< IREF0 register      */
00170         IREF1,          /**< IREF1 register      */
00171         IREF2,          /**< IREF2 register      */
00172         IREF3,          /**< IREF3 register      */
00173         IREF4,          /**< IREF4 register      */
00174         IREF5,          /**< IREF5 register      */
00175         IREF6,          /**< IREF6 register      */
00176         IREF7,          /**< IREF7 register      */
00177         IREF8,          /**< IREF8 register      */
00178         IREF9,          /**< IREF9 register      */
00179         IREF10,         /**< IREF10 register     */
00180         IREF11,         /**< IREF11 register     */
00181         IREF12,         /**< IREF12 register     */
00182         IREF13,         /**< IREF13 register     */
00183         IREF14,         /**< IREF14 register     */
00184         IREF15,         /**< IREF15 register     */
00185         IREF16,         /**< IREF16 register     */
00186         IREF17,         /**< IREF17 register     */
00187         IREF18,         /**< IREF18 register     */
00188         IREF19,         /**< IREF19 register     */
00189         IREF20,         /**< IREF20 register     */
00190         IREF21,         /**< IREF21 register     */
00191         IREF22,         /**< IREF22 register     */
00192         IREF23,         /**< IREF23 register     */
00193         OFFSET  = 0x3A, /**< OFFSET register     */
00194         SUBADR1,        /**< SUBADR1 register    */
00195         SUBADR2,        /**< SUBADR2 register    */
00196         SUBADR3,        /**< SUBADR3 register    */
00197         ALLCALLADR,     /**< ALLCALLADR register */
00198         PWMALL,         /**< PWMALL register     */
00199         IREFALL,        /**< IREFALL register    */
00200         EFLAG0,         /**< EFLAG0 register     */
00201         EFLAG1,         /**< EFLAG1 register     */
00202         EFLAG2,         /**< EFLAG2 register     */
00203         EFLAG3,         /**< EFLAG3 register     */
00204         EFLAG4,         /**< EFLAG4 register     */
00205         EFLAG5,         /**< EFLAG5 register     */
00206 
00207         REGISTER_START          = MODE1,
00208         LEDOUT_REGISTER_START   = LEDOUT0,
00209         PWM_REGISTER_START      = PWM0,
00210         IREF_REGISTER_START     = IREF0,
00211     };
00212 
00213     /** Create a PCA9956A instance connected to specified I2C pins with specified address
00214      *
00215      * @param i2c_sda       I2C-bus SDA pin
00216      * @param i2c_sda       I2C-bus SCL pin
00217      * @param i2c_address   I2C-bus address (default: 0xC0)
00218      */
00219     PCA9956A( PinName i2c_sda, PinName i2c_scl, char i2c_address = PCA995xA::DEFAULT_I2C_ADDR );
00220 
00221     /** Create a PCA9956A instance connected to specified I2C pins with specified address
00222      *
00223      * @param i2c_obj       I2C object (instance)
00224      * @param i2c_address   I2C-bus address (default: 0xC0)
00225      */
00226     PCA9956A( I2C &i2c_obj, char i2c_address = PCA995xA::DEFAULT_I2C_ADDR );
00227 
00228     /** Destractor
00229      *
00230      */
00231     virtual         ~PCA9956A();
00232     
00233     /** Returns the number of output ports
00234      *
00235      *  @returns
00236      *    The number of output ports
00237      */
00238      virtual int     number_of_ports( void );
00239 
00240 #if DOXYGEN_ONLY
00241     /** Set the output duty-cycle, specified as a percentage (float)
00242      *
00243      * @param port  Selecting output port
00244      *    'ALLPORTS' can be used to set all port duty-cycle same value.
00245      * @param v     A floating-point value representing the output duty-cycle,
00246      *    specified as a percentage. The value should lie between
00247      *    0.0f (representing on 0%) and 1.0f (representing on 99.6%).
00248      *    Values outside this range will have undefined behavior.
00249      */
00250     void            pwm( int port, float v );
00251     
00252     /** Set all output port duty-cycle, specified as a percentage (array of float)
00253      *
00254      * @param vp    Aray to floating-point values representing the output duty-cycle,
00255      *    specified as a percentage. The value should lie between
00256      *    0.0f (representing on 0%) and 1.0f (representing on 99.6%).
00257      *
00258      *  @note
00259      *    The aray should have length of 24
00260      */
00261     void            pwm( float *vp );
00262     
00263     /** Set the output current, specified as a percentage (float)
00264      *
00265      * @param port  Selecting output port
00266      *    'ALLPORTS' can be used to set all port current same value.
00267      * @param v     A floating-point value representing the output current,
00268      *    specified as a percentage. The value should lie between
00269      *    0.0f (representing on 0%) and 1.0f (representing on 100%).
00270      *    Values outside this range will have undefined behavior.
00271      */    
00272     void            current( int port, float vp );
00273 
00274     /** Set all output port curent, specified as a percentage (array of float)
00275      *
00276      * @param vp    Aray to floating-point values representing the output current,
00277      *    specified as a percentage. The value should lie between
00278      *    0.0f (representing on 0%) and 1.0f (representing on 100%).
00279      *
00280      *  @note
00281      *    The aray should have length of 24
00282      */
00283     void            current( float *vP );
00284     
00285     /** Register write (single byte) : Low level access to device register
00286      *
00287      * @param reg_addr  Register address
00288      * @param data      Value for setting into the register
00289      */    
00290     void            write( char reg_addr, char data );
00291 
00292     /** Register write (multiple bytes) : Low level access to device register
00293      *
00294      * @param data      Pointer to an array. First 1 byte should be the writing start register address
00295      * @param length    Length of data
00296      */    
00297     void            write( char *data, int length );
00298 
00299     /** Register read (single byte) : Low level access to device register
00300      *
00301      * @param reg_addr  Register address
00302      * @return          Read value from register
00303      */    
00304     char            read( char reg_addr );
00305 
00306     /** Register write (multiple bytes) : Low level access to device register
00307      *
00308      * @param reg_addr  Register address
00309      * @param data      Pointer to an array. The values are stored in this array.
00310      * @param length    Length of data
00311      */    
00312     void            read( char reg_addr, char *data, int length );
00313 #endif
00314 
00315 private:
00316     void            initialize( void );
00317     virtual char    pwm_register_access( int port );
00318     virtual char    current_register_access( int port );
00319 
00320     const int       n_of_ports;
00321 }
00322 ;
00323 
00324 #endif  //  MBED_PCA9956A