Created
January 23, 2025 00:37
-
-
Save jepler/efba133f7f43caf5361be7e0f9f85777 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/python3 | |
""" | |
Do framebuffer magic | |
Run like this: | |
$ python hub85_fb.py | |
The upper left corner of the framebuffer is displayed until the user hits ctrl-c | |
""" | |
import pathlib | |
import ctypes | |
import adafruit_raspberry_pi5_piomatter | |
import numpy as np | |
yoffset = 0 | |
xoffset = 0 | |
with open("/sys/class/graphics/fb0/virtual_size") as f: | |
screenx, screeny = [int(word) for word in f.read().split(",")] | |
with open("/sys/class/graphics/fb0/bits_per_pixel") as f: | |
bits_per_pixel = int(f.read()) | |
assert bits_per_pixel == 16 | |
bytes_per_pixel = bits_per_pixel // 8 | |
dtype = {2: np.uint16, 4: np.uint32}[bytes_per_pixel] | |
with open("/sys/class/graphics/fb0/stride") as f: | |
stride = int(f.read()) | |
linux_framebuffer = np.memmap('/dev/fb0',mode='r', shape=(screeny, stride // bytes_per_pixel), dtype=dtype) | |
width = 64 | |
height = 32 | |
geometry = adafruit_raspberry_pi5_piomatter.Geometry(width=width, height=height, n_addr_lines=4, rotation=adafruit_raspberry_pi5_piomatter.Orientation.Normal) | |
matrix_framebuffer = np.zeros(shape=(geometry.height, geometry.width), dtype=dtype) | |
matrix = adafruit_raspberry_pi5_piomatter.AdafruitMatrixBonnetRGB565(matrix_framebuffer, geometry) | |
while True: | |
matrix_framebuffer[:,:] = linux_framebuffer[yoffset:yoffset+height, xoffset:xoffset+width] | |
matrix.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment