Skip to content

Commit 2e19968

Browse files
authored
Merge pull request #19 from adafruit/fourwire-i2c
support 8.x.x and 9.x.x display bus differences
2 parents fbf0827 + 990989a commit 2e19968

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

adafruit_ssd1325.py

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

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

3043
__version__ = "0.0.0+auto.0"
3144
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SSD1325.git"
@@ -54,7 +67,7 @@
5467

5568

5669
# pylint: disable=too-few-public-methods
57-
class SSD1325(displayio.Display):
70+
class SSD1325(BusDisplay):
5871
"""
5972
SSD1325 driver
6073
@@ -64,7 +77,7 @@ class SSD1325(displayio.Display):
6477
(0, 90, 180, 270)
6578
"""
6679

67-
def __init__(self, bus: displayio.FourWire, **kwargs) -> None:
80+
def __init__(self, bus: Union[FourWire, I2CDisplayBus], **kwargs) -> None:
6881
# Patch the init sequence for 32 pixel high displays.
6982
init_sequence = bytearray(_INIT_SEQUENCE)
7083
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)