Compare commits

...

2 commits

Author SHA1 Message Date
d120ecab66 Allow passing in the matrix map directly to a Geometry object
Some checks failed
Pip / build (ubuntu-24.04-arm, 3.11) (push) Has been cancelled
Pip / build (ubuntu-24.04-arm, 3.12) (push) Has been cancelled
Pip / build (ubuntu-24.04-arm, 3.13) (push) Has been cancelled
pre-commit / pre-commit (push) Has been cancelled
Wheels / Build SDist (push) Has been cancelled
Wheels / Wheels on ubuntu-24.04-arm (push) Has been cancelled
Wheels / Upload release (push) Has been cancelled
2025-02-18 12:08:32 -06:00
86cef28c18 Move everything to a package structure 2025-02-16 09:55:48 -06:00
5 changed files with 47 additions and 6 deletions

1
.gitignore vendored
View file

@ -1,4 +1,3 @@
/*.pio.h
protodemo
/build
*.egg-info

View file

@ -11,7 +11,7 @@ __version__ = get_version()
# say from a submodule.
ext_modules = [
Pybind11Extension("adafruit_blinka_raspberry_pi5_piomatter",
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'],
@ -33,6 +33,8 @@ setup(
cmdclass={"build_ext": build_ext},
zip_safe=False,
python_requires=">=3.11",
packages=['adafruit_blinka_raspberry_pi5_piomatter'],
package_dir={'adafruit_blinka_raspberry_pi5_piomatter': 'src/adafruit_blinka_raspberry_pi5_piomatter'},
extras_require={
'docs': ["sphinx", "sphinx-rtd-theme", "sphinxcontrib-jquery"],
},

View file

@ -0,0 +1,21 @@
from ._piomatter import (
AdafruitMatrixBonnetRGB565,
AdafruitMatrixBonnetRGB888,
AdafruitMatrixBonnetRGB888Packed,
Colorspace,
Geometry,
Orientation,
Pinout,
PioMatter,
)
__all__ = [
'AdafruitMatrixBonnetRGB565',
'AdafruitMatrixBonnetRGB888',
'AdafruitMatrixBonnetRGB888Packed',
'Colorspace',
'Geometry',
'Orientation',
'Pinout',
'PioMatter',
]

View file

@ -84,16 +84,21 @@ struct matrix_geometry {
template <typename Cb>
matrix_geometry(size_t pixels_across, size_t n_addr_lines, int n_planes,
size_t width, size_t height, bool serpentine, const Cb &cb)
: matrix_geometry(
pixels_across, n_addr_lines, n_planes, width, height,
make_matrixmap(width, height, n_addr_lines, serpentine, cb)) {}
matrix_geometry(size_t pixels_across, size_t n_addr_lines, int n_planes,
size_t width, size_t height, matrix_map map)
: pixels_across(pixels_across), n_addr_lines(n_addr_lines),
n_planes(n_planes), width(width),
height(height), map{make_matrixmap(width, height, n_addr_lines,
serpentine, cb)} {
n_planes(n_planes), width(width), height(height), map(map) {
size_t pixels_down = 2u << n_addr_lines;
if (map.size() != pixels_down * pixels_across) {
throw std::range_error(
"map size does not match calculated pixel count");
}
}
size_t pixels_across, n_addr_lines;
int n_planes;
size_t width, height;

View file

@ -96,7 +96,7 @@ make_piomatter(Colorspace c, Pinout p, py::buffer buffer,
}
} // namespace
PYBIND11_MODULE(adafruit_blinka_raspberry_pi5_piomatter, m) {
PYBIND11_MODULE(_piomatter, m) {
py::options options;
options.enable_enum_members_docstring();
options.enable_function_signatures();
@ -209,6 +209,20 @@ The default, 10, is the maximum value.
py::arg("serpentine") = true,
py::arg("rotation") = piomatter::orientation::normal,
py::arg("n_planes") = 10u)
.def(py::init([](size_t width, size_t height, size_t n_addr_lines,
piomatter::matrix_map map, size_t n_planes) {
size_t n_lines = 2 << n_addr_lines;
size_t pixels_across = width * height / n_lines;
for (auto el : map) {
if ((size_t)el >= width * height) {
throw std::out_of_range("Map element out of range");
}
}
return piomatter::matrix_geometry(
pixels_across, n_addr_lines, n_planes, width, height, map);
}),
py::arg("width"), py::arg("height"), py::arg("n_addr_lines"),
py::arg("map"), py::arg("n_planes") = 10u)
.def_readonly("width", &piomatter::matrix_geometry::width)
.def_readonly("height", &piomatter::matrix_geometry::height);