rename everything per discussion
This commit is contained in:
parent
277e0a08a5
commit
9b64b9b088
14 changed files with 127 additions and 58 deletions
2
.clang-format
Normal file
2
.clang-format
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
BasedOnStyle: LLVM
|
||||
IndentWidth: 4
|
||||
36
.github/workflows/pip.yml
vendored
Normal file
36
.github/workflows/pip.yml
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
name: Pip
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
pull_request:
|
||||
push:
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
platform: ["ubuntu-latest"]
|
||||
python-version: ["3.11", "3.12", "3.13"]
|
||||
|
||||
runs-on: ${{ matrix.platform }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
fetch-depth: 0
|
||||
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
|
||||
- name: Add requirements
|
||||
run: python -m pip install --upgrade wheel setuptools
|
||||
|
||||
- name: Build and install
|
||||
run: pip install --verbose .
|
||||
14
.github/workflows/wheels.yml
vendored
14
.github/workflows/wheels.yml
vendored
|
|
@ -18,6 +18,9 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Build SDist
|
||||
run: pipx run build --sdist
|
||||
|
|
@ -39,10 +42,13 @@ jobs:
|
|||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: ubuntu-latest
|
||||
arch_linux: aarch64
|
||||
os: ["ubuntu-latest"]
|
||||
arch_linux: ["aarch64"]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
|
@ -52,8 +58,8 @@ jobs:
|
|||
- uses: pypa/cibuildwheel@v2.22.0
|
||||
env:
|
||||
CIBW_ARCHS_LINUX: ${{ matrix.arch_linux }}
|
||||
CIBW_BUILD: "cp311* cp312* cp313*"
|
||||
|
||||
CIBW_BUILD: "cp311-manylinux* cp312-manylinux* cp313-manylinux*"
|
||||
CIBW_MANYLINUX_AARCH64_IMAGE: "manylinux_2_28"
|
||||
- name: Verify clean directory
|
||||
run: git diff --exit-code
|
||||
shell: bash
|
||||
|
|
|
|||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -72,6 +72,7 @@ instance/
|
|||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
docs/_generate/
|
||||
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ repos:
|
|||
- id: remove-tabs
|
||||
|
||||
# Suggested hook if you add a .clang-format file
|
||||
# - repo: https://github.com/pre-commit/mirrors-clang-format
|
||||
# rev: v13.0.0
|
||||
# hooks:
|
||||
# - id: clang-format
|
||||
- repo: https://github.com/pre-commit/mirrors-clang-format
|
||||
rev: v13.0.0
|
||||
hooks:
|
||||
- id: clang-format
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@
|
|||
# Required
|
||||
version: 2
|
||||
|
||||
submodules:
|
||||
include: all
|
||||
|
||||
build:
|
||||
os: ubuntu-lts-latest
|
||||
tools:
|
||||
|
|
@ -15,5 +18,7 @@ build:
|
|||
|
||||
python:
|
||||
install:
|
||||
- requirements: docs/requirements.txt
|
||||
- requirements: requirements.txt
|
||||
- method: pip
|
||||
path: .
|
||||
extra_requirements:
|
||||
- docs
|
||||
|
|
|
|||
18
README.md
18
README.md
|
|
@ -6,11 +6,11 @@ adafruit-blinka-neopixel-pi5
|
|||
| pip builds | [![Pip Actions Status][actions-pip-badge]][actions-pip-link] |
|
||||
| [`cibuildwheel`][] | [![Wheels Actions Status][actions-wheels-badge]][actions-wheels-link] |
|
||||
|
||||
[actions-badge]: https://github.com/adafruit/adafruit-blinka-neopixel-pi5/workflows/Tests/badge.svg
|
||||
[actions-pip-link]: https://github.com/adafruit/adafruit-blinka-neopixel-pi5/actions?query=workflow%3A%22Pip
|
||||
[actions-pip-badge]: https://github.com/adafruit/adafruit-blinka-neopixel-pi5/workflows/Pip/badge.svg
|
||||
[actions-wheels-link]: https://github.com/adafruit/adafruit-blinka-neopixel-pi5/actions?query=workflow%3AWheels
|
||||
[actions-wheels-badge]: https://github.com/adafruit/adafruit-blinka-neopixel-pi5/workflows/Wheels/badge.svg
|
||||
[actions-badge]: https://github.com/adafruit/Adafruit_Blinka_Raspberry_Pi5_Neopixel/workflows/Tests/badge.svg
|
||||
[actions-pip-link]: https://github.com/adafruit/Adafruit_Blinka_Raspberry_Pi5_Neopixel/actions?query=workflow%3A%22Pip
|
||||
[actions-pip-badge]: https://github.com/adafruit/Adafruit_Blinka_Raspberry_Pi5_Neopixel/workflows/Pip/badge.svg
|
||||
[actions-wheels-link]: https://github.com/adafruit/Adafruit_Blinka_Raspberry_Pi5_Neopixel/actions?query=workflow%3AWheels
|
||||
[actions-wheels-badge]: https://github.com/adafruit/Adafruit_Blinka_Raspberry_Pi5_Neopixel/workflows/Wheels/badge.svg
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
|
@ -18,11 +18,11 @@ Installation
|
|||
Installing from source:
|
||||
|
||||
- clone this repository
|
||||
- `pip install ./adafruit-blinka-neopixel-pi5`
|
||||
- `pip install ./Adafruit_Blinka_Raspberry_Pi5_Neopixel`
|
||||
|
||||
Installing from pip (not yet available):
|
||||
Installing from pip:
|
||||
|
||||
- `pip install adafruit-blinka-neopixel-pi5`
|
||||
- `pip install Adafruit-Blinka-Raspberry-Pi5-Neopixel`
|
||||
|
||||
Building the documentation
|
||||
--------------------------
|
||||
|
|
@ -33,7 +33,7 @@ the extension module to generate beautiful documentation in a variety formats.
|
|||
The following command generates HTML-based reference documentation; for other
|
||||
formats please refer to the Sphinx manual:
|
||||
|
||||
- `cd adafruit-blinka-neopixel-pi5/docs`
|
||||
- `cd Adafruit_Blinka_Raspberry_Pi5_Neopixel/docs`
|
||||
- `make html`
|
||||
|
||||
License
|
||||
|
|
|
|||
1
docs/adafruit_raspberry_pi5_neopixel_write.rst
Normal file
1
docs/adafruit_raspberry_pi5_neopixel_write.rst
Normal file
|
|
@ -0,0 +1 @@
|
|||
.. automodule:: adafruit_raspberry_pi5_neopixel_write
|
||||
|
|
@ -111,7 +111,7 @@ todo_include_todos = False
|
|||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
html_theme = "alabaster"
|
||||
html_theme = "sphinx_rtd_theme"
|
||||
|
||||
# Theme options are theme-specific and customize the look and feel of a theme
|
||||
# further. For a list of options available for each theme, see the
|
||||
|
|
|
|||
|
|
@ -6,4 +6,4 @@ Contents:
|
|||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
neopixel_write_pi5
|
||||
adafruit_raspberry_pi5_neopixel_write
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
.. automodule:: adafruit-blinka-neopixel-pi5
|
||||
|
|
@ -1,12 +1,14 @@
|
|||
import adafruit_pixelbuf
|
||||
import board
|
||||
import neopixel_write_pi5
|
||||
from adafruit_led_animation.animation.rainbow import Rainbow
|
||||
from adafruit_led_animation.animation.rainbowchase import RainbowChase
|
||||
from adafruit_led_animation.animation.rainbowcomet import RainbowComet
|
||||
from adafruit_led_animation.animation.rainbowsparkle import RainbowSparkle
|
||||
from adafruit_led_animation.sequence import AnimationSequence
|
||||
from adafruit_raspberry_pi5_neopixel_write import neopixel_write
|
||||
|
||||
NEOPIXEL = board.D13
|
||||
num_pixels = 96
|
||||
|
||||
class Pi5Pixelbuf(adafruit_pixelbuf.PixelBuf):
|
||||
def __init__(self, pin, size, **kwargs):
|
||||
|
|
@ -14,9 +16,9 @@ class Pi5Pixelbuf(adafruit_pixelbuf.PixelBuf):
|
|||
super().__init__(size=size, **kwargs)
|
||||
|
||||
def _transmit(self, buf):
|
||||
neopixel_write_pi5.neopixel_write(self._pin, buf)
|
||||
neopixel_write(self._pin, buf)
|
||||
|
||||
pixels = Pi5Pixelbuf(board.D13, 120, auto_write=True, byteorder="WBGR")
|
||||
pixels = Pi5Pixelbuf(NEOPIXEL, num_pixels, auto_write=True, byteorder="BGR")
|
||||
|
||||
rainbow = Rainbow(pixels, speed=0.02, period=2)
|
||||
rainbow_chase = RainbowChase(pixels, speed=0.02, size=5, spacing=3)
|
||||
|
|
@ -33,9 +35,5 @@ animations = AnimationSequence(
|
|||
auto_clear=True,
|
||||
)
|
||||
|
||||
try:
|
||||
while True:
|
||||
animations.animate()
|
||||
finally:
|
||||
pixels.fill(0)
|
||||
pixels.show()
|
||||
while True:
|
||||
animations.animate()
|
||||
|
|
|
|||
13
setup.py
13
setup.py
|
|
@ -11,19 +11,19 @@ __version__ = get_version()
|
|||
# say from a submodule.
|
||||
|
||||
ext_modules = [
|
||||
Pybind11Extension("neopixel_write_pi5",
|
||||
Pybind11Extension("adafruit_raspberry_pi5_neopixel_write",
|
||||
["src/main.cpp", "src/utils/piolib/piolib.c", "src/utils/piolib/pio_rp1.c"],
|
||||
define_macros = [('VERSION_INFO', __version__)],
|
||||
include_dirs = ['./src/utils/piolib/include'],
|
||||
cxx_std = "20",
|
||||
extra_compile_args = ["-g3"],
|
||||
# use this setting when debugging
|
||||
#extra_compile_args = ["-g3", "-Og"],
|
||||
),
|
||||
]
|
||||
|
||||
setup(
|
||||
name="adafruit-blinka-neopixel-pi5",
|
||||
name="Adafruit-Blinka-Raspberry-Pi5-Neopixel",
|
||||
version=__version__,
|
||||
url="https://github.com/adafruit/adafruit-blinka-neopixel-pi5",
|
||||
url="https://github.com/adafruit/Adafruit_Blinka_Raspberry_Pi5_Neopixel",
|
||||
description="Control NeoPixel & compatibles on a Pi 5",
|
||||
long_description="A pio-based driver",
|
||||
ext_modules=ext_modules,
|
||||
|
|
@ -32,4 +32,7 @@ setup(
|
|||
cmdclass={"build_ext": build_ext},
|
||||
zip_safe=False,
|
||||
python_requires=">=3.11",
|
||||
extras_require={
|
||||
'docs': ["sphinx", "sphinx-rtd-theme", "sphinxcontrib-jquery"],
|
||||
},
|
||||
)
|
||||
|
|
|
|||
62
src/main.cpp
62
src/main.cpp
|
|
@ -13,6 +13,7 @@ static PIO pio{};
|
|||
static int sm{-1};
|
||||
static int offset{-1};
|
||||
static int last_gpio{-1};
|
||||
static size_t last_size{};
|
||||
|
||||
static void neopixel_write(py::object gpio_obj, py::buffer buf) {
|
||||
int gpio = py::getattr(gpio_obj, "_pin", gpio_obj).attr("id").cast<int>();
|
||||
|
|
@ -26,9 +27,11 @@ static void neopixel_write(py::object gpio_obj, py::buffer buf) {
|
|||
|
||||
// can't use `pio0` macro as it will call exit() on failure!
|
||||
pio = pio_open(0);
|
||||
if(PIO_IS_ERR(pio)) {
|
||||
if (PIO_IS_ERR(pio)) {
|
||||
throw std::runtime_error(
|
||||
py::str("Failed to open PIO device (error {})").attr("format")(PIO_ERR_VAL(pio)).cast<std::string>());
|
||||
py::str("Failed to open PIO device (error {})")
|
||||
.attr("format")(PIO_ERR_VAL(pio))
|
||||
.cast<std::string>());
|
||||
}
|
||||
|
||||
sm = pio_claim_unused_sm(pio, true);
|
||||
|
|
@ -38,61 +41,76 @@ static void neopixel_write(py::object gpio_obj, py::buffer buf) {
|
|||
pio_sm_clear_fifos(pio, sm);
|
||||
pio_sm_set_clkdiv(pio, sm, 1.0);
|
||||
|
||||
printf("Loaded program at %d, using sm %d\n", offset, sm, gpio);
|
||||
last_gpio = -1;
|
||||
}
|
||||
|
||||
if (gpio != last_gpio) {
|
||||
ws2812_program_init(pio, sm, offset, gpio, 800000.0, false);
|
||||
printf("Initialized program at %d, using sm %d, gpio %d\n", offset, sm, gpio);
|
||||
ws2812_program_init(pio, sm, offset, gpio, 800000.0, true);
|
||||
last_gpio = gpio;
|
||||
}
|
||||
|
||||
size_t size = info.size * info.itemsize;
|
||||
|
||||
if(size > UINT16_MAX) {
|
||||
// rp1pio can only DMA in 32-bit blocks.
|
||||
// Copy the data into a temporary vector, with redundant zeros at the end
|
||||
// then byteswap it so that the data comes out in the right order.
|
||||
uint8_t *data = reinterpret_cast<uint8_t *>(info.ptr);
|
||||
std::vector<uint32_t> vec;
|
||||
vec.resize((size + 3) / 4);
|
||||
size_t data_size = vec.size() * 4;
|
||||
memcpy(&vec[0], data, size);
|
||||
for (auto &i : vec)
|
||||
i = __builtin_bswap32(i);
|
||||
|
||||
if (data_size > UINT16_MAX) {
|
||||
throw py::value_error("Too much data");
|
||||
}
|
||||
|
||||
if (pio_sm_config_xfer(pio, sm, PIO_DIR_TO_SM, size, 1)) {
|
||||
throw std::runtime_error("pio_sm_config_xfer() failed");
|
||||
if (data_size != last_size) {
|
||||
if (pio_sm_config_xfer(pio, sm, PIO_DIR_TO_SM, data_size, 1)) {
|
||||
throw std::runtime_error("pio_sm_config_xfer() failed");
|
||||
}
|
||||
last_size = data_size;
|
||||
}
|
||||
if (pio_sm_xfer_data(pio, sm, PIO_DIR_TO_SM, size, info.ptr)) {
|
||||
if (pio_sm_xfer_data(pio, sm, PIO_DIR_TO_SM, data_size, &vec[0])) {
|
||||
throw std::runtime_error("pio_sm_xfer_data() failed");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void free_pio(void) {
|
||||
if (!pio) { return; }
|
||||
if (offset <= 0) { pio_remove_program(pio, &ws2812_program, offset); };
|
||||
if (!pio) {
|
||||
return;
|
||||
}
|
||||
if (offset <= 0) {
|
||||
pio_remove_program(pio, &ws2812_program, offset);
|
||||
};
|
||||
offset = -1;
|
||||
if (sm >= 0) { pio_sm_unclaim(pio, sm); }
|
||||
if (sm >= 0) {
|
||||
pio_sm_unclaim(pio, sm);
|
||||
}
|
||||
sm = -1;
|
||||
pio_close(pio);
|
||||
pio = nullptr;
|
||||
}
|
||||
|
||||
PYBIND11_MODULE(neopixel_write_pi5, m) {
|
||||
PYBIND11_MODULE(adafruit_raspberry_pi5_neopixel_write, m) {
|
||||
m.doc() = R"pbdoc(
|
||||
neopixel_write for pi5
|
||||
-----------------------
|
||||
----------------------
|
||||
|
||||
.. currentmodule:: neopixel_write_pi5
|
||||
.. currentmodule:: adafruit_raspberry_pi5_neopixel_write
|
||||
|
||||
.. autosummary::
|
||||
:toctree: _generate
|
||||
|
||||
neopixel_write
|
||||
free_pio
|
||||
)pbdoc";
|
||||
|
||||
m.def("neopixel_write", &neopixel_write,
|
||||
py::arg("gpio"),
|
||||
py::arg("buf"),
|
||||
R"pbdoc(NeoPixel writing function)pbdoc");
|
||||
m.def("neopixel_write", &neopixel_write, py::arg("gpio"), py::arg("buf"),
|
||||
R"pbdoc(NeoPixel writing function)pbdoc");
|
||||
|
||||
m.def("_free_pio", &free_pio,
|
||||
R"pbdoc(Release any held PIO resource)pbdoc");
|
||||
m.def("free_pio", &free_pio, R"pbdoc(Release any held PIO resource)pbdoc");
|
||||
|
||||
#ifdef VERSION_INFO
|
||||
m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO);
|
||||
|
|
|
|||
Loading…
Reference in a new issue