A feature complete driver for the PCA9952/55 LED driver from NXP.
Dependents: PCA9955_HelloWorld
Diff: PCA9955.h
- Revision:
- 7:7dd3cc73e873
- Parent:
- 6:c8dc0211e18c
- Child:
- 8:12a800c51b35
--- a/PCA9955.h Tue Apr 08 15:21:28 2014 +0000 +++ b/PCA9955.h Tue Apr 08 17:43:57 2014 +0000 @@ -27,8 +27,8 @@ * #include "mbed.h" * #include "PCA9955.h" * - * //Create a PCA9955 object using the LED All Call address - * PCA9955 driver(p28, p27, PCA9955::ADDRESS_ALL); + * //Create a PCA9955 object at the default address (ADDRESS_0) + * PCA9955 driver(p28, p27); * * int main() * { @@ -49,9 +49,8 @@ * * while (1) { * //Generate a breathing effect on all of the outputs - * for (float i = 0.0f; i < 360.0f; i += 0.1f) { + * for (float i = 0.0f; i < 360.0f; i += 0.1f) * driver = 0.5 * (sinf(i * 3.14159265f / 180.0f) + 1); - * } * } * } else { * error("Device not detected!\n"); @@ -80,9 +79,7 @@ ADDRESS_12 = (0x6C << 1), /**< A[3:0] pins = 1100 (not available on PCA9952) */ ADDRESS_13 = (0x6D << 1), /**< A[3:0] pins = 1101 (not available on PCA9952) */ ADDRESS_14 = (0x6E << 1), /**< A[3:0] pins = 1110 (not available on PCA9952) */ - ADDRESS_15 = (0x6F << 1), /**< A[3:0] pins = 1111 (not available on PCA9952) */ - ADDRESS_ALL = (0x70 << 1), /**< The default LED All Call address */ - ADDRESS_SUB = (0x76 << 1) /**< The default subaddress for 16-channel LED drivers */ + ADDRESS_15 = (0x6F << 1) /**< A[3:0] pins = 1111 (not available on PCA9952) */ }; /** Represents the different outputs of the PCA9952/55 @@ -157,6 +154,14 @@ FAULT_OUTPUT_15 = (1 << 15) /**< LED output 15 is either open or shorted */ }; + /** The default LED All Call address + */ + static const int ALLCALL_ADDRESS = (0x70 << 1); + + /** The default subaddress for 16-channel LED drivers + */ + static const int SUBCALL_ADDRESS = (0x76 << 1); + /** Create a PCA9952/55 object connected to the specified I2C pins with the specified I2C slave address * * @param sda The I2C data pin. @@ -165,15 +170,7 @@ */ PCA9955(PinName sda, PinName scl, Address addr = ADDRESS_0); - /** Create a PCA9952/55 object connected to the specified I2C pins with a custom I2C slave address - * - * @param sda The I2C data pin. - * @param scl The I2C clock pin. - * @param addr The custom I2C slave address (a modified subaddress or LED All Call address). - */ - PCA9955(PinName sda, PinName scl, int addr); - - /** Probe for the PCA9952/55 and configure auto-increment if present + /** Probe for the PCA9952/55 and indicate if it's present on the bus * * @returns * 'true' if the device exists on the bus, @@ -305,8 +302,9 @@ /** Set the group control duty cycle of the PCA9952/55 in percent * * @param duty The new group control duty cycle as a float (0.0 to 1.0). + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void groupDuty(float duty); + void groupDuty(float duty, int altAddr = NULL); /** Get the current group control duty cycle of the PCA9952/55 * @@ -317,8 +315,9 @@ /** Set the group control duty cycle of the PCA9952/55 * * @param duty The new group control duty cycle as an unsigned char (0 to 255). + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void groupDuty_char(char duty); + void groupDuty_char(char duty, int altAddr = NULL); /** Get the current group control blink period of the PCA9952/55 in seconds * @@ -329,8 +328,9 @@ /** Set the current group control blink period of the PCA9952/55 in seconds * * @param period The new group control blink period in seconds (0.067 to 16.8). + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void groupBlinkPeriod(float period); + void groupBlinkPeriod(float period, int altAddr = NULL); /** Get the current group control blink period of the PCA9952/55 * @@ -341,8 +341,9 @@ /** Set the current group control blink period of the PCA9952/55 * * @param period The new group control blink period as an unsigned char (0 to 255). + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void groupBlinkPeriod_char(char period); + void groupBlinkPeriod_char(char period, int altAddr = NULL); /** Get the specified output's duty cycle in percent * @@ -356,8 +357,9 @@ * * @param output The output to change. * @param duty The new output duty cycle as a float (0.0 to 1.0). + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void outputDuty(Output output, float duty); + void outputDuty(Output output, float duty, int altAddr = NULL); /** Get the specified output's duty cycle * @@ -371,8 +373,9 @@ * * @param output The output to change. * @param duty The new output duty cycle as an unsigned char (0 to 255). + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void outputDuty_char(Output output, char duty); + void outputDuty_char(Output output, char duty, int altAddr = NULL); /** Get the specified output's current reference in percent * @@ -386,8 +389,9 @@ * * @param output The output to change. * @param iref The new output current reference as a float (0.0 to 1.0). + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void outputCurrent(Output output, float iref); + void outputCurrent(Output output, float iref, int altAddr = NULL); /** Get the specified output's current reference * @@ -401,8 +405,9 @@ * * @param output The output to change. * @param iref The new output current reference as an unsigned char (0 to 255). + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void outputCurrent_char(Output output, char iref); + void outputCurrent_char(Output output, char iref, int altAddr = NULL); /** Get the turn-on delay between LEDn outputs * @@ -413,8 +418,9 @@ /** Set the specified output's current reference * * @param clocks The turn-on delay between LEDn outputs in clocks (0 to 15 - 125ns per clock). + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void outputDelay(char clocks); + void outputDelay(char clocks, int altAddr = NULL); /** Get subaddress 1 * @@ -425,8 +431,9 @@ /** Set subaddress 1 * * @param addr The new I2C subaddress 1. + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void subCall1Addr(char addr); + void subCall1Addr(char addr, int altAddr = NULL); /** Get subaddress 2 * @@ -437,8 +444,9 @@ /** Set subaddress 2 * * @param addr The new I2C subaddress 2. + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void subCall2Addr(char addr); + void subCall2Addr(char addr, int altAddr = NULL); /** Get subaddress 3 * @@ -449,8 +457,9 @@ /** Set subaddress 3 * * @param addr The new I2C subaddress 3. + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void subCall3Addr(char addr); + void subCall3Addr(char addr, int altAddr = NULL); /** Get the LED All Call address * @@ -461,14 +470,16 @@ /** Set the LED All Call address * * @param addr The new LED All Call address. + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void allCallAddr(char addr); + void allCallAddr(char addr, int altAddr = NULL); /** Set all of the output states to the same state * * @param state The new output state for all outputs. + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void allOutputStates(OutputState state); + void allOutputStates(OutputState state, int altAddr = NULL); /** Read all of the output duty cycles into an array as percents * @@ -479,14 +490,16 @@ /** Set all of the output duty cycles to the same value in percent * * @param duty The new duty cycle for all outputs as a float (0.0 to 1.0). + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void allOutputDuties(float duty); + void allOutputDuties(float duty, int altAddr = NULL); /** Set all of the output duty cycles from an array of percents * * @param duties Pointer to any array of 16 duty cycles as floats (0.0 to 1.0). + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void allOutputDuties(float* duties); + void allOutputDuties(float* duties, int altAddr = NULL); /** Read all of the output duty cycles into an array * @@ -497,14 +510,16 @@ /** Set all of the output duty cycles to the same value * * @param duty The new duty cycle for all outputs as an unsigned char (0 to 255). + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void allOutputDuties_char(char duty); + void allOutputDuties_char(char duty, int altAddr = NULL); /** Set all of the output duty cycles from an array * * @param duties Pointer to any array of 16 duty cycles as unsigned chars (0 to 255). + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void allOutputDuties_char(char* duties); + void allOutputDuties_char(char* duties, int altAddr = NULL); /** Read all of the output current references into an array as percents * @@ -515,14 +530,16 @@ /** Set all of the output current references to the same value in percent * * @param iref The new current reference for all outputs as a float (0.0 to 1.0). + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void allOutputCurrents(float iref); + void allOutputCurrents(float iref, int altAddr = NULL); /** Set all of the output current references from an array of percents * * @param irefs Pointer to any array of 16 current references as floats (0.0 to 1.0). + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void allOutputCurrents(float* irefs); + void allOutputCurrents(float* irefs, int altAddr = NULL); /** Read all of the output current references into an array * @@ -533,14 +550,16 @@ /** Set all of the output current references to the same value * * @param iref The new current reference for all outputs as an unsigned char (0 to 255). + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void allOutputCurrents_char(char iref); + void allOutputCurrents_char(char iref, int altAddr = NULL); /** Set all of the output current references from an array * * @param irefs Pointer to any array of 16 current references as unsigned chars (0 to 255). + * @param altAddr An optional, alternate address such as a subaddress or LED All Call address (defaults to NULL). */ - void allOutputCurrents_char(char* irefs); + void allOutputCurrents_char(char* irefs, int altAddr = NULL); /** Perform a fault test on all enabled outputs * @@ -620,9 +639,9 @@ //Internal functions char read(char reg); - void write(char reg, char data); + void write(int addr, char reg, char data); void readMulti(char startReg, char* data, int length); - void writeMulti(char* data, int length); + void writeMulti(int addr, char* data, int length); }; #endif