pamoja-gpio
I2C address frames with reserved-range checks, the four SPI clock modes, and active-high or active-low pins. 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:
# 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.
RELAY = Polarity.ACTIVE_LOW
FLOAT = Polarity.ACTIVE_LOW
pump = Line()
float_switch = Line([Level.HIGH, Level.LOW])
print(f"a pump on an active-low relay runs when its line is {pin.level_for(RELAY, True).value}")
# The pump runs while the tank fills. The stand-in line answers open and then closed, so
# this is the real loop with nothing plugged in.
pump.drive(pin.level_for(RELAY, True))
while_filling = pin.is_asserted(FLOAT, float_switch.read())
once_filled = pin.is_asserted(FLOAT, float_switch.read())
print(f"the float reads full: {while_filling}, then {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)
print(f"the float closing is a falling edge on that line: {closing}")
# Full, so the pump stops, and the levels the line was driven to are the whole
# conversation the board saw.
pump.drive(pin.level_for(RELAY, False))
ran, stopped = pump.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)
print(f"0x{i2c.RESERVED_FROM:02X} is reserved by the specification: {reserved}")
# And a datasheet quotes SPI's clock polarity and phase as one mode number.
clock = spi.clock_for(3)
print(f"SPI mode 3 idles high: {clock.cpol}, samples on the trailing edge: {clock.cpha}")
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.1.18
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.1.18.tar.gz | 5.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pamoja_gpio-0.1.18-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.7 kB
Release files / pamoja_gpio-0.1.18.tar.gz
| Download URL | pamoja_gpio-0.1.18.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a0ea7ad6153201763082b32cf27ecd7e64c119e290f8462b9ad193c2528ca437
|
|
BLAKE2b-256 checksum How to use checksums |
f7cc5f630319e1d8a8731c6570810d65c2b0329027b22abe9d62c31bc653a913
|
| 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.1.18-py3-none-any.whl
| Download URL | pamoja_gpio-0.1.18-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4cd9b59766eefbd2ebd1da92e79cb7a66fe23edf5dd6913708509eacf0403a6d
|
|
BLAKE2b-256 checksum How to use checksums |
984283a7c642ae2195367084c8a6cf6b051ecb5531cb3fdc1f3555ae0c878802
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|