A native Rust extension for Python providing direct GPIO, SPI (MCP3008) and RS-485 serial access on Linux, with no external dependencies beyond pyo3 and libc.
Currently used for super performance critical components of my py projects.
- setmode(mode: "BOARD" | "BCM")
- setup(pin: int, direction: "IN" | "OUT")
- output(pin: int, value: 0 | 1)
- input(pin: int) -> int
- MCP3008(bus: int, cs: int, channel: int, speed_khz: int)
- .read_raw()
-> int (0–1023) - .value
-> float (0.0–1.0) - .bits()
-> int (const. 10) - .read()
-> (raw: int, normalized: float)
- .read_raw()
- Serial(path: str, baud: int, timeout_s: float, de_pin: int, ...)
- .write(data: bytes)
-> int - .read(size: int)
-> bytes - .in_waiting()
-> int - .flush()
- .reset_input_buffer()
- .reset_output_buffer()
- .close()
- .write(data: bytes)
- sleep_s(s: float)
- sleep_ms(ms: float)
- sleep_us(us: float)
- time_time()
- Manages memory-mapped I/O for Raspberry Pi
- Lazy init of /dev/gpiomem
- Thread-safe via OnceLock
- Raw SPI ioctl calls to /dev/spidevX.Y
- Custom _IOC helper to calculate request codes
- Opens serial port non-blocking, toggles DE-pin for RS-485
- Configures termios for raw mode and timeouts
- Methods mirror Python serial package