Format code with pre-commit
This commit is contained in:
parent
a2f1470548
commit
f33e9ca82e
2 changed files with 81 additions and 63 deletions
|
|
@ -40,5 +40,4 @@ struct adafruit_matrix_bonnet_pinout_bgr {
|
|||
static constexpr uint32_t post_addr_delay = 500;
|
||||
};
|
||||
|
||||
|
||||
} // namespace piomatter
|
||||
|
|
|
|||
143
src/pymain.cpp
143
src/pymain.cpp
|
|
@ -23,7 +23,8 @@ struct PyPiomatter {
|
|||
|
||||
template <typename pinout, typename colorspace>
|
||||
std::unique_ptr<PyPiomatter>
|
||||
make_piomatter_pc(py::buffer buffer, const piomatter::matrix_geometry &geometry) {
|
||||
make_piomatter_pc(py::buffer buffer,
|
||||
const piomatter::matrix_geometry &geometry) {
|
||||
using cls = piomatter::piomatter<pinout, colorspace>;
|
||||
using data_type = colorspace::data_type;
|
||||
|
||||
|
|
@ -34,9 +35,11 @@ make_piomatter_pc(py::buffer buffer, const piomatter::matrix_geometry &geometry)
|
|||
|
||||
if (buffer_size_in_bytes != data_size_in_bytes) {
|
||||
throw std::runtime_error(
|
||||
py::str(
|
||||
"Framebuffer size must be {} bytes ({} elements of {} bytes each), got a buffer of {} bytes")
|
||||
.attr("format")(data_size_in_bytes, n_pixels, colorspace::data_size_in_bytes(1), buffer_size_in_bytes)
|
||||
py::str("Framebuffer size must be {} bytes ({} elements of {} "
|
||||
"bytes each), got a buffer of {} bytes")
|
||||
.attr("format")(data_size_in_bytes, n_pixels,
|
||||
colorspace::data_size_in_bytes(1),
|
||||
buffer_size_in_bytes)
|
||||
.template cast<std::string>());
|
||||
}
|
||||
|
||||
|
|
@ -46,44 +49,49 @@ make_piomatter_pc(py::buffer buffer, const piomatter::matrix_geometry &geometry)
|
|||
buffer, std::move(std::make_unique<cls>(framebuffer, geometry)));
|
||||
}
|
||||
|
||||
enum Colorspace {
|
||||
RGB565, RGB888, RGB888Packed
|
||||
};
|
||||
enum Colorspace { RGB565, RGB888, RGB888Packed };
|
||||
|
||||
enum Pinout {
|
||||
AdafruitMatrixBonnet,
|
||||
AdafruitMatrixBonnetBGR,
|
||||
};
|
||||
|
||||
template<class pinout>
|
||||
template <class pinout>
|
||||
std::unique_ptr<PyPiomatter>
|
||||
make_piomatter_p(Colorspace c, py::buffer buffer, const piomatter::matrix_geometry &geometry) {
|
||||
switch(c) {
|
||||
case RGB565:
|
||||
return make_piomatter_pc<pinout, piomatter::colorspace_rgb565>(buffer, geometry);
|
||||
case RGB888:
|
||||
return make_piomatter_pc<pinout, piomatter::colorspace_rgb888>(buffer, geometry);
|
||||
case RGB888Packed:
|
||||
return make_piomatter_pc<pinout, piomatter::colorspace_rgb888_packed>(buffer, geometry);
|
||||
make_piomatter_p(Colorspace c, py::buffer buffer,
|
||||
const piomatter::matrix_geometry &geometry) {
|
||||
switch (c) {
|
||||
case RGB565:
|
||||
return make_piomatter_pc<pinout, piomatter::colorspace_rgb565>(
|
||||
buffer, geometry);
|
||||
case RGB888:
|
||||
return make_piomatter_pc<pinout, piomatter::colorspace_rgb888>(
|
||||
buffer, geometry);
|
||||
case RGB888Packed:
|
||||
return make_piomatter_pc<pinout, piomatter::colorspace_rgb888_packed>(
|
||||
buffer, geometry);
|
||||
|
||||
default:
|
||||
throw std::runtime_error(
|
||||
py::str("Invalid colorspace {!r}").attr("format")(c)
|
||||
.template cast<std::string>());
|
||||
default:
|
||||
throw std::runtime_error(py::str("Invalid colorspace {!r}")
|
||||
.attr("format")(c)
|
||||
.template cast<std::string>());
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<PyPiomatter>
|
||||
make_piomatter(Colorspace c, Pinout p, py::buffer buffer, const piomatter::matrix_geometry &geometry) {
|
||||
switch(p) {
|
||||
case AdafruitMatrixBonnet:
|
||||
return make_piomatter_p<piomatter::adafruit_matrix_bonnet_pinout>(c, buffer, geometry);
|
||||
case AdafruitMatrixBonnetBGR:
|
||||
return make_piomatter_p<piomatter::adafruit_matrix_bonnet_pinout_bgr>(c, buffer, geometry);
|
||||
default:
|
||||
throw std::runtime_error(
|
||||
py::str("Invalid pinout {!r}").attr("format")(p)
|
||||
.template cast<std::string>());
|
||||
make_piomatter(Colorspace c, Pinout p, py::buffer buffer,
|
||||
const piomatter::matrix_geometry &geometry) {
|
||||
switch (p) {
|
||||
case AdafruitMatrixBonnet:
|
||||
return make_piomatter_p<piomatter::adafruit_matrix_bonnet_pinout>(
|
||||
c, buffer, geometry);
|
||||
case AdafruitMatrixBonnetBGR:
|
||||
return make_piomatter_p<piomatter::adafruit_matrix_bonnet_pinout_bgr>(
|
||||
c, buffer, geometry);
|
||||
default:
|
||||
throw std::runtime_error(py::str("Invalid pinout {!r}")
|
||||
.attr("format")(p)
|
||||
.template cast<std::string>());
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
|
@ -121,18 +129,22 @@ PYBIND11_MODULE(adafruit_raspberry_pi5_piomatter, m) {
|
|||
|
||||
py::enum_<Pinout>(
|
||||
m, "Pinout", "Describes the pins used for the connection to the matrix")
|
||||
.value("AdafruitMatrixBonnet", Pinout::AdafruitMatrixBonnet, "Adafruit Matrix Bonnet or Matrix Hat")
|
||||
.value("AdafruitMatrixBonnetBGR", Pinout::AdafruitMatrixBonnet, "Adafruit Matrix Bonnet or Matrix Hat with BGR color order")
|
||||
.value("AdafruitMatrixHat", Pinout::AdafruitMatrixBonnet, "Adafruit Matrix Bonnet or Matrix Hat")
|
||||
.value("AdafruitMatrixHatBGR", Pinout::AdafruitMatrixBonnet, "Adafruit Matrix Bonnet or Matrix Hat with BGR color order")
|
||||
;
|
||||
.value("AdafruitMatrixBonnet", Pinout::AdafruitMatrixBonnet,
|
||||
"Adafruit Matrix Bonnet or Matrix Hat")
|
||||
.value("AdafruitMatrixBonnetBGR", Pinout::AdafruitMatrixBonnet,
|
||||
"Adafruit Matrix Bonnet or Matrix Hat with BGR color order")
|
||||
.value("AdafruitMatrixHat", Pinout::AdafruitMatrixBonnet,
|
||||
"Adafruit Matrix Bonnet or Matrix Hat")
|
||||
.value("AdafruitMatrixHatBGR", Pinout::AdafruitMatrixBonnet,
|
||||
"Adafruit Matrix Bonnet or Matrix Hat with BGR color order");
|
||||
|
||||
py::enum_<Colorspace>(
|
||||
m, "Colorspace", "Describes the organization of the graphics data in memory")
|
||||
.value("RGB888Packed", Colorspace::RGB888Packed, "3 bytes per pixel in RGB order")
|
||||
m, "Colorspace",
|
||||
"Describes the organization of the graphics data in memory")
|
||||
.value("RGB888Packed", Colorspace::RGB888Packed,
|
||||
"3 bytes per pixel in RGB order")
|
||||
.value("RGB888", Colorspace::RGB888, "4 bytes per pixel in RGB order")
|
||||
.value("RGB565", Colorspace::RGB565, "2 bytes per pixel in RGB order")
|
||||
;
|
||||
.value("RGB565", Colorspace::RGB565, "2 bytes per pixel in RGB order");
|
||||
|
||||
py::class_<piomatter::matrix_geometry>(m, "Geometry", R"pbdoc(
|
||||
Describe the geometry of a set of panels
|
||||
|
|
@ -198,9 +210,8 @@ The default, 10, is the maximum value.
|
|||
py::class_<PyPiomatter>(m, "PioMatter", R"pbdoc(
|
||||
HUB75 matrix driver for Raspberry Pi 5 using PIO
|
||||
)pbdoc")
|
||||
.def(py::init(&make_piomatter),
|
||||
py::arg("colorspace"), py::arg("pinout"),
|
||||
py::arg("framebuffer"), py::arg("geometry"))
|
||||
.def(py::init(&make_piomatter), py::arg("colorspace"),
|
||||
py::arg("pinout"), py::arg("framebuffer"), py::arg("geometry"))
|
||||
.def("show", &PyPiomatter::show, R"pbdoc(
|
||||
Update the displayed image
|
||||
|
||||
|
|
@ -212,26 +223,31 @@ data is triple-buffered to prevent tearing.
|
|||
The approximate number of matrix refreshes per second.
|
||||
)pbdoc");
|
||||
|
||||
m.def("AdafruitMatrixBonnetRGB565",
|
||||
[](py::buffer buffer, const piomatter::matrix_geometry &geometry) {
|
||||
return make_piomatter(Colorspace::RGB565, Pinout::AdafruitMatrixBonnet, buffer, geometry);
|
||||
},
|
||||
py::arg("buffer"), py::arg("geometry"),
|
||||
R"pbdoc(
|
||||
m.def(
|
||||
"AdafruitMatrixBonnetRGB565",
|
||||
[](py::buffer buffer, const piomatter::matrix_geometry &geometry) {
|
||||
return make_piomatter(Colorspace::RGB565,
|
||||
Pinout::AdafruitMatrixBonnet, buffer,
|
||||
geometry);
|
||||
},
|
||||
py::arg("buffer"), py::arg("geometry"),
|
||||
R"pbdoc(
|
||||
Construct a PioMatter object to drive panels connected to an
|
||||
Adafruit Matrix Bonnet using the RGB565 memory layout (2 bytes per
|
||||
pixel)
|
||||
|
||||
This is deprecated shorthand for `PioMatter(Colorspace.RGB565, Pinout.AdafruitMatrixBonnet, ...)`.
|
||||
)pbdoc")
|
||||
;
|
||||
)pbdoc");
|
||||
|
||||
m.def("AdafruitMatrixBonnetRGB888",
|
||||
[](py::buffer buffer, const piomatter::matrix_geometry &geometry) {
|
||||
return make_piomatter(Colorspace::RGB888, Pinout::AdafruitMatrixBonnet, buffer, geometry);
|
||||
},
|
||||
py::arg("framebuffer"), py::arg("geometry"),
|
||||
R"pbdoc(
|
||||
m.def(
|
||||
"AdafruitMatrixBonnetRGB888",
|
||||
[](py::buffer buffer, const piomatter::matrix_geometry &geometry) {
|
||||
return make_piomatter(Colorspace::RGB888,
|
||||
Pinout::AdafruitMatrixBonnet, buffer,
|
||||
geometry);
|
||||
},
|
||||
py::arg("framebuffer"), py::arg("geometry"),
|
||||
R"pbdoc(
|
||||
Construct a PioMatter object to drive panels connected to an
|
||||
Adafruit Matrix Bonnet using the RGB888 memory layout (4 bytes per
|
||||
pixel)
|
||||
|
|
@ -241,12 +257,15 @@ This is deprecated shorthand for `PioMatter(Colorspace.RGB888, Pinout.AdafruitMa
|
|||
//.doc() =
|
||||
;
|
||||
|
||||
m.def("AdafruitMatrixBonnetRGB888Packed",
|
||||
[](py::buffer buffer, const piomatter::matrix_geometry &geometry) {
|
||||
return make_piomatter(Colorspace::RGB888Packed, Pinout::AdafruitMatrixBonnet, buffer, geometry);
|
||||
},
|
||||
py::arg("framebuffer"), py::arg("geometry"),
|
||||
R"pbdoc(
|
||||
m.def(
|
||||
"AdafruitMatrixBonnetRGB888Packed",
|
||||
[](py::buffer buffer, const piomatter::matrix_geometry &geometry) {
|
||||
return make_piomatter(Colorspace::RGB888Packed,
|
||||
Pinout::AdafruitMatrixBonnet, buffer,
|
||||
geometry);
|
||||
},
|
||||
py::arg("framebuffer"), py::arg("geometry"),
|
||||
R"pbdoc(
|
||||
Construct a PioMatter object to drive panels connected to an
|
||||
Adafruit Matrix Bonnet using the RGB888 packed memory layout (3
|
||||
bytes per pixel)
|
||||
|
|
|
|||
Loading…
Reference in a new issue