XPoint 0.1.0
Hardware-agnostic crosspoint matrix routing library
Loading...
Searching...
No Matches
XPoint.h
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-only
2// Copyright (c) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
3// https://github.com/dstroy0/XPoint
4
42#ifndef XPOINT_H
43#define XPOINT_H
44
45#include "drivers/BitPool.h"
47#include <stdint.h>
48
57
65{
66 uint8_t r;
67 uint8_t c;
68 uint32_t t0;
69 bool on;
70};
71
77class XPoint
78{
79 public:
91 XPoint(uint8_t rows, uint8_t cols, RelayType type = RE_NON_LATCHING, uint16_t pdur = 0);
92
105 XPoint(uint8_t rows, uint8_t cols, uint32_t *pool, RelayType type = RE_NON_LATCHING, uint16_t pdur = 0);
106
108 ~XPoint();
109
110 XPoint(const XPoint &) = delete;
111 XPoint &operator=(const XPoint &) = delete;
112
122 static uint16_t poolWords(uint8_t rows, uint8_t cols)
123 {
124 return BitPool::wordsFor((uint32_t)rows * cols + (uint32_t)rows * rows + cols);
125 }
126
128 void setDriver(XPointDriver *drv);
129
131 void begin();
132
141 bool connect(uint8_t row, uint8_t col);
142
150 bool disconnect(uint8_t row, uint8_t col);
151
160 bool setLevel(uint8_t row, uint8_t col, uint16_t level);
161
169 void clearAll();
170
176 void lockRows(uint8_t rowA, uint8_t rowB);
177
179 void exclusiveInput(uint8_t col);
180
187 void update();
188
189 private:
190 uint8_t _rows;
191 uint8_t _cols;
192 RelayType _type;
193 uint16_t _pdur;
194 XPointDriver *_drv;
195 BitPool _pool;
196
197 static const uint8_t MAX_PULSES = 8;
198 PulseEvent _pulses[MAX_PULSES];
199
200 /* Section offsets — computed from _rows/_cols, never stored. */
201 uint32_t _ilockOff() const
202 {
203 return (uint32_t)_rows * _cols;
204 }
205 uint32_t _exclOff() const
206 {
207 return (uint32_t)_rows * _cols + (uint32_t)_rows * _rows;
208 }
209
210 void _init();
211 bool _pulsePending(uint8_t row, uint8_t col) const;
212};
213
228template <uint8_t ROWS, uint8_t COLS> class XPointStatic : public XPoint
229{
230 static const uint16_t WORDS = (uint16_t)(((uint32_t)ROWS * COLS + (uint32_t)ROWS * ROWS + COLS + 31u) / 32u);
231
232 uint32_t _buf[WORDS > 0u ? WORDS : 1u];
233
234 public:
239 XPointStatic(RelayType type = RE_NON_LATCHING, uint16_t pdur = 0) : XPoint(ROWS, COLS, _buf, type, pdur)
240 {
241 }
242};
243
244#endif // XPOINT_H
Flat bit-array pool backed by a uint32_t word array.
#define XPOINT_PACKED
Definition BitPool.h:30
Abstract hardware driver interface for the XPoint crosspoint matrix.
RelayType
Relay operating mode.
Definition XPoint.h:53
@ RE_NON_LATCHING
Energize to connect; de-energize to disconnect.
Definition XPoint.h:54
@ RE_LATCHING_DUAL_COIL
SET coil to connect; RESET coil to disconnect.
Definition XPoint.h:55
Definition BitPool.h:34
static uint16_t wordsFor(uint32_t nBits)
Words required to hold nBits bits.
Definition BitPool.h:40
Abstract base class for all XPoint hardware drivers.
Definition XPointDriver.h:41
Zero-heap XPoint with a compile-time-sized embedded bit pool.
Definition XPoint.h:229
XPointStatic(RelayType type=RE_NON_LATCHING, uint16_t pdur=0)
Definition XPoint.h:239
Hardware-agnostic crosspoint matrix connection manager.
Definition XPoint.h:78
bool disconnect(uint8_t row, uint8_t col)
Disconnect row from column.
Definition XPoint.cpp:146
static uint16_t poolWords(uint8_t rows, uint8_t cols)
Number of uint32_t words needed for a pool of the given dimensions.
Definition XPoint.h:122
void setDriver(XPointDriver *drv)
Attach a driver backend. Must be called before begin().
Definition XPoint.cpp:66
void update()
Expire latching-relay coil pulses and call releaseNode() as needed.
Definition XPoint.cpp:336
XPoint(const XPoint &)=delete
void begin()
Initialize hardware via drv->begin(). Call once after setDriver().
Definition XPoint.cpp:71
bool connect(uint8_t row, uint8_t col)
Connect row to column.
Definition XPoint.cpp:81
void clearAll()
Disconnect all nodes, zeroing the state section of the pool.
Definition XPoint.cpp:265
void exclusiveInput(uint8_t col)
Mark column col as exclusive: at most one row may connect at a time.
Definition XPoint.cpp:325
void lockRows(uint8_t rowA, uint8_t rowB)
Prevent rowA and rowB from sharing a column simultaneously.
Definition XPoint.cpp:316
bool setLevel(uint8_t row, uint8_t col, uint16_t level)
Analog-level connect / disconnect for PWM drivers.
Definition XPoint.cpp:194
~XPoint()
Destructor. Frees pool only when built with the heap constructor.
Definition XPoint.cpp:39
XPoint & operator=(const XPoint &)=delete
Internal pulse-event slot for non-blocking latching-relay coil timing.
Definition XPoint.h:65
uint8_t c
Matrix column.
Definition XPoint.h:67
uint32_t t0
millis() at coil energize; wraps at ~49 days.
Definition XPoint.h:68
uint8_t r
Matrix row.
Definition XPoint.h:66
bool on
true = slot occupied.
Definition XPoint.h:69