From 8c4514b5b3c0f1296c182c767568e717b6bb5429 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 19 Mar 2019 22:10:54 -0700 Subject: [PATCH 01/24] Subclassed all the displays. Not tested all yet. --- .travis.yml | 2 +- README.rst | 2 +- adafruit_st7735/__init__.py | 0 adafruit_st7735/st7735.py | 159 ++++++++++++++++++ .../st7789.py | 60 +++---- docs/api.rst | 5 +- docs/examples.rst | 4 + examples/st7735_miniTFT_simpletest.py | 19 +++ 8 files changed, 215 insertions(+), 36 deletions(-) create mode 100755 adafruit_st7735/__init__.py create mode 100755 adafruit_st7735/st7735.py rename adafruit_st7735.py => adafruit_st7735/st7789.py (50%) mode change 100644 => 100755 create mode 100644 examples/st7735_miniTFT_simpletest.py diff --git a/.travis.yml b/.travis.yml index 143f8ad..1f85eca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,7 @@ install: - pip install --force-reinstall pylint==1.9.2 script: - - pylint adafruit_st7735.py + - pylint adafruit_st7735/*.py - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py) - circuitpython-build-bundles --filename_prefix adafruit-circuitpython-st7735 --library_location . - cd docs && sphinx-build -E -W -b html . _build/html && cd .. diff --git a/README.rst b/README.rst index 18c1870..459a09f 100644 --- a/README.rst +++ b/README.rst @@ -13,7 +13,7 @@ Introduction :target: https://travis-ci.com/adafruit/Adafruit_CircuitPython_ST7735 :alt: Build Status -displayio driver for ST7735 TFT-LCD displays. +displayio driver for ST7735 and ST7789 TFT-LCD displays. Dependencies ============= diff --git a/adafruit_st7735/__init__.py b/adafruit_st7735/__init__.py new file mode 100755 index 0000000..e69de29 diff --git a/adafruit_st7735/st7735.py b/adafruit_st7735/st7735.py new file mode 100755 index 0000000..1dbb175 --- /dev/null +++ b/adafruit_st7735/st7735.py @@ -0,0 +1,159 @@ +# The MIT License (MIT) +# +# Copyright (c) 2019 Scott Shawcroft and Melissa LeBlanc-Williams +# for Adafruit Industries LLC +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +""" +`adafruit_st7735.st7735` +==================================================== + +Displayio driver for ST7735 based displays. + +* Author(s): Scott Shawcroft and Melissa LeBlanc-Williams + +Implementation Notes +-------------------- + +**Hardware:** + +* 1.8" SPI TFT display, 160x128 18-bit color: + https://www.adafruit.com/product/618 +* Adafruit 0.96" 160x80 Color TFT Display w/ MicroSD Card Breakout: + https://www.adafruit.com/product/3533 +* 1.8" Color TFT LCD display with MicroSD Card Breakout: + https://www.adafruit.com/product/358 +* Adafruit 1.44" Color TFT LCD Display with MicroSD Card breakout: + https://www.adafruit.com/product/2088 +* Adafruit Mini Color TFT with Joystick FeatherWing: + https://www.adafruit.com/product/3321 + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://github.com/adafruit/circuitpython/releases + +""" + +import displayio + +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ST7735.git" + +_INIT_SEQUENCE_B = ( + b"\x01\x80\x32" # _SWRESET and Delay 50ms + b"\x11\x80\xFF" # _SLPOUT + b"\x3A\x81\x05\x0A" # _COLMOD + b"\xB1\x83\x00\x06\x03\x0A" # _FRMCTR1 + b"\x36\x01\x08" # _MADCTL + b"\xB6\x02\x15\x02" # _DISSET5 + #1 clk cycle nonoverlap, 2 cycle gate, rise, 3 cycle osc equalize, Fix on VTL + b"\xB4\x01\x00" # _INVCTR line inversion + b"\xC0\x82\x02\x70\x0A" # _PWCTR1 GVDD = 4.7V, 1.0uA, 10 ms delay + b"\xC1\x01\x05" # _PWCTR2 VGH = 14.7V, VGL = -7.35V + b"\xC2\x02\x01\x02" # _PWCTR3 Opamp current small, Boost frequency + b"\xC5\x82\x3C\x38\x0A" # _VMCTR1 + b"\xFC\x02\x11\x15" # _PWCTR6 + b"\xE0\x10\x09\x16\x09\x20\x21\x1B\x13\x19\x17\x15\x1E\x2B\x04\x05\x02\x0E" # _GMCTRP1 Gamma + b"\xE1\x90\x0B\x14\x08\x1E\x22\x1D\x18\x1E\x1B\x1A\x24\x2B\x06\x06\x02\x0F\x0A" # _GMCTRN1 + b"\x2a\x00\x02\x00\x81" # _CASET + b"\x2b\x00\x02\x00\x81" # _RASET + b"\x13\x80\x0a" # _NORON + b"\x29\x80\xFF" # _DISPON +) + +_INIT_R1 = ( + b"\x01\x80\x96" # SWRESET and Delay 150ms + b"\x11\x80\xff" # SLPOUT and Delay + b"\xb1\x03\x01\x2C\x2D" # _FRMCTR1 + b"\xb2\x03\x01\x2C\x2D" # _FRMCTR2 + b"\xb3\x06\x01\x2C\x2D\x01\x2C\x2D" # _FRMCTR3 + b"\xb4\x01\x07" # _INVCTR line inversion + b"\xc0\x03\xa2\x02\x84" # _PWCTR1 GVDD = 4.7V, 1.0uA + b"\xc1\x01\xc5" # _PWCTR2 VGH=14.7V, VGL=-7.35V + b"\xc2\x02\x0a\x00" # _PWCTR3 Opamp current small, Boost frequency + b"\xc3\x02\x8a\x2a" + b"\xc4\x02\x8a\xee" + b"\xc5\x01\x0e" # _VMCTR1 VCOMH = 4V, VOML = -1.1V + b"\x2a\x00" # _INVOFF + b"\x36\x01\x18" # _MADCTL bottom to top refresh + # 1 clk cycle nonoverlap, 2 cycle gate rise, 3 sycle osc equalie, + # fix on VTL + b"\x3a\x01\x05" # COLMOD - 16bit color +) + +_INIT_R2_GREEN = ( + b"\x2a\x03\x02\x00\x81" # _CASET XSTART = 2, XEND = 129 + b"\x2b\x03\x02\x00\x81" # _RASET XSTART = 2, XEND = 129 +) + +_INIT_R2_RED = ( + b"\x2a\x00\x00\x00\x7F" # _CASET XSTART = 0, XEND = 127 + b"\x2b\x00\x00\x00\x9F" # _RASET XSTART = 0, XEND = 159 +) + +_INIT_R2_GREEN_144 = ( + b"\x2a\x00\x00\x00\x7F" # _CASET XSTART = 0, XEND = 127 + b"\x2b\x00\x00\x00\x7F" # _RASET XSTART = 0, XEND = 127 +) + +_INIT_R2_GREEN_160X80 = ( + b"\x2a\x00\x00\x00\x4F" # _CASET XSTART = 0, XEND = 79 + b"\x2b\x00\x00\x00\x9F" # _RASET XSTART = 0, XEND = 159 +) + +_INIT_R3 = ( + b"\xe0\x10\x02\x1c\x07\x12\x37\x32\x29\x2d\x29\x25\x2B\x39\x00\x01\x03\x10" # _GMCTRP1 Gamma + b"\xe1\x10\x03\x1d\x07\x06\x2E\x2C\x29\x2D\x2E\x2E\x37\x3F\x00\x00\x02\x10" # _GMCTRN1 + b"\x13\x80\x0a" # _NORON + b"\x29\x80\x64" # _DISPON +) + +_INIT_ROTATE_160x80 = ( + b"\x36\x01\x68" # _MADCTL Rotate to Landscape Mode +) + +class ST7735R_GREEN(displayio.Display): + """ST7735 driver for ST7735R Green tabs""" + def __init__(self, bus, *, width, height): + _INIT_SEQUENCE = _INIT_R1 + _INIT_R2_GREEN + _INIT_R3 + super().__init__(bus, _INIT_SEQUENCE, width=width, height=height, colstart=2, rowstart=1) + +class ST7735R_GREEN144(displayio.Display): + """ST7735 driver for ST7735R Green tabs 1.44-inch""" + def __init__(self, bus, *, width, height): + _INIT_SEQUENCE = _INIT_R1 + _INIT_R2_GREEN + _INIT_R3 + super().__init__(bus, _INIT_SEQUENCE, width=width, height=height, colstart=2, rowstart=3) + +class ST7735R_RED(displayio.Display): + """ST7735 driver for ST7735R Red tabs""" + def __init__(self, bus, *, width, height): + _INIT_SEQUENCE = _INIT_R1 + _INIT_R2_RED + _INIT_R3 + super().__init__(bus, _INIT_SEQUENCE, width=width, height=height) + +class ST7735B(displayio.Display): + """ST7735 driver for ST7735B""" + def __init__(self, bus, *, width, height): + super().__init__(bus, _INIT_SEQUENCE_B, width=width, height=height) + +class MINI160x80(displayio.Display): + """ST7735 driver for MINI160x80""" + def __init__(self, bus, *): + _INIT_SEQUENCE = _INIT_R1 + _INIT_R2_GREEN_160X80 + _INIT_R3 + _INIT_ROTATE_160x80 + super().__init__(bus, _INIT_SEQUENCE, width=160, height=80, rowstart=24) diff --git a/adafruit_st7735.py b/adafruit_st7735/st7789.py old mode 100644 new mode 100755 similarity index 50% rename from adafruit_st7735.py rename to adafruit_st7735/st7789.py index beb0f04..78e4e6c --- a/adafruit_st7735.py +++ b/adafruit_st7735/st7789.py @@ -1,6 +1,6 @@ # The MIT License (MIT) # -# Copyright (c) 2019 Scott Shawcroft for Adafruit Industries LLC +# Copyright (c) 2019 Melissa LeBlanc-Williams for Adafruit Industries LLC # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -20,20 +20,20 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. """ -`adafruit_ST7735` +`adafruit_st7735.st7789` ==================================================== -Displayio driver for ST7735 based displays. +Displayio driver for ST7789 based displays. -* Author(s): Scott Shawcroft +* Author(s): Melissa LeBlanc-Williams Implementation Notes -------------------- **Hardware:** -.. todo:: Add links to any specific hardware product page(s), or category page(s). Use unordered list & hyperlink rST - inline format: "* `Link Text `_" +* Adafruit 1.54" 240x240 Wide Angle TFT LCD Display with MicroSD: + https://www.adafruit.com/product/3787 **Software and Dependencies:** @@ -47,35 +47,29 @@ __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ST7735.git" - _INIT_SEQUENCE = ( - b"\x01\x80\x96" # SWRESET - b"\x11\x80\xff" # SLPOUT - b"\xb1\x03\x01\x2C\x2D" # _FRMCTR1 - b"\xb2\x03\x01\x2C\x2D" # - b"\xb3\x06\x01\x2C\x2D\x01\x2C\x2D" - b"\xb4\x01\x07" # _INVCTR line inversion - b"\xc0\x03\xa2\x02\x84" # _PWCTR1 GVDD = 4.7V, 1.0uA - b"\xc1\x01\xc5" # _PWCTR2 VGH=14.7V, VGL=-7.35V - b"\xc2\x02\x0a\x00" # _PWCTR3 Opamp current small, Boost frequency - b"\xc3\x02\x8a\x2a" - b"\xc4\x02\x8a\xee" - b"\xc5\x01\x0e" # _VMCTR1 VCOMH = 4V, VOML = -1.1V - b"\x2a\x00" # _INVOFF - b"\x36\x01\x18" # _MADCTL bottom to top refresh - # 1 clk cycle nonoverlap, 2 cycle gate rise, 3 sycle osc equalie, - # fix on VTL - b"\x3a\x01\x05" # COLMOD - 16bit color - b"\xe0\x10\x02\x1c\x07\x12\x37\x32\x29\x2d\x29\x25\x2B\x39\x00\x01\x03\x10" # _GMCTRP1 Gamma - b"\xe1\x10\x03\x1d\x07\x06\x2E\x2C\x29\x2D\x2E\x2E\x37\x3F\x00\x00\x02\x10" # _GMCTRN1 - b"\x2a\x03\x02\x00\x81" # _CASET XSTART = 2, XEND = 129 - b"\x2b\x03\x02\x00\x81" # _RASET XSTART = 2, XEND = 129 + b"\x01\x80\x32" # _SWRESET and Delay 50ms + b"\x11\x80\xFF" # _SLPOUT + b"\x3A\x81\x05\x0A" # _COLMOD + b"\xB1\x83\x00\x06\x03\x0A" # _FRMCTR1 + b"\x36\x01\x08" # _MADCTL + b"\xB6\x02\x15\x02" # _DISSET5 + #1 clk cycle nonoverlap, 2 cycle gate, rise, 3 cycle osc equalize, Fix on VTL + b"\xB4\x01\x00" # _INVCTR line inversion + b"\xC0\x82\x02\x70\x0A" # _PWCTR1 GVDD = 4.7V, 1.0uA, 10 ms delay + b"\xC1\x01\x05" # _PWCTR2 VGH = 14.7V, VGL = -7.35V + b"\xC2\x02\x01\x02" # _PWCTR3 Opamp current small, Boost frequency + b"\xC5\x82\x3C\x38\x0A" # _VMCTR1 + b"\xFC\x02\x11\x15" # _PWCTR6 + b"\xE0\x10\x09\x16\x09\x20\x21\x1B\x13\x19\x17\x15\x1E\x2B\x04\x05\x02\x0E" # _GMCTRP1 Gamma + b"\xE1\x90\x0B\x14\x08\x1E\x22\x1D\x18\x1E\x1B\x1A\x24\x2B\x06\x06\x02\x0F\x0A" # _GMCTRN1 + b"\x2a\x00\x02\x00\x81" # _CASET + b"\x2b\x00\x02\x00\x81" # _RASET b"\x13\x80\x0a" # _NORON - b"\x29\x80\x64" # _DISPON + b"\x29\x80\xFF" # _DISPON ) -class ST7735(displayio.Display): - """ST7735 driver for ST7735R Green tabs""" - # TODO(tannewt): Add support for Red tabs and non-R chips. https://github.com/adafruit/Adafruit-ST7735-Library/blob/master/Adafruit_ST7735.cpp +class ST7789(displayio.Display): + """ST7789 driver""" def __init__(self, bus, *, width, height): - super().__init__(bus, _INIT_SEQUENCE, width=width, height=height, colstart=2) + super().__init__(bus, _INIT_SEQUENCE, width=width, height=height, colstart=2, rowstart=1) diff --git a/docs/api.rst b/docs/api.rst index 1edfad7..d31e16f 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -4,5 +4,8 @@ .. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py) .. use this format as the module name: "adafruit_foo.foo" -.. automodule:: adafruit_st7735 +.. automodule:: adafruit_st7735.st7735 :members: + +.. automodule:: adafruit_st7735.st7789 + :members: diff --git a/docs/examples.rst b/docs/examples.rst index 8495988..190b419 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -6,3 +6,7 @@ Ensure your device works with this simple test. .. literalinclude:: ../examples/st7735_simpletest.py :caption: examples/st7735_simpletest.py :linenos: + +.. literalinclude:: ../examples/st7735_miniTFT_simpletest.py + :caption: examples/st7735_miniTFT_simpletest.py + :linenos: diff --git a/examples/st7735_miniTFT_simpletest.py b/examples/st7735_miniTFT_simpletest.py new file mode 100644 index 0000000..90d6099 --- /dev/null +++ b/examples/st7735_miniTFT_simpletest.py @@ -0,0 +1,19 @@ +import board +import displayio +from adafruit_seesaw.seesaw import Seesaw +from adafruit_st7735 import st7735 + +reset_pin = 8 +i2c = board.I2C() +ss = Seesaw(i2c, 0x5E) +ss.pin_mode(reset_pin, ss.OUTPUT) + +spi = board.SPI() +tft_cs = board.D5 +tft_dc = board.D6 + +displayio.release_displays() +display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) + +ss.digital_write(reset_pin, True) +display = st7735.MINI160x80(display_bus) From 382dbbbade12258c8114a565e1dbd2df5f00a450 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 19 Mar 2019 22:30:22 -0700 Subject: [PATCH 02/24] Linting --- adafruit_st7735/st7735.py | 5 +++-- adafruit_st7735/st7789.py | 1 + docs/examples.rst | 4 ++-- examples/st7735_miniTFT_simpletest.py | 5 ++++- examples/st7735_simpletest.py | 11 +++++++---- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/adafruit_st7735/st7735.py b/adafruit_st7735/st7735.py index 1dbb175..7a5b0c1 100755 --- a/adafruit_st7735/st7735.py +++ b/adafruit_st7735/st7735.py @@ -129,7 +129,8 @@ b"\x36\x01\x68" # _MADCTL Rotate to Landscape Mode ) -class ST7735R_GREEN(displayio.Display): +# pylint: disable=too-few-public-methods +class ST7735(displayio.Display): """ST7735 driver for ST7735R Green tabs""" def __init__(self, bus, *, width, height): _INIT_SEQUENCE = _INIT_R1 + _INIT_R2_GREEN + _INIT_R3 @@ -154,6 +155,6 @@ def __init__(self, bus, *, width, height): class MINI160x80(displayio.Display): """ST7735 driver for MINI160x80""" - def __init__(self, bus, *): + def __init__(self, bus): _INIT_SEQUENCE = _INIT_R1 + _INIT_R2_GREEN_160X80 + _INIT_R3 + _INIT_ROTATE_160x80 super().__init__(bus, _INIT_SEQUENCE, width=160, height=80, rowstart=24) diff --git a/adafruit_st7735/st7789.py b/adafruit_st7735/st7789.py index 78e4e6c..f3b9886 100755 --- a/adafruit_st7735/st7789.py +++ b/adafruit_st7735/st7789.py @@ -69,6 +69,7 @@ b"\x29\x80\xFF" # _DISPON ) +# pylint: disable=too-few-public-methods class ST7789(displayio.Display): """ST7789 driver""" def __init__(self, bus, *, width, height): diff --git a/docs/examples.rst b/docs/examples.rst index 190b419..c4e6481 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -7,6 +7,6 @@ Ensure your device works with this simple test. :caption: examples/st7735_simpletest.py :linenos: -.. literalinclude:: ../examples/st7735_miniTFT_simpletest.py - :caption: examples/st7735_miniTFT_simpletest.py +.. literalinclude:: ../examples/st7735_minitft_simpletest.py + :caption: examples/st7735_minitft_simpletest.py :linenos: diff --git a/examples/st7735_miniTFT_simpletest.py b/examples/st7735_miniTFT_simpletest.py index 90d6099..c8e7765 100644 --- a/examples/st7735_miniTFT_simpletest.py +++ b/examples/st7735_miniTFT_simpletest.py @@ -1,7 +1,10 @@ +""" +This example will test out the display on the Mini TFT FeatherWing +""" import board import displayio from adafruit_seesaw.seesaw import Seesaw -from adafruit_st7735 import st7735 +import adafruit_st7735.st7735 as st7735 reset_pin = 8 i2c = board.I2C() diff --git a/examples/st7735_simpletest.py b/examples/st7735_simpletest.py index 20d8b4a..42886e6 100644 --- a/examples/st7735_simpletest.py +++ b/examples/st7735_simpletest.py @@ -1,19 +1,22 @@ -import adafruit_st7735 +""" +This example will test out the display on the ST7735 Display +""" +import time import board import busio import displayio -import time +import adafruit_st7735.st7735 as st7735 displayio.release_displays() spi = busio.SPI(board.SCL, board.SDA) bus = displayio.FourWire(spi, chip_select=board.D9, command=board.D7, reset=board.D8) -display = adafruit_st7735.ST7735(bus, width=128, height=128) +display = st7735.ST7735(bus, width=128, height=128) s = displayio.Shape(10, 10) p = displayio.Palette(2) p[1] = 0xff0000 -s = displayio.Sprite(s, pixel_shader=p, position=(0,0)) +s = displayio.TileGrid(s, pixel_shader=p, x=0, y=0) everything = displayio.Group(max_size=10) everything.append(s) display.show(everything) From ca042cad6a4e12a7b8e88289290054e9c583e72a Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 19 Mar 2019 22:40:44 -0700 Subject: [PATCH 03/24] More Linting --- adafruit_st7735/st7735.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/adafruit_st7735/st7735.py b/adafruit_st7735/st7735.py index 7a5b0c1..aa17c8f 100755 --- a/adafruit_st7735/st7735.py +++ b/adafruit_st7735/st7735.py @@ -125,7 +125,7 @@ b"\x29\x80\x64" # _DISPON ) -_INIT_ROTATE_160x80 = ( +_INIT_ROTATE_160X80 = ( b"\x36\x01\x68" # _MADCTL Rotate to Landscape Mode ) @@ -133,20 +133,20 @@ class ST7735(displayio.Display): """ST7735 driver for ST7735R Green tabs""" def __init__(self, bus, *, width, height): - _INIT_SEQUENCE = _INIT_R1 + _INIT_R2_GREEN + _INIT_R3 - super().__init__(bus, _INIT_SEQUENCE, width=width, height=height, colstart=2, rowstart=1) + init_sequence = _INIT_R1 + _INIT_R2_GREEN + _INIT_R3 + super().__init__(bus, init_sequence, width=width, height=height, colstart=2, rowstart=1) class ST7735R_GREEN144(displayio.Display): """ST7735 driver for ST7735R Green tabs 1.44-inch""" def __init__(self, bus, *, width, height): - _INIT_SEQUENCE = _INIT_R1 + _INIT_R2_GREEN + _INIT_R3 - super().__init__(bus, _INIT_SEQUENCE, width=width, height=height, colstart=2, rowstart=3) + init_sequence = _INIT_R1 + _INIT_R2_GREEN + _INIT_R3 + super().__init__(bus, init_sequence, width=width, height=height, colstart=2, rowstart=3) class ST7735R_RED(displayio.Display): """ST7735 driver for ST7735R Red tabs""" def __init__(self, bus, *, width, height): - _INIT_SEQUENCE = _INIT_R1 + _INIT_R2_RED + _INIT_R3 - super().__init__(bus, _INIT_SEQUENCE, width=width, height=height) + init_sequence = _INIT_R1 + _INIT_R2_RED + _INIT_R3 + super().__init__(bus, init_sequence, width=width, height=height) class ST7735B(displayio.Display): """ST7735 driver for ST7735B""" @@ -156,5 +156,5 @@ def __init__(self, bus, *, width, height): class MINI160x80(displayio.Display): """ST7735 driver for MINI160x80""" def __init__(self, bus): - _INIT_SEQUENCE = _INIT_R1 + _INIT_R2_GREEN_160X80 + _INIT_R3 + _INIT_ROTATE_160x80 - super().__init__(bus, _INIT_SEQUENCE, width=160, height=80, rowstart=24) + init_sequence = _INIT_R1 + _INIT_R2_GREEN_160X80 + _INIT_R3 + _INIT_ROTATE_160x80 + super().__init__(bus, init_sequence, width=160, height=80, rowstart=24) From 5a60f40da844554715ea938658f03fa074e8067d Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 19 Mar 2019 22:44:32 -0700 Subject: [PATCH 04/24] Bug fix from Linting --- adafruit_st7735/st7735.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_st7735/st7735.py b/adafruit_st7735/st7735.py index aa17c8f..3b38c20 100755 --- a/adafruit_st7735/st7735.py +++ b/adafruit_st7735/st7735.py @@ -156,5 +156,5 @@ def __init__(self, bus, *, width, height): class MINI160x80(displayio.Display): """ST7735 driver for MINI160x80""" def __init__(self, bus): - init_sequence = _INIT_R1 + _INIT_R2_GREEN_160X80 + _INIT_R3 + _INIT_ROTATE_160x80 + init_sequence = _INIT_R1 + _INIT_R2_GREEN_160X80 + _INIT_R3 + _INIT_ROTATE_160X80 super().__init__(bus, init_sequence, width=160, height=80, rowstart=24) From 4ca2cea0eba969e6060f8354cbaf6caf2751167a Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 19 Mar 2019 22:52:14 -0700 Subject: [PATCH 05/24] Hopefully a Fix for Travis and displayio --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index b453b45..49c0703 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -21,7 +21,7 @@ # digitalio, micropython and busio. List the modules you use. Without it, the # autodoc module docs will fail to generate with a warning. # autodoc_mock_imports = ["digitalio", "busio"] - +autodoc_mock_imports = ["displayio"] intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} From e49fd3501ee7f12c4fe412c2c36fc5f4becf8f1a Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 19 Mar 2019 22:57:20 -0700 Subject: [PATCH 06/24] Removing example for now --- docs/examples.rst | 4 ---- 1 file changed, 4 deletions(-) diff --git a/docs/examples.rst b/docs/examples.rst index c4e6481..8495988 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -6,7 +6,3 @@ Ensure your device works with this simple test. .. literalinclude:: ../examples/st7735_simpletest.py :caption: examples/st7735_simpletest.py :linenos: - -.. literalinclude:: ../examples/st7735_minitft_simpletest.py - :caption: examples/st7735_minitft_simpletest.py - :linenos: From 06fc4a38f8d133f317365035a5ff894b5e29c004 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 19 Mar 2019 23:01:03 -0700 Subject: [PATCH 07/24] Attempting to fix cryptic Travis Error --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index 459a09f..156addb 100644 --- a/README.rst +++ b/README.rst @@ -29,6 +29,7 @@ Usage Example ============= .. code-block:: python + import adafruit_st7735 import board import busio From 5cf39ceb35362f3b4b05d1ececd541221e76a26d Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 19 Mar 2019 23:08:20 -0700 Subject: [PATCH 08/24] Removed Tutorial Link. Added Product Links --- docs/index.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index b05cb7a..7154076 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -23,14 +23,15 @@ Table of Contents .. toctree:: :caption: Tutorials -.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave - the toctree above for use later. - .. toctree:: :caption: Related Products -.. todo:: Add any product links here. If there are none, then simply delete this todo and leave - the toctree above for use later. + 1.8" SPI TFT display, 160x128 18-bit color + Adafruit 0.96" 160x80 Color TFT Display w/ MicroSD Card Breakout + 1.8" Color TFT LCD display with MicroSD Card Breakout + Adafruit 1.44" Color TFT LCD Display with MicroSD Card breakout + Adafruit Mini Color TFT with Joystick FeatherWing + Adafruit 1.54" 240x240 Wide Angle TFT LCD Display with MicroSD .. toctree:: :caption: Other Links From b9df19241b170f6403b7ac1297d09304580b8b63 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 20 Mar 2019 22:02:10 -0700 Subject: [PATCH 09/24] Added Black Display --- adafruit_st7735/st7735.py | 30 ++++++++++++------- examples/st7735_128x160_simpletest.py | 39 ++++++++++++++++++++++++ examples/st7735_simpletest.py | 43 ++++++++++++++++++--------- 3 files changed, 88 insertions(+), 24 deletions(-) create mode 100644 examples/st7735_128x160_simpletest.py diff --git a/adafruit_st7735/st7735.py b/adafruit_st7735/st7735.py index 3b38c20..8af3f1e 100755 --- a/adafruit_st7735/st7735.py +++ b/adafruit_st7735/st7735.py @@ -125,36 +125,46 @@ b"\x29\x80\x64" # _DISPON ) -_INIT_ROTATE_160X80 = ( +_INIT_R4_GREEN_160x80 = ( b"\x36\x01\x68" # _MADCTL Rotate to Landscape Mode ) +_INIT_R4_BLACK = ( + b"\x36\x01\xC0" # _MADCTL Rotate to Landscape Mode +) + # pylint: disable=too-few-public-methods class ST7735(displayio.Display): """ST7735 driver for ST7735R Green tabs""" def __init__(self, bus, *, width, height): - init_sequence = _INIT_R1 + _INIT_R2_GREEN + _INIT_R3 - super().__init__(bus, init_sequence, width=width, height=height, colstart=2, rowstart=1) + _INIT_SEQUENCE = _INIT_R1 + _INIT_R2_GREEN + _INIT_R3 + super().__init__(bus, _INIT_SEQUENCE, width=width, height=height, colstart=2, rowstart=1) class ST7735R_GREEN144(displayio.Display): """ST7735 driver for ST7735R Green tabs 1.44-inch""" def __init__(self, bus, *, width, height): - init_sequence = _INIT_R1 + _INIT_R2_GREEN + _INIT_R3 - super().__init__(bus, init_sequence, width=width, height=height, colstart=2, rowstart=3) + _INIT_SEQUENCE = _INIT_R1 + _INIT_R2_GREEN + _INIT_R3 + super().__init__(bus, _INIT_SEQUENCE, width=width, height=height, colstart=2, rowstart=3) class ST7735R_RED(displayio.Display): """ST7735 driver for ST7735R Red tabs""" def __init__(self, bus, *, width, height): - init_sequence = _INIT_R1 + _INIT_R2_RED + _INIT_R3 - super().__init__(bus, init_sequence, width=width, height=height) + _INIT_SEQUENCE = _INIT_R1 + _INIT_R2_RED + _INIT_R3 + super().__init__(bus, _INIT_SEQUENCE, width=width, height=height) + +class ST7735R_BLACK(displayio.Display): + """ST7735 driver for ST7735R Red tabs""" + def __init__(self, bus, *, width, height): + _INIT_SEQUENCE = _INIT_R1 + _INIT_R2_RED + _INIT_R3 + _INIT_R4_BLACK + super().__init__(bus, _INIT_SEQUENCE, width=width, height=height) class ST7735B(displayio.Display): """ST7735 driver for ST7735B""" def __init__(self, bus, *, width, height): super().__init__(bus, _INIT_SEQUENCE_B, width=width, height=height) -class MINI160x80(displayio.Display): +class MINI160X80(displayio.Display): """ST7735 driver for MINI160x80""" def __init__(self, bus): - init_sequence = _INIT_R1 + _INIT_R2_GREEN_160X80 + _INIT_R3 + _INIT_ROTATE_160X80 - super().__init__(bus, init_sequence, width=160, height=80, rowstart=24) + _INIT_SEQUENCE = _INIT_R1 + _INIT_R2_GREEN_160X80 + _INIT_R3 + _INIT_R4_GREEN_160x80 + super().__init__(bus, _INIT_SEQUENCE, width=160, height=80, rowstart=24) diff --git a/examples/st7735_128x160_simpletest.py b/examples/st7735_128x160_simpletest.py new file mode 100644 index 0000000..934784d --- /dev/null +++ b/examples/st7735_128x160_simpletest.py @@ -0,0 +1,39 @@ +""" +This test will initialize the display using displayio +and draw a solid red background +""" + +import board +import displayio +from adafruit_seesaw.seesaw import Seesaw +import adafruit_st7735.st7735 as st7735 + +spi = board.SPI() +tft_cs = board.D5 +tft_dc = board.D6 + +displayio.release_displays() +display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) + +display = st7735.ST7735R_BLACK(display_bus, width=128, height=160) + +# Make the display context +splash = displayio.Group(max_size=10) +display.show(splash) + +color_bitmap = displayio.Bitmap(320, 240, 1) +color_palette = displayio.Palette(1) +color_palette[0] = 0xFF0000 + +try: + bg_sprite = displayio.TileGrid(color_bitmap, + pixel_shader=color_palette, + position=(0, 0)) +except TypeError: + bg_sprite = displayio.TileGrid(color_bitmap, + pixel_shader=color_palette, + x=0, y=0) +splash.append(bg_sprite) + +while True: + pass diff --git a/examples/st7735_simpletest.py b/examples/st7735_simpletest.py index 42886e6..a2f36b3 100644 --- a/examples/st7735_simpletest.py +++ b/examples/st7735_simpletest.py @@ -1,24 +1,39 @@ """ -This example will test out the display on the ST7735 Display +This test will initialize the display using displayio +and draw a solid red background """ -import time + import board -import busio import displayio +from adafruit_seesaw.seesaw import Seesaw import adafruit_st7735.st7735 as st7735 +spi = board.SPI() +tft_cs = board.D5 +tft_dc = board.D6 + displayio.release_displays() +display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) + +display = st7735.ST7735(display_bus, width=128, height=128) + +# Make the display context +splash = displayio.Group(max_size=10) +display.show(splash) -spi = busio.SPI(board.SCL, board.SDA) -bus = displayio.FourWire(spi, chip_select=board.D9, command=board.D7, reset=board.D8) -display = st7735.ST7735(bus, width=128, height=128) +color_bitmap = displayio.Bitmap(320, 240, 1) +color_palette = displayio.Palette(1) +color_palette[0] = 0xFF0000 -s = displayio.Shape(10, 10) -p = displayio.Palette(2) -p[1] = 0xff0000 -s = displayio.TileGrid(s, pixel_shader=p, x=0, y=0) -everything = displayio.Group(max_size=10) -everything.append(s) -display.show(everything) +try: + bg_sprite = displayio.TileGrid(color_bitmap, + pixel_shader=color_palette, + position=(0, 0)) +except TypeError: + bg_sprite = displayio.TileGrid(color_bitmap, + pixel_shader=color_palette, + x=0, y=0) +splash.append(bg_sprite) -time.sleep(10) +while True: + pass From 040d4ea6ee2d2fc65784e99041c1663f7936129e Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 20 Mar 2019 22:10:12 -0700 Subject: [PATCH 10/24] Linting --- adafruit_st7735/st7735.py | 18 +++++++++--------- examples/st7735_miniTFT_simpletest.py | 23 ++++++++++++++++++++++- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/adafruit_st7735/st7735.py b/adafruit_st7735/st7735.py index 8af3f1e..e3471e1 100755 --- a/adafruit_st7735/st7735.py +++ b/adafruit_st7735/st7735.py @@ -137,23 +137,23 @@ class ST7735(displayio.Display): """ST7735 driver for ST7735R Green tabs""" def __init__(self, bus, *, width, height): - _INIT_SEQUENCE = _INIT_R1 + _INIT_R2_GREEN + _INIT_R3 - super().__init__(bus, _INIT_SEQUENCE, width=width, height=height, colstart=2, rowstart=1) + init_sequence = _INIT_R1 + _INIT_R2_GREEN + _INIT_R3 + super().__init__(bus, init_sequence, width=width, height=height, colstart=2, rowstart=1) class ST7735R_GREEN144(displayio.Display): """ST7735 driver for ST7735R Green tabs 1.44-inch""" def __init__(self, bus, *, width, height): - _INIT_SEQUENCE = _INIT_R1 + _INIT_R2_GREEN + _INIT_R3 - super().__init__(bus, _INIT_SEQUENCE, width=width, height=height, colstart=2, rowstart=3) + init_sequence = _INIT_R1 + _INIT_R2_GREEN + _INIT_R3 + super().__init__(bus, init_sequence, width=width, height=height, colstart=2, rowstart=3) class ST7735R_RED(displayio.Display): """ST7735 driver for ST7735R Red tabs""" def __init__(self, bus, *, width, height): - _INIT_SEQUENCE = _INIT_R1 + _INIT_R2_RED + _INIT_R3 - super().__init__(bus, _INIT_SEQUENCE, width=width, height=height) + init_sequence = _INIT_R1 + _INIT_R2_RED + _INIT_R3 + super().__init__(bus, init_sequence, width=width, height=height) class ST7735R_BLACK(displayio.Display): - """ST7735 driver for ST7735R Red tabs""" + """ST7735 driver for ST7735R Black tabs""" def __init__(self, bus, *, width, height): _INIT_SEQUENCE = _INIT_R1 + _INIT_R2_RED + _INIT_R3 + _INIT_R4_BLACK super().__init__(bus, _INIT_SEQUENCE, width=width, height=height) @@ -166,5 +166,5 @@ def __init__(self, bus, *, width, height): class MINI160X80(displayio.Display): """ST7735 driver for MINI160x80""" def __init__(self, bus): - _INIT_SEQUENCE = _INIT_R1 + _INIT_R2_GREEN_160X80 + _INIT_R3 + _INIT_R4_GREEN_160x80 - super().__init__(bus, _INIT_SEQUENCE, width=160, height=80, rowstart=24) + init_sequence = _INIT_R1 + _INIT_R2_GREEN_160X80 + _INIT_R3 + _INIT_R4_GREEN_160x80 + super().__init__(bus, init_sequence, width=160, height=80, rowstart=24) diff --git a/examples/st7735_miniTFT_simpletest.py b/examples/st7735_miniTFT_simpletest.py index c8e7765..aa6a7ba 100644 --- a/examples/st7735_miniTFT_simpletest.py +++ b/examples/st7735_miniTFT_simpletest.py @@ -19,4 +19,25 @@ display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) ss.digital_write(reset_pin, True) -display = st7735.MINI160x80(display_bus) +display = st7735.MINI160X80(display_bus) + +# Make the display context +splash = displayio.Group(max_size=10) +display.show(splash) + +color_bitmap = displayio.Bitmap(320, 240, 1) +color_palette = displayio.Palette(1) +color_palette[0] = 0xFF0000 + +try: + bg_sprite = displayio.TileGrid(color_bitmap, + pixel_shader=color_palette, + position=(0, 0)) +except TypeError: + bg_sprite = displayio.TileGrid(color_bitmap, + pixel_shader=color_palette, + x=0, y=0) +splash.append(bg_sprite) + +while True: + pass From 29d10c86b5daffd431e94cb87047c0e93df7f171 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 20 Mar 2019 22:13:16 -0700 Subject: [PATCH 11/24] Linting --- adafruit_st7735/st7735.py | 8 ++++---- examples/st7735_128x160_simpletest.py | 1 - examples/st7735_simpletest.py | 1 - 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/adafruit_st7735/st7735.py b/adafruit_st7735/st7735.py index e3471e1..e7aed60 100755 --- a/adafruit_st7735/st7735.py +++ b/adafruit_st7735/st7735.py @@ -125,7 +125,7 @@ b"\x29\x80\x64" # _DISPON ) -_INIT_R4_GREEN_160x80 = ( +_INIT_R4_GREEN_160X80 = ( b"\x36\x01\x68" # _MADCTL Rotate to Landscape Mode ) @@ -155,8 +155,8 @@ def __init__(self, bus, *, width, height): class ST7735R_BLACK(displayio.Display): """ST7735 driver for ST7735R Black tabs""" def __init__(self, bus, *, width, height): - _INIT_SEQUENCE = _INIT_R1 + _INIT_R2_RED + _INIT_R3 + _INIT_R4_BLACK - super().__init__(bus, _INIT_SEQUENCE, width=width, height=height) + init_sequence = _INIT_R1 + _INIT_R2_RED + _INIT_R3 + _INIT_R4_BLACK + super().__init__(bus, init_sequence, width=width, height=height) class ST7735B(displayio.Display): """ST7735 driver for ST7735B""" @@ -166,5 +166,5 @@ def __init__(self, bus, *, width, height): class MINI160X80(displayio.Display): """ST7735 driver for MINI160x80""" def __init__(self, bus): - init_sequence = _INIT_R1 + _INIT_R2_GREEN_160X80 + _INIT_R3 + _INIT_R4_GREEN_160x80 + init_sequence = _INIT_R1 + _INIT_R2_GREEN_160X80 + _INIT_R3 + _INIT_R4_GREEN_160X80 super().__init__(bus, init_sequence, width=160, height=80, rowstart=24) diff --git a/examples/st7735_128x160_simpletest.py b/examples/st7735_128x160_simpletest.py index 934784d..6643e8f 100644 --- a/examples/st7735_128x160_simpletest.py +++ b/examples/st7735_128x160_simpletest.py @@ -5,7 +5,6 @@ import board import displayio -from adafruit_seesaw.seesaw import Seesaw import adafruit_st7735.st7735 as st7735 spi = board.SPI() diff --git a/examples/st7735_simpletest.py b/examples/st7735_simpletest.py index a2f36b3..c1252d1 100644 --- a/examples/st7735_simpletest.py +++ b/examples/st7735_simpletest.py @@ -5,7 +5,6 @@ import board import displayio -from adafruit_seesaw.seesaw import Seesaw import adafruit_st7735.st7735 as st7735 spi = board.SPI() From 39b75b979abf814e9e789849b6edb489d873efb1 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 20 Mar 2019 23:33:57 -0700 Subject: [PATCH 12/24] Removed ST7789. Bug Fixes for MiniTFT. --- .../st7735.py => adafruit_st7735.py | 4 +- adafruit_st7735/__init__.py | 0 adafruit_st7735/st7789.py | 76 ------------------- examples/st7735_128x160_simpletest.py | 4 +- examples/st7735_miniTFT_simpletest.py | 4 +- examples/st7735_simpletest.py | 4 +- 6 files changed, 8 insertions(+), 84 deletions(-) rename adafruit_st7735/st7735.py => adafruit_st7735.py (98%) delete mode 100755 adafruit_st7735/__init__.py delete mode 100755 adafruit_st7735/st7789.py diff --git a/adafruit_st7735/st7735.py b/adafruit_st7735.py similarity index 98% rename from adafruit_st7735/st7735.py rename to adafruit_st7735.py index e7aed60..9c2eb4e 100755 --- a/adafruit_st7735/st7735.py +++ b/adafruit_st7735.py @@ -21,7 +21,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. """ -`adafruit_st7735.st7735` +`adafruit_st7735` ==================================================== Displayio driver for ST7735 based displays. @@ -126,7 +126,7 @@ ) _INIT_R4_GREEN_160X80 = ( - b"\x36\x01\x68" # _MADCTL Rotate to Landscape Mode + b"\x36\x01\x60" # _MADCTL Rotate to Landscape Mode ) _INIT_R4_BLACK = ( diff --git a/adafruit_st7735/__init__.py b/adafruit_st7735/__init__.py deleted file mode 100755 index e69de29..0000000 diff --git a/adafruit_st7735/st7789.py b/adafruit_st7735/st7789.py deleted file mode 100755 index f3b9886..0000000 --- a/adafruit_st7735/st7789.py +++ /dev/null @@ -1,76 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2019 Melissa LeBlanc-Williams for Adafruit Industries LLC -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -""" -`adafruit_st7735.st7789` -==================================================== - -Displayio driver for ST7789 based displays. - -* Author(s): Melissa LeBlanc-Williams - -Implementation Notes --------------------- - -**Hardware:** - -* Adafruit 1.54" 240x240 Wide Angle TFT LCD Display with MicroSD: - https://www.adafruit.com/product/3787 - -**Software and Dependencies:** - -* Adafruit CircuitPython firmware for the supported boards: - https://github.com/adafruit/circuitpython/releases - -""" - -import displayio - -__version__ = "0.0.0-auto.0" -__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ST7735.git" - -_INIT_SEQUENCE = ( - b"\x01\x80\x32" # _SWRESET and Delay 50ms - b"\x11\x80\xFF" # _SLPOUT - b"\x3A\x81\x05\x0A" # _COLMOD - b"\xB1\x83\x00\x06\x03\x0A" # _FRMCTR1 - b"\x36\x01\x08" # _MADCTL - b"\xB6\x02\x15\x02" # _DISSET5 - #1 clk cycle nonoverlap, 2 cycle gate, rise, 3 cycle osc equalize, Fix on VTL - b"\xB4\x01\x00" # _INVCTR line inversion - b"\xC0\x82\x02\x70\x0A" # _PWCTR1 GVDD = 4.7V, 1.0uA, 10 ms delay - b"\xC1\x01\x05" # _PWCTR2 VGH = 14.7V, VGL = -7.35V - b"\xC2\x02\x01\x02" # _PWCTR3 Opamp current small, Boost frequency - b"\xC5\x82\x3C\x38\x0A" # _VMCTR1 - b"\xFC\x02\x11\x15" # _PWCTR6 - b"\xE0\x10\x09\x16\x09\x20\x21\x1B\x13\x19\x17\x15\x1E\x2B\x04\x05\x02\x0E" # _GMCTRP1 Gamma - b"\xE1\x90\x0B\x14\x08\x1E\x22\x1D\x18\x1E\x1B\x1A\x24\x2B\x06\x06\x02\x0F\x0A" # _GMCTRN1 - b"\x2a\x00\x02\x00\x81" # _CASET - b"\x2b\x00\x02\x00\x81" # _RASET - b"\x13\x80\x0a" # _NORON - b"\x29\x80\xFF" # _DISPON -) - -# pylint: disable=too-few-public-methods -class ST7789(displayio.Display): - """ST7789 driver""" - def __init__(self, bus, *, width, height): - super().__init__(bus, _INIT_SEQUENCE, width=width, height=height, colstart=2, rowstart=1) diff --git a/examples/st7735_128x160_simpletest.py b/examples/st7735_128x160_simpletest.py index 6643e8f..15f81b7 100644 --- a/examples/st7735_128x160_simpletest.py +++ b/examples/st7735_128x160_simpletest.py @@ -5,7 +5,7 @@ import board import displayio -import adafruit_st7735.st7735 as st7735 +from adafruit_st7735 import ST7735R_BLACK spi = board.SPI() tft_cs = board.D5 @@ -14,7 +14,7 @@ displayio.release_displays() display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) -display = st7735.ST7735R_BLACK(display_bus, width=128, height=160) +display = ST7735R_BLACK(display_bus, width=128, height=160) # Make the display context splash = displayio.Group(max_size=10) diff --git a/examples/st7735_miniTFT_simpletest.py b/examples/st7735_miniTFT_simpletest.py index aa6a7ba..4e2b47c 100644 --- a/examples/st7735_miniTFT_simpletest.py +++ b/examples/st7735_miniTFT_simpletest.py @@ -4,7 +4,7 @@ import board import displayio from adafruit_seesaw.seesaw import Seesaw -import adafruit_st7735.st7735 as st7735 +from adafruit_st7735 import MINI160X80 reset_pin = 8 i2c = board.I2C() @@ -19,7 +19,7 @@ display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) ss.digital_write(reset_pin, True) -display = st7735.MINI160X80(display_bus) +display = MINI160X80(display_bus) # Make the display context splash = displayio.Group(max_size=10) diff --git a/examples/st7735_simpletest.py b/examples/st7735_simpletest.py index c1252d1..2b31181 100644 --- a/examples/st7735_simpletest.py +++ b/examples/st7735_simpletest.py @@ -5,7 +5,7 @@ import board import displayio -import adafruit_st7735.st7735 as st7735 +from adafruit_st7735 import ST7735 spi = board.SPI() tft_cs = board.D5 @@ -14,7 +14,7 @@ displayio.release_displays() display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) -display = st7735.ST7735(display_bus, width=128, height=128) +display = ST7735(display_bus, width=128, height=128) # Make the display context splash = displayio.Group(max_size=10) From f4b6c8d21c24fb61f0582d4ae2ed1707487af08b Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 20 Mar 2019 23:37:05 -0700 Subject: [PATCH 13/24] Fixed pylint command --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1f85eca..143f8ad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,7 @@ install: - pip install --force-reinstall pylint==1.9.2 script: - - pylint adafruit_st7735/*.py + - pylint adafruit_st7735.py - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py) - circuitpython-build-bundles --filename_prefix adafruit-circuitpython-st7735 --library_location . - cd docs && sphinx-build -E -W -b html . _build/html && cd .. From 0fe8bda7c1322f5e6c6de1dc8fc488683c90f899 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 20 Mar 2019 23:41:23 -0700 Subject: [PATCH 14/24] Final details --- CODE_OF_CONDUCT.md | 4 ++-- README.rst | 6 +++--- docs/api.rst | 5 +---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 8ee6e44..7ca3a1d 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -41,7 +41,7 @@ Examples of unacceptable behavior by participants include: The goal of the standards and moderation guidelines outlined here is to build and maintain a respectful community. We ask that you don’t just aim to be -"technically unimpeachable", but rather try to be your best self. +"technically unimpeachable", but rather try to be your best self. We value many things beyond technical expertise, including collaboration and supporting others within our community. Providing a positive experience for @@ -72,7 +72,7 @@ You may report in the following ways: In any situation, you may send an email to . On the Adafruit Discord, you may send an open message from any channel -to all Community Helpers by tagging @community helpers. You may also send an +to all Community Helpers by tagging @community moderators. You may also send an open message from any channel, or a direct message to @kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or @Andon#8175. diff --git a/README.rst b/README.rst index 156addb..cb0f1b4 100644 --- a/README.rst +++ b/README.rst @@ -13,7 +13,7 @@ Introduction :target: https://travis-ci.com/adafruit/Adafruit_CircuitPython_ST7735 :alt: Build Status -displayio driver for ST7735 and ST7789 TFT-LCD displays. +displayio driver for ST7735 TFT-LCD displays. Dependencies ============= @@ -30,7 +30,7 @@ Usage Example .. code-block:: python - import adafruit_st7735 + from adafruit_st7735 import ST7735 import board import busio import displayio @@ -40,7 +40,7 @@ Usage Example spi = busio.SPI(board.SCL, board.SDA) bus = displayio.FourWire(spi, chip_select=board.D9, command=board.D7, reset=board.D8) - display = adafruit_st7735.ST7735(bus, width=128, height=128) + display = ST7735(bus, width=128, height=128) s = displayio.Shape(10, 10) p = displayio.Palette(2) diff --git a/docs/api.rst b/docs/api.rst index d31e16f..1edfad7 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -4,8 +4,5 @@ .. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py) .. use this format as the module name: "adafruit_foo.foo" -.. automodule:: adafruit_st7735.st7735 +.. automodule:: adafruit_st7735 :members: - -.. automodule:: adafruit_st7735.st7789 - :members: From 8690f945f187d5d884a22871d05dfc1d537ed3bf Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 21 Mar 2019 00:03:18 -0700 Subject: [PATCH 15/24] Removed ST7789 Product Link --- docs/index.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index 7154076..247238d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -31,7 +31,6 @@ Table of Contents 1.8" Color TFT LCD display with MicroSD Card Breakout Adafruit 1.44" Color TFT LCD Display with MicroSD Card breakout Adafruit Mini Color TFT with Joystick FeatherWing - Adafruit 1.54" 240x240 Wide Angle TFT LCD Display with MicroSD .. toctree:: :caption: Other Links From 6921f757acb7ea19936a3379b31a15b1e8975830 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 21 Mar 2019 00:11:55 -0700 Subject: [PATCH 16/24] Fixed example Bitmap Size --- examples/st7735_128x160_simpletest.py | 2 +- examples/st7735_miniTFT_simpletest.py | 2 +- examples/st7735_simpletest.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/st7735_128x160_simpletest.py b/examples/st7735_128x160_simpletest.py index 15f81b7..67538ed 100644 --- a/examples/st7735_128x160_simpletest.py +++ b/examples/st7735_128x160_simpletest.py @@ -20,7 +20,7 @@ splash = displayio.Group(max_size=10) display.show(splash) -color_bitmap = displayio.Bitmap(320, 240, 1) +color_bitmap = displayio.Bitmap(128, 160, 1) color_palette = displayio.Palette(1) color_palette[0] = 0xFF0000 diff --git a/examples/st7735_miniTFT_simpletest.py b/examples/st7735_miniTFT_simpletest.py index 4e2b47c..d76c7a2 100644 --- a/examples/st7735_miniTFT_simpletest.py +++ b/examples/st7735_miniTFT_simpletest.py @@ -25,7 +25,7 @@ splash = displayio.Group(max_size=10) display.show(splash) -color_bitmap = displayio.Bitmap(320, 240, 1) +color_bitmap = displayio.Bitmap(160, 80, 1) color_palette = displayio.Palette(1) color_palette[0] = 0xFF0000 diff --git a/examples/st7735_simpletest.py b/examples/st7735_simpletest.py index 2b31181..9f0711b 100644 --- a/examples/st7735_simpletest.py +++ b/examples/st7735_simpletest.py @@ -20,7 +20,7 @@ splash = displayio.Group(max_size=10) display.show(splash) -color_bitmap = displayio.Bitmap(320, 240, 1) +color_bitmap = displayio.Bitmap(128, 128, 1) color_palette = displayio.Palette(1) color_palette[0] = 0xFF0000 From 521dabe262633ac6eeb27d7f6a97661f09b4c715 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 21 Mar 2019 22:36:09 -0700 Subject: [PATCH 17/24] Changes requested by tannewt --- .travis.yml | 2 +- adafruit_st7735.py | 170 -------------------------- adafruit_st7735/st7735b.py | 74 +++++++++++ adafruit_st7735/st7735r.py | 93 ++++++++++++++ docs/api.rst | 5 +- examples/st7735_128x160_simpletest.py | 4 +- examples/st7735_miniTFT_simpletest.py | 5 +- examples/st7735_simpletest.py | 4 +- 8 files changed, 179 insertions(+), 178 deletions(-) delete mode 100755 adafruit_st7735.py create mode 100755 adafruit_st7735/st7735b.py create mode 100755 adafruit_st7735/st7735r.py diff --git a/.travis.yml b/.travis.yml index 143f8ad..1f85eca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,7 @@ install: - pip install --force-reinstall pylint==1.9.2 script: - - pylint adafruit_st7735.py + - pylint adafruit_st7735/*.py - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py) - circuitpython-build-bundles --filename_prefix adafruit-circuitpython-st7735 --library_location . - cd docs && sphinx-build -E -W -b html . _build/html && cd .. diff --git a/adafruit_st7735.py b/adafruit_st7735.py deleted file mode 100755 index 9c2eb4e..0000000 --- a/adafruit_st7735.py +++ /dev/null @@ -1,170 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2019 Scott Shawcroft and Melissa LeBlanc-Williams -# for Adafruit Industries LLC -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -""" -`adafruit_st7735` -==================================================== - -Displayio driver for ST7735 based displays. - -* Author(s): Scott Shawcroft and Melissa LeBlanc-Williams - -Implementation Notes --------------------- - -**Hardware:** - -* 1.8" SPI TFT display, 160x128 18-bit color: - https://www.adafruit.com/product/618 -* Adafruit 0.96" 160x80 Color TFT Display w/ MicroSD Card Breakout: - https://www.adafruit.com/product/3533 -* 1.8" Color TFT LCD display with MicroSD Card Breakout: - https://www.adafruit.com/product/358 -* Adafruit 1.44" Color TFT LCD Display with MicroSD Card breakout: - https://www.adafruit.com/product/2088 -* Adafruit Mini Color TFT with Joystick FeatherWing: - https://www.adafruit.com/product/3321 - -**Software and Dependencies:** - -* Adafruit CircuitPython firmware for the supported boards: - https://github.com/adafruit/circuitpython/releases - -""" - -import displayio - -__version__ = "0.0.0-auto.0" -__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ST7735.git" - -_INIT_SEQUENCE_B = ( - b"\x01\x80\x32" # _SWRESET and Delay 50ms - b"\x11\x80\xFF" # _SLPOUT - b"\x3A\x81\x05\x0A" # _COLMOD - b"\xB1\x83\x00\x06\x03\x0A" # _FRMCTR1 - b"\x36\x01\x08" # _MADCTL - b"\xB6\x02\x15\x02" # _DISSET5 - #1 clk cycle nonoverlap, 2 cycle gate, rise, 3 cycle osc equalize, Fix on VTL - b"\xB4\x01\x00" # _INVCTR line inversion - b"\xC0\x82\x02\x70\x0A" # _PWCTR1 GVDD = 4.7V, 1.0uA, 10 ms delay - b"\xC1\x01\x05" # _PWCTR2 VGH = 14.7V, VGL = -7.35V - b"\xC2\x02\x01\x02" # _PWCTR3 Opamp current small, Boost frequency - b"\xC5\x82\x3C\x38\x0A" # _VMCTR1 - b"\xFC\x02\x11\x15" # _PWCTR6 - b"\xE0\x10\x09\x16\x09\x20\x21\x1B\x13\x19\x17\x15\x1E\x2B\x04\x05\x02\x0E" # _GMCTRP1 Gamma - b"\xE1\x90\x0B\x14\x08\x1E\x22\x1D\x18\x1E\x1B\x1A\x24\x2B\x06\x06\x02\x0F\x0A" # _GMCTRN1 - b"\x2a\x00\x02\x00\x81" # _CASET - b"\x2b\x00\x02\x00\x81" # _RASET - b"\x13\x80\x0a" # _NORON - b"\x29\x80\xFF" # _DISPON -) - -_INIT_R1 = ( - b"\x01\x80\x96" # SWRESET and Delay 150ms - b"\x11\x80\xff" # SLPOUT and Delay - b"\xb1\x03\x01\x2C\x2D" # _FRMCTR1 - b"\xb2\x03\x01\x2C\x2D" # _FRMCTR2 - b"\xb3\x06\x01\x2C\x2D\x01\x2C\x2D" # _FRMCTR3 - b"\xb4\x01\x07" # _INVCTR line inversion - b"\xc0\x03\xa2\x02\x84" # _PWCTR1 GVDD = 4.7V, 1.0uA - b"\xc1\x01\xc5" # _PWCTR2 VGH=14.7V, VGL=-7.35V - b"\xc2\x02\x0a\x00" # _PWCTR3 Opamp current small, Boost frequency - b"\xc3\x02\x8a\x2a" - b"\xc4\x02\x8a\xee" - b"\xc5\x01\x0e" # _VMCTR1 VCOMH = 4V, VOML = -1.1V - b"\x2a\x00" # _INVOFF - b"\x36\x01\x18" # _MADCTL bottom to top refresh - # 1 clk cycle nonoverlap, 2 cycle gate rise, 3 sycle osc equalie, - # fix on VTL - b"\x3a\x01\x05" # COLMOD - 16bit color -) - -_INIT_R2_GREEN = ( - b"\x2a\x03\x02\x00\x81" # _CASET XSTART = 2, XEND = 129 - b"\x2b\x03\x02\x00\x81" # _RASET XSTART = 2, XEND = 129 -) - -_INIT_R2_RED = ( - b"\x2a\x00\x00\x00\x7F" # _CASET XSTART = 0, XEND = 127 - b"\x2b\x00\x00\x00\x9F" # _RASET XSTART = 0, XEND = 159 -) - -_INIT_R2_GREEN_144 = ( - b"\x2a\x00\x00\x00\x7F" # _CASET XSTART = 0, XEND = 127 - b"\x2b\x00\x00\x00\x7F" # _RASET XSTART = 0, XEND = 127 -) - -_INIT_R2_GREEN_160X80 = ( - b"\x2a\x00\x00\x00\x4F" # _CASET XSTART = 0, XEND = 79 - b"\x2b\x00\x00\x00\x9F" # _RASET XSTART = 0, XEND = 159 -) - -_INIT_R3 = ( - b"\xe0\x10\x02\x1c\x07\x12\x37\x32\x29\x2d\x29\x25\x2B\x39\x00\x01\x03\x10" # _GMCTRP1 Gamma - b"\xe1\x10\x03\x1d\x07\x06\x2E\x2C\x29\x2D\x2E\x2E\x37\x3F\x00\x00\x02\x10" # _GMCTRN1 - b"\x13\x80\x0a" # _NORON - b"\x29\x80\x64" # _DISPON -) - -_INIT_R4_GREEN_160X80 = ( - b"\x36\x01\x60" # _MADCTL Rotate to Landscape Mode -) - -_INIT_R4_BLACK = ( - b"\x36\x01\xC0" # _MADCTL Rotate to Landscape Mode -) - -# pylint: disable=too-few-public-methods -class ST7735(displayio.Display): - """ST7735 driver for ST7735R Green tabs""" - def __init__(self, bus, *, width, height): - init_sequence = _INIT_R1 + _INIT_R2_GREEN + _INIT_R3 - super().__init__(bus, init_sequence, width=width, height=height, colstart=2, rowstart=1) - -class ST7735R_GREEN144(displayio.Display): - """ST7735 driver for ST7735R Green tabs 1.44-inch""" - def __init__(self, bus, *, width, height): - init_sequence = _INIT_R1 + _INIT_R2_GREEN + _INIT_R3 - super().__init__(bus, init_sequence, width=width, height=height, colstart=2, rowstart=3) - -class ST7735R_RED(displayio.Display): - """ST7735 driver for ST7735R Red tabs""" - def __init__(self, bus, *, width, height): - init_sequence = _INIT_R1 + _INIT_R2_RED + _INIT_R3 - super().__init__(bus, init_sequence, width=width, height=height) - -class ST7735R_BLACK(displayio.Display): - """ST7735 driver for ST7735R Black tabs""" - def __init__(self, bus, *, width, height): - init_sequence = _INIT_R1 + _INIT_R2_RED + _INIT_R3 + _INIT_R4_BLACK - super().__init__(bus, init_sequence, width=width, height=height) - -class ST7735B(displayio.Display): - """ST7735 driver for ST7735B""" - def __init__(self, bus, *, width, height): - super().__init__(bus, _INIT_SEQUENCE_B, width=width, height=height) - -class MINI160X80(displayio.Display): - """ST7735 driver for MINI160x80""" - def __init__(self, bus): - init_sequence = _INIT_R1 + _INIT_R2_GREEN_160X80 + _INIT_R3 + _INIT_R4_GREEN_160X80 - super().__init__(bus, init_sequence, width=160, height=80, rowstart=24) diff --git a/adafruit_st7735/st7735b.py b/adafruit_st7735/st7735b.py new file mode 100755 index 0000000..d262220 --- /dev/null +++ b/adafruit_st7735/st7735b.py @@ -0,0 +1,74 @@ +# The MIT License (MIT) +# +# Copyright (c) 2019 Scott Shawcroft and Melissa LeBlanc-Williams +# for Adafruit Industries LLC +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +""" +`adafruit_st7735.st7735b` +==================================================== + +Displayio driver for ST7735B based displays. + +* Author(s): Melissa LeBlanc-Williams + +Implementation Notes +-------------------- + +**Hardware:** + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://github.com/adafruit/circuitpython/releases + +""" + +import displayio + +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ST7735.git" + +_INIT_SEQUENCE = ( + b"\x01\x80\x32" # _SWRESET and Delay 50ms + b"\x11\x80\xFF" # _SLPOUT + b"\x3A\x81\x05\x0A" # _COLMOD + b"\xB1\x83\x00\x06\x03\x0A" # _FRMCTR1 + b"\x36\x01\x08" # _MADCTL + b"\xB6\x02\x15\x02" # _DISSET5 + #1 clk cycle nonoverlap, 2 cycle gate, rise, 3 cycle osc equalize, Fix on VTL + b"\xB4\x01\x00" # _INVCTR line inversion + b"\xC0\x82\x02\x70\x0A" # _PWCTR1 GVDD = 4.7V, 1.0uA, 10 ms delay + b"\xC1\x01\x05" # _PWCTR2 VGH = 14.7V, VGL = -7.35V + b"\xC2\x02\x01\x02" # _PWCTR3 Opamp current small, Boost frequency + b"\xC5\x82\x3C\x38\x0A" # _VMCTR1 + b"\xFC\x02\x11\x15" # _PWCTR6 + b"\xE0\x10\x09\x16\x09\x20\x21\x1B\x13\x19\x17\x15\x1E\x2B\x04\x05\x02\x0E" # _GMCTRP1 Gamma + b"\xE1\x90\x0B\x14\x08\x1E\x22\x1D\x18\x1E\x1B\x1A\x24\x2B\x06\x06\x02\x0F\x0A" # _GMCTRN1 + b"\x2a\x00\x02\x00\x81" # _CASET + b"\x2b\x00\x02\x00\x81" # _RASET + b"\x13\x80\x0a" # _NORON + b"\x29\x80\xFF" # _DISPON +) + +# pylint: disable=too-few-public-methods +class ST7735B(displayio.Display): + """ST7735 driver for ST7735B""" + def __init__(self, bus, **kwargs): + super().__init__(bus, _INIT_SEQUENCE, **kwargs) diff --git a/adafruit_st7735/st7735r.py b/adafruit_st7735/st7735r.py new file mode 100755 index 0000000..91f535b --- /dev/null +++ b/adafruit_st7735/st7735r.py @@ -0,0 +1,93 @@ +# The MIT License (MIT) +# +# Copyright (c) 2019 Scott Shawcroft and Melissa LeBlanc-Williams +# for Adafruit Industries LLC +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +""" +`adafruit_st7735.st7735r` +==================================================== + +Displayio driver for ST7735R based displays. + +* Author(s): Scott Shawcroft and Melissa LeBlanc-Williams + +Implementation Notes +-------------------- + +**Hardware:** + +* 1.8" SPI TFT display, 160x128 18-bit color: + https://www.adafruit.com/product/618 +* Adafruit 0.96" 160x80 Color TFT Display w/ MicroSD Card Breakout: + https://www.adafruit.com/product/3533 +* 1.8" Color TFT LCD display with MicroSD Card Breakout: + https://www.adafruit.com/product/358 +* Adafruit 1.44" Color TFT LCD Display with MicroSD Card breakout: + https://www.adafruit.com/product/2088 +* Adafruit Mini Color TFT with Joystick FeatherWing: + https://www.adafruit.com/product/3321 + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://github.com/adafruit/circuitpython/releases + +""" + +import displayio + +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ST7735.git" + +_INIT_SEQUENCE = bytearray( + b"\x01\x80\x96" # SWRESET and Delay 150ms + b"\x11\x80\xff" # SLPOUT and Delay + b"\xb1\x03\x01\x2C\x2D" # _FRMCTR1 + b"\xb2\x03\x01\x2C\x2D" # _FRMCTR2 + b"\xb3\x06\x01\x2C\x2D\x01\x2C\x2D" # _FRMCTR3 + b"\xb4\x01\x07" # _INVCTR line inversion + b"\xc0\x03\xa2\x02\x84" # _PWCTR1 GVDD = 4.7V, 1.0uA + b"\xc1\x01\xc5" # _PWCTR2 VGH=14.7V, VGL=-7.35V + b"\xc2\x02\x0a\x00" # _PWCTR3 Opamp current small, Boost frequency + b"\xc3\x02\x8a\x2a" + b"\xc4\x02\x8a\xee" + b"\xc5\x01\x0e" # _VMCTR1 VCOMH = 4V, VOML = -1.1V + b"\x20\x00" # _INVOFF + b"\x36\x01\x18" # _MADCTL bottom to top refresh + # 1 clk cycle nonoverlap, 2 cycle gate rise, 3 sycle osc equalie, + # fix on VTL + b"\x3a\x01\x05" # COLMOD - 16bit color + b"\xe0\x10\x02\x1c\x07\x12\x37\x32\x29\x2d\x29\x25\x2B\x39\x00\x01\x03\x10" # _GMCTRP1 Gamma + b"\xe1\x10\x03\x1d\x07\x06\x2E\x2C\x29\x2D\x2E\x2E\x37\x3F\x00\x00\x02\x10" # _GMCTRN1 + b"\x13\x80\x0a" # _NORON + b"\x29\x80\x64" # _DISPON +) + +# pylint: disable=too-few-public-methods +class ST7735R(displayio.Display): + """ST7735 driver for ST7735R""" + def __init__(self, bus, *, init=None, **kwargs): + """ + :param bytes init: (Optional) An extra init sequence to append (default=None) + """ + init_sequence = _INIT_SEQUENCE + if init is not None: + init_sequence += init + super().__init__(bus, init_sequence, **kwargs) diff --git a/docs/api.rst b/docs/api.rst index 1edfad7..940c664 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -4,5 +4,8 @@ .. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py) .. use this format as the module name: "adafruit_foo.foo" -.. automodule:: adafruit_st7735 +.. automodule:: adafruit_st7735.st7735r :members: + +.. automodule:: adafruit_st7735.st7735b + :members: diff --git a/examples/st7735_128x160_simpletest.py b/examples/st7735_128x160_simpletest.py index 67538ed..7fe9b5f 100644 --- a/examples/st7735_128x160_simpletest.py +++ b/examples/st7735_128x160_simpletest.py @@ -5,7 +5,7 @@ import board import displayio -from adafruit_st7735 import ST7735R_BLACK +from adafruit_st7735.st7735r import ST7735R spi = board.SPI() tft_cs = board.D5 @@ -14,7 +14,7 @@ displayio.release_displays() display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) -display = ST7735R_BLACK(display_bus, width=128, height=160) +display = ST7735R(display_bus, width=128, height=160, init=b"\x36\x01\xC0") # Make the display context splash = displayio.Group(max_size=10) diff --git a/examples/st7735_miniTFT_simpletest.py b/examples/st7735_miniTFT_simpletest.py index d76c7a2..e0084ec 100644 --- a/examples/st7735_miniTFT_simpletest.py +++ b/examples/st7735_miniTFT_simpletest.py @@ -3,8 +3,9 @@ """ import board import displayio +import digitalio from adafruit_seesaw.seesaw import Seesaw -from adafruit_st7735 import MINI160X80 +from adafruit_st7735.st7735r import ST7735R reset_pin = 8 i2c = board.I2C() @@ -19,7 +20,7 @@ display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) ss.digital_write(reset_pin, True) -display = MINI160X80(display_bus) +display = ST7735R(display_bus, width=160, height=80, rowstart=24, init=b"\x36\x01\x60") # Make the display context splash = displayio.Group(max_size=10) diff --git a/examples/st7735_simpletest.py b/examples/st7735_simpletest.py index 9f0711b..d71fa07 100644 --- a/examples/st7735_simpletest.py +++ b/examples/st7735_simpletest.py @@ -5,7 +5,7 @@ import board import displayio -from adafruit_st7735 import ST7735 +from adafruit_st7735.st7735r import ST7735R spi = board.SPI() tft_cs = board.D5 @@ -14,7 +14,7 @@ displayio.release_displays() display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) -display = ST7735(display_bus, width=128, height=128) +display = ST7735R(display_bus, width=128, height=128, colstart=2, rowstart=1) # Make the display context splash = displayio.Group(max_size=10) From e9c3636be2c37e450c1c2fe17f91b621923140c8 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 21 Mar 2019 22:39:22 -0700 Subject: [PATCH 18/24] Linting --- examples/st7735_miniTFT_simpletest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/st7735_miniTFT_simpletest.py b/examples/st7735_miniTFT_simpletest.py index e0084ec..170892b 100644 --- a/examples/st7735_miniTFT_simpletest.py +++ b/examples/st7735_miniTFT_simpletest.py @@ -3,7 +3,6 @@ """ import board import displayio -import digitalio from adafruit_seesaw.seesaw import Seesaw from adafruit_st7735.st7735r import ST7735R From 2c43ccb15f5d6a4bb9b67baccbae85f09e069aa2 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 22 Mar 2019 06:42:27 -0700 Subject: [PATCH 19/24] Removing unnecessary sizing code --- adafruit_st7735/st7735b.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/adafruit_st7735/st7735b.py b/adafruit_st7735/st7735b.py index d262220..688274e 100755 --- a/adafruit_st7735/st7735b.py +++ b/adafruit_st7735/st7735b.py @@ -61,8 +61,6 @@ b"\xFC\x02\x11\x15" # _PWCTR6 b"\xE0\x10\x09\x16\x09\x20\x21\x1B\x13\x19\x17\x15\x1E\x2B\x04\x05\x02\x0E" # _GMCTRP1 Gamma b"\xE1\x90\x0B\x14\x08\x1E\x22\x1D\x18\x1E\x1B\x1A\x24\x2B\x06\x06\x02\x0F\x0A" # _GMCTRN1 - b"\x2a\x00\x02\x00\x81" # _CASET - b"\x2b\x00\x02\x00\x81" # _RASET b"\x13\x80\x0a" # _NORON b"\x29\x80\xFF" # _DISPON ) From 7107fdb397038b05a6f6d3ece15e16cda5e2d64c Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 22 Mar 2019 06:44:59 -0700 Subject: [PATCH 20/24] Updated example in Readme --- README.rst | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/README.rst b/README.rst index cb0f1b4..54cedfd 100644 --- a/README.rst +++ b/README.rst @@ -30,27 +30,39 @@ Usage Example .. code-block:: python - from adafruit_st7735 import ST7735 import board - import busio import displayio - import time + from adafruit_st7735.st7735r import ST7735R - displayio.release_displays() - - spi = busio.SPI(board.SCL, board.SDA) - bus = displayio.FourWire(spi, chip_select=board.D9, command=board.D7, reset=board.D8) - display = ST7735(bus, width=128, height=128) + spi = board.SPI() + tft_cs = board.D5 + tft_dc = board.D6 - s = displayio.Shape(10, 10) - p = displayio.Palette(2) - p[1] = 0xff0000 - s = displayio.Sprite(s, pixel_shader=p, position=(0,0)) - everything = displayio.Group(max_size=10) - everything.append(s) - display.show(everything) - - time.sleep(10) + displayio.release_displays() + display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) + + display = ST7735R(display_bus, width=128, height=128, colstart=2, rowstart=1) + + # Make the display context + splash = displayio.Group(max_size=10) + display.show(splash) + + color_bitmap = displayio.Bitmap(128, 128, 1) + color_palette = displayio.Palette(1) + color_palette[0] = 0xFF0000 + + try: + bg_sprite = displayio.TileGrid(color_bitmap, + pixel_shader=color_palette, + position=(0, 0)) + except TypeError: + bg_sprite = displayio.TileGrid(color_bitmap, + pixel_shader=color_palette, + x=0, y=0) + splash.append(bg_sprite) + + while True: + pass Contributing ============ From 2cd7054303953c5c8b2223f8a3ae615b2ba2aee8 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 22 Mar 2019 18:05:10 -0700 Subject: [PATCH 21/24] Added example for Mini TFT breakout --- examples/st7735_miniTFT_simpletest.py | 9 +--- .../st7735_minitft_featherwing_simpletest.py | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 examples/st7735_minitft_featherwing_simpletest.py diff --git a/examples/st7735_miniTFT_simpletest.py b/examples/st7735_miniTFT_simpletest.py index 170892b..a629d7f 100644 --- a/examples/st7735_miniTFT_simpletest.py +++ b/examples/st7735_miniTFT_simpletest.py @@ -1,16 +1,10 @@ """ -This example will test out the display on the Mini TFT FeatherWing +This example will test out the display on the Mini TFT Breakout """ import board import displayio -from adafruit_seesaw.seesaw import Seesaw from adafruit_st7735.st7735r import ST7735R -reset_pin = 8 -i2c = board.I2C() -ss = Seesaw(i2c, 0x5E) -ss.pin_mode(reset_pin, ss.OUTPUT) - spi = board.SPI() tft_cs = board.D5 tft_dc = board.D6 @@ -18,7 +12,6 @@ displayio.release_displays() display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) -ss.digital_write(reset_pin, True) display = ST7735R(display_bus, width=160, height=80, rowstart=24, init=b"\x36\x01\x60") # Make the display context diff --git a/examples/st7735_minitft_featherwing_simpletest.py b/examples/st7735_minitft_featherwing_simpletest.py new file mode 100644 index 0000000..170892b --- /dev/null +++ b/examples/st7735_minitft_featherwing_simpletest.py @@ -0,0 +1,43 @@ +""" +This example will test out the display on the Mini TFT FeatherWing +""" +import board +import displayio +from adafruit_seesaw.seesaw import Seesaw +from adafruit_st7735.st7735r import ST7735R + +reset_pin = 8 +i2c = board.I2C() +ss = Seesaw(i2c, 0x5E) +ss.pin_mode(reset_pin, ss.OUTPUT) + +spi = board.SPI() +tft_cs = board.D5 +tft_dc = board.D6 + +displayio.release_displays() +display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) + +ss.digital_write(reset_pin, True) +display = ST7735R(display_bus, width=160, height=80, rowstart=24, init=b"\x36\x01\x60") + +# Make the display context +splash = displayio.Group(max_size=10) +display.show(splash) + +color_bitmap = displayio.Bitmap(160, 80, 1) +color_palette = displayio.Palette(1) +color_palette[0] = 0xFF0000 + +try: + bg_sprite = displayio.TileGrid(color_bitmap, + pixel_shader=color_palette, + position=(0, 0)) +except TypeError: + bg_sprite = displayio.TileGrid(color_bitmap, + pixel_shader=color_palette, + x=0, y=0) +splash.append(bg_sprite) + +while True: + pass From 1d3f15df91e055a7ff2da69a3ca9675280498325 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 22 Mar 2019 18:06:41 -0700 Subject: [PATCH 22/24] Removed unnecessary Reset Pin --- examples/st7735_minitft_featherwing_simpletest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/st7735_minitft_featherwing_simpletest.py b/examples/st7735_minitft_featherwing_simpletest.py index 170892b..0873e8b 100644 --- a/examples/st7735_minitft_featherwing_simpletest.py +++ b/examples/st7735_minitft_featherwing_simpletest.py @@ -16,7 +16,7 @@ tft_dc = board.D6 displayio.release_displays() -display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) +display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs) ss.digital_write(reset_pin, True) display = ST7735R(display_bus, width=160, height=80, rowstart=24, init=b"\x36\x01\x60") From 5662cb0bc3510a4955e153ef7f22b46136d1934b Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 27 Mar 2019 23:43:32 -0700 Subject: [PATCH 23/24] removed init byte code as an option --- adafruit_st7735/st7735r.py | 8 ++++---- examples/st7735_128x160_simpletest.py | 2 +- examples/st7735_miniTFT_simpletest.py | 2 +- examples/st7735_minitft_featherwing_simpletest.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/adafruit_st7735/st7735r.py b/adafruit_st7735/st7735r.py index 91f535b..5b37146 100755 --- a/adafruit_st7735/st7735r.py +++ b/adafruit_st7735/st7735r.py @@ -83,11 +83,11 @@ # pylint: disable=too-few-public-methods class ST7735R(displayio.Display): """ST7735 driver for ST7735R""" - def __init__(self, bus, *, init=None, **kwargs): + def __init__(self, bus, *, bgr=False, **kwargs): """ - :param bytes init: (Optional) An extra init sequence to append (default=None) + :param bool bgr: (Optional) An extra init sequence to append (default=False) """ init_sequence = _INIT_SEQUENCE - if init is not None: - init_sequence += init + if bgr: + init_sequence += b"\x36\x01\xC0" # _MADCTL Default rotation plus BGR encoding super().__init__(bus, init_sequence, **kwargs) diff --git a/examples/st7735_128x160_simpletest.py b/examples/st7735_128x160_simpletest.py index 7fe9b5f..ce3f25c 100644 --- a/examples/st7735_128x160_simpletest.py +++ b/examples/st7735_128x160_simpletest.py @@ -14,7 +14,7 @@ displayio.release_displays() display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) -display = ST7735R(display_bus, width=128, height=160, init=b"\x36\x01\xC0") +display = ST7735R(display_bus, width=128, height=160, bgr=True) # Make the display context splash = displayio.Group(max_size=10) diff --git a/examples/st7735_miniTFT_simpletest.py b/examples/st7735_miniTFT_simpletest.py index a629d7f..5af4fb6 100644 --- a/examples/st7735_miniTFT_simpletest.py +++ b/examples/st7735_miniTFT_simpletest.py @@ -12,7 +12,7 @@ displayio.release_displays() display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) -display = ST7735R(display_bus, width=160, height=80, rowstart=24, init=b"\x36\x01\x60") +display = ST7735R(display_bus, width=160, height=80, colstart=24, rotation=90, bgr=True) # Make the display context splash = displayio.Group(max_size=10) diff --git a/examples/st7735_minitft_featherwing_simpletest.py b/examples/st7735_minitft_featherwing_simpletest.py index 0873e8b..a09bd46 100644 --- a/examples/st7735_minitft_featherwing_simpletest.py +++ b/examples/st7735_minitft_featherwing_simpletest.py @@ -19,7 +19,7 @@ display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs) ss.digital_write(reset_pin, True) -display = ST7735R(display_bus, width=160, height=80, rowstart=24, init=b"\x36\x01\x60") +display = ST7735R(display_bus, width=160, height=80, colstart=24, rotation=270, bgr=True) # Make the display context splash = displayio.Group(max_size=10) From b984037ca47662650d45fc9dcfad7eb5ca8a8f2e Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 2 Apr 2019 21:37:58 -0700 Subject: [PATCH 24/24] Separated Driver and Examples --- .travis.yml | 2 +- README.rst | 4 +- .../st7735b.py => adafruit_st7735.py | 8 +- adafruit_st7735/st7735r.py | 93 ------------------- docs/api.rst | 5 +- examples/st7735_128x160_simpletest.py | 38 -------- examples/st7735_miniTFT_simpletest.py | 36 ------- .../st7735_minitft_featherwing_simpletest.py | 43 --------- examples/st7735_simpletest.py | 4 +- 9 files changed, 10 insertions(+), 223 deletions(-) rename adafruit_st7735/st7735b.py => adafruit_st7735.py (94%) delete mode 100755 adafruit_st7735/st7735r.py delete mode 100644 examples/st7735_128x160_simpletest.py delete mode 100644 examples/st7735_miniTFT_simpletest.py delete mode 100644 examples/st7735_minitft_featherwing_simpletest.py diff --git a/.travis.yml b/.travis.yml index 1f85eca..143f8ad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,7 @@ install: - pip install --force-reinstall pylint==1.9.2 script: - - pylint adafruit_st7735/*.py + - pylint adafruit_st7735.py - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py) - circuitpython-build-bundles --filename_prefix adafruit-circuitpython-st7735 --library_location . - cd docs && sphinx-build -E -W -b html . _build/html && cd .. diff --git a/README.rst b/README.rst index 54cedfd..1104b2d 100644 --- a/README.rst +++ b/README.rst @@ -32,7 +32,7 @@ Usage Example import board import displayio - from adafruit_st7735.st7735r import ST7735R + from adafruit_st7735 import ST7735 spi = board.SPI() tft_cs = board.D5 @@ -41,7 +41,7 @@ Usage Example displayio.release_displays() display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) - display = ST7735R(display_bus, width=128, height=128, colstart=2, rowstart=1) + display = ST7735(display_bus, width=128, height=128) # Make the display context splash = displayio.Group(max_size=10) diff --git a/adafruit_st7735/st7735b.py b/adafruit_st7735.py similarity index 94% rename from adafruit_st7735/st7735b.py rename to adafruit_st7735.py index 688274e..9e9862c 100755 --- a/adafruit_st7735/st7735b.py +++ b/adafruit_st7735.py @@ -21,10 +21,10 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. """ -`adafruit_st7735.st7735b` +`adafruit_st7735` ==================================================== -Displayio driver for ST7735B based displays. +Displayio driver for ST7735 based displays. * Author(s): Melissa LeBlanc-Williams @@ -66,7 +66,7 @@ ) # pylint: disable=too-few-public-methods -class ST7735B(displayio.Display): - """ST7735 driver for ST7735B""" +class ST7735(displayio.Display): + """ST7735 driver""" def __init__(self, bus, **kwargs): super().__init__(bus, _INIT_SEQUENCE, **kwargs) diff --git a/adafruit_st7735/st7735r.py b/adafruit_st7735/st7735r.py deleted file mode 100755 index 5b37146..0000000 --- a/adafruit_st7735/st7735r.py +++ /dev/null @@ -1,93 +0,0 @@ -# The MIT License (MIT) -# -# Copyright (c) 2019 Scott Shawcroft and Melissa LeBlanc-Williams -# for Adafruit Industries LLC -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -""" -`adafruit_st7735.st7735r` -==================================================== - -Displayio driver for ST7735R based displays. - -* Author(s): Scott Shawcroft and Melissa LeBlanc-Williams - -Implementation Notes --------------------- - -**Hardware:** - -* 1.8" SPI TFT display, 160x128 18-bit color: - https://www.adafruit.com/product/618 -* Adafruit 0.96" 160x80 Color TFT Display w/ MicroSD Card Breakout: - https://www.adafruit.com/product/3533 -* 1.8" Color TFT LCD display with MicroSD Card Breakout: - https://www.adafruit.com/product/358 -* Adafruit 1.44" Color TFT LCD Display with MicroSD Card breakout: - https://www.adafruit.com/product/2088 -* Adafruit Mini Color TFT with Joystick FeatherWing: - https://www.adafruit.com/product/3321 - -**Software and Dependencies:** - -* Adafruit CircuitPython firmware for the supported boards: - https://github.com/adafruit/circuitpython/releases - -""" - -import displayio - -__version__ = "0.0.0-auto.0" -__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ST7735.git" - -_INIT_SEQUENCE = bytearray( - b"\x01\x80\x96" # SWRESET and Delay 150ms - b"\x11\x80\xff" # SLPOUT and Delay - b"\xb1\x03\x01\x2C\x2D" # _FRMCTR1 - b"\xb2\x03\x01\x2C\x2D" # _FRMCTR2 - b"\xb3\x06\x01\x2C\x2D\x01\x2C\x2D" # _FRMCTR3 - b"\xb4\x01\x07" # _INVCTR line inversion - b"\xc0\x03\xa2\x02\x84" # _PWCTR1 GVDD = 4.7V, 1.0uA - b"\xc1\x01\xc5" # _PWCTR2 VGH=14.7V, VGL=-7.35V - b"\xc2\x02\x0a\x00" # _PWCTR3 Opamp current small, Boost frequency - b"\xc3\x02\x8a\x2a" - b"\xc4\x02\x8a\xee" - b"\xc5\x01\x0e" # _VMCTR1 VCOMH = 4V, VOML = -1.1V - b"\x20\x00" # _INVOFF - b"\x36\x01\x18" # _MADCTL bottom to top refresh - # 1 clk cycle nonoverlap, 2 cycle gate rise, 3 sycle osc equalie, - # fix on VTL - b"\x3a\x01\x05" # COLMOD - 16bit color - b"\xe0\x10\x02\x1c\x07\x12\x37\x32\x29\x2d\x29\x25\x2B\x39\x00\x01\x03\x10" # _GMCTRP1 Gamma - b"\xe1\x10\x03\x1d\x07\x06\x2E\x2C\x29\x2D\x2E\x2E\x37\x3F\x00\x00\x02\x10" # _GMCTRN1 - b"\x13\x80\x0a" # _NORON - b"\x29\x80\x64" # _DISPON -) - -# pylint: disable=too-few-public-methods -class ST7735R(displayio.Display): - """ST7735 driver for ST7735R""" - def __init__(self, bus, *, bgr=False, **kwargs): - """ - :param bool bgr: (Optional) An extra init sequence to append (default=False) - """ - init_sequence = _INIT_SEQUENCE - if bgr: - init_sequence += b"\x36\x01\xC0" # _MADCTL Default rotation plus BGR encoding - super().__init__(bus, init_sequence, **kwargs) diff --git a/docs/api.rst b/docs/api.rst index 940c664..c795cf6 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -4,8 +4,5 @@ .. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py) .. use this format as the module name: "adafruit_foo.foo" -.. automodule:: adafruit_st7735.st7735r - :members: - -.. automodule:: adafruit_st7735.st7735b +.. automodule:: adafruit_st7735 :members: diff --git a/examples/st7735_128x160_simpletest.py b/examples/st7735_128x160_simpletest.py deleted file mode 100644 index ce3f25c..0000000 --- a/examples/st7735_128x160_simpletest.py +++ /dev/null @@ -1,38 +0,0 @@ -""" -This test will initialize the display using displayio -and draw a solid red background -""" - -import board -import displayio -from adafruit_st7735.st7735r import ST7735R - -spi = board.SPI() -tft_cs = board.D5 -tft_dc = board.D6 - -displayio.release_displays() -display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) - -display = ST7735R(display_bus, width=128, height=160, bgr=True) - -# Make the display context -splash = displayio.Group(max_size=10) -display.show(splash) - -color_bitmap = displayio.Bitmap(128, 160, 1) -color_palette = displayio.Palette(1) -color_palette[0] = 0xFF0000 - -try: - bg_sprite = displayio.TileGrid(color_bitmap, - pixel_shader=color_palette, - position=(0, 0)) -except TypeError: - bg_sprite = displayio.TileGrid(color_bitmap, - pixel_shader=color_palette, - x=0, y=0) -splash.append(bg_sprite) - -while True: - pass diff --git a/examples/st7735_miniTFT_simpletest.py b/examples/st7735_miniTFT_simpletest.py deleted file mode 100644 index 5af4fb6..0000000 --- a/examples/st7735_miniTFT_simpletest.py +++ /dev/null @@ -1,36 +0,0 @@ -""" -This example will test out the display on the Mini TFT Breakout -""" -import board -import displayio -from adafruit_st7735.st7735r import ST7735R - -spi = board.SPI() -tft_cs = board.D5 -tft_dc = board.D6 - -displayio.release_displays() -display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) - -display = ST7735R(display_bus, width=160, height=80, colstart=24, rotation=90, bgr=True) - -# Make the display context -splash = displayio.Group(max_size=10) -display.show(splash) - -color_bitmap = displayio.Bitmap(160, 80, 1) -color_palette = displayio.Palette(1) -color_palette[0] = 0xFF0000 - -try: - bg_sprite = displayio.TileGrid(color_bitmap, - pixel_shader=color_palette, - position=(0, 0)) -except TypeError: - bg_sprite = displayio.TileGrid(color_bitmap, - pixel_shader=color_palette, - x=0, y=0) -splash.append(bg_sprite) - -while True: - pass diff --git a/examples/st7735_minitft_featherwing_simpletest.py b/examples/st7735_minitft_featherwing_simpletest.py deleted file mode 100644 index a09bd46..0000000 --- a/examples/st7735_minitft_featherwing_simpletest.py +++ /dev/null @@ -1,43 +0,0 @@ -""" -This example will test out the display on the Mini TFT FeatherWing -""" -import board -import displayio -from adafruit_seesaw.seesaw import Seesaw -from adafruit_st7735.st7735r import ST7735R - -reset_pin = 8 -i2c = board.I2C() -ss = Seesaw(i2c, 0x5E) -ss.pin_mode(reset_pin, ss.OUTPUT) - -spi = board.SPI() -tft_cs = board.D5 -tft_dc = board.D6 - -displayio.release_displays() -display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs) - -ss.digital_write(reset_pin, True) -display = ST7735R(display_bus, width=160, height=80, colstart=24, rotation=270, bgr=True) - -# Make the display context -splash = displayio.Group(max_size=10) -display.show(splash) - -color_bitmap = displayio.Bitmap(160, 80, 1) -color_palette = displayio.Palette(1) -color_palette[0] = 0xFF0000 - -try: - bg_sprite = displayio.TileGrid(color_bitmap, - pixel_shader=color_palette, - position=(0, 0)) -except TypeError: - bg_sprite = displayio.TileGrid(color_bitmap, - pixel_shader=color_palette, - x=0, y=0) -splash.append(bg_sprite) - -while True: - pass diff --git a/examples/st7735_simpletest.py b/examples/st7735_simpletest.py index d71fa07..9f0711b 100644 --- a/examples/st7735_simpletest.py +++ b/examples/st7735_simpletest.py @@ -5,7 +5,7 @@ import board import displayio -from adafruit_st7735.st7735r import ST7735R +from adafruit_st7735 import ST7735 spi = board.SPI() tft_cs = board.D5 @@ -14,7 +14,7 @@ displayio.release_displays() display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9) -display = ST7735R(display_bus, width=128, height=128, colstart=2, rowstart=1) +display = ST7735(display_bus, width=128, height=128) # Make the display context splash = displayio.Group(max_size=10)