-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split display.py into files for each backend (#930)
* split display.py into files for each backend * update Display.md * remove unecessary call to displayio.release_displays() * rename DisplayBackend to DisplayBase * use relative imports in display extension
- Loading branch information
1 parent
0334a85
commit 5d4e787
Showing
5 changed files
with
111 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from . import DisplayBase | ||
|
||
|
||
# Intended for displays with drivers built into CircuitPython | ||
# that can be used directly without manual initialization | ||
class BuiltInDisplay(DisplayBase): | ||
def __init__(self, display=None, sleep_command=None, wake_command=None): | ||
self.display = display | ||
self.sleep_command = sleep_command | ||
self.wake_command = wake_command | ||
self.is_awake = True | ||
|
||
def during_bootup(self, width, height, rotation): | ||
self.display.rotation = rotation | ||
return self.display | ||
|
||
def deinit(self): | ||
return | ||
|
||
def sleep(self): | ||
self.display.bus.send(self.sleep_command, b'') | ||
|
||
def wake(self): | ||
self.display.bus.send(self.wake_command, b'') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import busio | ||
|
||
import adafruit_displayio_sh1106 # Display-specific library | ||
import displayio | ||
|
||
from . import DisplayBase | ||
|
||
# Required to initialize this display | ||
displayio.release_displays() | ||
|
||
|
||
class SH1106(DisplayBase): | ||
def __init__( | ||
self, | ||
spi=None, | ||
sck=None, | ||
mosi=None, | ||
command=None, | ||
chip_select=None, | ||
reset=None, | ||
baudrate=1000000, | ||
): | ||
self.command = command | ||
self.chip_select = chip_select | ||
self.reset = reset | ||
self.baudrate = baudrate | ||
# spi initialization | ||
self.spi = spi | ||
if self.spi is None: | ||
self.spi = busio.SPI(sck, mosi) | ||
|
||
def during_bootup(self, width, height, rotation): | ||
self.display = adafruit_displayio_sh1106.SH1106( | ||
displayio.FourWire( | ||
self.spi, | ||
command=self.command, | ||
chip_select=self.chip_select, | ||
reset=self.reset, | ||
baudrate=self.baudrate, | ||
), | ||
width=width, | ||
height=height, | ||
rotation=rotation, | ||
) | ||
|
||
return self.display | ||
|
||
def deinit(self): | ||
self.spi.deinit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import busio | ||
|
||
import adafruit_displayio_ssd1306 # Display-specific library | ||
import displayio | ||
|
||
from . import DisplayBase | ||
|
||
# Required to initialize this display | ||
displayio.release_displays() | ||
|
||
|
||
class SSD1306(DisplayBase): | ||
def __init__(self, i2c=None, sda=None, scl=None, device_address=0x3C): | ||
self.device_address = device_address | ||
# i2c initialization | ||
self.i2c = i2c | ||
if self.i2c is None: | ||
self.i2c = busio.I2C(scl, sda) | ||
|
||
def during_bootup(self, width, height, rotation): | ||
self.display = adafruit_displayio_ssd1306.SSD1306( | ||
displayio.I2CDisplay(self.i2c, device_address=self.device_address), | ||
width=width, | ||
height=height, | ||
rotation=rotation, | ||
) | ||
|
||
return self.display | ||
|
||
def deinit(self): | ||
self.i2c.deinit() |