MAX14661 Serial Controlled 16:2 Multiplexer

Dependents:   MBD2PMD_WebServer ARD2PMD_WebServer MAX14661_DEMO MAX3232_DEMO

Revision:
0:6bd0b1a28e10
Child:
1:4b0d22958890
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MAX14661.h	Mon Feb 03 04:14:24 2014 +0000
@@ -0,0 +1,139 @@
+/* MAX14661 Driver Library
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef MAX14661_H
+#define MAX14661_H
+
+#include "mbed.h"
+
+/** MAX14661 Library, Provides utilities for configuring the MAX14661 over I2C
+ *
+ * Example:
+ * @code
+ * // Enable only switch B3 and read back switch state.
+ *
+ * #include "MAX14661.h"
+ *
+ * MAX14661 mux(p28, p27);
+ *
+ * int main() {
+ *     mux.setAB(0x0000, MAX14661::SW03);
+ *     printf("mux = 0x%08X\n", mux.read());
+ *     mux.clearAll();
+ *     printf("mux = 0x%08X\n", mux.read());
+ * }
+ * @endcode
+ */
+class MAX14661
+{
+public:
+
+    /** Create a MAX14661 interface
+     *
+     * @param sda I2C data line pin
+     * @param scl I2C clock line pin
+     * @param addr MAX14661 I2C address
+     */
+    MAX14661(PinName sda, PinName scl, int addr = 0x98);
+
+    ~MAX14661();
+
+    /** Name the register addresses
+    */
+    enum MAX14661regs {
+        REG_DIR0 = 0x00,
+        REG_DIR1,
+        REG_DIR2,
+        REG_DIR3,
+        REG_SHDW0 = 0x10,
+        REG_SHDW1,
+        REG_SHDW2,
+        REG_SHSW3,
+        REG_CMD_A,
+        REG_CMD_B
+    };
+
+    /** Name the command codes
+    */
+    enum MAX14661cmds {
+        CMD_EN01 = 0x00,
+        CMD_EN02,
+        CMD_EN03,
+        CMD_EN04,
+        CMD_EN05,
+        CMD_EN06,
+        CMD_EN07,
+        CMD_EN08,
+        CMD_EN09,
+        CMD_EN10,
+        CMD_EN11,
+        CMD_EN12,
+        CMD_EN13,
+        CMD_EN14,
+        CMD_EN15,
+        CMD_EN16,
+        CMD_DIS,
+        CMD_COPY,
+        CMD_NOOP = 0x1F
+    };
+
+    /** Name the switch bits
+    */
+    enum MAX14661sws {
+        SW01 = (1 << 0),
+        SW02 = (1 << 1),
+        SW03 = (1 << 2),
+        SW04 = (1 << 3),
+        SW05 = (1 << 4),
+        SW06 = (1 << 5),
+        SW07 = (1 << 6),
+        SW08 = (1 << 7),
+        SW09 = (1 << 8),
+        SW10 = (1 << 9),
+        SW11 = (1 << 10),
+        SW12 = (1 << 11),
+        SW13 = (1 << 12),
+        SW14 = (1 << 13),
+        SW15 = (1 << 14),
+        SW16 = (1 << 15)
+    };
+
+    /** Clears all bits to opens all 32 switches
+     */
+    void clearAll();
+
+    /** Set all 32 switches simultaneously
+     *
+     *  @param swA the desired state of switches [A16 - A01]
+     *  @param swB the desired state of switches [B16 - B01]
+     */
+    void setAB(int swA, int swB);
+
+    /** Read the status of all 32 switches concatenated into a single int
+     *
+     *  @returns
+     *    the switch states [B16-B01,A16-A1]
+     */
+    int read();
+
+private:
+    I2C _i2c;
+    int _addr;
+};
+
+#endif
\ No newline at end of file