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:56:37 2013 +0000
Revision:
5:ca315c82dc1b
Parent:
4:6ffeb0008f11
Child:
6:3f51c9139496
Comment update

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 5:ca315c82dc1b 97 /**A driver for the CD22M3494 crosspoint switch matrix.
ollie8 5:ca315c82dc1b 98 */
ollie8 0:5ef90cd25c10 99 class CD22M3494 {
ollie8 0:5ef90cd25c10 100
ollie8 0:5ef90cd25c10 101 public:
ollie8 0:5ef90cd25c10 102
ollie8 4:6ffeb0008f11 103 /**Conucts a new CD22M3494 object
ollie8 4:6ffeb0008f11 104 *
ollie8 4:6ffeb0008f11 105 * @param x0 the pin name for the first byte of the x axis address
ollie8 4:6ffeb0008f11 106 * @param x1 the pin name for the second byte of the x axis address
ollie8 4:6ffeb0008f11 107 * @param x2 the pin name for the thrid byte of the x axis address
ollie8 4:6ffeb0008f11 108 * @param x3 the pin name for the forth byte of the x axis address
ollie8 4:6ffeb0008f11 109 * @param y0 the pin name for the first byte of the y axis address
ollie8 4:6ffeb0008f11 110 * @param y1 the pin name for the second byte of the y axis address
ollie8 4:6ffeb0008f11 111 * @param y2 the pin name for the thrid byte of the y axis address
ollie8 4:6ffeb0008f11 112 * @param d the pin name for the data bus
ollie8 4:6ffeb0008f11 113 * @param str the pin name for the strobe bus
ollie8 4:6ffeb0008f11 114 * @param rs the pin name for reset.
ollie8 4:6ffeb0008f11 115 */
ollie8 0:5ef90cd25c10 116 CD22M3494(PinName x0, PinName x1, PinName x2, PinName x3, PinName y0, PinName y1, PinName y2, PinName d, PinName str, PinName rs) {
ollie8 0:5ef90cd25c10 117 xbus = new BusOut(x0, x1, x2, x3);
ollie8 0:5ef90cd25c10 118 ybus = new BusOut(y0, y1, y2);
ollie8 0:5ef90cd25c10 119 data = new DigitalOut(d);
ollie8 4:6ffeb0008f11 120 obe = new DigitalOut(str);
ollie8 0:5ef90cd25c10 121 reset = new DigitalOut(rs);
ollie8 0:5ef90cd25c10 122 data->write(0);
ollie8 4:6ffeb0008f11 123 obe->write(0);
ollie8 0:5ef90cd25c10 124 reset->write(0);
ollie8 4:6ffeb0008f11 125 crosspointLookup[X0] = X0I;
ollie8 4:6ffeb0008f11 126 crosspointLookup[X1] = X1I;
ollie8 4:6ffeb0008f11 127 crosspointLookup[X2] = X2I;
ollie8 4:6ffeb0008f11 128 crosspointLookup[X3] = X3I;
ollie8 4:6ffeb0008f11 129 crosspointLookup[X4] = X4I;
ollie8 4:6ffeb0008f11 130 crosspointLookup[X5] = X5I;
ollie8 4:6ffeb0008f11 131 crosspointLookup[X6] = X6I;
ollie8 4:6ffeb0008f11 132 crosspointLookup[X7] = X7I;
ollie8 4:6ffeb0008f11 133 crosspointLookup[X8] = X8I;
ollie8 4:6ffeb0008f11 134 crosspointLookup[X9] = X9I;
ollie8 4:6ffeb0008f11 135 crosspointLookup[X10] = X10I;
ollie8 4:6ffeb0008f11 136 crosspointLookup[X11] = X11I;
ollie8 4:6ffeb0008f11 137 crosspointLookup[X12] = X12I;
ollie8 4:6ffeb0008f11 138 crosspointLookup[X13] = X13I;
ollie8 4:6ffeb0008f11 139 crosspointLookup[X14] = X14I;
ollie8 4:6ffeb0008f11 140 crosspointLookup[X15] = X15I;
ollie8 4:6ffeb0008f11 141 crosspointLookup[Y0] = Y0I;
ollie8 4:6ffeb0008f11 142 crosspointLookup[Y1] = Y1I;
ollie8 4:6ffeb0008f11 143 crosspointLookup[Y2] = Y2I;
ollie8 4:6ffeb0008f11 144 crosspointLookup[Y3] = Y3I;
ollie8 4:6ffeb0008f11 145 crosspointLookup[Y4] = Y4I;
ollie8 4:6ffeb0008f11 146 crosspointLookup[Y5] = Y5I;
ollie8 4:6ffeb0008f11 147 crosspointLookup[Y6] = Y6I;
ollie8 4:6ffeb0008f11 148 crosspointLookup[Y7] = Y7I;
ollie8 0:5ef90cd25c10 149 }
ollie8 0:5ef90cd25c10 150
ollie8 0:5ef90cd25c10 151 ~CD22M3494() {
ollie8 0:5ef90cd25c10 152 delete xbus;
ollie8 0:5ef90cd25c10 153 delete ybus;
ollie8 0:5ef90cd25c10 154 delete data;
ollie8 4:6ffeb0008f11 155 delete obe;
ollie8 0:5ef90cd25c10 156 delete reset;
ollie8 2:25049dc7da13 157 associationTable.clear();
ollie8 2:25049dc7da13 158 delete &associationTable;
ollie8 0:5ef90cd25c10 159 }
ollie8 0:5ef90cd25c10 160
ollie8 4:6ffeb0008f11 161 /**Closes the switch at the given cross point.
ollie8 4:6ffeb0008f11 162 *
ollie8 4:6ffeb0008f11 163 * @param x the x axis
ollie8 4:6ffeb0008f11 164 * @param y the y axis
ollie8 4:6ffeb0008f11 165 */
ollie8 0:5ef90cd25c10 166 bool crossPointConnect(unsigned short x, unsigned short y) {
ollie8 0:5ef90cd25c10 167 if (x <= MAX_X && y <= MAX_Y) {
ollie8 0:5ef90cd25c10 168 data->write(1);
ollie8 0:5ef90cd25c10 169 xbus->write(x);
ollie8 0:5ef90cd25c10 170 ybus->write(y);
ollie8 4:6ffeb0008f11 171 // let the data busses settle before setting obe high
ollie8 0:5ef90cd25c10 172 wait_us(2);
ollie8 4:6ffeb0008f11 173 obe->write(1);
ollie8 4:6ffeb0008f11 174 // obe must be high for at least 20 ns
ollie8 0:5ef90cd25c10 175 wait_us(1);
ollie8 4:6ffeb0008f11 176 obe->write(0);
ollie8 0:5ef90cd25c10 177 return true;
ollie8 0:5ef90cd25c10 178 }
ollie8 0:5ef90cd25c10 179 return false;
ollie8 0:5ef90cd25c10 180 }
ollie8 0:5ef90cd25c10 181
ollie8 4:6ffeb0008f11 182 /**Opens the switch at the given cross point.
ollie8 4:6ffeb0008f11 183 *
ollie8 4:6ffeb0008f11 184 * @param x the x axis
ollie8 4:6ffeb0008f11 185 * @param y the y axis
ollie8 4:6ffeb0008f11 186 */
ollie8 0:5ef90cd25c10 187 bool crossPointDisconnect(unsigned short x, unsigned short y) {
ollie8 0:5ef90cd25c10 188 if (x <= MAX_X && y <= MAX_Y) {
ollie8 0:5ef90cd25c10 189 data->write(0);
ollie8 0:5ef90cd25c10 190 xbus->write(x);
ollie8 0:5ef90cd25c10 191 ybus->write(y);
ollie8 4:6ffeb0008f11 192 // let the data busses settle before setting obe high
ollie8 0:5ef90cd25c10 193 wait_us(2);
ollie8 4:6ffeb0008f11 194 obe->write(1);
ollie8 4:6ffeb0008f11 195 // obe must be high for at least 20 ns
ollie8 0:5ef90cd25c10 196 wait_us(1);
ollie8 4:6ffeb0008f11 197 obe->write(0);
ollie8 0:5ef90cd25c10 198 return true;
ollie8 0:5ef90cd25c10 199 }
ollie8 0:5ef90cd25c10 200 return false;
ollie8 0:5ef90cd25c10 201 }
ollie8 1:bc9ca1d1d7a6 202
ollie8 4:6ffeb0008f11 203 /**Associated the two given crosspoint with the given name, note, both crosspoint MUST be on the same axis.
ollie8 4:6ffeb0008f11 204 *
ollie8 4:6ffeb0008f11 205 * @param name the name of the association
ollie8 4:6ffeb0008f11 206 * @param xp1 the first crosspoint to associate with the given name
ollie8 4:6ffeb0008f11 207 * @param xp2 the second crosspoint to associate with the given name
ollie8 4:6ffeb0008f11 208 */
ollie8 4:6ffeb0008f11 209 bool associate(string name, string xp1, string xp2) {
ollie8 4:6ffeb0008f11 210 if (crosspointLookup.count(xp1) && crosspointLookup.count(xp2)) {
ollie8 4:6ffeb0008f11 211 Association *assoc = new Association();
ollie8 4:6ffeb0008f11 212 assoc->xp1 = xp1;
ollie8 4:6ffeb0008f11 213 assoc->xp2 = xp2;
ollie8 4:6ffeb0008f11 214 associationTable[name] = assoc;
ollie8 4:6ffeb0008f11 215 }
ollie8 1:bc9ca1d1d7a6 216 }
ollie8 1:bc9ca1d1d7a6 217
ollie8 4:6ffeb0008f11 218 /**Connects all the crosspoints for the given associations.
ollie8 4:6ffeb0008f11 219 *
ollie8 4:6ffeb0008f11 220 * @param src the source association
ollie8 4:6ffeb0008f11 221 * @param dst the destination to connect the source to.
ollie8 4:6ffeb0008f11 222 */
ollie8 1:bc9ca1d1d7a6 223 bool routeAssociations(string src, string dst) {
ollie8 1:bc9ca1d1d7a6 224 if (associationTable.count(src) && associationTable.count(dst)) {
ollie8 4:6ffeb0008f11 225 crossPointConnect(crosspointLookup[associationTable[src]->xp1], crosspointLookup[associationTable[dst]->xp1]);
ollie8 4:6ffeb0008f11 226 crossPointConnect(crosspointLookup[associationTable[src]->xp2], crosspointLookup[associationTable[dst]->xp2]);
ollie8 1:bc9ca1d1d7a6 227 return true;
ollie8 1:bc9ca1d1d7a6 228 }
ollie8 1:bc9ca1d1d7a6 229 return false;
ollie8 1:bc9ca1d1d7a6 230 }
ollie8 1:bc9ca1d1d7a6 231
ollie8 4:6ffeb0008f11 232 /**Disconnects all the crosspoints for the given associations.
ollie8 4:6ffeb0008f11 233 *
ollie8 4:6ffeb0008f11 234 * @param src the source association
ollie8 4:6ffeb0008f11 235 * @param dst the destination to disconnect from the source.
ollie8 4:6ffeb0008f11 236 */
ollie8 1:bc9ca1d1d7a6 237 bool unRouteAssociations(string src, string dst) {
ollie8 1:bc9ca1d1d7a6 238 if (associationTable.count(src) && associationTable.count(dst)) {
ollie8 4:6ffeb0008f11 239 crossPointDisconnect(crosspointLookup[associationTable[src]->xp1], crosspointLookup[associationTable[dst]->xp1]);
ollie8 4:6ffeb0008f11 240 crossPointDisconnect(crosspointLookup[associationTable[src]->xp2], crosspointLookup[associationTable[dst]->xp2]);
ollie8 1:bc9ca1d1d7a6 241 return true;
ollie8 1:bc9ca1d1d7a6 242 }
ollie8 1:bc9ca1d1d7a6 243 return false;
ollie8 1:bc9ca1d1d7a6 244 }
ollie8 4:6ffeb0008f11 245
ollie8 0:5ef90cd25c10 246 private:
ollie8 2:25049dc7da13 247 BusOut *xbus;
ollie8 2:25049dc7da13 248 BusOut *ybus;
ollie8 2:25049dc7da13 249 DigitalOut *data;
ollie8 4:6ffeb0008f11 250 DigitalOut *obe;
ollie8 4:6ffeb0008f11 251 DigitalOut *reset;
ollie8 4:6ffeb0008f11 252 struct Association {
ollie8 4:6ffeb0008f11 253 string name;
ollie8 4:6ffeb0008f11 254 string xp1;
ollie8 4:6ffeb0008f11 255 string xp2;
ollie8 4:6ffeb0008f11 256 };
ollie8 4:6ffeb0008f11 257 map<string, Association*> associationTable;
ollie8 4:6ffeb0008f11 258 map<string, unsigned short> crosspointLookup;
ollie8 0:5ef90cd25c10 259 };
ollie8 0:5ef90cd25c10 260
ollie8 0:5ef90cd25c10 261
ollie8 0:5ef90cd25c10 262 #endif