Skip to content

Commit

Permalink
support 8.x.x and 9.x.x display bus differences
Browse files Browse the repository at this point in the history
  • Loading branch information
dhalbert committed Dec 18, 2023
1 parent fbf0827 commit 57d22b0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
14 changes: 11 additions & 3 deletions adafruit_ssd1325.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@
"""

import displayio
# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.
try:
from fourwire import FourWire
from busdisplay import BusDisplay
from i2cdisplaybus import I2CDisplayBus
except ImportError:
from displayio import FourWire
from displayio import Display as BusDisplay
from busio import I2C as I2CDisplayBus

__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SSD1325.git"
Expand Down Expand Up @@ -54,7 +62,7 @@


# pylint: disable=too-few-public-methods
class SSD1325(displayio.Display):
class SSD1325(BusDisplay):
"""
SSD1325 driver
Expand All @@ -64,7 +72,7 @@ class SSD1325(displayio.Display):
(0, 90, 180, 270)
"""

def __init__(self, bus: displayio.FourWire, **kwargs) -> None:
def __init__(self, bus: [FourWire | I2CDisplayBus], **kwargs) -> None:
# Patch the init sequence for 32 pixel high displays.
init_sequence = bytearray(_INIT_SEQUENCE)
height = kwargs["height"]
Expand Down
9 changes: 7 additions & 2 deletions examples/ssd1325_gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@
import time
import board
import displayio
import fourwire
import adafruit_ssd1325

# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.
try:
from fourwire import FourWire
except ImportError:
from displayio import FourWire

displayio.release_displays()

spi = board.SPI()
oled_cs = board.D5
oled_dc = board.D6
oled_reset = board.D9

display_bus = fourwire.FourWire(
display_bus = FourWire(
spi, command=oled_dc, chip_select=oled_cs, reset=oled_reset, baudrate=1000000
)
time.sleep(1)
Expand Down
17 changes: 14 additions & 3 deletions examples/ssd1325_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,36 @@

import board
import displayio
import fourwire
import terminalio
from adafruit_display_text import label
import adafruit_ssd1325

# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.
try:
from fourwire import FourWire
except ImportError:
from displayio import FourWire

# Use for I2C
# try:
# from i2cdisplaybus import I2CDisplayBus
# except ImportError:
# from displayio import I2CDisplayBus

displayio.release_displays()

# Use for SPI
spi = board.SPI()
oled_cs = board.D5
oled_dc = board.D6
display_bus = fourwire.FourWire(
display_bus = FourWire(
spi, command=oled_dc, chip_select=oled_cs, baudrate=1000000, reset=board.D9
)

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

WIDTH = 128
HEIGHT = 64
Expand Down

0 comments on commit 57d22b0

Please sign in to comment.