PCA9955A and PCA9956A class library. The PCA9955A is a 16-channel and the PCA9956A is a 24-channel Fm+ I2C-bus 57mA/20V constant current LED driver. The PCA9955A has a extended feature which called "Gradation control".

Dependencies:   CompLedDvrCC

Dependents:   PCA9956A_Hello pca9956b_two_demoboards PCA9955A_Gradation_control PCA9955A_Gradation_control ... more

What is this?

Code for PCA9956A and PCA9955A.
24-channel and 16-channel constant current type LED driver component class.

Please refer to the component page for details

PCA9955B and PCA9956B are I²C-bus controlled 16-channel constant current LED driver optimized for dimming and blinking.

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.
Output current also controllable by API function.
For detail information, refer API document of LedPwmOutCC Class class which is included in PCA995xA class library.

#include "mbed.h"
#include "PCA9956A.h"

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

int main()
{
    while( 1 ) {
        for( float p = 0.0f; p < 1.0f; p += 0.1f ) {
            led     = p;
            wait( 0.1 );
        }
    }
}

About the chips

PCA9956A

The PCA9956A is an I2C-bus controlled 24-channel constant current LED driver optimized for dimming and blinking 57 mA LEDs. Each LED output has its own 8-bit resolution (256 steps) fixed frequency individual PWM controller that operates at 31.25 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.

Datasheet: http://www.nxp.com/documents/data_sheet/PCA9956A.pdf

PCA9955A

The PCA9955A is an I2C-bus controlled 16-channel constant current LED driver optimized for dimming and blinking 57 mA Red/Green/Blue/Amber (RGBA) LEDs in amusement products. Each LED output has its own 8-bit resolution (256 steps) fixed frequency individual PWM controller that operates at 31.25 kHz with a duty cycle that is adjustable from 0 % to 100 % to allow the LED to be set to a specific brightness value.

On addition to this, the PCA9955A has "Gradation control".
The gradation control is a new feature of PCA995xA series. After the register setting and start the control, the PCA9955A performs dimming cycles automatically without MCU intervention.

Datasheet: http://www.nxp.com/documents/data_sheet/PCA9955A.pdf

PCA9952 and PCA9955 (non-A version)

The PCA9955 and PCA9955 (no-A at end of the type number) is not supported by this component class.

PCA9955(non-A)

PCA9955A != PCA9955

PCA9955A is not software compatible to PCA9955(non-A version).
There are several differences between A and non-A versions.
Register mapping is one of the difference. Please make sure you are using PCA9955A.

How the API works?

When the instance is made, all set up for PWM operation are done automatically.
For the operation, user can control the LED brightness in two ways.

  • PWM
  • Current

PCA9955A and PCA9956A have internal 31.25kHz oscillator to generate internal PWM waveform. This signal switchs the output current ON and OFF. The class' function pwm() controls duty-cycle of this output.

Another control is current. Since the PCA9955A and PCA9956A are constant current type LED driver, those have internal current sources. The current source on each channels has independent control of output current. The class' function current() provides interface to current change.

API_and_output

Tips for the chips

PCA995xA family

This PCA995xA components library can be used for both PCA9955A(16-channel) and PCA9956A(24-channel).
If you are using both chips on the I2C bus, those can be operated like..

#include "mbed.h"
 
#include "PCA9955A.h"
#include "PCA9956A.h"

PCA9955A    led0( p28, p27, 0xC0 );    //  SDA, SCL, Slave_address=0xC0 (16-channel chip)
PCA9956A    led1( p28, p27, 0xC2 );    //  SDA, SCL, Slave_address=0xC2 (24-channel chip)
 
int main()
{
    led0.current( ALLPORTS, 1.0 ); //  Set all ports output current 100%
    led1.current( ALLPORTS, 1.0 ); //  Set all ports output current 100%

    led0.pwm( ....    //  PWM control for PCA9955A(16-channel chip)
    led1.pwm( ....    //  PWM control for PCA9956A(24-channel chip)
    ...

Other sample code

For PCA9955A : http://developer.mbed.org/users/nxp_ip/code/PCA9955A_Hello/
For PCA9956A : http://developer.mbed.org/users/nxp_ip/code/PCA9956A_Hello/
For Gradation control of PCA9955A http://developer.mbed.org/users/nxp_ip/code/PCA9955A_Gradation_control/

Committer:
nxp_ip
Date:
Thu Mar 19 10:47:49 2015 +0000
Revision:
5:cb07190e05e7
Parent:
4:fe221e1d4f44
Child:
7:5c1762c7610a
API document update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxp_ip 0:a624e2eeccac 1 /** PCA9955A constant current LED driver
nxp_ip 0:a624e2eeccac 2 *
nxp_ip 0:a624e2eeccac 3 * An operation sample of PCA9955A 16-channel Fm+ I2C-bus 57mA/20V constant current LED driver.
nxp_ip 0:a624e2eeccac 4 * mbed accesses PCA9955A registers via I2C.
nxp_ip 0:a624e2eeccac 5 *
nxp_ip 0:a624e2eeccac 6 * @class PCA9955A
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 PCA9955A:
nxp_ip 0:a624e2eeccac 14 * http://www.nxp.com/products/interface_and_connectivity/i2c/i2c_led_display_control/PCA9955ATW.html
nxp_ip 0:a624e2eeccac 15 */
nxp_ip 0:a624e2eeccac 16
nxp_ip 0:a624e2eeccac 17 #ifndef MBED_PCA9955A
nxp_ip 0:a624e2eeccac 18 #define MBED_PCA9955A
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 /** PCA9955A class
nxp_ip 0:a624e2eeccac 25 *
nxp_ip 0:a624e2eeccac 26 * This is a driver code for the PCA9955A 16-channel Fm+ I2C-bus 57mA/20V constant current LED driver.
nxp_ip 0:a624e2eeccac 27 * This class provides interface for PCA9955A 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/PCA9955ATW.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 * // PCA9955A operation sample using its device instance
nxp_ip 4:fe221e1d4f44 36 *
nxp_ip 0:a624e2eeccac 37 * #include "mbed.h"
nxp_ip 0:a624e2eeccac 38 * #include "PCA9955A.h"
nxp_ip 0:a624e2eeccac 39 * PCA9955A led_cntlr( p28, p27, 0x02 ); // SDA, SCL, Slave_address(option)
nxp_ip 0:a624e2eeccac 40 *
nxp_ip 0:a624e2eeccac 41 * int main()
nxp_ip 0:a624e2eeccac 42 * {
nxp_ip 0:a624e2eeccac 43 * led_cntlr.current( ALLPORTS, 1.0 ); // Set all ports output current 100%
nxp_ip 0:a624e2eeccac 44 *
nxp_ip 0:a624e2eeccac 45 * while(1) {
nxp_ip 0:a624e2eeccac 46 * for ( int port = 0; port < led_cntlr.number_of_ports(); port++ ) {
nxp_ip 0:a624e2eeccac 47 * for ( int i = 1; i <= 100; i++ ) {
nxp_ip 0:a624e2eeccac 48 * led_cntlr.pwm( port, (float)i / 100.0 );
nxp_ip 0:a624e2eeccac 49 * wait( 0.01 );
nxp_ip 0:a624e2eeccac 50 * }
nxp_ip 0:a624e2eeccac 51 * }
nxp_ip 0:a624e2eeccac 52 * led_cntlr.pwm( ALLPORTS, 0.0 );
nxp_ip 0:a624e2eeccac 53 * }
nxp_ip 0:a624e2eeccac 54 * }
nxp_ip 0:a624e2eeccac 55 * @endcode
nxp_ip 4:fe221e1d4f44 56 *
nxp_ip 4:fe221e1d4f44 57 * The high-level-API:LedPwmOutCC is also available.
nxp_ip 4:fe221e1d4f44 58 * It can be used like next sample code.
nxp_ip 4:fe221e1d4f44 59 *
nxp_ip 4:fe221e1d4f44 60 * @code
nxp_ip 4:fe221e1d4f44 61 * // PCA9955A operation sample using high-level-API
nxp_ip 4:fe221e1d4f44 62 *
nxp_ip 4:fe221e1d4f44 63 * #include "mbed.h"
nxp_ip 4:fe221e1d4f44 64 * #include "PCA9955A.h"
nxp_ip 4:fe221e1d4f44 65 *
nxp_ip 4:fe221e1d4f44 66 * PCA9955A led_cntlr( p28, p27, 0x02 ); // SDA, SCL, Slave_address(option)
nxp_ip 4:fe221e1d4f44 67 * LedPwmOutCC led0( led_cntlr, L0 ); // Instance for LED0 pin
nxp_ip 4:fe221e1d4f44 68 * LedPwmOutCC led1( led_cntlr, L1 ); // Instance for LED1 pin
nxp_ip 4:fe221e1d4f44 69 * LedPwmOutCC led2( led_cntlr, L2 ); // Instance for LED2 pin
nxp_ip 4:fe221e1d4f44 70 *
nxp_ip 4:fe221e1d4f44 71 * int main()
nxp_ip 4:fe221e1d4f44 72 * {
nxp_ip 4:fe221e1d4f44 73 * led0.current( 0.5 ); // LED0 pin current output setting to 50%
nxp_ip 4:fe221e1d4f44 74 * led1.current( 0.5 ); // LED1 pin current output setting to 50%
nxp_ip 4:fe221e1d4f44 75 * led2.current( 0.5 ); // LED2 pin current output setting to 50%
nxp_ip 4:fe221e1d4f44 76 *
nxp_ip 4:fe221e1d4f44 77 * while(1) {
nxp_ip 4:fe221e1d4f44 78 *
nxp_ip 4:fe221e1d4f44 79 * for ( float p = 1.0; p >= 0.0; p -= 0.01 ) {
nxp_ip 4:fe221e1d4f44 80 * led0 = p; // Set LED0 output PWM dutycycle as 'p'
nxp_ip 4:fe221e1d4f44 81 * wait( 0.01 );
nxp_ip 4:fe221e1d4f44 82 * }
nxp_ip 4:fe221e1d4f44 83 *
nxp_ip 4:fe221e1d4f44 84 * for ( float p = 1.0; p >= 0.0; p -= 0.01 ) {
nxp_ip 4:fe221e1d4f44 85 * led1 = p; // Set LED1 output PWM dutycycle as 'p'
nxp_ip 4:fe221e1d4f44 86 * wait( 0.01 );
nxp_ip 4:fe221e1d4f44 87 * }
nxp_ip 4:fe221e1d4f44 88 *
nxp_ip 4:fe221e1d4f44 89 * for ( float p = 1.0; p >= 0.0; p -= 0.01 ) {
nxp_ip 4:fe221e1d4f44 90 * led2 = p; // Set LED2 output PWM dutycycle as 'p'
nxp_ip 4:fe221e1d4f44 91 * wait( 0.01 );
nxp_ip 4:fe221e1d4f44 92 * }
nxp_ip 4:fe221e1d4f44 93 * }
nxp_ip 4:fe221e1d4f44 94 * }
nxp_ip 4:fe221e1d4f44 95 * @endcode
nxp_ip 0:a624e2eeccac 96 */
nxp_ip 0:a624e2eeccac 97 class PCA9955A : public PCA995xA
nxp_ip 0:a624e2eeccac 98 {
nxp_ip 0:a624e2eeccac 99 public:
nxp_ip 4:fe221e1d4f44 100
nxp_ip 4:fe221e1d4f44 101 #if DOXYGEN_ONLY
nxp_ip 4:fe221e1d4f44 102 /** PCA9955A pin names high-level API i.e. LedPwmOutCC */
nxp_ip 4:fe221e1d4f44 103 typedef enum {
nxp_ip 4:fe221e1d4f44 104 L0, /**< LED0 pin */
nxp_ip 4:fe221e1d4f44 105 L1, /**< LED1 pin */
nxp_ip 4:fe221e1d4f44 106 L2, /**< LED2 pin */
nxp_ip 4:fe221e1d4f44 107 L3, /**< LED3 pin */
nxp_ip 4:fe221e1d4f44 108 L4, /**< LED4 pin */
nxp_ip 4:fe221e1d4f44 109 L5, /**< LED5 pin */
nxp_ip 4:fe221e1d4f44 110 L6, /**< LED6 pin */
nxp_ip 4:fe221e1d4f44 111 L7, /**< LED7 pin */
nxp_ip 4:fe221e1d4f44 112 L8, /**< LED8 pin */
nxp_ip 4:fe221e1d4f44 113 L9, /**< LED9 pin */
nxp_ip 4:fe221e1d4f44 114 L10, /**< LED10 pin */
nxp_ip 4:fe221e1d4f44 115 L11, /**< LED11 pin */
nxp_ip 4:fe221e1d4f44 116 L12, /**< LED12 pin */
nxp_ip 4:fe221e1d4f44 117 L13, /**< LED13 pin */
nxp_ip 4:fe221e1d4f44 118 L14, /**< LED14 pin */
nxp_ip 4:fe221e1d4f44 119 L15, /**< LED15 pin */
nxp_ip 4:fe221e1d4f44 120 L_NC = ~0x0L /**< for when the pin is left no-connection */
nxp_ip 4:fe221e1d4f44 121 } LedPinName;
nxp_ip 4:fe221e1d4f44 122 #endif // DOXYGEN_ONLY
nxp_ip 4:fe221e1d4f44 123
nxp_ip 5:cb07190e05e7 124 /** Name of the PCA9955A registers (for direct register access) */
nxp_ip 0:a624e2eeccac 125 enum command_reg {
nxp_ip 5:cb07190e05e7 126 MODE1 = 0x00, /**< MODE1 register */
nxp_ip 5:cb07190e05e7 127 MODE2, /**< MODE2 register */
nxp_ip 5:cb07190e05e7 128 LEDOUT0, /**< LEDOUT0 register */
nxp_ip 5:cb07190e05e7 129 LEDOUT1, /**< LEDOUT1 register */
nxp_ip 5:cb07190e05e7 130 LEDOUT2, /**< LEDOUT2 register */
nxp_ip 5:cb07190e05e7 131 LEDOUT3, /**< LEDOUT3 register */
nxp_ip 5:cb07190e05e7 132 GRPPWM = 0x06, /**< GRPPWM register */
nxp_ip 5:cb07190e05e7 133 GRPFREQ, /**< GRPFREQ register */
nxp_ip 5:cb07190e05e7 134 PWM0, /**< PWM0 register */
nxp_ip 5:cb07190e05e7 135 PWM1, /**< PWM1 register */
nxp_ip 5:cb07190e05e7 136 PWM2, /**< PWM2 register */
nxp_ip 5:cb07190e05e7 137 PWM3, /**< PWM3 register */
nxp_ip 5:cb07190e05e7 138 PWM4, /**< PWM4 register */
nxp_ip 5:cb07190e05e7 139 PWM5, /**< PWM5 register */
nxp_ip 5:cb07190e05e7 140 PWM6, /**< PWM6 register */
nxp_ip 5:cb07190e05e7 141 PWM7, /**< PWM7 register */
nxp_ip 5:cb07190e05e7 142 PWM8, /**< PWM8 register */
nxp_ip 5:cb07190e05e7 143 PWM9, /**< PWM9 register */
nxp_ip 5:cb07190e05e7 144 PWM10, /**< PWM10 register */
nxp_ip 5:cb07190e05e7 145 PWM11, /**< PWM11 register */
nxp_ip 5:cb07190e05e7 146 PWM12, /**< PWM12 register */
nxp_ip 5:cb07190e05e7 147 PWM13, /**< PWM13 register */
nxp_ip 5:cb07190e05e7 148 PWM14, /**< PWM14 register */
nxp_ip 5:cb07190e05e7 149 PWM15, /**< PWM15 register */
nxp_ip 5:cb07190e05e7 150 IREF0, /**< IREF0 register */
nxp_ip 5:cb07190e05e7 151 IREF1, /**< IREF1 register */
nxp_ip 5:cb07190e05e7 152 IREF2, /**< IREF2 register */
nxp_ip 5:cb07190e05e7 153 IREF3, /**< IREF3 register */
nxp_ip 5:cb07190e05e7 154 IREF4, /**< IREF4 register */
nxp_ip 5:cb07190e05e7 155 IREF5, /**< IREF5 register */
nxp_ip 5:cb07190e05e7 156 IREF6, /**< IREF6 register */
nxp_ip 5:cb07190e05e7 157 IREF7, /**< IREF7 register */
nxp_ip 5:cb07190e05e7 158 IREF8, /**< IREF8 register */
nxp_ip 5:cb07190e05e7 159 IREF9, /**< IREF9 register */
nxp_ip 5:cb07190e05e7 160 IREF10, /**< IREF10 register */
nxp_ip 5:cb07190e05e7 161 IREF11, /**< IREF11 register */
nxp_ip 5:cb07190e05e7 162 IREF12, /**< IREF12 register */
nxp_ip 5:cb07190e05e7 163 IREF13, /**< IREF13 register */
nxp_ip 5:cb07190e05e7 164 IREF14, /**< IREF14 register */
nxp_ip 5:cb07190e05e7 165 IREF15, /**< IREF15 register */
nxp_ip 5:cb07190e05e7 166 RAMP_RATE_GRP0, /**< RAMP_RATE_GRP0 register */
nxp_ip 5:cb07190e05e7 167 STEP_TIME_GRP0, /**< STEP_TIME_GRP0 register */
nxp_ip 5:cb07190e05e7 168 HOLD_CNTL_GRP0, /**< HOLD_CNTL_GRP0 register */
nxp_ip 5:cb07190e05e7 169 IREF_GRP0, /**< IREF_GRP0 register */
nxp_ip 5:cb07190e05e7 170 RAMP_RATE_GRP1, /**< RAMP_RATE_GRP1 register */
nxp_ip 5:cb07190e05e7 171 STEP_TIME_GRP1, /**< STEP_TIME_GRP1 register */
nxp_ip 5:cb07190e05e7 172 HOLD_CNTL_GRP1, /**< HOLD_CNTL_GRP1 register */
nxp_ip 5:cb07190e05e7 173 IREF_GRP1, /**< IREF_GRP1 register */
nxp_ip 5:cb07190e05e7 174 RAMP_RATE_GRP2, /**< RAMP_RATE_GRP2 register */
nxp_ip 5:cb07190e05e7 175 STEP_TIME_GRP2, /**< STEP_TIME_GRP2 register */
nxp_ip 5:cb07190e05e7 176 HOLD_CNTL_GRP2, /**< HOLD_CNTL_GRP2 register */
nxp_ip 5:cb07190e05e7 177 IREF_GRP2, /**< IREF_GRP2 register */
nxp_ip 5:cb07190e05e7 178 RAMP_RATE_GRP3, /**< RAMP_RATE_GRP3 register */
nxp_ip 5:cb07190e05e7 179 STEP_TIME_GRP3, /**< STEP_TIME_GRP3 register */
nxp_ip 5:cb07190e05e7 180 HOLD_CNTL_GRP3, /**< HOLD_CNTL_GRP3 register */
nxp_ip 5:cb07190e05e7 181 IREF_GRP3, /**< IREF_GRP3 register */
nxp_ip 5:cb07190e05e7 182 GRAD_MODE_SEL0 = 0x38, /**< GRAD_MODE_SEL0 register */
nxp_ip 5:cb07190e05e7 183 GRAD_MODE_SEL1, /**< GRAD_MODE_SEL1 register */
nxp_ip 5:cb07190e05e7 184 GRAD_GRP_SEL0, /**< GRAD_GRP_SEL0 register */
nxp_ip 5:cb07190e05e7 185 GRAD_GRP_SEL1, /**< GRAD_GRP_SEL1 register */
nxp_ip 5:cb07190e05e7 186 GRAD_GRP_SEL2, /**< GRAD_GRP_SEL2 register */
nxp_ip 5:cb07190e05e7 187 GRAD_GRP_SEL3, /**< GRAD_GRP_SEL3 register */
nxp_ip 5:cb07190e05e7 188 GRAD_CNTL, /**< GRAD_CNTL register */
nxp_ip 5:cb07190e05e7 189 OFFSET = 0x3F, /**< OFFSET register */
nxp_ip 5:cb07190e05e7 190 SUBADR1, /**< SUBADR1 register */
nxp_ip 5:cb07190e05e7 191 SUBADR2, /**< SUBADR2 register */
nxp_ip 5:cb07190e05e7 192 SUBADR3, /**< SUBADR3 register */
nxp_ip 5:cb07190e05e7 193 ALLCALLADR, /**< ALLCALLADR register */
nxp_ip 5:cb07190e05e7 194 PWMALL, /**< PWMALL register */
nxp_ip 5:cb07190e05e7 195 IREFALL, /**< IREFALL register */
nxp_ip 5:cb07190e05e7 196 EFLAG0, /**< EFLAG0 register */
nxp_ip 5:cb07190e05e7 197 EFLAG1, /**< EFLAG1 register */
nxp_ip 0:a624e2eeccac 198
nxp_ip 0:a624e2eeccac 199 REGISTER_START = MODE1,
nxp_ip 0:a624e2eeccac 200 LEDOUT_REGISTER_START = LEDOUT0,
nxp_ip 0:a624e2eeccac 201 PWM_REGISTER_START = PWM0,
nxp_ip 0:a624e2eeccac 202 IREF_REGISTER_START = IREF0,
nxp_ip 0:a624e2eeccac 203 GRAD_GROUP_OFFSET = RAMP_RATE_GRP1 - RAMP_RATE_GRP0
nxp_ip 0:a624e2eeccac 204 };
nxp_ip 0:a624e2eeccac 205
nxp_ip 5:cb07190e05e7 206 /** Create a PCA9955A instance connected to specified I2C pins with specified address
nxp_ip 0:a624e2eeccac 207 *
nxp_ip 0:a624e2eeccac 208 * @param i2c_sda I2C-bus SDA pin
nxp_ip 0:a624e2eeccac 209 * @param i2c_sda I2C-bus SCL pin
nxp_ip 0:a624e2eeccac 210 * @param i2c_address (option) I2C-bus address (default: 0xC0)
nxp_ip 0:a624e2eeccac 211 */
nxp_ip 0:a624e2eeccac 212 PCA9955A( PinName i2c_sda, PinName i2c_scl, char i2c_address = PCA995xA::DEFAULT_I2C_ADDR );
nxp_ip 0:a624e2eeccac 213
nxp_ip 5:cb07190e05e7 214 /** Create a PCA9955A instance connected to specified I2C pins with specified address
nxp_ip 0:a624e2eeccac 215 *
nxp_ip 0:a624e2eeccac 216 * @param i2c_obj I2C object (instance)
nxp_ip 0:a624e2eeccac 217 * @param i2c_address (option) I2C-bus address (default: 0xC0)
nxp_ip 0:a624e2eeccac 218 */
nxp_ip 0:a624e2eeccac 219 PCA9955A( I2C &i2c_obj, char i2c_address = PCA995xA::DEFAULT_I2C_ADDR );
nxp_ip 0:a624e2eeccac 220
nxp_ip 0:a624e2eeccac 221 /** Destractor
nxp_ip 0:a624e2eeccac 222 *
nxp_ip 0:a624e2eeccac 223 */
nxp_ip 0:a624e2eeccac 224 virtual ~PCA9955A();
nxp_ip 0:a624e2eeccac 225
nxp_ip 0:a624e2eeccac 226 /** Returns the number of output ports
nxp_ip 0:a624e2eeccac 227 *
nxp_ip 0:a624e2eeccac 228 * @returns
nxp_ip 0:a624e2eeccac 229 * The number of output ports
nxp_ip 0:a624e2eeccac 230 */
nxp_ip 0:a624e2eeccac 231 virtual int number_of_ports( void );
nxp_ip 0:a624e2eeccac 232
nxp_ip 0:a624e2eeccac 233 #if DOXYGEN_ONLY
nxp_ip 0:a624e2eeccac 234 /** Set the output duty-cycle, specified as a percentage (float)
nxp_ip 0:a624e2eeccac 235 *
nxp_ip 0:a624e2eeccac 236 * @param port Selecting output port
nxp_ip 0:a624e2eeccac 237 * 'ALLPORTS' can be used to set all port duty-cycle same value.
nxp_ip 0:a624e2eeccac 238 * @param v A floating-point value representing the output duty-cycle,
nxp_ip 0:a624e2eeccac 239 * specified as a percentage. The value should lie between
nxp_ip 0:a624e2eeccac 240 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
nxp_ip 0:a624e2eeccac 241 * Values outside this range will have undefined behavior.
nxp_ip 0:a624e2eeccac 242 */
nxp_ip 0:a624e2eeccac 243 void pwm( int port, float v );
nxp_ip 0:a624e2eeccac 244
nxp_ip 0:a624e2eeccac 245 /** Set all output port duty-cycle, specified as a percentage (array of float)
nxp_ip 0:a624e2eeccac 246 *
nxp_ip 0:a624e2eeccac 247 * @param vp Aray to floating-point values representing the output duty-cycle,
nxp_ip 0:a624e2eeccac 248 * specified as a percentage. The value should lie between
nxp_ip 0:a624e2eeccac 249 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
nxp_ip 0:a624e2eeccac 250 *
nxp_ip 0:a624e2eeccac 251 * @note
nxp_ip 0:a624e2eeccac 252 * The aray should have length of 16
nxp_ip 0:a624e2eeccac 253 */
nxp_ip 0:a624e2eeccac 254 void pwm( float *vp );
nxp_ip 0:a624e2eeccac 255
nxp_ip 0:a624e2eeccac 256 /** Set the output current, specified as a percentage (float)
nxp_ip 0:a624e2eeccac 257 *
nxp_ip 0:a624e2eeccac 258 * @param port Selecting output port
nxp_ip 0:a624e2eeccac 259 * 'ALLPORTS' can be used to set all port duty-cycle same value.
nxp_ip 0:a624e2eeccac 260 * @param v A floating-point value representing the output current,
nxp_ip 0:a624e2eeccac 261 * specified as a percentage. The value should lie between
nxp_ip 0:a624e2eeccac 262 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
nxp_ip 0:a624e2eeccac 263 * Values outside this range will have undefined behavior.
nxp_ip 0:a624e2eeccac 264 */
nxp_ip 0:a624e2eeccac 265 void current( int port, float vp );
nxp_ip 0:a624e2eeccac 266
nxp_ip 0:a624e2eeccac 267 /** Set all output port curent, specified as a percentage (array of float)
nxp_ip 0:a624e2eeccac 268 *
nxp_ip 0:a624e2eeccac 269 * @param vp Aray to floating-point values representing the output current,
nxp_ip 0:a624e2eeccac 270 * specified as a percentage. The value should lie between
nxp_ip 0:a624e2eeccac 271 * 0.0f (representing on 0%) and 1.0f (representing on 100%).
nxp_ip 0:a624e2eeccac 272 *
nxp_ip 0:a624e2eeccac 273 * @note
nxp_ip 0:a624e2eeccac 274 * The aray should have length of 16
nxp_ip 0:a624e2eeccac 275 */
nxp_ip 0:a624e2eeccac 276 void current( float *vP );
nxp_ip 0:a624e2eeccac 277
nxp_ip 0:a624e2eeccac 278 /** Register write (single byte) : Low level access to device register
nxp_ip 0:a624e2eeccac 279 *
nxp_ip 0:a624e2eeccac 280 * @param reg_addr Register address
nxp_ip 0:a624e2eeccac 281 * @param data Value for setting into the register
nxp_ip 0:a624e2eeccac 282 */
nxp_ip 0:a624e2eeccac 283 void write( char reg_addr, char data );
nxp_ip 0:a624e2eeccac 284
nxp_ip 0:a624e2eeccac 285 /** Register write (multiple bytes) : Low level access to device register
nxp_ip 0:a624e2eeccac 286 *
nxp_ip 0:a624e2eeccac 287 * @param data Pointer to an array. First 1 byte should be the writing start register address
nxp_ip 0:a624e2eeccac 288 * @param length Length of data
nxp_ip 0:a624e2eeccac 289 */
nxp_ip 0:a624e2eeccac 290 void write( char *data, int length );
nxp_ip 0:a624e2eeccac 291
nxp_ip 0:a624e2eeccac 292 /** Register read (single byte) : Low level access to device register
nxp_ip 0:a624e2eeccac 293 *
nxp_ip 0:a624e2eeccac 294 * @param reg_addr Register address
nxp_ip 0:a624e2eeccac 295 * @return Read value from register
nxp_ip 0:a624e2eeccac 296 */
nxp_ip 0:a624e2eeccac 297 char read( char reg_addr );
nxp_ip 0:a624e2eeccac 298
nxp_ip 0:a624e2eeccac 299 /** Register write (multiple bytes) : Low level access to device register
nxp_ip 0:a624e2eeccac 300 *
nxp_ip 0:a624e2eeccac 301 * @param reg_addr Register address
nxp_ip 0:a624e2eeccac 302 * @param data Pointer to an array. The values are stored in this array.
nxp_ip 0:a624e2eeccac 303 * @param length Length of data
nxp_ip 0:a624e2eeccac 304 */
nxp_ip 0:a624e2eeccac 305 void read( char reg_addr, char *data, int length );
nxp_ip 0:a624e2eeccac 306 #endif
nxp_ip 0:a624e2eeccac 307
nxp_ip 0:a624e2eeccac 308 /** Gradation control setting
nxp_ip 0:a624e2eeccac 309 *
nxp_ip 0:a624e2eeccac 310 * Auto calculation and register setting API for gradation control.
nxp_ip 0:a624e2eeccac 311 * User can set the gradation by specifying cycle, hold-ON/OFF time and ramp-up/down enabling.
nxp_ip 0:a624e2eeccac 312 * All register values are calcurated automatically to have fine gradation setting.
nxp_ip 0:a624e2eeccac 313 * In this routine, the IREF (current) setting is fixed to maximum (i.e. 0xFF)
nxp_ip 0:a624e2eeccac 314 *
nxp_ip 0:a624e2eeccac 315 * @param group Group selector
nxp_ip 0:a624e2eeccac 316 * @param cycle Ramp rate register (RAMP_RATE_GRPn) value
nxp_ip 0:a624e2eeccac 317 * @param flag_on Holding time for ON can be selected from available constants.
nxp_ip 0:a624e2eeccac 318 * Those are 0, 0.25, 0.5, 0.75, 1, 2, 4 and 6 seconds.
nxp_ip 0:a624e2eeccac 319 * Use one of next words: HOLD_0_00_SEC, HOLD_0_25_SEC, HOLD_0_50_SEC, HOLD_0_75_SEC, HOLD_1_00_SEC, HOLD_2_00_SEC, HOLD_4_00_SEC or HOLD_6_00_SEC
nxp_ip 0:a624e2eeccac 320 * @param flag_off Holding time for OFF can be selected from available constants.
nxp_ip 0:a624e2eeccac 321 * Those are 0, 0.25, 0.5, 0.75, 1, 2, 4 and 6 seconds.
nxp_ip 0:a624e2eeccac 322 * Use one of next words: HOLD_0_00_SEC, HOLD_0_25_SEC, HOLD_0_50_SEC, HOLD_0_75_SEC, HOLD_1_00_SEC, HOLD_2_00_SEC, HOLD_4_00_SEC or HOLD_6_00_SEC
nxp_ip 0:a624e2eeccac 323 * @param ramp_flag Choose one from next words : NO_RAMP, RAMP_UP_ONLY, RAMP_DOWN_ONLY or RAMP_UP_DOWN
nxp_ip 0:a624e2eeccac 324 *
nxp_ip 0:a624e2eeccac 325 * @return calculated actual time for one cycle (in seconds)
nxp_ip 0:a624e2eeccac 326 *
nxp_ip 0:a624e2eeccac 327 * @see gradation_setting()
nxp_ip 0:a624e2eeccac 328 */
nxp_ip 0:a624e2eeccac 329 float gradation_ramp_setting( char group, float cycle, char flag_on, char flag_off, int ramp_flag );
nxp_ip 0:a624e2eeccac 330
nxp_ip 0:a624e2eeccac 331 /** Gradation control: Port assignment to group
nxp_ip 0:a624e2eeccac 332 *
nxp_ip 0:a624e2eeccac 333 * Each ports which is going to use in gradation control should be assigned to group.
nxp_ip 0:a624e2eeccac 334 * This function help to assign the port to 1 of 4 groups.
nxp_ip 0:a624e2eeccac 335 *
nxp_ip 0:a624e2eeccac 336 * @param group Target group
nxp_ip 0:a624e2eeccac 337 * @param port A output port which is being assigned to the target group
nxp_ip 0:a624e2eeccac 338 */
nxp_ip 0:a624e2eeccac 339 void gradation_group_setting( char group, char port );
nxp_ip 0:a624e2eeccac 340
nxp_ip 0:a624e2eeccac 341 /** Gradation control: Start
nxp_ip 0:a624e2eeccac 342 *
nxp_ip 0:a624e2eeccac 343 * @param group Group selector
nxp_ip 0:a624e2eeccac 344 * @param continuous_flag (option) Set false for one-shot operation
nxp_ip 0:a624e2eeccac 345 */
nxp_ip 0:a624e2eeccac 346 void gradation_start( char group, char continuous_flag = true );
nxp_ip 0:a624e2eeccac 347
nxp_ip 0:a624e2eeccac 348 /** Gradation control: Stop
nxp_ip 0:a624e2eeccac 349 *
nxp_ip 0:a624e2eeccac 350 */
nxp_ip 0:a624e2eeccac 351 void gradation_stop( void );
nxp_ip 0:a624e2eeccac 352
nxp_ip 0:a624e2eeccac 353
nxp_ip 0:a624e2eeccac 354 /** Gradation control: Clear all group assignments
nxp_ip 0:a624e2eeccac 355 *
nxp_ip 0:a624e2eeccac 356 * Set all output port operation to no-gradation control
nxp_ip 0:a624e2eeccac 357 *
nxp_ip 0:a624e2eeccac 358 */
nxp_ip 0:a624e2eeccac 359 void gradation_group_clear( void );
nxp_ip 0:a624e2eeccac 360
nxp_ip 0:a624e2eeccac 361 /** Setting gradation control registers (low level setting API)
nxp_ip 0:a624e2eeccac 362 *
nxp_ip 0:a624e2eeccac 363 * @param group Group selector
nxp_ip 0:a624e2eeccac 364 * @param ramp_rate Ramp rate register (RAMP_RATE_GRPn) value
nxp_ip 0:a624e2eeccac 365 * @param step_time Step time register (STEP_TIME_GRPn) value
nxp_ip 0:a624e2eeccac 366 * @param hold_cntl Hold control register (HOLD_CNTL_GRPn) value
nxp_ip 0:a624e2eeccac 367 * @param iref IREF (current setting) register (IREF_GRPn) value
nxp_ip 0:a624e2eeccac 368 *
nxp_ip 0:a624e2eeccac 369 * @see gradation_ramp_setting()
nxp_ip 0:a624e2eeccac 370 */
nxp_ip 0:a624e2eeccac 371 void gradation_setting( int group, char ramp_rate, char step_time, char hold_cntl, char iref );
nxp_ip 0:a624e2eeccac 372
nxp_ip 0:a624e2eeccac 373 /** Setting gradation register dump (for debugging)
nxp_ip 0:a624e2eeccac 374 *
nxp_ip 0:a624e2eeccac 375 */
nxp_ip 0:a624e2eeccac 376 void dump_gradation_registers( void );
nxp_ip 0:a624e2eeccac 377
nxp_ip 0:a624e2eeccac 378 private:
nxp_ip 0:a624e2eeccac 379 void initialize( void );
nxp_ip 0:a624e2eeccac 380 virtual char pwm_register_access( int port );
nxp_ip 0:a624e2eeccac 381 virtual char current_register_access( int port );
nxp_ip 0:a624e2eeccac 382
nxp_ip 0:a624e2eeccac 383 void group_selector( short g0, short g1, short g2, short g3 );
nxp_ip 0:a624e2eeccac 384
nxp_ip 0:a624e2eeccac 385 const int n_of_ports;
nxp_ip 0:a624e2eeccac 386 static char gradation_group[];
nxp_ip 0:a624e2eeccac 387 }
nxp_ip 0:a624e2eeccac 388 ;
nxp_ip 0:a624e2eeccac 389
nxp_ip 0:a624e2eeccac 390 /** Constants for Gradation control */
nxp_ip 0:a624e2eeccac 391 enum GradationControlConstants {
nxp_ip 0:a624e2eeccac 392 CONTINUOUS = 1,
nxp_ip 0:a624e2eeccac 393 NOGROUP = 0xFF
nxp_ip 0:a624e2eeccac 394 };
nxp_ip 0:a624e2eeccac 395
nxp_ip 0:a624e2eeccac 396 /** Flags for Gradation control (Ramp selector) */
nxp_ip 0:a624e2eeccac 397 enum GradationControlRampSelector {
nxp_ip 0:a624e2eeccac 398 NO_RAMP = 0x0,
nxp_ip 0:a624e2eeccac 399 RAMP_UP_ONLY,
nxp_ip 0:a624e2eeccac 400 RAMP_DOWN_ONLY,
nxp_ip 0:a624e2eeccac 401 RAMP_UP_DOWN
nxp_ip 0:a624e2eeccac 402 };
nxp_ip 0:a624e2eeccac 403
nxp_ip 0:a624e2eeccac 404 /** Flags for Gradation control (Hold time selector) */
nxp_ip 0:a624e2eeccac 405 enum GradationControlHoldTimeSelector {
nxp_ip 0:a624e2eeccac 406 HOLD_0_00_SEC = 0x0,
nxp_ip 0:a624e2eeccac 407 HOLD_0_25_SEC,
nxp_ip 0:a624e2eeccac 408 HOLD_0_50_SEC,
nxp_ip 0:a624e2eeccac 409 HOLD_0_75_SEC,
nxp_ip 0:a624e2eeccac 410 HOLD_1_00_SEC,
nxp_ip 0:a624e2eeccac 411 HOLD_2_00_SEC,
nxp_ip 0:a624e2eeccac 412 HOLD_4_00_SEC,
nxp_ip 0:a624e2eeccac 413 HOLD_6_00_SEC
nxp_ip 0:a624e2eeccac 414 };
nxp_ip 0:a624e2eeccac 415
nxp_ip 0:a624e2eeccac 416 #endif // MBED_PCA9955A