Namespace PanelGroup
Static singleton for CAN sub-node ( PanelGroup ) firmware.More...
Public Functions
| Type | Name |
|---|---|
| void | flushExpanderWrites () Push every port dirtied by writeCachedPinDeferred() — one writePort() each. |
| void | loop () Run all PanelGroup work. Call once perloop() iteration. |
| bool | readCachedPin (const MCP23017 & chip, uint8_t port, uint8_t bit) Return cached MCP23017 pin state. Called by PinRef::read() . No I2C. |
| bool | readLivePin (MCP23017 & chip, uint8_t port, uint8_t bit) Live MCP23017 pin read — fresh readPort() over I2C, refreshing the cache. |
| void | registerADC (ADS1115 & adc, uint8_t addr=0x48, TwoWire & wire=Wire) Register an ADS1115 ADC. Call beforesetup() . |
| void | registerExpander (MCP23017 & chip, uint8_t intaPin, uint8_t intbPin) Register an MCP23017 expander in interrupt-driven mode. Call before setup() . |
| void | registerExpander (MCP23017 & chip) Register an MCP23017 expander in polling-fallback mode. Call before setup() . |
| void | setup () Initialise PanelGroup . Call from sketchsetup() after Wire.begin(). |
| void | writeCachedPin (MCP23017 & chip, uint8_t port, uint8_t bit, bool value) Write MCP23017 pin and update cache. Called by PinRef::write() . |
| void | writeCachedPinDeferred (MCP23017 & chip, uint8_t port, uint8_t bit, bool value) Deferred MCP23017 write — update the cache + mark the port dirty, no I2C. |
Detailed Description
Manages MCP23017 expander registration and cache, ADS1115 registration, the 8-step boot sequence, per-loop interrupt dispatch and polling fallback, CAN EVT batching, CTRL_BCAST dispatch, SYNC_REQ response, and the 500 ms HB_n heartbeat.
Public Functions Documentation
function flushExpanderWrites
Push every port dirtied by writeCachedPinDeferred() — one writePort() each.
void PanelGroup::flushExpanderWrites ()
Note:
No-op when nothing is pending (GPIO-only outputs never dirty a port).
function loop
Run all PanelGroup work. Call once perloop() iteration.
void PanelGroup::loop ()
Each call: * Check interrupt flags; read INTCAP; update expander port caches. * Polling fallback (~20 ms): read ports for chips registered without interrupt. * poll() on all InputBase objects. * CANProtocol::drain() — dispatches CTRL_BCAST, SYNC_REQ, TEST_SEQ echo. * update() on all OutputBase objects. * Heartbeat: send HB_n every 500 ms.
function readCachedPin
Return cached MCP23017 pin state. Called by PinRef::read() . No I2C.
bool PanelGroup::readCachedPin (
const MCP23017 & chip,
uint8_t port,
uint8_t bit
)
Parameters:
chipChip reference — used as key to locate the ExpanderEntry.portPORT_A (0) or PORT_B (1).bitBit index 0–7.
Returns:
Cached logical level (true = HIGH).
function readLivePin
Live MCP23017 pin read — fresh readPort() over I2C, refreshing the cache.
bool PanelGroup::readLivePin (
MCP23017 & chip,
uint8_t port,
uint8_t bit
)
Parameters:
chipChip reference.portPORT_A (0) or PORT_B (1).bitBit index 0–7.
Returns:
Live logical level (true = HIGH).
Note:
Called by PinRef::readLive() for time-critical reads before loop() refreshes the cache (e.g. blocking homing on an MCP-backed home sensor). One I2C transaction per call.
function registerADC
Register an ADS1115 ADC. Call beforesetup() .
void PanelGroup::registerADC (
ADS1115 & adc,
uint8_t addr=0x48,
TwoWire & wire=Wire
)
PanelGroup calls adc.begin(addr, wire) during setup(). Register each ADS1115 instance exactly once — multiple AnalogInput objects may share the same chip.
Adafruit_ADS1115 takes address and bus via begin(), not the constructor. Pattern:
ADS1115 adc;
PanelGroup::registerADC(adc, 0x48, Wire); // 0x48–0x4B via ADDR pin
Parameters:
adcADS1115 instance. Must outlive PanelGroup.addrI2C address (0x48–0x4B via ADDR pin). Default 0x48.wireI2C bus. Default Wire (I2C1 on STM32).
Note:
Wire.begin() (or Wire1.begin()) must be called by the sketch before setup().
function registerExpander
Register an MCP23017 expander in interrupt-driven mode. Call before setup() .
void PanelGroup::registerExpander (
MCP23017 & chip,
uint8_t intaPin,
uint8_t intbPin
)
PanelGroup calls chip.init(), configures IOCON (MIRROR and/or open-drain as detected), enables interrupt-on-change on input pins only (IODIR-masked, bit 7 excluded per GPA7/GPB7 silicon erratum), reads baseline port state, and attaches STM32 ISRs.
Pass the same STM32 pin for intaPin and intbPin to use MIRROR mode (IOCON.MIRROR=1), where either port interrupt asserts the shared line.
If two or more chips share an interrupt line (wired-OR), PanelGroup sets IOCON.ODR=1 (open-drain) automatically on all chips on that line.
Parameters:
chipblemasle/MCP23017 instance. Must outlive PanelGroup.intaPinSTM32 GPIO pin connected to chip INTA.intbPinSTM32 GPIO pin connected to chip INTB. Same as intaPin for MIRROR.
Note:
Do not use PB14/PB15 (status LED) or PC13–PC15 (RTC/oscillator).
function registerExpander
Register an MCP23017 expander in polling-fallback mode. Call before setup() .
void PanelGroup::registerExpander (
MCP23017 & chip
)
PanelGroup reads all port registers every ~20 ms in loop(). No STM32 interrupt pin is required. Use when interrupt lines are not wired or not needed.
Parameters:
chipblemasle/MCP23017 instance. Must outlive PanelGroup.
function setup
Initialise PanelGroup . Call from sketchsetup() after Wire.begin().
void PanelGroup::setup ()
Performs the 8-step boot sequence: * STM32Board::begin() * For each registered ADC: begin(addr, wire). For each registered expander: init(), configure IOCON, enable interrupt-on-change on input pins, read baseline port state, attach STM32 ISR. * configure() on all InputBase and OutputBase objects. * Register CAN callbacks. * CANProtocol::start(). * forceReport() burst — one EVT per registered input. * flushBatched(canIdEvt(NODE_ID)). * READY_n frame (canIdReady(NODE_ID), DLC=0). Arm heartbeat timer.
Note:
Wire.begin() must be called by the sketch before this function. PanelGroup never calls Wire.begin() — only start buses in use.
function writeCachedPin
Write MCP23017 pin and update cache. Called by PinRef::write() .
void PanelGroup::writeCachedPin (
MCP23017 & chip,
uint8_t port,
uint8_t bit,
bool value
)
Parameters:
chipChip reference.portPORT_A (0) or PORT_B (1).bitBit index 0–7.valueLogical level to write.
function writeCachedPinDeferred
Deferred MCP23017 write — update the cache + mark the port dirty, no I2C.
void PanelGroup::writeCachedPinDeferred (
MCP23017 & chip,
uint8_t port,
uint8_t bit,
bool value
)
Note:
Pair with flushExpanderWrites(). Lets a multi-pin output (e.g. a stepper's four coils) collapse N per-pin read-modify-writes into one writePort() per port.
The documentation for this class was generated from the following file Firmware/Libraries/PanelGroup/PanelGroup.cpp