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