arduino-emulator
|
GPIO wrapper class that provides flexible hardware abstraction. More...
#include <GPIOWrapper.h>
Public Member Functions | |
GPIOWrapper (GPIOSource &source) | |
GPIOWrapper (HardwareGPIO &gpio) | |
int | analogRead (pin_size_t pinNumber) |
Read the value from the specified analog pin. | |
void | analogReference (uint8_t mode) |
Configure the reference voltage used for analog input. | |
void | analogWrite (pin_size_t pinNumber, int value) |
Write an analog value (PWM wave) to a pin. | |
PinStatus | digitalRead (pin_size_t pinNumber) |
Read the value from a specified digital pin. | |
void | digitalWrite (pin_size_t pinNumber, PinStatus status) |
Write a HIGH or LOW value to a digital pin. | |
void | noTone (uint8_t _pin) |
Stop the generation of a square wave triggered by tone() | |
void | pinMode (pin_size_t pinNumber, PinMode pinMode) |
Configure the specified pin to behave as an input or output. | |
unsigned long | pulseIn (uint8_t pin, uint8_t state, unsigned long timeout=1000000L) |
Read a pulse (HIGH or LOW) on a pin. | |
unsigned long | pulseInLong (uint8_t pin, uint8_t state, unsigned long timeout=1000000L) |
Alternative to pulseIn() which is better at handling long pulses. | |
void | setGPIO (HardwareGPIO *gpio) |
defines the gpio implementation: use nullptr to reset. | |
void | setSource (GPIOSource *source) |
alternatively defines a class that provides the GPIO implementation | |
void | tone (uint8_t _pin, unsigned int frequency, unsigned long duration=0) |
Generate a square wave of the specified frequency on a pin. | |
Protected Member Functions | |
HardwareGPIO * | getGPIO () |
Protected Attributes | |
HardwareGPIO * | p_gpio = nullptr |
GPIOSource * | p_source = nullptr |
GPIO wrapper class that provides flexible hardware abstraction.
GPIOWrapper is a concrete implementation of the HardwareGPIO interface that supports multiple delegation patterns for GPIO operations. It can delegate operations to:
This class implements the complete GPIO interface including:
The wrapper automatically handles null safety and provides appropriate default return values when no underlying GPIO implementation is available. It supports all standard Arduino GPIO operations with hardware abstraction.
A global GPIO
instance is automatically provided for system-wide GPIO access.
|
virtual |
Read the value from the specified analog pin.
pinNumber | The analog pin to read from (A0, A1, etc.) |
Implements arduino::HardwareGPIO.
Configure the reference voltage used for analog input.
mode | The reference type (DEFAULT, INTERNAL, EXTERNAL, etc.) |
Implements arduino::HardwareGPIO.
Write an analog value (PWM wave) to a pin.
pinNumber | The pin to write to |
value | The duty cycle (0-255 for 8-bit PWM) |
Implements arduino::HardwareGPIO.
|
virtual |
Read the value from a specified digital pin.
pinNumber | The pin number to read from |
Implements arduino::HardwareGPIO.
|
virtual |
Write a HIGH or LOW value to a digital pin.
pinNumber | The pin number to write to |
status | The value to write (HIGH or LOW) |
Implements arduino::HardwareGPIO.
Stop the generation of a square wave triggered by tone()
_pin | The pin on which to stop generating the tone |
Implements arduino::HardwareGPIO.
|
virtual |
Configure the specified pin to behave as an input or output.
pinNumber | The pin number to configure |
pinMode | The mode to set (INPUT, OUTPUT, INPUT_PULLUP, etc.) |
Implements arduino::HardwareGPIO.
|
virtual |
Read a pulse (HIGH or LOW) on a pin.
pin | The pin on which you want to read the pulse |
state | Type of pulse to read (HIGH or LOW) |
timeout | Timeout in microseconds (default 1 second) |
Implements arduino::HardwareGPIO.
|
virtual |
Alternative to pulseIn() which is better at handling long pulses.
pin | The pin on which you want to read the pulse |
state | Type of pulse to read (HIGH or LOW) |
timeout | Timeout in microseconds (default 1 second) |
Implements arduino::HardwareGPIO.
|
virtual |
Generate a square wave of the specified frequency on a pin.
_pin | The pin on which to generate the tone |
frequency | The frequency of the tone in hertz |
duration | The duration of the tone in milliseconds (0 = continuous) |
Implements arduino::HardwareGPIO.