1 /*********************************************************************
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 #include <xc.h>
34 #include <math.h>
35 #include "MainBrain.h"
36
37 char HeaderString[10] = {"MainBrain"};
38 char DisplayString[36] = {"480x320 16-bit RGB 65K Touch"};
39 char MessageBoxTitle[8] = {"Message"};
40 char ProcessorArray[18] = {"PIC32MZ2048EFH100"};
41 char SRAMsize[10] = {"8Kx8 SRAM"};
42 char PeripheralsStr[7] = {"Boards"};
43 char SRAMStatusPass[5] = {"Pass"};
44 char failStr[5] = {"Fail"};
45 char FlashSize[13] = {"512Kx8 Flash"};
46 char USBver[8] = {"USB 2.0"};
47 char ExitButtonText[5] = {"Exit"};
48 char Button1Text[5] = {"Info"};
49 char Button2Text[8] = {"Draw"};
50 char MenuText[20] = {"Draw"};
51 char SRAMFailText[14] = {"SRAM Fail!"};
52 char SRAMLockedText[14] = {"SRAM Locked!"};
53 char lastErrorText[9] = {"Errors: "};
54 char noneStr[5] = {"none"};
55 char vbusStr[5] = {"VBUS"};
56 char PrimaryOsc[8] = {"Pri OSC"};
57 char OtherOsc[6] = {"Other"};
58 char SequenceStr[15] = {"Sequence Data:"};
59 char M300Str[] = {"0x300:"};
60 char M301Str[] = {"0x301:"};
61 char M302Str[] = {"0x302:"};
62 char M306Str[] = {"0x306:"};
63 char M307Str[] = {"0x307:"};
64 char M308Str[] = {"0x308:"};
65 char StatusStr[8] = {"Status:"};
66 char ControlStr[9] = {"Control:"};
67 char ADCtitleStr[4] = {"ADC"};
68 char BoardtitleStr[12] = {"Peripherals"};
69 uint8_t LastError = 0;
70 int ButtonTopColor = 0xef7d;
71 int ButtonLowerColor = 0xd6ba;
72 bool DrawScreenOpen = false;
73 bool motionScreenActive = false;
74
75 void ShowSplashScreen(uint8_t option)
76 {
77 int i;
78
79
80 Display_CLRSCN(white);
81
82
83
84 Display_CASET(0, 479);
85 Display_RASET(120, 170);
86 Display_RAMWR();
87
88
89
90 PORTBbits.RB1 = 1;
91
92 for(i=0;i<=23040; i++)
93 {
94 PMDOUT = SplashImage[i*2];
95 while(PMMODEbits.BUSY == 1);
96 }
97
98
99
100 PORTAbits.RA9 = 1;
101
102 if(option == 1)
103 {
104 LongDelay(2);
105
106
107 Display_CLRSCN(white);
108
109
110 Delay32(0, 1000);
111 }
112 }
113
114 void ShowSRAM_FailScreen(void)
115 {
116
117 }
118
119 void ShowDrawScreen(void)
120 {
121 DrawScreenOpen = true;
122
123
124 Display_CLRSCN(white);
125
126
127
128
129 Display_Rect(10, 100, 40, 90, 0xd591);
130 WriteString(25, 50, MenuText, black, 0xd591);
131
132
133 }
134
135 DrawHeader()
136 {
137
138 Display_Rect(0, 480, 0, 40, 0x04D3);
139 }
140
141 void DrawMenu(void)
142 {
143 int i;
144
145 Display_CASET(100, 249);
146 Display_RASET(80, 229);
147 Display_RAMWR();
148
149
150
151 PORTBbits.RB1 = 1;
152
153 for(i=0;i<=22500; i++)
154 {
155 PMDOUT = DisplayMenu[i];
156 while(PMMODEbits.BUSY == 1);
157 }
158
159 WriteChar(192, 120, '5', black, white);
160
161
162
163 PORTAbits.RA9 = 1;
164
165 }
166
167 void DrawCanvas(uint8_t screen_, uint32_t begin_xpos, uint32_t begin_ypos, uint32_t _count)
168 {
169 uint32_t i;
170 uint32_t array_begin;
171 uint32_t array_count;
172
173
174 if(screen_ == CONFIG_SCREEN)
175 {
176
177 array_begin = (((begin_ypos + 1) * 480) - (480 - (begin_xpos + 1))) - 1;
178
179
180 Display_CASET(0, 479);
181 Display_RASET(0, 319);
182
183
184
185 Display_RAMWR();
186
187
188
189 PORTBbits.RB1 = 1;
190
191 for(i=0;i<=_count; i++)
192 {
193 PMDOUT = ConfigImage[i + array_begin];
194 while(PMMODEbits.BUSY == 1);
195 }
196 }
197 }
198
199 void DrawScreen(uint8_t scrn, char title[])
200 {
201
202 Display_CLRSCN(white);
203
204
205 DrawHeader();
206
207 switch(scrn)
208 {
209
210 case INFO_SCREEN:
211
212 WriteString(170, 5, title, black, 0x04D3);
213
214 hchar = 10;
215 vchar = 50;
216
217
218 WriteString(hchar, vchar, lastErrorText, black, white);
219
220 if(!lastError)
221 {
222 WriteString(hchar, vchar, noneStr, green, white);
223 }
224 else
225 {
226 Binary2ASCIIBCD(lastError);
227 WriteChar(hchar, vchar, d1, red, white);
228 WriteChar(hchar, vchar, d0, red, white);
229 }
230
231
232
233 hchar = 10;
234 vchar = vchar + 25;
235 WriteString(hchar, vchar, ProcessorArray, black, white);
236
237
238 hchar = 10;
239 vchar = vchar + 25;
240 WriteString(hchar, vchar, DisplayString, black, white);
241
242
243 hchar = 10;
244 vchar = vchar + 25;
245 WriteString(hchar, vchar, SRAMsize, black, white);
246
247 hchar = hchar + 15;
248
249 if((lastError & 0x4) != 0)
250 {
251 WriteString(hchar, vchar, failStr, red, white);
252 }
253 else
254 {
255 WriteString(hchar, vchar, SRAMStatusPass, green, white);
256 }
257
258 hchar = hchar + 15;
259
260
261 hchar = 10;
262 vchar = vchar + 25;
263 WriteString(hchar, vchar, FlashSize, black, white);
264
265
266 hchar = hchar + 15;
267 Binary2ASCIIHex(Flash_MID);
268 WriteChar(hchar, vchar, d_hex[1], black, white);
269 WriteChar(hchar, vchar, d_hex[0], black, white);
270
271
272 hchar = hchar + 15;
273 Binary2ASCIIHex(Flash_DID);
274 WriteChar(hchar, vchar, d_hex[1], black, white);
275 WriteChar(hchar, vchar, d_hex[0], black, white);
276
277 hchar = 10;
278 vchar = vchar + 25;
279
280
281 WriteString(hchar, vchar, PeripheralsStr, black, white);
282
283 hchar = hchar + 15;
284
285 for(int i=1;i<8;i++)
286 {
287 Binary2ASCIIHex(PeripheralList[i]);
288 WriteChar(hchar, vchar, d_hex[1], blue, white);
289 WriteChar(hchar, vchar, d_hex[0], blue, white);
290 hchar = hchar + 10;
291 }
292
293
294 hchar = 10;
295 vchar = vchar + 25;
296 WriteString(hchar, vchar, USBver, black, white);
297
298
299 hchar = 10;
300 vchar = vchar + 25;
301
302 switch(OSCCONbits.COSC)
303 {
304 case 1:
305 WriteString(hchar, vchar, PrimaryOsc, green, white);
306 break;
307
308 default:
309 WriteString(hchar, vchar, OtherOsc, green, white);
310 break;
311 }
312
313 vchar = vchar + 25;
314 hchar = 10;
315
316 WriteString(hchar, vchar, vbusStr, black, white);
317
318 break;
319
320
321 case BOARD_SCREEN:
322
323 WriteString(170, 5, title, black, 0x04D3);
324
325 hchar = 10;
326 vchar = 50;
327
328 for(int i=0;i<26;i++)
329 {
330 Binary2ASCIIHex(peripheral_info[current_board_address][i]);
331 WriteChar(hchar, vchar, d_hex[1], black, white);
332 WriteChar(hchar, vchar, d_hex[0], black, white);
333
334 hchar = hchar + 10;
335
336 if(hchar > 430)
337 {
338 hchar = 10;
339 vchar = vchar + 20;
340 }
341 }
342 break;
343
344 case CONFIG_SCREEN:
345
346
347
348 Display_CASET(0, 479);
349 Display_RASET(0, 319);
350 Display_RAMWR();
351
352
353
354 PORTBbits.RB1 = 1;
355
356 for(int i=0;i<=153600; i++)
357 {
358 PMDOUT = ConfigImage[i];
359 while(PMMODEbits.BUSY == 1);
360 }
361
362 break;
363
364
365 case HOME_SCREEN:
366
367 WriteString(120, 5, title, black, 0x04D3);
368
369
370 DrawButton(20, 50, 150, 50, ButtonTopColor, ButtonLowerColor, black, Button1Text);
371
372
373 DrawButton(20, 125, 150, 50, ButtonTopColor, ButtonLowerColor, black, Button2Text);
374
375 break;
376
377 case MOTION_SCREEN:
378
379 WriteString(120, 5, title, black, 0x04D3);
380
381 WriteString(10, 50, StatusStr, black, white);
382
383 WriteString(180, 50, ControlStr, black, white);
384
385 break;
386
387 case DEBUG_SCREEN:
388
389 WriteString(180, 5, HeaderString, black, 0x04D3);
390
391 WriteString(10, 50, StatusStr, black, white);
392
393 WriteString(180, 50, ControlStr, black, white);
394
395 break;
396
397 case ADC_SCREEN:
398
399 WriteString(10, 50, StatusStr, black, white);
400
401 break;
402 case MESSAGE_SCREEN:
403 Display_Rect(100, 200, 100, 200, blue);
404 break;
405 }
406
407 }
408
409 void DrawCircle(void)
410 {
411 int theta = 0;
412 int h = 200;
413 int k = 150;
414 int step = 15;
415 int x;
416 int y;
417 int r = 100;
418
419 while(theta < 360)
420 {
421 x = h + r*cos(theta);
422 y = k + r*sin(theta);
423 Display_Rect(x, x+5, y, y+5, blue);
424 theta = theta + 1;
425 }
426 }
427
428 void MessageBox(char text[], uint8_t show_time)
429 {
430
431 Display_Rect(100, 300, 220, 222, blue);
432 Display_Rect(98, 100, 100, 222, blue);
433 Display_Rect(300, 302, 100, 222, blue);
434
435
436 Display_Rect(100, 300, 100, 125, blue);
437 WriteString(105, 100, MessageBoxTitle, white, blue);
438
439
440 Display_Rect(100, 300, 125, 180, white);
441
442
443 Display_Rect(100, 300, 180, 220, 0xe73c);
444
445
446 WriteString(104, 140, text, black, white);
447
448
449 Display_Rect(302, 330, 130, 240, 0xef9d);
450 Display_Rect(130, 330, 222, 250, 0xef9d);
451
452 LongDelay(show_time);
453
454 screen = old_screen;
455 }
456
457