-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathgc9a01a.py
126 lines (113 loc) · 3.55 KB
/
gc9a01a.py
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
# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
`adafruit_rgb_display.gc9a01a`
====================================================
A simple driver for the GC9A01A-based displays.
* Author(s): Liz Clark
"""
import time
import busio
import digitalio
from micropython import const
from adafruit_rgb_display.rgb import DisplaySPI
try:
from typing import Optional
except ImportError:
pass
__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display.git"
# Command constants
_SWRESET = const(0xFE)
_SLPOUT = const(0x11)
_NORON = const(0x13)
_INVOFF = const(0x20)
_INVON = const(0x21)
_DISPOFF = const(0x28)
_DISPON = const(0x29)
_CASET = const(0x2A)
_RASET = const(0x2B)
_RAMWR = const(0x2C)
_RAMRD = const(0x2E)
_MADCTL = const(0x36)
_COLMOD = const(0x3A)
class GC9A01A(DisplaySPI):
"""
A simple driver for the GC9A01A-based displays.
>>> import busio
>>> import digitalio
>>> import board
>>> from adafruit_rgb_display import gc9a01a
>>> spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
>>> display = gc9a01a.GC9A01A(spi, cs=digitalio.DigitalInOut(board.CE0),
... dc=digitalio.DigitalInOut(board.D25), rst=digitalio.DigitalInOut(board.D27))
>>> display.fill(0x7521)
>>> display.pixel(64, 64, 0)
"""
_COLUMN_SET = _CASET
_PAGE_SET = _RASET
_RAM_WRITE = _RAMWR
_RAM_READ = _RAMRD
_INIT = (
(_SWRESET, None),
(0xEF, None), # Inter Register Enable2
(0xB6, b"\x00\x00"), # Display Function Control
(_MADCTL, b"\x48"), # Memory Access Control - Set to BGR color filter panel
(_COLMOD, b"\x05"), # Interface Pixel Format - 16 bits per pixel
(0xC3, b"\x13"), # Power Control 2
(0xC4, b"\x13"), # Power Control 3
(0xC9, b"\x22"), # Power Control 4
(0xF0, b"\x45\x09\x08\x08\x26\x2a"), # SET_GAMMA1
(0xF1, b"\x43\x70\x72\x36\x37\x6f"), # SET_GAMMA2
(0xF2, b"\x45\x09\x08\x08\x26\x2a"), # SET_GAMMA3
(0xF3, b"\x43\x70\x72\x36\x37\x6f"), # SET_GAMMA4
(0x66, b"\x3c\x00\xcd\x67\x45\x45\x10\x00\x00\x00"),
(0x67, b"\x00\x3c\x00\x00\x00\x01\x54\x10\x32\x98"),
(0x74, b"\x10\x85\x80\x00\x00\x4e\x00"),
(0x98, b"\x3e\x07"),
(0x35, None), # Tearing Effect Line ON
(_INVON, None), # Display Inversion ON
(_SLPOUT, None), # Sleep Out Mode
(_NORON, None), # Normal Display Mode ON
(_DISPON, None), # Display ON
)
# pylint: disable-msg=useless-super-delegation, too-many-arguments
def __init__(
self,
spi: busio.SPI,
dc: digitalio.DigitalInOut,
cs: digitalio.DigitalInOut,
rst: Optional[digitalio.DigitalInOut] = None,
width: int = 240,
height: int = 240,
baudrate: int = 24000000,
polarity: int = 0,
phase: int = 0,
*,
x_offset: int = 0,
y_offset: int = 0,
rotation: int = 0
) -> None:
super().__init__(
spi,
dc,
cs,
rst,
width,
height,
baudrate=baudrate,
polarity=polarity,
phase=phase,
x_offset=x_offset,
y_offset=y_offset,
rotation=rotation,
)
def init(self) -> None:
"""Initialize the display."""
if self.rst:
self.rst.value = 0
time.sleep(0.05)
self.rst.value = 1
time.sleep(0.05)
super().init()