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.

Committer:
ollie8
Date:
Thu Sep 19 11:53:21 2013 +0000
Revision:
4:6ffeb0008f11
Parent:
3:fa46a8badc92
Child:
5:ca315c82dc1b
Crosspoints are now referenced by name outside of the driver

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ollie8 0:5ef90cd25c10 1 #ifndef CD22M3494_H
ollie8 0:5ef90cd25c10 2 #define CD22M3494_H
ollie8 0:5ef90cd25c10 3
ollie8 0:5ef90cd25c10 4 #include <mbed.h>
ollie8 1:bc9ca1d1d7a6 5 #include <map>
ollie8 1:bc9ca1d1d7a6 6 #include <string>
ollie8 1:bc9ca1d1d7a6 7
ollie8 0:5ef90cd25c10 8 /*
ollie8 0:5ef90cd25c10 9 X ADDRESS
ollie8 0:5ef90cd25c10 10 AX3 AX2 AX1 AX0 X SWITCH
ollie8 0:5ef90cd25c10 11 0 0 0 0 X0
ollie8 0:5ef90cd25c10 12 0 0 0 1 X1
ollie8 0:5ef90cd25c10 13 0 0 1 0 X2
ollie8 0:5ef90cd25c10 14 0 0 1 1 X3
ollie8 0:5ef90cd25c10 15 0 1 0 0 X4
ollie8 0:5ef90cd25c10 16 0 1 0 1 X5
ollie8 0:5ef90cd25c10 17 0 1 1 0 X12
ollie8 0:5ef90cd25c10 18 0 1 1 1 X13
ollie8 0:5ef90cd25c10 19 1 0 0 0 X6
ollie8 0:5ef90cd25c10 20 1 0 0 1 X7
ollie8 0:5ef90cd25c10 21 1 0 1 0 X8
ollie8 0:5ef90cd25c10 22 1 0 1 1 X9
ollie8 0:5ef90cd25c10 23 1 1 0 0 X10
ollie8 0:5ef90cd25c10 24 1 1 0 1 X11
ollie8 0:5ef90cd25c10 25 1 1 1 0 X14
ollie8 0:5ef90cd25c10 26 1 1 1 1 X15
ollie8 0:5ef90cd25c10 27 */
ollie8 4:6ffeb0008f11 28 #define X0 "X0"
ollie8 4:6ffeb0008f11 29 #define X1 "X1"
ollie8 4:6ffeb0008f11 30 #define X2 "X2"
ollie8 4:6ffeb0008f11 31 #define X3 "X3"
ollie8 4:6ffeb0008f11 32 #define X4 "X4"
ollie8 4:6ffeb0008f11 33 #define X5 "X5"
ollie8 4:6ffeb0008f11 34 #define X6 "X6"
ollie8 4:6ffeb0008f11 35 #define X7 "X7"
ollie8 4:6ffeb0008f11 36 #define X8 "X8"
ollie8 4:6ffeb0008f11 37 #define X9 "X9"
ollie8 4:6ffeb0008f11 38 #define X10 "X10"
ollie8 4:6ffeb0008f11 39 #define X11 "X11"
ollie8 4:6ffeb0008f11 40 #define X12 "X12"
ollie8 4:6ffeb0008f11 41 #define X13 "X13"
ollie8 4:6ffeb0008f11 42 #define X14 "X14"
ollie8 4:6ffeb0008f11 43 #define X15 "X15"
ollie8 0:5ef90cd25c10 44
ollie8 4:6ffeb0008f11 45
ollie8 4:6ffeb0008f11 46 #define X0I 0x00
ollie8 4:6ffeb0008f11 47 #define X1I 0x01
ollie8 4:6ffeb0008f11 48 #define X2I 0x02
ollie8 4:6ffeb0008f11 49 #define X3I 0x03
ollie8 4:6ffeb0008f11 50 #define X4I 0x04
ollie8 4:6ffeb0008f11 51 #define X5I 0x05
ollie8 4:6ffeb0008f11 52 #define X12I 0x06
ollie8 4:6ffeb0008f11 53 #define X13I 0x07
ollie8 4:6ffeb0008f11 54 #define X6I 0x08
ollie8 4:6ffeb0008f11 55 #define X7I 0x09
ollie8 4:6ffeb0008f11 56 #define X8I 0x0A
ollie8 4:6ffeb0008f11 57 #define X9I 0x0B
ollie8 4:6ffeb0008f11 58 #define X10I 0x0C
ollie8 4:6ffeb0008f11 59 #define X11I 0x0D
ollie8 4:6ffeb0008f11 60 #define X14I 0x0E
ollie8 4:6ffeb0008f11 61 #define X15I 0x0F
ollie8 0:5ef90cd25c10 62
ollie8 0:5ef90cd25c10 63 /*
ollie8 0:5ef90cd25c10 64 Y ADDRESS
ollie8 0:5ef90cd25c10 65 AY2 AY1 AY0 Y SWITCH
ollie8 0:5ef90cd25c10 66 0 0 0 Y0
ollie8 0:5ef90cd25c10 67 0 0 1 Y1
ollie8 0:5ef90cd25c10 68 0 1 0 Y2
ollie8 0:5ef90cd25c10 69 0 1 1 Y3
ollie8 0:5ef90cd25c10 70 1 0 0 Y4
ollie8 0:5ef90cd25c10 71 1 0 1 Y5
ollie8 0:5ef90cd25c10 72 1 1 0 Y6
ollie8 0:5ef90cd25c10 73 1 1 1 Y7
ollie8 0:5ef90cd25c10 74 */
ollie8 0:5ef90cd25c10 75
ollie8 4:6ffeb0008f11 76 #define Y0I 0x0
ollie8 4:6ffeb0008f11 77 #define Y1I 0x1
ollie8 4:6ffeb0008f11 78 #define Y2I 0x2
ollie8 4:6ffeb0008f11 79 #define Y3I 0x3
ollie8 4:6ffeb0008f11 80 #define Y4I 0x4
ollie8 4:6ffeb0008f11 81 #define Y5I 0x5
ollie8 4:6ffeb0008f11 82 #define Y6I 0x6
ollie8 4:6ffeb0008f11 83 #define Y7I 0x7
ollie8 4:6ffeb0008f11 84
ollie8 4:6ffeb0008f11 85 #define Y0 "Y0"
ollie8 4:6ffeb0008f11 86 #define Y1 "Y1"
ollie8 4:6ffeb0008f11 87 #define Y2 "Y2"
ollie8 4:6ffeb0008f11 88 #define Y3 "Y3"
ollie8 4:6ffeb0008f11 89 #define Y4 "Y4"
ollie8 4:6ffeb0008f11 90 #define Y5 "Y5"
ollie8 4:6ffeb0008f11 91 #define Y6 "Y6"
ollie8 4:6ffeb0008f11 92 #define Y7 "Y7"
ollie8 0:5ef90cd25c10 93
ollie8 0:5ef90cd25c10 94 #define MAX_X 0x0F
ollie8 0:5ef90cd25c10 95 #define MAX_Y 0x7
ollie8 0:5ef90cd25c10 96
ollie8 0:5ef90cd25c10 97 class CD22M3494 {
ollie8 0:5ef90cd25c10 98
ollie8 0:5ef90cd25c10 99 public:
ollie8 0:5ef90cd25c10 100
ollie8 4:6ffeb0008f11 101 /**Conucts a new CD22M3494 object
ollie8 4:6ffeb0008f11 102 *
ollie8 4:6ffeb0008f11 103 * @param x0 the pin name for the first byte of the x axis address
ollie8 4:6ffeb0008f11 104 * @param x1 the pin name for the second byte of the x axis address
ollie8 4:6ffeb0008f11 105 * @param x2 the pin name for the thrid byte of the x axis address
ollie8 4:6ffeb0008f11 106 * @param x3 the pin name for the forth byte of the x axis address
ollie8 4:6ffeb0008f11 107 * @param y0 the pin name for the first byte of the y axis address
ollie8 4:6ffeb0008f11 108 * @param y1 the pin name for the second byte of the y axis address
ollie8 4:6ffeb0008f11 109 * @param y2 the pin name for the thrid byte of the y axis address
ollie8 4:6ffeb0008f11 110 * @param d the pin name for the data bus
ollie8 4:6ffeb0008f11 111 * @param str the pin name for the strobe bus
ollie8 4:6ffeb0008f11 112 * @param rs the pin name for reset.
ollie8 4:6ffeb0008f11 113 */
ollie8 0:5ef90cd25c10 114 CD22M3494(PinName x0, PinName x1, PinName x2, PinName x3, PinName y0, PinName y1, PinName y2, PinName d, PinName str, PinName rs) {
ollie8 0:5ef90cd25c10 115 xbus = new BusOut(x0, x1, x2, x3);
ollie8 0:5ef90cd25c10 116 ybus = new BusOut(y0, y1, y2);
ollie8 0:5ef90cd25c10 117 data = new DigitalOut(d);
ollie8 4:6ffeb0008f11 118 obe = new DigitalOut(str);
ollie8 0:5ef90cd25c10 119 reset = new DigitalOut(rs);
ollie8 0:5ef90cd25c10 120 data->write(0);
ollie8 4:6ffeb0008f11 121 obe->write(0);
ollie8 0:5ef90cd25c10 122 reset->write(0);
ollie8 4:6ffeb0008f11 123 crosspointLookup[X0] = X0I;
ollie8 4:6ffeb0008f11 124 crosspointLookup[X1] = X1I;
ollie8 4:6ffeb0008f11 125 crosspointLookup[X2] = X2I;
ollie8 4:6ffeb0008f11 126 crosspointLookup[X3] = X3I;
ollie8 4:6ffeb0008f11 127 crosspointLookup[X4] = X4I;
ollie8 4:6ffeb0008f11 128 crosspointLookup[X5] = X5I;
ollie8 4:6ffeb0008f11 129 crosspointLookup[X6] = X6I;
ollie8 4:6ffeb0008f11 130 crosspointLookup[X7] = X7I;
ollie8 4:6ffeb0008f11 131 crosspointLookup[X8] = X8I;
ollie8 4:6ffeb0008f11 132 crosspointLookup[X9] = X9I;
ollie8 4:6ffeb0008f11 133 crosspointLookup[X10] = X10I;
ollie8 4:6ffeb0008f11 134 crosspointLookup[X11] = X11I;
ollie8 4:6ffeb0008f11 135 crosspointLookup[X12] = X12I;
ollie8 4:6ffeb0008f11 136 crosspointLookup[X13] = X13I;
ollie8 4:6ffeb0008f11 137 crosspointLookup[X14] = X14I;
ollie8 4:6ffeb0008f11 138 crosspointLookup[X15] = X15I;
ollie8 4:6ffeb0008f11 139 crosspointLookup[Y0] = Y0I;
ollie8 4:6ffeb0008f11 140 crosspointLookup[Y1] = Y1I;
ollie8 4:6ffeb0008f11 141 crosspointLookup[Y2] = Y2I;
ollie8 4:6ffeb0008f11 142 crosspointLookup[Y3] = Y3I;
ollie8 4:6ffeb0008f11 143 crosspointLookup[Y4] = Y4I;
ollie8 4:6ffeb0008f11 144 crosspointLookup[Y5] = Y5I;
ollie8 4:6ffeb0008f11 145 crosspointLookup[Y6] = Y6I;
ollie8 4:6ffeb0008f11 146 crosspointLookup[Y7] = Y7I;
ollie8 0:5ef90cd25c10 147 }
ollie8 0:5ef90cd25c10 148
ollie8 0:5ef90cd25c10 149 ~CD22M3494() {
ollie8 0:5ef90cd25c10 150 delete xbus;
ollie8 0:5ef90cd25c10 151 delete ybus;
ollie8 0:5ef90cd25c10 152 delete data;
ollie8 4:6ffeb0008f11 153 delete obe;
ollie8 0:5ef90cd25c10 154 delete reset;
ollie8 2:25049dc7da13 155 associationTable.clear();
ollie8 2:25049dc7da13 156 delete &associationTable;
ollie8 0:5ef90cd25c10 157 }
ollie8 0:5ef90cd25c10 158
ollie8 4:6ffeb0008f11 159 /**Closes the switch at the given cross point.
ollie8 4:6ffeb0008f11 160 *
ollie8 4:6ffeb0008f11 161 * @param x the x axis
ollie8 4:6ffeb0008f11 162 * @param y the y axis
ollie8 4:6ffeb0008f11 163 */
ollie8 0:5ef90cd25c10 164 bool crossPointConnect(unsigned short x, unsigned short y) {
ollie8 0:5ef90cd25c10 165 if (x <= MAX_X && y <= MAX_Y) {
ollie8 0:5ef90cd25c10 166 data->write(1);
ollie8 0:5ef90cd25c10 167 xbus->write(x);
ollie8 0:5ef90cd25c10 168 ybus->write(y);
ollie8 4:6ffeb0008f11 169 // let the data busses settle before setting obe high
ollie8 0:5ef90cd25c10 170 wait_us(2);
ollie8 4:6ffeb0008f11 171 obe->write(1);
ollie8 4:6ffeb0008f11 172 // obe must be high for at least 20 ns
ollie8 0:5ef90cd25c10 173 wait_us(1);
ollie8 4:6ffeb0008f11 174 obe->write(0);
ollie8 0:5ef90cd25c10 175 return true;
ollie8 0:5ef90cd25c10 176 }
ollie8 0:5ef90cd25c10 177 return false;
ollie8 0:5ef90cd25c10 178 }
ollie8 0:5ef90cd25c10 179
ollie8 4:6ffeb0008f11 180 /**Opens the switch at the given cross point.
ollie8 4:6ffeb0008f11 181 *
ollie8 4:6ffeb0008f11 182 * @param x the x axis
ollie8 4:6ffeb0008f11 183 * @param y the y axis
ollie8 4:6ffeb0008f11 184 */
ollie8 0:5ef90cd25c10 185 bool crossPointDisconnect(unsigned short x, unsigned short y) {
ollie8 0:5ef90cd25c10 186 if (x <= MAX_X && y <= MAX_Y) {
ollie8 0:5ef90cd25c10 187 data->write(0);
ollie8 0:5ef90cd25c10 188 xbus->write(x);
ollie8 0:5ef90cd25c10 189 ybus->write(y);
ollie8 4:6ffeb0008f11 190 // let the data busses settle before setting obe high
ollie8 0:5ef90cd25c10 191 wait_us(2);
ollie8 4:6ffeb0008f11 192 obe->write(1);
ollie8 4:6ffeb0008f11 193 // obe must be high for at least 20 ns
ollie8 0:5ef90cd25c10 194 wait_us(1);
ollie8 4:6ffeb0008f11 195 obe->write(0);
ollie8 0:5ef90cd25c10 196 return true;
ollie8 0:5ef90cd25c10 197 }
ollie8 0:5ef90cd25c10 198 return false;
ollie8 0:5ef90cd25c10 199 }
ollie8 1:bc9ca1d1d7a6 200
ollie8 4:6ffeb0008f11 201 /**Associated the two given crosspoint with the given name, note, both crosspoint MUST be on the same axis.
ollie8 4:6ffeb0008f11 202 *
ollie8 4:6ffeb0008f11 203 * @param name the name of the association
ollie8 4:6ffeb0008f11 204 * @param xp1 the first crosspoint to associate with the given name
ollie8 4:6ffeb0008f11 205 * @param xp2 the second crosspoint to associate with the given name
ollie8 4:6ffeb0008f11 206 */
ollie8 4:6ffeb0008f11 207 bool associate(string name, string xp1, string xp2) {
ollie8 4:6ffeb0008f11 208 if (crosspointLookup.count(xp1) && crosspointLookup.count(xp2)) {
ollie8 4:6ffeb0008f11 209 Association *assoc = new Association();
ollie8 4:6ffeb0008f11 210 assoc->xp1 = xp1;
ollie8 4:6ffeb0008f11 211 assoc->xp2 = xp2;
ollie8 4:6ffeb0008f11 212 associationTable[name] = assoc;
ollie8 4:6ffeb0008f11 213 }
ollie8 1:bc9ca1d1d7a6 214 }
ollie8 1:bc9ca1d1d7a6 215
ollie8 4:6ffeb0008f11 216 /**Connects all the crosspoints for the given associations.
ollie8 4:6ffeb0008f11 217 *
ollie8 4:6ffeb0008f11 218 * @param src the source association
ollie8 4:6ffeb0008f11 219 * @param dst the destination to connect the source to.
ollie8 4:6ffeb0008f11 220 */
ollie8 1:bc9ca1d1d7a6 221 bool routeAssociations(string src, string dst) {
ollie8 1:bc9ca1d1d7a6 222 if (associationTable.count(src) && associationTable.count(dst)) {
ollie8 4:6ffeb0008f11 223 crossPointConnect(crosspointLookup[associationTable[src]->xp1], crosspointLookup[associationTable[dst]->xp1]);
ollie8 4:6ffeb0008f11 224 crossPointConnect(crosspointLookup[associationTable[src]->xp2], crosspointLookup[associationTable[dst]->xp2]);
ollie8 1:bc9ca1d1d7a6 225 return true;
ollie8 1:bc9ca1d1d7a6 226 }
ollie8 1:bc9ca1d1d7a6 227 return false;
ollie8 1:bc9ca1d1d7a6 228 }
ollie8 1:bc9ca1d1d7a6 229
ollie8 4:6ffeb0008f11 230 /**Disconnects all the crosspoints for the given associations.
ollie8 4:6ffeb0008f11 231 *
ollie8 4:6ffeb0008f11 232 * @param src the source association
ollie8 4:6ffeb0008f11 233 * @param dst the destination to disconnect from the source.
ollie8 4:6ffeb0008f11 234 */
ollie8 1:bc9ca1d1d7a6 235 bool unRouteAssociations(string src, string dst) {
ollie8 1:bc9ca1d1d7a6 236 if (associationTable.count(src) && associationTable.count(dst)) {
ollie8 4:6ffeb0008f11 237 crossPointDisconnect(crosspointLookup[associationTable[src]->xp1], crosspointLookup[associationTable[dst]->xp1]);
ollie8 4:6ffeb0008f11 238 crossPointDisconnect(crosspointLookup[associationTable[src]->xp2], crosspointLookup[associationTable[dst]->xp2]);
ollie8 1:bc9ca1d1d7a6 239 return true;
ollie8 1:bc9ca1d1d7a6 240 }
ollie8 1:bc9ca1d1d7a6 241 return false;
ollie8 1:bc9ca1d1d7a6 242 }
ollie8 4:6ffeb0008f11 243
ollie8 0:5ef90cd25c10 244 private:
ollie8 2:25049dc7da13 245 BusOut *xbus;
ollie8 2:25049dc7da13 246 BusOut *ybus;
ollie8 2:25049dc7da13 247 DigitalOut *data;
ollie8 4:6ffeb0008f11 248 DigitalOut *obe;
ollie8 4:6ffeb0008f11 249 DigitalOut *reset;
ollie8 4:6ffeb0008f11 250 struct Association {
ollie8 4:6ffeb0008f11 251 string name;
ollie8 4:6ffeb0008f11 252 string xp1;
ollie8 4:6ffeb0008f11 253 string xp2;
ollie8 4:6ffeb0008f11 254 };
ollie8 4:6ffeb0008f11 255 map<string, Association*> associationTable;
ollie8 4:6ffeb0008f11 256 map<string, unsigned short> crosspointLookup;
ollie8 0:5ef90cd25c10 257 };
ollie8 0:5ef90cd25c10 258
ollie8 0:5ef90cd25c10 259
ollie8 0:5ef90cd25c10 260 #endif