-
Notifications
You must be signed in to change notification settings - Fork 0
/
ST7735.c
1734 lines (1597 loc) · 67.5 KB
/
ST7735.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
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
/***************************************************
This is a library for the Adafruit 1.8" SPI display.
This library works with the Adafruit 1.8" TFT Breakout w/SD card
----> http://www.adafruit.com/products/358
as well as Adafruit raw 1.8" TFT displayun
----> http://www.adafruit.com/products/618
Check out the links above for our tutorials and wiring diagrams
These displays use SPI to communicate, 4 or 5 pins are required to
interface (RST is optional)
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
****************************************************/
// ST7735.c
// Runs on LM4F120/TM4C123
// Low level drivers for the ST7735 160x128 LCD based off of
// the file described above.
// 16-bit color, 128 wide by 160 high LCD
// Daniel Valvano
// March 20, 2018
// Augmented 7/17/2014 to have a simple graphics facility
// Tested with LaunchPadDLL.dll simulator 9/2/2014
// Last Modified: 3/20/2018
/* This example accompanies the book
"Embedded Systems: Real Time Interfacing to Arm Cortex M Microcontrollers",
ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2017
Copyright 2018 by Jonathan W. Valvano, [email protected]
You may use, edit, run or distribute this file
as long as the above copyright notice remains
THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
VALVANO SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
For more information about my classes, my research, and my books, see
http://users.ece.utexas.edu/~valvano/
*/
// hardware connections
// **********ST7735 TFT and SDC*******************
// ST7735
// Backlight (pin 10) connected to +3.3 V
// MISO (pin 9) unconnected
// SCK (pin 8) connected to PA2 (SSI0Clk)
// MOSI (pin 7) connected to PA5 (SSI0Tx)
// TFT_CS (pin 6) connected to PA3 (SSI0Fss)
// CARD_CS (pin 5) unconnected
// Data/Command (pin 4) connected to PA6 (GPIO), high for data, low for command
// RESET (pin 3) connected to PA7 (GPIO)
// VCC (pin 2) connected to +3.3 V
// Gnd (pin 1) connected to ground
// **********wide.hk ST7735R with ADXL345 accelerometer *******************
// Silkscreen Label (SDC side up; LCD side down) - Connection
// VCC - +3.3 V
// GND - Ground
// !SCL - PA2 Sclk SPI clock from microcontroller to TFT or SDC
// !SDA - PA5 MOSI SPI data from microcontroller to TFT or SDC
// DC - PA6 TFT data/command
// RES - PA7 TFT reset
// CS - PA3 TFT_CS, active low to enable TFT
// *CS - (NC) SDC_CS, active low to enable SDC
// MISO - (NC) MISO SPI data from SDC to microcontroller
// SDA – (NC) I2C data for ADXL345 accelerometer
// SCL – (NC) I2C clock for ADXL345 accelerometer
// SDO – (NC) I2C alternate address for ADXL345 accelerometer
// Backlight + - Light, backlight connected to +3.3 V
// **********wide.hk ST7735R with ADXL335 accelerometer *******************
// Silkscreen Label (SDC side up; LCD side down) - Connection
// VCC - +3.3 V
// GND - Ground
// !SCL - PA2 Sclk SPI clock from microcontroller to TFT or SDC
// !SDA - PA5 MOSI SPI data from microcontroller to TFT or SDC
// DC - PA6 TFT data/command
// RES - PA7 TFT reset
// CS - PA3 TFT_CS, active low to enable TFT
// *CS - (NC) SDC_CS, active low to enable SDC
// MISO - (NC) MISO SPI data from SDC to microcontroller
// X– (NC) analog input X-axis from ADXL335 accelerometer
// Y– (NC) analog input Y-axis from ADXL335 accelerometer
// Z– (NC) analog input Z-axis from ADXL335 accelerometer
// Backlight + - Light, backlight connected to +3.3 V
// **********HiLetgo ST7735 TFT and SDC (SDC not tested)*******************
// ST7735
// LED- (pin 16) TFT, connected to ground
// LED+ (pin 15) TFT, connected to +3.3 V
// SD_CS (pin 14) SDC, chip select
// MOSI (pin 13) SDC, MOSI
// MISO (pin 12) SDC, MISO
// SCK (pin 11) SDC, serial clock
// CS (pin 10) TFT, PA3 (SSI0Fss)
// SCL (pin 9) TFT, SCK PA2 (SSI0Clk)
// SDA (pin 8) TFT, MOSI PA5 (SSI0Tx)
// A0 (pin 7) TFT, Data/Command PA6 (GPIO), high for data, low for command
// RESET (pin 6) TFT, to PA7 (GPIO)
// NC (pins 3,4,5) not connected
// VCC (pin 2) connected to +3.3 V
// GND (pin 1) connected to ground
#include <stdio.h>
#include <stdint.h>
#include "ST7735.h"
#include "../inc/tm4c123gh6pm.h"
extern uint8_t buffer[20480];
// 16 rows (0 to 15) and 21 characters (0 to 20)
// Requires (11 + size*size*6*8) bytes of transmission for each character
uint32_t StX=0; // position along the horizonal axis 0 to 20
uint32_t StY=0; // position along the vertical axis 0 to 15
uint16_t StTextColor = 0xFFFF;
#define ST7735_NOP 0x00
#define ST7735_SWRESET 0x01
#define ST7735_RDDID 0x04
#define ST7735_RDDST 0x09
#define ST7735_SLPIN 0x10
#define ST7735_SLPOUT 0x11
#define ST7735_PTLON 0x12
#define ST7735_NORON 0x13
#define ST7735_INVOFF 0x20
#define ST7735_INVON 0x21
#define ST7735_DISPOFF 0x28
#define ST7735_DISPON 0x29
#define ST7735_CASET 0x2A
#define ST7735_RASET 0x2B
#define ST7735_RAMWR 0x2C
#define ST7735_RAMRD 0x2E
#define ST7735_PTLAR 0x30
#define ST7735_COLMOD 0x3A
#define ST7735_MADCTL 0x36
#define ST7735_FRMCTR1 0xB1
#define ST7735_FRMCTR2 0xB2
#define ST7735_FRMCTR3 0xB3
#define ST7735_INVCTR 0xB4
#define ST7735_DISSET5 0xB6
#define ST7735_PWCTR1 0xC0
#define ST7735_PWCTR2 0xC1
#define ST7735_PWCTR3 0xC2
#define ST7735_PWCTR4 0xC3
#define ST7735_PWCTR5 0xC4
#define ST7735_VMCTR1 0xC5
#define ST7735_RDID1 0xDA
#define ST7735_RDID2 0xDB
#define ST7735_RDID3 0xDC
#define ST7735_RDID4 0xDD
#define ST7735_PWCTR6 0xFC
#define ST7735_GMCTRP1 0xE0
#define ST7735_GMCTRN1 0xE1
#define TFT_CS (*((volatile uint32_t *)0x40004020))
#define TFT_CS_LOW 0 // CS normally controlled by hardware
#define TFT_CS_HIGH 0x08
#define DC (*((volatile uint32_t *)0x40004100))
#define DC_COMMAND 0
#define DC_DATA 0x40
#define RESET (*((volatile uint32_t *)0x40004200))
#define RESET_LOW 0
#define RESET_HIGH 0x80
#define SSI_CR0_SCR_M 0x0000FF00 // SSI Serial Clock Rate
#define SSI_CR0_SPH 0x00000080 // SSI Serial Clock Phase
#define SSI_CR0_SPO 0x00000040 // SSI Serial Clock Polarity
#define SSI_CR0_FRF_M 0x00000030 // SSI Frame Format Select
#define SSI_CR0_FRF_MOTO 0x00000000 // Freescale SPI Frame Format
#define SSI_CR0_DSS_M 0x0000000F // SSI Data Size Select
#define SSI_CR0_DSS_8 0x00000007 // 8-bit data
#define SSI_CR1_MS 0x00000004 // SSI Master/Slave Select
#define SSI_CR1_SSE 0x00000002 // SSI Synchronous Serial Port
// Enable
#define SSI_SR_BSY 0x00000010 // SSI Busy Bit
#define SSI_SR_TNF 0x00000002 // SSI Transmit FIFO Not Full
#define SSI_CPSR_CPSDVSR_M 0x000000FF // SSI Clock Prescale Divisor
#define SSI_CC_CS_M 0x0000000F // SSI Baud Clock Source
#define SSI_CC_CS_SYSPLL 0x00000000 // Either the system clock (if the
// PLL bypass is in effect) or the
// PLL output (default)
#define SYSCTL_RCGC1_SSI0 0x00000010 // SSI0 Clock Gating Control
#define SYSCTL_RCGC2_GPIOA 0x00000001 // port A Clock Gating Control
#define ST7735_TFTWIDTH 128
#define ST7735_TFTHEIGHT 160
#define ST7735_NOP 0x00
#define ST7735_SWRESET 0x01
#define ST7735_RDDID 0x04
#define ST7735_RDDST 0x09
#define ST7735_SLPIN 0x10
#define ST7735_SLPOUT 0x11
#define ST7735_PTLON 0x12
#define ST7735_NORON 0x13
#define ST7735_INVOFF 0x20
#define ST7735_INVON 0x21
#define ST7735_DISPOFF 0x28
#define ST7735_DISPON 0x29
#define ST7735_CASET 0x2A
#define ST7735_RASET 0x2B
#define ST7735_RAMWR 0x2C
#define ST7735_RAMRD 0x2E
#define ST7735_PTLAR 0x30
#define ST7735_COLMOD 0x3A
#define ST7735_MADCTL 0x36
#define ST7735_FRMCTR1 0xB1
#define ST7735_FRMCTR2 0xB2
#define ST7735_FRMCTR3 0xB3
#define ST7735_INVCTR 0xB4
#define ST7735_DISSET5 0xB6
#define ST7735_PWCTR1 0xC0
#define ST7735_PWCTR2 0xC1
#define ST7735_PWCTR3 0xC2
#define ST7735_PWCTR4 0xC3
#define ST7735_PWCTR5 0xC4
#define ST7735_VMCTR1 0xC5
#define ST7735_RDID1 0xDA
#define ST7735_RDID2 0xDB
#define ST7735_RDID3 0xDC
#define ST7735_RDID4 0xDD
#define ST7735_PWCTR6 0xFC
#define ST7735_GMCTRP1 0xE0
#define ST7735_GMCTRN1 0xE1
static const uint8_t Font[] = {
0x00, 0x00, 0x00, 0x00, 0x00, // char = 0
0x24, 0x14, 0x0E, 0x14, 0x24, // char = 1 // Korean "ch"
0x3E, 0x6B, 0x4F, 0x6B, 0x3E, // char = 2
0x1C, 0x3E, 0x7C, 0x3E, 0x1C, // char = 3
0x18, 0x3C, 0x7E, 0x3C, 0x18, // char = 4
0x1C, 0x57, 0x7D, 0x57, 0x1C, // char = 5
0x1C, 0x5E, 0x7F, 0x5E, 0x1C, // char = 6
0x00, 0x18, 0x3C, 0x18, 0x00, // char = 7
0xFF, 0xE7, 0xC3, 0xE7, 0xFF, // char = 8
0x00, 0x18, 0x24, 0x18, 0x00, // char = 9
0xFF, 0xE7, 0xDB, 0xE7, 0xFF, // char = 10
0x30, 0x48, 0x3A, 0x06, 0x0E, // char = 11
0x26, 0x29, 0x79, 0x29, 0x26, // char = 12
0x40, 0x7F, 0x05, 0x05, 0x07, // char = 13
0x40, 0x7F, 0x05, 0x25, 0x3F, // char = 14
0x5A, 0x3C, 0xE7, 0x3C, 0x5A, // char = 15
0x7F, 0x3E, 0x1C, 0x1C, 0x08, // char = 16
0x08, 0x1C, 0x1C, 0x3E, 0x7F, // char = 17
0x14, 0x22, 0x7F, 0x22, 0x14, // char = 18
0x5F, 0x5F, 0x00, 0x5F, 0x5F, // char = 19
0x06, 0x09, 0x7F, 0x01, 0x7F, // char = 20
0x00, 0x66, 0x89, 0x95, 0x6A, // char = 21
0x60, 0x60, 0x60, 0x60, 0x60, // char = 22
0x94, 0xA2, 0xFF, 0xA2, 0x94, // char = 23
0x08, 0x04, 0x7E, 0x04, 0x08, // char = 24
0x10, 0x20, 0x7E, 0x20, 0x10, // char = 25
0x08, 0x08, 0x2A, 0x1C, 0x08, // char = 26
0x08, 0x1C, 0x2A, 0x08, 0x08, // char = 27
0x1E, 0x10, 0x10, 0x10, 0x10, // char = 28
0x0C, 0x1E, 0x0C, 0x1E, 0x0C, // char = 29
0x30, 0x38, 0x3E, 0x38, 0x30, // char = 30
0x06, 0x0E, 0x3E, 0x0E, 0x06, // char = 31
0x00, 0x00, 0x00, 0x00, 0x00, // char = 32
0x00, 0x00, 0x5F, 0x00, 0x00, // char = 33
0x00, 0x07, 0x00, 0x07, 0x00, // char = 34
0x14, 0x7F, 0x14, 0x7F, 0x14, // char = 35
0x24, 0x2A, 0x7F, 0x2A, 0x12, // char = 36
0x23, 0x13, 0x08, 0x64, 0x62, // char = 37
0x36, 0x49, 0x56, 0x20, 0x50, // char = 38
0x00, 0x08, 0x07, 0x03, 0x00, // char = 39
0x00, 0x1C, 0x22, 0x41, 0x00, // char = 40
0x00, 0x41, 0x22, 0x1C, 0x00, // char = 41
0x2A, 0x1C, 0x7F, 0x1C, 0x2A, // char = 42
0x08, 0x08, 0x3E, 0x08, 0x08, // char = 43
0x00, 0x80, 0x70, 0x30, 0x00, // char = 44
0x08, 0x08, 0x08, 0x08, 0x08, // char = 45
0x00, 0x00, 0x60, 0x60, 0x00, // char = 46
0x20, 0x10, 0x08, 0x04, 0x02, // char = 47
0x3E, 0x51, 0x49, 0x45, 0x3E, // 0 // char = 48
0x00, 0x42, 0x7F, 0x40, 0x00, // 1 // char = 49
0x72, 0x49, 0x49, 0x49, 0x46, // 2 // char = 50
0x21, 0x41, 0x49, 0x4D, 0x33, // 3 // char = 51
0x18, 0x14, 0x12, 0x7F, 0x10, // 4 // char = 52
0x27, 0x45, 0x45, 0x45, 0x39, // 5 // char = 53
0x3C, 0x4A, 0x49, 0x49, 0x31, // 6 // char = 54
0x41, 0x21, 0x11, 0x09, 0x07, // 7 // char = 55
0x36, 0x49, 0x49, 0x49, 0x36, // 8 // char = 56
0x46, 0x49, 0x49, 0x29, 0x1E, // 9 // char = 57
0x00, 0x00, 0x14, 0x00, 0x00, // char = 58
0x00, 0x40, 0x34, 0x00, 0x00, // char = 59
0x00, 0x08, 0x14, 0x22, 0x41, // char = 60
0x14, 0x14, 0x14, 0x14, 0x14, // char = 61
0x00, 0x41, 0x22, 0x14, 0x08, // char = 62
0x02, 0x01, 0x59, 0x09, 0x06, // char = 63
0x3E, 0x41, 0x5D, 0x59, 0x4E, // char = 64
0x7C, 0x12, 0x11, 0x12, 0x7C, // A // char = 65
0x7F, 0x49, 0x49, 0x49, 0x36, // B // char = 66
0x3E, 0x41, 0x41, 0x41, 0x22, // C // char = 67
0x7F, 0x41, 0x41, 0x41, 0x3E, // D // char = 68
0x7F, 0x49, 0x49, 0x49, 0x41, // E // char = 69
0x7F, 0x09, 0x09, 0x09, 0x01, // F // char = 70
0x3E, 0x41, 0x41, 0x51, 0x73, // G // char = 71
0x7F, 0x08, 0x08, 0x08, 0x7F, // H // char = 72
0x00, 0x41, 0x7F, 0x41, 0x00, // I // char = 73
0x20, 0x40, 0x41, 0x3F, 0x01, // J // char = 74
0x7F, 0x08, 0x14, 0x22, 0x41, // K // char = 75
0x7F, 0x40, 0x40, 0x40, 0x40, // L // char = 76
0x7F, 0x02, 0x1C, 0x02, 0x7F, // M // char = 77
0x7F, 0x04, 0x08, 0x10, 0x7F, // N // char = 78
0x3E, 0x41, 0x41, 0x41, 0x3E, // O // char = 79
0x7F, 0x09, 0x09, 0x09, 0x06, // P // char = 80
0x3E, 0x41, 0x51, 0x21, 0x5E, // Q // char = 81
0x7F, 0x09, 0x19, 0x29, 0x46, // R // char = 82
0x26, 0x49, 0x49, 0x49, 0x32, // S // char = 83
0x03, 0x01, 0x7F, 0x01, 0x03, // T // char = 84
0x3F, 0x40, 0x40, 0x40, 0x3F, // U // char = 85
0x1F, 0x20, 0x40, 0x20, 0x1F, // V // char = 86
0x3F, 0x40, 0x38, 0x40, 0x3F, // W // char = 87
0x63, 0x14, 0x08, 0x14, 0x63, // X // char = 88
0x03, 0x04, 0x78, 0x04, 0x03, // Y // char = 89
0x61, 0x59, 0x49, 0x4D, 0x43, // Z // char = 90
0x00, 0x7F, 0x41, 0x41, 0x41, // char = 91
0x02, 0x04, 0x08, 0x10, 0x20, // char = 92
0x00, 0x41, 0x41, 0x41, 0x7F, // char = 93
0x04, 0x02, 0x01, 0x02, 0x04, // char = 94
0x40, 0x40, 0x40, 0x40, 0x40, // char = 95
0x00, 0x03, 0x07, 0x08, 0x00, // char = 96
0x20, 0x54, 0x54, 0x78, 0x40, // a // char = 97
0x7F, 0x28, 0x44, 0x44, 0x38, // b // char = 98
0x38, 0x44, 0x44, 0x44, 0x28, // c // char = 99
0x38, 0x44, 0x44, 0x28, 0x7F, // d // char = 100
0x38, 0x54, 0x54, 0x54, 0x18, // e // char = 101
0x00, 0x08, 0x7E, 0x09, 0x02, // f // char = 102
0x18, 0xA4, 0xA4, 0x9C, 0x78, // g // char = 103
0x7F, 0x08, 0x04, 0x04, 0x78, // h // char = 104
0x00, 0x44, 0x7D, 0x40, 0x00, // i // char = 105
0x20, 0x40, 0x40, 0x3D, 0x00, // j // char = 106
0x7F, 0x10, 0x28, 0x44, 0x00, // k // char = 107
0x00, 0x41, 0x7F, 0x40, 0x00, // l // char = 108
0x7C, 0x04, 0x78, 0x04, 0x78, // m // char = 109
0x7C, 0x08, 0x04, 0x04, 0x78, // n // char = 110
0x38, 0x44, 0x44, 0x44, 0x38, // o // char = 111
0xFC, 0x18, 0x24, 0x24, 0x18, // p // char = 112
0x18, 0x24, 0x24, 0x18, 0xFC, // q // char = 113
0x7C, 0x08, 0x04, 0x04, 0x08, // r // char = 114
0x48, 0x54, 0x54, 0x54, 0x24, // s // char = 115
0x04, 0x04, 0x3F, 0x44, 0x24, // t // char = 116
0x3C, 0x40, 0x40, 0x20, 0x7C, // u // char = 117
0x1C, 0x20, 0x40, 0x20, 0x1C, // v // char = 118
0x3C, 0x40, 0x30, 0x40, 0x3C, // w // char = 119
0x44, 0x28, 0x10, 0x28, 0x44, // x // char = 120
0x4C, 0x90, 0x90, 0x90, 0x7C, // y // char = 121
0x44, 0x64, 0x54, 0x4C, 0x44, // z // char = 122
0x00, 0x08, 0x36, 0x41, 0x00, // char = 123
0x00, 0x00, 0x77, 0x00, 0x00, // char = 124
0x00, 0x41, 0x36, 0x08, 0x00, // char = 125
0x02, 0x01, 0x02, 0x04, 0x02, // char = 126
0x3C, 0x26, 0x23, 0x26, 0x3C, // char = 127
0x1E, 0xA1, 0xA1, 0x61, 0x12, // char = 128
0x3A, 0x40, 0x40, 0x20, 0x7A, // char = 129
0x38, 0x54, 0x54, 0x55, 0x59, // char = 130
0x21, 0x55, 0x55, 0x79, 0x41, // char = 131
0x21, 0x54, 0x54, 0x78, 0x41, // char = 132
0x21, 0x55, 0x54, 0x78, 0x40, // char = 133
0x20, 0x54, 0x55, 0x79, 0x40, // char = 134
0x0C, 0x1E, 0x52, 0x72, 0x12, // char = 135
0x39, 0x55, 0x55, 0x55, 0x59, // char = 136
0x39, 0x54, 0x54, 0x54, 0x59, // char = 137
0x39, 0x55, 0x54, 0x54, 0x58, // char = 138
0x00, 0x00, 0x45, 0x7C, 0x41, // char = 139
0x00, 0x02, 0x45, 0x7D, 0x42, // char = 140
0x00, 0x01, 0x45, 0x7C, 0x40, // char = 141
0xF0, 0x29, 0x24, 0x29, 0xF0, // char = 142
0xF0, 0x28, 0x25, 0x28, 0xF0, // char = 143
0x7C, 0x54, 0x55, 0x45, 0x00, // char = 144
0x20, 0x54, 0x54, 0x7C, 0x54, // char = 145
0x7C, 0x0A, 0x09, 0x7F, 0x49, // char = 146
0x32, 0x49, 0x49, 0x49, 0x32, // char = 147
0x32, 0x48, 0x48, 0x48, 0x32, // char = 148
0x32, 0x4A, 0x48, 0x48, 0x30, // char = 149
0x3A, 0x41, 0x41, 0x21, 0x7A, // char = 150
0x3A, 0x42, 0x40, 0x20, 0x78, // char = 151
0x00, 0x9D, 0xA0, 0xA0, 0x7D, // char = 152
0x39, 0x44, 0x44, 0x44, 0x39, // char = 153
0x3D, 0x40, 0x40, 0x40, 0x3D, // char = 154
0x3C, 0x24, 0xFF, 0x24, 0x24, // char = 155
0x48, 0x7E, 0x49, 0x43, 0x66, // char = 156
0x2B, 0x2F, 0xFC, 0x2F, 0x2B, // char = 157
0xFF, 0x09, 0x29, 0xF6, 0x20, // char = 158
0xC0, 0x88, 0x7E, 0x09, 0x03, // char = 159
0x20, 0x54, 0x54, 0x79, 0x41, // char = 160
0x00, 0x00, 0x44, 0x7D, 0x41, // char = 161
0x30, 0x48, 0x48, 0x4A, 0x32, // char = 162
0x38, 0x40, 0x40, 0x22, 0x7A, // char = 163
0x00, 0x7A, 0x0A, 0x0A, 0x72, // char = 164
0x7D, 0x0D, 0x19, 0x31, 0x7D, // char = 165
0x26, 0x29, 0x29, 0x2F, 0x28, // char = 166
0x26, 0x29, 0x29, 0x29, 0x26, // char = 167
0x30, 0x48, 0x4D, 0x40, 0x20, // char = 168
0x38, 0x08, 0x08, 0x08, 0x08, // char = 169
0x08, 0x08, 0x08, 0x08, 0x38, // char = 170
0x2F, 0x10, 0xC8, 0xAC, 0xBA, // char = 171
0x2F, 0x10, 0x28, 0x34, 0xFA, // char = 172
0x00, 0x00, 0x7B, 0x00, 0x00, // char = 173
0x08, 0x14, 0x2A, 0x14, 0x22, // char = 174
0x22, 0x14, 0x2A, 0x14, 0x08, // char = 175
0xAA, 0x00, 0x55, 0x00, 0xAA, // char = 176
0xAA, 0x55, 0xAA, 0x55, 0xAA, // char = 177
0x00, 0x00, 0x00, 0xFF, 0x00, // char = 178
0x10, 0x10, 0x10, 0xFF, 0x00, // char = 179
0x14, 0x14, 0x14, 0xFF, 0x00, // char = 180
0x10, 0x10, 0xFF, 0x00, 0xFF, // char = 181
0x10, 0x10, 0xF0, 0x10, 0xF0, // char = 182
0x14, 0x14, 0x14, 0xFC, 0x00, // char = 183
0x14, 0x14, 0xF7, 0x00, 0xFF, // char = 184
0x00, 0x00, 0xFF, 0x00, 0xFF, // char = 185
0x14, 0x14, 0xF4, 0x04, 0xFC, // char = 186
0x14, 0x14, 0x17, 0x10, 0x1F, // char = 187
0x10, 0x10, 0x1F, 0x10, 0x1F, // char = 188
0x14, 0x14, 0x14, 0x1F, 0x00, // char = 189
0x10, 0x10, 0x10, 0xF0, 0x00, // char = 190
0x00, 0x00, 0x00, 0x1F, 0x10, // char = 191
0x10, 0x10, 0x10, 0x1F, 0x10, // char = 192
0x10, 0x10, 0x10, 0xF0, 0x10, // char = 193
0x00, 0x00, 0x00, 0xFF, 0x10, // char = 194
0x10, 0x10, 0x10, 0x10, 0x10, // char = 195
0x10, 0x10, 0x10, 0xFF, 0x10, // char = 196
0x00, 0x00, 0x00, 0xFF, 0x14, // char = 197
0x00, 0x00, 0xFF, 0x00, 0xFF, // char = 198
0x00, 0x00, 0x1F, 0x10, 0x17, // char = 199
0x00, 0x00, 0xFC, 0x04, 0xF4, // char = 200
0x14, 0x14, 0x17, 0x10, 0x17, // char = 201
0x14, 0x14, 0xF4, 0x04, 0xF4, // char = 202
0x00, 0x00, 0xFF, 0x00, 0xF7, // char = 203
0x14, 0x14, 0x14, 0x14, 0x14, // char = 204
0x14, 0x14, 0xF7, 0x00, 0xF7, // char = 205
0x14, 0x14, 0x14, 0x17, 0x14, // char = 206
0x10, 0x10, 0x1F, 0x10, 0x1F, // char = 207
0x14, 0x14, 0x14, 0xF4, 0x14, // char = 208
0x10, 0x10, 0xF0, 0x10, 0xF0, // char = 209
0x00, 0x00, 0x1F, 0x10, 0x1F, // char = 210
0x00, 0x00, 0x00, 0x1F, 0x14, // char = 211
0x00, 0x00, 0x00, 0xFC, 0x14, // char = 212
0x00, 0x00, 0xF0, 0x10, 0xF0, // char = 213
0x10, 0x10, 0xFF, 0x10, 0xFF, // char = 214
0x14, 0x14, 0x14, 0xFF, 0x14, // char = 215
0x10, 0x10, 0x10, 0x1F, 0x00, // char = 216
0x00, 0x00, 0x00, 0xF0, 0x10, // char = 217
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // char = 218
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, // char = 219
0xFF, 0xFF, 0xFF, 0x00, 0x00, // char = 220
0x00, 0x00, 0x00, 0xFF, 0xFF, // char = 221
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, // char = 222
0x38, 0x44, 0x44, 0x38, 0x44, // char = 223
0x7C, 0x2A, 0x2A, 0x3E, 0x14, // char = 224
0x7E, 0x02, 0x02, 0x06, 0x06, // char = 225
0x02, 0x7E, 0x02, 0x7E, 0x02, // char = 226
0x63, 0x55, 0x49, 0x41, 0x63, // char = 227
0x38, 0x44, 0x44, 0x3C, 0x04, // char = 228
0x40, 0x7E, 0x20, 0x1E, 0x20, // char = 229
0x06, 0x02, 0x7E, 0x02, 0x02, // char = 230
0x99, 0xA5, 0xE7, 0xA5, 0x99, // char = 231
0x1C, 0x2A, 0x49, 0x2A, 0x1C, // char = 232
0x4C, 0x72, 0x01, 0x72, 0x4C, // char = 233
0x30, 0x4A, 0x4D, 0x4D, 0x30, // char = 234
0x30, 0x48, 0x78, 0x48, 0x30, // char = 235
0xBC, 0x62, 0x5A, 0x46, 0x3D, // char = 236
0x3E, 0x49, 0x49, 0x49, 0x00, // char = 237
0x7E, 0x01, 0x01, 0x01, 0x7E, // char = 238
0x2A, 0x2A, 0x2A, 0x2A, 0x2A, // char = 239
0x44, 0x44, 0x5F, 0x44, 0x44, // char = 240
0x40, 0x51, 0x4A, 0x44, 0x40, // char = 241
0x40, 0x44, 0x4A, 0x51, 0x40, // char = 242
0x00, 0x00, 0xFF, 0x01, 0x03, // char = 243
0xE0, 0x80, 0xFF, 0x00, 0x00, // char = 244
0x08, 0x08, 0x6B, 0x6B, 0x08, // char = 245
0x36, 0x12, 0x36, 0x24, 0x36, // char = 246
0x06, 0x0F, 0x09, 0x0F, 0x06, // char = 247
0x00, 0x00, 0x18, 0x18, 0x00, // char = 248
0x00, 0x00, 0x10, 0x10, 0x00, // char = 249
0x30, 0x40, 0xFF, 0x01, 0x01, // char = 250
0x00, 0x1F, 0x01, 0x01, 0x1E, // char = 251
0x00, 0x19, 0x1D, 0x17, 0x12, // char = 252
0x00, 0x3C, 0x3C, 0x3C, 0x3C, // char = 253
0x00, 0x00, 0x00, 0x00, 0x00, // char = 254
};
static uint8_t ColStart, RowStart; // some displays need this changed
static uint8_t Rotation; // 0 to 3
static enum initRFlags TabColor;
static int16_t _width = ST7735_TFTWIDTH; // this could probably be a constant, except it is used in Adafruit_GFX and depends on image rotation
static int16_t _height = ST7735_TFTHEIGHT;
// The Data/Command pin must be valid when the eighth bit is
// sent. The SSI module has hardware input and output FIFOs
// that are 8 locations deep. Based on the observation that
// the LCD interface tends to send a few commands and then a
// lot of data, the FIFOs are not used when writing
// commands, and they are used when writing data. This
// ensures that the Data/Command pin status matches the byte
// that is actually being transmitted.
// The write command operation waits until all data has been
// sent, configures the Data/Command pin for commands, sends
// the command, and then waits for the transmission to
// finish.
// The write data operation waits until there is room in the
// transmit FIFO, configures the Data/Command pin for data,
// and then adds the data to the transmit FIFO.
// NOTE: These functions will crash or stall indefinitely if
// the SSI0 module is not initialized and enabled.
void writecommand(uint8_t c);
void writedata(uint8_t c);
// Subroutine to wait 1 msec
// Inputs: None
// Outputs: None
// Notes: ...
void Delay1ms(uint32_t n){uint32_t volatile time;
while(n){
time = 72724*2/91; // 1msec, tuned at 80 MHz
while(time){
time--;
}
n--;
}
}
// Rather than a bazillion writecommand() and writedata() calls, screen
// initialization commands and arguments are organized in these tables
// stored in ROM. The table may look bulky, but that's mostly the
// formatting -- storage-wise this is hundreds of bytes more compact
// than the equivalent code. Companion function follows.
#define DELAY 0x80
static const uint8_t
Bcmd[] = { // Initialization commands for 7735B screens
18, // 18 commands in list:
ST7735_SWRESET, DELAY, // 1: Software reset, no args, w/delay
50, // 50 ms delay
ST7735_SLPOUT , DELAY, // 2: Out of sleep mode, no args, w/delay
255, // 255 = 500 ms delay
ST7735_COLMOD , 1+DELAY, // 3: Set color mode, 1 arg + delay:
0x05, // 16-bit color
10, // 10 ms delay
ST7735_FRMCTR1, 3+DELAY, // 4: Frame rate control, 3 args + delay:
0x00, // fastest refresh
0x06, // 6 lines front porch
0x03, // 3 lines back porch
10, // 10 ms delay
ST7735_MADCTL , 1 , // 5: Memory access ctrl (directions), 1 arg:
0x08, // Row addr/col addr, bottom to top refresh
ST7735_DISSET5, 2 , // 6: Display settings #5, 2 args, no delay:
0x15, // 1 clk cycle nonoverlap, 2 cycle gate
// rise, 3 cycle osc equalize
0x02, // Fix on VTL
ST7735_INVCTR , 1 , // 7: Display inversion control, 1 arg:
0x0, // Line inversion
ST7735_PWCTR1 , 2+DELAY, // 8: Power control, 2 args + delay:
0x02, // GVDD = 4.7V
0x70, // 1.0uA
10, // 10 ms delay
ST7735_PWCTR2 , 1 , // 9: Power control, 1 arg, no delay:
0x05, // VGH = 14.7V, VGL = -7.35V
ST7735_PWCTR3 , 2 , // 10: Power control, 2 args, no delay:
0x01, // Opamp current small
0x02, // Boost frequency
ST7735_VMCTR1 , 2+DELAY, // 11: Power control, 2 args + delay:
0x3C, // VCOMH = 4V
0x38, // VCOML = -1.1V
10, // 10 ms delay
ST7735_PWCTR6 , 2 , // 12: Power control, 2 args, no delay:
0x11, 0x15,
ST7735_GMCTRP1,16 , // 13: Magical unicorn dust, 16 args, no delay:
0x09, 0x16, 0x09, 0x20, // (seriously though, not sure what
0x21, 0x1B, 0x13, 0x19, // these config values represent)
0x17, 0x15, 0x1E, 0x2B,
0x04, 0x05, 0x02, 0x0E,
ST7735_GMCTRN1,16+DELAY, // 14: Sparkles and rainbows, 16 args + delay:
0x0B, 0x14, 0x08, 0x1E, // (ditto)
0x22, 0x1D, 0x18, 0x1E,
0x1B, 0x1A, 0x24, 0x2B,
0x06, 0x06, 0x02, 0x0F,
10, // 10 ms delay
ST7735_CASET , 4 , // 15: Column addr set, 4 args, no delay:
0x00, 0x02, // XSTART = 2
0x00, 0x81, // XEND = 129
ST7735_RASET , 4 , // 16: Row addr set, 4 args, no delay:
0x00, 0x02, // XSTART = 1
0x00, 0x81, // XEND = 160
ST7735_NORON , DELAY, // 17: Normal display on, no args, w/delay
10, // 10 ms delay
ST7735_DISPON , DELAY, // 18: Main screen turn on, no args, w/delay
255 }; // 255 = 500 ms delay
static const uint8_t
Rcmd1[] = { // Init for 7735R, part 1 (red or green tab)
15, // 15 commands in list:
ST7735_SWRESET, DELAY, // 1: Software reset, 0 args, w/delay
150, // 150 ms delay
ST7735_SLPOUT , DELAY, // 2: Out of sleep mode, 0 args, w/delay
255, // 500 ms delay
ST7735_FRMCTR1, 3 , // 3: Frame rate ctrl - normal mode, 3 args:
0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D)
ST7735_FRMCTR2, 3 , // 4: Frame rate control - idle mode, 3 args:
0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D)
ST7735_FRMCTR3, 6 , // 5: Frame rate ctrl - partial mode, 6 args:
0x01, 0x2C, 0x2D, // Dot inversion mode
0x01, 0x2C, 0x2D, // Line inversion mode
ST7735_INVCTR , 1 , // 6: Display inversion ctrl, 1 arg, no delay:
0x07, // No inversion
ST7735_PWCTR1 , 3 , // 7: Power control, 3 args, no delay:
0xA2,
0x02, // -4.6V
0x84, // AUTO mode
ST7735_PWCTR2 , 1 , // 8: Power control, 1 arg, no delay:
0xC5, // VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD
ST7735_PWCTR3 , 2 , // 9: Power control, 2 args, no delay:
0x0A, // Opamp current small
0x00, // Boost frequency
ST7735_PWCTR4 , 2 , // 10: Power control, 2 args, no delay:
0x8A, // BCLK/2, Opamp current small & Medium low
0x2A,
ST7735_PWCTR5 , 2 , // 11: Power control, 2 args, no delay:
0x8A, 0xEE,
ST7735_VMCTR1 , 1 , // 12: Power control, 1 arg, no delay:
0x0E,
ST7735_INVOFF , 0 , // 13: Don't invert display, no args, no delay
ST7735_MADCTL , 1 , // 14: Memory access control (directions), 1 arg:
0xC8, // row addr/col addr, bottom to top refresh
ST7735_COLMOD , 1 , // 15: set color mode, 1 arg, no delay:
0x05 }; // 16-bit color
static const uint8_t
Rcmd2green[] = { // Init for 7735R, part 2 (green tab only)
2, // 2 commands in list:
ST7735_CASET , 4 , // 1: Column addr set, 4 args, no delay:
0x00, 0x02, // XSTART = 0
0x00, 0x7F+0x02, // XEND = 127
ST7735_RASET , 4 , // 2: Row addr set, 4 args, no delay:
0x00, 0x01, // XSTART = 0
0x00, 0x9F+0x01 }; // XEND = 159
static const uint8_t
Rcmd2red[] = { // Init for 7735R, part 2 (red tab only)
2, // 2 commands in list:
ST7735_CASET , 4 , // 1: Column addr set, 4 args, no delay:
0x00, 0x00, // XSTART = 0
0x00, 0x7F, // XEND = 127
ST7735_RASET , 4 , // 2: Row addr set, 4 args, no delay:
0x00, 0x00, // XSTART = 0
0x00, 0x9F }; // XEND = 159
static const uint8_t
Rcmd3[] = { // Init for 7735R, part 3 (red or green tab)
4, // 4 commands in list:
ST7735_GMCTRP1, 16 , // 1: Magical unicorn dust, 16 args, no delay:
0x02, 0x1c, 0x07, 0x12,
0x37, 0x32, 0x29, 0x2d,
0x29, 0x25, 0x2B, 0x39,
0x00, 0x01, 0x03, 0x10,
ST7735_GMCTRN1, 16 , // 2: Sparkles and rainbows, 16 args, no delay:
0x03, 0x1d, 0x07, 0x06,
0x2E, 0x2C, 0x29, 0x2D,
0x2E, 0x2E, 0x37, 0x3F,
0x00, 0x00, 0x02, 0x10,
ST7735_NORON , DELAY, // 3: Normal display on, no args, w/delay
10, // 10 ms delay
ST7735_DISPON , DELAY, // 4: Main screen turn on, no args w/delay
100 }; // 100 ms delay
// Companion code to the above tables. Reads and issues
// a series of LCD commands stored in ROM byte array.
void static commandList(const uint8_t *addr) {
uint8_t numCommands, numArgs;
uint16_t ms;
numCommands = *(addr++); // Number of commands to follow
while(numCommands--) { // For each command...
writecommand(*(addr++)); // Read, issue command
numArgs = *(addr++); // Number of args to follow
ms = numArgs & DELAY; // If hibit set, delay follows args
numArgs &= ~DELAY; // Mask out delay bit
while(numArgs--) { // For each argument...
writedata(*(addr++)); // Read, issue argument
}
if(ms) {
ms = *(addr++); // Read post-command delay time (ms)
if(ms == 255) ms = 500; // If 255, delay for 500 ms
Delay1ms(ms);
}
}
}
// Initialization code common to both 'B' and 'R' type displays
void static commonInit(const uint8_t *cmdList) {
volatile uint32_t delay;
ColStart = RowStart = 0; // May be overridden in init func
SYSCTL_RCGCSSI_R |= 0x01; // activate SSI0
SYSCTL_RCGCGPIO_R |= 0x01; // activate port A
while((SYSCTL_PRGPIO_R&0x01)==0){}; // allow time for clock to start
// toggle RST low to reset; CS low so it'll listen to us
// SSI0Fss is temporarily used as GPIO
GPIO_PORTA_DIR_R |= 0xC8; // make PA3,6,7 out
GPIO_PORTA_AFSEL_R &= ~0xC8; // disable alt funct on PA3,6,7
GPIO_PORTA_DEN_R |= 0xC8; // enable digital I/O on PA3,6,7
// configure PA3,6,7 as GPIO
GPIO_PORTA_PCTL_R = (GPIO_PORTA_PCTL_R&0x00FF0FFF)+0x00000000;
GPIO_PORTA_AMSEL_R &= ~0xC8; // disable analog functionality on PA3,6,7
TFT_CS = TFT_CS_LOW;
RESET = RESET_HIGH;
Delay1ms(500);
RESET = RESET_LOW;
Delay1ms(500);
RESET = RESET_HIGH;
Delay1ms(500);
// initialize SSI0
GPIO_PORTA_AFSEL_R |= 0x2C; // enable alt funct on PA2,3,5
GPIO_PORTA_DEN_R |= 0x2C; // enable digital I/O on PA2,3,5
// configure PA2,3,5 as SSI
GPIO_PORTA_PCTL_R = (GPIO_PORTA_PCTL_R&0xFF0F00FF)+0x00202200;
GPIO_PORTA_AMSEL_R &= ~0x2C; // disable analog functionality on PA2,3,5
SSI0_CR1_R &= ~SSI_CR1_SSE; // disable SSI
SSI0_CR1_R &= ~SSI_CR1_MS; // master mode
// configure for system clock/PLL baud clock source
SSI0_CC_R = (SSI0_CC_R&~SSI_CC_CS_M)+SSI_CC_CS_SYSPLL;
// // clock divider for 3.125 MHz SSIClk (50 MHz PIOSC/16)
// SSI0_CPSR_R = (SSI0_CPSR_R&~SSI_CPSR_CPSDVSR_M)+16;
// clock divider for 8 MHz SSIClk (80 MHz PLL/24)
// SysClk/(CPSDVSR*(1+SCR))
// 80/(10*(1+0)) = 8 MHz (slower than 4 MHz)
SSI0_CPSR_R = (SSI0_CPSR_R&~SSI_CPSR_CPSDVSR_M)+10; // must be even number
SSI0_CR0_R &= ~(SSI_CR0_SCR_M | // SCR = 0 (8 Mbps data rate)
SSI_CR0_SPH | // SPH = 0
SSI_CR0_SPO); // SPO = 0
// FRF = Freescale format
SSI0_CR0_R = (SSI0_CR0_R&~SSI_CR0_FRF_M)+SSI_CR0_FRF_MOTO;
// DSS = 8-bit data
SSI0_CR0_R = (SSI0_CR0_R&~SSI_CR0_DSS_M)+SSI_CR0_DSS_8;
SSI0_CR1_R |= SSI_CR1_SSE; // enable SSI
if(cmdList) commandList(cmdList);
}
//------------ST7735_InitB------------
// Initialization for ST7735B screens.
// Input: none
// Output: none
void ST7735_InitB(void) {
commonInit(Bcmd);
ST7735_SetCursor(0,0);
StTextColor = ST7735_YELLOW;
ST7735_FillScreen(0); // set screen to black
}
//------------ST7735_InitR------------
// Initialization for ST7735R screens (green or red tabs).
// Input: option one of the enumerated options depending on tabs
// Output: none
void ST7735_InitR(enum initRFlags option) {
commonInit(Rcmd1);
if(option == INITR_GREENTAB) {
commandList(Rcmd2green);
ColStart = 2;
RowStart = 1;
} else {
// colstart, rowstart left at default '0' values
commandList(Rcmd2red);
}
commandList(Rcmd3);
// if black, change MADCTL color filter
if (option == INITR_BLACKTAB) {
writecommand(ST7735_MADCTL);
writedata(0xC0);
}
TabColor = option;
ST7735_SetCursor(0,0);
StTextColor = ST7735_YELLOW;
ST7735_FillScreen(0); // set screen to black
}
// Set the region of the screen RAM to be modified
// Pixel colors are sent left to right, top to bottom
// (same as Font table is encoded; different from regular bitmap)
// Requires 11 bytes of transmission
void static setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) {
writecommand(ST7735_CASET); // Column addr set
writedata(0x00);
writedata(x0+ColStart); // XSTART
writedata(0x00);
writedata(x1+ColStart); // XEND
writecommand(ST7735_RASET); // Row addr set
writedata(0x00);
writedata(y0+RowStart); // YSTART
writedata(0x00);
writedata(y1+RowStart); // YEND
writecommand(ST7735_RAMWR); // write to RAM
}
// Send two bytes of data, most significant byte first
// Requires 2 bytes of transmission
void static pushColor(uint16_t color) {
writedata((uint8_t)(color >> 8));
writedata((uint8_t)color);
}
//------------ST7735_DrawPixel------------
// Color the pixel at the given coordinates with the given color.
// Requires 13 bytes of transmission
// Input: x horizontal position of the pixel, columns from the left edge
// must be less than 128
// 0 is on the left, 126 is near the right
// y vertical position of the pixel, rows from the top edge
// must be less than 160
// 159 is near the wires, 0 is the side opposite the wires
// color 16-bit color, which can be produced by ST7735_Color565()
// Output: none
void ST7735_DrawPixel(int16_t x, int16_t y, uint16_t color) {
if((x < 0) || (x >= _width) || (y < 0) || (y >= _height)) return;
// setAddrWindow(x,y,x+1,y+1); // original code, bug???
setAddrWindow(x,y,x,y);
pushColor(color);
}
//------------ST7735_DrawFastVLine------------
// Draw a vertical line at the given coordinates with the given height and color.
// A vertical line is parallel to the longer side of the rectangular display
// Requires (11 + 2*h) bytes of transmission (assuming image fully on screen)
// Input: x horizontal position of the start of the line, columns from the left edge
// y vertical position of the start of the line, rows from the top edge
// h vertical height of the line
// color 16-bit color, which can be produced by ST7735_Color565()
// Output: none
void ST7735_DrawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) {
uint8_t hi = color >> 8, lo = color;
// Rudimentary clipping
if((x >= _width) || (y >= _height)) return;
if((y+h-1) >= _height) h = _height-y;
setAddrWindow(x, y, x, y+h-1);
while (h--) {
writedata(hi);
writedata(lo);
}
}
//------------ST7735_DrawFastHLine------------
// Draw a horizontal line at the given coordinates with the given width and color.
// A horizontal line is parallel to the shorter side of the rectangular display
// Requires (11 + 2*w) bytes of transmission (assuming image fully on screen)
// Input: x horizontal position of the start of the line, columns from the left edge
// y vertical position of the start of the line, rows from the top edge
// w horizontal width of the line
// color 16-bit color, which can be produced by ST7735_Color565()
// Output: none
void ST7735_DrawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) {
uint8_t hi = color >> 8, lo = color;
// Rudimentary clipping
if((x >= _width) || (y >= _height)) return;
if((x+w-1) >= _width) w = _width-x;
setAddrWindow(x, y, x+w-1, y);
while (w--) {
writedata(hi);
writedata(lo);
}
}
//------------ST7735_FillScreen------------
// Fill the screen with the given color.
// Requires 40,971 bytes of transmission
// Input: color 16-bit color, which can be produced by ST7735_Color565()
// Output: none
void ST7735_FillScreen(uint16_t color) {
ST7735_FillRect(0, 0, _width, _height, color); // original
// screen is actually 129 by 161 pixels, x 0 to 128, y goes from 0 to 160
}
//------------ST7735_FillRect------------
// Draw a filled rectangle at the given coordinates with the given width, height, and color.
// Requires (11 + 2*w*h) bytes of transmission (assuming image fully on screen)
// Input: x horizontal position of the top left corner of the rectangle, columns from the left edge
// y vertical position of the top left corner of the rectangle, rows from the top edge
// w horizontal width of the rectangle
// h vertical height of the rectangle
// color 16-bit color, which can be produced by ST7735_Color565()
// Output: none
void ST7735_FillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) {
uint8_t hi = color >> 8, lo = color;
// rudimentary clipping (drawChar w/big text requires this)
if((x >= _width) || (y >= _height)) return;
if((x + w - 1) >= _width) w = _width - x;
if((y + h - 1) >= _height) h = _height - y;
setAddrWindow(x, y, x+w-1, y+h-1);
for(y=h; y>0; y--) {
for(x=w; x>0; x--) {
writedata(hi);
writedata(lo);
}
}
}
void static deselect(void) {
// wait until SSI0 not busy/transmit FIFO empty
while((SSI0_SR_R&SSI_SR_BSY)==SSI_SR_BSY){};
TFT_CS = TFT_CS_HIGH;
}
//------------ST7735_DrawSmallCircle------------
// Draw a small circle (diameter of 6 pixels)
// rectangle at the given coordinates with the given color.
// Requires (11*6+24*2)=114 bytes of transmission (assuming image on screen)
// Input: x horizontal position of the top left corner of the circle, columns from the left edge
// y vertical position of the top left corner of the circle, rows from the top edge
// color 16-bit color, which can be produced by ST7735_Color565()
// Output: none
int16_t const smallCircle[6][3]={
{2,3, 2},
{1 , 4, 4},
{0 , 5, 6},
{0 , 5, 6},
{1 , 4, 4},
{2,3, 2}};
void ST7735_DrawSmallCircle(int16_t x, int16_t y, uint16_t color) {
uint32_t i,w;
uint8_t hi = color >> 8, lo = color;
// rudimentary clipping
if((x>_width-5)||(y>_height-5)) return; // doesn't fit
for(i=0; i<6; i++){
setAddrWindow(x+smallCircle[i][0], y+i, x+smallCircle[i][1], y+i);
w = smallCircle[i][2];
while (w--) {
writedata(hi);
writedata(lo);
}
}
deselect();
}
//------------ST7735_DrawCircle------------
// Draw a small circle (diameter of 10 pixels)
// rectangle at the given coordinates with the given color.
// Requires (11*10+68*2)=178 bytes of transmission (assuming image on screen)
// Input: x horizontal position of the top left corner of the circle, columns from the left edge
// y vertical position of the top left corner of the circle, rows from the top edge
// color 16-bit color, which can be produced by ST7735_Color565()
// Output: none
int16_t const circle[10][3]={
{ 4,5, 2},
{2 , 7, 6},
{1 , 8, 8},
{1 , 8, 8},
{0 , 9, 10},
{0 , 9, 10},
{1 , 8, 8},
{1 , 8, 8},
{2 , 7, 6},
{ 4,5, 2}};
void ST7735_DrawCircle(int16_t x, int16_t y, uint16_t color) {
uint32_t i,w;