Skip to content

Commit b55666b

Browse files
committed
Create gc9a01a.py
1 parent 197da2c commit b55666b

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed

adafruit_rgb_display/gc9a01a.py

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
"""
5+
`adafruit_rgb_display.gc9a01a`
6+
====================================================
7+
A simple driver for the GC9A01A-based displays.
8+
9+
* Author(s): Liz Clark
10+
11+
Implementation Notes
12+
--------------------
13+
Adapted from the CircuitPython GC9A01A driver for use with the RGB Display library.
14+
"""
15+
import struct
16+
import busio
17+
import digitalio
18+
from micropython import const
19+
from adafruit_rgb_display.rgb import DisplaySPI
20+
21+
try:
22+
from typing import Optional
23+
except ImportError:
24+
pass
25+
26+
__version__ = "0.0.0+auto.0"
27+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display.git"
28+
29+
# Command constants
30+
_NOP = const(0x00)
31+
_SWRESET = const(0x01)
32+
_SLPIN = const(0x10)
33+
_SLPOUT = const(0x11)
34+
_PTLON = const(0x12)
35+
_NORON = const(0x13)
36+
_INVOFF = const(0x20)
37+
_INVON = const(0x21)
38+
_DISPOFF = const(0x28)
39+
_DISPON = const(0x29)
40+
_CASET = const(0x2A)
41+
_RASET = const(0x2B)
42+
_RAMWR = const(0x2C)
43+
_RAMRD = const(0x2E)
44+
_MADCTL = const(0x36)
45+
_COLMOD = const(0x3A)
46+
_TEON = const(0x35)
47+
48+
# Extended command constants
49+
_PWCTR1 = const(0xC3)
50+
_PWCTR2 = const(0xC4)
51+
_PWCTR3 = const(0xC9)
52+
_GMCTRP1 = const(0xF0)
53+
_GMCTRN1 = const(0xF1)
54+
_GMCTRP2 = const(0xF2)
55+
_GMCTRN2 = const(0xF3)
56+
57+
class GC9A01A(DisplaySPI):
58+
"""
59+
A simple driver for the GC9A01A-based displays.
60+
61+
>>> import busio
62+
>>> import digitalio
63+
>>> import board
64+
>>> from adafruit_rgb_display import color565
65+
>>> import adafruit_rgb_display.gc9a01a as gc9a01a
66+
>>> spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
67+
>>> display = gc9a01a.GC9A01A(spi, cs=digitalio.DigitalInOut(board.GPIO0),
68+
... dc=digitalio.DigitalInOut(board.GPIO15), rst=digitalio.DigitalInOut(board.GPIO16))
69+
>>> display.fill(0x7521)
70+
>>> display.pixel(64, 64, 0)
71+
"""
72+
# pylint: disable=too-few-public-methods
73+
74+
COLUMN_SET = _CASET
75+
PAGE_SET = _RASET
76+
RAM_WRITE = _RAMWR
77+
RAM_READ = _RAMRD
78+
79+
_INIT = (
80+
(_SWRESET, None),
81+
(0xFE, None), # Inter Register Enable1
82+
(0xEF, None), # Inter Register Enable2
83+
(0xB6, b"\x00\x00"), # Display Function Control
84+
(_MADCTL, b"\x48"), # Memory Access Control
85+
(_COLMOD, b"\x05"), # Interface Pixel Format (16 bits/pixel)
86+
(_PWCTR1, b"\x13"), # Power Control 2
87+
(_PWCTR2, b"\x13"), # Power Control 3
88+
(_PWCTR3, b"\x22"), # Power Control 4
89+
(_GMCTRP1, b"\x45\x09\x08\x08\x26\x2a"), # Set Gamma 1
90+
(_GMCTRN1, b"\x43\x70\x72\x36\x37\x6f"), # Set Gamma 2
91+
(_GMCTRP2, b"\x45\x09\x08\x08\x26\x2a"), # Set Gamma 3
92+
(_GMCTRN2, b"\x43\x70\x72\x36\x37\x6f"), # Set Gamma 4
93+
(0x66, b"\x3c\x00\xcd\x67\x45\x45\x10\x00\x00\x00"),
94+
(0x67, b"\x00\x3c\x00\x00\x00\x01\x54\x10\x32\x98"),
95+
(0x74, b"\x10\x85\x80\x00\x00\x4e\x00"),
96+
(0x98, b"\x3e\x07"),
97+
(_TEON, None), # Tearing Effect Line ON
98+
(_INVON, None), # Display Inversion ON
99+
(_SLPOUT, None), # Exit Sleep Mode
100+
(_NORON, None), # Normal Display Mode ON
101+
(_DISPON, None), # Display ON
102+
)
103+
104+
def __init__(
105+
self,
106+
spi: busio.SPI,
107+
dc: digitalio.DigitalInOut,
108+
cs: digitalio.DigitalInOut,
109+
rst: Optional[digitalio.DigitalInOut] = None,
110+
width: int = 240,
111+
height: int = 240,
112+
baudrate: int = 16000000,
113+
polarity: int = 0,
114+
phase: int = 0,
115+
*,
116+
x_offset: int = 0,
117+
y_offset: int = 0,
118+
rotation: int = 0
119+
) -> None:
120+
super().__init__(
121+
spi,
122+
dc,
123+
cs,
124+
rst,
125+
width,
126+
height,
127+
baudrate=baudrate,
128+
polarity=polarity,
129+
phase=phase,
130+
x_offset=x_offset,
131+
y_offset=y_offset,
132+
rotation=rotation,
133+
)
134+
135+
def init(self) -> None:
136+
super().init()
137+
cols = struct.pack(">HH", 0, self.width - 1)
138+
rows = struct.pack(">HH", 0, self.height - 1)
139+
140+
for command, data in (
141+
(_CASET, cols),
142+
(_RASET, rows),
143+
(_MADCTL, b"\xc0"), # Set rotation to 0 and use RGB
144+
):
145+
self.write(command, data)

0 commit comments

Comments
 (0)