-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathhx8357.py
executable file
·127 lines (116 loc) · 3.49 KB
/
hx8357.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
127
# SPDX-FileCopyrightText: 2019 Melissa LeBlanc-Williams for Adafruit Industries
# SPDX-FileCopyrightText: 2023 Matt Land
#
# SPDX-License-Identifier: MIT
"""
`adafruit_rgb_display.hx8357`
====================================================
A simple driver for the HX8357-based displays.
* Author(s): Melissa LeBlanc-Williams, Matt Land
"""
from micropython import const
from adafruit_rgb_display.rgb import DisplaySPI
try:
from typing import Optional
import digitalio
import busio
except ImportError:
pass
__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display.git"
_SWRESET = const(0x01)
_SLPOUT = const(0x11)
_NORON = const(0x13)
_INVOFF = const(0x20)
_INVON = const(0x21)
_DISPOFF = const(0x28)
_DISPON = const(0x29)
_CASET = const(0x2A)
_PASET = const(0x2B)
_RAMWR = const(0x2C)
_RAMRD = const(0x2E)
_TEON = const(0x35)
_MADCTL = const(0x36)
_COLMOD = const(0x3A)
_TEARLINE = const(0x44)
_SETOSC = const(0xB0)
_SETPWR1 = const(0xB1)
_SETRGB = const(0xB3)
_SETCYC = const(0xB4)
_SETCOM = const(0xB6)
_SETC = const(0xB9)
_SETSTBA = const(0xC0)
_SETPANEL = const(0xCC)
_SETGAMMA = const(0xE0)
class HX8357(DisplaySPI):
"""
A simple driver for the HX8357-based displays.
>>> import busio
>>> import digitalio
>>> import board
>>> from adafruit_rgb_display import color565
>>> import adafruit_rgb_display.hx8357 as hx8357
>>> spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
>>> display = hx8357.HX8357(spi, cs=digitalio.DigitalInOut(board.GPIO0),
... dc=digitalio.DigitalInOut(board.GPIO15))
>>> display.fill(0x7521)
>>> display.pixel(64, 64, 0)
"""
_COLUMN_SET = _CASET
_PAGE_SET = _PASET
_RAM_WRITE = _RAMWR
_RAM_READ = _RAMRD
_INIT = (
(_SWRESET, None),
(_SETC, b"\xFF\x83\x57"),
(_SETRGB, b"\x80\x00\x06\x06"), # 0x80 enables SDO pin (0x00 disables)
(_SETCOM, b"\x25"), # -1.52V
(_SETOSC, b"\x68"), # Normal mode 70Hz, Idle mode 55 Hz
(_SETPANEL, b"\x05"), # BGR, Gate direction swapped
(_SETPWR1, b"\x00\x15\x1C\x1C\x83\xAA"), # Not deep standby BT VSPR VSNR AP
(_SETSTBA, b"\x50\x50\x01\x3C\x1E\x08"), # OPON normal OPON idle STBA GEN
(
_SETCYC,
b"\x02\x40\x00\x2A\x2A\x0D\x78",
), # NW 0x02 RTN DIV DUM DUM GDON GDOFF
(
_SETGAMMA,
b"\x02\x0A\x11\x1d\x23\x35\x41\x4b\x4b\x42\x3A\x27\x1B\x08\x09\x03\x02"
b"\x0A\x11\x1d\x23\x35\x41\x4b\x4b\x42\x3A\x27\x1B\x08\x09\x03\x00\x01",
),
(_COLMOD, b"\x55"), # 16 bit
(_MADCTL, b"\xc0"),
(_TEON, b"\x00"),
(_TEARLINE, b"\x00\x02"), # TW off
(_SLPOUT, None),
(_MADCTL, b"\xa0"),
(_DISPON, None),
)
_ENCODE_PIXEL = ">H"
_ENCODE_POS = ">HH"
# 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 = 480,
height: int = 320,
baudrate: int = 16000000,
polarity: int = 0,
phase: int = 0,
rotation: int = 0,
):
super().__init__(
spi,
dc,
cs,
rst,
width,
height,
baudrate=baudrate,
polarity=polarity,
phase=phase,
rotation=rotation,
)