gfdgd

Dependencies:   CompLedDvrCC

Fork of PCA995xA by InetrfaceProducts NXP

Committer:
nxp_ip
Date:
Thu Mar 19 08:40:03 2015 +0000
Revision:
4:fe221e1d4f44
Parent:
2:eeea2e848b81
Child:
5:cb07190e05e7
API document update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxp_ip 0:a624e2eeccac 1 /** PCA9956A constant current LED driver
nxp_ip 0:a624e2eeccac 2 *
nxp_ip 0:a624e2eeccac 3 * An operation sample of PCA9956A 24-channel Fm+ I2C-bus 57mA/20V constant current LED driver.
nxp_ip 0:a624e2eeccac 4 * mbed accesses the PCA9956A registers through I2C.
nxp_ip 0:a624e2eeccac 5 *
nxp_ip 0:a624e2eeccac 6 * @class PCA9956A
nxp_ip 0:a624e2eeccac 7 * @author Akifumi (Tedd) OKANO, NXP Semiconductors
nxp_ip 4:fe221e1d4f44 8 * @version 0.6
nxp_ip 4:fe221e1d4f44 9 * @date 19-Mar-2015
nxp_ip 0:a624e2eeccac 10 *
nxp_ip 1:3522be54a4f5 11 * Released under the Apache 2 license
nxp_ip 0:a624e2eeccac 12 *
nxp_ip 0:a624e2eeccac 13 * About PCA9956A:
nxp_ip 0:a624e2eeccac 14 * http://www.nxp.com/products/interface_and_connectivity/i2c/i2c_led_display_control/PCA9956ATW.html
nxp_ip 0:a624e2eeccac 15 */
nxp_ip 0:a624e2eeccac 16
nxp_ip 0:a624e2eeccac 17 #ifndef MBED_PCA9956A
nxp_ip 0:a624e2eeccac 18 #define MBED_PCA9956A
nxp_ip 0:a624e2eeccac 19
nxp_ip 0:a624e2eeccac 20 #include "mbed.h"
nxp_ip 0:a624e2eeccac 21 #include "PCA995xA.h"
nxp_ip 2:eeea2e848b81 22 #include "LedPwmOutCC.h"
nxp_ip 0:a624e2eeccac 23
nxp_ip 0:a624e2eeccac 24 /** PCA9956A class
nxp_ip 0:a624e2eeccac 25 *
nxp_ip 0:a624e2eeccac 26 * This is a driver code for the PCA9956A 24-channel Fm+ I2C-bus 57mA/20V constant current LED driver.
nxp_ip 0:a624e2eeccac 27 * This class provides interface for PCA9956A operation and accessing its registers.
nxp_ip 0:a624e2eeccac 28 * Detail information is available on next URL.
nxp_ip 0:a624e2eeccac 29 * http://www.nxp.com/products/interface_and_connectivity/i2c/i2c_led_display_control/PCA9956ATW.html
nxp_ip 0:a624e2eeccac 30 *
nxp_ip 4:fe221e1d4f44 31 * Next sample code shows operation based on low-level-API (operated by just device instane)
nxp_ip 4:fe221e1d4f44 32 *
nxp_ip 0:a624e2eeccac 33 * Example:
nxp_ip 0:a624e2eeccac 34 * @code
nxp_ip 4:fe221e1d4f44 35 * // PCA9956A operation sample using its device instance
nxp_ip 0:a624e2eeccac 36 *
nxp_ip 4:fe221e1d4f44 37 * #include "mbed.h"
nxp_ip 0:a624e2eeccac 38 * #include "PCA9956A.h"
nxp_ip 4:fe221e1d4f44 39 *
nxp_ip 0:a624e2eeccac 40 * PCA9956A led_cntlr( p28, p27, 0x02 ); // SDA, SCL, Slave_address(option)
nxp_ip 0:a624e2eeccac 41 *
nxp_ip 0:a624e2eeccac 42 * int main()
nxp_ip 0:a624e2eeccac 43 * {
nxp_ip 0:a624e2eeccac 44 * led_cntlr.current( ALLPORTS, 1.0 ); // Set all ports output current 100%
nxp_ip 0:a624e2eeccac 45 *
nxp_ip 0:a624e2eeccac 46 * while(1) {
nxp_ip 0:a624e2eeccac 47 * for ( int port = 0; port < led_cntlr.number_of_ports(); port++ ) {
nxp_ip 0:a624e2eeccac 48 * for ( int i = 1; i <= 100; i++ ) {
nxp_ip 0:a624e2eeccac 49 * led_cntlr.pwm( port, (float)i / 100.0 );
nxp_ip 0:a624e2eeccac 50 * wait( 0.01 );
nxp_ip 0:a624e2eeccac 51 * }
nxp_ip 0:a624e2eeccac 52 * }
nxp_ip 0:a624e2eeccac 53 * led_cntlr.pwm( ALLPORTS, 0.0 );
nxp_ip 0:a624e2eeccac 54 * }
nxp_ip 0:a624e2eeccac 55 * }
nxp_ip 0:a624e2eeccac 56 * @endcode
nxp_ip 4:fe221e1d4f44 57 *
nxp_ip 4:fe221e1d4f44 58 * The high-level-API:LedPwmOutCC is also available.
nxp_ip 4:fe221e1d4f44 59 * It can be used like next sample code.
nxp_ip 4:fe221e1d4f44 60 *
nxp_ip 4:fe221e1d4f44 61 * @code
nxp_ip 4:fe221e1d4f44 62 * // PCA9956A operation sample using high-level-API
nxp_ip 4:fe221e1d4f44 63 *
nxp_ip 4:fe221e1d4f44 64 * #include "mbed.h"
nxp_ip 4:fe221e1d4f44 65 * #include "PCA9956A.h"
nxp_ip 4:fe221e1d4f44 66 *
nxp_ip 4:fe221e1d4f44 67 * PCA9956A led_cntlr( p28, p27, 0x02 ); // SDA, SCL, Slave_address(option)
nxp_ip 4:fe221e1d4f44 68 * LedPwmOutCC led0( led_cntlr, L0 ); // Instance for LED0 pin
nxp_ip 4:fe221e1d4f44 69 * LedPwmOutCC led1( led_cntlr, L1 ); // Instance for LED1 pin
nxp_ip 4:fe221e1d4f44 70 * LedPwmOutCC led2( led_cntlr, L2 ); // Instance for LED2 pin
nxp_ip 4:fe221e1d4f44 71 *
nxp_ip 4:fe221e1d4f44 72 * int main()
nxp_ip 4:fe221e1d4f44 73 * {
nxp_ip 4:fe221e1d4f44 74 * led0.current( 0.5 ); // LED0 pin current output setting to 50%
nxp_ip 4:fe221e1d4f44 75 * led1.current( 0.5 ); // LED1 pin current output setting to 50%
nxp_ip 4:fe221e1d4f44 76 * led2.current( 0.5 ); // LED2 pin current output setting to 50%
nxp_ip 4:fe221e1d4f44 77 *
nxp_ip 4:fe221e1d4f44 78 * while(1) {
nxp_ip 4:fe221e1d4f44 79 *
nxp_ip 4:fe221e1d4f44 80 * for ( float p = 1.0; p >= 0.0; p -= 0.01 ) {
nxp_ip 4:fe221e1d4f44 81 * led0 = p; // Set LED0 output PWM dutycycle as 'p'
nxp_ip 4:fe221e1d4f44 82 * wait( 0.01 );
nxp_ip 4:fe221e1d4f44 83 * }
nxp_ip 4:fe221e1d4f44 84 *
nxp_ip 4:fe221e1d4f44 85 * for ( float p = 1.0; p >= 0.0; p -= 0.01 ) {
nxp_ip 4:fe221e1d4f44 86 * led1 = p; // Set LED1 output PWM dutycycle as 'p'
nxp_ip 4:fe221e1d4f44 87 * wait( 0.01 );
nxp_ip 4:fe221e1d4f44 88 * }
nxp_ip 4:fe221e1d4f44 89 *
nxp_ip 4:fe221e1d4f44 90 * for ( float p = 1.0; p >= 0.0; p -= 0.01 ) {
nxp_ip 4:fe221e1d4f44 91 * led2 = p; // Set LED2 output PWM dutycycle as 'p'
nxp_ip 4:fe221e1d4f44 92 * wait( 0.01 );
nxp_ip 4:fe221e1d4f44 93 * }
nxp_ip 4:fe221e1d4f44 94 * }
nxp_ip 4:fe221e1d4f44 95 * }
nxp_ip 4:fe221e1d4f44 96 * @endcode
nxp_ip 0:a624e2eeccac 97 */
nxp_ip 0:a624e2eeccac 98 class PCA9956A : public PCA995xA
nxp_ip 0:a624e2eeccac 99 {
nxp_ip 0:a624e2eeccac 100 public:
nxp_ip 4:fe221e1d4f44 101
nxp_ip 4:fe221e1d4f44 102 #if DOXYGEN_ONLY
nxp_ip 4:fe221e1d4f44 103 /** PCA9956A pin names high-level API i.e. LedPwmOutCC */
nxp_ip 4:fe221e1d4f44 104 typedef enum {
nxp_ip 4:fe221e1d4f44 105 L0, /**< LED0 pin */
nxp_ip 4:fe221e1d4f44 106 L1, /**< LED1 pin */
nxp_ip 4:fe221e1d4f44 107 L2, /**< LED2 pin */
nxp_ip 4:fe221e1d4f44 108 L3, /**< LED3 pin */
nxp_ip 4:fe221e1d4f44 109 L4, /**< LED4 pin */
nxp_ip 4:fe221e1d4f44 110 L5, /**< LED5 pin */
nxp_ip 4:fe221e1d4f44 111 L6, /**< LED6 pin */
nxp_ip 4:fe221e1d4f44 112 L7, /**< LED7 pin */
nxp_ip 4:fe221e1d4f44 113 L8, /**< LED8 pin */
nxp_ip 4:fe221e1d4f44 114 L9, /**< LED9 pin */
nxp_ip 4:fe221e1d4f44 115 L10, /**< LED10 pin */
nxp_ip 4:fe221e1d4f44 116 L11, /**< LED11 pin */
nxp_ip 4:fe221e1d4f44 117 L12, /**< LED12 pin */
nxp_ip 4:fe221e1d4f44 118 L13, /**< LED13 pin */
nxp_ip 4:fe221e1d4f44 119 L14, /**< LED14 pin */
nxp_ip 4:fe221e1d4f44 120 L15, /**< LED15 pin */
nxp_ip 4:fe221e1d4f44 121 L16, /**< LED16 pin */
nxp_ip 4:fe221e1d4f44 122 L17, /**< LED17 pin */
nxp_ip 4:fe221e1d4f44 123 L18, /**< LED18 pin */
nxp_ip 4:fe221e1d4f44 124 L19, /**< LED19 pin */
nxp_ip 4:fe221e1d4f44 125 L20, /**< LED20 pin */
nxp_ip 4:fe221e1d4f44 126 L21, /**< LED21 pin */
nxp_ip 4:fe221e1d4f44 127 L22, /**< LED22 pin */
nxp_ip 4:fe221e1d4f44 128 L23, /**< LED23 pin */
nxp_ip 4:fe221e1d4f44 129 L_NC = ~0x0L /**< for when the pin is left no-connection */
nxp_ip 4:fe221e1d4f44 130 } LedPinName;
nxp_ip 4:fe221e1d4f44 131 #endif // DOXYGEN_ONLY
nxp_ip 4:fe221e1d4f44 132
nxp_ip 0:a624e2eeccac 133 /** Name of the PCA9956A registers */
nxp_ip 0:a624e2eeccac 134 enum command_reg {
nxp_ip 0:a624e2eeccac 135 MODE1, MODE2,
nxp_ip 0:a624e2eeccac 136 LEDOUT0, LEDOUT1, LEDOUT2, LEDOUT3, LEDOUT4, LEDOUT5,
nxp_ip 0:a624e2eeccac 137 GRPPWM, GRPFREQ,
nxp_ip 0:a624e2eeccac 138 PWM0, PWM1, PWM2, PWM3,
nxp_ip 0:a624e2eeccac 139 PWM4, PWM5, PWM6, PWM7,
nxp_ip 0:a624e2eeccac 140 PWM8, PWM9, PWM10, PWM11,
nxp_ip 0:a624e2eeccac 141 PWM12, PWM13, PWM14, PWM15,
nxp_ip 0:a624e2eeccac 142 PWM16, PWM17, PWM18, PWM19,
nxp_ip 0:a624e2eeccac 143 PWM20, PWM21, PWM22, PWM23,
nxp_ip 0:a624e2eeccac 144 IREF0, IREF1, IREF2, IREF3,
nxp_ip 0:a624e2eeccac 145 IREF4, IREF5, IREF6, IREF7,
nxp_ip 0:a624e2eeccac 146 IREF8, IREF9, IREF10, IREF11,
nxp_ip 0:a624e2eeccac 147 IREF12, IREF13, IREF14, IREF15,
nxp_ip 0:a624e2eeccac 148 IREF16, IREF17, IREF18, IREF19,
nxp_ip 0:a624e2eeccac 149 IREF20, IREF21, IREF22, IREF23,
nxp_ip 0:a624e2eeccac 150 OFFSET = 0x3A,
nxp_ip 0:a624e2eeccac 151 SUBADR1, SUBADR2, SUBADR3, ALLCALLADR,
nxp_ip 0:a624e2eeccac 152 PWMALL, IREFALL,
nxp_ip 0:a624e2eeccac 153 EFLAG0, EFLAG1, EFLAG2, EFLAG3, EFLAG4, EFLAG5,
nxp_ip 0:a624e2eeccac 154
nxp_ip 0:a624e2eeccac 155 REGISTER_START = MODE1,
nxp_ip 0:a624e2eeccac 156 LEDOUT_REGISTER_START = LEDOUT0,
nxp_ip 0:a624e2eeccac 157 PWM_REGISTER_START = PWM0,
nxp_ip 0:a624e2eeccac 158 IREF_REGISTER_START = IREF0,
nxp_ip 0:a624e2eeccac 159 };
nxp_ip 0:a624e2eeccac 160
nxp_ip 0:a624e2eeccac 161 /** Create a PCA9629A instance connected to specified I2C pins with specified address
nxp_ip 0:a624e2eeccac 162 *
nxp_ip 0:a624e2eeccac 163 * @param i2c_sda I2C-bus SDA pin
nxp_ip 0:a624e2eeccac 164 * @param i2c_sda I2C-bus SCL pin
nxp_ip 0:a624e2eeccac 165 * @param i2c_address I2C-bus address (default: 0xC0)
nxp_ip 0:a624e2eeccac 166 */
nxp_ip 0:a624e2eeccac 167 PCA9956A( PinName i2c_sda, PinName i2c_scl, char i2c_address = PCA995xA::DEFAULT_I2C_ADDR );
nxp_ip 0:a624e2eeccac 168
nxp_ip 0:a624e2eeccac 169 /** Create a PCA9629A instance connected to specified I2C pins with specified address
nxp_ip 0:a624e2eeccac 170 *
nxp_ip 0:a624e2eeccac 171 * @param i2c_obj I2C object (instance)
nxp_ip 0:a624e2eeccac 172 * @param i2c_address I2C-bus address (default: 0xC0)
nxp_ip 0:a624e2eeccac 173 */
nxp_ip 0:a624e2eeccac 174 PCA9956A( I2C &i2c_obj, char i2c_address = PCA995xA::DEFAULT_I2C_ADDR );
nxp_ip 0:a624e2eeccac 175
nxp_ip 0:a624e2eeccac 176 /** Destractor
nxp_ip 0:a624e2eeccac 177 *
nxp_ip 0:a624e2eeccac 178 */
nxp_ip 0:a624e2eeccac 179 virtual ~PCA9956A();
nxp_ip 0:a624e2eeccac 180
nxp_ip 0:a624e2eeccac 181 /** Returns the number of output ports
nxp_ip 0:a624e2eeccac 182 *
nxp_ip 0:a624e2eeccac 183 * @returns
nxp_ip 0:a624e2eeccac 184 * The number of output ports
nxp_ip 0:a624e2eeccac 185 */
nxp_ip 0:a624e2eeccac 186 virtual int number_of_ports( void );
nxp_ip 0:a624e2eeccac 187
nxp_ip 0:a624e2eeccac 188 #if DOXYGEN_ONLY
nxp_ip 0:a624e2eeccac 189 /** Set the output duty-cycle, specified as a percentage (float)
nxp_ip 0:a624e2eeccac 190 *
nxp_ip 0:a624e2eeccac 191 * @param port Selecting output port
nxp_ip 0:a624e2eeccac 192 * 'ALLPORTS' can be used to set all port duty-cycle same value.
nxp_ip 0:a624e2eeccac 193 * @param v A floating-point value representing the output duty-cycle,
nxp_ip 0:a624e2eeccac 194 * specified as a percentage. The value should lie between
nxp_ip 1:3522be54a4f5 195 * 0.0f (representing on 0%) and 1.0f (representing on 99.6%).
nxp_ip 0:a624e2eeccac 196 * Values outside this range will have undefined behavior.
nxp_ip 0:a624e2eeccac 197 */
nxp_ip 0:a624e2eeccac 198 void pwm( int port, float v );
nxp_ip 0:a624e2eeccac 199
nxp_ip 0:a624e2eeccac 200 /** Set all output port duty-cycle, specified as a percentage (array of float)
nxp_ip 0:a624e2eeccac 201 *
nxp_ip 0:a624e2eeccac 202 * @param vp Aray to floating-point values representing the output duty-cycle,
nxp_ip 0:a624e2eeccac 203 * specified as a percentage. The value should lie between
nxp_ip 1:3522be54a4f5 204 * 0.0f (representing on 0%) and 1.0f (representing on 99.6%).
nxp_ip 0:a624e2eeccac 205 *
nxp_ip 0:a624e2eeccac 206 * @note
nxp_ip 0:a624e2eeccac 207 * The aray should have length of 24
nxp_ip 0:a624e2eeccac 208 */
nxp_ip 0:a624e2eeccac 209 void pwm( float *vp );
nxp_ip 0:a624e2eeccac 210
nxp_ip 0:a624e2eeccac 211 /** Set the output current, specified as a percentage (float)
nxp_ip 0:a624e2eeccac 212 *
nxp_ip 0:a624e2eeccac 213 * @param port Selecting output port
nxp_ip 0:a624e2eeccac 214 * 'ALLPORTS' can be used to set all port duty-cycle same value.
nxp_ip 0:a624e2eeccac 215 * @param v A floating-point value representing the output current,
nxp_ip 0:a624e2eeccac 216 * specified as a percentage. The value should lie between
nxp_ip 0:a624e2eeccac 217 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
nxp_ip 0:a624e2eeccac 218 * Values outside this range will have undefined behavior.
nxp_ip 0:a624e2eeccac 219 */
nxp_ip 0:a624e2eeccac 220 void current( int port, float vp );
nxp_ip 0:a624e2eeccac 221
nxp_ip 0:a624e2eeccac 222 /** Set all output port curent, specified as a percentage (array of float)
nxp_ip 0:a624e2eeccac 223 *
nxp_ip 0:a624e2eeccac 224 * @param vp Aray to floating-point values representing the output current,
nxp_ip 0:a624e2eeccac 225 * specified as a percentage. The value should lie between
nxp_ip 0:a624e2eeccac 226 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
nxp_ip 0:a624e2eeccac 227 *
nxp_ip 0:a624e2eeccac 228 * @note
nxp_ip 0:a624e2eeccac 229 * The aray should have length of 24
nxp_ip 0:a624e2eeccac 230 */
nxp_ip 0:a624e2eeccac 231 void current( float *vP );
nxp_ip 0:a624e2eeccac 232
nxp_ip 0:a624e2eeccac 233 /** Register write (single byte) : Low level access to device register
nxp_ip 0:a624e2eeccac 234 *
nxp_ip 0:a624e2eeccac 235 * @param reg_addr Register address
nxp_ip 0:a624e2eeccac 236 * @param data Value for setting into the register
nxp_ip 0:a624e2eeccac 237 */
nxp_ip 0:a624e2eeccac 238 void write( char reg_addr, char data );
nxp_ip 0:a624e2eeccac 239
nxp_ip 0:a624e2eeccac 240 /** Register write (multiple bytes) : Low level access to device register
nxp_ip 0:a624e2eeccac 241 *
nxp_ip 0:a624e2eeccac 242 * @param data Pointer to an array. First 1 byte should be the writing start register address
nxp_ip 0:a624e2eeccac 243 * @param length Length of data
nxp_ip 0:a624e2eeccac 244 */
nxp_ip 0:a624e2eeccac 245 void write( char *data, int length );
nxp_ip 0:a624e2eeccac 246
nxp_ip 0:a624e2eeccac 247 /** Register read (single byte) : Low level access to device register
nxp_ip 0:a624e2eeccac 248 *
nxp_ip 0:a624e2eeccac 249 * @param reg_addr Register address
nxp_ip 0:a624e2eeccac 250 * @return Read value from register
nxp_ip 0:a624e2eeccac 251 */
nxp_ip 0:a624e2eeccac 252 char read( char reg_addr );
nxp_ip 0:a624e2eeccac 253
nxp_ip 0:a624e2eeccac 254 /** Register write (multiple bytes) : Low level access to device register
nxp_ip 0:a624e2eeccac 255 *
nxp_ip 0:a624e2eeccac 256 * @param reg_addr Register address
nxp_ip 0:a624e2eeccac 257 * @param data Pointer to an array. The values are stored in this array.
nxp_ip 0:a624e2eeccac 258 * @param length Length of data
nxp_ip 0:a624e2eeccac 259 */
nxp_ip 0:a624e2eeccac 260 void read( char reg_addr, char *data, int length );
nxp_ip 0:a624e2eeccac 261 #endif
nxp_ip 0:a624e2eeccac 262
nxp_ip 0:a624e2eeccac 263 private:
nxp_ip 0:a624e2eeccac 264 void initialize( void );
nxp_ip 0:a624e2eeccac 265 virtual char pwm_register_access( int port );
nxp_ip 0:a624e2eeccac 266 virtual char current_register_access( int port );
nxp_ip 0:a624e2eeccac 267
nxp_ip 0:a624e2eeccac 268 const int n_of_ports;
nxp_ip 0:a624e2eeccac 269 }
nxp_ip 0:a624e2eeccac 270 ;
nxp_ip 0:a624e2eeccac 271
nxp_ip 0:a624e2eeccac 272 #endif // MBED_PCA9956A