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.
CD22M3494.h@3:fa46a8badc92, 2013-09-11 (annotated)
- Committer:
- ollie8
- Date:
- Wed Sep 11 11:54:24 2013 +0000
- Revision:
- 3:fa46a8badc92
- Parent:
- 2:25049dc7da13
- Child:
- 4:6ffeb0008f11
Added get association method
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:5ef90cd25c10 | 28 | |
ollie8 | 0:5ef90cd25c10 | 29 | #define X0 0x00 |
ollie8 | 0:5ef90cd25c10 | 30 | #define X1 0x01 |
ollie8 | 0:5ef90cd25c10 | 31 | #define X2 0x02 |
ollie8 | 0:5ef90cd25c10 | 32 | #define X3 0x03 |
ollie8 | 0:5ef90cd25c10 | 33 | #define X4 0x04 |
ollie8 | 0:5ef90cd25c10 | 34 | #define X5 0x05 |
ollie8 | 0:5ef90cd25c10 | 35 | #define X12 0x06 |
ollie8 | 0:5ef90cd25c10 | 36 | #define X13 0x07 |
ollie8 | 0:5ef90cd25c10 | 37 | #define X6 0x08 |
ollie8 | 0:5ef90cd25c10 | 38 | #define X7 0x09 |
ollie8 | 0:5ef90cd25c10 | 39 | #define X8 0x0A |
ollie8 | 0:5ef90cd25c10 | 40 | #define X9 0x0B |
ollie8 | 0:5ef90cd25c10 | 41 | #define X10 0x0C |
ollie8 | 0:5ef90cd25c10 | 42 | #define X11 0x0D |
ollie8 | 0:5ef90cd25c10 | 43 | #define X14 0x0E |
ollie8 | 0:5ef90cd25c10 | 44 | #define X15 0x0F |
ollie8 | 0:5ef90cd25c10 | 45 | |
ollie8 | 0:5ef90cd25c10 | 46 | /* |
ollie8 | 0:5ef90cd25c10 | 47 | Y ADDRESS |
ollie8 | 0:5ef90cd25c10 | 48 | AY2 AY1 AY0 Y SWITCH |
ollie8 | 0:5ef90cd25c10 | 49 | 0 0 0 Y0 |
ollie8 | 0:5ef90cd25c10 | 50 | 0 0 1 Y1 |
ollie8 | 0:5ef90cd25c10 | 51 | 0 1 0 Y2 |
ollie8 | 0:5ef90cd25c10 | 52 | 0 1 1 Y3 |
ollie8 | 0:5ef90cd25c10 | 53 | 1 0 0 Y4 |
ollie8 | 0:5ef90cd25c10 | 54 | 1 0 1 Y5 |
ollie8 | 0:5ef90cd25c10 | 55 | 1 1 0 Y6 |
ollie8 | 0:5ef90cd25c10 | 56 | 1 1 1 Y7 |
ollie8 | 0:5ef90cd25c10 | 57 | */ |
ollie8 | 0:5ef90cd25c10 | 58 | |
ollie8 | 0:5ef90cd25c10 | 59 | #define Y0 0x0 |
ollie8 | 0:5ef90cd25c10 | 60 | #define Y1 0x1 |
ollie8 | 0:5ef90cd25c10 | 61 | #define Y2 0x2 |
ollie8 | 0:5ef90cd25c10 | 62 | #define Y3 0x3 |
ollie8 | 0:5ef90cd25c10 | 63 | #define Y4 0x4 |
ollie8 | 0:5ef90cd25c10 | 64 | #define Y5 0x5 |
ollie8 | 0:5ef90cd25c10 | 65 | #define Y6 0x6 |
ollie8 | 0:5ef90cd25c10 | 66 | #define Y7 0x7 |
ollie8 | 0:5ef90cd25c10 | 67 | |
ollie8 | 0:5ef90cd25c10 | 68 | #define MAX_X 0x0F |
ollie8 | 0:5ef90cd25c10 | 69 | #define MAX_Y 0x7 |
ollie8 | 0:5ef90cd25c10 | 70 | |
ollie8 | 0:5ef90cd25c10 | 71 | class CD22M3494 { |
ollie8 | 0:5ef90cd25c10 | 72 | |
ollie8 | 0:5ef90cd25c10 | 73 | public: |
ollie8 | 0:5ef90cd25c10 | 74 | |
ollie8 | 0:5ef90cd25c10 | 75 | CD22M3494(PinName x0, PinName x1, PinName x2, PinName x3, PinName y0, PinName y1, PinName y2, PinName d, PinName str, PinName rs) { |
ollie8 | 0:5ef90cd25c10 | 76 | xbus = new BusOut(x0, x1, x2, x3); |
ollie8 | 0:5ef90cd25c10 | 77 | ybus = new BusOut(y0, y1, y2); |
ollie8 | 0:5ef90cd25c10 | 78 | data = new DigitalOut(d); |
ollie8 | 0:5ef90cd25c10 | 79 | strobe = new DigitalOut(str); |
ollie8 | 0:5ef90cd25c10 | 80 | reset = new DigitalOut(rs); |
ollie8 | 0:5ef90cd25c10 | 81 | data->write(0); |
ollie8 | 0:5ef90cd25c10 | 82 | strobe->write(0); |
ollie8 | 0:5ef90cd25c10 | 83 | reset->write(0); |
ollie8 | 0:5ef90cd25c10 | 84 | } |
ollie8 | 0:5ef90cd25c10 | 85 | |
ollie8 | 0:5ef90cd25c10 | 86 | ~CD22M3494() { |
ollie8 | 0:5ef90cd25c10 | 87 | delete xbus; |
ollie8 | 0:5ef90cd25c10 | 88 | delete ybus; |
ollie8 | 0:5ef90cd25c10 | 89 | delete data; |
ollie8 | 0:5ef90cd25c10 | 90 | delete strobe; |
ollie8 | 0:5ef90cd25c10 | 91 | delete reset; |
ollie8 | 2:25049dc7da13 | 92 | associationTable.clear(); |
ollie8 | 2:25049dc7da13 | 93 | delete &associationTable; |
ollie8 | 0:5ef90cd25c10 | 94 | } |
ollie8 | 0:5ef90cd25c10 | 95 | |
ollie8 | 0:5ef90cd25c10 | 96 | bool crossPointConnect(unsigned short x, unsigned short y) { |
ollie8 | 0:5ef90cd25c10 | 97 | if (x <= MAX_X && y <= MAX_Y) { |
ollie8 | 0:5ef90cd25c10 | 98 | data->write(1); |
ollie8 | 0:5ef90cd25c10 | 99 | xbus->write(x); |
ollie8 | 0:5ef90cd25c10 | 100 | ybus->write(y); |
ollie8 | 0:5ef90cd25c10 | 101 | // let the data busses settle before setting strobe high |
ollie8 | 0:5ef90cd25c10 | 102 | wait_us(2); |
ollie8 | 0:5ef90cd25c10 | 103 | strobe->write(1); |
ollie8 | 0:5ef90cd25c10 | 104 | // strobe must be high for at least 20 ns |
ollie8 | 0:5ef90cd25c10 | 105 | wait_us(1); |
ollie8 | 0:5ef90cd25c10 | 106 | strobe->write(0); |
ollie8 | 0:5ef90cd25c10 | 107 | return true; |
ollie8 | 0:5ef90cd25c10 | 108 | } |
ollie8 | 0:5ef90cd25c10 | 109 | return false; |
ollie8 | 0:5ef90cd25c10 | 110 | } |
ollie8 | 0:5ef90cd25c10 | 111 | |
ollie8 | 0:5ef90cd25c10 | 112 | bool crossPointDisconnect(unsigned short x, unsigned short y) { |
ollie8 | 0:5ef90cd25c10 | 113 | if (x <= MAX_X && y <= MAX_Y) { |
ollie8 | 0:5ef90cd25c10 | 114 | data->write(0); |
ollie8 | 0:5ef90cd25c10 | 115 | xbus->write(x); |
ollie8 | 0:5ef90cd25c10 | 116 | ybus->write(y); |
ollie8 | 0:5ef90cd25c10 | 117 | // let the data busses settle before setting strobe high |
ollie8 | 0:5ef90cd25c10 | 118 | wait_us(2); |
ollie8 | 0:5ef90cd25c10 | 119 | strobe->write(1); |
ollie8 | 0:5ef90cd25c10 | 120 | // strobe must be high for at least 20 ns |
ollie8 | 0:5ef90cd25c10 | 121 | wait_us(1); |
ollie8 | 0:5ef90cd25c10 | 122 | strobe->write(0); |
ollie8 | 0:5ef90cd25c10 | 123 | return true; |
ollie8 | 0:5ef90cd25c10 | 124 | } |
ollie8 | 0:5ef90cd25c10 | 125 | return false; |
ollie8 | 0:5ef90cd25c10 | 126 | } |
ollie8 | 1:bc9ca1d1d7a6 | 127 | |
ollie8 | 1:bc9ca1d1d7a6 | 128 | void associate(string name, unsigned short xp1, unsigned short xp2) { |
ollie8 | 2:25049dc7da13 | 129 | unsigned short *xps = new unsigned short[2]; |
ollie8 | 1:bc9ca1d1d7a6 | 130 | xps[0] = xp1; |
ollie8 | 1:bc9ca1d1d7a6 | 131 | xps[1] = xp2; |
ollie8 | 1:bc9ca1d1d7a6 | 132 | associationTable[name] = xps; |
ollie8 | 1:bc9ca1d1d7a6 | 133 | } |
ollie8 | 1:bc9ca1d1d7a6 | 134 | |
ollie8 | 1:bc9ca1d1d7a6 | 135 | bool routeAssociations(string src, string dst) { |
ollie8 | 1:bc9ca1d1d7a6 | 136 | if (associationTable.count(src) && associationTable.count(dst)) { |
ollie8 | 2:25049dc7da13 | 137 | crossPointConnect(associationTable[src][0], associationTable[dst][0]); |
ollie8 | 2:25049dc7da13 | 138 | crossPointConnect(associationTable[src][1], associationTable[dst][1]); |
ollie8 | 1:bc9ca1d1d7a6 | 139 | return true; |
ollie8 | 1:bc9ca1d1d7a6 | 140 | } |
ollie8 | 1:bc9ca1d1d7a6 | 141 | return false; |
ollie8 | 1:bc9ca1d1d7a6 | 142 | } |
ollie8 | 1:bc9ca1d1d7a6 | 143 | |
ollie8 | 1:bc9ca1d1d7a6 | 144 | bool unRouteAssociations(string src, string dst) { |
ollie8 | 1:bc9ca1d1d7a6 | 145 | if (associationTable.count(src) && associationTable.count(dst)) { |
ollie8 | 2:25049dc7da13 | 146 | crossPointDisconnect(associationTable[src][0], associationTable[dst][0]); |
ollie8 | 2:25049dc7da13 | 147 | crossPointDisconnect(associationTable[src][1], associationTable[dst][1]); |
ollie8 | 1:bc9ca1d1d7a6 | 148 | return true; |
ollie8 | 1:bc9ca1d1d7a6 | 149 | } |
ollie8 | 1:bc9ca1d1d7a6 | 150 | return false; |
ollie8 | 1:bc9ca1d1d7a6 | 151 | } |
ollie8 | 1:bc9ca1d1d7a6 | 152 | |
ollie8 | 3:fa46a8badc92 | 153 | bool getAssociation(string name, unsigned short *xps) { |
ollie8 | 3:fa46a8badc92 | 154 | if (associationTable.count(name)) { |
ollie8 | 3:fa46a8badc92 | 155 | xps[0] = associationTable[name][0]; |
ollie8 | 3:fa46a8badc92 | 156 | xps[1] = associationTable[name][1]; |
ollie8 | 3:fa46a8badc92 | 157 | return true; |
ollie8 | 3:fa46a8badc92 | 158 | } |
ollie8 | 3:fa46a8badc92 | 159 | return false; |
ollie8 | 3:fa46a8badc92 | 160 | } |
ollie8 | 3:fa46a8badc92 | 161 | |
ollie8 | 0:5ef90cd25c10 | 162 | private: |
ollie8 | 2:25049dc7da13 | 163 | BusOut *xbus; |
ollie8 | 2:25049dc7da13 | 164 | BusOut *ybus; |
ollie8 | 2:25049dc7da13 | 165 | DigitalOut *data; |
ollie8 | 2:25049dc7da13 | 166 | DigitalOut *strobe; |
ollie8 | 2:25049dc7da13 | 167 | DigitalOut *reset; |
ollie8 | 1:bc9ca1d1d7a6 | 168 | map<string, unsigned short*> associationTable; |
ollie8 | 0:5ef90cd25c10 | 169 | }; |
ollie8 | 0:5ef90cd25c10 | 170 | |
ollie8 | 0:5ef90cd25c10 | 171 | |
ollie8 | 0:5ef90cd25c10 | 172 | #endif |