-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathirsstd.cpp
More file actions
1846 lines (1762 loc) · 49.1 KB
/
irsstd.cpp
File metadata and controls
1846 lines (1762 loc) · 49.1 KB
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
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Ñòàíäàðòàíàÿ áèáëèîòåêà ÈÐÑ
// Äàòà: 20.07.2010
// Ðàííÿÿ äàòà: 25.11.2007
// Íîìåð ôàéëà
#define IRSSTDCPP_IDX 15
#include <irspch.h>
#ifdef __BORLANDC__
#pragma hdrstop
#endif // __BORLANDC__
#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <irserror.h>
#include <irsstd.h>
//#include <irscpp.h>
#include <irsfinal.h>
// Êîíñòðóêòîð ïî óìîë÷àíèþ
mxconsole_t::mxconsole_t()
{
}
// Êîíñòðóêòîð
mxconsole_t::mxconsole_t(mxcondrv_t *a_condrv):
f_condrv(a_condrv)
{
}
// Äåñòðóêòîð
mxconsole_t::~mxconsole_t()
{
}
// Âûâîä îòëàäî÷íîé èíôîðìàöèè ïî òèïó puts
void mxconsole_t::puts(const char *a_msg)
{
const irs_u8 *msg = reinterpret_cast<const irs_u8 *>(a_msg);
if (!f_condrv) return;
if (!msg) return;
irs_i32 len = strlen(reinterpret_cast<const char*>(msg));
irs_u8 *msg_crlf = new irs_u8[len + 2];
if (!msg_crlf) return;
::strcpy(reinterpret_cast<char*>(msg_crlf),
reinterpret_cast<const char*>(msg));
msg_crlf[len] = '\n';
msg_crlf[len + 1] = 0;
f_condrv->out(reinterpret_cast<const char*>(msg_crlf));
delete []msg_crlf;
}
// Âûâîä îòëàäî÷íîé èíôîðìàöèè ïî òèïó printf
void mxconsole_t::printf(const char *a_format, ...)
{
const irs_u8 *format = reinterpret_cast<const irs_u8 *>(a_format);
if (!f_condrv) return;
if (!format) return;
irs_u8 *msgbuf;
irs_i32 len;
va_list arglist;
va_start(arglist, a_format);
len = vsnprintf(NULL, 0, reinterpret_cast<const char*>(format), arglist);
len++;
va_end(arglist);
msgbuf = new irs_u8[len];
if (!msgbuf) return;
va_start(arglist, a_format);
vsnprintf(reinterpret_cast<char*>(msgbuf), len,
reinterpret_cast<const char*>(format), arglist);
msgbuf[len - 1] = 0;
va_end(arglist);
f_condrv->out(reinterpret_cast<const char*>(msgbuf));
delete []msgbuf;
}
// Êëàññ äëÿ ïðèëîæåíèÿ
mxapplication_t::mxapplication_t():
first_exec(irs_true),
stop_exec(irs_false),
f_init(IRS_NULL),
f_deinit(IRS_NULL),
f_tick(IRS_NULL),
f_stop(IRS_NULL),
f_stopped(IRS_NULL)
{
}
mxapplication_t::~mxapplication_t()
{
}
irs_bool mxapplication_t::run(irs_bool exec)
{
if (exec)
if (first_exec) {
first_exec = irs_false;
init();
}
if (!first_exec) {
if (!exec && !stop_exec) {
stop_exec = irs_true;
stop();
}
tick();
}
if (stopped() && !first_exec) {
deinit();
first_exec = irs_true;
stop_exec = irs_false;
return irs_false;
} else {
return irs_true;
}
}
void mxapplication_t::set_init_event(void (*a_init)())
{
f_init = a_init;
}
void mxapplication_t::set_denit_event(void (*a_deinit)())
{
f_deinit = a_deinit;
}
void mxapplication_t::set_tick_event(void (*a_tick)())
{
f_tick = a_tick;
}
void mxapplication_t::set_stop_event(void (*a_stop)())
{
f_stop = a_stop;
}
void mxapplication_t::set_stopped_event(irs_bool (*a_stopped)())
{
f_stopped = a_stopped;
}
void mxapplication_t::init()
{
if (f_init) f_init();
}
void mxapplication_t::deinit()
{
if (f_deinit) f_deinit();
}
void mxapplication_t::tick()
{
if (f_tick) f_tick();
}
void mxapplication_t::stop()
{
if (f_stop) f_stop();
}
irs_bool mxapplication_t::stopped()
{
if (f_stopped) return f_stopped();
else return irs_true;
}
// Ïåðåðàñïðåäåëåíèå ïàìÿòè ñ ñîõðàíåíèåì äàííûõ
void *irs_renew(void *pointer, size_t old_size, size_t new_size)
{
if (old_size == new_size) return pointer;
void *new_pointer = IRS_NULL;
if (new_size) {
new_pointer = reinterpret_cast<void*>(IRS_LIB_NEW_ASSERT(
irs_u8 *[new_size], IRSSTDCPP_IDX));
if (!new_pointer) return new_pointer;
}
if (pointer) {
if (old_size && new_size) {
memcpy(new_pointer, pointer, irs_min(old_size, new_size));
}
irs_u8*& pointer_u8 = reinterpret_cast<irs_u8*&>(pointer);
IRS_LIB_ARRAY_DELETE_ASSERT(pointer_u8);
}
return new_pointer;
}
mxapplication_t *mxapplication = IRS_NULL;
void afloat_to_str(char *str, double N, size_t len, size_t accur,
irs::num_mode_t a_num_mode)
{
ostrstream strm(str, len + 1);
switch (a_num_mode) {
case irs::num_mode_invalid: {
// Èãíîðèðóåì
} break;
case irs::num_mode_general: {
} break;
case irs::num_mode_fixed: {
strm << fixed;
} break;
case irs::num_mode_scientific: {
strm << scientific;
} break;
}
strm << setw(len) << setprecision(accur) << N;
strm << '\0';
str[len] = '\0';
}
#if defined(__ICCAVR__) || defined(__ICCARM__)
#if defined(__ICCAVR__)
__flash irs_u8 lcd_table[] =
#elif defined(__ICCARM__)
const irs_u8 lcd_table[] =
#endif
{
0x20, // '~':0
0xFF, // '~':1 //Êóðñîð êâàäðàòîì
0x20, // '~':2
0x20, // '~':3
0x20, // '~':4
0x20, // '~':5
0x20, // '~':6
0x20, // '~':7
0x20, // '~':8
0x20, // '~':9
0x20, // '~':10
0x20, // '~':11
0x20, // '~':12
0x20, // '~':13
0x20, // '~':14
0x20, // '~':15
0x20, // '~':16
0x20, // '~':17
0x20, // '~':18
0x20, // '~':19
0x20, // '~':20
0x20, // '~':21
0x20, // '~':22
0x20, // '~':23
0x20, // '~':24
0x20, // '~':25
0x20, // '~':26
0x20, // '~':27
0x20, // '~':28
0x20, // '~':29
0x20, // '~':30
0x20, // '~':31
0x20, // ' ':32
0x21, // '!':33
0x22, // '"':34
0xEF,//0x23, // '#':35-------led on
0xEE, // '$':36--------------led off
0x25, // '%':37
0x26, // '&':38
0x27, // ''':39
0x28, // '(':40
0x29, // ')':41
0x2A, // '*':42
0x2B, // '+':43
0x2C, // ',':44
0x2D, // '-':45
0x2E, // '.':46
0x2F, // '/':47
0x30, // '0':48
0x31, // '1':49
0x32, // '2':50
0x33, // '3':51
0x34, // '4':52
0x35, // '5':53
0x36, // '6':54
0x37, // '7':55
0x38, // '8':56
0x39, // '9':57
0x3A, // ':':58
0x3B, // ';':59
0x3C, // '<':60
0x3D, // '=':61
0x3E, // '>':62
0x3F, // '?':63
0x40, // '@':64
0x41, // 'A':65
0x42, // 'B':66
0x43, // 'C':67
0x44, // 'D':68
0x45, // 'E':69
0x46, // 'F':70
0x47, // 'G':71
0x48, // 'H':72
0x49, // 'I':73
0x4A, // 'J':74
0x4B, // 'K':75
0x4C, // 'L':76
0x4D, // 'M':77
0x4E, // 'N':78
0x4F, // 'O':79
0x50, // 'P':80
0x51, // 'Q':81
0x52, // 'R':82
0x53, // 'S':83
0x54, // 'T':84
0x55, // 'U':85
0x56, // 'V':86
0x57, // 'W':87
0x58, // 'X':88
0x59, // 'Y':89
0x5A, // 'Z':90
0x5B, // '[':91
0x5C, // '\':92
0x5D, // ']':93
0xD9, // '^':94 ñòðåëêà ââåðõ
0x5F, // '_':95
0x60, // '`':96
0x61, // 'a':97
0x62, // 'b':98
0x63, // 'c':99
0x64, // 'd':100
0x65, // 'e':101
0x66, // 'f':102
0x67, // 'g':103
0x68, // 'h':104
0x69, // 'i':105
0x6A, // 'j':106
0x6B, // 'k':107
0x6C, // 'l':108
0x6D, // 'm':109
0x6E, // 'n':110
0x6F, // 'o':111
0x70, // 'p':112
0x71, // 'q':113
0x72, // 'r':114
0x73, // 's':115
0x74, // 't':116
0x75, // 'u':117
0x76, // 'v':118
0x77, // 'w':119
0x78, // 'x':120
0x79, // 'y':121
0x7A, // 'z':122
0x20, // '{':123
0x20, // '|':124
0x20, // '}':125
0xDA, // '~':126 ñòðåëêà âíèç
0x20, // '':127
0x20, // '€':128
0x20, // '':129
0x20, // '‚':130
0x20, // 'ƒ':131
0xCA, // '„':132
0x20, // '…':133
0x20, // '†':134
0x20, // '‡':135
0x7E, // 'ˆ':136 'enter'
0xD4, // '‰':137
0x20, // 'Š':138
0x20, // '‹':139
0x20, // 'Œ':140
0x20, // '':141
0x20, // 'Ž':142
0xE9, // '':143
0x20, // '':144
0x27, // '‘':145
0x27, // '’':146
0xCB, // '“':147
0xCB, // '”':148
0xDF, // '•':149
0x2D, // '–':150
0x2D, // '—':151
0x20, // '~':152
0x20, // '™':153
0x20, // 'š':154
0x3E, // '›':155
0x20, // 'œ':156
0x20, // '':157
0x20, // 'ž':158
0x20, // 'Ÿ':159
0x20, // ' ':160
0x20, // '¡':161
0x20, // '¢':162
0x4A, // '£':163
0x20, // '¤':164
0x20, // '¥':165
0x20, // '¦':166
0xFD, // '§':167
0xA2, // '¨':168
0x20, // '©':169
0x20, // 'ª':170
0xC8, // '«':171
0x20, // '¬':172
0x2D, // '':173
0x20, // '®':174
0x20, // '¯':175
0xEF, // '°':176
0x20, // '±':177
0x49, // '²':178
0x69, // '³':179
0xB4, // '´':180
0x75, // 'µ':181
0xFE, // '¶':182
0xDF, // '·':183
0xB5, // '¸':184
0x23, // '¹':185
0x20, // 'º':186
0xC9, // '»':187
0x6A, // '¼':188
0x53, // '½':189
0x73, // '¾':190
0x69, // '¿':191
0x41, // 'À':192
0xA0, // 'Á':193
0x42, // 'Â':194
0xA1, // 'Ã':195
0xE0, // 'Ä':196
0x45, // 'Å':197
0xA3, // 'Æ':198
0x33, // 'Ç':199
0xA5, // 'È':200
0xA6, // 'É':201
0x4B, // 'Ê':202
0xA7, // 'Ë':203
0x4D, // 'Ì':204
0x48, // 'Í':205
0x4F, // 'Î':206
0xA8, // 'Ï':207
0x50, // 'Ð':208
0x43, // 'Ñ':209
0x54, // 'Ò':210
0xA9, // 'Ó':211
0xAA, // 'Ô':212
0x58, // 'Õ':213
0xE1, // 'Ö':214
0xAB, // '×':215
0xAC, // 'Ø':216
0xE2, // 'Ù':217
0xAD, // 'Ú':218
0xAE, // 'Û':219
0xAD, // 'Ü':220 = 'Ú'
0xAF, // 'Ý':221
0xB0, // 'Þ':222
0xB1, // 'ß':223
0x61, // 'à':224
0xB2, // 'á':225
0xB3, // 'â':226
0xB4, // 'ã':227
0xE3, // 'ä':228
0x65, // 'å':229
0xB6, // 'æ':230
0xB7, // 'ç':231
0xB8, // 'è':232
0xB9, // 'é':233
0xBA, // 'ê':234
0xBB, // 'ë':235
0xBC, // 'ì':236
0xBD, // 'í':237
0x6F, // 'î':238
0xBE, // 'ï':239
0x70, // 'ð':240
0x63, // 'ñ':241
0xBF, // 'ò':242
0x79, // 'ó':243
0xE4, // 'ô':244
0x78, // 'õ':245
0xE5, // 'ö':246
0xC0, // '÷':247
0xC1, // 'ø':248
0xE6, // 'ù':249
0xC2, // 'ú':250
0xC3, // 'û':251
0xC4, // 'ü':252
0xC5, // 'ý':253
0xC6, // 'þ':254
0xC7 // 'ÿ':255
};
#endif //defined(__ICCAVR__) || defined(__ICCARM__)
#ifdef __ICCAVR__
// Êàðòà ïðåîáðàçîâàíèÿ íîìåðîâ êëàâèø â êîäû
// äëÿ âåðòèêàëüíîãî ðàñïîëîæåíèÿ êëàâèàòóðû
__flash irskey_t irskbd_table_vertical[] =
{
irskey_none, // 0
irskey_0, // 1
irskey_1, // 2
irskey_2, // 3
irskey_3, // 4
irskey_4, // 5
irskey_5, // 6
irskey_6, // 7
irskey_7, // 8
irskey_8, // 9
irskey_9, // 10
irskey_point, // 11
irskey_enter, // 12
irskey_up, // 13
irskey_down, // 14
irskey_backspace, // 15
irskey_escape // 16
};
// Êàðòà ïðåîáðàçîâàíèÿ íîìåðîâ êëàâèø â êîäû
// äëÿ ãîðèçîíòàëüíîãî ðàñïîëîæåíèÿ êëàâèàòóðû
__flash irskey_t irskbd_table_horisontal[] =
{
irskey_none, // 0
irskey_enter, // 1
irskey_backspace, // 2
irskey_3, // 3
irskey_6, // 4
irskey_point, // 5
irskey_2, // 6
irskey_5, // 7
irskey_0, // 8
irskey_1, // 9
irskey_4, // 10
irskey_down, // 11
irskey_escape, // 12
irskey_8, // 13
irskey_9, // 14
irskey_up, // 15
irskey_7 // 16
};
// Êàðòà ïðåîáðàçîâàíèÿ íîìåðîâ êëàâèø â êîäû
// äëÿ ðàñïîëîæåíèÿ êëàâèàòóðû äëÿ ÃÒ× rev 0 (ìàêåòêà edition)
__flash irskey_t irskbd_table_gtch_rev_0[] =
{
irskey_none, // 0
irskey_none, // 1
irskey_none, // 2
irskey_escape, // 3
irskey_6, // 4
irskey_none, // 5
irskey_2, // 6
irskey_5, // 7
irskey_none, // 8
irskey_1, // 9
irskey_4, // 10
irskey_enter, // 11
irskey_up, // 12
irskey_8, // 13
irskey_9, // 14
irskey_down, // 15
irskey_7 // 16
};
// Êàðòà ïðåîáðàçîâàíèÿ íîìåðîâ êëàâèø â êîäû
// äëÿ ðàñïîëîæåíèÿ êëàâèàòóðû äëÿ ÃÒ× rev 1 (÷åìîäàí edition)
__flash irskey_t irskbd_table_gtch_rev_1[] =
{
irskey_none, // 0
irskey_none, // 1
irskey_none, // 2
irskey_2, // 3
irskey_5, // 4
irskey_none, // 5
irskey_escape, // 6
irskey_6, // 7
irskey_none, // 8
irskey_enter, // 9
irskey_down, // 10
irskey_1, // 11
irskey_7, // 12
irskey_9, // 13
irskey_8, // 14
irskey_4, // 15
irskey_up // 16
};
//#define avr_port_map_size IRS_ARRAYOFSIZE(avr_port_map);
const irs_avr_port_map_t* irs::get_avr_port_map()
{
static const irs_avr_port_map_t avr_port_map_i[] = {
{&PORTA, &PINA, &DDRA},
{&PORTB, &PINB, &DDRB},
{&PORTC, &PINC, &DDRC},
{&PORTD, &PIND, &DDRD},
{&PORTE, &PINE, &DDRE},
{&PORTF, &PINF, &DDRF},
{&PORTG, &PING, &DDRG}
};
return avr_port_map_i;
}
//__flash irs_u8 lcd_table[] =
mxkey_drv_avr_t::mxkey_drv_avr_t(irskbd_t type, irskbd_map_t map_type,
irs_avr_port_t a_port):
m_high_set_bit(7),
m_high_get_bit(3),
mp_set(avr_port_map[a_port].set),
mp_get(avr_port_map[a_port].get),
mp_dir(avr_port_map[a_port].dir)
{
switch (type) {
case irskbd_high_pull_up: {
m_high_set_bit = 3;
m_high_get_bit = 7;
(*mp_dir) = 0x0F;
} break;
default:
case irskbd_low_pull_up: {
m_high_set_bit = 7;
m_high_get_bit = 3;
(*mp_dir) = 0xF0;
} break;
}
switch(map_type) {
default:
case irskbd_map_vertical: {
mp_key_map = irskbd_table_vertical;
} break;
case irskbd_map_horisontal: {
mp_key_map = irskbd_table_horisontal;
} break;
case irskbd_map_gtch_rev_1: {
mp_key_map = irskbd_table_gtch_rev_1;
} break;
}
(*mp_set) = (*mp_dir)^0xFF;
}
mxkey_drv_avr_t::~mxkey_drv_avr_t()
{
(*mp_dir) = 0x00;
(*mp_set) = 0x00;
}
irskey_t mxkey_drv_avr_t::operator()()
{
reshor(0);
sethor(1);
sethor(2);
sethor(3);
if (!chkver(0)) return mp_key_map[8];
if (!chkver(1)) return mp_key_map[9];
if (!chkver(2)) return mp_key_map[10];
if (!chkver(3)) return mp_key_map[16];
sethor(0);
reshor(1);
sethor(2);
sethor(3);
if (!chkver(0)) return mp_key_map[5];
if (!chkver(1)) return mp_key_map[6];
if (!chkver(2)) return mp_key_map[7];
if (!chkver(3)) return mp_key_map[13];
sethor(0);
sethor(1);
reshor(2);
sethor(3);
if (!chkver(0)) return mp_key_map[2];
if (!chkver(1)) return mp_key_map[3];
if (!chkver(2)) return mp_key_map[4];
if (!chkver(3)) return mp_key_map[14];
sethor(0);
sethor(1);
sethor(2);
reshor(3);
if (!chkver(0)) return mp_key_map[1];
if (!chkver(1)) return mp_key_map[11];
if (!chkver(2)) return mp_key_map[15];
if (!chkver(3)) return mp_key_map[12];
return mp_key_map[0];
}
// Ïåðåêîäèðîâêà ñèìâîëîâ Windows-1251 â êîäû êîíòðîëëåðà Epson íà áàçå
// HD44780 ñ ðàçíûìè ïðèáàìáàñàìè
// Êëàññ äðàéâåðà äèñïëåÿ AVR
#define LCD_INIT_DELAY_MS 15
#define LCD_TICK_DELAY_US 100 //100
#define LCD_CYCLE_DELAY_US 40
//#define LCD_SIZE 80 //symbols
#define LINE0 0
#define LINE1 20
#define LINE2 40
#define LINE3 60
#define LINE0_ADR 0x00
#define LINE1_ADR 0x40
#define LINE2_ADR 0x14
#define LINE3_ADR 0x54
//#define LINE_LEN 20
#define IMAGE_ON 0x0C // Âêëþ÷åíèå èçîáðàæåíèÿ, êóðñîðîâ åñòü
#define IMAGE_OFF 0x08 // Âûêëþ÷åíèå èçîáðàæåíèÿ
#define BUS_8BIT 0x30 // Èíèöèàëèçàöèîííàÿ êîìàíäà - âûáîð øèðèíû øèíû
// äàííûõ = 8 áèò
#define TWO_LINES 0x38 // 8 áèò øèíà äàííûõ, ðåæèì îòîáðàæåíèÿ 2 ñòðîêè,
// ðàçìåð ìàòðèöû ñèìâîëà 5 õ 8 òî÷åê
#define ADR_INC 0x06 // Ñ÷åò÷èê àäðåñà èíêðåìåíòèðóåòñÿ
#define LCD_NULL 0 // Íè÷î
// Êðàøåíèííèêîâ: Ïî÷åìó-òî îòñóòñâîâàëè îïðåäåëåíèÿ OLED_
// Êîíêðåòíûå çíà÷åíèÿ âçÿòû èç mxdisplay_drv_gen_t
#define OLED_FUNCTION_SET 0x3A
#define OLED_DISPLAY_ON 0x0C
#define OLED_DISPLAY_CLEAR 0x01
#define lcd_delay_mcs(delay)\
{\
set_to_cnt(lcd_timer, MCS_TO_CNT(delay));\
while (!test_to_cnt(lcd_timer));\
}
#define lcd_delay_ms(delay)\
{\
set_to_cnt(lcd_timer, MS_TO_CNT(delay));\
while (!test_to_cnt(lcd_timer));\
}
#define lcd_init_command(command)\
{\
lcd_IR_enable();\
set_to_cnt(lcd_timer, MS_TO_CNT(LCD_INIT_DELAY_MS));\
while (!test_to_cnt(lcd_timer));\
lcd_enable();\
set_to_cnt(lcd_timer, MS_TO_CNT(LCD_INIT_DELAY_MS));\
while (!test_to_cnt(lcd_timer));\
lcd_out(command);\
set_to_cnt(lcd_timer, MS_TO_CNT(LCD_INIT_DELAY_MS));\
while (!test_to_cnt(lcd_timer));\
lcd_disable();\
set_to_cnt(lcd_timer, MS_TO_CNT(LCD_INIT_DELAY_MS));\
while (!test_to_cnt(lcd_timer));\
lcd_out(LCD_NULL);\
}
mxdisplay_drv_avr_t::mxdisplay_drv_avr_t(
irslcd_t a_type,
irs_avr_port_t a_data_port,
irs_avr_port_t a_control_port,
irs_u8 a_control_pin
):
mp_set_data(avr_port_map[a_data_port].set),
mp_get_data(avr_port_map[a_data_port].get),
mp_dir_data(avr_port_map[a_data_port].dir),
mp_set_control(avr_port_map[a_control_port].set),
mp_get_control(avr_port_map[a_control_port].get),
mp_dir_control(avr_port_map[a_control_port].dir),
m_LCD_E(a_control_pin + 0),
m_LCD_RS(a_control_pin + 1),
LINE_COUNT(4),
LINE_LEN(20),
LCD_SIZE(LINE_LEN*LINE_COUNT),
lcd_status(LCD_BEGIN),
lcd_ram(IRS_NULL),
lcd_current_symbol(0),
lcd_current_symbol_address(0),
lcd_init_counter(0),
lcd_timer(0),
lcd_address_jump(irs_false)
{
init_to_cnt();
lcd_ram = new irs_u8[LCD_SIZE];
memset(lcd_ram, ' ', LCD_SIZE);
//IRS_PAUSE(TIME_TO_CNT(1, 1));
// Èíèöèàëèçàöèÿ ïîðòîâ ââîäà/âûâîäà
(*mp_dir_data) = 0xFF; // Øèíà äàííûõ LCD
(*mp_set_data) = 0x00;
(*mp_dir_control) |= ((1 << m_LCD_RS)|(1 << m_LCD_E)); // Ëèíèè E è RS LCD
(*mp_set_control) &= (((1 << m_LCD_RS)|(1 << m_LCD_E))^0xFF);
// Íà÷àëüíàÿ ïàóçà äëÿ ñòàáèëèçàöèè ïèòàíèÿ
irs::pause(irs::make_cnt_ms(200));
switch (a_type) {
// Èíèöèàëèçàöèÿ OLED-èíäèêàòîðà
case irslcd_oled_4x20: {
lcd_init_command(OLED_FUNCTION_SET);
irs::pause(irs::make_cnt_ms(LCD_INIT_DELAY_MS));
lcd_init_command(OLED_DISPLAY_ON);
irs::pause(irs::make_cnt_ms(LCD_INIT_DELAY_MS));
lcd_init_command(OLED_DISPLAY_CLEAR);
irs::pause(irs::make_cnt_ms(LCD_INIT_DELAY_MS));
lcd_init_command(ADR_INC);
} break;
// Èíèöèàëèçàöèÿ LCD-èíäèêàòîðà
default: {
for (irs_u8 i = 0; i < 3; i++)
{
// Âûäåðæêà
lcd_delay_ms(LCD_INIT_DELAY_MS);
// Êîìàíäà
lcd_init_command(BUS_8BIT);
// È òàê - 3 ðàçà
}
lcd_delay_ms(LCD_INIT_DELAY_MS);
lcd_init_command(TWO_LINES);
lcd_delay_ms(LCD_INIT_DELAY_MS);
lcd_init_command(IMAGE_ON);
lcd_delay_ms(LCD_INIT_DELAY_MS);
lcd_init_command(ADR_INC);
}
}
}
mxdisplay_drv_avr_t::~mxdisplay_drv_avr_t()
{
// Ãàøåíèå èíäèêàòîðà
lcd_delay_mcs(LCD_TICK_DELAY_US);
lcd_init_command(IMAGE_OFF);
// Äåèíèöèàëèçàöèÿ ïîðòîâ ââîäà/âûâîäà
// Øèíà äàííûõ LCD
(*mp_dir_data) = 0x0;
(*mp_set_data) = 0x00;
// Ëèíèè E è RS LCD
(*mp_dir_control) &= (((1 << m_LCD_RS)&(1 << m_LCD_E))^0xFF);
(*mp_set_control) &= (((1 << m_LCD_RS)&(1 << m_LCD_E))^0xFF);
delete []lcd_ram;
deinit_to_cnt();
}
mxdisp_pos_t mxdisplay_drv_avr_t::get_height()
{
return LINE_COUNT;
}
mxdisp_pos_t mxdisplay_drv_avr_t::get_width()
{
return LINE_LEN;
}
void mxdisplay_drv_avr_t::outtextpos(mxdisp_pos_t a_left, mxdisp_pos_t a_top,
const char *text)
{
irs_u8 begin = (irs_u8)(a_top*LINE_LEN) + a_left;
irs_u8 delta = LCD_SIZE - begin;
for (irs_u8 i = 0; (i < strlen(text))&&(i < delta); i++) {
lcd_ram[begin + i] = lcd_table[(irs_u8)text[i]];
}
}
void mxdisplay_drv_avr_t::tick()
{
switch (lcd_status)
{
case LCD_BEGIN:
{
set_to_cnt(lcd_timer, MCS_TO_CNT(LCD_TICK_DELAY_US));
lcd_status = LCD_RS;
break;
}
case LCD_RS:
{
if (test_to_cnt(lcd_timer))
{
set_to_cnt(lcd_timer, MCS_TO_CNT(LCD_TICK_DELAY_US));
if (lcd_current_symbol > LCD_SIZE-1) lcd_current_symbol = 0;
if (lcd_address_jump == irs_false)
{
switch (lcd_current_symbol)
{
case LINE0:
{
lcd_current_symbol_address = LINE0_ADR;
lcd_status = LCD_ADDRESS_OUT;
lcd_address_jump = irs_true;
lcd_IR_enable();
break;
}
case /*(irs_u8)(LCD_SIZE/2)*/LINE1:
{
// Ïåðåõîä íà âòîðóþ ñòðîêó. Àäðåñ çàïèñûâàåòñÿ â èíäèêàòîð
// òîëüêî ïðè ïåðåõîäå íà íîâóþ ñòðîêó
lcd_current_symbol_address = LINE1_ADR;
lcd_status = LCD_ADDRESS_OUT;
lcd_address_jump = irs_true;
lcd_IR_enable();
break;
}
case LINE2:
{
// Ïåðåõîä íà òðåòüþ ñòðîêó. Àäðåñ çàïèñûâàåòñÿ â èíäèêàòîð
// òîëüêî ïðè ïåðåõîäå íà íîâóþ ñòðîêó
lcd_current_symbol_address = LINE2_ADR;
lcd_status = LCD_ADDRESS_OUT;
lcd_address_jump = irs_true;
lcd_IR_enable();
break;
}
case LINE3:
{
// Ïåðåõîä íà ÷åòâåðòóþ ñòðîêó. Àäðåñ çàïèñûâàåòñÿ â èíäèêàòîð
// òîëüêî ïðè ïåðåõîäå íà íîâóþ ñòðîêó
lcd_current_symbol_address = LINE3_ADR;
lcd_status = LCD_ADDRESS_OUT;
lcd_address_jump = irs_true;
lcd_IR_enable();
break;
}
default:
{
lcd_status = LCD_DATA_OUT;
lcd_DR_enable();
break;
}
}
}
else
{
lcd_status = LCD_DATA_OUT;
lcd_DR_enable();
lcd_address_jump = irs_false;
}
}
break;
}
case LCD_DATA_OUT:
{
if (test_to_cnt(lcd_timer))
{
lcd_status = LCD_E_RISE;
lcd_out(lcd_ram[lcd_current_symbol]);
lcd_current_symbol++;
set_to_cnt(lcd_timer, MCS_TO_CNT(LCD_TICK_DELAY_US));
}
break;
}
case LCD_ADDRESS_OUT:
{
if (test_to_cnt(lcd_timer))
{
set_to_cnt(lcd_timer, MCS_TO_CNT(LCD_TICK_DELAY_US));
lcd_status = LCD_E_RISE;
lcd_out(lcd_current_symbol_address|0x80);
}
break;
}
case LCD_E_RISE:
{
if (test_to_cnt(lcd_timer))
{
set_to_cnt(lcd_timer, MCS_TO_CNT(LCD_TICK_DELAY_US));
lcd_status = LCD_E_FALL;
lcd_enable();
}
break;
}
case LCD_E_FALL:
{
if (test_to_cnt(lcd_timer))
{
set_to_cnt(lcd_timer, MCS_TO_CNT(LCD_CYCLE_DELAY_US));
lcd_status = LCD_RS;
lcd_disable();
}
break;
}
case LCD_FREE:
{
lcd_disable();
lcd_out(0);
break;
}
}
}
#endif //__ICCAVR__
#if defined(__ICCAVR__) || defined(__ICCARM__)
mxdisplay_drv_gen_t::mxdisplay_drv_gen_t(
irslcd_t a_type,
irs::gpio_port_t& a_data_port,
irs::gpio_pin_t& a_rs_pin,
irs::gpio_pin_t& a_e_pin
):
m_data_port(a_data_port),
m_rs_pin(a_rs_pin),
m_e_pin(a_e_pin),
m_line_cnt(0),
m_line_len(0),
m_lcd_size(m_line_cnt * m_line_len),
m_status(lcd_init_wait),
m_target_status(lcd_init),
m_ram_vector(m_lcd_size, ' '),
m_current_symbol(0),
m_current_symbol_address(0),
m_lcd_init_counter(0),
m_timer(irs::make_cnt_ms(m_start_interval)),
m_address_jump(false),
m_command(m_com_null)
{
if (a_type == irslcd_4x20) {
m_line_cnt = 4;
m_line_len = 20;
m_lcd_size = m_line_cnt * m_line_len;
}
m_ram_vector.resize(m_lcd_size, ' ');
m_data_port.set(0);
m_rs_pin.clear();
m_e_pin.clear();
m_timer.start();
}
mxdisplay_drv_gen_t::~mxdisplay_drv_gen_t()
{
m_data_port.set(0);
m_rs_pin.clear();
m_e_pin.clear();
}
mxdisp_pos_t mxdisplay_drv_gen_t::get_height()
{
return m_line_cnt;