Skip to content

Commit

Permalink
Merge pull request #35 from pimoroni/feature/floyd-made-me-do-it
Browse files Browse the repository at this point in the history
Various fixes & improvements
  • Loading branch information
Gadgetoid authored Jan 14, 2025
2 parents f7b386e + 9aabd78 commit 2e0df28
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 11 deletions.
3 changes: 2 additions & 1 deletion examples/framerate.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
port=0,
cs=st7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT
dc=9,
backlight=backlight, # 18 for back BG slot, 19 for front BG slot.
backlight=19, # Breakout Garden: 18 for back slot, 19 for front slot.
# NOTE: Change this to 13 for Pirate Audio boards
spi_speed_hz=SPI_SPEED_MHZ * 1000000,
offset_left=offset_left,
offset_top=offset_top,
Expand Down
3 changes: 2 additions & 1 deletion examples/gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
port=0,
cs=st7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT
dc=9,
backlight=19, # 18 for back BG slot, 19 for front BG slot.
backlight=19, # Breakout Garden: 18 for back slot, 19 for front slot.
# NOTE: Change this to 13 for Pirate Audio boards
spi_speed_hz=80 * 1000 * 1000,
offset_left=0 if display_type == "square" else 40,
offset_top=53 if display_type == "rect" else 0,
Expand Down
3 changes: 2 additions & 1 deletion examples/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
port=0,
cs=st7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT
dc=9,
backlight=19, # 18 for back BG slot, 19 for front BG slot.
backlight=19, # Breakout Garden: 18 for back slot, 19 for front slot.
# NOTE: Change this to 13 for Pirate Audio boards
spi_speed_hz=80 * 1000 * 1000,
offset_left=0 if display_type == "square" else 40,
offset_top=53 if display_type == "rect" else 0,
Expand Down
3 changes: 2 additions & 1 deletion examples/round.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
port=0,
cs=st7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT
dc=9,
backlight=19, # 18 for back BG slot, 19 for front BG slot.
backlight=19, # Breakout Garden: 18 for back slot, 19 for front slot.
# NOTE: Change this to 13 for Pirate Audio boards
rotation=90,
spi_speed_hz=80 * 1000 * 1000,
offset_left=40,
Expand Down
3 changes: 2 additions & 1 deletion examples/scrolling-text.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
port=0,
cs=st7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT
dc=9,
backlight=19, # 18 for back BG slot, 19 for front BG slot.
backlight=19, # Breakout Garden: 18 for back slot, 19 for front slot.
# NOTE: Change this to 13 for Pirate Audio boards
spi_speed_hz=80 * 1000 * 1000,
offset_left=0 if display_type == "square" else 40,
offset_top=53 if display_type == "rect" else 0,
Expand Down
3 changes: 2 additions & 1 deletion examples/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
port=0,
cs=st7789.BG_SPI_CS_FRONT, # BG_SPI_CS_BACK or BG_SPI_CS_FRONT
dc=9,
backlight=19, # 18 for back BG slot, 19 for front BG slot.
backlight=19, # Breakout Garden: 18 for back slot, 19 for front slot.
# NOTE: Change this to 13 for Pirate Audio boards
spi_speed_hz=80 * 1000 * 1000,
offset_left=0 if display_type == "square" else 40,
offset_top=53 if display_type == "rect" else 0,
Expand Down
29 changes: 24 additions & 5 deletions st7789/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,26 @@ 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(backlight, int):
self._bl = ST7789.get_bl_pin(backlight)
else:
self._bl = 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 @@ -384,3 +391,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 2e0df28

Please sign in to comment.