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:
from pamoja.gpio import Edge, Level, Polarity, i2c, pin, spi
# A BME280 answers at the 7-bit address its datasheet gives. That is not the byte that
# goes on the wire: the address shifts up one and the low bit says whether this
# transaction reads or writes, which is the step easiest to get wrong by hand.
BME280 = 0x76
print(f"write to 0x{i2c.address_frame(BME280)[0]:02X}")
print(f"read from 0x{i2c.address_frame(BME280, read=True)[0]:02X}")
# The I2C specification keeps two ranges of addresses for itself, so a part answering in
# either is a wiring mistake rather than a device.
reserved = i2c.RESERVED_FROM
print(f"0x{BME280:02X} reserved: {i2c.is_reserved(BME280)}, "
f"0x{reserved:02X} reserved: {i2c.is_reserved(reserved)}")
# A 10-bit address spends a reserved prefix over two bytes rather than one, so a bus
# driver has to send a different number of bytes depending on the address it holds.
# This is the worked example UM10204 itself prints.
TEN_BIT_DEVICE = 0x2A5
print(f"a 10-bit address takes {i2c.frame_len(TEN_BIT_DEVICE, ten_bit=True)} bytes")
# Datasheets quote clock polarity and phase as one mode number. Mode 3 idles the clock
# high and samples on the trailing edge.
clock = spi.clock_for(3)
print(f"spi mode 3: idles high {clock.cpol}, samples on the trailing edge {clock.cpha}")
# A relay board sold as active low energises when its pin is driven low. The polarity
# carries that inversion, so no call site has to remember which way round it is.
energise = pin.level_for(Polarity.ACTIVE_LOW, True)
print(f"to energise an active-low relay, drive the pin {energise.name}")
# Releasing it drives the line back high, an edge a falling trigger ignores.
rising = pin.triggers(Edge.RISING, Level.LOW, Level.HIGH)
falling = pin.triggers(Edge.FALLING, Level.LOW, Level.HIGH)
print(f"release seen by a rising trigger: {rising}, by a falling trigger: {falling}")
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.17
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.17.tar.gz | 5.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pamoja_gpio-0.1.17-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.5 kB
Release files / pamoja_gpio-0.1.17.tar.gz
| Download URL | pamoja_gpio-0.1.17.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3247ec8d79f2de73f06afaac29b7706f786e0900892ea81df54466482596e94f
|
|
BLAKE2b-256 checksum How to use checksums |
f93dcd4d33c4a8145959ec6b1fef8d79c41e551c7ea424ed049d2c409c80a4a6
|
| 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.17-py3-none-any.whl
| Download URL | pamoja_gpio-0.1.17-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
75f5c6da59b74dd1bd29f2686a30349643f81ef74865ecc980cc1e8ea61ff45d
|
|
BLAKE2b-256 checksum How to use checksums |
fd3a0448515856204f33f4be320b981bbb1d9426a18fc828cfbfe5b681bb0f86
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|