Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes & improvements #35

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading