|
| 1 | +diff --git a/adafruit_ili9341.py b/adafruit_ili9341.py |
| 2 | +--- a/adafruit_ili9341.py |
| 3 | ++++ b/adafruit_ili9341.py |
| 4 | +@@ -131,11 +131,12 @@ class ILI9341(BusDisplay): |
| 5 | + :param FourWire bus: bus that the display is connected to |
| 6 | + :param bool bgr: Use BGR color order instead of RGB |
| 7 | + :param bool invert: Invert the display |
| 8 | +- :param int madctl: Optional custom MADCTL value to override rotation/scan order bits |
| 9 | ++ :keyword int madctl: (optional) Raw value to write to the MADCTL register (0x36). |
| 10 | ++ If provided, the driver emits a MADCTL write during init. If omitted, |
| 11 | ++ the driver will not alter MADCTL. |
| 12 | + """ |
| 13 | + |
| 14 | + def __init__( |
| 15 | + self, |
| 16 | + bus: FourWire, |
| 17 | + *, |
| 18 | + bgr: bool = False, |
| 19 | + invert: bool = False, |
| 20 | +- madctl: int | None = None, |
| 21 | + **kwargs: Any, |
| 22 | + ): |
| 23 | +- # Start with base init sequence |
| 24 | ++ # Accept optional raw MADCTL via kwargs (requested by maintainers) |
| 25 | ++ madctl = kwargs.pop("madctl", None) |
| 26 | ++ # Start with base init sequence |
| 27 | + init_sequence = bytearray(_INIT_SEQUENCE) |
| 28 | + |
| 29 | +- # --- Replace existing MADCTL instead of appending --- |
| 30 | +- # Find MADCTL (0x36) in init sequence |
| 31 | +- try: |
| 32 | +- idx = init_sequence.index(0x36) |
| 33 | +- # Overwrite the length (always 1) + value |
| 34 | +- if madctl is not None: |
| 35 | +- init_sequence[idx + 1] = 0x01 |
| 36 | +- init_sequence[idx + 2] = madctl |
| 37 | +- elif bgr: |
| 38 | +- init_sequence[idx + 1] = 0x01 |
| 39 | +- init_sequence[idx + 2] = 0x30 # BGR encoding |
| 40 | +- else: |
| 41 | +- init_sequence[idx + 1] = 0x01 |
| 42 | +- init_sequence[idx + 2] = 0x38 # RGB encoding |
| 43 | +- except ValueError: |
| 44 | +- # If no MADCTL present, append it |
| 45 | +- if madctl is not None: |
| 46 | +- init_sequence += bytes([0x36, 0x01, madctl]) |
| 47 | +- elif bgr: |
| 48 | +- init_sequence += b"\x36\x01\x30" |
| 49 | +- else: |
| 50 | +- init_sequence += b"\x36\x01\x38" |
| 51 | ++ # Only touch MADCTL if caller explicitly provided it via kwargs |
| 52 | ++ if madctl is not None: |
| 53 | ++ # If MADCTL (0x36) already exists, overwrite its single data byte |
| 54 | ++ try: |
| 55 | ++ idx = init_sequence.index(0x36) |
| 56 | ++ init_sequence[idx + 1] = 0x01 # data length |
| 57 | ++ init_sequence[idx + 2] = madctl & 0xFF |
| 58 | ++ except ValueError: |
| 59 | ++ # Not present — append a single-byte MADCTL write |
| 60 | ++ init_sequence += bytes((0x36, 0x01, madctl & 0xFF)) |
| 61 | + |
| 62 | + # Inversion |
| 63 | + if invert: |
| 64 | + init_sequence += b"\x21\x00" |
| 65 | + |
| 66 | + super().__init__(bus, init_sequence, **kwargs) |
0 commit comments