Driver for a CD22M3494 cross point switcher

Library description

The CD22M3494 is a 16x8 crosspoint switch matrix, it can be used in any configuration i.e. 16 ins' 8 outs' or 16 outs' and 8 ins'. Control of the chip is pretty simple there are two parallel address buses a 4 byte address controls the X axis (16 IO pins) and a 3 byte address controls the Y axis (8 IO pins). A data bus says whether to open or close the switch and a 'strobe' bus actually performs the switch. This library provides a simple interface to control the CD22M3494 and provides a mechanism to associate source and destinations in pairs and switch the pairs via their names.

Revision:
4:6ffeb0008f11
Parent:
3:fa46a8badc92
Child:
5:ca315c82dc1b
--- a/CD22M3494.h	Wed Sep 11 11:54:24 2013 +0000
+++ b/CD22M3494.h	Thu Sep 19 11:53:21 2013 +0000
@@ -25,23 +25,40 @@
  1   1   1   0    X14
  1   1   1   1    X15
 */
+#define X0 "X0"
+#define X1 "X1"
+#define X2 "X2"
+#define X3 "X3"
+#define X4 "X4"
+#define X5 "X5"
+#define X6 "X6"
+#define X7 "X7"
+#define X8 "X8"
+#define X9 "X9"
+#define X10 "X10"
+#define X11 "X11"
+#define X12 "X12"
+#define X13 "X13"
+#define X14 "X14"
+#define X15 "X15"
 
-#define X0 0x00
-#define X1 0x01
-#define X2 0x02
-#define X3 0x03
-#define X4 0x04
-#define X5 0x05
-#define X12 0x06
-#define X13 0x07
-#define X6 0x08
-#define X7 0x09
-#define X8 0x0A
-#define X9 0x0B
-#define X10 0x0C
-#define X11 0x0D
-#define X14 0x0E
-#define X15 0x0F
+
+#define X0I 0x00
+#define X1I 0x01
+#define X2I 0x02
+#define X3I 0x03
+#define X4I 0x04
+#define X5I 0x05
+#define X12I 0x06
+#define X13I 0x07
+#define X6I 0x08
+#define X7I 0x09
+#define X8I 0x0A
+#define X9I 0x0B
+#define X10I 0x0C
+#define X11I 0x0D
+#define X14I 0x0E
+#define X15I 0x0F
 
 /*
 Y ADDRESS
@@ -56,14 +73,23 @@
  1   1   1    Y7
 */
 
-#define Y0 0x0
-#define Y1 0x1
-#define Y2 0x2
-#define Y3 0x3
-#define Y4 0x4
-#define Y5 0x5
-#define Y6 0x6
-#define Y7 0x7
+#define Y0I 0x0
+#define Y1I 0x1
+#define Y2I 0x2
+#define Y3I 0x3
+#define Y4I 0x4
+#define Y5I 0x5
+#define Y6I 0x6
+#define Y7I 0x7
+
+#define Y0 "Y0"
+#define Y1 "Y1"
+#define Y2 "Y2"
+#define Y3 "Y3"
+#define Y4 "Y4"
+#define Y5 "Y5"
+#define Y6 "Y6"
+#define Y7 "Y7"
 
 #define MAX_X 0x0F
 #define MAX_Y 0x7
@@ -72,100 +98,162 @@
 
 public:
 
+    /**Conucts a new CD22M3494 object
+     *
+     * @param x0 the pin name for the first byte of the x axis address
+     * @param x1 the pin name for the second byte of the x axis address
+     * @param x2 the pin name for the thrid byte of the x axis address
+     * @param x3 the pin name for the forth byte of the x axis address
+     * @param y0 the pin name for the first byte of the y axis address
+     * @param y1 the pin name for the second byte of the y axis address
+     * @param y2 the pin name for the thrid byte of the y axis address
+     * @param d the pin name for the data bus
+     * @param str the pin name for the strobe bus
+     * @param rs the pin name for reset.
+     */
     CD22M3494(PinName x0, PinName x1, PinName x2, PinName x3, PinName y0, PinName y1, PinName y2, PinName d, PinName str, PinName rs) {
         xbus = new BusOut(x0, x1, x2, x3);
         ybus = new BusOut(y0, y1, y2);
         data = new DigitalOut(d);
-        strobe = new DigitalOut(str);
+        obe = new DigitalOut(str);
         reset = new DigitalOut(rs);
         data->write(0);
-        strobe->write(0);
+        obe->write(0);
         reset->write(0);
+        crosspointLookup[X0] = X0I;
+        crosspointLookup[X1] = X1I;
+        crosspointLookup[X2] = X2I;
+        crosspointLookup[X3] = X3I;
+        crosspointLookup[X4] = X4I;
+        crosspointLookup[X5] = X5I;
+        crosspointLookup[X6] = X6I;
+        crosspointLookup[X7] = X7I;
+        crosspointLookup[X8] = X8I;
+        crosspointLookup[X9] = X9I;
+        crosspointLookup[X10] = X10I;
+        crosspointLookup[X11] = X11I;
+        crosspointLookup[X12] = X12I;
+        crosspointLookup[X13] = X13I;
+        crosspointLookup[X14] = X14I;
+        crosspointLookup[X15] = X15I;
+        crosspointLookup[Y0] = Y0I;
+        crosspointLookup[Y1] = Y1I;
+        crosspointLookup[Y2] = Y2I;
+        crosspointLookup[Y3] = Y3I;
+        crosspointLookup[Y4] = Y4I;
+        crosspointLookup[Y5] = Y5I;
+        crosspointLookup[Y6] = Y6I;
+        crosspointLookup[Y7] = Y7I;
     }
     
     ~CD22M3494() {
         delete xbus;
         delete ybus;
         delete data;
-        delete strobe;
+        delete obe;
         delete reset;
         associationTable.clear();
         delete &associationTable;
     }
     
+    /**Closes the switch at the given cross point.
+     *
+     * @param x the x axis
+     * @param y the y axis
+     */
     bool crossPointConnect(unsigned short x, unsigned short y) {
         if (x <= MAX_X && y <= MAX_Y) {
             data->write(1);
             xbus->write(x);
             ybus->write(y);
-            // let the data busses settle before setting strobe high
+            // let the data busses settle before setting obe high
             wait_us(2);
-            strobe->write(1);
-            // strobe must be high for at least 20 ns
+            obe->write(1);
+            // obe must be high for at least 20 ns
             wait_us(1);
-            strobe->write(0);       
+            obe->write(0);       
             return true; 
         }
         return false;
     }
 
+    /**Opens the switch at the given cross point.
+     *
+     * @param x the x axis
+     * @param y the y axis
+     */
     bool crossPointDisconnect(unsigned short x, unsigned short y) {
         if (x <= MAX_X && y <= MAX_Y) {
             data->write(0);
             xbus->write(x);
             ybus->write(y);
-            // let the data busses settle before setting strobe high
+            // let the data busses settle before setting obe high
             wait_us(2);
-            strobe->write(1);
-            // strobe must be high for at least 20 ns
+            obe->write(1);
+            // obe must be high for at least 20 ns
             wait_us(1);
-            strobe->write(0);
+            obe->write(0);
             return true;        
         }
         return false;
     }
     
-    void associate(string name, unsigned short xp1, unsigned short xp2) {
-        unsigned short *xps = new unsigned short[2];
-        xps[0] = xp1;
-        xps[1] = xp2;
-        associationTable[name] = xps;
+    /**Associated the two given crosspoint with the given name, note, both crosspoint MUST be on the same axis.
+     *
+     * @param name the name of the association
+     * @param xp1 the first crosspoint to associate with the given name
+     * @param xp2 the second crosspoint to associate with the given name
+     */
+    bool associate(string name, string xp1, string xp2) {
+        if (crosspointLookup.count(xp1) && crosspointLookup.count(xp2)) {
+            Association *assoc = new Association();
+            assoc->xp1 = xp1;
+            assoc->xp2 = xp2;
+            associationTable[name] = assoc;
+        }
     }
     
+    /**Connects all the crosspoints for the given associations.
+     * 
+     * @param src the source association
+     * @param dst the destination to connect the source to.
+     */
     bool routeAssociations(string src, string dst) {
         if (associationTable.count(src) && associationTable.count(dst)) {
-            crossPointConnect(associationTable[src][0], associationTable[dst][0]);
-            crossPointConnect(associationTable[src][1], associationTable[dst][1]);
+            crossPointConnect(crosspointLookup[associationTable[src]->xp1], crosspointLookup[associationTable[dst]->xp1]);
+            crossPointConnect(crosspointLookup[associationTable[src]->xp2], crosspointLookup[associationTable[dst]->xp2]);
             return true;
         }
         return false;    
     }
     
+    /**Disconnects all the crosspoints for the given associations.
+     * 
+     * @param src the source association
+     * @param dst the destination to disconnect from the source.
+     */
     bool unRouteAssociations(string src, string dst) {
         if (associationTable.count(src) && associationTable.count(dst)) {
-            crossPointDisconnect(associationTable[src][0], associationTable[dst][0]);
-            crossPointDisconnect(associationTable[src][1], associationTable[dst][1]);
+            crossPointDisconnect(crosspointLookup[associationTable[src]->xp1], crosspointLookup[associationTable[dst]->xp1]);
+            crossPointDisconnect(crosspointLookup[associationTable[src]->xp2], crosspointLookup[associationTable[dst]->xp2]);
             return true;
         }
         return false;            
     }
-    
-    bool getAssociation(string name, unsigned short *xps) {
-        if (associationTable.count(name)) {
-            xps[0] = associationTable[name][0];
-            xps[1] = associationTable[name][1];
-            return true;
-        }
-        return false;
-    }
-    
+        
 private:
     BusOut *xbus;
     BusOut *ybus;
     DigitalOut *data;
-    DigitalOut *strobe;
-    DigitalOut *reset;      
-    map<string, unsigned short*> associationTable; 
+    DigitalOut *obe;
+    DigitalOut *reset;  
+    struct Association {
+        string name;
+        string xp1;
+        string xp2;
+    };    
+    map<string, Association*> associationTable;
+    map<string, unsigned short> crosspointLookup; 
 };