Skip to content

Commit 7868db5

Browse files
committed
ILI9341 8-bit driver: add rot and bgr constructor args.
1 parent ef1e80b commit 7868db5

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

drivers/ili93xx/ili9341_8bit.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,19 @@ def rgb(r, g, b):
4141
return (r & 0xE0) | ((g >> 3) & 0x1C) | (b >> 6)
4242

4343
# Transpose width & height for landscape mode
44-
def __init__(self, spi, cs, dc, rst, height=240, width=320, usd=False, init_spi=False):
44+
def __init__(
45+
self,
46+
spi,
47+
cs,
48+
dc,
49+
rst,
50+
height=240,
51+
width=320,
52+
usd=False,
53+
init_spi=False,
54+
rot=False,
55+
bgr=False,
56+
):
4557
"""For more information see
4658
https://github.com/peterhinch/micropython-nano-gui/blob/master/DRIVERS.md#32-drivers-for-ili9341
4759
"""
@@ -82,10 +94,16 @@ def __init__(self, spi, cs, dc, rst, height=240, width=320, usd=False, init_spi=
8294
self._wcd(b"\xc5", b"\x3E\x28") # VMCTR1 VCOM ctrl 1
8395
self._wcd(b"\xc7", b"\x86") # VMCTR2 VCOM ctrl 2
8496
# (b'\x88', b'\xe8', b'\x48', b'\x28')[rotation // 90]
85-
if height > width:
86-
self._wcd(b"\x36", b"\x48" if usd else b"\x88") # MADCTL: RGB portrait mode
97+
if (self.height > self.width) ^ rot:
98+
if bgr:
99+
self._wcd(b"\x36", b"\x40" if usd else b"\x80") # MADCTL: BGR portrait mode
100+
else:
101+
self._wcd(b"\x36", b"\x48" if usd else b"\x88") # MADCTL: RGB portrait mode
87102
else:
88-
self._wcd(b"\x36", b"\x28" if usd else b"\xe8") # MADCTL: RGB landscape mode
103+
if bgr:
104+
self._wcd(b"\x36", b"\x20" if usd else b"\xe0") # MADCTL: BGR landscape mode
105+
else:
106+
self._wcd(b"\x36", b"\x28" if usd else b"\xe8") # MADCTL: RGB landscape mode
89107
self._wcd(b"\x37", b"\x00") # VSCRSADD Vertical scrolling start address
90108
self._wcd(b"\x3a", b"\x55") # PIXFMT COLMOD: Pixel format 16 bits (MCU & interface)
91109
self._wcd(b"\xb1", b"\x00\x18") # FRMCTR1 Frame rate ctrl

0 commit comments

Comments
 (0)