Compare commits
11 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
abd7f18fc5 | ||
|
|
b057531ef1 | ||
|
|
d5a979df18 | ||
|
|
5d46945596 | ||
|
|
263f530375 | ||
|
|
e9a07d4942 | ||
|
|
792955cf1a | ||
|
|
b35b3d35bb | ||
|
|
0225964f24 | ||
| 89dd515ae5 | |||
| fc7295eb74 |
15 changed files with 150 additions and 112 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
|
@ -1,3 +0,0 @@
|
||||||
[submodule "pybind11"]
|
|
||||||
path = pybind11
|
|
||||||
url = https://github.com/pybind/pybind11.git
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
cmake_minimum_required(VERSION 3.4...3.18)
|
|
||||||
project("_piomatter")
|
|
||||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
|
|
||||||
add_subdirectory(pybind11)
|
|
||||||
|
|
||||||
pybind11_add_module("_piomatter"
|
|
||||||
src/pymain.cpp src/piolib/pio_rp1.c src/piolib/piolib.c)
|
|
||||||
target_include_directories("_piomatter" PRIVATE
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/include
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/piolib/include)
|
|
||||||
set_property(TARGET "_piomatter" PROPERTY
|
|
||||||
CXX_STANDARD 20)
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
include README.md LICENSE pybind11/LICENSE
|
|
||||||
graft pybind11/include
|
|
||||||
graft pybind11/tools
|
|
||||||
graft src
|
|
||||||
global-include CMakeLists.txt *.cmake
|
|
||||||
|
|
@ -44,7 +44,7 @@ def main(xoffset, yoffset, width, height, serpentine, rotation, pinout, n_planes
|
||||||
pixelmap = simple_multilane_mapper(width, height, n_addr_lines, n_lanes)
|
pixelmap = simple_multilane_mapper(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)
|
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)
|
||||||
else:
|
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)
|
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, serpentine=serpentine)
|
||||||
framebuffer = np.zeros(shape=(geometry.height, geometry.width), dtype=dtype)
|
framebuffer = np.zeros(shape=(geometry.height, geometry.width), dtype=dtype)
|
||||||
matrix = piomatter.PioMatter(colorspace=piomatter.Colorspace.RGB565, pinout=pinout, framebuffer=framebuffer, geometry=geometry)
|
matrix = piomatter.PioMatter(colorspace=piomatter.Colorspace.RGB565, pinout=pinout, framebuffer=framebuffer, geometry=geometry)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ def main(xoffset, yoffset, scale, width, height, serpentine, rotation, pinout, n
|
||||||
pixelmap = simple_multilane_mapper(width, height, n_addr_lines, n_lanes)
|
pixelmap = simple_multilane_mapper(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)
|
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)
|
||||||
else:
|
else:
|
||||||
geometry = piomatter.Geometry(width=width, height=height, n_planes=n_planes, n_temporal_planes=n_temporal_planes, n_addr_lines=n_addr_lines, rotation=rotation)
|
geometry = piomatter.Geometry(width=width, height=height, n_planes=n_planes, n_temporal_planes=n_temporal_planes, n_addr_lines=n_addr_lines, rotation=rotation, serpentine=serpentine)
|
||||||
matrix_framebuffer = np.zeros(shape=(geometry.height, geometry.width, 3), dtype=np.uint8)
|
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)
|
matrix = piomatter.PioMatter(colorspace=piomatter.Colorspace.RGB888Packed, pinout=pinout, framebuffer=matrix_framebuffer, geometry=geometry)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ pixelmap = simple_multilane_mapper(width, height, n_addr_lines, n_lanes)
|
||||||
geometry = piomatter.Geometry(width=width, height=height, n_addr_lines=n_addr_lines, n_planes=10, n_temporal_planes=4, map=pixelmap, n_lanes=n_lanes)
|
geometry = piomatter.Geometry(width=width, height=height, n_addr_lines=n_addr_lines, n_planes=10, n_temporal_planes=4, map=pixelmap, n_lanes=n_lanes)
|
||||||
framebuffer = np.asarray(canvas) + 0 # Make a mutable copy
|
framebuffer = np.asarray(canvas) + 0 # Make a mutable copy
|
||||||
matrix = piomatter.PioMatter(colorspace=piomatter.Colorspace.RGB888Packed,
|
matrix = piomatter.PioMatter(colorspace=piomatter.Colorspace.RGB888Packed,
|
||||||
pinout=piomatter.Pinout.Active3,
|
pinout=piomatter.Pinout.Active3BGR,
|
||||||
framebuffer=framebuffer,
|
framebuffer=framebuffer,
|
||||||
geometry=geometry)
|
geometry=geometry)
|
||||||
|
|
||||||
|
|
@ -66,7 +66,7 @@ def darken_color(hex_color, darkness_factor):
|
||||||
|
|
||||||
return darkened_hex_color
|
return darkened_hex_color
|
||||||
|
|
||||||
step_count = 4
|
step_count = 8
|
||||||
darkness_factor = 0.5
|
darkness_factor = 0.5
|
||||||
|
|
||||||
clearing = False
|
clearing = False
|
||||||
|
|
|
||||||
46
examples/triple_matrix_active3_simpletest.py
Normal file
46
examples/triple_matrix_active3_simpletest.py
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
# SPDX-FileCopyrightText: 2025 Tim Cocks for Adafruit Industries
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
"""
|
||||||
|
Display a simple test pattern of 3 shapes on three 64x64 matrix panels
|
||||||
|
using Active3 compatible connections.
|
||||||
|
|
||||||
|
Run like this:
|
||||||
|
|
||||||
|
$ python triple_matrix_active3_simpletest.py
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
from PIL import Image, ImageDraw
|
||||||
|
|
||||||
|
import adafruit_blinka_raspberry_pi5_piomatter as piomatter
|
||||||
|
from adafruit_blinka_raspberry_pi5_piomatter.pixelmappers import simple_multilane_mapper
|
||||||
|
|
||||||
|
width = 64
|
||||||
|
n_lanes = 6
|
||||||
|
n_addr_lines = 5
|
||||||
|
height = n_lanes << n_addr_lines
|
||||||
|
pen_radius = 1
|
||||||
|
|
||||||
|
canvas = Image.new('RGB', (width, height), (0, 0, 0))
|
||||||
|
draw = ImageDraw.Draw(canvas)
|
||||||
|
|
||||||
|
pixelmap = simple_multilane_mapper(width, height, n_addr_lines, n_lanes)
|
||||||
|
geometry = piomatter.Geometry(width=width, height=height, n_addr_lines=n_addr_lines, n_planes=10, n_temporal_planes=4, map=pixelmap, n_lanes=n_lanes)
|
||||||
|
framebuffer = np.asarray(canvas) + 0 # Make a mutable copy
|
||||||
|
matrix = piomatter.PioMatter(colorspace=piomatter.Colorspace.RGB888Packed,
|
||||||
|
pinout=piomatter.Pinout.Active3,
|
||||||
|
framebuffer=framebuffer,
|
||||||
|
geometry=geometry)
|
||||||
|
|
||||||
|
|
||||||
|
draw.rectangle((8, 8, width-8, width-8), fill=0x008800)
|
||||||
|
draw.circle((32, 64+32), 22, fill=0x880000)
|
||||||
|
draw.polygon([(32, 136), (54, 180), (10, 180)], fill=0x000088)
|
||||||
|
|
||||||
|
framebuffer[:] = np.asarray(canvas)
|
||||||
|
matrix.show()
|
||||||
|
|
||||||
|
input("Press enter to exit")
|
||||||
|
|
@ -57,7 +57,7 @@ def main(scale, backend, use_xauth, extra_args, rfbport, brightness, width, heig
|
||||||
n_temporal_planes=n_temporal_planes, n_lanes=n_lanes, map=pixelmap)
|
n_temporal_planes=n_temporal_planes, n_lanes=n_lanes, map=pixelmap)
|
||||||
else:
|
else:
|
||||||
geometry = piomatter.Geometry(width=width, height=height, n_planes=n_planes, n_addr_lines=n_addr_lines,
|
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_temporal_planes=n_temporal_planes, rotation=rotation, serpentine=serpentine)
|
||||||
framebuffer = np.zeros(shape=(geometry.height, geometry.width, 3), dtype=np.uint8)
|
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)
|
matrix = piomatter.PioMatter(colorspace=piomatter.Colorspace.RGB888Packed, pinout=pinout, framebuffer=framebuffer, geometry=geometry)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ def main(width, height, serpentine, rotation, pinout, n_planes,
|
||||||
n_temporal_planes=n_temporal_planes, n_lanes=n_lanes, map=pixelmap)
|
n_temporal_planes=n_temporal_planes, n_lanes=n_lanes, map=pixelmap)
|
||||||
else:
|
else:
|
||||||
geometry = piomatter.Geometry(width=width, height=height, n_planes=n_planes, n_addr_lines=n_addr_lines,
|
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_temporal_planes=n_temporal_planes, rotation=rotation, serpentine=serpentine)
|
||||||
|
|
||||||
framebuffer = np.zeros(shape=(geometry.height, geometry.width, 3), dtype=np.uint8)
|
framebuffer = np.zeros(shape=(geometry.height, geometry.width, 3), dtype=np.uint8)
|
||||||
matrix = piomatter.PioMatter(colorspace=piomatter.Colorspace.RGB888Packed, pinout=pinout, framebuffer=framebuffer,
|
matrix = piomatter.PioMatter(colorspace=piomatter.Colorspace.RGB888Packed, pinout=pinout, framebuffer=framebuffer,
|
||||||
|
|
|
||||||
1
pybind11
1
pybind11
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit a2e59f0e7065404b44dfe92a28aca47ba1378dc4
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = [
|
requires = [
|
||||||
"cmake>=3.12",
|
|
||||||
"setuptools>=42",
|
"setuptools>=42",
|
||||||
|
"pybind11>=2.10.0",
|
||||||
"setuptools_scm[toml]>=6.2",
|
"setuptools_scm[toml]>=6.2",
|
||||||
]
|
]
|
||||||
build-backend = "setuptools.build_meta"
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
|
||||||
78
setup.py
78
setup.py
|
|
@ -1,80 +1,36 @@
|
||||||
# Available at setup time due to pyproject.toml
|
# Available at setup time due to pyproject.toml
|
||||||
import multiprocessing
|
from pybind11.setup_helpers import Pybind11Extension, build_ext
|
||||||
import os
|
from setuptools import setup
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from setuptools import Extension, setup
|
|
||||||
from setuptools.command.build_ext import build_ext
|
|
||||||
from setuptools_scm import get_version
|
from setuptools_scm import get_version
|
||||||
|
|
||||||
__version__ = get_version()
|
__version__ = get_version()
|
||||||
|
|
||||||
# A CMakeExtension needs a sourcedir instead of a file list.
|
|
||||||
# The name must be the _single_ output extension from the CMake build.
|
|
||||||
# If you need multiple extensions, see scikit-build.
|
|
||||||
class CMakeExtension(Extension):
|
|
||||||
def __init__(self, name: str, sourcedir: str = "") -> None:
|
|
||||||
super().__init__(name, sources=[])
|
|
||||||
self.sourcedir = os.fspath(Path(sourcedir).resolve())
|
|
||||||
|
|
||||||
|
|
||||||
class CMakeBuild(build_ext):
|
|
||||||
def build_extension(self, ext: CMakeExtension) -> None:
|
|
||||||
# Must be in this form due to bug in .resolve() only fixed in Python 3.10+
|
|
||||||
ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name)
|
|
||||||
extdir = ext_fullpath.parent.resolve()
|
|
||||||
|
|
||||||
# Using this requires trailing slash for auto-detection & inclusion of
|
|
||||||
# auxiliary "native" libs
|
|
||||||
|
|
||||||
debug = int(os.environ.get("DEBUG", 0)) if self.debug is None else self.debug
|
|
||||||
cfg = "Debug" if debug else "Release"
|
|
||||||
|
|
||||||
# Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON
|
|
||||||
# EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code
|
|
||||||
# from Python.
|
|
||||||
cmake_args = [
|
|
||||||
"-GUnix Makefiles",
|
|
||||||
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}",
|
|
||||||
f"-DPYTHON_EXECUTABLE={sys.executable}",
|
|
||||||
f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm
|
|
||||||
]
|
|
||||||
build_args = []
|
|
||||||
# Adding CMake arguments set as environment variable
|
|
||||||
# (needed e.g. to build for ARM OSx on conda-forge)
|
|
||||||
if "CMAKE_ARGS" in os.environ:
|
|
||||||
cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item]
|
|
||||||
|
|
||||||
build_args += [f"-j{multiprocessing.cpu_count()}"]
|
|
||||||
|
|
||||||
build_temp = Path(self.build_temp) / ext.name
|
|
||||||
if not build_temp.exists():
|
|
||||||
build_temp.mkdir(parents=True)
|
|
||||||
|
|
||||||
subprocess.run(
|
|
||||||
["cmake", ext.sourcedir, *cmake_args], cwd=build_temp, check=True
|
|
||||||
)
|
|
||||||
subprocess.run(
|
|
||||||
["make", *build_args], cwd=build_temp, check=True
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# The main interface is through Pybind11Extension.
|
# The main interface is through Pybind11Extension.
|
||||||
# * You can add cxx_std=11/14/17, and then build_ext can be removed.
|
# * You can add cxx_std=11/14/17, and then build_ext can be removed.
|
||||||
# * You can set include_pybind11=false to add the include directory yourself,
|
# * You can set include_pybind11=false to add the include directory yourself,
|
||||||
# say from a submodule.
|
# say from a submodule.
|
||||||
|
|
||||||
|
ext_modules = [
|
||||||
|
Pybind11Extension("adafruit_blinka_raspberry_pi5_piomatter._piomatter",
|
||||||
|
["src/pymain.cpp", "src/piolib/piolib.c", "src/piolib/pio_rp1.c"],
|
||||||
|
define_macros = [('VERSION_INFO', __version__)],
|
||||||
|
include_dirs = ['./src/include', './src/piolib/include'],
|
||||||
|
cxx_std=20,
|
||||||
|
# use this setting when debugging
|
||||||
|
extra_compile_args = ["-g3", "-Og"],
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="Adafruit-Blinka-Raspberry-Pi5-Piomatter",
|
name="Adafruit-Blinka-Raspberry-Pi5-Piomatter",
|
||||||
version=__version__,
|
version=__version__,
|
||||||
url="https://github.com/adafruit/Adafruit_Blinka_Raspberry_Pi5_Piomatter",
|
url="https://github.com/adafruit/Adafruit_Blinka_Raspberry_Pi5_Piomatter",
|
||||||
description="HUB75 matrix driver for Raspberry Pi 5 using PIO",
|
description="HUB75 matrix driver for Raspberry Pi 5 using PIO",
|
||||||
long_description="A pio-based driver",
|
long_description="A pio-based driver",
|
||||||
ext_modules=[CMakeExtension("adafruit_blinka_raspberry_pi5_piomatter._piomatter")],
|
ext_modules=ext_modules,
|
||||||
cmdclass={"build_ext": CMakeBuild},
|
# Currently, build_ext only provides an optional "highest supported C++
|
||||||
|
# level" feature, but in the future it may provide more features.
|
||||||
|
cmdclass={"build_ext": build_ext},
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
python_requires=">=3.11",
|
python_requires=">=3.11",
|
||||||
packages=['adafruit_blinka_raspberry_pi5_piomatter'],
|
packages=['adafruit_blinka_raspberry_pi5_piomatter'],
|
||||||
|
|
|
||||||
|
|
@ -41,25 +41,6 @@ struct adafruit_matrix_bonnet_pinout_bgr {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct active3_pinout {
|
struct active3_pinout {
|
||||||
static constexpr pin_t PIN_RGB[] = {7, 27, 11, 10, 9, 8, 6, 5, 12,
|
|
||||||
20, 13, 19, 3, 2, 14, 21, 16, 26};
|
|
||||||
static constexpr pin_t PIN_ADDR[] = {22, 23, 24, 25, 15};
|
|
||||||
static constexpr pin_t PIN_OE = 18; // /OE: output enable when LOW
|
|
||||||
static constexpr pin_t PIN_CLK = 17; // SRCLK: clocks on RISING edge
|
|
||||||
static constexpr pin_t PIN_LAT = 4; // RCLK: latches on RISING edge
|
|
||||||
|
|
||||||
static constexpr uint32_t clk_bit = 1u << PIN_CLK;
|
|
||||||
static constexpr uint32_t lat_bit = 1u << PIN_LAT;
|
|
||||||
static constexpr uint32_t oe_bit = 1u << PIN_OE;
|
|
||||||
static constexpr uint32_t oe_active = 0;
|
|
||||||
static constexpr uint32_t oe_inactive = oe_bit;
|
|
||||||
|
|
||||||
static constexpr uint32_t post_oe_delay = 0;
|
|
||||||
static constexpr uint32_t post_latch_delay = 0;
|
|
||||||
static constexpr uint32_t post_addr_delay = 5;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct active3_pinout_bgr {
|
|
||||||
static constexpr pin_t PIN_RGB[] = {11, 27, 7, 8, 9, 10, 12, 5, 6,
|
static constexpr pin_t PIN_RGB[] = {11, 27, 7, 8, 9, 10, 12, 5, 6,
|
||||||
19, 13, 20, 14, 2, 3, 26, 16, 21};
|
19, 13, 20, 14, 2, 3, 26, 16, 21};
|
||||||
static constexpr pin_t PIN_ADDR[] = {22, 23, 24, 25, 15};
|
static constexpr pin_t PIN_ADDR[] = {22, 23, 24, 25, 15};
|
||||||
|
|
@ -78,4 +59,23 @@ struct active3_pinout_bgr {
|
||||||
static constexpr uint32_t post_addr_delay = 5;
|
static constexpr uint32_t post_addr_delay = 5;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct active3_pinout_bgr {
|
||||||
|
static constexpr pin_t PIN_RGB[] = {7, 27, 11, 10, 9, 8, 6, 5, 12,
|
||||||
|
20, 13, 19, 3, 2, 14, 21, 16, 26};
|
||||||
|
static constexpr pin_t PIN_ADDR[] = {22, 23, 24, 25, 15};
|
||||||
|
static constexpr pin_t PIN_OE = 18; // /OE: output enable when LOW
|
||||||
|
static constexpr pin_t PIN_CLK = 17; // SRCLK: clocks on RISING edge
|
||||||
|
static constexpr pin_t PIN_LAT = 4; // RCLK: latches on RISING edge
|
||||||
|
|
||||||
|
static constexpr uint32_t clk_bit = 1u << PIN_CLK;
|
||||||
|
static constexpr uint32_t lat_bit = 1u << PIN_LAT;
|
||||||
|
static constexpr uint32_t oe_bit = 1u << PIN_OE;
|
||||||
|
static constexpr uint32_t oe_active = 0;
|
||||||
|
static constexpr uint32_t oe_inactive = oe_bit;
|
||||||
|
|
||||||
|
static constexpr uint32_t post_oe_delay = 0;
|
||||||
|
static constexpr uint32_t post_latch_delay = 0;
|
||||||
|
static constexpr uint32_t post_addr_delay = 5;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace piomatter
|
} // namespace piomatter
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,42 @@
|
||||||
|
|
||||||
namespace piomatter {
|
namespace piomatter {
|
||||||
|
|
||||||
|
static int pio_sm_xfer_data_large(PIO pio, int sm, int direction, size_t size,
|
||||||
|
uint32_t *databuf) {
|
||||||
|
#if 0
|
||||||
|
// it would be NICE to gracefully fall back to blocked transfer, but sadly
|
||||||
|
// once the large xfer ioctl fails, future small xfers fail too.
|
||||||
|
static enum { UNKNOWN, OK, BAD } large_xfer_status = UNKNOWN;
|
||||||
|
printf("large_xfer_status=%d\n", large_xfer_status);
|
||||||
|
if (large_xfer_status != BAD) {
|
||||||
|
int r = pio_sm_xfer_data(pio, sm, direction, size, databuf);
|
||||||
|
if (large_xfer_status == UNKNOWN && r != 0) {
|
||||||
|
large_xfer_status = BAD;
|
||||||
|
fprintf(stderr,
|
||||||
|
"Transmission limit workaround engaged. May reduce quality of "
|
||||||
|
"output.\nSee https://github.com/raspberrypi/utils/issues/123 "
|
||||||
|
"for details.\n");
|
||||||
|
} else {
|
||||||
|
if (large_xfer_status == UNKNOWN && r == 0) {
|
||||||
|
large_xfer_status = OK;
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
constexpr size_t MAX_XFER = 65532;
|
||||||
|
while (size) {
|
||||||
|
size_t xfersize = std::min(size_t{MAX_XFER}, size);
|
||||||
|
int r = pio_sm_xfer_data(pio, sm, direction, xfersize, databuf);
|
||||||
|
if (r != 0) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
size -= xfersize;
|
||||||
|
databuf += xfersize / sizeof(*databuf);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static uint64_t monotonicns64() {
|
static uint64_t monotonicns64() {
|
||||||
struct timespec tp;
|
struct timespec tp;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &tp);
|
clock_gettime(CLOCK_MONOTONIC, &tp);
|
||||||
|
|
@ -26,7 +62,7 @@ struct piomatter_base {
|
||||||
piomatter_base &operator=(const piomatter_base &) = delete;
|
piomatter_base &operator=(const piomatter_base &) = delete;
|
||||||
|
|
||||||
virtual ~piomatter_base() {}
|
virtual ~piomatter_base() {}
|
||||||
virtual void show() = 0;
|
virtual int show() = 0;
|
||||||
|
|
||||||
double fps;
|
double fps;
|
||||||
};
|
};
|
||||||
|
|
@ -48,7 +84,11 @@ struct piomatter : piomatter_base {
|
||||||
show();
|
show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void show() override {
|
int show() override {
|
||||||
|
int err = pending_error_errno.exchange(0); // we're handling this error
|
||||||
|
if (err != 0) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
int buffer_idx = manager.get_free_buffer();
|
int buffer_idx = manager.get_free_buffer();
|
||||||
auto &bufseq = buffers[buffer_idx];
|
auto &bufseq = buffers[buffer_idx];
|
||||||
bufseq.resize(geometry.schedules.size());
|
bufseq.resize(geometry.schedules.size());
|
||||||
|
|
@ -61,6 +101,7 @@ struct piomatter : piomatter_base {
|
||||||
old_active_time = geometry.schedules[i].back().active_time;
|
old_active_time = geometry.schedules[i].back().active_time;
|
||||||
}
|
}
|
||||||
manager.put_filled_buffer(buffer_idx);
|
manager.put_filled_buffer(buffer_idx);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
~piomatter() {
|
~piomatter() {
|
||||||
|
|
@ -174,7 +215,15 @@ struct piomatter : piomatter_base {
|
||||||
const auto &data = cur_buf[seq_idx];
|
const auto &data = cur_buf[seq_idx];
|
||||||
auto datasize = sizeof(uint32_t) * data.size();
|
auto datasize = sizeof(uint32_t) * data.size();
|
||||||
auto dataptr = const_cast<uint32_t *>(&data[0]);
|
auto dataptr = const_cast<uint32_t *>(&data[0]);
|
||||||
pio_sm_xfer_data(pio, sm, PIO_DIR_TO_SM, datasize, dataptr);
|
// returns err = rp1_ioctl.... which seems to be a negative
|
||||||
|
// errno value
|
||||||
|
int r = pio_sm_xfer_data_large(pio, sm, PIO_DIR_TO_SM, datasize,
|
||||||
|
dataptr);
|
||||||
|
if (r != 0) {
|
||||||
|
pending_error_errno.store(errno);
|
||||||
|
printf("xfer_data() returned error %d (errno=%s)\n", r,
|
||||||
|
strerror(errno));
|
||||||
|
}
|
||||||
t1 = monotonicns64();
|
t1 = monotonicns64();
|
||||||
if (t0 != t1) {
|
if (t0 != t1) {
|
||||||
fps = 1e9 / (t1 - t0);
|
fps = 1e9 / (t1 - t0);
|
||||||
|
|
@ -194,6 +243,7 @@ struct piomatter : piomatter_base {
|
||||||
matrix_geometry geometry;
|
matrix_geometry geometry;
|
||||||
colorspace converter;
|
colorspace converter;
|
||||||
std::thread blitter_thread;
|
std::thread blitter_thread;
|
||||||
|
std::atomic<int> pending_error_errno;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace piomatter
|
} // namespace piomatter
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,14 @@ struct PyPiomatter {
|
||||||
py::buffer buffer;
|
py::buffer buffer;
|
||||||
std::unique_ptr<piomatter::piomatter_base> matter;
|
std::unique_ptr<piomatter::piomatter_base> matter;
|
||||||
|
|
||||||
void show() { matter->show(); }
|
void show() {
|
||||||
|
int err = matter->show();
|
||||||
|
if (err != 0) {
|
||||||
|
errno = err;
|
||||||
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
|
throw py::error_already_set();
|
||||||
|
}
|
||||||
|
}
|
||||||
double fps() const { return matter->fps; }
|
double fps() const { return matter->fps; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue