Dispatch console driver.

Committer:
Jasper
Date:
Thu Apr 14 17:05:36 2011 +0000
Revision:
0:8c8623cc3eb2
dispatch console fiddling

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jasper 0:8c8623cc3eb2 1 #include "mbed.h"
Jasper 0:8c8623cc3eb2 2
Jasper 0:8c8623cc3eb2 3 DigitalOut green(p22);
Jasper 0:8c8623cc3eb2 4 DigitalOut red(p21);
Jasper 0:8c8623cc3eb2 5 DigitalOut led1(LED1);
Jasper 0:8c8623cc3eb2 6 DigitalOut led2(LED2);
Jasper 0:8c8623cc3eb2 7 DigitalOut led3(LED3);
Jasper 0:8c8623cc3eb2 8 DigitalOut led4(LED4);
Jasper 0:8c8623cc3eb2 9
Jasper 0:8c8623cc3eb2 10 #define CH7 0x00000001
Jasper 0:8c8623cc3eb2 11 #define KEY_HASH 0x00000002
Jasper 0:8c8623cc3eb2 12 #define CH6 0x00000004
Jasper 0:8c8623cc3eb2 13 #define CH5 0x00000008
Jasper 0:8c8623cc3eb2 14 #define CH4 0x00000010
Jasper 0:8c8623cc3eb2 15 #define CH3 0x00000020
Jasper 0:8c8623cc3eb2 16 #define CH2 0x00000040
Jasper 0:8c8623cc3eb2 17 #define CH1 0x00000080
Jasper 0:8c8623cc3eb2 18 #define TAPE 0x00000100
Jasper 0:8c8623cc3eb2 19 #define B_CAST 0x00000200
Jasper 0:8c8623cc3eb2 20 #define CONN 0x00000400
Jasper 0:8c8623cc3eb2 21 #define T_T 0x00000800
Jasper 0:8c8623cc3eb2 22 #define MON 0x00001000
Jasper 0:8c8623cc3eb2 23 #define SEL 0x00002000
Jasper 0:8c8623cc3eb2 24 #define LS 0x00004000
Jasper 0:8c8623cc3eb2 25 #define TEL 0x00008000
Jasper 0:8c8623cc3eb2 26 #define KEY_5 0x00010000
Jasper 0:8c8623cc3eb2 27 #define KEY_4 0x00020000
Jasper 0:8c8623cc3eb2 28 #define KEY_3 0x00040000
Jasper 0:8c8623cc3eb2 29 #define KEY_2 0x00080000
Jasper 0:8c8623cc3eb2 30 #define KEY_1 0x00100000
Jasper 0:8c8623cc3eb2 31 #define BRB 0x00200000
Jasper 0:8c8623cc3eb2 32 #define FUNC 0x00400000
Jasper 0:8c8623cc3eb2 33 #define CTCSS 0x00800000
Jasper 0:8c8623cc3eb2 34 #define KEY_6 0x01000000
Jasper 0:8c8623cc3eb2 35 #define KEY_0 0x02000000
Jasper 0:8c8623cc3eb2 36 #define KEY_STAR 0x04000000
Jasper 0:8c8623cc3eb2 37 #define KEY_9 0x08000000
Jasper 0:8c8623cc3eb2 38 #define KEY_8 0x10000000
Jasper 0:8c8623cc3eb2 39 #define KEY_7 0x20000000
Jasper 0:8c8623cc3eb2 40
Jasper 0:8c8623cc3eb2 41
Jasper 0:8c8623cc3eb2 42 DigitalOut buttonspl(p20);
Jasper 0:8c8623cc3eb2 43 DigitalOut ledclock(p19);
Jasper 0:8c8623cc3eb2 44 DigitalOut leddata(p18);
Jasper 0:8c8623cc3eb2 45 DigitalOut ledstrobe(p17);
Jasper 0:8c8623cc3eb2 46 DigitalIn buttonsdata(p16);
Jasper 0:8c8623cc3eb2 47
Jasper 0:8c8623cc3eb2 48 void blues(int ledc)
Jasper 0:8c8623cc3eb2 49 {
Jasper 0:8c8623cc3eb2 50 led1 = led2 = led3 = led4 = 0;
Jasper 0:8c8623cc3eb2 51 switch (ledc) {
Jasper 0:8c8623cc3eb2 52 case 0:
Jasper 0:8c8623cc3eb2 53 led1 = 1;
Jasper 0:8c8623cc3eb2 54 break;
Jasper 0:8c8623cc3eb2 55 case 1:
Jasper 0:8c8623cc3eb2 56 led2 = 1;
Jasper 0:8c8623cc3eb2 57 break;
Jasper 0:8c8623cc3eb2 58 case 2:
Jasper 0:8c8623cc3eb2 59 led3 = 1;
Jasper 0:8c8623cc3eb2 60 break;
Jasper 0:8c8623cc3eb2 61 case 3:
Jasper 0:8c8623cc3eb2 62 led4 = 1;
Jasper 0:8c8623cc3eb2 63 break;
Jasper 0:8c8623cc3eb2 64 case 4:
Jasper 0:8c8623cc3eb2 65 led3 = 1;
Jasper 0:8c8623cc3eb2 66 break;
Jasper 0:8c8623cc3eb2 67 case 5:
Jasper 0:8c8623cc3eb2 68 led2 = 1;
Jasper 0:8c8623cc3eb2 69 break;
Jasper 0:8c8623cc3eb2 70 }
Jasper 0:8c8623cc3eb2 71 }
Jasper 0:8c8623cc3eb2 72
Jasper 0:8c8623cc3eb2 73 void switchled(int led) {
Jasper 0:8c8623cc3eb2 74 int i;
Jasper 0:8c8623cc3eb2 75
Jasper 0:8c8623cc3eb2 76 for (i = 0; i < 32 ; i++) {
Jasper 0:8c8623cc3eb2 77 ledclock = 0;
Jasper 0:8c8623cc3eb2 78 if (i == led)
Jasper 0:8c8623cc3eb2 79 leddata = 0;
Jasper 0:8c8623cc3eb2 80 else
Jasper 0:8c8623cc3eb2 81 leddata = 1;
Jasper 0:8c8623cc3eb2 82 ledclock = 1;
Jasper 0:8c8623cc3eb2 83 }
Jasper 0:8c8623cc3eb2 84 }
Jasper 0:8c8623cc3eb2 85
Jasper 0:8c8623cc3eb2 86 void button_test(uint32_t buttons) {
Jasper 0:8c8623cc3eb2 87 printf("keys down: ");
Jasper 0:8c8623cc3eb2 88 if (buttons & CH7) printf("CH7 ");
Jasper 0:8c8623cc3eb2 89 if (buttons & KEY_HASH) printf("KEY_HASH ");
Jasper 0:8c8623cc3eb2 90 if (buttons & CH6) printf("CH6 ");
Jasper 0:8c8623cc3eb2 91 if (buttons & CH5) printf("CH5 ");
Jasper 0:8c8623cc3eb2 92 if (buttons & CH4) printf("CH4 ");
Jasper 0:8c8623cc3eb2 93 if (buttons & CH3) printf("CH3 ");
Jasper 0:8c8623cc3eb2 94 if (buttons & CH2) printf("CH2 ");
Jasper 0:8c8623cc3eb2 95 if (buttons & CH1) printf("CH1 ");
Jasper 0:8c8623cc3eb2 96 if (buttons & TAPE) printf("TAPE ");
Jasper 0:8c8623cc3eb2 97 if (buttons & B_CAST) printf("B_CAST ");
Jasper 0:8c8623cc3eb2 98 if (buttons & CONN) printf("CONN ");
Jasper 0:8c8623cc3eb2 99 if (buttons & T_T) printf("T_T ");
Jasper 0:8c8623cc3eb2 100 if (buttons & MON) printf("MON ");
Jasper 0:8c8623cc3eb2 101 if (buttons & SEL) printf("SEL ");
Jasper 0:8c8623cc3eb2 102 if (buttons & LS) printf("LS ");
Jasper 0:8c8623cc3eb2 103 if (buttons & TEL) printf("TEL ");
Jasper 0:8c8623cc3eb2 104 if (buttons & KEY_5) printf("KEY_5 ");
Jasper 0:8c8623cc3eb2 105 if (buttons & KEY_4) printf("KEY_4 ");
Jasper 0:8c8623cc3eb2 106 if (buttons & KEY_3) printf("KEY_3 ");
Jasper 0:8c8623cc3eb2 107 if (buttons & KEY_2) printf("KEY_2 ");
Jasper 0:8c8623cc3eb2 108 if (buttons & KEY_1) printf("KEY_1 ");
Jasper 0:8c8623cc3eb2 109 if (buttons & BRB) printf("BRB ");
Jasper 0:8c8623cc3eb2 110 if (buttons & FUNC) printf("FUNC ");
Jasper 0:8c8623cc3eb2 111 if (buttons & CTCSS) printf("CTCSS ");
Jasper 0:8c8623cc3eb2 112 if (buttons & KEY_6) printf("KEY_6 ");
Jasper 0:8c8623cc3eb2 113 if (buttons & KEY_0) printf("KEY_0 ");
Jasper 0:8c8623cc3eb2 114 if (buttons & KEY_STAR) printf("KEY_STAR ");
Jasper 0:8c8623cc3eb2 115 if (buttons & KEY_9) printf("KEY_9 ");
Jasper 0:8c8623cc3eb2 116 if (buttons & KEY_8) printf("KEY_8 ");
Jasper 0:8c8623cc3eb2 117 if (buttons & KEY_7) printf("KEY_7 ");
Jasper 0:8c8623cc3eb2 118 printf("\r\n");
Jasper 0:8c8623cc3eb2 119 }
Jasper 0:8c8623cc3eb2 120
Jasper 0:8c8623cc3eb2 121 int boardstatus(uint32_t leds)
Jasper 0:8c8623cc3eb2 122 {
Jasper 0:8c8623cc3eb2 123 uint32_t buttons = 0;
Jasper 0:8c8623cc3eb2 124 int i, bbit;
Jasper 0:8c8623cc3eb2 125
Jasper 0:8c8623cc3eb2 126 buttonspl = 1;
Jasper 0:8c8623cc3eb2 127 wait_us(20);
Jasper 0:8c8623cc3eb2 128 buttonspl = 0;
Jasper 0:8c8623cc3eb2 129
Jasper 0:8c8623cc3eb2 130 ledstrobe = 1;
Jasper 0:8c8623cc3eb2 131
Jasper 0:8c8623cc3eb2 132 for (i = 0; i < 32 ; i++) {
Jasper 0:8c8623cc3eb2 133 ledclock = 1;
Jasper 0:8c8623cc3eb2 134 if (leds & (1 << i))
Jasper 0:8c8623cc3eb2 135 leddata = 0;
Jasper 0:8c8623cc3eb2 136 else
Jasper 0:8c8623cc3eb2 137 leddata = 1;
Jasper 0:8c8623cc3eb2 138 ledclock = 0;
Jasper 0:8c8623cc3eb2 139 bbit = buttonsdata;
Jasper 0:8c8623cc3eb2 140 buttons |= bbit << i;
Jasper 0:8c8623cc3eb2 141 }
Jasper 0:8c8623cc3eb2 142
Jasper 0:8c8623cc3eb2 143 ledstrobe = 0;
Jasper 0:8c8623cc3eb2 144
Jasper 0:8c8623cc3eb2 145 return buttons;
Jasper 0:8c8623cc3eb2 146 }
Jasper 0:8c8623cc3eb2 147
Jasper 0:8c8623cc3eb2 148 int main() {
Jasper 0:8c8623cc3eb2 149 green = 1; red = 0;
Jasper 0:8c8623cc3eb2 150 int count = 0;
Jasper 0:8c8623cc3eb2 151 int buttons, obuttons;
Jasper 0:8c8623cc3eb2 152 uint32_t bleds;
Jasper 0:8c8623cc3eb2 153
Jasper 0:8c8623cc3eb2 154 ledclock = 0;
Jasper 0:8c8623cc3eb2 155 bleds = 0;
Jasper 0:8c8623cc3eb2 156
Jasper 0:8c8623cc3eb2 157 buttons = obuttons = 0;
Jasper 0:8c8623cc3eb2 158
Jasper 0:8c8623cc3eb2 159 printf("Hello\r\n");
Jasper 0:8c8623cc3eb2 160
Jasper 0:8c8623cc3eb2 161 while(1) {
Jasper 0:8c8623cc3eb2 162 if ((count % 10) == 0)
Jasper 0:8c8623cc3eb2 163 green = !green;
Jasper 0:8c8623cc3eb2 164
Jasper 0:8c8623cc3eb2 165 if ((count % 5) == 0)
Jasper 0:8c8623cc3eb2 166 red = !red;
Jasper 0:8c8623cc3eb2 167
Jasper 0:8c8623cc3eb2 168 buttons = boardstatus(bleds);
Jasper 0:8c8623cc3eb2 169
Jasper 0:8c8623cc3eb2 170 if (buttons != obuttons) {
Jasper 0:8c8623cc3eb2 171 button_test(buttons);
Jasper 0:8c8623cc3eb2 172
Jasper 0:8c8623cc3eb2 173 #define ISPRESSED(x) (buttons & x)
Jasper 0:8c8623cc3eb2 174 #define WASPRESSED(x) (!(buttons &x ) && (obuttons & x))
Jasper 0:8c8623cc3eb2 175
Jasper 0:8c8623cc3eb2 176 if (ISPRESSED(CH1)) {bleds |= 0xf;}
Jasper 0:8c8623cc3eb2 177 if (ISPRESSED(CH2)) {bleds |= 0xf0;}
Jasper 0:8c8623cc3eb2 178 if (ISPRESSED(CH3)) {bleds |= 0xf00;}
Jasper 0:8c8623cc3eb2 179 if (ISPRESSED(CH4)) {bleds |= 0xf000;}
Jasper 0:8c8623cc3eb2 180 if (ISPRESSED(CH5)) {bleds |= (uint32_t)0xf << 28;}
Jasper 0:8c8623cc3eb2 181 if (ISPRESSED(CH6)) {bleds |= (uint32_t)0xf << 24;}
Jasper 0:8c8623cc3eb2 182 if (ISPRESSED(CH7)) {bleds |= 0xf << 20;}
Jasper 0:8c8623cc3eb2 183
Jasper 0:8c8623cc3eb2 184 if (WASPRESSED(CH1)) {bleds &= ~0xf;}
Jasper 0:8c8623cc3eb2 185 if (WASPRESSED(CH2)) {bleds &= ~0xf0;}
Jasper 0:8c8623cc3eb2 186 if (WASPRESSED(CH3)) {bleds &= ~0xf00;}
Jasper 0:8c8623cc3eb2 187 if (WASPRESSED(CH4)) {bleds &= ~0xf000;}
Jasper 0:8c8623cc3eb2 188 if (WASPRESSED(CH5)) {bleds &= ~((uint32_t)0xf << 28);}
Jasper 0:8c8623cc3eb2 189 if (WASPRESSED(CH6)) {bleds &= ~((uint32_t)0xf << 24);}
Jasper 0:8c8623cc3eb2 190 if (WASPRESSED(CH7)) {bleds &= ~(0xf << 20);}
Jasper 0:8c8623cc3eb2 191
Jasper 0:8c8623cc3eb2 192 if (ISPRESSED(BRB)) {bleds = 0;}
Jasper 0:8c8623cc3eb2 193 obuttons = buttons;
Jasper 0:8c8623cc3eb2 194 }
Jasper 0:8c8623cc3eb2 195
Jasper 0:8c8623cc3eb2 196 if (count & 1) {
Jasper 0:8c8623cc3eb2 197 bleds |= 1 << 16;
Jasper 0:8c8623cc3eb2 198 bleds &= ~(1 << 17);
Jasper 0:8c8623cc3eb2 199 } else {
Jasper 0:8c8623cc3eb2 200 bleds |= 1 << 17;
Jasper 0:8c8623cc3eb2 201 bleds &= ~(1 << 16);
Jasper 0:8c8623cc3eb2 202 }
Jasper 0:8c8623cc3eb2 203
Jasper 0:8c8623cc3eb2 204 count++;
Jasper 0:8c8623cc3eb2 205 wait(0.1);
Jasper 0:8c8623cc3eb2 206 }
Jasper 0:8c8623cc3eb2 207 }