ILI9341 drivers: add mod constructor arg.

pull/89/head
Peter Hinch 2025-01-26 12:31:29 +00:00
rodzic 7868db5317
commit b608f4db66
3 zmienionych plików z 25 dodań i 22 usunięć

Wyświetl plik

@ -411,6 +411,9 @@ soft SPI may be used but hard may be faster. See note on overclocking below.
* `width=320` * `width=320`
* `usd=False` Upside down: set `True` to invert display. * `usd=False` Upside down: set `True` to invert display.
* `init_spi=False` Allow bus sharing. See note below. * `init_spi=False` Allow bus sharing. See note below.
* `mod=None` Set to a number from 0 to 7 to correct garbled display on some
Chinese units.
* `bgr=False` If `True` use BGR color rendition in place of RGB.
#### Method (4-bit driver only) #### Method (4-bit driver only)

Wyświetl plik

@ -63,7 +63,7 @@ class ILI9341(framebuf.FrameBuffer):
width=320, width=320,
usd=False, usd=False,
init_spi=False, init_spi=False,
rot=False, mod=None,
bgr=False, bgr=False,
): ):
"""For more information see """For more information see
@ -106,17 +106,17 @@ class ILI9341(framebuf.FrameBuffer):
self._wcd(b"\xc1", b"\x10") # PWCTR2 Pwr ctrl 2 self._wcd(b"\xc1", b"\x10") # PWCTR2 Pwr ctrl 2
self._wcd(b"\xc5", b"\x3E\x28") # VMCTR1 VCOM ctrl 1 self._wcd(b"\xc5", b"\x3E\x28") # VMCTR1 VCOM ctrl 1
self._wcd(b"\xc7", b"\x86") # VMCTR2 VCOM ctrl 2 self._wcd(b"\xc7", b"\x86") # VMCTR2 VCOM ctrl 2
# (b'\x88', b'\xe8', b'\x48', b'\x28')[rotation // 90] if mod is None:
if (self.height > self.width) ^ rot: if self.height > self.width:
if bgr: v = 0x40 if usd else 0x80 # MADCTL: BGR portrait mode
self._wcd(b"\x36", b"\x40" if usd else b"\x80") # MADCTL: BGR portrait mode
else: else:
self._wcd(b"\x36", b"\x48" if usd else b"\x88") # MADCTL: RGB portrait mode v = 0x20 if usd else 0xE0 # MADCTL: BGR landscape mode
else: else: # Weird Chinese display
if bgr: if not 0 <= mod <= 7:
self._wcd(b"\x36", b"\x20" if usd else b"\xe0") # MADCTL: BGR landscape mode raise ValueError("mod must be in range 0 to 7")
else: v = mod << 5
self._wcd(b"\x36", b"\x28" if usd else b"\xe8") # MADCTL: RGB landscape mode v = v if bgr else (v | 8)
self._wcd(b"\x36", int.to_bytes(v, 1, "big"))
self._wcd(b"\x37", b"\x00") # VSCRSADD Vertical scrolling start address self._wcd(b"\x37", b"\x00") # VSCRSADD Vertical scrolling start address
self._wcd(b"\x3a", b"\x55") # PIXFMT COLMOD: Pixel format 16 bits (MCU & interface) self._wcd(b"\x3a", b"\x55") # PIXFMT COLMOD: Pixel format 16 bits (MCU & interface)
self._wcd(b"\xb1", b"\x00\x18") # FRMCTR1 Frame rate ctrl self._wcd(b"\xb1", b"\x00\x18") # FRMCTR1 Frame rate ctrl

Wyświetl plik

@ -51,7 +51,7 @@ class ILI9341(framebuf.FrameBuffer):
width=320, width=320,
usd=False, usd=False,
init_spi=False, init_spi=False,
rot=False, mod=None,
bgr=False, bgr=False,
): ):
"""For more information see """For more information see
@ -93,17 +93,17 @@ class ILI9341(framebuf.FrameBuffer):
self._wcd(b"\xc1", b"\x10") # PWCTR2 Pwr ctrl 2 self._wcd(b"\xc1", b"\x10") # PWCTR2 Pwr ctrl 2
self._wcd(b"\xc5", b"\x3E\x28") # VMCTR1 VCOM ctrl 1 self._wcd(b"\xc5", b"\x3E\x28") # VMCTR1 VCOM ctrl 1
self._wcd(b"\xc7", b"\x86") # VMCTR2 VCOM ctrl 2 self._wcd(b"\xc7", b"\x86") # VMCTR2 VCOM ctrl 2
# (b'\x88', b'\xe8', b'\x48', b'\x28')[rotation // 90] if mod is None:
if (self.height > self.width) ^ rot: if self.height > self.width:
if bgr: v = 0x40 if usd else 0x80 # MADCTL: BGR portrait mode
self._wcd(b"\x36", b"\x40" if usd else b"\x80") # MADCTL: BGR portrait mode
else: else:
self._wcd(b"\x36", b"\x48" if usd else b"\x88") # MADCTL: RGB portrait mode v = 0x20 if usd else 0xE0 # MADCTL: BGR landscape mode
else: else: # Weird Chinese display
if bgr: if not 0 <= mod <= 7:
self._wcd(b"\x36", b"\x20" if usd else b"\xe0") # MADCTL: BGR landscape mode raise ValueError("mod must be in range 0 to 7")
else: v = mod << 5
self._wcd(b"\x36", b"\x28" if usd else b"\xe8") # MADCTL: RGB landscape mode v = v if bgr else (v | 8)
self._wcd(b"\x36", int.to_bytes(v, 1, "big"))
self._wcd(b"\x37", b"\x00") # VSCRSADD Vertical scrolling start address self._wcd(b"\x37", b"\x00") # VSCRSADD Vertical scrolling start address
self._wcd(b"\x3a", b"\x55") # PIXFMT COLMOD: Pixel format 16 bits (MCU & interface) self._wcd(b"\x3a", b"\x55") # PIXFMT COLMOD: Pixel format 16 bits (MCU & interface)
self._wcd(b"\xb1", b"\x00\x18") # FRMCTR1 Frame rate ctrl self._wcd(b"\xb1", b"\x00\x18") # FRMCTR1 Frame rate ctrl