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:
Wed Aug 19 11:42:26 2015 +0000
Revision:
16:29b83f5c042b
Parent:
15:f0a218113b15
Updated to use new logger

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 16:29b83f5c042b 8 #define LOG_LEVEL_INFO
ollie8 16:29b83f5c042b 9 #include "logger.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 15:f0a218113b15 112 /**Constructs a new CD22M3494 object
ollie8 4:6ffeb0008f11 113 *
ollie8 14:7cb4d76170b2 114 * @param x0 the pin name for the first bit of the x axis address
ollie8 14:7cb4d76170b2 115 * @param x1 the pin name for the second bit of the x axis address
ollie8 14:7cb4d76170b2 116 * @param x2 the pin name for the thrid bit of the x axis address
ollie8 14:7cb4d76170b2 117 * @param x3 the pin name for the forth bit of the x axis address
ollie8 14:7cb4d76170b2 118 * @param y0 the pin name for the first bit of the y axis address
ollie8 14:7cb4d76170b2 119 * @param y1 the pin name for the second bit of the y axis address
ollie8 14:7cb4d76170b2 120 * @param y2 the pin name for the thrid bit 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 8:20fd0ebff489 125 CD22M3494(PinName x0, PinName x1, PinName x2, PinName x3, PinName y0, PinName y1, PinName y2, PinName d, PinName str, PinName rs) {
ollie8 0:5ef90cd25c10 126 xbus = new BusOut(x0, x1, x2, x3);
ollie8 8:20fd0ebff489 127 ybus = new BusOut(y0, y1, y2);
ollie8 0:5ef90cd25c10 128 data = new DigitalOut(d);
ollie8 14:7cb4d76170b2 129 strobe = new DigitalOut(str);
ollie8 0:5ef90cd25c10 130 reset = new DigitalOut(rs);
ollie8 0:5ef90cd25c10 131 data->write(0);
ollie8 14:7cb4d76170b2 132 strobe->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 14:7cb4d76170b2 164 delete strobe;
ollie8 0:5ef90cd25c10 165 delete reset;
ollie8 2:25049dc7da13 166 associationTable.clear();
ollie8 2:25049dc7da13 167 delete &associationTable;
ollie8 13:ee719eb11161 168 }
ollie8 7:6dc462dd6a0a 169
ollie8 4:6ffeb0008f11 170 /**Closes the switch at the given cross point.
ollie8 4:6ffeb0008f11 171 *
ollie8 4:6ffeb0008f11 172 * @param x the x axis
ollie8 4:6ffeb0008f11 173 * @param y the y axis
ollie8 4:6ffeb0008f11 174 */
ollie8 0:5ef90cd25c10 175 bool crossPointConnect(unsigned short x, unsigned short y) {
ollie8 13:ee719eb11161 176 INFO("Got x point connect for x %d, y %d", x, y);
ollie8 0:5ef90cd25c10 177 if (x <= MAX_X && y <= MAX_Y) {
ollie8 7:6dc462dd6a0a 178 INFO("setting data high...");
ollie8 0:5ef90cd25c10 179 data->write(1);
ollie8 7:6dc462dd6a0a 180 INFO("writing x...");
ollie8 0:5ef90cd25c10 181 xbus->write(x);
ollie8 7:6dc462dd6a0a 182 INFO("writing y...");
ollie8 0:5ef90cd25c10 183 ybus->write(y);
ollie8 4:6ffeb0008f11 184 // let the data busses settle before setting obe high
ollie8 0:5ef90cd25c10 185 wait_us(2);
ollie8 14:7cb4d76170b2 186 strobe->write(1);
ollie8 4:6ffeb0008f11 187 // obe must be high for at least 20 ns
ollie8 0:5ef90cd25c10 188 wait_us(1);
ollie8 14:7cb4d76170b2 189 strobe->write(0);
ollie8 7:6dc462dd6a0a 190 INFO("Done");
ollie8 0:5ef90cd25c10 191 return true;
ollie8 0:5ef90cd25c10 192 }
ollie8 7:6dc462dd6a0a 193 INFO("Error");
ollie8 0:5ef90cd25c10 194 return false;
ollie8 0:5ef90cd25c10 195 }
ollie8 0:5ef90cd25c10 196
ollie8 4:6ffeb0008f11 197 /**Opens the switch at the given cross point.
ollie8 4:6ffeb0008f11 198 *
ollie8 4:6ffeb0008f11 199 * @param x the x axis
ollie8 4:6ffeb0008f11 200 * @param y the y axis
ollie8 4:6ffeb0008f11 201 */
ollie8 0:5ef90cd25c10 202 bool crossPointDisconnect(unsigned short x, unsigned short y) {
ollie8 13:ee719eb11161 203 INFO("Got x point disconnect for x %d, y %d", x, y);
ollie8 0:5ef90cd25c10 204 if (x <= MAX_X && y <= MAX_Y) {
ollie8 7:6dc462dd6a0a 205 INFO("setting data high...");
ollie8 0:5ef90cd25c10 206 data->write(0);
ollie8 7:6dc462dd6a0a 207 INFO("writing x...");
ollie8 0:5ef90cd25c10 208 xbus->write(x);
ollie8 7:6dc462dd6a0a 209 INFO("writing y...");
ollie8 0:5ef90cd25c10 210 ybus->write(y);
ollie8 4:6ffeb0008f11 211 // let the data busses settle before setting obe high
ollie8 0:5ef90cd25c10 212 wait_us(2);
ollie8 14:7cb4d76170b2 213 strobe->write(1);
ollie8 4:6ffeb0008f11 214 // obe must be high for at least 20 ns
ollie8 0:5ef90cd25c10 215 wait_us(1);
ollie8 14:7cb4d76170b2 216 strobe->write(0);
ollie8 7:6dc462dd6a0a 217 INFO("Done");
ollie8 0:5ef90cd25c10 218 return true;
ollie8 0:5ef90cd25c10 219 }
ollie8 7:6dc462dd6a0a 220 INFO("Error");
ollie8 0:5ef90cd25c10 221 return false;
ollie8 0:5ef90cd25c10 222 }
ollie8 1:bc9ca1d1d7a6 223
ollie8 4:6ffeb0008f11 224 /**Associated the two given crosspoint with the given name, note, both crosspoint MUST be on the same axis.
ollie8 4:6ffeb0008f11 225 *
ollie8 4:6ffeb0008f11 226 * @param name the name of the association
ollie8 4:6ffeb0008f11 227 * @param xp1 the first crosspoint to associate with the given name
ollie8 4:6ffeb0008f11 228 * @param xp2 the second crosspoint to associate with the given name
ollie8 4:6ffeb0008f11 229 */
ollie8 4:6ffeb0008f11 230 bool associate(string name, string xp1, string xp2) {
ollie8 4:6ffeb0008f11 231 if (crosspointLookup.count(xp1) && crosspointLookup.count(xp2)) {
ollie8 4:6ffeb0008f11 232 Association *assoc = new Association();
ollie8 4:6ffeb0008f11 233 assoc->xp1 = xp1;
ollie8 4:6ffeb0008f11 234 assoc->xp2 = xp2;
ollie8 4:6ffeb0008f11 235 associationTable[name] = assoc;
ollie8 6:3f51c9139496 236 return true;
ollie8 4:6ffeb0008f11 237 }
ollie8 6:3f51c9139496 238 return false;
ollie8 1:bc9ca1d1d7a6 239 }
ollie8 1:bc9ca1d1d7a6 240
ollie8 4:6ffeb0008f11 241 /**Connects all the crosspoints for the given associations.
ollie8 4:6ffeb0008f11 242 *
ollie8 4:6ffeb0008f11 243 * @param src the source association
ollie8 4:6ffeb0008f11 244 * @param dst the destination to connect the source to.
ollie8 4:6ffeb0008f11 245 */
ollie8 1:bc9ca1d1d7a6 246 bool routeAssociations(string src, string dst) {
ollie8 1:bc9ca1d1d7a6 247 if (associationTable.count(src) && associationTable.count(dst)) {
ollie8 4:6ffeb0008f11 248 crossPointConnect(crosspointLookup[associationTable[src]->xp1], crosspointLookup[associationTable[dst]->xp1]);
ollie8 4:6ffeb0008f11 249 crossPointConnect(crosspointLookup[associationTable[src]->xp2], crosspointLookup[associationTable[dst]->xp2]);
ollie8 1:bc9ca1d1d7a6 250 return true;
ollie8 1:bc9ca1d1d7a6 251 }
ollie8 1:bc9ca1d1d7a6 252 return false;
ollie8 1:bc9ca1d1d7a6 253 }
ollie8 1:bc9ca1d1d7a6 254
ollie8 4:6ffeb0008f11 255 /**Disconnects all the crosspoints for the given associations.
ollie8 4:6ffeb0008f11 256 *
ollie8 4:6ffeb0008f11 257 * @param src the source association
ollie8 4:6ffeb0008f11 258 * @param dst the destination to disconnect from the source.
ollie8 4:6ffeb0008f11 259 */
ollie8 1:bc9ca1d1d7a6 260 bool unRouteAssociations(string src, string dst) {
ollie8 1:bc9ca1d1d7a6 261 if (associationTable.count(src) && associationTable.count(dst)) {
ollie8 4:6ffeb0008f11 262 crossPointDisconnect(crosspointLookup[associationTable[src]->xp1], crosspointLookup[associationTable[dst]->xp1]);
ollie8 4:6ffeb0008f11 263 crossPointDisconnect(crosspointLookup[associationTable[src]->xp2], crosspointLookup[associationTable[dst]->xp2]);
ollie8 1:bc9ca1d1d7a6 264 return true;
ollie8 1:bc9ca1d1d7a6 265 }
ollie8 1:bc9ca1d1d7a6 266 return false;
ollie8 1:bc9ca1d1d7a6 267 }
ollie8 6:3f51c9139496 268
ollie8 6:3f51c9139496 269 Association* getAssociation(string name) {
ollie8 6:3f51c9139496 270 return associationTable[name];
ollie8 6:3f51c9139496 271 }
ollie8 6:3f51c9139496 272
ollie8 0:5ef90cd25c10 273 private:
ollie8 2:25049dc7da13 274 BusOut *xbus;
ollie8 2:25049dc7da13 275 BusOut *ybus;
ollie8 2:25049dc7da13 276 DigitalOut *data;
ollie8 14:7cb4d76170b2 277 DigitalOut *strobe;
ollie8 6:3f51c9139496 278 DigitalOut *reset;
ollie8 4:6ffeb0008f11 279 map<string, Association*> associationTable;
ollie8 4:6ffeb0008f11 280 map<string, unsigned short> crosspointLookup;
ollie8 0:5ef90cd25c10 281 };
ollie8 0:5ef90cd25c10 282
ollie8 0:5ef90cd25c10 283
ollie8 0:5ef90cd25c10 284 #endif