/ adafruit_rgb_display / hx8357.py
hx8357.py
1 # The MIT License (MIT) 2 # 3 # Copyright (c) 2019 Melissa LeBlanc-Williams for Adafruit Industries 4 # 5 # Permission is hereby granted, free of charge, to any person obtaining a copy 6 # of this software and associated documentation files (the "Software"), to deal 7 # in the Software without restriction, including without limitation the rights 8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 # copies of the Software, and to permit persons to whom the Software is 10 # furnished to do so, subject to the following conditions: 11 # 12 # The above copyright notice and this permission notice shall be included in 13 # all copies or substantial portions of the Software. 14 # 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 # THE SOFTWARE. 22 """ 23 `adafruit_rgb_display.hx8357` 24 ==================================================== 25 26 A simple driver for the HX8357-based displays. 27 28 * Author(s): Melissa LeBlanc-Williams 29 """ 30 from micropython import const 31 from adafruit_rgb_display.rgb import DisplaySPI 32 33 __version__ = "0.0.0-auto.0" 34 __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RGB_Display.git" 35 36 _SWRESET = const(0x01) 37 _SLPOUT = const(0x11) 38 _NORON = const(0x13) 39 _INVOFF = const(0x20) 40 _INVON = const(0x21) 41 _DISPOFF = const(0x28) 42 _DISPON = const(0x29) 43 _CASET = const(0x2A) 44 _PASET = const(0x2B) 45 _RAMWR = const(0x2C) 46 _RAMRD = const(0x2E) 47 _TEON = const(0x35) 48 _MADCTL = const(0x36) 49 _COLMOD = const(0x3A) 50 _TEARLINE = const(0x44) 51 _SETOSC = const(0xB0) 52 _SETPWR1 = const(0xB1) 53 _SETRGB = const(0xB3) 54 _SETCYC = const(0xB4) 55 _SETCOM = const(0xB6) 56 _SETC = const(0xB9) 57 _SETSTBA = const(0xC0) 58 _SETPANEL = const(0xCC) 59 _SETGAMMA = const(0xE0) 60 61 62 class HX8357(DisplaySPI): 63 """ 64 A simple driver for the HX8357-based displays. 65 66 >>> import busio 67 >>> import digitalio 68 >>> import board 69 >>> from adafruit_rgb_display import color565 70 >>> import adafruit_rgb_display.hx8357 as hx8357 71 >>> spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO) 72 >>> display = hx8357.HX8357(spi, cs=digitalio.DigitalInOut(board.GPIO0), 73 ... dc=digitalio.DigitalInOut(board.GPIO15)) 74 >>> display.fill(0x7521) 75 >>> display.pixel(64, 64, 0) 76 """ 77 78 _COLUMN_SET = _CASET 79 _PAGE_SET = _PASET 80 _RAM_WRITE = _RAMWR 81 _RAM_READ = _RAMRD 82 _INIT = ( 83 (_SWRESET, None), 84 (_SETC, b"\xFF\x83\x57"), 85 (_SETRGB, b"\x80\x00\x06\x06"), # 0x80 enables SDO pin (0x00 disables) 86 (_SETCOM, b"\x25"), # -1.52V 87 (_SETOSC, b"\x68"), # Normal mode 70Hz, Idle mode 55 Hz 88 (_SETPANEL, b"\x05"), # BGR, Gate direction swapped 89 (_SETPWR1, b"\x00\x15\x1C\x1C\x83\xAA"), # Not deep standby BT VSPR VSNR AP 90 (_SETSTBA, b"\x50\x50\x01\x3C\x1E\x08"), # OPON normal OPON idle STBA GEN 91 ( 92 _SETCYC, 93 b"\x02\x40\x00\x2A\x2A\x0D\x78", 94 ), # NW 0x02 RTN DIV DUM DUM GDON GDOFF 95 ( 96 _SETGAMMA, 97 b"\x02\x0A\x11\x1d\x23\x35\x41\x4b\x4b\x42\x3A\x27\x1B\x08\x09\x03\x02" 98 b"\x0A\x11\x1d\x23\x35\x41\x4b\x4b\x42\x3A\x27\x1B\x08\x09\x03\x00\x01", 99 ), 100 (_COLMOD, b"\x55"), # 16 bit 101 (_MADCTL, b"\xc0"), 102 (_TEON, b"\x00"), 103 (_TEARLINE, b"\x00\x02"), # TW off 104 (_SLPOUT, None), 105 (_MADCTL, b"\xa0"), 106 (_DISPON, None), 107 ) 108 _ENCODE_PIXEL = ">H" 109 _ENCODE_POS = ">HH" 110 111 # pylint: disable-msg=useless-super-delegation, too-many-arguments 112 def __init__( 113 self, 114 spi, 115 dc, 116 cs, 117 rst=None, 118 width=480, 119 height=320, 120 baudrate=16000000, 121 polarity=0, 122 phase=0, 123 rotation=0, 124 ): 125 super().__init__( 126 spi, 127 dc, 128 cs, 129 rst, 130 width, 131 height, 132 baudrate=baudrate, 133 polarity=polarity, 134 phase=phase, 135 rotation=rotation, 136 )