Skip to main content

pamoja-gpio

I2C address frames with reserved-range checks, the four SPI clock modes, active-high or active-low switches and contacts, and GPIO lines opened on a Linux board. One capability of pamoja, one memory-safe Rust core with bindings for TypeScript, Python, and C#.

read the guide documentation API reference

Install

pip install pamoja-gpio
from pamoja import gpio

This pulls in pamoja-native, the compiled engine. pip install pamoja is the whole framework in one package.

Example

The script the test suite runs, spliced here as it ran.

From bindings/python/guides/gpio.py:

from pamoja.gpio import Contact, Edge, GpioLine, Level, PinScript, Switch, i2c, pin, spi

# Most relay boards energize when their input is pulled low, and a float switch wired to
# ground closes the same way. Saying "active low" once, here, is what keeps the inversion
# out of every line below it.
pump = Switch.active_low(PinScript())
float_switch = Contact.active_low(PinScript([Level.HIGH, Level.LOW]))
runs_on = pin.level_for(pump.polarity, True)
print(f"a pump on an active-low relay runs when its line is {runs_on.value}")

# The pump runs while the tank fills. The scripted line answers open and then closed, so
# this is the real loop with nothing plugged in; on a board the same two lines take a pin
# from the board's GPIO library instead.
pump.set(True)
while_filling = float_switch.is_asserted()
once_filled = float_switch.is_asserted()
full = {True: "full", False: "not full"}
print(f"the float reads {full[while_filling]}, then {full[once_filled]}")

# The moment the float closes is that line going low, which is a falling edge. A watch
# armed for the rising one would sleep through the tank filling.
closing = pin.triggers(Edge.FALLING, Level.HIGH, Level.LOW)
edge = "a falling edge" if closing else "not a falling edge"
print(f"the float closing is {edge} on that line")

# Full, so the pump stops. Releasing the switch hands the line back, and the levels it was
# driven to are the whole conversation the board saw.
pump.set(False)
ran, stopped = pump.release().driven
print(f"running drove the line {ran.value} and stopping drove it {stopped.value}")

# A part on a shared bus answers to an address, and the byte on the wire is not the
# address the datasheet prints: it shifts up one and the low bit says read or write.
to_write = i2c.address_frame(0x76)[0]
to_read = i2c.address_frame(0x76, read=True)[0]
print(f"a part at 0x76 is written to as 0x{to_write:02X} and read from as 0x{to_read:02X}")

# Two ranges belong to the specification itself, so a part answering in either is a wiring
# mistake rather than a device.
reserved = i2c.is_reserved(i2c.RESERVED_FROM)
owner = "reserved by the specification" if reserved else "free for a device"
print(f"0x{i2c.RESERVED_FROM:02X} is {owner}")

# And a datasheet quotes SPI's clock polarity and phase as one mode number.
clock = spi.clock_for(3)
idle = "high" if clock.cpol else "low"
edge = "trailing" if clock.cpha else "leading"
print(f"SPI mode 3 idles {idle} and samples on the {edge} edge")

The same capability in every language

Language Package Reference
Rust pamoja-gpio reference, docs.rs, install
TypeScript @pamoja/gpio reference, install
Python pamoja-gpio reference, install
C# Pamoja.Gpio reference, install

Documentation

License

MIT

Metadata

Release files for pamoja-gpio 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pamoja-gpio 0.2.1
File Size Uploaded Provenance Actions
pamoja_gpio-0.2.1.tar.gz 8.1 kB Without provenance Details for pamoja_gpio-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pamoja-gpio 0.2.1
File Interpreter ABI Platform Actions
pamoja_gpio-0.2.1-py3-none-any.whl Python 3 none any Details for pamoja_gpio-0.2.1-py3-none-any.whl

Total release size: 17.1 kB

Release files / pamoja_gpio-0.2.1.tar.gz

Download URL pamoja_gpio-0.2.1.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
35a4444be2086c473b035c03da1aed8c6111f025b72984c27ce569c73066e7d4
BLAKE2b-256 checksum
How to use checksums
b6fbf44cce9c4265894cf8df510a592b16e7ec3364eb205988910cc1c1f47cfe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / pamoja_gpio-0.2.1-py3-none-any.whl

Download URL pamoja_gpio-0.2.1-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa3f75c483a95c9b301653051495e93aa91a728c8240bb70a9aec4630d53ffaa
BLAKE2b-256 checksum
How to use checksums
4bdfc704fdc6e11f6b52e100d15926602834a314af22bc55b87580cc5beb6114
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Security for pamoja-gpio 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page