8
8
9
9
* Author(s): Liz Clark
10
10
11
- Implementation Notes
12
- --------------------
13
- Adapted from the CircuitPython GC9A01A driver for use with the RGB Display library.
14
11
"""
12
+
15
13
import struct
14
+ import time
16
15
import busio
17
16
import digitalio
18
17
from micropython import const
26
25
__version__ = "0.0.0+auto.0"
27
26
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display.git"
28
27
29
- # Constants for MADCTL
30
- _MADCTL_MY = const (0x80 ) # Bottom to top
31
- _MADCTL_MX = const (0x40 ) # Right to left
32
- _MADCTL_MV = const (0x20 ) # Reverse Mode
33
- _MADCTL_ML = const (0x10 ) # LCD refresh Bottom to top
34
- _MADCTL_RGB = const (0x00 ) # Red-Green-Blue pixel order
35
- _MADCTL_BGR = const (0x08 ) # Blue-Green-Red pixel order
36
- _MADCTL_MH = const (0x04 ) # LCD refresh right to left
37
- _PTLON = const (0x12 )
28
+ # Command constants
29
+ _SWRESET = const (0xFE )
30
+ _SLPOUT = const (0x11 )
38
31
_NORON = const (0x13 )
39
32
_INVOFF = const (0x20 )
40
33
_INVON = const (0x21 )
46
39
_RAMRD = const (0x2E )
47
40
_MADCTL = const (0x36 )
48
41
_COLMOD = const (0x3A )
49
- _TEON = const (0x35 )
50
42
51
- # Extended command constants
52
- _PWCTR1 = const (0xC3 )
53
- _PWCTR2 = const (0xC4 )
54
- _PWCTR3 = const (0xC9 )
55
- _GMCTRP1 = const (0xF0 )
56
- _GMCTRN1 = const (0xF1 )
57
- _GMCTRP2 = const (0xF2 )
58
- _GMCTRN2 = const (0xF3 )
59
43
60
44
class GC9A01A (DisplaySPI ):
61
45
"""
@@ -64,42 +48,40 @@ class GC9A01A(DisplaySPI):
64
48
>>> import busio
65
49
>>> import digitalio
66
50
>>> import board
67
- >>> from adafruit_rgb_display import color565
68
- >>> import adafruit_rgb_display.gc9a01a as gc9a01a
51
+ >>> from adafruit_rgb_display import gc9a01a
69
52
>>> spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
70
- >>> display = gc9a01a.GC9A01A(spi, cs=digitalio.DigitalInOut(board.GPIO0 ),
71
- ... dc=digitalio.DigitalInOut(board.GPIO15 ), rst=digitalio.DigitalInOut(board.GPIO16 ))
53
+ >>> display = gc9a01a.GC9A01A(spi, cs=digitalio.DigitalInOut(board.CE0 ),
54
+ ... dc=digitalio.DigitalInOut(board.D25 ), rst=digitalio.DigitalInOut(board.D27 ))
72
55
>>> display.fill(0x7521)
73
56
>>> display.pixel(64, 64, 0)
74
57
"""
75
- # pylint: disable=too-few-public-methods
76
-
77
- COLUMN_SET = _CASET
78
- PAGE_SET = _RASET
79
- RAM_WRITE = _RAMWR
80
- RAM_READ = _RAMRD
81
58
59
+ _COLUMN_SET = _CASET
60
+ _PAGE_SET = _RASET
61
+ _RAM_WRITE = _RAMWR
62
+ _RAM_READ = _RAMRD
82
63
_INIT = (
83
- (0xFE , b" \x00 " ), # Inter Register Enable1
84
- (0xEF , b" \x00 " ), # Inter Register Enable2
85
- (0xB6 , b"\x00 \x00 " ), # Display Function Control [S1→S360 source, G1→G32 gate]
86
- (_MADCTL , b"\x48 " ), # Memory Access Control [Invert Row order, invert vertical scan order]
87
- (_COLMOD , b"\x05 " ), # COLMOD: Pixel Format Set [ 16 bits/ pixel]
88
- (_PWCTR1 , b"\x13 " ), # Power Control 2 [VREG1A = 5.06, VREG1B = 0.68]
89
- (_PWCTR2 , b"\x13 " ), # Power Control 3 [VREG2A = -3.7, VREG2B = 0.68]
90
- (_PWCTR3 , b"\x22 " ), # Power Control 4
91
- (_GMCTRP1 , b"\x45 \x09 \x08 \x08 \x26 \x2a " ), # SET_GAMMA1
92
- (_GMCTRN1 , b"\x43 \x70 \x72 \x36 \x37 \x6f " ), # SET_GAMMA2
93
- (_GMCTRP2 , b"\x45 \x09 \x08 \x08 \x26 \x2a " ), # SET_GAMMA3
94
- (_GMCTRN2 , b"\x43 \x70 \x72 \x36 \x37 \x6f " ), # SET_GAMMA4
64
+ (_SWRESET , None ),
65
+ (0xEF , None ), # Inter Register Enable2
66
+ (0xB6 , b"\x00 \x00 " ), # Display Function Control
67
+ (_MADCTL , b"\x48 " ), # Memory Access Control - Set to BGR color filter panel
68
+ (_COLMOD , b"\x05 " ), # Interface Pixel Format - 16 bits per pixel
69
+ (0xC3 , b"\x13 " ), # Power Control 2
70
+ (0xC4 , b"\x13 " ), # Power Control 3
71
+ (0xC9 , b"\x22 " ), # Power Control 4
72
+ (0xF0 , b"\x45 \x09 \x08 \x08 \x26 \x2a " ), # SET_GAMMA1
73
+ (0xF1 , b"\x43 \x70 \x72 \x36 \x37 \x6f " ), # SET_GAMMA2
74
+ (0xF2 , b"\x45 \x09 \x08 \x08 \x26 \x2a " ), # SET_GAMMA3
75
+ (0xF3 , b"\x43 \x70 \x72 \x36 \x37 \x6f " ), # SET_GAMMA4
95
76
(0x66 , b"\x3c \x00 \xcd \x67 \x45 \x45 \x10 \x00 \x00 \x00 " ),
96
77
(0x67 , b"\x00 \x3c \x00 \x00 \x00 \x01 \x54 \x10 \x32 \x98 " ),
97
78
(0x74 , b"\x10 \x85 \x80 \x00 \x00 \x4e \x00 " ),
98
79
(0x98 , b"\x3e \x07 " ),
99
- (_TEON , b"\x00 " ), # Tearing Effect Line ON [both V-blanking and H-blanking]
100
- (_INVON , b"\x00 " ), # Display Inversion ON
101
- (_SLPOUT , None ), # Sleep Out Mode (with 120ms delay)
102
- (_DISPON , None ), # Display ON (with 20ms delay)
80
+ (0x35 , None ), # Tearing Effect Line ON
81
+ (_INVON , None ), # Display Inversion ON
82
+ (_SLPOUT , None ), # Sleep Out Mode
83
+ (_NORON , None ), # Normal Display Mode ON
84
+ (_DISPON , None ), # Display ON
103
85
)
104
86
105
87
def __init__ (
@@ -110,7 +92,7 @@ def __init__(
110
92
rst : Optional [digitalio .DigitalInOut ] = None ,
111
93
width : int = 240 ,
112
94
height : int = 240 ,
113
- baudrate : int = 16000000 ,
95
+ baudrate : int = 24000000 ,
114
96
polarity : int = 0 ,
115
97
phase : int = 0 ,
116
98
* ,
@@ -134,24 +116,13 @@ def __init__(
134
116
)
135
117
136
118
def init (self ) -> None :
119
+ """Initialize the display."""
120
+ if self .rst :
121
+ self .rst .value = 0
122
+ time .sleep (0.05 )
123
+ self .rst .value = 1
124
+ time .sleep (0.05 )
125
+
137
126
super ().init ()
138
- # Account for offsets in the column and row addressing
139
- cols = struct .pack (">HH" , self ._X_START , self .width + self ._X_START - 1 )
140
- rows = struct .pack (">HH" , self ._Y_START , self .height + self ._Y_START - 1 )
141
-
142
- def init (self ) -> None :
143
- """Initialize the display"""
144
- super ().init ()
145
-
146
- # Initialize display
147
- self .write (_SWRESET )
148
- time .sleep (0.150 ) # 150ms delay after reset
149
-
150
- # Set addressing mode and color format
151
- self .write (_MADCTL , bytes ([_MADCTL_MX | _MADCTL_BGR ]))
152
-
153
- # Set addressing windows
154
- self .write (_CASET , b"\x00 \x00 \x00 \xef " ) # Column Address Set [0-239]
155
- self .write (_RASET , b"\x00 \x00 \x00 \xef " ) # Row Address Set [0-239]
156
-
157
- time .sleep (0.150 ) # 150ms delay before turning on display
127
+
128
+ self ._block (0 , 0 , self .width - 1 , self .height - 1 )
0 commit comments