A feature complete driver for the PCA9952/55 LED driver from NXP.

Dependents:   PCA9955_HelloWorld

Revision:
1:016f916c5579
Parent:
0:7b3cbb5a53b8
Child:
2:9d866639b32b
--- a/PCA9955.h	Tue Nov 05 21:16:25 2013 +0000
+++ b/PCA9955.h	Thu Nov 07 21:16:07 2013 +0000
@@ -162,24 +162,24 @@
      */
     PCA9955(PinName sda, PinName scl, Address addr = ADDRESS_0);
 
-    /** Probe for the PCA9952/55 and indicate whether it is present on the bus
+    /** Probe for the PCA9952/55 and configure Auto-Increment if present
      *
      * @returns
      *   'true' if the device exists on the bus,
      *   'false' if the device doesn't exist on the bus.
      */
-    bool open(void);
+    bool open();
 
     /** Issue an SWRST call to reset the PCA9952/55
      * @warning This might reset other I2C devices as well!
      */
-    void reset(void);
+    void reset();
 
     /** Determine whether the LED All Call address is enabled on the PCA9952/55
      *
      * @returns Whether or not the LED All Call address is enabled.
      */
-    bool allCallEnabled(void);
+    bool allCallEnabled();
 
     /** Set whether the LED All Call address is enabled on the PCA9952/55
      *
@@ -191,7 +191,7 @@
      *
      * @returns Whether or not subaddress 3 is enabled.
      */
-    bool subCall3Enabled(void);
+    bool subCall3Enabled();
 
     /** Set whether subaddress 3 is enabled on the PCA9952/55
      *
@@ -203,7 +203,7 @@
      *
      * @returns Whether or not subaddress 2 is enabled.
      */
-    bool subCall2Enabled(void);
+    bool subCall2Enabled();
 
     /** Set whether subaddress 2 is enabled on the PCA9952/55
      *
@@ -215,7 +215,7 @@
      *
      * @returns Whether or not subaddress 1 is enabled.
      */
-    bool subCall1Enabled(void);
+    bool subCall1Enabled();
 
     /** Set whether subaddress 1 is enabled on the PCA9952/55
      *
@@ -227,7 +227,7 @@
      *
      * @returns The current power mode as a PowerMode enum.
      */
-    PCA9955::PowerMode powerMode(void);
+    PCA9955::PowerMode powerMode();
 
     /** Set the power mode of the PCA9952/55
      *
@@ -239,7 +239,7 @@
      *
      * @returns The current output change mode as an OutputChangeMode enum.
      */
-    PCA9955::OutputChangeMode outputChangeMode(void);
+    PCA9955::OutputChangeMode outputChangeMode();
 
     /** Set the output change mode of the PCA9952/55
      *
@@ -251,7 +251,7 @@
      *
      * @returns The current group control mode as a GroupMode enum.
      */
-    PCA9955::GroupMode groupMode(void);
+    PCA9955::GroupMode groupMode();
 
     /** Set the group control mode of the PCA9952/55
      *
@@ -265,7 +265,7 @@
      *   'true' if the device is currently disabled due to overheating,
      *   'false' if the device is functioning normally.
      */
-    bool overTemp(void);
+    bool overTemp();
 
     /** Get the specified output's state
      *
@@ -286,7 +286,7 @@
      *
      * @returns The current group control duty cycle as a float (0.0 to 1.0).
      */
-    float groupDuty(void);
+    float groupDuty();
 
     /** Set the group control duty cycle of the PCA9952/55 in percent
      *
@@ -298,7 +298,7 @@
      *
      * @returns The current group control duty cycle as an unsigned char (0 to 255).
      */
-    char groupDuty_char(void);
+    char groupDuty_char();
 
     /** Set the group control duty cycle of the PCA9952/55
      *
@@ -310,7 +310,7 @@
      *
      * @returns The current group control blink period in seconds (0.067 to 16.8).
      */
-    float groupBlinkPeriod(void);
+    float groupBlinkPeriod();
 
     /** Set the current group control blink period of the PCA9952/55 in seconds
      *
@@ -322,7 +322,7 @@
      *
      * @returns The current group control blink period as an unsigned char (0 to 255).
      */
-    char groupBlinkPeriod_char(void);
+    char groupBlinkPeriod_char();
 
     /** Set the current group control blink period of the PCA9952/55
      *
@@ -394,7 +394,7 @@
      *
      * @returns The turn-on delay between LEDn outputs in clocks (0 to 15 - 125ns per clock).
      */
-    char outputDelay(void);
+    char outputDelay();
 
     /** Set the specified output's current reference
      *
@@ -406,7 +406,7 @@
      *
      * @returns The current I2C subaddress 1.
      */
-    char subCall1Addr(void);
+    char subCall1Addr();
 
     /** Set subaddress 1
      *
@@ -418,7 +418,7 @@
      *
      * @returns The current I2C subaddress 2.
      */
-    char subCall2Addr(void);
+    char subCall2Addr();
 
     /** Set subaddress 2
      *
@@ -430,7 +430,7 @@
      *
      * @returns The current I2C subaddress 3.
      */
-    char subCall3Addr(void);
+    char subCall3Addr();
 
     /** Set subaddress 3
      *
@@ -442,7 +442,7 @@
      *
      * @returns The current LED All Call address.
      */
-    char allCallAddr(void);
+    char allCallAddr();
 
     /** Set the LED All Call address
      *
@@ -450,41 +450,97 @@
      */
     void allCallAddr(char addr);
 
-    /** Set all of the output states at once
+    /** Set all of the output states to the same state
      *
      * @param state The new output state for all outputs.
      */
     void allOutputStates(OutputState state);
 
-    /** Set all of the output duties at once in percent
+    /** Read all of the output duty cycles into an array as percents
+     *
+     * @param duties Pointer to any array for 16 duty cycles as floats (0.0 to 1.0).
+     */
+    void getOutputDuties(float* duties);
+
+    /** 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).
      */
     void allOutputDuties(float duty);
 
-    /** Set all of the output duties at once
+    /** 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).
+     */
+    void allOutputDuties(float* duties);
+
+    /** Read all of the output duty cycles into an array
+     *
+     * @param duties Pointer to any array for 16 duty cycles as unsigned chars (0 to 255).
+     */
+    void getOutputDuties_char(char* duties);
+
+    /** 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).
      */
     void allOutputDuties_char(char duty);
 
-    /** Set all of the output current references at once in percent
+    /** 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).
+     */
+    void allOutputDuties_char(char* duties);
+
+    /** Read all of the output current references into an array as percents
+     *
+     * @param irefs Pointer to any array for 16 current references as floats (0.0 to 1.0).
+     */
+    void getOutputCurrents(float* irefs);
+
+    /** 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).
      */
     void allOutputCurrents(float iref);
 
-    /** Set all of the output current references at once
+    /** 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).
+     */
+    void allOutputCurrents(float* irefs);
+
+    /** Read all of the output current references into an array
+     *
+     * @param irefs Pointer to any array for 16 current references as unsigned chars (0 to 255).
+     */
+    void getOutputCurrents_char(char* irefs);
+
+    /** 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).
      */
     void allOutputCurrents_char(char iref);
 
+    /** 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).
+     */
+    void allOutputCurrents_char(char* irefs);
+
     /** Perform a fault test on all enabled outputs
      *
      * @returns The fault test flags as FaultFlags enum values OR'd together.
      */
-    unsigned short faultTest(void);
+    unsigned short faultTest();
+
+#ifdef MBED_OPERATORS
+    /** A shorthand for allOutputDuties()
+     *
+     * @param value The new duty cycle for all outputs as a float (0.0 to 1.0).
+     */
+    PCA9955& operator=(float value);
+#endif
 
 private:
     //I2C register addresses
@@ -546,12 +602,12 @@
 
     //Member variables
     I2C m_I2C;
-    int m_Addr;
+    const int m_ADDR;
 
     //Internal functions
     char read(char reg);
+    void write(char reg, char data);
     void readMulti(char startReg, char* data, int length);
-    void write(char reg, char data);
     void writeMulti(char* data, int length);
 };