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#.
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
pamoja.gpioreference, every class and function in this module.- The I2C, SPI, and GPIO guide, with the same example in Rust, TypeScript, and C#.
- Every capability, and the install page.
License
MIT
Release files for pamoja-gpio 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pamoja_gpio-0.2.0.tar.gz | 8.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pamoja_gpio-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.1 kB
Release files / pamoja_gpio-0.2.0.tar.gz
| Download URL | pamoja_gpio-0.2.0.tar.gz |
|---|---|
| Size | 8.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
21f751ffe9a548ba942880c9648d0ff8117efcbf4e3fedcec4e7e3706c4192f2
|
|
BLAKE2b-256 checksum How to use checksums |
6ae396e3d9f40e0ac39473eda76aa145da5d40e31c2338cfb98a893cd4f23c7f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / pamoja_gpio-0.2.0-py3-none-any.whl
| Download URL | pamoja_gpio-0.2.0-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
94d4ff16817febcccf11d1a1ed7b7ef88d615d7d2d79ff550387a77fc7db5463
|
|
BLAKE2b-256 checksum How to use checksums |
cf76cb86e7add5683df74c49fa70f6d75e0f182e9e6445a41788003f183ada24
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|