From 2e341591ff44bb1040665b38deb2f0f6e46fae92 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 25 Mar 2024 15:22:00 -0500 Subject: [PATCH 1/2] 9.x compatibility --- adafruit_displayio_sh1107.py | 21 ++++++++++++++++--- examples/displayio_sh1107_game_of_life.py | 10 ++++++++- .../displayio_sh1107_mono_128x128_test.py | 16 ++++++++++++-- examples/displayio_sh1107_random_motion.py | 10 ++++++++- examples/displayio_sh1107_simpletest.py | 10 ++++++++- 5 files changed, 59 insertions(+), 8 deletions(-) diff --git a/adafruit_displayio_sh1107.py b/adafruit_displayio_sh1107.py index a119bc9..be0e55b 100644 --- a/adafruit_displayio_sh1107.py +++ b/adafruit_displayio_sh1107.py @@ -27,11 +27,26 @@ """ import sys -import displayio + + +try: + from busdisplay import BusDisplay as Display + from fourwire import FourWire +except ImportError: + from displayio import Display + from displayio import FourWire + from micropython import const try: from typing import Union + + try: + from i2cdisplaybus import I2CDisplayBus + except ImportError: + # pylint: disable=ungrouped-imports + from displayio import I2CDisplay as I2CDisplayBus + except ImportError: pass @@ -130,7 +145,7 @@ _ROTATION_OFFSET = 90 -class SH1107(displayio.Display): +class SH1107(Display): """ SH1107 driver for use with DisplayIO @@ -146,7 +161,7 @@ class SH1107(displayio.Display): def __init__( self, - bus: Union[displayio.I2CDisplay, displayio.FourWire], + bus: Union[I2CDisplayBus, FourWire], display_offset: int = DISPLAY_OFFSET_ADAFRUIT_FEATHERWING_OLED_4650, rotation: int = 0, **kwargs diff --git a/examples/displayio_sh1107_game_of_life.py b/examples/displayio_sh1107_game_of_life.py index 2d20d95..0efd2c0 100644 --- a/examples/displayio_sh1107_game_of_life.py +++ b/examples/displayio_sh1107_game_of_life.py @@ -12,6 +12,14 @@ import board import displayio + +# Compatibility with both CircuitPython 8.x.x and 9.x.x. +# Remove after 8.x.x is no longer a supported release. +try: + from i2cdisplaybus import I2CDisplayBus +except ImportError: + from displayio import I2CDisplay as I2CDisplayBus + import adafruit_displayio_sh1107 displayio.release_displays() @@ -93,7 +101,7 @@ def conway(output): 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) # SH1107 is vertically oriented 64x128 WIDTH = 128 diff --git a/examples/displayio_sh1107_mono_128x128_test.py b/examples/displayio_sh1107_mono_128x128_test.py index d83fe47..c4f323e 100644 --- a/examples/displayio_sh1107_mono_128x128_test.py +++ b/examples/displayio_sh1107_mono_128x128_test.py @@ -9,6 +9,18 @@ import board import displayio + +# Compatibility with both CircuitPython 8.x.x and 9.x.x. +# Remove after 8.x.x is no longer a supported release. +try: + from i2cdisplaybus import I2CDisplayBus + + # from fourwire import FourWire +except ImportError: + from displayio import I2CDisplay as I2CDisplayBus + + # from displayio import FourWire + import terminalio from adafruit_display_text import bitmap_label as label from adafruit_displayio_sh1107 import SH1107, DISPLAY_OFFSET_ADAFRUIT_128x128_OLED_5297 @@ -18,12 +30,12 @@ # 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=0x3D) +display_bus = I2CDisplayBus(i2c, device_address=0x3D) # For SPI: # import busio # spi_bus = busio.SPI(board.SCK, board.MOSI) -# display_bus = displayio.FourWire(spi_bus, command=board.D6, chip_select=board.D5, reset=board.D9) +# display_bus = FourWire(spi_bus, command=board.D6, chip_select=board.D5, reset=board.D9) # Width, height and rotation for Monochrome 1.12" 128x128 OLED WIDTH = 128 diff --git a/examples/displayio_sh1107_random_motion.py b/examples/displayio_sh1107_random_motion.py index 8004932..94d61ae 100644 --- a/examples/displayio_sh1107_random_motion.py +++ b/examples/displayio_sh1107_random_motion.py @@ -12,6 +12,14 @@ import time import board import displayio + +# Compatibility with both CircuitPython 8.x.x and 9.x.x. +# Remove after 8.x.x is no longer a supported release. +try: + from i2cdisplaybus import I2CDisplayBus +except ImportError: + from displayio import I2CDisplay as I2CDisplayBus + import terminalio # can try import bitmap_label below for alternative @@ -24,7 +32,7 @@ # 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) # SH1107 is vertically oriented 64x128 WIDTH = 128 diff --git a/examples/displayio_sh1107_simpletest.py b/examples/displayio_sh1107_simpletest.py index 8e7e1e9..b91956a 100644 --- a/examples/displayio_sh1107_simpletest.py +++ b/examples/displayio_sh1107_simpletest.py @@ -11,6 +11,14 @@ import board import displayio + +# Compatibility with both CircuitPython 8.x.x and 9.x.x. +# Remove after 8.x.x is no longer a supported release. +try: + from i2cdisplaybus import I2CDisplayBus +except ImportError: + from displayio import I2CDisplay as I2CDisplayBus + import terminalio # can try import bitmap_label below for alternative @@ -23,7 +31,7 @@ # 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) # SH1107 is vertically oriented 64x128 WIDTH = 128 From d445cc7c9b2f3e9764d83e60d4dd6f727da16f57 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 1 Apr 2024 08:57:22 -0500 Subject: [PATCH 2/2] add blinka-displayio req --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 7a984a4..007b042 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ # SPDX-License-Identifier: Unlicense Adafruit-Blinka +Adafruit-Blinka-Displayio