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 Dec 19 14:35:12 2013 +0000
Revision:
7:6dc462dd6a0a
Parent:
6:3f51c9139496
Child:
8:20fd0ebff489
Finally got the fucking thing working!!

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