-
Notifications
You must be signed in to change notification settings - Fork 10
/
tft.c
700 lines (629 loc) · 18.9 KB
/
tft.c
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <libgen.h>
#include <sys/stat.h>
#ifdef SPI
#include "spilib.h"
#endif
#ifndef SPI
#include "8bitlib.h"
#endif
#define MAXLINE 8
#define MAXCHAR 32
#define _DEBUG_ 0
uint16_t _FONT_DIRECTION_;
uint16_t _FONT_FILL_;
uint16_t _FONT_FILL_COLOR_;
uint16_t _FONT_UNDER_LINE_;
uint16_t _FONT_UNDER_LINE_COLOR_;
typedef struct {
uint8_t colum;
uint16_t fcolor;
uint16_t bcolor;
uint8_t enhance;
uint8_t size;
uint16_t sjis[MAXCHAR];
} SaveData;
typedef struct {
uint16_t basecolor;
uint16_t fontwidth;
uint16_t fontheight;
uint16_t direction;
SaveData save[MAXLINE];
} SaveFrame;
void usage(char *prog);
void InitSaveData(SaveFrame *hoge);
void DumpSaveFrame(SaveFrame hoge);
int ReadTFTConfig(char *path, int *width, int *height, int *xofs, int *yofs);
int ReadPinConfig(TFTPin *pins, char *path);
int main(int argc, char **argv){
int i;
int XMAX, YMAX;
int XOFS, YOFS;
char dir[128];
char cpath[128];
char dpath[128];
char spath[128];
char ppath[128];
FILE *fp;
SaveFrame sv;
if(_DEBUG_)printf("argv[0]=%s\n",argv[0]);
strcpy(dir, argv[0]);
for(i=strlen(dir);i>0;i--) {
if (dir[i-1] == '/') {
dir[i] = 0;
break;
}
}
if(_DEBUG_)printf("dir=%s\n",dir);
strcpy(dpath,dir);
strcat(dpath,"tft.data");
if(_DEBUG_)printf("dpath=%s\n",dpath);
strcpy(cpath,dir);
strcat(cpath,"tft.conf");
if(_DEBUG_)printf("cpath=%s\n",cpath);
strcpy(spath,dir);
strcat(spath,"spi.conf");
if(_DEBUG_)printf("spath=%s\n",spath);
strcpy(ppath,dir);
strcat(ppath,"pin.conf");
if(_DEBUG_)printf("ppath=%s\n",ppath);
if (ReadTFTConfig(cpath, &XMAX, &YMAX, &XOFS, &YOFS) == 0) {
printf("%s Not found\n",cpath);
return 1;
}
if(_DEBUG_)printf("ReadTFTConfig:XMAX=%d YMAX=%d XOFS=%d YOFS=%d\n",XMAX, YMAX, XOFS, YOFS);
#ifdef SPI
TFTPin pins;
pins.rst = 9;
pins.rs = 8;
ReadPinConfig(&pins, spath);
if(_DEBUG_)printf("rst=%d cs=%d\n", pins.rst,pins.rs);
#endif
#ifndef SPI
TFTPin pins;
pins.rst = 7;
pins.cs = 8;
pins.rs = 9;
pins.wr = 11;
pins.rd = 31;
pins.d0 = 21;
pins.d1 = 22;
pins.d2 = 23;
pins.d3 = 24;
pins.d4 = 25;
pins.d5 = 26;
pins.d6 = 27;
pins.d7 = 28;
ReadPinConfig(&pins, ppath);
if(_DEBUG_)printf("rst=%d cs=%d rs=%d wr=%d rd=%d\n",
pins.rst,pins.cs,pins.rs,pins.wr,pins.rd);
if(_DEBUG_)printf("d0=%d d1=%d d2=%d d4=%d d4=%d d5=%d d6=%d d7=%d\n",
pins.d0,pins.d1,pins.d2,pins.d3,pins.d4,pins.d5,pins.d6,pins.d7);
#endif
struct stat stat_buf;
if (stat(dpath,&stat_buf) == 0) {
if(_DEBUG_)printf("%s found\n",dpath);
fp = fopen(dpath,"rb");
fread(&sv,sizeof(sv),1,fp);
fclose(fp);
} else {
if(_DEBUG_)printf("%s not found\n",dpath);
memset(&sv,0,sizeof(sv));
InitSaveData(&sv);
}
if(_DEBUG_)DumpSaveFrame(sv);
if (argc == 1) {
usage(basename(argv[0]));
return 0;
}
char numc[5];
int num;
if ( (strcmp(argv[1],"+1") == 0) ||
(strcmp(argv[1],"+2") == 0) ||
(strcmp(argv[1],"+3") == 0) ||
(strcmp(argv[1],"+4") == 0) ||
(strcmp(argv[1],"+5") == 0) ||
(strcmp(argv[1],"+6") == 0) ||
(strcmp(argv[1],"+7") == 0) ||
(strcmp(argv[1],"+8") == 0) ) {
strcpy(numc,argv[1]);
num = (numc[1] - '0') - 1;
if(_DEBUG_)printf("add string to line [%d]\n",num);
sv.save[num].size = String2SJIS((unsigned char*)argv[2], strlen(argv[2]), sv.save[num].sjis, MAXCHAR);
//sv.save[num].size = String2ISO((unsigned char*)argv[2], strlen(argv[2]), sv.save[num].sjis, MAXCHAR);
if(_DEBUG_)DumpSaveFrame(sv);
fp = fopen(dpath,"wb");
fwrite(&sv,sizeof(sv),1,fp);
fclose(fp);
return 0;
}
if ( (strcmp(argv[1],"-1") == 0) ||
(strcmp(argv[1],"-2") == 0) ||
(strcmp(argv[1],"-3") == 0) ||
(strcmp(argv[1],"-4") == 0) ||
(strcmp(argv[1],"-5") == 0) ||
(strcmp(argv[1],"-6") == 0) ||
(strcmp(argv[1],"-7") == 0) ||
(strcmp(argv[1],"-8") == 0) ) {
strcpy(numc,argv[1]);
num = (numc[1] - '0') - 1;
if(_DEBUG_)printf("delete string to line [%d]\n",num);
sv.save[num].size = 0;
if(_DEBUG_)DumpSaveFrame(sv);
fp = fopen(dpath,"wb");
fwrite(&sv,sizeof(sv),1,fp);
fclose(fp);
return 0;
}
if ( (strcmp(argv[1],"16") == 0) ||
(strcmp(argv[1],"24") == 0) ||
(strcmp(argv[1],"32") == 0) ) {
if (strcmp(argv[1],"16") == 0) sv.fontheight = 16;
if (strcmp(argv[1],"24") == 0) sv.fontheight = 24;
if (strcmp(argv[1],"32") == 0) sv.fontheight = 32;
sv.fontwidth = sv.fontheight / 2;
if(_DEBUG_)printf("set fontwidth=%d fontheight=%d\n",sv.fontwidth, sv.fontheight);
fp = fopen(dpath,"wb");
fwrite(&sv,sizeof(sv),1,fp);
fclose(fp);
return 0;
}
if ( (strcmp(argv[1],"R0") == 0) ||
(strcmp(argv[1],"R90") == 0) ||
(strcmp(argv[1],"R180") == 0) ||
(strcmp(argv[1],"R270") == 0) ) {
if (strcmp(argv[1],"R0") == 0) sv.direction = DIRECTION0;
if (strcmp(argv[1],"R90") == 0) sv.direction = DIRECTION90;
if (strcmp(argv[1],"R180") == 0) sv.direction = DIRECTION180;
if (strcmp(argv[1],"R270") == 0) sv.direction = DIRECTION270;
if(_DEBUG_)printf("set direction=%d\n",sv.direction);
fp = fopen(dpath,"wb");
fwrite(&sv,sizeof(sv),1,fp);
fclose(fp);
return 0;
}
if ( (strcmp(argv[1],"B0") == 0) ) {
if (strcmp(argv[2],"RED") == 0) sv.basecolor = RED;
if (strcmp(argv[2],"GREEN") == 0) sv.basecolor = GREEN;
if (strcmp(argv[2],"BLUE") == 0) sv.basecolor = BLUE;
if (strcmp(argv[2],"BLACK") == 0) sv.basecolor = BLACK;
if (strcmp(argv[2],"WHITE") == 0) sv.basecolor = WHITE;
if (strcmp(argv[2],"GRAY") == 0) sv.basecolor = GRAY;
if (strcmp(argv[2],"YELLOW") == 0) sv.basecolor = YELLOW;
if (strcmp(argv[2],"CYAN") == 0) sv.basecolor = CYAN;
if (strcmp(argv[2],"PURPLE") == 0) sv.basecolor = PURPLE;
if(_DEBUG_)printf("set base color=%x\n",sv.basecolor);
fp = fopen(dpath,"wb");
fwrite(&sv,sizeof(sv),1,fp);
fclose(fp);
return 0;
}
if ( (strcmp(argv[1],"F1") == 0) ||
(strcmp(argv[1],"F2") == 0) ||
(strcmp(argv[1],"F3") == 0) ||
(strcmp(argv[1],"F4") == 0) ||
(strcmp(argv[1],"F5") == 0) ||
(strcmp(argv[1],"F6") == 0) ||
(strcmp(argv[1],"F7") == 0) ||
(strcmp(argv[1],"F8") == 0) ) {
strcpy(numc,argv[1]);
num = (numc[1] - '0') - 1;
if (strcmp(argv[2],"RED") == 0) sv.save[num].fcolor = RED;
if (strcmp(argv[2],"GREEN") == 0) sv.save[num].fcolor = GREEN;
if (strcmp(argv[2],"BLUE") == 0) sv.save[num].fcolor = BLUE;
if (strcmp(argv[2],"BLACK") == 0) sv.save[num].fcolor = BLACK;
if (strcmp(argv[2],"WHITE") == 0) sv.save[num].fcolor = WHITE;
if (strcmp(argv[2],"GRAY") == 0) sv.save[num].fcolor = GRAY;
if (strcmp(argv[2],"YELLOW") == 0) sv.save[num].fcolor = YELLOW;
if (strcmp(argv[2],"CYAN") == 0) sv.save[num].fcolor = CYAN;
if (strcmp(argv[2],"PURPLE") == 0) sv.save[num].fcolor = PURPLE;
if(_DEBUG_)printf("set fcolor to line [%d]=%x\n",num,sv.save[num].fcolor);
fp = fopen(dpath,"wb");
fwrite(&sv,sizeof(sv),1,fp);
fclose(fp);
return 0;
}
if ( (strcmp(argv[1],"B1") == 0) ||
(strcmp(argv[1],"B2") == 0) ||
(strcmp(argv[1],"B3") == 0) ||
(strcmp(argv[1],"B4") == 0) ||
(strcmp(argv[1],"B5") == 0) ||
(strcmp(argv[1],"B6") == 0) ||
(strcmp(argv[1],"B7") == 0) ||
(strcmp(argv[1],"B8") == 0) ) {
strcpy(numc,argv[1]);
num = (numc[1] - '0') - 1;
if (strcmp(argv[2],"RED") == 0) sv.save[num].bcolor = RED;
if (strcmp(argv[2],"GREEN") == 0) sv.save[num].bcolor = GREEN;
if (strcmp(argv[2],"BLUE") == 0) sv.save[num].bcolor = BLUE;
if (strcmp(argv[2],"BLACK") == 0) sv.save[num].bcolor = BLACK;
if (strcmp(argv[2],"WHITE") == 0) sv.save[num].bcolor = WHITE;
if (strcmp(argv[2],"GRAY") == 0) sv.save[num].bcolor = GRAY;
if (strcmp(argv[2],"YELLOW") == 0) sv.save[num].bcolor = YELLOW;
if (strcmp(argv[2],"CYAN") == 0) sv.save[num].bcolor = CYAN;
if (strcmp(argv[2],"PURPLE") == 0) sv.save[num].bcolor = PURPLE;
if(_DEBUG_)printf("set bcolor to line [%d]=%x\n",num,sv.save[num].bcolor);
fp = fopen(dpath,"wb");
fwrite(&sv,sizeof(sv),1,fp);
fclose(fp);
return 0;
}
if ( (strcmp(argv[1],"+U") == 0) ||
(strcmp(argv[1],"-U") == 0) ) {
strcpy(numc,argv[2]);
num = (numc[0] - '0') - 1;
if(_DEBUG_)printf("set/unset underline to line [%d]\n",num);
if (num < 0 || num >= MAXLINE) return 1;
if (strcmp(argv[1],"+U") == 0) sv.save[num].enhance = 1;
if (strcmp(argv[1],"-U") == 0) sv.save[num].enhance = 0;
fp = fopen(dpath,"wb");
fwrite(&sv,sizeof(sv),1,fp);
fclose(fp);
return 0;
}
if ( strcmp(argv[1],"+L") == 0) {
memcpy(&sv.save[0],&sv.save[1],sizeof(SaveData));
memcpy(&sv.save[1],&sv.save[2],sizeof(SaveData));
memcpy(&sv.save[2],&sv.save[3],sizeof(SaveData));
memcpy(&sv.save[3],&sv.save[4],sizeof(SaveData));
memcpy(&sv.save[4],&sv.save[5],sizeof(SaveData));
memcpy(&sv.save[5],&sv.save[6],sizeof(SaveData));
memcpy(&sv.save[6],&sv.save[7],sizeof(SaveData));
memset(&sv.save[7],0,sizeof(SaveData));
fp = fopen(dpath,"wb");
fwrite(&sv,sizeof(sv),1,fp);
fclose(fp);
return 0;
}
if ( strcmp(argv[1],"-L") == 0) {
memcpy(&sv.save[7],&sv.save[6],sizeof(SaveData));
memcpy(&sv.save[6],&sv.save[5],sizeof(SaveData));
memcpy(&sv.save[5],&sv.save[4],sizeof(SaveData));
memcpy(&sv.save[4],&sv.save[3],sizeof(SaveData));
memcpy(&sv.save[3],&sv.save[2],sizeof(SaveData));
memcpy(&sv.save[2],&sv.save[1],sizeof(SaveData));
memcpy(&sv.save[1],&sv.save[0],sizeof(SaveData));
memset(&sv.save[0],0,sizeof(SaveData));
fp = fopen(dpath,"wb");
fwrite(&sv,sizeof(sv),1,fp);
fclose(fp);
return 0;
}
if ( (strcmp(argv[1],"P1") == 0) ||
(strcmp(argv[1],"P2") == 0) ||
(strcmp(argv[1],"P3") == 0) ||
(strcmp(argv[1],"P4") == 0) ||
(strcmp(argv[1],"P5") == 0) ||
(strcmp(argv[1],"P6") == 0) ||
(strcmp(argv[1],"P7") == 0) ||
(strcmp(argv[1],"P8") == 0) ) {
strcpy(numc,argv[1]);
num = (numc[1] - '0') - 1;
strcpy(numc,argv[2]);
int col;
col = atoi(numc) - 1;
if (col < 0 || col >= MAXCHAR) return 1;
if(_DEBUG_)printf("set start colum to line [%d] = %d\n",num,col);
sv.save[num].colum = col;
fp = fopen(dpath,"wb");
fwrite(&sv,sizeof(sv),1,fp);
fclose(fp);
return 0;
}
if (strcmp(argv[1],"r") == 0) {
memset(&sv,0,sizeof(sv));
InitSaveData(&sv);
if(_DEBUG_)DumpSaveFrame(sv);
fp = fopen(dpath,"wb");
fwrite(&sv,sizeof(sv),1,fp);
fclose(fp);
return 0;
}
if (strcmp(argv[1],"s") == 0) {
if(_DEBUG_)printf("show dislay\n");
char fnameh[64];
char fnamez[64];
FontxFile fx[2];
strcpy(fnameh,dir);
strcpy(fnamez,dir);
if(_DEBUG_)printf("sv.fontwidth=%d sv.fontheight=%d\n",sv.fontwidth, sv.fontheight);
if (sv.fontheight == 16) {
strcat(fnameh,"fontx/ILGH16XB.FNT");
strcat(fnamez,"fontx/ILGZ16XB.FNT");
} else if (sv.fontheight == 24) {
strcat(fnameh,"fontx/ILGH24XB.FNT");
strcat(fnamez,"fontx/ILGZ24XB.FNT");
} else if (sv.fontheight == 32) {
strcat(fnameh,"fontx/ILGH32XB.FNT");
strcat(fnamez,"fontx/ILGZ32XB.FNT");
}
if(_DEBUG_)printf("fnameh=%s\nfnamez=%s\n",fnameh,fnamez);
Fontx_init(fx,fnameh,fnamez);
#ifdef SPI
lcdInit(XMAX, YMAX, pins);
#define MODEL "SPI"
#endif
#ifdef ILI9225
lcdInit(0x9225, XMAX, YMAX, XOFS, YOFS, pins);
#define MODEL "ILI9225"
#endif
#ifdef ILI9226
lcdInit(0x9225, XMAX, YMAX, XOFS, YOFS, pins);
#define MODEL "ILI9226"
#endif
#ifdef ILI9320
lcdInit(0x9320, XMAX, YMAX, XOFS, YOFS, pins);
#define MODEL "ILI9320"
#endif
#ifdef ILI9325
lcdInit(0x9325, XMAX, YMAX, XOFS, YOFS, pins);
#define MODEL "ILI9325"
#endif
#ifdef ILI9327
lcdInit(0x9327, XMAX, YMAX, XOFS, YOFS, pins);
#define MODEL "ILI9327"
#endif
#ifdef ILI9340
lcdInit(0x9341, XMAX, YMAX, XOFS, YOFS, pins);
#define MODEL "ILI9340"
#endif
#ifdef ILI9341
lcdInit(0x9341, XMAX, YMAX, XOFS, YOFS, pins);
#define MODEL "ILI9341"
#endif
#ifdef ILI9342
lcdInit(0x9342, XMAX, YMAX, XOFS, YOFS, pins);
#define MODEL "ILI9342"
#endif
#ifdef ILI9481
lcdInit(0x9481, XMAX, YMAX, XOFS, YOFS, pins);
#define MODEL "ILI9481"
#endif
#ifdef ILI9486
lcdInit(0x9486, XMAX, YMAX, XOFS, YOFS, pins);
#define MODEL "ILI9486"
#endif
#ifdef ILI9488
lcdInit(0x9488, XMAX, YMAX, XOFS, YOFS, pins);
#define MODEL "ILI9488"
#endif
#ifdef LGDP4532
lcdInit(0x4532, XMAX, YMAX, XOFS, YOFS, pins);
#define MODEL "LGDP4532"
#endif
#ifdef R61505U
lcdInit(0x9320, XMAX, YMAX, XOFS, YOFS, pins);
#define MODEL "R61505U"
#endif
#ifdef R61509V
lcdInit(0xB509, XMAX, YMAX, XOFS, YOFS, pins);
#define MODEL "R61509V"
#endif
#ifdef S6D1121
lcdInit(0x1121, XMAX, YMAX, XOFS, YOFS, pins);
#define MODEL "S6D1121"
#endif
#ifdef SPFD5408
lcdInit(0x9320, XMAX, YMAX, XOFS, YOFS, pins);
#define MODEL "SPFD5408"
#endif
#ifdef ST7775
lcdInit(0x9225, XMAX, YMAX, XOFS, YOFS, pins);
#define MODEL "ST7775"
#endif
#ifdef ST7781
lcdInit(0x7781, XMAX, YMAX, XOFS, YOFS, pins);
#define MODEL "ST7781"
#endif
#ifdef ST7783
lcdInit(0x7781, XMAX, YMAX, XOFS, YOFS, pins);
#define MODEL "ST7783"
#endif
#ifdef ST7793
lcdInit(0xB509, XMAX, YMAX, XOFS, YOFS, pins);
#define MODEL "ST7793"
#endif
#ifdef ST7796
lcdInit(0x9486, XMAX, YMAX, XOFS, YOFS, pins);
#define MODEL "ST7796"
#endif
lcdReset();
lcdSetup();
lcdFillScreen(sv.basecolor);
lcdSetFontDirection(sv.direction);
uint16_t xpos,ypos;
for (num=0;num<MAXLINE;num++) {
if (sv.save[num].size == 0) continue;
if (sv.direction == DIRECTION0) {
xpos = sv.save[num].colum * sv.fontwidth;
ypos = sv.fontheight*(num+1) - 1;
} else if (sv.direction == DIRECTION90) {
xpos = (XMAX-1)-(sv.fontheight*(num+1)) + 1;
ypos = sv.save[num].colum * sv.fontwidth;
} else if (sv.direction == DIRECTION180) {
xpos = (XMAX-1)-sv.save[num].colum * sv.fontwidth;
ypos = (YMAX-1)-(sv.fontheight*(num+1)) + 1;
} else if (sv.direction == DIRECTION270) {
xpos = sv.fontheight*(num+1) - 1;
ypos = (YMAX-1)-(sv.save[num].colum * sv.fontwidth);
}
if(_DEBUG_)printf("xpos=%d ypos=%d\n",xpos,ypos);
lcdUnsetFontFill();
lcdUnsetFontUnderLine();
if (sv.save[num].bcolor) lcdSetFontFill(sv.save[num].bcolor);
if (sv.save[num].enhance) lcdSetFontUnderLine(sv.save[num].fcolor);
for (i=0;i<sv.save[num].size;i++) {
if (sv.direction == DIRECTION0) {
xpos = lcdDrawSJISChar(fx, xpos, ypos, sv.save[num].sjis[i], sv.save[num].fcolor);
} else if (sv.direction == DIRECTION90) {
ypos = lcdDrawSJISChar(fx, xpos, ypos, sv.save[num].sjis[i], sv.save[num].fcolor);
} else if (sv.direction == DIRECTION180) {
xpos = lcdDrawSJISChar(fx, xpos, ypos, sv.save[num].sjis[i], sv.save[num].fcolor);
} else if (sv.direction == DIRECTION270) {
ypos = lcdDrawSJISChar(fx, xpos, ypos, sv.save[num].sjis[i], sv.save[num].fcolor);
}
if(_DEBUG_)printf("xpos(2)=%d ypos(2)=%d\n",xpos,ypos);
}
}
return 0;
}
if (strcmp(argv[1],"D") == 0) {
DumpSaveFrame(sv);
return 0;
}
if (strcmp(argv[1],"M") == 0) {
printf("%s(%3dx%3d)\n",MODEL,XMAX,YMAX);
return 0;
}
if (strcmp(argv[1],"P") == 0) {
#ifdef SPI
printf("RST=%d\n",pins.rst);
printf("RS =%d\n",pins.rs);
printf("CS =%d\n",pins.cs);
printf("CH =%d\n",pins.ch);
#endif
#ifndef SPI
printf("RST=%d\n",pins.rst);
printf("CS =%d\n",pins.cs);
printf("RS =%d\n",pins.rs);
printf("WR =%d\n",pins.wr);
printf("RD =%d\n",pins.rd);
printf("D0 =%d\n",pins.d0);
printf("D1 =%d\n",pins.d1);
printf("D2 =%d\n",pins.d2);
printf("D3 =%d\n",pins.d3);
printf("D4 =%d\n",pins.d4);
printf("D5 =%d\n",pins.d5);
printf("D6 =%d\n",pins.d6);
printf("D7 =%d\n",pins.d7);
#endif
return 0;
}
return 1;
}
/*
Show Usage
*/
void usage(char *prog){
printf("Usage : %s option\n",prog);
printf("Options:\n");
printf(" s\t\tshow display\n");
printf(" r\t\tremove all string\n");
printf(" +n string\tadd string to line#n\n");
printf(" -n\t\tdelete string from line#n\n");
printf(" Fn COLOR\tset fore ground color to line#n\n");
printf(" Bn COLOR\tset back ground color to line#n\n");
printf(" B0 COLOR\tset base color(Default is WHITE)\n");
printf(" \t\tRED/GREEN/BLUE/BLACK/WHITE/GRAY/YELLOW/CYAN/PURPLE\n");
printf(" +U n\t\tset underline to line#n\n");
printf(" -U n\t\tunset underline to line#n\n");
printf(" +L\t\tline scroll up\n");
printf(" -L\t\tline scroll down\n");
printf(" Pn c\t\tset start colum c to line#n\n");
printf(" 16\t\tdraw 16 dot fonts(Default)\n");
printf(" 24\t\tdraw 24 dot fonts\n");
printf(" 32\t\tdraw 32 dot fonts\n");
printf(" R0\t\tset angle 0(Default)\n");
printf(" R90\t\tset angle 90\n");
printf(" R180\t\tset angle 180\n");
printf(" R270\t\tset angle 270\n");
}
void InitSaveData(SaveFrame *hoge) {
hoge->basecolor = WHITE;
hoge->fontheight = 16;
hoge->fontwidth = 8;
hoge->direction = 0;
}
void DumpSaveFrame(SaveFrame hoge) {
printf("basecolor=%x\n",hoge.basecolor);
printf("fontwidth=%d\n",hoge.fontwidth);
printf("fontheight=%d\n",hoge.fontheight);
printf("direction=%d\n",hoge.direction);
for(int i=0;i<MAXLINE;i++) {
printf("[%d].colum=%d ",i,hoge.save[i].colum);
printf("[%d].fcolor=%x ",i,hoge.save[i].fcolor);
printf("[%d].bcolor=%x ",i,hoge.save[i].bcolor);
printf("[%d].enhance=%d",i,hoge.save[i].enhance);
printf("[%d].size=%d\n",i,hoge.save[i].size);
for(int j=0;j<hoge.save[i].size;j++) {
printf("[%d].sjis[%d]=%x\n",i,j,hoge.save[i].sjis[j]);
}
}
}
int ReadTFTConfig(char *path, int *width, int *height, int *xofs, int *yofs) {
FILE *fp;
char buff[128];
*xofs = 0;
*yofs = 0;
//printf("path=%s\n",path);
fp = fopen(path,"r");
if(fp == NULL) return 0;
while (fgets(buff,128,fp) != NULL) {
//printf("buf=%s\n",buff);
//printf("buff[0]=%x\n",buff[0]);
if (buff[0] == '#') continue;
if (buff[0] == 0x0a) continue;
if (strncmp(buff, "width=", 6) == 0) {
sscanf(buff, "width=%d height=%d",width, height);
//printf("width=%d height=%d\n",*width, *height);
} else if (strncmp(buff, "xofs=", 5) == 0) {
sscanf(buff, "xofs=%d yofs=%d",xofs, yofs);
//printf("xofs=%d yofs=%d\n",*xofs, *yofs);
}
}
fclose(fp);
return 1;
}
int ReadPinConfig(TFTPin *pin, char *path) {
FILE *fp;
char buff[128];
//printf("path=%s\n",path);
fp = fopen(path,"r");
if(fp == NULL) return 0;
while (fgets(buff,128,fp) != NULL) {
//printf("buf=%s\n",buff);
//printf("buff[0]=%x\n",buff[0]);
if (buff[0] == '#') continue;
if (buff[0] == 0x0a) continue;
if (strncmp(buff,"RST=",4) == 0) {
sscanf(buff, "RST=%d", &(pin->rst));
} else if (strncmp(buff,"RS=",3) == 0) {
sscanf(buff, "RS=%d", &(pin->rs));
} else if (strncmp(buff,"CS=",3) == 0) {
sscanf(buff, "CS=%d", &(pin->cs));
}
#ifdef SPI
if (strncmp(buff,"CH=",3) == 0) {
sscanf(buff, "CH=%d", &(pin->ch));
}
#else
if (strncmp(buff,"WR=",3) == 0) {
sscanf(buff, "WR=%d", &(pin->wr));
} else if (strncmp(buff,"RD=",3) == 0) {
sscanf(buff, "RD=%d", &(pin->rd));
} else if (strncmp(buff,"D0=",3) == 0) {
sscanf(buff, "D0=%d", &(pin->d0));
} else if (strncmp(buff,"D1=",3) == 0) {
sscanf(buff, "D1=%d", &(pin->d1));
} else if (strncmp(buff,"D2=",3) == 0) {
sscanf(buff, "D2=%d", &(pin->d2));
} else if (strncmp(buff,"D3=",3) == 0) {
sscanf(buff, "D3=%d", &(pin->d3));
} else if (strncmp(buff,"D4=",3) == 0) {
sscanf(buff, "D4=%d", &(pin->d4));
} else if (strncmp(buff,"D5=",3) == 0) {
sscanf(buff, "D5=%d", &(pin->d5));
} else if (strncmp(buff,"D6=",3) == 0) {
sscanf(buff, "D6=%d", &(pin->d6));
} else if (strncmp(buff,"D7=",3) == 0) {
sscanf(buff, "D7=%d", &(pin->d7));
}
#endif
}
fclose(fp);
return 1;
}