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) |
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; |