This is a driver code for the PCA9632 is an I2C-bus controlled 4-bit LED driver optimized for Red/Green/Blue/Amber (RGBA) color mixing applications. In Individual brightness control mode, each LED output has its own 8-bit resolution (256 steps) fixed frequency Individual PWM controller that operates at 1.5625 kHz with a duty cycle that is adjustable from 0 % to 99.6 % to allow the LED to be set to a specific brightness value. This library including device class and "LedPwmOut class API" for ease of use.

Dependencies:   CompLedDvr

Dependents:   PCA9632_Hello

Please refer to the component page for details

The PCA9632 is an I²C-bus controlled 4-bit LED driver optimized for Red/Green/Blue/Amber (RGBA) color mixing applications.

High-level API is available

A high-level API that can be used as the "PwmOut" of bed-SDK is available.
This API enables to make instances of each LED output pins and control PWM duty cycle by assignment.
For detail information, refer API document of LedPwmOut Class class which is included in PCA962xA class library.

#include "mbed.h"
#include "PCA9632.h"

PCA9632     led_cntlr( p28, p27, 0xC4 );  //  SDA, SCL, Slave_address(option)
LedPwmOut   led( led_cntlr, L0 );

int main()
{
    while( 1 ) {
        for( float p = 0.0f; p < 1.0f; p += 0.1f ) {
            led     = p;
            wait( 0.1 );
        }
    }
}
Committer:
nxp_ip
Date:
Thu Mar 19 10:34:33 2015 +0000
Revision:
2:3574bf73abf5
Parent:
0:da1fe3fe7093
API document update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxp_ip 0:da1fe3fe7093 1 /** PCA9632 PWM control LED driver
nxp_ip 0:da1fe3fe7093 2 *
nxp_ip 0:da1fe3fe7093 3 * An operation sample of PCA9632 16-channel Fm+ I2C-bus 100mA/40V LED driver.
nxp_ip 0:da1fe3fe7093 4 * mbed accesses the PCA9632 registers through I2C.
nxp_ip 0:da1fe3fe7093 5 *
nxp_ip 0:da1fe3fe7093 6 * @author Akifumi (Tedd) OKANO, NXP Semiconductors
nxp_ip 0:da1fe3fe7093 7 * @version 0.5
nxp_ip 0:da1fe3fe7093 8 * @date 4-Mar-2015
nxp_ip 0:da1fe3fe7093 9 *
nxp_ip 0:da1fe3fe7093 10 * Released under the Apache 2 license
nxp_ip 0:da1fe3fe7093 11 *
nxp_ip 0:da1fe3fe7093 12 * About PCA9632:
nxp_ip 0:da1fe3fe7093 13 * http://www.nxp.com/products/lighting_driver_and_controller_ics/i2c_led_display_control/series/PCA9632.html
nxp_ip 0:da1fe3fe7093 14 */
nxp_ip 0:da1fe3fe7093 15
nxp_ip 0:da1fe3fe7093 16 #ifndef MBED_PCA9632
nxp_ip 0:da1fe3fe7093 17 #define MBED_PCA9632
nxp_ip 0:da1fe3fe7093 18
nxp_ip 0:da1fe3fe7093 19 #include "mbed.h"
nxp_ip 0:da1fe3fe7093 20 #include "CompLedDvr.h"
nxp_ip 0:da1fe3fe7093 21 #include "LedPwmOut.h"
nxp_ip 0:da1fe3fe7093 22
nxp_ip 0:da1fe3fe7093 23 #define ALLPORTS 0xFF
nxp_ip 0:da1fe3fe7093 24
nxp_ip 0:da1fe3fe7093 25
nxp_ip 0:da1fe3fe7093 26 /** PCA9632 class
nxp_ip 0:da1fe3fe7093 27 *
nxp_ip 0:da1fe3fe7093 28 * @class PCA9632
nxp_ip 0:da1fe3fe7093 29 *
nxp_ip 2:3574bf73abf5 30 * This is a driver code for the PCA9632 is an I2C-bus controlled 4-bit LED driver
nxp_ip 2:3574bf73abf5 31 * optimized for Red/Green/Blue/Amber (RGBA) color mixing applications. In Individual
nxp_ip 2:3574bf73abf5 32 * brightness control mode, each LED output has its own 8-bit resolution (256 steps)
nxp_ip 2:3574bf73abf5 33 * fixed frequency Individual PWM controller that operates at 1.5625 kHz with a duty
nxp_ip 2:3574bf73abf5 34 * cycle that is adjustable from 0 % to 99.6 % to allow the LED to be set to a specific
nxp_ip 0:da1fe3fe7093 35 * brightness value.
nxp_ip 0:da1fe3fe7093 36 * This class provides interface for PCA9632 operation and accessing its registers.
nxp_ip 0:da1fe3fe7093 37 * Detail information is available on next URL.
nxp_ip 0:da1fe3fe7093 38 * http://www.jp.nxp.com/products/interface_and_connectivity/i2c/i2c_led_display_control/series/PCA9632.html
nxp_ip 0:da1fe3fe7093 39 *
nxp_ip 0:da1fe3fe7093 40 * Example:
nxp_ip 0:da1fe3fe7093 41 * @code
nxp_ip 0:da1fe3fe7093 42 * #include "mbed.h"
nxp_ip 0:da1fe3fe7093 43 * #include "PCA9632.h"
nxp_ip 2:3574bf73abf5 44 *
nxp_ip 0:da1fe3fe7093 45 * PCA9632 led_cntlr( p28, p27, 0xC4 ); // SDA, SCL, Slave_address(option)
nxp_ip 0:da1fe3fe7093 46 * LedPwmOut led( led_cntlr, L0 ); // for LED0 pin
nxp_ip 2:3574bf73abf5 47 *
nxp_ip 0:da1fe3fe7093 48 * int main()
nxp_ip 0:da1fe3fe7093 49 * {
nxp_ip 0:da1fe3fe7093 50 * //
nxp_ip 0:da1fe3fe7093 51 * // Here are two types of PWM control samples
nxp_ip 0:da1fe3fe7093 52 * // (User can choose one of those interface to set the PWM.)
nxp_ip 0:da1fe3fe7093 53 * //
nxp_ip 0:da1fe3fe7093 54 * // 1st sample is using LedPwmOut API.
nxp_ip 0:da1fe3fe7093 55 * // It provides similar interface like PwmOut of mbed-SDK
nxp_ip 0:da1fe3fe7093 56 * //
nxp_ip 0:da1fe3fe7093 57 * // 2nd sample is using PCA9632 class function.
nxp_ip 0:da1fe3fe7093 58 * // the 'pwm()' function takes LED channel number and duty-ratio value
nxp_ip 0:da1fe3fe7093 59 * //
nxp_ip 2:3574bf73abf5 60 *
nxp_ip 0:da1fe3fe7093 61 * while ( 1 ) {
nxp_ip 2:3574bf73abf5 62 *
nxp_ip 0:da1fe3fe7093 63 * //
nxp_ip 0:da1fe3fe7093 64 * // 1st sample is using LedPwmOut API.
nxp_ip 0:da1fe3fe7093 65 * // PWM control via LedPwmOut
nxp_ip 0:da1fe3fe7093 66 * //
nxp_ip 0:da1fe3fe7093 67 * for ( int i = 0; i < 3; i++ ) {
nxp_ip 0:da1fe3fe7093 68 * for( float p = 0.0f; p < 1.0f; p += 0.1f ) {
nxp_ip 0:da1fe3fe7093 69 * led = p; // Controls LED0 pin
nxp_ip 0:da1fe3fe7093 70 * wait( 0.1 );
nxp_ip 0:da1fe3fe7093 71 * }
nxp_ip 0:da1fe3fe7093 72 * }
nxp_ip 2:3574bf73abf5 73 *
nxp_ip 0:da1fe3fe7093 74 * //
nxp_ip 0:da1fe3fe7093 75 * // 2nd sample is using PCA9632 class function.
nxp_ip 0:da1fe3fe7093 76 * // PWM control by device class function call
nxp_ip 0:da1fe3fe7093 77 * //
nxp_ip 0:da1fe3fe7093 78 * for ( int i = 0; i < 3; i++ ) {
nxp_ip 0:da1fe3fe7093 79 * for( float p = 0.0f; p < 1.0f; p += 0.1f ) {
nxp_ip 0:da1fe3fe7093 80 * led_cntlr.pwm( 1, p ); // Controls LED1 pin
nxp_ip 0:da1fe3fe7093 81 * wait( 0.1 );
nxp_ip 0:da1fe3fe7093 82 * }
nxp_ip 0:da1fe3fe7093 83 * }
nxp_ip 0:da1fe3fe7093 84 * }
nxp_ip 0:da1fe3fe7093 85 * }
nxp_ip 0:da1fe3fe7093 86 * @endcode
nxp_ip 0:da1fe3fe7093 87 */
nxp_ip 0:da1fe3fe7093 88 class PCA9632 : public CompLedDvr
nxp_ip 0:da1fe3fe7093 89 {
nxp_ip 0:da1fe3fe7093 90 public:
nxp_ip 0:da1fe3fe7093 91
nxp_ip 2:3574bf73abf5 92 #if DOXYGEN_ONLY
nxp_ip 2:3574bf73abf5 93 /** PCA9626 pin names high-level API i.e. LedPwmOut */
nxp_ip 2:3574bf73abf5 94 typedef enum {
nxp_ip 2:3574bf73abf5 95 L0, /**< LED0 pin */
nxp_ip 2:3574bf73abf5 96 L1, /**< LED2 pin */
nxp_ip 2:3574bf73abf5 97 L2, /**< LED2 pin */
nxp_ip 2:3574bf73abf5 98 L3, /**< LED2 pin */
nxp_ip 2:3574bf73abf5 99 L_NC = ~0x0L /**< for when the pin is left no-connection */
nxp_ip 2:3574bf73abf5 100 } LedPinName;
nxp_ip 2:3574bf73abf5 101 #endif // DOXYGEN_ONLY
nxp_ip 2:3574bf73abf5 102
nxp_ip 2:3574bf73abf5 103 /** Name of the PCA9632 registers (for direct register access) */
nxp_ip 0:da1fe3fe7093 104 enum command_reg {
nxp_ip 2:3574bf73abf5 105 MODE1, /**< MODE1 register */
nxp_ip 2:3574bf73abf5 106 MODE2, /**< MODE2 register */
nxp_ip 2:3574bf73abf5 107 PWM0, /**< PWM0 register */
nxp_ip 2:3574bf73abf5 108 PWM1, /**< PWM1 register */
nxp_ip 2:3574bf73abf5 109 PWM2, /**< PWM2 register */
nxp_ip 2:3574bf73abf5 110 PWM3, /**< PWM3 register */
nxp_ip 2:3574bf73abf5 111 GRPPWM, /**< GRPPWM register */
nxp_ip 2:3574bf73abf5 112 GRPFREQ, /**< GRPFREQ register */
nxp_ip 2:3574bf73abf5 113 LEDOUT, /**< LEDOUT register */
nxp_ip 2:3574bf73abf5 114 SUBADR1, /**< SUBADR1 register */
nxp_ip 2:3574bf73abf5 115 SUBADR2, /**< SUBADR2 register */
nxp_ip 2:3574bf73abf5 116 SUBADR3, /**< SUBADR3 register */
nxp_ip 2:3574bf73abf5 117 ALLCALLADR, /**< ALLCALLADR register */
nxp_ip 0:da1fe3fe7093 118
nxp_ip 0:da1fe3fe7093 119 REGISTER_START = MODE1,
nxp_ip 0:da1fe3fe7093 120 PWM_REGISTER_START = PWM0,
nxp_ip 0:da1fe3fe7093 121 };
nxp_ip 0:da1fe3fe7093 122
nxp_ip 0:da1fe3fe7093 123 /** Difinition of the number of LED pins */
nxp_ip 0:da1fe3fe7093 124 enum {
nxp_ip 0:da1fe3fe7093 125 N_OF_PORTS = 4
nxp_ip 0:da1fe3fe7093 126 };
nxp_ip 0:da1fe3fe7093 127
nxp_ip 0:da1fe3fe7093 128 /** Create a PCA9632 instance connected to specified I2C pins with specified address
nxp_ip 0:da1fe3fe7093 129 *
nxp_ip 0:da1fe3fe7093 130 * @param i2c_sda I2C-bus SDA pin
nxp_ip 0:da1fe3fe7093 131 * @param i2c_sda I2C-bus SCL pin
nxp_ip 0:da1fe3fe7093 132 * @param i2c_address I2C-bus address (default: 0xC4)
nxp_ip 0:da1fe3fe7093 133 */
nxp_ip 0:da1fe3fe7093 134 PCA9632( PinName i2c_sda, PinName i2c_scl, char i2c_address = DEFAULT_I2C_ADDR );
nxp_ip 0:da1fe3fe7093 135
nxp_ip 0:da1fe3fe7093 136 /** Create a PCA9632 instance connected to specified I2C pins with specified address
nxp_ip 0:da1fe3fe7093 137 *
nxp_ip 0:da1fe3fe7093 138 * @param i2c_obj I2C object (instance)
nxp_ip 0:da1fe3fe7093 139 * @param i2c_address I2C-bus address (default: 0xC4)
nxp_ip 0:da1fe3fe7093 140 */
nxp_ip 0:da1fe3fe7093 141 PCA9632( I2C &i2c_obj, char i2c_address = DEFAULT_I2C_ADDR );
nxp_ip 0:da1fe3fe7093 142
nxp_ip 0:da1fe3fe7093 143 /** Destractor
nxp_ip 0:da1fe3fe7093 144 */
nxp_ip 0:da1fe3fe7093 145 virtual ~PCA9632();
nxp_ip 0:da1fe3fe7093 146
nxp_ip 0:da1fe3fe7093 147 /** Performs Software reset via I2C bus
nxp_ip 0:da1fe3fe7093 148 */
nxp_ip 0:da1fe3fe7093 149 void reset( void );
nxp_ip 0:da1fe3fe7093 150
nxp_ip 0:da1fe3fe7093 151 /** Set the output duty-cycle, specified as a percentage (float)
nxp_ip 0:da1fe3fe7093 152 *
nxp_ip 0:da1fe3fe7093 153 * @param port Selecting output port
nxp_ip 0:da1fe3fe7093 154 * 'ALLPORTS' can be used to set all port duty-cycle same value.
nxp_ip 0:da1fe3fe7093 155 * @param v A floating-point value representing the output duty-cycle,
nxp_ip 0:da1fe3fe7093 156 * specified as a percentage. The value should lie between
nxp_ip 0:da1fe3fe7093 157 * 0.0f (representing on 0%) and 1.0f (representing on 99.6%).
nxp_ip 0:da1fe3fe7093 158 * Values outside this range will have undefined behavior.
nxp_ip 0:da1fe3fe7093 159 */
nxp_ip 0:da1fe3fe7093 160 virtual void pwm( int port, float v );
nxp_ip 0:da1fe3fe7093 161
nxp_ip 0:da1fe3fe7093 162 /** Set all output port duty-cycle, specified as a percentage (array of float)
nxp_ip 0:da1fe3fe7093 163 *
nxp_ip 0:da1fe3fe7093 164 * @param vp Aray to floating-point values representing the output duty-cycle,
nxp_ip 0:da1fe3fe7093 165 * specified as a percentage. The value should lie between
nxp_ip 0:da1fe3fe7093 166 * 0.0f (representing on 0%) and 1.0f (representing on 99.6%).
nxp_ip 0:da1fe3fe7093 167 *
nxp_ip 0:da1fe3fe7093 168 * @note
nxp_ip 0:da1fe3fe7093 169 * The aray should have length of 4
nxp_ip 0:da1fe3fe7093 170 */
nxp_ip 0:da1fe3fe7093 171 void pwm( float *vp );
nxp_ip 0:da1fe3fe7093 172
nxp_ip 0:da1fe3fe7093 173 /** Register write (single byte) : Low level access to device register
nxp_ip 0:da1fe3fe7093 174 *
nxp_ip 0:da1fe3fe7093 175 * @param reg_addr Register address
nxp_ip 0:da1fe3fe7093 176 * @param data Value for setting into the register
nxp_ip 2:3574bf73abf5 177 */
nxp_ip 0:da1fe3fe7093 178 void write( char reg_addr, char data );
nxp_ip 0:da1fe3fe7093 179
nxp_ip 0:da1fe3fe7093 180 /** Register write (multiple bytes) : Low level access to device register
nxp_ip 0:da1fe3fe7093 181 *
nxp_ip 0:da1fe3fe7093 182 * @param data Pointer to an array. First 1 byte should be the writing start register address
nxp_ip 0:da1fe3fe7093 183 * @param length Length of data
nxp_ip 2:3574bf73abf5 184 */
nxp_ip 0:da1fe3fe7093 185 void write( char *data, int length );
nxp_ip 2:3574bf73abf5 186
nxp_ip 0:da1fe3fe7093 187 /** Register read (single byte) : Low level access to device register
nxp_ip 0:da1fe3fe7093 188 *
nxp_ip 0:da1fe3fe7093 189 * @param reg_addr Register address
nxp_ip 0:da1fe3fe7093 190 * @return Read value from register
nxp_ip 2:3574bf73abf5 191 */
nxp_ip 0:da1fe3fe7093 192 char read( char reg_addr );
nxp_ip 2:3574bf73abf5 193
nxp_ip 0:da1fe3fe7093 194 /** Register write (multiple bytes) : Low level access to device register
nxp_ip 0:da1fe3fe7093 195 *
nxp_ip 0:da1fe3fe7093 196 * @param reg_addr Register address
nxp_ip 0:da1fe3fe7093 197 * @param data Pointer to an array. The values are stored in this array.
nxp_ip 0:da1fe3fe7093 198 * @param length Length of data
nxp_ip 2:3574bf73abf5 199 */
nxp_ip 0:da1fe3fe7093 200
nxp_ip 0:da1fe3fe7093 201 void read( char reg_addr, char *data, int length );
nxp_ip 0:da1fe3fe7093 202
nxp_ip 0:da1fe3fe7093 203 protected:
nxp_ip 0:da1fe3fe7093 204 enum {
nxp_ip 0:da1fe3fe7093 205 DEFAULT_I2C_ADDR = 0xC4,
nxp_ip 0:da1fe3fe7093 206 AUTO_INCREMENT = 0x80,
nxp_ip 0:da1fe3fe7093 207 PWMALL = 0xFF
nxp_ip 0:da1fe3fe7093 208 };
nxp_ip 0:da1fe3fe7093 209
nxp_ip 0:da1fe3fe7093 210 private:
nxp_ip 0:da1fe3fe7093 211 void initialize( void );
nxp_ip 0:da1fe3fe7093 212
nxp_ip 0:da1fe3fe7093 213 I2C *i2c_p;
nxp_ip 0:da1fe3fe7093 214 I2C &i2c;
nxp_ip 0:da1fe3fe7093 215 char address; // I2C slave address
nxp_ip 0:da1fe3fe7093 216 }
nxp_ip 0:da1fe3fe7093 217 ;
nxp_ip 0:da1fe3fe7093 218
nxp_ip 0:da1fe3fe7093 219 #endif // MBED_PCA9632