Skip to content

Commit

Permalink
Support shared pins.
Browse files Browse the repository at this point in the history
Allow the same pin instance to be passed into multiple driver instances.

Fixes #34.
  • Loading branch information
Gadgetoid committed Nov 11, 2024
1 parent 74d4575 commit 202923b
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions st7789/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,23 @@ def __init__(
self._offset_left = offset_left
self._offset_top = offset_top

# Set DC as output.
self._dc = gpiodevice.get_pin(dc, "st7789-dc", OUTL)
# Set up DC pin if a lines/offset tuple is not supplied
if isinstance(dc, int):
self._dc = ST7789.get_dc_pin(dc)

# Setup backlight as output (if provided).
if backlight is not None:
self._bl = gpiodevice.get_pin(backlight, "st7789-bl", OUTL)
if isinstance(dc, int):
self._bl = ST7789.get_bl_pin(backlight)
self.set_pin(self._bl, False)
time.sleep(0.1)
self.set_pin(self._bl, True)

# Setup reset as output (if provided).
# Set up and call reset (if provided)
if rst is not None:
self._rst = gpiodevice.get_pin(rst, "st7789-rst", OUTL)
# Set up RESET pin if a lines/offset tuple is not supplied
if isinstance(rst, int):
self._rst = ST7789.get_rst_pin(rst)
self.reset()

self._init()
Expand Down Expand Up @@ -385,3 +389,15 @@ def image_to_data(self, image, rotation=0):

# Output the raw bytes
return result.byteswap().tobytes()

@staticmethod
def get_bl_pin(pin):
return gpiodevice.get_pin(pin, "st7789-bl", OUTL)

@staticmethod
def get_rst_pin(pin):
return gpiodevice.get_pin(pin, "st7789-rst", OUTL)

@staticmethod
def get_dc_pin(pin):
return gpiodevice.get_pin(pin, "st7789-dc", OUTL)

0 comments on commit 202923b

Please sign in to comment.