Pure Python peripheral APIs for NuttX character devices
Project description
nuttx-periphery
Pure Python peripheral APIs for NuttX character devices.
nuttx_periphery wraps GPIO, PWM, User LED, and Timer character devices with typed Python methods built on os.open, fcntl.ioctl, and ctypes structures aligned with NuttX headers.
NuttX is a POSIX compliant real-time operating system (RTOS) which now has CPython support on QEMU RISC-V and Espressif devices such as ESP32-P4.
Installation
On NuttX RTOS, this package is installed automatically during build of Python (see INTERPRETERS_CPYTHON_INSTALL_NUTTX_PACKAGE on nuttx-apps).
Features
- GPIO: output, input, and signal-based interrupt registration.
- User LED: per-LED and mask read/write.
- PWM: per-channel frequency, duty, and optional dead-time / pulse count.
- Timer: status polling, timeouts, and signal notification.
- Generic device access: raw read/ioctl via
CharacterDevice.
Requirements
- NuttX running on microcontroller with CPython available
- esp32p4-function-ev-board:python
- NuttX on QEMU
- rv-virt:python
Quick Start
Start Python on NuttX:
NuttShell (NSH) NuttX-12.4.0
nsh> python
Toggle pin state using GPIO module:
from nuttx_periphery import GPIO, GPIOPinType
with GPIO("/dev/gpio0") as gpio:
gpio.set_pin_type(GPIOPinType.GPIO_OUTPUT_PIN)
gpio.write(True)
Or operate a PWM pin:
from nuttx_periphery.pwm import PWM
with PWM("/dev/pwm0", channel_count=1) as pwm:
print(pwm.list_channels()) # See available channels
pwm.frequency = 200
pwm.channel[0].duty = 45
pwm.apply()
pwm.start()
time.sleep(5)
pwm.stop()
Examples
Additional runnable scripts are in examples/:
gpio_out.py— blink a GPIO outputgpio_interrupt.py— wait for a GPIO interrupt via signalpwm.py— read and write PWM channel settingstimer.py— poll timer time left until expirationtimer_notification.py— wait for timer expiration via signal
Download scripts to the target board using wget:
- Host:
Clone this repository on the host machine and start Python HTTP server
cd nuttx-periphery
python3 -m http.server
- Target:
Use wget on the target board to download scripts
wget -o /tmp/gpio_out.py http://192.168.0.20:8000/examples/gpio_out.py
python /tmp/gpio_out.py
Contributing
Contributions are welcome.
- Tests are required for new features.
- Code linting via
pre-commitis required.
Install from source:
git clone <repository-url>
cd nuttx-periphery
python -m pip install -e ".[dev]"
pre-commit install
pytest
The generated .whl and install script will be in dist/.
License
This project is licensed under the Apache License 2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nuttx_periphery-0.2.0.tar.gz.
File metadata
- Download URL: nuttx_periphery-0.2.0.tar.gz
- Upload date:
- Size: 35.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a44c12ba9a249bd70a9cf7f9ffcd08b606b42b57a937b1174bf1ffdcde2fdc37
|
|
| MD5 |
396ee6cece22343e930943422d75aff6
|
|
| BLAKE2b-256 |
e16ca172ad824dad164df5e66c316f245fc105932f09873e40fd4ca76dc1bbb9
|
Provenance
The following attestation bundles were made for nuttx_periphery-0.2.0.tar.gz:
Publisher:
publish-pypi.yml on fdcavalcanti/nuttx-periphery
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nuttx_periphery-0.2.0.tar.gz -
Subject digest:
a44c12ba9a249bd70a9cf7f9ffcd08b606b42b57a937b1174bf1ffdcde2fdc37 - Sigstore transparency entry: 1803137346
- Sigstore integration time:
-
Permalink:
fdcavalcanti/nuttx-periphery@141f4ec57d8175382db07331bc99f4568641bc7f -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/fdcavalcanti
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@141f4ec57d8175382db07331bc99f4568641bc7f -
Trigger Event:
release
-
Statement type:
File details
Details for the file nuttx_periphery-0.2.0-py3-none-any.whl.
File metadata
- Download URL: nuttx_periphery-0.2.0-py3-none-any.whl
- Upload date:
- Size: 17.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6955244297c9d01577fa4cbc18580edaad10098a41737611342a553c83aa9510
|
|
| MD5 |
94536773d6e7bb0196155ba6e846763f
|
|
| BLAKE2b-256 |
c8736dd045bf5c00a19c3ae50387f49b272f86806f0add2dbc2435485930ea6e
|
Provenance
The following attestation bundles were made for nuttx_periphery-0.2.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on fdcavalcanti/nuttx-periphery
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nuttx_periphery-0.2.0-py3-none-any.whl -
Subject digest:
6955244297c9d01577fa4cbc18580edaad10098a41737611342a553c83aa9510 - Sigstore transparency entry: 1803137380
- Sigstore integration time:
-
Permalink:
fdcavalcanti/nuttx-periphery@141f4ec57d8175382db07331bc99f4568641bc7f -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/fdcavalcanti
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@141f4ec57d8175382db07331bc99f4568641bc7f -
Trigger Event:
release
-
Statement type: