Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support 8.x.x and 9.x.x display bus differences #19

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions adafruit_ssd1325.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,20 @@

"""

import displayio
try:
from typing import Union
except ImportError:
pass

# 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 +67,7 @@


# pylint: disable=too-few-public-methods
class SSD1325(displayio.Display):
class SSD1325(BusDisplay):
"""
SSD1325 driver

Expand All @@ -64,7 +77,7 @@ class SSD1325(displayio.Display):
(0, 90, 180, 270)
"""

def __init__(self, bus: displayio.FourWire, **kwargs) -> None:
def __init__(self, bus: Union[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