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

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/:

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-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.2.0.tar.gz (35.1 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.2.0-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

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

Hashes for nuttx_periphery-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a44c12ba9a249bd70a9cf7f9ffcd08b606b42b57a937b1174bf1ffdcde2fdc37
MD5 396ee6cece22343e930943422d75aff6
BLAKE2b-256 e16ca172ad824dad164df5e66c316f245fc105932f09873e40fd4ca76dc1bbb9

See more details on using hashes here.

Provenance

The following attestation bundles were made for nuttx_periphery-0.2.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.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

Hashes for nuttx_periphery-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6955244297c9d01577fa4cbc18580edaad10098a41737611342a553c83aa9510
MD5 94536773d6e7bb0196155ba6e846763f
BLAKE2b-256 c8736dd045bf5c00a19c3ae50387f49b272f86806f0add2dbc2435485930ea6e

See more details on using hashes here.

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

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