|
XPoint 0.1.0
Hardware-agnostic crosspoint matrix routing library
|
A small, hardware-agnostic C++11 library for managing crosspoint matrices and signal routing on Arduino and PlatformIO targets. Designed to work on everything from AVR (Uno/Nano) to ESP32 and ARM without pulling in the C++ standard library.
connect(row, col) / disconnect(row, col) / setLevel(row, col, level) APIXPointStatic<ROWS, COLS> — zero-heap variant with compile-time dimensions for AVRdelay())XPointDriver) — swap hardware without touching application codestd::vector, no std::function, no exceptions — compatible with avr-libcAdd to your platformio.ini:
Heap-allocating (recommended for ESP32, STM32, native)
Uses new[]/delete[]. Dimensions are set at runtime. Suitable for any target with adequate heap.
**XPointStatic<ROWS, COLS> (recommended for AVR / zero-heap)**
All state arrays live inside the object — no heap allocation. Dimensions must be known at compile time. Safe to declare globally on an ATmega328P.
User-buffer (maximum control)
Pass your own pre-allocated buffers. The object does not own or free them.
Total SRAM consumed = class overhead + state buffers.
State buffers hold the logical connection state and are sized by the matrix dimensions:
| Buffer | Size (bytes) |
|---|---|
_matrixState — one bool per node | rows × cols |
_interlockMap — one bool per row-pair | rows × rows |
_exclusiveCols — one bool per column | cols |
| Total state buffers | rows×cols + rows² + cols |
Common matrix sizes:
| Matrix | rows×cols | rows² | cols | State total |
|---|---|---|---|---|
| 2×8 | 16 | 4 | 8 | 28 B |
| 4×4 | 16 | 16 | 4 | 36 B |
| 1×12 | 12 | 1 | 12 | 25 B |
| 4×8 | 32 | 16 | 8 | 56 B |
| 8×8 | 64 | 64 | 8 | 136 B |
| 8×16 | 128 | 64 | 16 | 208 B |
| 16×16 | 256 | 256 | 16 | 528 B |
Class overhead is fixed per XPoint instance, regardless of matrix size:
| Platform | sizeof(XPoint) |
|---|---|
| AVR (ATmega328P, 8-bit, 2-byte pointers) | ~71 B |
| 32-bit ARM / ESP32 | ~100 B |
| 64-bit host | 152 B (measured) |
The overhead is dominated by PulseEvent _activePulses[8] — 8 slots × 7 bytes each on AVR (56 B), 8 × 12 bytes on 32-bit (96 B).
Verify on your target with:
Heap vs. XPointStatic: both strategies consume the same total bytes. XPointStatic<R,C> embeds the buffers directly in the object (BSS / global storage), so the heap is never touched and there is no fragmentation risk.
setLevel(row, col, level) calls driver->setNodeLevel() instead of setNodeHardware(). Binary drivers (GPIO, shift register) treat level > 0 as on and 0 as off. PWM-capable drivers (TLC59711) set the actual fractional output:
Interlock and exclusive-input protections apply to setLevel the same as connect.
Call matrix.update() in loop(). It de-energizes coils automatically after the pulse duration via driver->releaseNode().
All drivers are in src/drivers/. Arduino-specific drivers compile only when ARDUINO is defined; host-side stubs are provided for testing.
| Driver | File | Use case |
|---|---|---|
ArduinoDirectGPIODriver | ArduinoDirectGPIODriver.* | One MCU pin per node via digitalWrite |
ArduinoShiftRegisterDriver | ArduinoShiftRegisterDriver.* | 74HC595 chain driven by digitalWrite |
MCP23017Driver | MCP23017Driver.* | MCP23017 16-bit I2C GPIO expander |
TLC59711Driver | TLC59711Driver.* | TLC59711 12-channel 16-bit PWM SPI expander |
DirectGPIODriver | DirectGPIODriver.* | Virtual pin-state driver (testing / simulation) |
ShiftRegisterDriver | ShiftRegisterDriver.* | Virtual byte-shadow shift register (testing / simulation) |
begin() configures only the pins your mapper actually returns, so serial/I2C/SPI pins are never disturbed.
commitPhysicalUpdates() shifts bytes MSB-first, last register first (standard 74HC595 daisy-chain order).
Up to 8 MCP23017s can share one I2C bus (address pins A0–A2). Use a transistor stage when driving relay coils.
commitPhysicalUpdates() assembles the correct 28-byte-per-chip SPI packet (4-byte control word + GS11→GS0 channel order) and transfers it once.
Inherit from XPointDriver and implement begin() and setNodeHardware(). All other methods have default no-op implementations.
| XPoint call | setNodeHardware state | Meaning |
|---|---|---|
connect() | true | Pulse SET coil |
disconnect() | false | Pulse RESET coil |
update() expires | releaseNode() | De-energize coil |
Drivers take a plain C function pointer whose return type matches the driver:
| Driver | MapFn return type | Range |
|---|---|---|
ArduinoDirectGPIODriver | uint8_t | Arduino pin number |
ArduinoShiftRegisterDriver | uint16_t | bit index in SR chain |
MCP23017Driver | uint8_t | pin index 0–15 |
TLC59711Driver | uint16_t | channel index 0–(N×12) |
Non-capturing lambdas convert to function pointers automatically in C++11:
HC595Helper::rowMajorIndex(row, col, cols) computes a row-major shift-register bit index inline.
See test/TESTS.md for the full test suite description, build instructions, and mock infrastructure reference.
GitHub Actions runs on every push and PR to main/master:
g++ compiles and runs test/test_xpoint.cpp (17 tests, no Arduino headers)AGPL-3.0-only — Copyright (c) 2026 Douglas Quigg (dstroy0) <dquig.nosp@m.g123.nosp@m.@gmai.nosp@m.l.co.nosp@m.m>