src/main.cpp

changeset 3
a3233abe730e
parent 2
d0826e4a1ff7
child 4
219766126afb
equal deleted inserted replaced
2:d0826e4a1ff7 3:a3233abe730e
1 #include "stdio.h" 1 #include "stdio.h"
2 #include "mbed.h" 2 #include "mbed.h"
3 #include "string" 3 #include "string"
4 #include "Terminal6x8.h"
5 #include "Mono19x27.h"
6 #include "Mono15x22.h"
4 #include "Arial12x12.h" 7 #include "Arial12x12.h"
5 #include "Arial28x28.h"
6 //#include "Arial24x23.h"
7 //#include "Terminal6x8.h"
8 //#include "Arial43x48_numb.h"
9 8
10 #include "BufferedSerial.h" 9 #include "BufferedSerial.h"
11 10
12 #include "SPI8.h" 11 #include "SSD1322.h"
13 #include "ILI9341.h" 12
14 13 Serial pc(USBTX, USBRX);
15 //Serial pc(USBTX, USBRX);
16 BufferedSerial hp(NC, PA_1, 64, 0); // serial4 14 BufferedSerial hp(NC, PA_1, 64, 0); // serial4
17 15
18 ILI9341 tft(SPI_8, 24000000, PA_7, PA_6, PA_5, PA_4, PB_6, PC_7, "myLCD"); // Spi 8bit, 24MHz, mosi, miso, sclk, cs, reset, dc 16 SSD1322 dsp(SPI_8, 10000000, PB_15, PB_14, PB_13, PB_12, D11, D12, "SSD1322", 256, 64);
19 //ILI9341 tft(SPI_8, 24000000, PA_7, PA_6, PA_5, PA_4, PB_6, PB_5, "myLCD"); 17
20 18 #define MAX_BUFF 14
21 #define MAX_BUFF 16
22 uint8_t curchar; 19 uint8_t curchar;
23 uint8_t cmd; 20 uint8_t cmd;
24 uint8_t nchars; 21 uint8_t nchars;
25 char buffer[MAX_BUFF+1]; 22 char buffer[MAX_BUFF+1];
26 23
27 typedef struct _DSP 24 typedef struct _DSP
28 { 25 {
29 uint8_t cmd; 26 uint8_t cmd;
30 uint16_t color; 27 uint8_t color;
31 uint16_t bgcolor; 28 uint8_t bgcolor;
29 uint8_t x0;
32 uint8_t y0; 30 uint8_t y0;
33 uint8_t fmt; // 0=>ascii, 1=>hex, 2=>bits, 3=>flags 31 uint8_t fmt; // 0=>ascii, 1=>hex, 2=>bits, 3=>flags
34 uint8_t maxsize; 32 uint8_t maxsize;
33 uint8_t width;
35 const unsigned char* font; 34 const unsigned char* font;
36 char buffer[MAX_BUFF+1]; 35 char buffer[MAX_BUFF+1];
37 } DSP; 36 } DSP;
38 37
39 static DSP table[] = 38 static DSP table[] =
40 { 39 {
41 { 0x00, Blue, Black, 5, 0, MAX_BUFF, Arial28x28}, 40 { 0x00, 0xF, 0x0, 0, 0, 0, MAX_BUFF, 245, Mono19x27}, // main display
42 { 0x0C, Blue, Black, 40, 0, 3, Arial28x28}, 41 { 0x0C, 0xF, 0x0,204, 38, 0, 3, 45, Mono15x22}, // channels display
43 { 0x01, Green, Black, 95, 1, MAX_BUFF, Arial12x12}, 42 { 0x01, 0xF, 0x0, 0, 0, 4, MAX_BUFF, 0, Terminal6x8},
44 { 0x02, Green, Black, 110, 1, MAX_BUFF, Arial12x12}, 43 { 0x02, 0xF, 0x0, 0, 0, 4, MAX_BUFF, 0, Terminal6x8},
45 { 0x0A, Blue, Yellow, 145, 2, 4, Arial12x12}, 44 { 0x0A, 0xF, 0x0, 0, 57, 2, 4, 0, Terminal6x8},
46 { 0x0A, Yellow, Black, 70 , 3, 4, Arial12x12}, 45 { 0x0A, 0xF, 0x0, 0, 0, 3, 4, 0, Terminal6x8}, // flags
47 { 0xFF, Red, Black, 210, 0, MAX_BUFF, Arial12x12}, 46 { 0xFF, 0xF, 0x0, 0, 0, 4, MAX_BUFF, 0, Terminal6x8},
48 }; 47 };
49 48
49 // 9x10
50 const unsigned char icon_alarm[] __attribute__((aligned (2))) =
51 {
52 0x1c, 0x0,
53 0x3e, 0x0,
54 0x7f, 0x0,
55 0x7f, 0x0,
56 0x7f, 0x0,
57 0x7f, 0x0,
58 0x7f, 0x0,
59 0x7f, 0x0,
60 0xff, 0x80,
61 0x10, 0x0
62 };
63
64 const unsigned char icon_curve[] __attribute__((aligned (2))) =
65 {
66 0x80, 0x0,
67 0x80, 0x0,
68 0x80, 0x80,
69 0x81, 0x0,
70 0x9e, 0x0,
71 0xa0, 0x0,
72 0xc0, 0x0,
73 0x80, 0x0,
74 0x80, 0x0,
75 0xff, 0x80
76 };
77
50 typedef struct _FLAG 78 typedef struct _FLAG
51 { 79 {
52 uint8_t flag; 80 uint8_t flag;
53 uint8_t x; 81 uint8_t x;
54 uint8_t y; 82 uint8_t y;
55 const char* msg; 83 const char* msg;
84 const unsigned char* icon;
56 } FLAG; 85 } FLAG;
57 86
58 static const FLAG flags[] = 87 static const FLAG flags[] =
59 { 88 {
60 { 0x00, 0, 70, "Alarm"}, // F1.1 89 //{ 0x00, 160, 30, "Alarm"}, // for the 'alarm' box
61 { 0x01, 40, 70, "Mx+B"}, // F1.2 90 { 0x00, 246, 0, NULL, icon_alarm}, // F1.1
62 { 0x03, 40, 70, "Channels"}, // F1.4 91 { 0x01, 246, 11, NULL, icon_curve}, // F1.2
63 { 0x14, 70, 70, "4W"}, // F2.5 92 { 0x03, 204, 30, "Channel"}, // F1.4
64 { 0x33, 90, 70, "VIEW"}, 93 { 0x14, 68, 44, "4W"}, // F2.5
65 { 0x34, 120, 70, "MON"}, 94 { 0x33, 40, 44, "VIEW"}, // F4.4
66 { 0x36, 150, 70, "CONFIG"}, 95 { 0x34, 0, 30, "MON"}, // F4.5
96 { 0x36, 0, 44, "CONFIG"}, // F4.7
97
98 { 0xFF, 0, 0, "SCAN"}, // F4.6 or F4.3
99 { 0xFF, 0, 0, "*"},
100 { 0xFF, 0, 0, "ADRS"},
101 { 0xFF, 0, 0, "RMT"},
102 { 0xFF, 0, 0, "ERROR"},
103 { 0xFF, 0, 0, "EXT"},
104 { 0xFF, 0, 0, "ONCE"},
105 { 0xFF, 0, 0, "AUTO"},
106 { 0xFF, 0, 0, "MEM"},
107 { 0xFF, 0, 0, "LAST"},
108 { 0xFF, 0, 0, "MIN"},
109 { 0xFF, 0, 0, "MAX"},
110 { 0xFF, 0, 0, "AVG"},
111 { 0xFF, 0, 0, "OC"},
112
113 { 0xFF, 0, 0, "H"},
114 { 0xFF, 0, 0, "1"},
115 { 0xFF, 0, 0, "2"},
116 { 0xFF, 0, 0, "3"},
117 { 0xFF, 0, 0, "4"},
118 { 0xFF, 0, 0, "L"},
119
67 }; 120 };
68 #define DEBUG 121
122
69 #ifdef DEBUG 123 #ifdef DEBUG
70 #define DBGPIN PC_0 124 #define DBGPIN PC_0
71 125
72 DigitalOut dbgpin(DBGPIN); 126 DigitalOut dbgpin(DBGPIN);
73 inline void DebugPulse(uint8_t count=1) 127 inline void DebugPulse(uint8_t count=1)
81 #else 135 #else
82 inline void DebugPulse(uint8_t count=1) 136 inline void DebugPulse(uint8_t count=1)
83 {} 137 {}
84 #endif 138 #endif
85 139
140 void test_dsp();
141
86 void setup() { 142 void setup() {
87 // init the LCD 143 // init the LCD
88 144
89 tft.set_orientation(3); 145 //dsp.set_orientation(3);
90 //pc.baud (115200); 146 pc.baud (115200);
91 //pc.printf("\n\nSystem Core Clock = %.3f MHZ\r\n", 147 pc.printf("\n\nSystem Core Clock = %.3f MHZ\r\n",
92 // (float)SystemCoreClock/1000000); 148 (float)SystemCoreClock/1000000);
93 149
94 hp.baud(187500); 150 hp.baud(187500);
95 151
96 // myLCD.set_font((unsigned char*) Terminal6x8); 152 // myLCD.set_font((unsigned char*) Terminal6x8);
97 // myLCD.claim(stdout); // send stdout to the LCD display 153 // myLCD.claim(stdout); // send stdout to the LCD display
98 // myLCD.claim(stderr); // send stderr to the LCD display 154 // myLCD.claim(stderr); // send stderr to the LCD display
99 tft.background(Black); // set background to black 155 dsp.background(Black); // set background to black
100 tft.cls(); 156 dsp.foreground(0xF);
101 157 dsp.cls();
158 dsp.locate(0, 0);
159 dsp.set_font(Mono19x27);
160
102 cmd = 0xFF; 161 cmd = 0xFF;
103 curchar = 0; 162 curchar = 0;
104 nchars = 0; 163 nchars = 0;
164
165 dsp.printf("HP34970A");
166 dsp.set_font(Terminal6x8);
167 for(uint8_t i=0; i<4; i++) {
168 dsp.locate(160, i*8);
169 dsp.printf("Lg %d", i+1);
170 dsp.locate(208, (3-i)*8);
171 dsp.printf("Lg %d", i+1);
172 }
173 dsp.copy_to_lcd();
174 wait(2);
175 dsp.cls();
176 test_dsp();
177 wait(2);
178 dsp.cls();
105 } 179 }
106 180
107 void go_msg() { 181 void go_msg() {
108 tft.set_font((unsigned char*) Arial12x12); 182 dsp.set_font((unsigned char*) Arial12x12);
109 tft.locate(0, 210); 183 dsp.locate(0, 38);
110 } 184 }
111 185
112 void show(uint8_t cmd, char *txt, uint8_t nchar=0) { 186 void show(uint8_t cmd, char *txt, uint8_t nchar=0) {
113 uint8_t i, len; 187 uint8_t i, len;
114 uint16_t bgcolor, fgcolor; 188 uint16_t bgcolor, fgcolor;
118 192
119 for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) { 193 for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) {
120 if (table[i].cmd == cmd) { 194 if (table[i].cmd == cmd) {
121 bgcolor = table[i].bgcolor; 195 bgcolor = table[i].bgcolor;
122 fgcolor = table[i].color; 196 fgcolor = table[i].color;
123 tft.background(bgcolor); 197 dsp.background(bgcolor);
124 tft.foreground(fgcolor); 198 dsp.foreground(fgcolor);
125 tft.locate(0, table[i].y0); 199 dsp.locate(table[i].x0, table[i].y0);
126 tft.set_font((unsigned char*) table[i].font); 200 dsp.set_font((unsigned char*) table[i].font);
127 oldv = table[i].buffer; 201 oldv = table[i].buffer;
128 202
129 switch (table[i].fmt) { 203 switch (table[i].fmt) {
130 case 0: //ascii 204 case 0: //ascii
131 tft.printf(txt); 205 if (table[i].width > 0)
132 for (uint8_t j=strlen(txt); j<table[i].maxsize; j++) 206 dsp.fillrect(table[i].x0, table[i].y0, table[i].x0 + table[i].width, table[i].y0 + table[i].font[2], bgcolor);
133 tft.printf(" "); 207 dsp.printf(txt);
134 break; 208 break;
135 case 1: // hex 209 case 1: // hex
136 for (uint8_t j=0;; j++) { 210 for (uint8_t j=0;; j++) {
137 if (txt[j] == 0x00) 211 if (txt[j] == 0x00)
138 break; 212 break;
139 tft.printf("%02X ", txt[j]); 213 dsp.printf("%02X ", txt[j]);
140 } 214 }
141 for (uint8_t j=3*strlen(txt); j<table[i].maxsize; j++) 215 for (uint8_t j=3*strlen(txt); j<table[i].maxsize; j++)
142 tft.printf(" "); 216 dsp.printf(" ");
143 break; 217 break;
144 case 2: // binary 218 case 2: // binary
145 tft.foreground(fgcolor); 219 dsp.foreground(fgcolor);
146 tft.printf(" ["); 220 dsp.printf(" [");
147 for (uint8_t j=0; j<max(nchar, table[i].maxsize) ; j++) { 221 for (uint8_t j=0; j<max(nchar, table[i].maxsize) ; j++) {
148 if (j>0) { 222 if (j>0) {
149 tft.foreground(fgcolor); 223 dsp.foreground(fgcolor);
150 tft.printf(" | "); 224 dsp.printf(" | ");
151 } 225 }
152 for (uint8_t k=0; k<8; k++) { 226 for (uint8_t k=0; k<8; k++) {
153 if (txt[j] & (1 << (7-k))) 227 if (txt[j] & (1 << (7-k)))
154 tft.foreground(fgcolor); 228 dsp.foreground(fgcolor);
155 else 229 else
156 tft.foreground(bgcolor); 230 dsp.foreground(bgcolor);
157 tft.printf("%d", (8-k)); 231 dsp.printf("%d", (8-k));
158 } 232 }
159 } 233 }
160 tft.foreground(fgcolor); 234 dsp.foreground(fgcolor);
161 tft.printf("]"); 235 dsp.printf("]");
162 break; 236 break;
163 case 3: // flags 237 case 3: // flags
164 for (uint8_t j=0; j<max(nchar, table[i].maxsize) ; j++) { 238 for (uint8_t j=0; j<max(nchar, table[i].maxsize) ; j++) {
165 for (uint8_t k=0; k<8; k++) { 239 for (uint8_t k=0; k<8; k++) {
166 if ((txt[j] & (1 << k) ) != (oldv[j] & (1 << k))) { 240 if ((txt[j] & (1 << k) ) != (oldv[j] & (1 << k))) {
167 241
168 if (txt[j] & (1 << k)) 242 if (txt[j] & (1 << k))
169 tft.foreground(fgcolor); 243 dsp.foreground(fgcolor);
170 else 244 else
171 tft.foreground(bgcolor); 245 dsp.foreground(bgcolor);
172 for (uint8_t l=0; 246 for (uint8_t l=0;
173 l<(sizeof(flags)/sizeof(flags[0])); ++l) { 247 l<(sizeof(flags)/sizeof(flags[0])); ++l) {
174 if (flags[l].flag == ((j<<4) + k)) { 248 if (flags[l].flag == ((j<<4) + k)) {
175 tft.locate(flags[l].x, flags[l].y); 249 if (flags[l].msg != NULL) { // a string
176 tft.printf(flags[l].msg); 250 dsp.locate(flags[l].x, flags[l].y);
251 dsp.printf(flags[l].msg);}
252 else { // an icon
253 Bitmap_s pic = {9, 10, 2, flags[l].icon};
254 dsp.Bitmap_BW(pic, flags[l].x, flags[l].y);
255 }
177 break; 256 break;
178 } 257 }
179 } 258 }
180 } 259 }
181 } 260 }
182 oldv[j] = txt[j]; 261 oldv[j] = txt[j];
183 } 262 }
184 break; 263 break;
264 case 4: //ignore
265 break;
185 } 266 }
186
187 } 267 }
188 } 268 }
189 269 dsp.copy_to_lcd();
270
271 }
272
273 void test_dsp()
274 {
275 show(0x00, "8g8g8g8g8g8g8", 13); // main dsp
276 show(0x0C, "888", 3); // channel dsp
277 show(0x0A, "\xFF\xFF\xFF\xFF", 4); // flags
278 dsp.copy_to_lcd();
190 } 279 }
191 280
192 281
193 void loop() { // run over and over 282 void loop() { // run over and over
194 if (hp.readable()) { 283 if (hp.readable()) {
195 uint8_t val = hp.getc(); 284 uint8_t val = hp.getc();
196 DebugPulse(3); 285 DebugPulse(3);
197 // 0xFF: idle 286 // 0xFF: idle
198 // 0xFE: frame finished 287 // 0xFE: frame finished
199 // 0x66: Start of transmission received 288 // 0x66: Start of transmission received
289 pc.printf(" VAL=0x%X\tCMD=0x%X\n", val, cmd);
200 if (cmd == 0xFF) { 290 if (cmd == 0xFF) {
201 if ((val == 0x66) || (val == 0x99)) { 291 if ((val == 0x66) || (val == 0x99)) {
202 cmd = val; 292 cmd = val;
203 } else if ((val == 0x00) || (val == 0x55)){ 293 } else if ((val == 0x00) || (val == 0x55)){
204 // probably an ACK for a keypad related event 294 // probably an ACK for a keypad related event
205 } else { 295 } else {
206 // display "junk" byte 296 // display "junk" byte
207 //DebugPulse(); 297 //DebugPulse();
208 show(0xFF, "", 0); 298 show(0xFF, "", 0);
209 tft.printf("%02X:> %02x", cmd, val); 299 dsp.printf("%02X:> %02x", cmd, val);
210 } 300 }
211 301
212 } else if (cmd == 0xFE ) { 302 } else if (cmd == 0xFE ) {
213 if ((val == 0x66) || (val == 0x99)) { 303 if ((val == 0x66) || (val == 0x99)) {
214 cmd = val; 304 cmd = val;
218 // probably an ACK for a keypad related event 308 // probably an ACK for a keypad related event
219 } else { 309 } else {
220 // display "junk" byte 310 // display "junk" byte
221 DebugPulse(); 311 DebugPulse();
222 show(0xFF, "", 5); 312 show(0xFF, "", 5);
223 tft.printf("%02X=> %02x", cmd, val); 313 dsp.printf("%02X=> %02x", cmd, val);
224 } 314 }
225 315
226 } else if (cmd == 0x66) { // waiting for the display command 316 } else if (cmd == 0x66) { // waiting for the display command
227 if ((val == 0x0C) || (val == 0x00) || (val == 0x01) || (val == 0x02) || (val == 0x0A)) { 317 if ((val == 0x0C) || (val == 0x00) || (val == 0x01) || (val == 0x02) || (val == 0x0A)) {
228 cmd = val; 318 cmd = val;
230 } else { 320 } else {
231 cmd = 0xFE; 321 cmd = 0xFE;
232 // display unknown cmd byte 322 // display unknown cmd byte
233 DebugPulse(); 323 DebugPulse();
234 show(0xFF, "", 10); 324 show(0xFF, "", 10);
235 tft.printf("%02X-> %02x", cmd, val); 325 dsp.printf("%02X-> %02x", cmd, val);
236 } 326 }
237 327
238 } else if (cmd == 0x99) { // waiting for a 0x00, it's the DP that sent a keypress event 328 } else if (cmd == 0x99) { // waiting for a 0x00, it's the DP that sent a keypress event
239 if (val != 0x00) { 329 if (val != 0x00) {
240 show(0xFF, "", 0); 330 show(0xFF, "", 0);
241 tft.printf("%02X kp %02X", cmd, val); 331 dsp.printf("%02X kp %02X", cmd, val);
242 } 332 }
243 cmd = 0xFF; 333 cmd = 0xFF;
244 334
245 } else if (nchars == 0) { // waiting for the number of chars to display 335 } else if (nchars == 0) { // waiting for the number of chars to display
246 if (val>MAX_BUFF) { 336 if (val>MAX_BUFF) {
247 // display warning 337 // display warning
248 //dsp(); 338 //dsp();
249 //tft << cmd << " got len " << val; 339 //dsp << cmd << " got len " << val;
250 //DebugPulse(); 340 //DebugPulse();
251 show(0xFF, "", 0); 341 show(0xFF, "", 0);
252 tft.printf("%02X len %d", cmd, val); 342 dsp.printf("%02X len %d", cmd, val);
253 cmd = 0xFE; // weird 343 cmd = 0xFE; // weird
254 } else { 344 } else {
255 nchars = val; 345 nchars = val;
256 curchar = 0; 346 curchar = 0;
257 } 347 }

mercurial