Last active
September 7, 2023 05:07
-
-
Save lynt-smitka/ca02beb951a479eebb01066f575846d8 to your computer and use it in GitHub Desktop.
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
import board | |
import struct | |
import time | |
import busio | |
import sdcardio | |
import storage | |
display = board.DISPLAY | |
display.auto_refresh = False | |
# Setup SD card and mount it to /sd directory | |
spi = busio.SPI(board.SD_SCK, MOSI=board.SD_MOSI, MISO=board.SD_MISO) | |
cs = board.SD_CS | |
sdcard = sdcardio.SDCard(spi, cs, baudrate=31_250_000) | |
vfs = storage.VfsFat(sdcard) | |
storage.mount(vfs, "/sd") | |
def send_chunks_to_display(file_path, width=320, rows = 24): | |
chunk_size= 2 * width * rows # 2bytes per pixel - every chunk = row * number of rows to display at once | |
chunk = bytearray(chunk_size) | |
row_start = 0 | |
send = display.bus.send | |
pack = struct.pack | |
mw = memoryview | |
send(42, pack(">hh", 0, width-1)) | |
with open(file_path, "rb") as f: | |
read = f.readinto | |
while True: | |
n = read(chunk) | |
if n == 0: | |
break | |
send(43, pack(">hh", row_start, row_start + rows)) | |
send(44, mw(chunk)[:n]) | |
row_start += rows | |
while True: | |
# Bitmaps are in RGB 565 Swapped format | |
# converter: https://lvgl.io/tools/imageconverter | |
send_chunks_to_display("/sd/img1.bin") | |
time.sleep(3) | |
send_chunks_to_display("/sd/img2.bin") | |
time.sleep(3) |
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
import board | |
import struct | |
import time | |
display = board.DISPLAY | |
display.auto_refresh = False | |
def send_chunks_to_display(file_path, width=320, rows = 24): | |
chunk_size= 2 * width * rows # 2bytes per pixel - every chunk = row * number of rows to display at once | |
chunk = bytearray(chunk_size) | |
row_start = 0 | |
send = display.bus.send | |
pack = struct.pack | |
mw = memoryview | |
send(42, pack(">hh", 0, width-1)) | |
with open(file_path, "rb") as f: | |
read = f.readinto | |
while True: | |
n = read(chunk) | |
if n == 0: | |
break | |
send(43, pack(">hh", row_start, row_start + rows)) | |
send(44, mw(chunk)[:n]) | |
row_start += rows | |
while True: | |
# Bitmaps are in RGB 565 Swapped format | |
# converter: https://lvgl.io/tools/imageconverter | |
send_chunks_to_display("/SLIDE/img1.bin") | |
time.sleep(3) | |
send_chunks_to_display("/SLIDE/img2.bin") | |
time.sleep(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment