-
Notifications
You must be signed in to change notification settings - Fork 5
/
SmartResponseXEmt.cpp
1174 lines (1065 loc) · 38.3 KB
/
SmartResponseXEmt.cpp
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
//
// SMART Response XE library
//
// LCD and keyboard routines for the SRXE handheld classroom communicator
//
// Copyright (c) 2018 BitBank Software, Inc.
// written by Larry Bank
// email: [email protected]
// Project started 8/4/2018
//
// Modified by Dan Geiger (Port to SMART Response XE)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// 18/11/2019 fdufnews keyboard map modification
// DEL --> enter (0x0D) (more intuitive position)
// shift + DEL --> backspace (0x08)
// SYM + I --> ;
// SYM + Z --> *
// SYM + X --> /
// square root --> ESC
// 8/12/2019 fdufnews added function to define scroll area
//
#include <Arduino.h>
#include <avr/pgmspace.h>
#include <avr/sleep.h>
#include "SmartResponseXEmt.h"
//#include <SPI.h>
// Mapping of keyboard to GPIO pins
//static byte rowPins[ROWS] = {6,35,34,8,9,0};
//static byte colPins[COLS] = {4,A1,A3,2,1,25,16,19,23,22};
const uint8_t rowPins[ROWS] = {0xe6, 0xb7, 0xb6, 0xb5, 0xb4, 0xe0};
const uint8_t colPins[COLS] = {0xe4, 0xf1, 0xf3, 0xe2, 0xe1, 0xd7, 0xa0, 0xa5, 0xd5, 0xd4};
//extern static byte bKeyMap[COLS]; // bits indicating pressed keys
static byte bOldKeyMap[COLS]; // previous map to look for pressed/released keys
static byte bColorToByte[4] = {0, 0x49, 0x92, 0xff};
static byte iCSPin, iDCPin, iResetPin;
static int iScrollOffset;
static int scrollArea=LCD_HEIGHT;
void SRXEFill(byte ucData);
static void SRXEWriteCommand(unsigned char c);
typedef enum
{
MODE_DATA = 0,
MODE_COMMAND
} DC_MODE;
#ifndef HIGH
#define HIGH 1
#define LOW 0
#define INPUT 0
#define INPUT_PULLUP 1
#define OUTPUT 2
#endif
// Chip select for the external 1Mb flash module
#define CS_FLASH 0xd3
//Keyboard
//Logical Layout (SK# are screen keys: top to bottom 1-5 on left, 6-10 on right):
// ROW1|ROW2|ROW3|ROW4|ROW5|ROW6|ROW7|ROW8|ROW9|ROW10
// COL1 1| 2| 3| 4| 5| 6| 7| 8| 9| 0
// COL2 Q| W| E| R| T| Y| U| I| O| P
// COL3 A| S| D| F| G| H| J| K| L| Bksp
// COL4 Shft| Z| X| C| V| B| N|Down|Entr| Up
// COL5 Sym|Frac|Root| Exp| Spc| ,| .| M|Left|Right
// COL6 SK1| SK2| SK3| SK4| SK5| SK6| SK7| SK8| SK9| SK10
byte OriginalKeys[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p',
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', '\b', // enter (now del needs a shift)
0 , 'z', 'x', 'c', 'v', 'b', 'n', 0xe1, 0, 0xe0, // 5 = down, 4 = up
0 , '\t', '\e', 0, ' ', ',', '.', 'm', 0xe3, 0xe2, // 2 = left, 3 = right, root = ESC
0xf0, 0xf1, 0xf2, 0xf3, 0, 0xf5, 0xf6, 0xf7, 0xf8, '\n'
};
byte ShiftedKeys[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P',
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '\b',
0 , 'Z', 'X', 'C', 'V', 'B', 'N', 0x5, 0, 0x4, // 5 = down
0 , '\t', '\e', 0, '_', ',', '.', 'M', 2, 3,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, '\n'
};
byte SymKeys[] = {'!', '#', '@', '$', '%', '^', '\'', '\"', '(', ')',
'&', '~', '|', '`', '£', '¬', 'u', ';', '[', ']', // i = ;
'=', '+', '-', 'f', 'g', 'h', 'j', ':', '?', '\b',
0 , '*', '/', 'c', 'v', 'b', 'n', 0x5, 0, 0x4, // z = *, x = /
0 , '\t', '\e' , 0 , 0x1, '<', '>', 'm', 2, 3, // 1 = menu
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, '\n'
};
byte SymShiftKeys[] = {'!', '2', '3', '$', '%', '6', '\'', '\"', '{', '}',
'q', 'w', 'e', 'r', 't', 'y', 'u', ';', '[', ']', // i = ;
'=', '+', '-', 'f', 'g', 'h', 'j', ':', '?', '\b',
0 , '*', '\\', 'c', 'v', 'b', 'n', 0x5, 0, 0x4, // z = *, x = /
0 , '\t', '\e' , 0 , 0x1, '<', '>', 'm', 2, 3, // 1 = menu
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, '\n'
};
//
// Power on the LCD
//
const char powerup[] PROGMEM = {
1, 0x01, // soft reset
99, 120, // 120ms delay
1, 0x11, // sleep out
1, 0x28, // display off
99, 50, // 50ms delay
3, 0xc0, 0xf8, 0x00, // Vop = 0xF0
2, 0xc3, 0x04, // BIAS = 1/14
2, 0xc4, 0x05, // Booster = x8
2, 0xd0, 0x1d, // Enable analog circuit
2, 0xb3, 0x00, // Set FOSC divider
2, 0xb5, 0x8b, // N-Line = 0
1, 0x38, // Set grayscale mode (0x39 = monochrome mode)
2, 0x3a, 0x02, // Enable DDRAM interface
2, 0x36, 0x00, // Scan direction setting
2, 0xB0, 0x9f, // Duty setting (0x87?)
5, 0xf0, 0x12, 0x12, 0x12, 0x12, // 77Hz frame rate in all temperatures
1, 0x20, // Display inversion off
1, 0x29, // Display ON
0
};
// small font
const byte ucFont[]PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x5f, 0x5f, 0x06, 0x00, 0x00,
0x00, 0x07, 0x07, 0x00, 0x07, 0x07, 0x00, 0x00, 0x14, 0x7f, 0x7f, 0x14, 0x7f, 0x7f, 0x14, 0x00,
0x24, 0x2e, 0x2a, 0x6b, 0x6b, 0x3a, 0x12, 0x00, 0x46, 0x66, 0x30, 0x18, 0x0c, 0x66, 0x62, 0x00,
0x30, 0x7a, 0x4f, 0x5d, 0x37, 0x7a, 0x48, 0x00, 0x00, 0x04, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1c, 0x3e, 0x63, 0x41, 0x00, 0x00, 0x00, 0x00, 0x41, 0x63, 0x3e, 0x1c, 0x00, 0x00, 0x00,
0x08, 0x2a, 0x3e, 0x1c, 0x1c, 0x3e, 0x2a, 0x08, 0x00, 0x08, 0x08, 0x3e, 0x3e, 0x08, 0x08, 0x00,
0x00, 0x00, 0x80, 0xe0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00,
0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x03, 0x01, 0x00,
0x3e, 0x7f, 0x59, 0x4d, 0x47, 0x7f, 0x3e, 0x00, 0x40, 0x42, 0x7f, 0x7f, 0x40, 0x40, 0x00, 0x00,
0x62, 0x73, 0x59, 0x49, 0x6f, 0x66, 0x00, 0x00, 0x22, 0x63, 0x49, 0x49, 0x7f, 0x36, 0x00, 0x00,
0x18, 0x1c, 0x16, 0x53, 0x7f, 0x7f, 0x50, 0x00, 0x27, 0x67, 0x45, 0x45, 0x7d, 0x39, 0x00, 0x00,
0x3c, 0x7e, 0x4b, 0x49, 0x79, 0x30, 0x00, 0x00, 0x03, 0x03, 0x71, 0x79, 0x0f, 0x07, 0x00, 0x00,
0x36, 0x7f, 0x49, 0x49, 0x7f, 0x36, 0x00, 0x00, 0x06, 0x4f, 0x49, 0x69, 0x3f, 0x1e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xe6, 0x66, 0x00, 0x00, 0x00,
0x08, 0x1c, 0x36, 0x63, 0x41, 0x00, 0x00, 0x00, 0x00, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00,
0x00, 0x41, 0x63, 0x36, 0x1c, 0x08, 0x00, 0x00, 0x00, 0x02, 0x03, 0x59, 0x5d, 0x07, 0x02, 0x00,
0x3e, 0x7f, 0x41, 0x5d, 0x5d, 0x5f, 0x0e, 0x00, 0x7c, 0x7e, 0x13, 0x13, 0x7e, 0x7c, 0x00, 0x00,
0x41, 0x7f, 0x7f, 0x49, 0x49, 0x7f, 0x36, 0x00, 0x1c, 0x3e, 0x63, 0x41, 0x41, 0x63, 0x22, 0x00,
0x41, 0x7f, 0x7f, 0x41, 0x63, 0x3e, 0x1c, 0x00, 0x41, 0x7f, 0x7f, 0x49, 0x5d, 0x41, 0x63, 0x00,
0x41, 0x7f, 0x7f, 0x49, 0x1d, 0x01, 0x03, 0x00, 0x1c, 0x3e, 0x63, 0x41, 0x51, 0x33, 0x72, 0x00,
0x7f, 0x7f, 0x08, 0x08, 0x7f, 0x7f, 0x00, 0x00, 0x00, 0x41, 0x7f, 0x7f, 0x41, 0x00, 0x00, 0x00,
0x30, 0x70, 0x40, 0x41, 0x7f, 0x3f, 0x01, 0x00, 0x41, 0x7f, 0x7f, 0x08, 0x1c, 0x77, 0x63, 0x00,
0x41, 0x7f, 0x7f, 0x41, 0x40, 0x60, 0x70, 0x00, 0x7f, 0x7f, 0x0e, 0x1c, 0x0e, 0x7f, 0x7f, 0x00,
0x7f, 0x7f, 0x06, 0x0c, 0x18, 0x7f, 0x7f, 0x00, 0x1c, 0x3e, 0x63, 0x41, 0x63, 0x3e, 0x1c, 0x00,
0x41, 0x7f, 0x7f, 0x49, 0x09, 0x0f, 0x06, 0x00, 0x1e, 0x3f, 0x21, 0x31, 0x61, 0x7f, 0x5e, 0x00,
0x41, 0x7f, 0x7f, 0x09, 0x19, 0x7f, 0x66, 0x00, 0x26, 0x6f, 0x4d, 0x49, 0x59, 0x73, 0x32, 0x00,
0x03, 0x41, 0x7f, 0x7f, 0x41, 0x03, 0x00, 0x00, 0x7f, 0x7f, 0x40, 0x40, 0x7f, 0x7f, 0x00, 0x00,
0x1f, 0x3f, 0x60, 0x60, 0x3f, 0x1f, 0x00, 0x00, 0x3f, 0x7f, 0x60, 0x30, 0x60, 0x7f, 0x3f, 0x00,
0x63, 0x77, 0x1c, 0x08, 0x1c, 0x77, 0x63, 0x00, 0x07, 0x4f, 0x78, 0x78, 0x4f, 0x07, 0x00, 0x00,
0x47, 0x63, 0x71, 0x59, 0x4d, 0x67, 0x73, 0x00, 0x00, 0x7f, 0x7f, 0x41, 0x41, 0x00, 0x00, 0x00,
0x01, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x00, 0x00, 0x41, 0x41, 0x7f, 0x7f, 0x00, 0x00, 0x00,
0x08, 0x0c, 0x06, 0x03, 0x06, 0x0c, 0x08, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x00, 0x00, 0x03, 0x07, 0x04, 0x00, 0x00, 0x00, 0x20, 0x74, 0x54, 0x54, 0x3c, 0x78, 0x40, 0x00,
0x41, 0x7f, 0x3f, 0x48, 0x48, 0x78, 0x30, 0x00, 0x38, 0x7c, 0x44, 0x44, 0x6c, 0x28, 0x00, 0x00,
0x30, 0x78, 0x48, 0x49, 0x3f, 0x7f, 0x40, 0x00, 0x38, 0x7c, 0x54, 0x54, 0x5c, 0x18, 0x00, 0x00,
0x48, 0x7e, 0x7f, 0x49, 0x03, 0x06, 0x00, 0x00, 0x98, 0xbc, 0xa4, 0xa4, 0xf8, 0x7c, 0x04, 0x00,
0x41, 0x7f, 0x7f, 0x08, 0x04, 0x7c, 0x78, 0x00, 0x00, 0x44, 0x7d, 0x7d, 0x40, 0x00, 0x00, 0x00,
0x60, 0xe0, 0x80, 0x84, 0xfd, 0x7d, 0x00, 0x00, 0x41, 0x7f, 0x7f, 0x10, 0x38, 0x6c, 0x44, 0x00,
0x00, 0x41, 0x7f, 0x7f, 0x40, 0x00, 0x00, 0x00, 0x7c, 0x7c, 0x18, 0x78, 0x1c, 0x7c, 0x78, 0x00,
0x7c, 0x78, 0x04, 0x04, 0x7c, 0x78, 0x00, 0x00, 0x38, 0x7c, 0x44, 0x44, 0x7c, 0x38, 0x00, 0x00,
0x84, 0xfc, 0xf8, 0xa4, 0x24, 0x3c, 0x18, 0x00, 0x18, 0x3c, 0x24, 0xa4, 0xf8, 0xfc, 0x84, 0x00,
0x44, 0x7c, 0x78, 0x4c, 0x04, 0x0c, 0x18, 0x00, 0x48, 0x5c, 0x54, 0x74, 0x64, 0x24, 0x00, 0x00,
0x04, 0x04, 0x3e, 0x7f, 0x44, 0x24, 0x00, 0x00, 0x3c, 0x7c, 0x40, 0x40, 0x3c, 0x7c, 0x40, 0x00,
0x1c, 0x3c, 0x60, 0x60, 0x3c, 0x1c, 0x00, 0x00, 0x3c, 0x7c, 0x60, 0x30, 0x60, 0x7c, 0x3c, 0x00,
0x44, 0x6c, 0x38, 0x10, 0x38, 0x6c, 0x44, 0x00, 0x9c, 0xbc, 0xa0, 0xa0, 0xfc, 0x7c, 0x00, 0x00,
0x4c, 0x64, 0x74, 0x5c, 0x4c, 0x64, 0x00, 0x00, 0x08, 0x08, 0x3e, 0x77, 0x41, 0x41, 0x00, 0x00,
0x00, 0x00, 0x00, 0x77, 0x77, 0x00, 0x00, 0x00, 0x41, 0x41, 0x77, 0x3e, 0x08, 0x08, 0x00, 0x00,
0x02, 0x03, 0x01, 0x03, 0x02, 0x03, 0x01, 0x00, 0x70, 0x78, 0x4c, 0x46, 0x4c, 0x78, 0x70, 0x00
};
// 5x7 font (in 6x8 cell)
const unsigned char ucSmallFont[]PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x5f, 0x06, 0x00, 0x00, 0x07, 0x03, 0x00,
0x07, 0x03, 0x00, 0x24, 0x7e, 0x24, 0x7e, 0x24, 0x00, 0x24, 0x2b, 0x6a, 0x12, 0x00, 0x00, 0x63,
0x13, 0x08, 0x64, 0x63, 0x00, 0x36, 0x49, 0x56, 0x20, 0x50, 0x00, 0x00, 0x07, 0x03, 0x00, 0x00,
0x00, 0x00, 0x3e, 0x41, 0x00, 0x00, 0x00, 0x00, 0x41, 0x3e, 0x00, 0x00, 0x00, 0x08, 0x3e, 0x1c,
0x3e, 0x08, 0x00, 0x08, 0x08, 0x3e, 0x08, 0x08, 0x00, 0x00, 0xe0, 0x60, 0x00, 0x00, 0x00, 0x08,
0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02,
0x00, 0x3e, 0x51, 0x49, 0x45, 0x3e, 0x00, 0x00, 0x42, 0x7f, 0x40, 0x00, 0x00, 0x62, 0x51, 0x49,
0x49, 0x46, 0x00, 0x22, 0x49, 0x49, 0x49, 0x36, 0x00, 0x18, 0x14, 0x12, 0x7f, 0x10, 0x00, 0x2f,
0x49, 0x49, 0x49, 0x31, 0x00, 0x3c, 0x4a, 0x49, 0x49, 0x30, 0x00, 0x01, 0x71, 0x09, 0x05, 0x03,
0x00, 0x36, 0x49, 0x49, 0x49, 0x36, 0x00, 0x06, 0x49, 0x49, 0x29, 0x1e, 0x00, 0x00, 0x6c, 0x6c,
0x00, 0x00, 0x00, 0x00, 0xec, 0x6c, 0x00, 0x00, 0x00, 0x08, 0x14, 0x22, 0x41, 0x00, 0x00, 0x24,
0x24, 0x24, 0x24, 0x24, 0x00, 0x00, 0x41, 0x22, 0x14, 0x08, 0x00, 0x02, 0x01, 0x59, 0x09, 0x06,
0x00, 0x3e, 0x41, 0x5d, 0x55, 0x1e, 0x00, 0x7e, 0x11, 0x11, 0x11, 0x7e, 0x00, 0x7f, 0x49, 0x49,
0x49, 0x36, 0x00, 0x3e, 0x41, 0x41, 0x41, 0x22, 0x00, 0x7f, 0x41, 0x41, 0x41, 0x3e, 0x00, 0x7f,
0x49, 0x49, 0x49, 0x41, 0x00, 0x7f, 0x09, 0x09, 0x09, 0x01, 0x00, 0x3e, 0x41, 0x49, 0x49, 0x7a,
0x00, 0x7f, 0x08, 0x08, 0x08, 0x7f, 0x00, 0x00, 0x41, 0x7f, 0x41, 0x00, 0x00, 0x30, 0x40, 0x40,
0x40, 0x3f, 0x00, 0x7f, 0x08, 0x14, 0x22, 0x41, 0x00, 0x7f, 0x40, 0x40, 0x40, 0x40, 0x00, 0x7f,
0x02, 0x04, 0x02, 0x7f, 0x00, 0x7f, 0x02, 0x04, 0x08, 0x7f, 0x00, 0x3e, 0x41, 0x41, 0x41, 0x3e,
0x00, 0x7f, 0x09, 0x09, 0x09, 0x06, 0x00, 0x3e, 0x41, 0x51, 0x21, 0x5e, 0x00, 0x7f, 0x09, 0x09,
0x19, 0x66, 0x00, 0x26, 0x49, 0x49, 0x49, 0x32, 0x00, 0x01, 0x01, 0x7f, 0x01, 0x01, 0x00, 0x3f,
0x40, 0x40, 0x40, 0x3f, 0x00, 0x1f, 0x20, 0x40, 0x20, 0x1f, 0x00, 0x3f, 0x40, 0x3c, 0x40, 0x3f,
0x00, 0x63, 0x14, 0x08, 0x14, 0x63, 0x00, 0x07, 0x08, 0x70, 0x08, 0x07, 0x00, 0x71, 0x49, 0x45,
0x43, 0x00, 0x00, 0x00, 0x7f, 0x41, 0x41, 0x00, 0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00,
0x41, 0x41, 0x7f, 0x00, 0x00, 0x04, 0x02, 0x01, 0x02, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80,
0x00, 0x00, 0x03, 0x07, 0x00, 0x00, 0x00, 0x20, 0x54, 0x54, 0x54, 0x78, 0x00, 0x7f, 0x44, 0x44,
0x44, 0x38, 0x00, 0x38, 0x44, 0x44, 0x44, 0x28, 0x00, 0x38, 0x44, 0x44, 0x44, 0x7f, 0x00, 0x38,
0x54, 0x54, 0x54, 0x08, 0x00, 0x08, 0x7e, 0x09, 0x09, 0x00, 0x00, 0x18, 0xa4, 0xa4, 0xa4, 0x7c,
0x00, 0x7f, 0x04, 0x04, 0x78, 0x00, 0x00, 0x00, 0x00, 0x7d, 0x40, 0x00, 0x00, 0x40, 0x80, 0x84,
0x7d, 0x00, 0x00, 0x7f, 0x10, 0x28, 0x44, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x40, 0x00, 0x00, 0x7c,
0x04, 0x18, 0x04, 0x78, 0x00, 0x7c, 0x04, 0x04, 0x78, 0x00, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38,
0x00, 0xfc, 0x44, 0x44, 0x44, 0x38, 0x00, 0x38, 0x44, 0x44, 0x44, 0xfc, 0x00, 0x44, 0x78, 0x44,
0x04, 0x08, 0x00, 0x08, 0x54, 0x54, 0x54, 0x20, 0x00, 0x04, 0x3e, 0x44, 0x24, 0x00, 0x00, 0x3c,
0x40, 0x20, 0x7c, 0x00, 0x00, 0x1c, 0x20, 0x40, 0x20, 0x1c, 0x00, 0x3c, 0x60, 0x30, 0x60, 0x3c,
0x00, 0x6c, 0x10, 0x10, 0x6c, 0x00, 0x00, 0x9c, 0xa0, 0x60, 0x3c, 0x00, 0x00, 0x64, 0x54, 0x54,
0x4c, 0x00, 0x00, 0x08, 0x3e, 0x41, 0x41, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x00,
0x41, 0x41, 0x3e, 0x08, 0x00, 0x02, 0x01, 0x02, 0x01, 0x00, 0x00, 0x3c, 0x26, 0x23, 0x26, 0x3c
};
uint8_t getPinInfo(uint8_t pin, volatile uint8_t **iDDR, volatile uint8_t **iPort, int bInput)
{
uint8_t port, bit;
port = (pin & 0xf0); // hex port (A,B,D,E,F)
bit = pin & 0x7;
switch (port)
{
case 0xA0: // really port G
*iPort = (bInput) ? &PING : &PORTG;
*iDDR = &DDRG;
break;
case 0xB0:
*iPort = (bInput) ? &PINB : &PORTB;
*iDDR = &DDRB;
break;
case 0xD0:
*iPort = (bInput) ? &PIND : &PORTD;
*iDDR = &DDRD;
break;
case 0xE0:
*iPort = (bInput) ? &PINE : &PORTE;
*iDDR = &DDRE;
break;
case 0xF0:
*iPort = (bInput) ? &PINF : &PORTF;
*iDDR = &DDRF;
break;
}
return bit;
} /* getPinInfo() */
//
// Simplified pin numbering scheme uses a hex number to specify the port number
// and bit. Top 4 bits = port (B/D/E/F/G), bottom 3 bits specify the bit of the port
// e.g. 0xB4 = PORTB, bit 4, 0Ax is for port G
//
void mypinMode(uint8_t pin, uint8_t mode)
{
uint8_t bit;
volatile uint8_t *iPort, *iDDR;
bit = getPinInfo(pin, &iDDR, &iPort, 0);
switch (mode)
{
case INPUT:
*iDDR &= ~(1 << bit);
break;
case INPUT_PULLUP:
*iDDR |= (1 << bit);
*iPort |= (1 << bit); // set the output high, then set it as an input
*iDDR &= ~(1 << bit);
break;
case OUTPUT:
*iDDR |= (1 << bit);
break;
}
} /* mypinMode() */
void mydigitalWrite(uint8_t pin, uint8_t value)
{
uint8_t bit;
volatile uint8_t *iPort, *iDDR;
bit = getPinInfo(pin, &iDDR, &iPort, 0);
if (value == LOW)
{
*iPort &= ~(1 << bit);
}
else
{
*iPort |= (1 << bit);
}
} /* mydigitalWrite() */
uint8_t mydigitalRead(uint8_t pin)
{
uint8_t bit;
volatile uint8_t *iPort, *iDDR;
bit = getPinInfo(pin, &iDDR, &iPort, 1);
if (*iPort & (1 << bit))
return HIGH;
else
return LOW;
} /* mydigitalRead() */
//
// Put the device in a deep sleep to save power
// Wakes up when pressing the "power" button
//
void SRXESleep(void)
{
// Turn off the LCD
SRXEPowerDown();
//TRXPR = 1 << SLPTR; // send transceiver to sleep
// disable ADC
ADCSRA = 0;
DDRD &= ~(1 << PORTD2); //PIN INT2 as input
PORTD |= (1 << PORTD2); // pull-up resistor, the pin is forced to 1 if nothing is connected
EIMSK &= ~(1 << INT2); //disabling interrupt on INT2
EICRA &= ~((1 << ISC21) | (1 << ISC20)); // low level triggers interrupt
EIFR |= (1 << INTF2); //clear interrupt flag
EIMSK |= (1 << INT2); //enabling interrupt flag on INT2
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
sleep_enable();
// turn off brown-out enable in software
// BODS must be set to one and BODSE must be set to zero within four clock cycles
// MCUCR = bit (BODS) | bit (BODSE);
// The BODS bit is automatically cleared after three clock cycles
// MCUCR = bit (BODS);
// We are guaranteed that the sleep_cpu call will be done
// as the processor executes the next instruction after
// interrupts are turned on.
sleep_cpu (); // one cycle
SRXEPowerUp();
} /* SRXESleep() */
//
// Initialize SPI using direct register access
//
void SPI_Init(void)
{
uint8_t temp;
// Initialize SPI
// Set SS to high so a connected chip will be "deselected" by default
// digitalWrite(SS, HIGH);
mydigitalWrite(0xb0, HIGH);
// When the SS pin is set as OUTPUT, it can be used as
// a general purpose output port (it doesn't influence
// SPI operations).
// pinMode(SS, OUTPUT);
mypinMode(0xb0, OUTPUT);
// SPCR = 01010000
//interrupt disabled,spi enabled,msb 1st,master,clk low when idle,
//*fdufnews 11/2019 **************** modification to speed SPI transfert *********************
//sample on leading edge of clk,system clock/2 rate
SPCR = (1 << SPE) | (1 << MSTR);
SPSR = (1 << SPI2X);
temp = SPSR; // clear old data
temp = SPDR;
if (temp != 0) {}; // suppress compiler warning
// Set SCK as output
//pinMode(13, OUTPUT);
mypinMode(0xb1, OUTPUT);
// set MOSI as output
//pinMode(11, OUTPUT);
mypinMode(0xb2, OUTPUT);
} /* SPI_Init() */
uint8_t SPI_transfer(volatile char data)
{
SPDR = data; // Start the transmission
/* trick from arduboy code
The following NOP introduces a small delay that can prevent the wait
loop from iterating when running at the maximum speed. This gives
about 10% more speed, even if it seems counter-intuitive. At lower
speeds it is unnoticed.
*/
asm volatile("nop");
while (!(SPSR & (1 << SPIF))) // Wait for the end of the transmission
{
};
return SPDR; // return the received byte
} /* SPI_transfer() */
// Sets the D/C pin to data or command mode
static void SRXESetMode(int iMode)
{
mydigitalWrite(iDCPin, (iMode == MODE_DATA));
} /* SRXESetMode() */
// Write a block of pixel data to the LCD
// Length can be anything from 1 to 17404 (whole display)
void SRXEWriteDataBlock(unsigned char *ucBuf, int iLen)
{
int i;
mydigitalWrite(iCSPin, LOW);
for (i = 0; i < iLen; i++)
SPI_transfer(ucBuf[i]);
mydigitalWrite(iCSPin, HIGH);
}
//
// Command sequence to power up the LCD controller
//
void SRXEPowerUp(void)
{
uint8_t ucTemp[4];
const char *pList = powerup;
uint8_t val, count, len = 1;
while (len != 0)
{
len = pgm_read_byte(pList++);
if (len == 99) // delay
{
val = pgm_read_byte(pList++);
delay(val);
}
else if (len != 0) // send command with optional data
{
val = pgm_read_byte(pList++); // command
SRXEWriteCommand(val);
count = len - 1;
if (count != 0)
{
memcpy_P(ucTemp, pList, count);
pList += count;
SRXEWriteDataBlock(ucTemp, count);
}
}
}
} /* SRXEPowerUp() */
//
// Initializes the LCD controller
// Parameters: GPIO pin numbers used for the CS/DC/RST control lines
//
int SRXEInit(int iCS, int iDC, int iReset)
{
byte uc, ucTemp[8];
iCSPin = iCS;
iDCPin = iDC;
iResetPin = iReset;
SPI_Init();
mypinMode(iCSPin, OUTPUT);
mypinMode(CS_FLASH, OUTPUT); // in case we want to use the SPI flash
mydigitalWrite(iCSPin, HIGH);
mypinMode(iDCPin, OUTPUT);
mypinMode(iResetPin, OUTPUT);
// Start by reseting the LCD controller
mydigitalWrite(iResetPin, HIGH);
delay(50);
mydigitalWrite(iResetPin, LOW);
delay(5);
mydigitalWrite(iResetPin, HIGH); // take it out of reset
delay(150); // datasheet says it must be at least 120ms
// mydigitalWrite(iCSPin, LOW); // leave CS low forever
SRXEPowerUp(); // turn on and initialize the display
SRXEFill(0); // erase memory (it's already cleared by resetting it)
return 0;
} /* SRXEInit() */
//
// Turn off the LCD display (lowest power mode)
//
void SRXEPowerDown()
{
//SRXEFill(0); // fill memory with zeros to go to lowest power mode
SRXEWriteCommand(0x28); // Display OFF
SRXEWriteCommand(0x10); // Sleep in
} /* SRXEPowerDown() */
//
// Write a 1 byte command to the LCD controller
//
static void SRXEWriteCommand(unsigned char c)
{
mydigitalWrite(iCSPin, LOW);
SRXESetMode(MODE_COMMAND);
SPI_transfer(c);
SRXESetMode(MODE_DATA);
mydigitalWrite(iCSPin, HIGH);
} /* SRXEWriteCommand() */
//
// Send commands to position the "cursor" to the given
// row and column
// Opens a window in the display RAM
// the windows starts @ x, y and it is cx wide and cy tall
// all the subsequent write cycles will be done in that window
//
void SRXESetPosition(int x, int y, int cx, int cy)
{
byte ucTemp[4];
if (x > 383 || y > 159 || cx > 384 || cy > 160)
return; // invalid
SRXEWriteCommand(0x2a); // set column address
ucTemp[0] = 0; // start column high byte
ucTemp[1] = x / 3; // start column low byte
ucTemp[2] = 0; // end col high byte
ucTemp[3] = (x + cx - 1) / 3; // end col low byte
SRXEWriteDataBlock(ucTemp, 4);
SRXEWriteCommand(0x2b); // set row address
ucTemp[0] = 0; // start row high byte
ucTemp[1] = y; // start row low byte
ucTemp[2] = 0; // end row high byte
ucTemp[3] = y + cy - 1; // end row low byte
SRXEWriteDataBlock(ucTemp, 4);
SRXEWriteCommand(0x2c); // write RAM
} /* SRXESetPosition() */
// SRXELoadBitmapRLE
// load a bitmap in the display RAM
// input
// x, y coordinate of top left in the display
// btmp array containing the bitmap compressed with RLE
//
void SRXELoadBitmapRLE(int x, int y, const uint8_t *btmp){
int width, height, index=0;
unsigned char length, value;
width = pgm_read_byte_near(btmp+index++) + (pgm_read_byte_near(btmp+index++) <<8);
height = pgm_read_byte_near(btmp+index++) + (pgm_read_byte_near(btmp+index++) <<8);
SRXESetPosition(x, y, width, height);
mydigitalWrite(iCSPin, LOW);
while(length = pgm_read_byte_near(btmp+index++) ){
value = pgm_read_byte_near(btmp+index++) ;
for(unsigned char count=0; count<length; count++){
SPI_transfer(value);
}
}
mydigitalWrite(iCSPin, HIGH);
}
//
// Called when the power button is pressed to wake up the system
// Power up the display
//
ISR (INT2_vect)
{
// cancel sleep as a precaution
sleep_disable();
}
//
// Set Scroll Area
// inputs:
// TA: top fixed area
// SA: scroll area
// BA: bottom fixed area
// TA + SA + BA = 160
//
// fdufnews 12/2019
//
void SRXEScrollArea(int TA, int SA, int BA)
{
byte ucTemp[3];
if ((TA+SA+BA)!=160) return;
SRXEWriteCommand(0x33); // set scroll area
ucTemp[0] = (byte)TA;
ucTemp[1] = (byte)SA;
ucTemp[2] = (byte)BA;
SRXEWriteDataBlock(ucTemp, 3);
scrollArea = (byte)SA;
}
//
// Scroll the screen N lines vertically (positive or negative)
// The value given represents a delta which affects the current scroll offset
//
// fdufnews 12/2019
// scroll offset is modulo scrollArea and not LCD_HEIGHT
//
void SRXEScroll(int iLines)
{
byte b;
// iScrollOffset = (iScrollOffset + iLines) % LCD_HEIGHT;
iScrollOffset = (iScrollOffset + iLines) % scrollArea;
SRXEWriteCommand(0x37); // set scroll start line
b = (byte)iScrollOffset;
SRXEWriteDataBlock(&b, 1);
} /* SRXEScroll() */
//
// Reset the scroll position to 0
//
void SRXEScrollReset(void)
{
byte b;
iScrollOffset = 0;
SRXEWriteCommand(0x37); // scroll start address
b = 0;
SRXEWriteDataBlock(&b, 1);
} /* SRXEcdScrollReset() */
void SRXEHorizontalLine(int x, int y, int length, byte color, int thickness) {
byte bTemp[128];
SRXESetPosition(x * 3, y, length * 3, thickness);
memset(bTemp, bColorToByte[color], length);
for (int i = 0; i < thickness ; i++) {
SRXEWriteDataBlock(bTemp, length);
}
}
void SRXEVerticalLine(int x, int y, int height, byte color) {
byte bTemp[128];
SRXESetPosition(x, y, 1, height);
memset(bTemp, bColorToByte[color], height);
SRXEWriteDataBlock(bTemp, height);
}
//
// Draw an outline or filled rectangle
// Only draws on byte boundaries (3 pixels wide)
// (display is treated as 128x136)
//
void SRXERectangle(int x, int y, int cx, int cy, byte color, byte bFilled)
{
byte bTemp[128];
if (x < 0 || x > 127 || y < 0 || y > 135) return;
if (x + cx > 127 || y + cy > 135) return;
if (bFilled)
{
SRXESetPosition(x * 3, y, cx * 3, cy);
for (y = 0; y < cy; y++)
{
memset(bTemp, bColorToByte[color], cx);
SRXEWriteDataBlock(bTemp, cx);
}
} // filled
else // outline
{
// Draw top part
SRXESetPosition(x * 3, y, cx * 3, 1);
memset(bTemp, bColorToByte[color], cx);
SRXEWriteDataBlock(bTemp, cx);
// Bottom
SRXESetPosition(x * 3, y + cy - 1, cx * 3, 1);
memset(bTemp, bColorToByte[color], cx);
SRXEWriteDataBlock(bTemp, cx);
// Left
SRXESetPosition(x * 3, y, 3, cy);
memset(bTemp, bColorToByte[color], cy);
SRXEWriteDataBlock(bTemp, cy);
// Right
SRXESetPosition((x + cx - 1) * 3, y, 3, cy);
memset(bTemp, bColorToByte[color], cy);
SRXEWriteDataBlock(bTemp, cy);
}
} /* SRXERectangle() */
int SRXEWriteChar(int x, int y, char ch) {
int i, j, iLen;
unsigned char ucTemp[8], *s;
byte fgColor0, fgColor1, fgColor2, bgColor;
fgColor0 = 0xe0; fgColor1 = 0x1c; fgColor2 = 0x3;
bgColor = 0x00;
int tx, ty;
byte bTemp[16], bMask, bOut, *d;
s = (unsigned char *)&ucSmallFont[(ch - 32) * 6];
memcpy_P(ucTemp, s, 6); // copy from FLASH memory
// convert from 1-bpp to 2/3-bpp
d = bTemp;
for (ty = 0; ty < 8; ty++)
{
bMask = 1 << ty;
for (tx = 0; tx < 6; tx += 3) // 2 sets of 3 pixels
{
bOut = bgColor;
if (ucTemp[tx] & bMask)
{
bOut &= 0x1f; // clear top 3 bits
bOut |= fgColor0; // first pixel (3 bits)
}
if (ucTemp[tx + 1] & bMask)
{
bOut &= 0xe3; // clear middle 3 bits
bOut |= fgColor1; // second pixel (3 bits)
}
if (ucTemp[tx + 2] & bMask)
{
bOut &= 0xfc; // clear lower 2 bits
bOut |= fgColor2; // third pixel (2 bits)
}
*d++ = bOut;
} // for tx
} // for ty
SRXESetPosition(x, y, 6, 8);
x += 6;
SRXEWriteDataBlock(bTemp, 16); // write character pattern
return 0;
}
//
// Draw a string of normal (8x8), small (6x8) or large (16x24) characters
// At the given col+row
//
int SRXEWriteString(int x, int y, char *szMsg, int iSize, int iFGColor, int iBGColor)
{
int i, j, iLen;
unsigned char ucTemp[8], *s;
byte fgColor0, fgColor1, fgColor2, bgColor;
if (iFGColor > 3) iFGColor = 3;
if (iBGColor > 3) iBGColor = 3;
if (iFGColor == 3)
{
fgColor0 = 0xe0; fgColor1 = 0x1c; fgColor2 = 0x3;
}
else
{
fgColor0 = (byte)iFGColor << 6; // first pixel 3-bit version of the color
fgColor1 = (byte)iFGColor << 3; // second pixel
fgColor2 = (byte)iFGColor; // 3rd pixel
}
bgColor = bColorToByte[iBGColor];
iLen = strlen(szMsg);
if (iSize == FONT_LARGE || iSize == FONT_MEDIUM) // draw 12x16 or 15x16 font
{
int iWidth, iDelta;
iWidth = (iSize == FONT_LARGE) ? 15 : 12;
iDelta = (iSize == FONT_LARGE) ? 5 : 4;
if ((iWidth * iLen) + x > 384) iLen = (384 - x) / iWidth; // can't display it all
if (iLen < 0)return -1;
for (i = 0; i < iLen; i++)
{
int tx, ty;
byte bTemp[84], bMask, bOut, bOut2, *d;
if (iSize == FONT_LARGE)
{
s = (unsigned char *)&ucFont[((unsigned char)szMsg[i] - 32) * 8];
memcpy_P(ucTemp, s, 8); // copy from FLASH memory
}
else
{
s = (unsigned char *)&ucSmallFont[((unsigned char)szMsg[i] - 32) * 6];
memcpy_P(ucTemp, s, 6);
}
// convert from 1-bpp to 2/3-bpp
d = bTemp;
s = ucTemp;
bMask = 1;
for (ty = 0; ty < 8; ty++)
{
for (tx = 0; tx < iWidth - 6; tx += 3) // 3 sets of 3 pixels
{
bOut = bOut2 = bgColor;
if (s[tx] & bMask)
{
bOut &= 0x3; // clear top 6 bits
bOut |= fgColor0 | fgColor1; // first 2 pixels (6 bits)
}
if (s[tx + 1] & bMask)
{
bOut &= 0xfc; // clear bottom 2 bits
bOut2 &= 0x1f; // clear top 3 bits
bOut |= fgColor2; // third pixel (2 bits)
bOut2 |= fgColor0;
}
if (s[tx + 2] & bMask)
{
bOut2 &= 0xe0; // clear lower 5 bits
bOut2 |= fgColor1 | fgColor2; // 2nd & 3rd pixel2 of second byte
}
d[0] = d[iDelta] = bOut;
if (tx != 6)
d[1] = d[iDelta + 1] = bOut2;
d += 2;
} // for tx
d += 4; // skip extra line (add 4 since we incremented by 6 already)
bMask <<= 1;
} // for ty
SRXESetPosition(x, y, iWidth, 16);
SRXEWriteDataBlock(bTemp, 16 * iDelta); // write character pattern
x += iWidth;
} // for each character
} // large+medium
else if (iSize == FONT_NORMAL)// draw 8x8 font
{
if ((9 * iLen) + x > 384) iLen = (384 - x) / 9; // can't display it all
if (iLen < 0)return -1;
for (i = 0; i < iLen; i++)
{
int tx, ty;
byte bTemp[24], bMask, bOut, *d;
s = (unsigned char *)&ucFont[((unsigned char)szMsg[i] - 32) * 8];
memcpy_P(ucTemp, s, 8); // copy from FLASH memory
// convert from 1-bpp to 2/3-bpp
d = bTemp;
for (ty = 0; ty < 8; ty++)
{
bMask = 1 << ty;
for (tx = 0; tx < 9; tx += 3) // 3 sets of 3 pixels
{
bOut = bgColor;
if (ucTemp[tx] & bMask)
{
bOut &= 0x1f; // clear top 3 bits
bOut |= fgColor0; // first pixel (3 bits)
}
if (ucTemp[tx + 1] & bMask)
{
bOut &= 0xe3; // clear middle 3 bits
bOut |= fgColor1; // second pixel (3 bits)
}
if (tx != 6 &&
ucTemp[tx + 2] & bMask)
{
bOut &= 0xfc; // clear lower 2 bits
bOut |= fgColor2; // third pixel (2 bits)
}
*d++ = bOut;
} // for tx
} // for ty
SRXESetPosition(x, y, 9, 8);
x += 9;
SRXEWriteDataBlock(bTemp, 24); // write character pattern
}
} // normal
else // 6x8
{
if ((6 * iLen) + x > 384) iLen = (384 - x) / 6; // can't display it all
if (iLen < 0)return -1;
for (i = 0; i < iLen; i++)
{
int tx, ty;
byte bTemp[16], bMask, bOut, *d;
s = (unsigned char *)&ucSmallFont[((unsigned char)szMsg[i] - 32) * 6];
memcpy_P(ucTemp, s, 6); // copy from FLASH memory
// convert from 1-bpp to 2/3-bpp
d = bTemp;
for (ty = 0; ty < 8; ty++)
{
bMask = 1 << ty;
for (tx = 0; tx < 6; tx += 3) // 2 sets of 3 pixels
{
bOut = bgColor;
if (ucTemp[tx] & bMask)
{
bOut &= 0x1f; // clear top 3 bits
bOut |= fgColor0; // first pixel (3 bits)
}
if (ucTemp[tx + 1] & bMask)
{
bOut &= 0xe3; // clear middle 3 bits
bOut |= fgColor1; // second pixel (3 bits)
}
if (ucTemp[tx + 2] & bMask)
{
bOut &= 0xfc; // clear lower 2 bits
bOut |= fgColor2; // third pixel (2 bits)
}
*d++ = bOut;
} // for tx
} // for ty
SRXESetPosition(x, y, 6, 8);
x += 6;
SRXEWriteDataBlock(bTemp, 16); // write character pattern
}
} // small
return 0;
} /* SRXEWriteString() */
// Fill the frame buffer with a byte pattern
// e.g. all off (0x00) or all on (0xff)
void SRXEFill(byte ucData)
{
int y;
byte temp[128];
SRXESetPosition(0, 0, 384, 160);
for (y = 0; y < 160; y++)
{
memset(temp, ucData, 128); // have to do this because the bytes get overwritten
SRXEWriteDataBlock(temp, 128); // fill with data byte
}
} /* SRXEFill() */
//
// External SPI flash functions (MX25L1005C - Macronix 1Mb/128KB serial flash memory)
// Data sheet here: http://www1.futureelectronics.com/doc/MACRONIX/MX25L1005CZUI-12GTR.pdf
// The CS line must be set low before each command and then set high after
// If you try to send 2 commands with the CS line left low, they won't execute
//
// ------------------
//
// Erase a 4k sector
// This is the smallest area that can be erased
// It can take around 60ms
// This function optionally waits until it completes
// returns 1 for success, 0 for failure
//
int SRXEFlashEraseSector(uint32_t ulAddr, int bWait)
{
uint8_t rc;
int timeout;
if (ulAddr & 4095L) // invalid address
return 0;
mydigitalWrite(CS_FLASH, LOW);
SPI_transfer(0x05); // read status register
rc = SPI_transfer(0);
mydigitalWrite(CS_FLASH, HIGH);
if (rc & 1) // indicates the chip is busy in a write operation
{
return 0; // fail
}
mydigitalWrite(CS_FLASH, LOW);
SPI_transfer(0x06); // WREN - Write enable
mydigitalWrite(CS_FLASH, HIGH);
mydigitalWrite(CS_FLASH, LOW);
SPI_transfer(0x20); // Sector Erase
// send 3-byte address (big-endian order)
SPI_transfer((uint8_t)(ulAddr >> 16)); // AD1
SPI_transfer((uint8_t)(ulAddr >> 8)); // AD2
SPI_transfer((uint8_t)ulAddr); // AD3
mydigitalWrite(CS_FLASH, HIGH);
// wait for the erase to complete
if (bWait)
{
rc = 1;
timeout = 0;
mydigitalWrite(CS_FLASH, LOW);
while (rc & 1)
{
SPI_transfer(0x05); // read status register
rc = SPI_transfer(0);
delay(1);
timeout++;
if (timeout >= 120) // took too long, bail out
{
mydigitalWrite(CS_FLASH, HIGH);
return 0;
}
}
mydigitalWrite(CS_FLASH, HIGH);