|
| 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 | +class HX8357(DisplaySPI): |
| 62 | + """ |
| 63 | + A simple driver for the HX8357-based displays. |
| 64 | +
|
| 65 | + >>> import busio |
| 66 | + >>> import digitalio |
| 67 | + >>> import board |
| 68 | + >>> from adafruit_rgb_display import color565 |
| 69 | + >>> import adafruit_rgb_display.hx8357 as hx8357 |
| 70 | + >>> spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO) |
| 71 | + >>> display = hx8357.HX8357(spi, cs=digitalio.DigitalInOut(board.GPIO0), |
| 72 | + ... dc=digitalio.DigitalInOut(board.GPIO15)) |
| 73 | + >>> display.fill(0x7521) |
| 74 | + >>> display.pixel(64, 64, 0) |
| 75 | + """ |
| 76 | + _COLUMN_SET = _CASET |
| 77 | + _PAGE_SET = _PASET |
| 78 | + _RAM_WRITE = _RAMWR |
| 79 | + _RAM_READ = _RAMRD |
| 80 | + _INIT = ( |
| 81 | + (_SWRESET, None), |
| 82 | + (_SETC, b'\xFF\x83\x57'), |
| 83 | + (_SETRGB, b'\x80\x00\x06\x06'), # 0x80 enables SDO pin (0x00 disables) |
| 84 | + (_SETCOM, b'\x25'), # -1.52V |
| 85 | + (_SETOSC, b'\x68'), # Normal mode 70Hz, Idle mode 55 Hz |
| 86 | + (_SETPANEL, b'\x05'), # BGR, Gate direction swapped |
| 87 | + (_SETPWR1, b'\x00\x15\x1C\x1C\x83\xAA'), # Not deep standby BT VSPR VSNR AP |
| 88 | + (_SETSTBA, b'\x50\x50\x01\x3C\x1E\x08'), # OPON normal OPON idle STBA GEN |
| 89 | + (_SETCYC, b'\x02\x40\x00\x2A\x2A\x0D\x78'), # NW 0x02 RTN DIV DUM DUM GDON GDOFF |
| 90 | + (_SETGAMMA, b'\x02\x0A\x11\x1d\x23\x35\x41\x4b\x4b\x42\x3A\x27\x1B\x08\x09\x03\x02\x0A\x11\x1d\x23\x35\x41\x4b\x4b\x42\x3A\x27\x1B\x08\x09\x03\x00\x01'), |
| 91 | + (_COLMOD, b'\x55'), # 16 bit |
| 92 | + (_MADCTL, b'\xc0'), |
| 93 | + (_TEON, b'\x00'), |
| 94 | + (_TEARLINE, b'\x00\x02'), # TW off |
| 95 | + (_SLPOUT, None), |
| 96 | + (_MADCTL, b'\xa0'), |
| 97 | + (_DISPON, None), |
| 98 | + ) |
| 99 | + _ENCODE_PIXEL = ">H" |
| 100 | + _ENCODE_POS = ">HH" |
| 101 | + |
| 102 | + #pylint: disable-msg=useless-super-delegation, too-many-arguments |
| 103 | + def __init__(self, spi, dc, cs, rst=None, width=480, height=320, |
| 104 | + baudrate=16000000, polarity=0, phase=0): |
| 105 | + super().__init__(spi, dc, cs, rst, width, height, |
| 106 | + baudrate=baudrate, polarity=polarity, phase=phase) |
0 commit comments