Skip to content

Commit

Permalink
Merge pull request #18 from RetiredWizard/main
Browse files Browse the repository at this point in the history
Replace depreciated .show() & changes to displayio
  • Loading branch information
dhalbert committed Nov 6, 2023
2 parents 3cbac14 + 740777a commit 107baf3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
19 changes: 15 additions & 4 deletions README.rst
Expand Up @@ -64,6 +64,15 @@ Usage Example
import board
import displayio
# Starting in CircuitPython 9.x fourwire will be a seperate internal library
# rather than a component of the displayio library
try:
from fourwire import FourWire
# Use for I2C
# from i2cdisplaybus import I2CDisplayBus
except ImportError:
from displayio import FourWire
# from displayio import I2CDisplay as I2CDisplayBus
import terminalio
from adafruit_display_text import label
import adafruit_displayio_ssd1305
Expand All @@ -74,12 +83,14 @@ Usage Example
spi = board.SPI()
oled_cs = board.D5
oled_dc = board.D6
display_bus = displayio.FourWire(spi, command=oled_dc, chip_select=oled_cs,
baudrate=1000000, reset=board.D9)
display_bus = FourWire(
spi, command=oled_dc, chip_select=oled_cs, baudrate=1000000, reset=board.D9
)
# Use for I2C
# i2c = board.I2C()
# display_bus = displayio.I2CDisplay(i2c, device_address=0x3c)
#
# display_bus = I2CDisplayBus(i1c, device_address=0x3c)
WIDTH = 128
HEIGHT = 64 # Change to 32 if needed
Expand All @@ -90,7 +101,7 @@ Usage Example
# Make the display context
splash = displayio.Group()
display.show(splash)
display.root_group = splash
color_bitmap = displayio.Bitmap(display.width, display.height, 1)
color_palette = displayio.Palette(1)
Expand Down
17 changes: 12 additions & 5 deletions adafruit_displayio_ssd1305.py
Expand Up @@ -29,7 +29,16 @@

# imports

import displayio
# Starting in CircuitPython 9.x fourwire will be a seperate internal library
# rather than a component of the displayio library
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 displayio import I2CDisplay as I2CDisplayBus

try:
from typing import Union
Expand Down Expand Up @@ -61,7 +70,7 @@


# pylint: disable=too-few-public-methods
class SSD1305(displayio.Display):
class SSD1305(BusDisplay):
"""
SSD1305 driver
Expand All @@ -71,9 +80,7 @@ class SSD1305(displayio.Display):
One of (0, 90, 180, 270)
"""

def __init__(
self, bus: Union[displayio.Fourwire, displayio.I2CDisplay], **kwargs
) -> None:
def __init__(self, bus: Union[FourWire, I2CDisplayBus], **kwargs) -> None:
colstart = 0
# Patch the init sequence for 32 pixel high displays.
init_sequence = bytearray(_INIT_SEQUENCE)
Expand Down
18 changes: 15 additions & 3 deletions examples/displayio_ssd1305_simpletest.py
Expand Up @@ -8,6 +8,18 @@

import board
import displayio

# Starting in CircuitPython 9.x fourwire will be a seperate internal library
# rather than a component of the displayio library
try:
from fourwire import FourWire

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

# from displayio import I2CDisplay as I2CDisplayBus
import terminalio
from adafruit_display_text import label
import adafruit_displayio_ssd1305
Expand All @@ -21,14 +33,14 @@
spi = board.SPI()
oled_cs = board.D5
oled_dc = board.D6
display_bus = displayio.FourWire(
display_bus = FourWire(
spi, command=oled_dc, chip_select=oled_cs, baudrate=1000000, reset=oled_reset
)

# 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, reset=oled_reset)
# display_bus = I2CDisplayBus(i2c, device_address=0x3c, reset=oled_reset)

WIDTH = 128
HEIGHT = 64 # Change to 32 if needed
Expand All @@ -39,7 +51,7 @@

# Make the display context
splash = displayio.Group()
display.show(splash)
display.root_group = splash

color_bitmap = displayio.Bitmap(display.width, display.height, 1)
color_palette = displayio.Palette(1)
Expand Down

0 comments on commit 107baf3

Please sign in to comment.