Skip to content

Commit b8d34d6

Browse files
authored
Merge pull request #15 from dhalbert/fourwire
FourWire support for 8.x.x and 9.x.x
2 parents 285c8aa + 4546968 commit b8d34d6

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

adafruit_displayio_sh1106.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@
2323
2424
"""
2525

26-
# imports
27-
import displayio
26+
# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.
27+
try:
28+
from fourwire import FourWire
29+
from busdisplay import BusDisplay
30+
except ImportError:
31+
from displayio import FourWire
32+
from displayio import Display as BusDisplay
2833

2934
__version__ = "0.0.0+auto.0"
3035
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SH1106.git"
@@ -52,17 +57,17 @@
5257
)
5358

5459

55-
class SH1106(displayio.Display):
60+
class SH1106(BusDisplay):
5661
"""
57-
SH1106 driver for use with DisplayIO
62+
SH1106 driver for use with displayio
5863
5964
:param bus: The bus that the display is connected to.
6065
:param int width: The width of the display. Maximum of 132
6166
:param int height: The height of the display. Maximum of 64
6267
:param int rotation: The rotation of the display. 0, 90, 180 or 270.
6368
"""
6469

65-
def __init__(self, bus: displayio.FourWire, **kwargs) -> None:
70+
def __init__(self, bus: FourWire, **kwargs) -> None:
6671
init_sequence = bytearray(_INIT_SEQUENCE)
6772
super().__init__(
6873
bus,

examples/displayio_sh1106_simpletest.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@
66
import board
77
import busio
88
import displayio
9-
import fourwire
109
import terminalio
1110
from adafruit_display_text import label
1211
import adafruit_displayio_sh1106
1312

13+
# Compatibility with both CircuitPython 8.x.x and 9.x.x.
14+
# Remove after 8.x.x is no longer a supported release.
15+
try:
16+
from fourwire import FourWire
17+
except ImportError:
18+
from displayio import FourWire
19+
1420
displayio.release_displays()
1521

1622
spi = busio.SPI(board.SCK, board.MOSI)
17-
display_bus = fourwire.FourWire(
23+
display_bus = FourWire(
1824
spi,
1925
command=board.OLED_DC,
2026
chip_select=board.OLED_CS,

0 commit comments

Comments
 (0)