Skip to content

Commit ad2e00c

Browse files
authored
Merge pull request #33 from dhalbert/fourwire
FourWire support for both 8.x.x and 9.x.x
2 parents e68da58 + 9083dbb commit ad2e00c

8 files changed

+58
-23
lines changed

adafruit_st7735r.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@
3939
except ImportError:
4040
pass
4141

42-
import displayio
42+
# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.
43+
try:
44+
from fourwire import FourWire
45+
from busdisplay import BusDisplay
46+
except ImportError:
47+
from displayio import FourWire
48+
from displayio import Display as BusDisplay
4349

4450
__version__ = "0.0.0+auto.0"
4551
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ST7735R.git"
@@ -70,22 +76,17 @@
7076

7177

7278
# pylint: disable=too-few-public-methods
73-
class ST7735R(displayio.Display):
79+
class ST7735R(BusDisplay):
7480
"""
7581
ST7735R display driver
7682
77-
:param displayio.FourWire bus: bus that the display is connected to
83+
:param FourWire bus: bus that the display is connected to
7884
:param bool bgr: (Optional) An extra init sequence to append (default=False)
7985
:param bool invert: (Optional) Invert the colors (default=False)
8086
"""
8187

8288
def __init__(
83-
self,
84-
bus: displayio.FourWire,
85-
*,
86-
bgr: bool = False,
87-
invert: bool = False,
88-
**kwargs: Any
89+
self, bus: FourWire, *, bgr: bool = False, invert: bool = False, **kwargs: Any
8990
):
9091
init_sequence = _INIT_SEQUENCE
9192
if bgr:

examples/st7735r_128x160_colored_labels.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,22 @@
99
import board
1010
import terminalio
1111
import displayio
12-
import fourwire
1312
from adafruit_display_text import label
1413
from adafruit_st7735r import ST7735R
1514

15+
try:
16+
from fourwire import FourWire
17+
except ImportError:
18+
from displayio import FourWire
19+
1620
# Release any resources currently in use for the displays
1721
displayio.release_displays()
1822

1923
spi = board.SPI()
2024
tft_cs = board.D5
2125
tft_dc = board.D6
2226

23-
display_bus = fourwire.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
27+
display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
2428

2529
display = ST7735R(
2630
display_bus, width=160, height=80, colstart=24, rotation=270, bgr=False

examples/st7735r_128x160_simpletest.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,23 @@
99
import board
1010
import terminalio
1111
import displayio
12-
import fourwire
1312
from adafruit_display_text import label
1413
from adafruit_st7735r import ST7735R
1514

15+
# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.
16+
try:
17+
from fourwire import FourWire
18+
except ImportError:
19+
from displayio import FourWire
20+
1621
# Release any resources currently in use for the displays
1722
displayio.release_displays()
1823

1924
spi = board.SPI()
2025
tft_cs = board.D5
2126
tft_dc = board.D6
2227

23-
display_bus = fourwire.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
28+
display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
2429

2530
display = ST7735R(display_bus, width=160, height=128, rotation=90, bgr=True)
2631

examples/st7735r_18tftshield_buttons.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
77
import time
88
import board
99
import displayio
10-
import fourwire
1110
from adafruit_seesaw.tftshield18 import TFTShield18
1211
from adafruit_st7735r import ST7735R
1312

13+
# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.
14+
try:
15+
from fourwire import FourWire
16+
except ImportError:
17+
from displayio import FourWire
18+
1419
# Release any resources currently in use for the displays
1520
displayio.release_displays()
1621

@@ -20,7 +25,7 @@
2025
tft_cs = board.D10
2126
tft_dc = board.D8
2227

23-
display_bus = fourwire.FourWire(spi, command=tft_dc, chip_select=tft_cs)
28+
display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs)
2429

2530
ss.tft_reset()
2631
display = ST7735R(display_bus, width=160, height=128, rotation=90, bgr=True)

examples/st7735r_minitft_featherwing_simpletest.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@
99
import board
1010
import terminalio
1111
import displayio
12-
import fourwire
1312
from adafruit_display_text import label
1413
from adafruit_seesaw.seesaw import Seesaw
1514
from adafruit_st7735r import ST7735R
1615

16+
# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.
17+
try:
18+
from fourwire import FourWire
19+
except ImportError:
20+
from displayio import FourWire
21+
1722
# Release any resources currently in use for the displays
1823
displayio.release_displays()
1924

@@ -27,7 +32,7 @@
2732
tft_cs = board.D5
2833
tft_dc = board.D6
2934

30-
display_bus = fourwire.FourWire(spi, command=tft_dc, chip_select=tft_cs)
35+
display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs)
3136

3237
ss.digital_write(reset_pin, True)
3338
display = ST7735R(

examples/st7735r_minitft_revb_simpletest.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,23 @@
99
import board
1010
import terminalio
1111
import displayio
12-
import fourwire
1312
from adafruit_display_text import label
1413
from adafruit_st7735r import ST7735R
1514

15+
# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.
16+
try:
17+
from fourwire import FourWire
18+
except ImportError:
19+
from displayio import FourWire
20+
1621
# Release any resources currently in use for the displays
1722
displayio.release_displays()
1823

1924
spi = board.SPI()
2025
tft_cs = board.D5
2126
tft_dc = board.D6
2227

23-
display_bus = fourwire.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
28+
display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
2429

2530
display = ST7735R(
2631
display_bus,

examples/st7735r_minitft_simpletest.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,23 @@
99
import board
1010
import terminalio
1111
import displayio
12-
import fourwire
1312
from adafruit_display_text import label
1413
from adafruit_st7735r import ST7735R
1514

15+
# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.
16+
try:
17+
from fourwire import FourWire
18+
except ImportError:
19+
from displayio import FourWire
20+
1621
# Release any resources currently in use for the displays
1722
displayio.release_displays()
1823

1924
spi = board.SPI()
2025
tft_cs = board.D5
2126
tft_dc = board.D6
2227

23-
display_bus = fourwire.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
28+
display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
2429

2530
display = ST7735R(
2631
display_bus, width=160, height=80, colstart=24, rotation=270, bgr=True

examples/st7735r_simpletest.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,23 @@
99
import board
1010
import terminalio
1111
import displayio
12-
import fourwire
1312
from adafruit_display_text import label
1413
from adafruit_st7735r import ST7735R
1514

15+
# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.
16+
try:
17+
from fourwire import FourWire
18+
except ImportError:
19+
from displayio import FourWire
20+
1621
# Release any resources currently in use for the displays
1722
displayio.release_displays()
1823

1924
spi = board.SPI()
2025
tft_cs = board.D5
2126
tft_dc = board.D6
2227

23-
display_bus = fourwire.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
28+
display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
2429

2530
display = ST7735R(display_bus, width=128, height=128, colstart=2, rowstart=1)
2631

0 commit comments

Comments
 (0)