/ adafruit_st7735r.py
adafruit_st7735r.py
 1  # The MIT License (MIT)
 2  #
 3  # Copyright (c) 2019 Scott Shawcroft and Melissa LeBlanc-Williams
 4  #                    for Adafruit Industries LLC
 5  #
 6  # Permission is hereby granted, free of charge, to any person obtaining a copy
 7  # of this software and associated documentation files (the "Software"), to deal
 8  # in the Software without restriction, including without limitation the rights
 9  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  # copies of the Software, and to permit persons to whom the Software is
11  # furnished to do so, subject to the following conditions:
12  #
13  # The above copyright notice and this permission notice shall be included in
14  # all copies or substantial portions of the Software.
15  #
16  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  # THE SOFTWARE.
23  """
24  `adafruit_st7735r`
25  ====================================================
26  
27  Displayio driver for ST7735R based displays.
28  
29  * Author(s): Scott Shawcroft and Melissa LeBlanc-Williams
30  
31  Implementation Notes
32  --------------------
33  
34  **Hardware:**
35  
36  * 1.8" SPI TFT display, 160x128 18-bit color:
37    https://www.adafruit.com/product/618
38  * Adafruit 0.96" 160x80 Color TFT Display w/ MicroSD Card Breakout:
39    https://www.adafruit.com/product/3533
40  * 1.8" Color TFT LCD display with MicroSD Card Breakout:
41    https://www.adafruit.com/product/358
42  * Adafruit 1.44" Color TFT LCD Display with MicroSD Card breakout:
43    https://www.adafruit.com/product/2088
44  * Adafruit Mini Color TFT with Joystick FeatherWing:
45    https://www.adafruit.com/product/3321
46  
47  **Software and Dependencies:**
48  
49  * Adafruit CircuitPython firmware for the supported boards:
50    https://github.com/adafruit/circuitpython/releases
51  
52  """
53  
54  import displayio
55  
56  __version__ = "0.0.0-auto.0"
57  __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ST7735R.git"
58  
59  _INIT_SEQUENCE = bytearray(
60      b"\x01\x80\x96"  # SWRESET and Delay 150ms
61      b"\x11\x80\xff"  # SLPOUT and Delay
62      b"\xb1\x03\x01\x2C\x2D"  # _FRMCTR1
63      b"\xb2\x03\x01\x2C\x2D"  # _FRMCTR2
64      b"\xb3\x06\x01\x2C\x2D\x01\x2C\x2D"  # _FRMCTR3
65      b"\xb4\x01\x07"  # _INVCTR line inversion
66      b"\xc0\x03\xa2\x02\x84"  # _PWCTR1 GVDD = 4.7V, 1.0uA
67      b"\xc1\x01\xc5"  # _PWCTR2 VGH=14.7V, VGL=-7.35V
68      b"\xc2\x02\x0a\x00"  # _PWCTR3 Opamp current small, Boost frequency
69      b"\xc3\x02\x8a\x2a"
70      b"\xc4\x02\x8a\xee"
71      b"\xc5\x01\x0e"  # _VMCTR1 VCOMH = 4V, VOML = -1.1V
72      b"\x20\x00"  # _INVOFF
73      b"\x36\x01\x18"  # _MADCTL bottom to top refresh
74      # 1 clk cycle nonoverlap, 2 cycle gate rise, 3 sycle osc equalie,
75      # fix on VTL
76      b"\x3a\x01\x05"  # COLMOD - 16bit color
77      b"\xe0\x10\x02\x1c\x07\x12\x37\x32\x29\x2d\x29\x25\x2B\x39\x00\x01\x03\x10"  # _GMCTRP1 Gamma
78      b"\xe1\x10\x03\x1d\x07\x06\x2E\x2C\x29\x2D\x2E\x2E\x37\x3F\x00\x00\x02\x10"  # _GMCTRN1
79      b"\x13\x80\x0a"  # _NORON
80      b"\x29\x80\x64"  # _DISPON
81  )
82  
83  # pylint: disable=too-few-public-methods
84  class ST7735R(displayio.Display):
85      """ST7735 driver for ST7735R"""
86  
87      def __init__(self, bus, *, bgr=False, invert=False, **kwargs):
88          """
89          :param bool bgr: (Optional) An extra init sequence to append (default=False)
90          """
91          init_sequence = _INIT_SEQUENCE
92          if bgr:
93              init_sequence += (
94                  b"\x36\x01\xC0"  # _MADCTL Default rotation plus BGR encoding
95              )
96          if invert:
97              init_sequence += b"\x21\x00"  # _INVON
98          super().__init__(bus, init_sequence, **kwargs)