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