@@ -53,7 +53,19 @@ def rgb(r, g, b):
5353 return (r & 0xF8 ) | (g & 0xE0 ) >> 5 | (g & 0x1C ) << 11 | (b & 0xF8 ) << 5
5454
5555 # Transpose width & height for landscape mode
56- def __init__ (self , spi , cs , dc , rst , height = 240 , width = 320 , usd = False , init_spi = False ):
56+ def __init__ (
57+ self ,
58+ spi ,
59+ cs ,
60+ dc ,
61+ rst ,
62+ height = 240 ,
63+ width = 320 ,
64+ usd = False ,
65+ init_spi = False ,
66+ rot = False ,
67+ bgr = False ,
68+ ):
5769 """For more information see
5870 https://github.com/peterhinch/micropython-nano-gui/blob/master/DRIVERS.md#32-drivers-for-ili9341
5971 """
@@ -95,10 +107,16 @@ def __init__(self, spi, cs, dc, rst, height=240, width=320, usd=False, init_spi=
95107 self ._wcd (b"\xc5 " , b"\x3E \x28 " ) # VMCTR1 VCOM ctrl 1
96108 self ._wcd (b"\xc7 " , b"\x86 " ) # VMCTR2 VCOM ctrl 2
97109 # (b'\x88', b'\xe8', b'\x48', b'\x28')[rotation // 90]
98- if self .height > self .width :
99- self ._wcd (b"\x36 " , b"\x48 " if usd else b"\x88 " ) # MADCTL: RGB portrait mode
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
113+ else :
114+ self ._wcd (b"\x36 " , b"\x48 " if usd else b"\x88 " ) # MADCTL: RGB portrait mode
100115 else :
101- self ._wcd (b"\x36 " , b"\x28 " if usd else b"\xe8 " ) # MADCTL: RGB landscape mode
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
102120 self ._wcd (b"\x37 " , b"\x00 " ) # VSCRSADD Vertical scrolling start address
103121 self ._wcd (b"\x3a " , b"\x55 " ) # PIXFMT COLMOD: Pixel format 16 bits (MCU & interface)
104122 self ._wcd (b"\xb1 " , b"\x00 \x18 " ) # FRMCTR1 Frame rate ctrl
0 commit comments