Skip to content

Commit b608f4d

Browse files
committed
ILI9341 drivers: add mod constructor arg.
1 parent 7868db5 commit b608f4d

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

DRIVERS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ soft SPI may be used but hard may be faster. See note on overclocking below.
411411
* `width=320`
412412
* `usd=False` Upside down: set `True` to invert display.
413413
* `init_spi=False` Allow bus sharing. See note below.
414+
* `mod=None` Set to a number from 0 to 7 to correct garbled display on some
415+
Chinese units.
416+
* `bgr=False` If `True` use BGR color rendition in place of RGB.
414417

415418
#### Method (4-bit driver only)
416419

drivers/ili93xx/ili9341.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __init__(
6363
width=320,
6464
usd=False,
6565
init_spi=False,
66-
rot=False,
66+
mod=None,
6767
bgr=False,
6868
):
6969
"""For more information see
@@ -106,17 +106,17 @@ def __init__(
106106
self._wcd(b"\xc1", b"\x10") # PWCTR2 Pwr ctrl 2
107107
self._wcd(b"\xc5", b"\x3E\x28") # VMCTR1 VCOM ctrl 1
108108
self._wcd(b"\xc7", b"\x86") # VMCTR2 VCOM ctrl 2
109-
# (b'\x88', b'\xe8', b'\x48', b'\x28')[rotation // 90]
110-
if (self.height > self.width) ^ rot:
111-
if bgr:
112-
self._wcd(b"\x36", b"\x40" if usd else b"\x80") # MADCTL: BGR portrait mode
109+
if mod is None:
110+
if self.height > self.width:
111+
v = 0x40 if usd else 0x80 # MADCTL: BGR portrait mode
113112
else:
114-
self._wcd(b"\x36", b"\x48" if usd else b"\x88") # MADCTL: RGB portrait mode
115-
else:
116-
if bgr:
117-
self._wcd(b"\x36", b"\x20" if usd else b"\xe0") # MADCTL: BGR landscape mode
118-
else:
119-
self._wcd(b"\x36", b"\x28" if usd else b"\xe8") # MADCTL: RGB landscape mode
113+
v = 0x20 if usd else 0xE0 # MADCTL: BGR landscape mode
114+
else: # Weird Chinese display
115+
if not 0 <= mod <= 7:
116+
raise ValueError("mod must be in range 0 to 7")
117+
v = mod << 5
118+
v = v if bgr else (v | 8)
119+
self._wcd(b"\x36", int.to_bytes(v, 1, "big"))
120120
self._wcd(b"\x37", b"\x00") # VSCRSADD Vertical scrolling start address
121121
self._wcd(b"\x3a", b"\x55") # PIXFMT COLMOD: Pixel format 16 bits (MCU & interface)
122122
self._wcd(b"\xb1", b"\x00\x18") # FRMCTR1 Frame rate ctrl

drivers/ili93xx/ili9341_8bit.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(
5151
width=320,
5252
usd=False,
5353
init_spi=False,
54-
rot=False,
54+
mod=None,
5555
bgr=False,
5656
):
5757
"""For more information see
@@ -93,17 +93,17 @@ def __init__(
9393
self._wcd(b"\xc1", b"\x10") # PWCTR2 Pwr ctrl 2
9494
self._wcd(b"\xc5", b"\x3E\x28") # VMCTR1 VCOM ctrl 1
9595
self._wcd(b"\xc7", b"\x86") # VMCTR2 VCOM ctrl 2
96-
# (b'\x88', b'\xe8', b'\x48', b'\x28')[rotation // 90]
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
96+
if mod is None:
97+
if self.height > self.width:
98+
v = 0x40 if usd else 0x80 # MADCTL: BGR portrait mode
10099
else:
101-
self._wcd(b"\x36", b"\x48" if usd else b"\x88") # MADCTL: RGB portrait mode
102-
else:
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
100+
v = 0x20 if usd else 0xE0 # MADCTL: BGR landscape mode
101+
else: # Weird Chinese display
102+
if not 0 <= mod <= 7:
103+
raise ValueError("mod must be in range 0 to 7")
104+
v = mod << 5
105+
v = v if bgr else (v | 8)
106+
self._wcd(b"\x36", int.to_bytes(v, 1, "big"))
107107
self._wcd(b"\x37", b"\x00") # VSCRSADD Vertical scrolling start address
108108
self._wcd(b"\x3a", b"\x55") # PIXFMT COLMOD: Pixel format 16 bits (MCU & interface)
109109
self._wcd(b"\xb1", b"\x00\x18") # FRMCTR1 Frame rate ctrl

0 commit comments

Comments
 (0)