Skip to content

Commit 57d22b0

Browse files
committed
support 8.x.x and 9.x.x display bus differences
1 parent fbf0827 commit 57d22b0

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

adafruit_ssd1325.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@
2525
2626
"""
2727

28-
import displayio
28+
# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.
29+
try:
30+
from fourwire import FourWire
31+
from busdisplay import BusDisplay
32+
from i2cdisplaybus import I2CDisplayBus
33+
except ImportError:
34+
from displayio import FourWire
35+
from displayio import Display as BusDisplay
36+
from busio import I2C as I2CDisplayBus
2937

3038
__version__ = "0.0.0+auto.0"
3139
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SSD1325.git"
@@ -54,7 +62,7 @@
5462

5563

5664
# pylint: disable=too-few-public-methods
57-
class SSD1325(displayio.Display):
65+
class SSD1325(BusDisplay):
5866
"""
5967
SSD1325 driver
6068
@@ -64,7 +72,7 @@ class SSD1325(displayio.Display):
6472
(0, 90, 180, 270)
6573
"""
6674

67-
def __init__(self, bus: displayio.FourWire, **kwargs) -> None:
75+
def __init__(self, bus: [FourWire | I2CDisplayBus], **kwargs) -> None:
6876
# Patch the init sequence for 32 pixel high displays.
6977
init_sequence = bytearray(_INIT_SEQUENCE)
7078
height = kwargs["height"]

examples/ssd1325_gamma.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@
44
import time
55
import board
66
import displayio
7-
import fourwire
87
import adafruit_ssd1325
98

9+
# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.
10+
try:
11+
from fourwire import FourWire
12+
except ImportError:
13+
from displayio import FourWire
14+
1015
displayio.release_displays()
1116

1217
spi = board.SPI()
1318
oled_cs = board.D5
1419
oled_dc = board.D6
1520
oled_reset = board.D9
1621

17-
display_bus = fourwire.FourWire(
22+
display_bus = FourWire(
1823
spi, command=oled_dc, chip_select=oled_cs, reset=oled_reset, baudrate=1000000
1924
)
2025
time.sleep(1)

examples/ssd1325_simpletest.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,36 @@
88

99
import board
1010
import displayio
11-
import fourwire
1211
import terminalio
1312
from adafruit_display_text import label
1413
import adafruit_ssd1325
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+
21+
# Use for I2C
22+
# try:
23+
# from i2cdisplaybus import I2CDisplayBus
24+
# except ImportError:
25+
# from displayio import I2CDisplayBus
26+
1627
displayio.release_displays()
1728

1829
# Use for SPI
1930
spi = board.SPI()
2031
oled_cs = board.D5
2132
oled_dc = board.D6
22-
display_bus = fourwire.FourWire(
33+
display_bus = FourWire(
2334
spi, command=oled_dc, chip_select=oled_cs, baudrate=1000000, reset=board.D9
2435
)
2536

2637
# Use for I2C
2738
# i2c = board.I2C() # uses board.SCL and board.SDA
2839
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
29-
# display_bus = displayio.I2CDisplay(i2c, device_address=0x3c)
40+
# display_bus = I2CDisplayBus(i2c, device_address=0x3c)
3041

3142
WIDTH = 128
3243
HEIGHT = 64

0 commit comments

Comments
 (0)