Skip to content

Commit 9f02995

Browse files
committed
pre-commit, tested
1 parent 67547fa commit 9f02995

File tree

1 file changed

+39
-68
lines changed

1 file changed

+39
-68
lines changed

adafruit_rgb_display/gc9a01a.py

+39-68
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
99
* Author(s): Liz Clark
1010
11-
Implementation Notes
12-
--------------------
13-
Adapted from the CircuitPython GC9A01A driver for use with the RGB Display library.
1411
"""
12+
1513
import struct
14+
import time
1615
import busio
1716
import digitalio
1817
from micropython import const
@@ -26,15 +25,9 @@
2625
__version__ = "0.0.0+auto.0"
2726
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display.git"
2827

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)
3831
_NORON = const(0x13)
3932
_INVOFF = const(0x20)
4033
_INVON = const(0x21)
@@ -46,16 +39,7 @@
4639
_RAMRD = const(0x2E)
4740
_MADCTL = const(0x36)
4841
_COLMOD = const(0x3A)
49-
_TEON = const(0x35)
5042

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)
5943

6044
class GC9A01A(DisplaySPI):
6145
"""
@@ -64,42 +48,40 @@ class GC9A01A(DisplaySPI):
6448
>>> import busio
6549
>>> import digitalio
6650
>>> import board
67-
>>> from adafruit_rgb_display import color565
68-
>>> import adafruit_rgb_display.gc9a01a as gc9a01a
51+
>>> from adafruit_rgb_display import gc9a01a
6952
>>> 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))
7255
>>> display.fill(0x7521)
7356
>>> display.pixel(64, 64, 0)
7457
"""
75-
# pylint: disable=too-few-public-methods
76-
77-
COLUMN_SET = _CASET
78-
PAGE_SET = _RASET
79-
RAM_WRITE = _RAMWR
80-
RAM_READ = _RAMRD
8158

59+
_COLUMN_SET = _CASET
60+
_PAGE_SET = _RASET
61+
_RAM_WRITE = _RAMWR
62+
_RAM_READ = _RAMRD
8263
_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
9576
(0x66, b"\x3c\x00\xcd\x67\x45\x45\x10\x00\x00\x00"),
9677
(0x67, b"\x00\x3c\x00\x00\x00\x01\x54\x10\x32\x98"),
9778
(0x74, b"\x10\x85\x80\x00\x00\x4e\x00"),
9879
(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
10385
)
10486

10587
def __init__(
@@ -110,7 +92,7 @@ def __init__(
11092
rst: Optional[digitalio.DigitalInOut] = None,
11193
width: int = 240,
11294
height: int = 240,
113-
baudrate: int = 16000000,
95+
baudrate: int = 24000000,
11496
polarity: int = 0,
11597
phase: int = 0,
11698
*,
@@ -134,24 +116,13 @@ def __init__(
134116
)
135117

136118
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+
137126
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

Comments
 (0)