diff --git a/examples/fbmirror.py b/examples/fbmirror.py index 99bd3b4..876869e 100644 --- a/examples/fbmirror.py +++ b/examples/fbmirror.py @@ -34,29 +34,16 @@ with open("/sys/class/graphics/fb0/stride") as f: linux_framebuffer = np.memmap('/dev/fb0',mode='r', shape=(screeny, stride // bytes_per_pixel), dtype=dtype) -def make_pixelmap_multilane(width, height, n_addr_lines, n_lanes): - calc_height = n_lanes << n_addr_lines - if height != calc_height: - raise RuntimeError(f"Calculated height {calc_height} does not match requested height {height}") - n_addr = 1 << n_addr_lines - - m = [] - for addr in range(n_addr): - for x in range(width): - for lane in range(n_lanes): - y = addr + lane * n_addr - m.append(x + width * y) - print(m) - return m - @click.command @click.option("--x-offset", "xoffset", type=int, help="The x offset of top left corner of the region to mirror", default=0) @click.option("--y-offset", "yoffset", type=int, help="The y offset of top left corner of the region to mirror", default=0) @piomatter_click.standard_options(n_lanes=2, n_temporal_planes=4) def main(xoffset, yoffset, width, height, serpentine, rotation, pinout, n_planes, n_temporal_planes, n_addr_lines, n_lanes): if n_lanes != 2: - pixelmap = make_pixelmap_multilane(width, height, n_addr_lines, n_lanes) - geometry = piomatter.Geometry(width=width, height=height, n_planes=n_planes, n_addr_lines=n_addr_lines, n_temporal_planes=n_temporal_planes, n_lanes=n_lanes, map=pixelmap) + pixelmap = piomatter.make_pixelmap_multilane(width, height, n_addr_lines, n_lanes) + geometry = piomatter.Geometry(width=width, height=height, n_planes=n_planes, n_addr_lines=n_addr_lines, + n_temporal_planes=n_temporal_planes, rotation=rotation, n_lanes=n_lanes, + map=pixelmap) else: geometry = piomatter.Geometry(width=width, height=height, n_planes=n_planes, n_addr_lines=n_addr_lines, n_temporal_planes=n_temporal_planes, rotation=rotation) framebuffer = np.zeros(shape=(geometry.height, geometry.width), dtype=dtype) diff --git a/examples/fbmirror_scaled.py b/examples/fbmirror_scaled.py index b104e60..75d1d70 100644 --- a/examples/fbmirror_scaled.py +++ b/examples/fbmirror_scaled.py @@ -65,9 +65,16 @@ linux_framebuffer = np.memmap('/dev/fb0',mode='r', shape=(screeny, stride // byt @click.option("--x-offset", "xoffset", type=int, help="The x offset of top left corner of the region to mirror", default=0) @click.option("--y-offset", "yoffset", type=int, help="The y offset of top left corner of the region to mirror", default=0) @click.option("--scale", "scale", type=int, help="The scale factor to reduce the display down by.", default=3) -@piomatter_click.standard_options -def main(xoffset, yoffset, scale, width, height, serpentine, rotation, pinout, n_planes, n_addr_lines): - geometry = piomatter.Geometry(width=width, height=height, n_planes=n_planes, n_addr_lines=n_addr_lines, rotation=rotation) +@piomatter_click.standard_options(n_lanes=2, n_temporal_planes=4) +def main(xoffset, yoffset, scale, width, height, serpentine, rotation, pinout, n_planes, n_temporal_planes, n_addr_lines, n_lanes): + if n_lanes != 2: + pixelmap = piomatter.make_pixelmap_multilane(width, height, n_addr_lines, n_lanes) + geometry = piomatter.Geometry(width=width, height=height, n_planes=n_planes, n_addr_lines=n_addr_lines, + n_temporal_planes=n_temporal_planes, rotation=rotation, n_lanes=n_lanes, map=pixelmap) + else: + geometry = piomatter.Geometry(width=width, height=height, n_planes=n_planes, n_addr_lines=n_addr_lines, + n_temporal_planes=n_temporal_planes, rotation=rotation) + matrix_framebuffer = np.zeros(shape=(geometry.height, geometry.width, 3), dtype=np.uint8) matrix = piomatter.PioMatter(colorspace=piomatter.Colorspace.RGB888Packed, pinout=pinout, framebuffer=matrix_framebuffer, geometry=geometry) diff --git a/examples/virtualdisplay.py b/examples/virtualdisplay.py index 139444f..47d83f8 100644 --- a/examples/virtualdisplay.py +++ b/examples/virtualdisplay.py @@ -40,16 +40,23 @@ import adafruit_blinka_raspberry_pi5_piomatter.click as piomatter_click @click.option("--extra-args", help="Extra arguments to pass to the backend server", default="") @click.option("--rfbport", help="The port number for the --backend xvnc", default=None, type=int) @click.option("--use-xauth/--no-use-xauth", help="If a Xauthority file should be created", default=False) -@piomatter_click.standard_options +@piomatter_click.standard_options(n_lanes=2, n_temporal_planes=4) @click.argument("command", nargs=-1) -def main(scale, backend, use_xauth, extra_args, rfbport, width, height, serpentine, rotation, pinout, n_planes, n_addr_lines, command): +def main(scale, backend, use_xauth, extra_args, rfbport, width, height, serpentine, rotation, pinout, n_planes, n_temporal_planes, n_addr_lines, n_lanes, command): kwargs = {} if backend == "xvnc": kwargs['rfbport'] = rfbport if extra_args: kwargs['extra_args'] = shlex.split(extra_args) print("xauth", use_xauth) - geometry = piomatter.Geometry(width=width, height=height, n_planes=n_planes, n_addr_lines=n_addr_lines, rotation=rotation) + if n_lanes != 2: + pixelmap = piomatter.make_pixelmap_multilane(width, height, n_addr_lines, n_lanes) + geometry = piomatter.Geometry(width=width, height=height, n_planes=n_planes, n_addr_lines=n_addr_lines, + n_temporal_planes=n_temporal_planes, rotation=rotation, n_lanes=n_lanes, + map=pixelmap) + else: + geometry = piomatter.Geometry(width=width, height=height, n_planes=n_planes, n_addr_lines=n_addr_lines, + n_temporal_planes=n_temporal_planes, rotation=rotation) framebuffer = np.zeros(shape=(geometry.height, geometry.width, 3), dtype=np.uint8) matrix = piomatter.PioMatter(colorspace=piomatter.Colorspace.RGB888Packed, pinout=pinout, framebuffer=framebuffer, geometry=geometry) diff --git a/examples/xdisplay_mirror.py b/examples/xdisplay_mirror.py index fdbac74..73d6f48 100644 --- a/examples/xdisplay_mirror.py +++ b/examples/xdisplay_mirror.py @@ -21,6 +21,7 @@ This example command will mirror a 128x128 pixel square from the top left of the import click import numpy as np from PIL import ImageGrab + import adafruit_blinka_raspberry_pi5_piomatter as piomatter import adafruit_blinka_raspberry_pi5_piomatter.click as piomatter_click @@ -29,11 +30,17 @@ import adafruit_blinka_raspberry_pi5_piomatter.click as piomatter_click @click.option("--mirror-region", help="Region of X display to mirror. Comma seperated x,y,w,h. " "Default will mirror entire display.", default="") @click.option("--x-display", help="The X display to mirror. Default is :0", default=":0") -@piomatter_click.standard_options(n_temporal_planes=0) +@piomatter_click.standard_options(n_lanes=2, n_temporal_planes=0) def main(width, height, serpentine, rotation, pinout, n_planes, - n_temporal_planes, n_addr_lines, mirror_region, x_display): - geometry = piomatter.Geometry(width=width, height=height, n_planes=n_planes, n_addr_lines=n_addr_lines, - rotation=rotation, serpentine=serpentine, n_temporal_planes=n_temporal_planes) + n_temporal_planes, n_addr_lines, n_lanes, mirror_region, x_display): + if n_lanes != 2: + pixelmap = piomatter.make_pixelmap_multilane(width, height, n_addr_lines, n_lanes) + geometry = piomatter.Geometry(width=width, height=height, n_planes=n_planes, n_addr_lines=n_addr_lines, + n_temporal_planes=n_temporal_planes, rotation=rotation, n_lanes=n_lanes, map=pixelmap) + else: + geometry = piomatter.Geometry(width=width, height=height, n_planes=n_planes, n_addr_lines=n_addr_lines, + n_temporal_planes=n_temporal_planes, rotation=rotation) + framebuffer = np.zeros(shape=(geometry.height, geometry.width, 3), dtype=np.uint8) matrix = piomatter.PioMatter(colorspace=piomatter.Colorspace.RGB888Packed, pinout=pinout, framebuffer=framebuffer, geometry=geometry) diff --git a/src/adafruit_blinka_raspberry_pi5_piomatter/__init__.py b/src/adafruit_blinka_raspberry_pi5_piomatter/__init__.py index d3c5c7f..ca45d68 100644 --- a/src/adafruit_blinka_raspberry_pi5_piomatter/__init__.py +++ b/src/adafruit_blinka_raspberry_pi5_piomatter/__init__.py @@ -9,6 +9,22 @@ from ._piomatter import ( PioMatter, ) + +def make_pixelmap_multilane(width, height, n_addr_lines, n_lanes): + calc_height = n_lanes << n_addr_lines + if height != calc_height: + raise RuntimeError(f"Calculated height {calc_height} does not match requested height {height}") + n_addr = 1 << n_addr_lines + + m = [] + for addr in range(n_addr): + for x in range(width): + for lane in range(n_lanes): + y = addr + lane * n_addr + m.append(x + width * y) + print(m) + return m + __all__ = [ 'AdafruitMatrixBonnetRGB565', 'AdafruitMatrixBonnetRGB888', @@ -18,4 +34,5 @@ __all__ = [ 'Orientation', 'Pinout', 'PioMatter', + 'make_pixelmap_multilane', ]