10000 generic/ili9341 driver initial commit · shankezh/lv_binding_micropython@cb0c758 · GitHub
[go: up one dir, main page]

Skip to content

Commit cb0c758

Browse files
committed
generic/ili9341 driver initial commit
1 parent a69f4b5 commit cb0c758

File tree

1 file changed

+148
-0
lines changed

1 file changed

+148
-0
lines changed

driver/generic/ili9xxx.py

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
from micropython import const
2+
3+
from .st77xx import St77xx_hw, St77xx_lvgl
4+
5+
# Command constants from ILI9341 datasheet
6+
_NOP = const(0x00) # No-op
7+
_SWRESET = const(0x01) # Software reset
8+
_RDDID = const(0x04) # Read display ID info
9+
_RDDST = const(0x09) # Read display status
10+
_SLPIN = const(0x10) # Enter sleep mode
11+
_SLPOUT = const(0x11) # Exit sleep mode
12+
_PTLON = const(0x12) # Partial mode on
13+
_NORON = const(0x13) # Normal display mode on
14+
_RDMODE = const(0x0A) # Read display power mode
15+
_RDMADCTL = const(0x0B) # Read display MADCTL
16+
_RDPIXFMT = const(0x0C) # Read display pixel format
17+
_RDIMGFMT = const(0x0D) # Read display image format
18+
_RDSELFDIAG = const(0x0F) # Read display self-diagnostic
19+
_INVOFF = const(0x20) # Display inversion off
20+
_INVON = const(0x21) # Display inversion on
21+
_GAMMASET = const(0x26) # Gamma set
22+
_DISPLAY_OFF = const(0x28) # Display off
23+
_DISPLAY_ON = const(0x29) # Display on
24+
_SET_COLUMN = const(0x2A) # Column address set
25+
_SET_PAGE = const(0x2B) # Page address set
26+
_WRITE_RAM = const(0x2C) # Memory write
27+
_READ_RAM = const(0x2E) # Memory read
28+
_PTLAR = const(0x30) # Partial area
29+
_VSCRDEF = const(0x33) # Vertical scrolling definition
30+
_MADCTL = const(0x36) # Memory access control
31+
_VSCRSADD = const(0x37) # Vertical scrolling start address
32+
_PIXFMT = const(0x3A) # COLMOD: Pixel format set
33+
_WRITE_DISPLAY_BRIGHTNESS = const(0x51) # Brightness hardware dependent!
34+
_READ_DISPLAY_BRIGHTNESS = const(0x52)
35+
_WRITE_CTRL_DISPLAY = const(0x53)
36+
_READ_CTRL_DISPLAY = const(0x54)
37+
_WRITE_CABC = const(0x55) # Write Content Adaptive Brightness Control
38+
_READ_CABC = const(0x56) # Read Content Adaptive Brightness Control
39+
_WRITE_CABC_MINIMUM = const(0x5E) # Write CABC Minimum Brightness
40+
_READ_CABC_MINIMUM = const(0x5F) # Read CABC Minimum Brightness
41+
_FRMCTR1 = const(0xB1) # Frame rate control (In normal mode/full colors)
42+
_FRMCTR2 = const(0xB2) # Frame rate control (In idle mode/8 colors)
43+
_FRMCTR3 = const(0xB3) # Frame rate control (In partial mode/full colors)
44+
_INVCTR = const(0xB4) # Display inversion control
45+
_DFUNCTR = const(0xB6) # Display function control
46+
_PWCTR1 = const(0xC0) # Power control 1
47+
_PWCTR2 = const(0xC1) # Power control 2
48+
_PWCTRA = const(0xCB) # Power control A
49+
_PWCTRB = const(0xCF) # Power control B
50+
_VMCTR1 = const(0xC5) # VCOM control 1
51+
_VMCTR2 = const(0xC7) # VCOM control 2
52+
_RDID1 = const(0xDA) # Read ID 1
53+
_RDID2 = const(0xDB) # Read ID 2
54+
_RDID3 = const(0xDC) # Read ID 3
55+
_RDID4 = const(0xDD) # Read ID 4
56+
_GMCTRP1 = const(0xE0) # Positive gamma correction
57+
_GMCTRN1 = const(0xE1) # Negative gamma correction
58+
_DTCA = const(0xE8) # Driver timing control A
59+
_DTCB = const(0xEA) # Driver timing control B
60+
_POSC = const(0xED) # Power on sequence control
61+
_ENABLE3G = const(0xF2) # Enable 3 gamma control
62+
_PUMPRC = const(0xF7) # Pump ratio control
63+
64+
_MADCTL_MY = const(0x80) # page address order (0: top to bottom; 1: bottom to top)
65+
_MADCTL_MX = const(0x40) # column address order (0: left to right; 1: right to left)
66+
_MADCTL_MV = const(0x20) # page/column order (0: normal mode 1; reverse mode)
67+
_MADCTL_ML = const(
68+
0x10
69+
) # line address order (0: refresh to to bottom; 1: refresh bottom to top)
70+
_MADCTL_BGR = const(0x08) # colors are BGR (not RGB)
71+
_MADCTL_RTL = const(0x04) # refresh right to left
72+
73+
_MADCTL_ROTS = (
74+
const(_MADCTL_MX), # 0 = portrait
75+
const(_MADCTL_MV), # 1 = landscape
76+
const(_MADCTL_MY), # 2 = inverted portrait
77+
const(_MADCTL_MX | _MADCTL_MY | _MADCTL_MV), # 3 = inverted landscape
78+
)
79+
80+
81+
class Ili9341_hw(St77xx_hw):
82+
def __init__(self, res, **kw):
83+
super().__init__(
84+
res=res,
85+
suppRes=[
86+
(240, 320),
87+
],
88+
model=None,
89+
suppModel=None,
90+
bgr=True,
91+
**kw,
92+
)
93+
94+
def config_hw(self):
95+
self._run_seq(
96+
[
97+
(_SLPOUT, None, 100),
98+
(_PWCTRB, b"\x00\xC1\x30"), # Pwr ctrl B
99+
(_POSC, b"\x64\x03\x12\x81"), # Pwr on seq. ctrl
100+
(_DTCA, b"\x85\x00\x78"), # Driver timing ctrl A
101+
(_PWCTRA, b"\x39\x2C\x00\x34\x02"), # Pwr ctrl A
102+
(_PUMPRC, b"\x20"), # Pump ratio control
103+
(_DTCB, b"\x00\x00"), # Driver timing ctrl B
104+
(_PWCTR1, b"\x23"), # Pwr ctrl 1
105+
(_PWCTR2, b"\x10"), # Pwr ctrl 2
106+
(_VMCTR1, b"\x3E\x28"), # VCOM ctrl 1
107+
(_VMCTR2, b"\x86"), # VCOM ctrl 2
108+
# (_MADCTL, self.rotation"), # Memory access ctrl # TODO: rotation?
109+
(_VSCRSADD, b"\x00"), # Vertical scrolling start address
110+
(_PIXFMT, b"\x55"), # COLMOD: Pixel format
111+
(_FRMCTR1, b"\x00\x18"), # Frame rate ctrl
112+
(_DFUNCTR, b"\x08\x82\x27"),
113+
(_ENABLE3G, b"\x00"), # Enable 3 gamma ctrl
114+
(_GAMMASET, b"\x01"), # Gamma curve selected
115+
(
116+
_GMCTRP1,
117+
b"\x0F\x31\x2B\x0C\x0E\x08\x4E\xF1\x37\x07\x10\x03\x0E\x09\x00",
118+
),
119+
(
120+
_GMCTRN1,
121+
b"\x00\x0E\x14\x03\x11\x07\x31\xC1\x48\x08\x0F\x0C\x31\x36\x0F",
122+
),
123+
(_SLPOUT, None, 100),
124+
(_DISPLAY_ON, None),
125+
]
126+
)
127+
128+
def apply_rotation(self, rot):
129+
self.rot = rot
130+
if (self.rot % 2) == 0:
131+
self.width, self.height = self.res
132+
else:
133+
self.height, self.width = self.res
134+
self.write_register(
135+
_MADCTL,
136+
bytes([(_MADCTL_BGR if self.bgr else 0) | _MADCTL_ROTS[self.rot % 4]]),
137+
)
138+
139+
140+
class Ili9341(Ili9341_hw, St77xx_lvgl):
141+
def __init__(self, res, doublebuffer=True, factor=4, **kw):
142+
"""See :obj:`Ili9341_hw` for the meaning of the parameters."""
143+
import lvgl as lv
144+
145+
Ili9341_hw.__init__(self, res=res, **kw)
146+
St77xx_lvgl.__init__(self, doublebuffer, factor)
147+
self.disp_drv.color_format = lv.COLOR_FORMAT.NATIVE_REVERSE
148+
self.disp_drv.register()

0 commit comments

Comments
 (0)
0