Class PinRef
Hardware pin abstraction used by all OpenSkyhawk input and output classes.More...
#include <PinRef.h>
Public Attributes
| Type | Name |
|---|---|
| ADS1115 * | adc |
| struct PinRef | ads ADS1115 source. |
| uint8_t | bit |
| uint8_t | channel |
| MCP23017 * | chip |
| struct PinRef | mcp MCP23017 source. |
| uint8_t | pin GPIO pin number. |
| uint8_t | port |
Public Functions
| Type | Name |
|---|---|
| PinRef (uint8_t pin) Direct STM32 GPIO pin. |
|
| PinRef (MCP23017 & chip, uint8_t port, uint8_t bit) MCP23017 expander GPIO. |
|
| PinRef (ADS1115 & adc, uint8_t channel) ADS1115 ADC channel. |
|
| constexpr | PinRef () No-connect sentinel — represents a position with no physical pin. |
| void | configureAsInput () Configure this pin as a digital input. |
| void | configureAsOutput () Configure this pin as a digital output. |
| uint8_t | gpioPin () const Return the raw Arduino pin number for GPIO PinRefs. |
| bool | isGpio () const Returns true if this PinRef wraps a direct STM32 GPIO pin. |
| bool | isNC () const Returns true if this is the NC (no-connect) sentinel. |
| bool | read () const Digital read. |
| uint16_t | readAnalog () const Analog read, normalised to 16-bit (0–65535). |
| bool | readLive () const Live digital read — bypasses any cache. |
| void | write (bool value) Digital write. |
| void | writeAnalog (uint16_t val) Analog write (PWM). GPIO only. |
| void | writeDeferred (bool value) Like write() , but MCP writes only update the cache (no I2C) — the caller then invokesPanelGroup::flushExpanderWrites() to push each port in one writePort(). |
Detailed Description
Provides read, write, readAnalog, and writeAnalog behind a uniform interface regardless of whether the backing pin is a direct STM32 GPIO, an MCP23017 expander bit, or an ADS1115 ADC channel. Size: ~12 bytes (1-byte type tag + largest union member).
Public Attributes Documentation
variable adc
ADS1115* PinRef::adc;
variable ads
ADS1115 source.
struct PinRef PinRef::ads;
variable bit
uint8_t PinRef::bit;
variable channel
uint8_t PinRef::channel;
variable chip
MCP23017* PinRef::chip;
variable mcp
MCP23017 source.
struct PinRef PinRef::mcp;
variable pin
GPIO pin number.
uint8_t PinRef::pin;
variable port
uint8_t PinRef::port;
Public Functions Documentation
function PinRef [1/4]
Direct STM32 GPIO pin.
explicit PinRef::PinRef (
uint8_t pin
)
Parameters:
pinArduino pin number (e.g. PA0, PB5).
function PinRef [2/4]
MCP23017 expander GPIO.
PinRef::PinRef (
MCP23017 & chip,
uint8_t port,
uint8_t bit
)
Parameters:
chipReference to the registered MCP23017 instance.portPORT_A (0) or PORT_B (1).bitBit within the port, 0–7.
function PinRef [3/4]
ADS1115 ADC channel.
PinRef::PinRef (
ADS1115 & adc,
uint8_t channel
)
Parameters:
adcReference to the ADS1115 instance.channelChannel number, 0–3.
function PinRef [4/4]
No-connect sentinel — represents a position with no physical pin.
inline constexpr PinRef::PinRef ()
All reads return false / 0. All writes are no-ops. Equivalent to PIN_NC. Provided for use in array initialisers.
Note:
constexpr so PIN_NC — and any default-constructed NC PinRef — is constant-initialized. This makes it safe to place in a global wiring-map array without the static-initialization-order hazard a dynamically-initialized global would have.
function configureAsInput
Configure this pin as a digital input.
void PinRef::configureAsInput ()
GPIO: calls pinMode(pin, INPUT). Bias is provided by board wiring. MCP23017: sets IODIR bit to 1 (input) and GPPU bit to 0 (pull-up disabled) for this pin only via PanelGroup's expander management path. ADS1115: no-op — always an analog input. NC: no-op.
Note:
Must be called after chip.begin() — i.e. from an InputBase::configure() override called by PanelGroup::setup(), not from a constructor.
function configureAsOutput
Configure this pin as a digital output.
void PinRef::configureAsOutput ()
GPIO: calls pinMode(pin, OUTPUT). MCP23017: sets IODIR bit to 0 (output) and GPPU bit to 0 (pull-up disabled) for this pin only via PanelGroup's expander management path. ADS1115: no-op; debug assertion fires if PINREF_DEBUG is defined. NC: no-op.
Note:
Must be called after chip.begin() — i.e. from an OutputBase::configure() override called by PanelGroup::setup(), not from a constructor.
function gpioPin
Return the raw Arduino pin number for GPIO PinRefs.
uint8_t PinRef::gpioPin () const
Used by output classes that must call APIs requiring a raw pin number, such as Servo::attach().
Returns:
Arduino pin number (e.g. PA0, PB9), or 0 for non-GPIO PinRefs.
Note:
Debug builds log if called on non-GPIO PinRefs.
function isGpio
Returns true if this PinRef wraps a direct STM32 GPIO pin.
bool PinRef::isGpio () const
Used by direct-only output classes (AnalogOutput, ServoOutput) to reject MCP23017, ADS1115, and NC pins at construction time.
function isNC
Returns true if this is the NC (no-connect) sentinel.
bool PinRef::isNC () const
function read
Digital read.
bool PinRef::read () const
GPIO: digitalRead(pin) — true when the pin is HIGH. MCP23017: cached bit from PanelGroup's last INTCAP or port read. No I2C. ADS1115: true if readAnalog() > 32767 (half-scale threshold). NC: always false.
Returns:
true = HIGH, false = LOW.
function readAnalog
Analog read, normalised to 16-bit (0–65535).
uint16_t PinRef::readAnalog () const
GPIO: analogRead(pin) × 16 → 0–65520 (12-bit ADC scaled to 16-bit). ADS1115: readADC_SingleEnded(channel) × 2 → 0–65534 (15-bit single-ended scaled). MCP23017: always 0; debug assertion fires if PINREF_DEBUG is defined. NC: always 0.
Returns:
Normalised 16-bit ADC value.
Note:
Do not call from an ISR on ADS1115 pins — blocks ~8 ms per conversion.
function readLive
Live digital read — bypasses any cache.
bool PinRef::readLive () const
GPIO: digitalRead(pin) (already live). MCP23017: a fresh readPort() over I2C, also refreshing PanelGroup's cache. ADS1115: live readAnalog() > half-scale. NC: false.
Returns:
true = HIGH, false = LOW.
Note:
For time-critical reads before PanelGroup::loop() refreshes the cache — e.g. blocking homing on an MCP-backed sensor. Costs one I2C transaction per call on MCP pins.
function write
Digital write.
void PinRef::write (
bool value
)
GPIO: digitalWrite(pin, value ? HIGH : LOW). MCP23017: sets the output bit via PanelGroup's expander write path and cache. ADS1115: no-op; debug assertion fires if PINREF_DEBUG is defined. NC: no-op.
Parameters:
valuetrue = HIGH, false = LOW.
function writeAnalog
Analog write (PWM). GPIO only.
void PinRef::writeAnalog (
uint16_t val
)
GPIO: analogWrite(pin, val >> 8) — maps 16-bit value to 8-bit duty cycle. MCP23017: no-op; debug assertion fires if PINREF_DEBUG is defined. ADS1115: no-op; debug assertion fires if PINREF_DEBUG is defined. NC: no-op.
Parameters:
val16-bit value (0–65535); upper 8 bits used as PWM duty cycle.
Note:
Pin must be a PWM-capable STM32 GPIO. No runtime check is performed.
function writeDeferred
Like write() , but MCP writes only update the cache (no I2C) — the caller then invokesPanelGroup::flushExpanderWrites() to push each port in one writePort().
void PinRef::writeDeferred (
bool value
)
GPIO writes stay immediate (already cheap). Lets a multi-pin output batch its expander writes: one I2C transaction per port instead of one read-modify-write per pin.
Parameters:
valuetrue = HIGH, false = LOW.
The documentation for this class was generated from the following file Firmware/Libraries/PanelGroup/PinRef.h