arduino-emulator
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
arduino::GPIOWrapper Class Reference

GPIO wrapper class that provides flexible hardware abstraction. More...

#include <GPIOWrapper.h>

Inheritance diagram for arduino::GPIOWrapper:
arduino::HardwareGPIO

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

HardwareGPIOgetGPIO ()
 

Protected Attributes

HardwareGPIOp_gpio = nullptr
 
GPIOSourcep_source = nullptr
 

Detailed Description

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.

See also
HardwareGPIO
GPIOSource

Member Function Documentation

◆ analogRead()

int arduino::GPIOWrapper::analogRead ( pin_size_t  pinNumber)
virtual

Read the value from the specified analog pin.

Parameters
pinNumberThe analog pin to read from (A0, A1, etc.)
Returns
The analog reading on the pin (0-1023 for 10-bit ADC)

Implements arduino::HardwareGPIO.

◆ analogReference()

void arduino::GPIOWrapper::analogReference ( uint8_t  mode)
virtual

Configure the reference voltage used for analog input.

Parameters
modeThe reference type (DEFAULT, INTERNAL, EXTERNAL, etc.)

Implements arduino::HardwareGPIO.

◆ analogWrite()

void arduino::GPIOWrapper::analogWrite ( pin_size_t  pinNumber,
int  value 
)
virtual

Write an analog value (PWM wave) to a pin.

Parameters
pinNumberThe pin to write to
valueThe duty cycle (0-255 for 8-bit PWM)

Implements arduino::HardwareGPIO.

◆ digitalRead()

PinStatus arduino::GPIOWrapper::digitalRead ( pin_size_t  pinNumber)
virtual

Read the value from a specified digital pin.

Parameters
pinNumberThe pin number to read from
Returns
HIGH or LOW

Implements arduino::HardwareGPIO.

◆ digitalWrite()

void arduino::GPIOWrapper::digitalWrite ( pin_size_t  pinNumber,
PinStatus  status 
)
virtual

Write a HIGH or LOW value to a digital pin.

Parameters
pinNumberThe pin number to write to
statusThe value to write (HIGH or LOW)

Implements arduino::HardwareGPIO.

◆ noTone()

void arduino::GPIOWrapper::noTone ( uint8_t  _pin)
virtual

Stop the generation of a square wave triggered by tone()

Parameters
_pinThe pin on which to stop generating the tone

Implements arduino::HardwareGPIO.

◆ pinMode()

void arduino::GPIOWrapper::pinMode ( pin_size_t  pinNumber,
PinMode  pinMode 
)
virtual

Configure the specified pin to behave as an input or output.

Parameters
pinNumberThe pin number to configure
pinModeThe mode to set (INPUT, OUTPUT, INPUT_PULLUP, etc.)

Implements arduino::HardwareGPIO.

◆ pulseIn()

unsigned long arduino::GPIOWrapper::pulseIn ( uint8_t  pin,
uint8_t  state,
unsigned long  timeout = 1000000L 
)
virtual

Read a pulse (HIGH or LOW) on a pin.

Parameters
pinThe pin on which you want to read the pulse
stateType of pulse to read (HIGH or LOW)
timeoutTimeout in microseconds (default 1 second)
Returns
The length of the pulse in microseconds, or 0 if timeout

Implements arduino::HardwareGPIO.

◆ pulseInLong()

unsigned long arduino::GPIOWrapper::pulseInLong ( uint8_t  pin,
uint8_t  state,
unsigned long  timeout = 1000000L 
)
virtual

Alternative to pulseIn() which is better at handling long pulses.

Parameters
pinThe pin on which you want to read the pulse
stateType of pulse to read (HIGH or LOW)
timeoutTimeout in microseconds (default 1 second)
Returns
The length of the pulse in microseconds, or 0 if timeout

Implements arduino::HardwareGPIO.

◆ tone()

void arduino::GPIOWrapper::tone ( uint8_t  _pin,
unsigned int  frequency,
unsigned long  duration = 0 
)
virtual

Generate a square wave of the specified frequency on a pin.

Parameters
_pinThe pin on which to generate the tone
frequencyThe frequency of the tone in hertz
durationThe duration of the tone in milliseconds (0 = continuous)

Implements arduino::HardwareGPIO.


The documentation for this class was generated from the following files: