Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PCA9632.h
00001 /** PCA9632 PWM control LED driver 00002 * 00003 * An operation sample of PCA9632 16-channel Fm+ I2C-bus 100mA/40V LED driver. 00004 * mbed accesses the PCA9632 registers through I2C. 00005 * 00006 * @author Akifumi (Tedd) OKANO, NXP Semiconductors 00007 * @version 0.5 00008 * @date 4-Mar-2015 00009 * 00010 * Released under the Apache 2 license 00011 * 00012 * About PCA9632: 00013 * http://www.nxp.com/products/lighting_driver_and_controller_ics/i2c_led_display_control/series/PCA9632.html 00014 */ 00015 00016 #ifndef MBED_PCA9632 00017 #define MBED_PCA9632 00018 00019 #include "mbed.h" 00020 #include "CompLedDvr.h" 00021 #include "LedPwmOut.h" 00022 00023 #define ALLPORTS 0xFF 00024 00025 00026 /** PCA9632 class 00027 * 00028 * @class PCA9632 00029 * 00030 * This is a driver code for the PCA9632 is an I2C-bus controlled 4-bit LED driver 00031 * optimized for Red/Green/Blue/Amber (RGBA) color mixing applications. In Individual 00032 * brightness control mode, each LED output has its own 8-bit resolution (256 steps) 00033 * fixed frequency Individual PWM controller that operates at 1.5625 kHz with a duty 00034 * cycle that is adjustable from 0 % to 99.6 % to allow the LED to be set to a specific 00035 * brightness value. 00036 * This class provides interface for PCA9632 operation and accessing its registers. 00037 * Detail information is available on next URL. 00038 * http://www.jp.nxp.com/products/interface_and_connectivity/i2c/i2c_led_display_control/series/PCA9632.html 00039 * 00040 * Example: 00041 * @code 00042 * #include "mbed.h" 00043 * #include "PCA9632.h" 00044 * 00045 * PCA9632 led_cntlr( p28, p27, 0xC4 ); // SDA, SCL, Slave_address(option) 00046 * LedPwmOut led( led_cntlr, L0 ); // for LED0 pin 00047 * 00048 * int main() 00049 * { 00050 * // 00051 * // Here are two types of PWM control samples 00052 * // (User can choose one of those interface to set the PWM.) 00053 * // 00054 * // 1st sample is using LedPwmOut API. 00055 * // It provides similar interface like PwmOut of mbed-SDK 00056 * // 00057 * // 2nd sample is using PCA9632 class function. 00058 * // the 'pwm()' function takes LED channel number and duty-ratio value 00059 * // 00060 * 00061 * while ( 1 ) { 00062 * 00063 * // 00064 * // 1st sample is using LedPwmOut API. 00065 * // PWM control via LedPwmOut 00066 * // 00067 * for ( int i = 0; i < 3; i++ ) { 00068 * for( float p = 0.0f; p < 1.0f; p += 0.1f ) { 00069 * led = p; // Controls LED0 pin 00070 * wait( 0.1 ); 00071 * } 00072 * } 00073 * 00074 * // 00075 * // 2nd sample is using PCA9632 class function. 00076 * // PWM control by device class function call 00077 * // 00078 * for ( int i = 0; i < 3; i++ ) { 00079 * for( float p = 0.0f; p < 1.0f; p += 0.1f ) { 00080 * led_cntlr.pwm( 1, p ); // Controls LED1 pin 00081 * wait( 0.1 ); 00082 * } 00083 * } 00084 * } 00085 * } 00086 * @endcode 00087 */ 00088 class PCA9632 : public CompLedDvr 00089 { 00090 public: 00091 00092 #if DOXYGEN_ONLY 00093 /** PCA9626 pin names high-level API i.e. LedPwmOut */ 00094 typedef enum { 00095 L0, /**< LED0 pin */ 00096 L1, /**< LED2 pin */ 00097 L2, /**< LED2 pin */ 00098 L3, /**< LED2 pin */ 00099 L_NC = ~0x0L /**< for when the pin is left no-connection */ 00100 } LedPinName; 00101 #endif // DOXYGEN_ONLY 00102 00103 /** Name of the PCA9632 registers (for direct register access) */ 00104 enum command_reg { 00105 MODE1, /**< MODE1 register */ 00106 MODE2, /**< MODE2 register */ 00107 PWM0, /**< PWM0 register */ 00108 PWM1, /**< PWM1 register */ 00109 PWM2, /**< PWM2 register */ 00110 PWM3, /**< PWM3 register */ 00111 GRPPWM, /**< GRPPWM register */ 00112 GRPFREQ, /**< GRPFREQ register */ 00113 LEDOUT, /**< LEDOUT register */ 00114 SUBADR1, /**< SUBADR1 register */ 00115 SUBADR2, /**< SUBADR2 register */ 00116 SUBADR3, /**< SUBADR3 register */ 00117 ALLCALLADR, /**< ALLCALLADR register */ 00118 00119 REGISTER_START = MODE1, 00120 PWM_REGISTER_START = PWM0, 00121 }; 00122 00123 /** Difinition of the number of LED pins */ 00124 enum { 00125 N_OF_PORTS = 4 00126 }; 00127 00128 /** Create a PCA9632 instance connected to specified I2C pins with specified address 00129 * 00130 * @param i2c_sda I2C-bus SDA pin 00131 * @param i2c_sda I2C-bus SCL pin 00132 * @param i2c_address I2C-bus address (default: 0xC4) 00133 */ 00134 PCA9632( PinName i2c_sda, PinName i2c_scl, char i2c_address = DEFAULT_I2C_ADDR ); 00135 00136 /** Create a PCA9632 instance connected to specified I2C pins with specified address 00137 * 00138 * @param i2c_obj I2C object (instance) 00139 * @param i2c_address I2C-bus address (default: 0xC4) 00140 */ 00141 PCA9632( I2C &i2c_obj, char i2c_address = DEFAULT_I2C_ADDR ); 00142 00143 /** Destractor 00144 */ 00145 virtual ~PCA9632(); 00146 00147 /** Performs Software reset via I2C bus 00148 */ 00149 void reset( void ); 00150 00151 /** Set the output duty-cycle, specified as a percentage (float) 00152 * 00153 * @param port Selecting output port 00154 * 'ALLPORTS' can be used to set all port duty-cycle same value. 00155 * @param v A floating-point value representing the output duty-cycle, 00156 * specified as a percentage. The value should lie between 00157 * 0.0f (representing on 0%) and 1.0f (representing on 99.6%). 00158 * Values outside this range will have undefined behavior. 00159 */ 00160 virtual void pwm( int port, float v ); 00161 00162 /** Set all output port duty-cycle, specified as a percentage (array of float) 00163 * 00164 * @param vp Aray to floating-point values representing the output duty-cycle, 00165 * specified as a percentage. The value should lie between 00166 * 0.0f (representing on 0%) and 1.0f (representing on 99.6%). 00167 * 00168 * @note 00169 * The aray should have length of 4 00170 */ 00171 void pwm( float *vp ); 00172 00173 /** Register write (single byte) : Low level access to device register 00174 * 00175 * @param reg_addr Register address 00176 * @param data Value for setting into the register 00177 */ 00178 void write( char reg_addr, char data ); 00179 00180 /** Register write (multiple bytes) : Low level access to device register 00181 * 00182 * @param data Pointer to an array. First 1 byte should be the writing start register address 00183 * @param length Length of data 00184 */ 00185 void write( char *data, int length ); 00186 00187 /** Register read (single byte) : Low level access to device register 00188 * 00189 * @param reg_addr Register address 00190 * @return Read value from register 00191 */ 00192 char read( char reg_addr ); 00193 00194 /** Register write (multiple bytes) : Low level access to device register 00195 * 00196 * @param reg_addr Register address 00197 * @param data Pointer to an array. The values are stored in this array. 00198 * @param length Length of data 00199 */ 00200 00201 void read( char reg_addr, char *data, int length ); 00202 00203 protected: 00204 enum { 00205 DEFAULT_I2C_ADDR = 0xC4, 00206 AUTO_INCREMENT = 0x80, 00207 PWMALL = 0xFF 00208 }; 00209 00210 private: 00211 void initialize( void ); 00212 00213 I2C *i2c_p; 00214 I2C &i2c; 00215 char address; // I2C slave address 00216 } 00217 ; 00218 00219 #endif // MBED_PCA9632
Generated on Wed Jul 13 2022 08:58:56 by
1.7.2
PCA9632 : 4ch LED driver (voltage switch type)