Skip to main content

Pure Python peripheral APIs for NuttX character devices

Project description

nuttx-periphery

Python 3.8+ NuttX License

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

Currently pip installations are very slow due to the amount of imports required. To fix this, a custom installation script is provided.

NOTE: This process will be simplified when PyPi releases are available.

On the host machine, clone this repository, generate the .whl file and start a http server:

python3 -m venv venv
source venv/bin/activate
pip install -e .
python3 -m build --wheel
python3 -m http.server

On the target, download the install script and wheel to /tmp/:

wget -O /tmp/install-packages.py <host IP>:8000/scripts/install-packages.py
wget -O /tmp/nuttx_periphery-0.1.0-py3-none-any.whl <host IP>:8000/dist/nuttx_periphery-0.1.0-py3-none-any.whl

Now run the installer (defaults: install to /data, use the newest .whl in the script directory):

python /tmp/install-packages.py /data /tmp/nuttx_periphery-0.1.0-py3-none-any.whl
export PYTHONPATH=/data:$PYTHONPATH

The script and wheel must live in the same directory (e.g. /tmp/) unless the wheel path is passed explicitly.

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)
    • rv-virt:python

Quick Start

Execute the following snippet from the Python interpreter on target:

from nuttx_periphery import GPIO, GPIOPinType

with GPIO("/dev/gpio0") as gpio:
    gpio.set_pin_type(GPIOPinType.GPIO_OUTPUT_PIN)
    gpio.write(True)

Examples

Additional runnable scripts are in examples/:

Run on a NuttX board:

wget -O /tmp/gpio_out.py <host IP>:8000/examples/gpio_out.py
python /tmp/gpio_out.py

Contributing

Contributions are welcome.

  • Tests are required for new features.
  • Code linting via pre-commit is 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nuttx_periphery-0.1.0.tar.gz (27.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nuttx_periphery-0.1.0-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file nuttx_periphery-0.1.0.tar.gz.

File metadata

  • Download URL: nuttx_periphery-0.1.0.tar.gz
  • Upload date:
  • Size: 27.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nuttx_periphery-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b747f6102b654b752cc4d76689ce8c06fe516e873a3e3829aad59dd3e2371ffe
MD5 70f05990bdb5c7035d3c1efda69e3e4a
BLAKE2b-256 e2d5f65d387847453aca183c1d5ee39571164cd7961c10ddb6228aafbb5641a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for nuttx_periphery-0.1.0.tar.gz:

Publisher: publish-pypi.yml on fdcavalcanti/nuttx-periphery

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nuttx_periphery-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for nuttx_periphery-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f74fecdd85e4b4defaa049c5a0b780bdf22ed6a4a10fa329b8f7c5b1a3b793ec
MD5 295e816eb59188fa47b4102f14365955
BLAKE2b-256 0507656a4fbb17bd2ce41e692c0ef895cdc32ffe4eb9d46db6540d0e21f4d41f

See more details on using hashes here.

Provenance

The following attestation bundles were made for nuttx_periphery-0.1.0-py3-none-any.whl:

Publisher: publish-pypi.yml on fdcavalcanti/nuttx-periphery

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page