PIDUINO
Loading...
Searching...
No Matches
Piduino::Pin

Represents a general-purpose input/output (GPIO) pin and its configuration. More...

#include <gpiopin.h>

Collaboration diagram for Piduino::Pin:

Classes

class  Descriptor
 Describes a pin's type, numbering, and associated names. More...
 
class  Number
 Holds various numbering representations for a pin. More...
 
class  SpiCs
 Represents a SPI chip select configuration for a pin. More...
 

Public Types

enum  Mode {
  ModeInput , ModeOutput , ModeDisabled , ModePwm ,
  ModeAlt0 , ModeAlt1 , ModeAlt2 , ModeAlt3 ,
  ModeAlt4 , ModeAlt5 , ModeAlt6 , ModeAlt7 ,
  ModeAlt8 , ModeAlt9 , ModeUnknown = -1
}
 Enumerates the possible modes for a pin. More...
 
enum  Pull { PullOff , PullDown , PullUp , PullUnknown = -1 }
 Enumerates the possible pull resistor configurations. More...
 
enum  Edge {
  EdgeNone , EdgeRising , EdgeFalling , EdgeBoth ,
  EdgeUnknown = -1
}
 Enumerates the possible edge detection types for interrupts. More...
 
enum  Numbering { NumberingLogical , NumberingMcu , NumberingSystem , NumberingUnknown = -1 }
 Enumerates the possible pin numbering schemes. More...
 
enum  Type {
  TypeGpio , TypePower , TypeUsb , TypeSound ,
  TypeVideo , TypeNotConnected , TypeNet , TypeUnknown = -1
}
 Enumerates the possible types of pins. More...
 
using Event = Gpio2::LineEvent
 Alias for Gpio2::LineEvent, representing a GPIO event.
 
typedef void(* Isr) (Event event, void *userData)
 Interrupt service routine callback type.
 

Public Member Functions

AccessLayer accessLayer () const
 Returns the access layer used by the pin.
 
bool isOpen () const
 Checks if the pin is open.
 
int number (Numbering numbering) const
 Returns the pin number according to the specified numbering scheme.
 
int logicalNumber () const
 Returns the logical pin number.
 
int mcuNumber () const
 Returns the MCU-specific pin number.
 
int systemNumber () const
 Returns the system pin number.
 
int physicalNumber () const
 Returns the physical pin number.
 
int chipNumber () const
 Returns the chip number for the pin.
 
int chipOffset () const
 Returns the offset within the chip.
 
int row () const
 Returns the row position of the pin.
 
int column () const
 Returns the column position of the pin.
 
Type type () const
 Returns the type of the pin.
 
unsigned int flags () const
 Gets the capability flags of the GPIO Pin.
 
const std::string & typeName () const
 Returns the name of the pin type.
 
const std::string & name () const
 Returns the default name of the pin.
 
const std::string & name (Mode mode) const
 Returns the name of the pin for a specific mode.
 
void setMode (Mode mode)
 Sets the mode of the pin.
 
Mode mode () const
 Returns the current mode of the pin.
 
const std::map< Mode, std::string > & modes () const
 Returns the map of available modes and their names.
 
const std::string & modeName ()
 Returns the name of the current mode.
 
const std::string & modeName (Mode mode) const
 Returns the name of a specific mode.
 
void setPull (Pull pull)
 Sets the pull resistor configuration.
 
Pull pull () const
 Returns the current pull resistor configuration.
 
const std::string & pullName ()
 Returns the name of the current pull configuration.
 
int drive ()
 Returns the drive strength of the pin.
 
void setDrive (int drive)
 Sets the drive strength of the pin.
 
void write (bool value)
 Writes a digital value to the pin.
 
bool read () const
 Reads the digital value from the pin.
 
void toggle ()
 Toggles the digital output value of the pin.
 
void release ()
 Releases the pin, closing any open resources.
 
void waitForInterrupt (Edge edge, int timeout_ms=-1)
 Waits for an interrupt event on the pin.
 
void waitForInterrupt (Edge edge, Event &event, int timeout_ms=-1)
 Waits for an interrupt event and returns the event data.
 
void waitForInterrupt (Edge edge, int debounce_ms, Event &event, int timeout_ms=-1)
 Waits for an interrupt event with debounce and returns the event data.
 
void attachInterrupt (Isr isr, Edge edge, void *userData=nullptr)
 Attaches an interrupt handler to the pin.
 
void attachInterrupt (Isr isr, Edge edge, int debounce_ms, void *userData=nullptr)
 Attaches an interrupt handler with debounce.
 
void detachInterrupt ()
 Detaches the interrupt handler from the pin.
 
bool isGpioDevEnabled () const
 Checks if the GPIO device is enabled.
 
bool enableGpioDev (bool enable=true)
 Enables or disables the GPIO device.
 
void analogWrite (long value)
 Writes an analog value to the pin (PWM or DAC).
 
Converterdac ()
 Returns the DAC converter associated with the pin.
 
bool setDac (Converter *dac)
 Sets the DAC converter for the pin.
 
void resetDac ()
 Resets the DAC converter for the pin.
 
long long id () const
 Returns the unique identifier of the pin.
 
Connectorconnector () const
 Returns the parent connector of the pin.
 
Gpiogpio () const
 Returns the GPIO object associated with the pin.
 
bool isDebug () const
 Checks if debug mode is enabled for the pin.
 
void setDebug (bool enable)
 Enables or disables debug mode for the pin.
 
 Pin (Connector *parent, const Descriptor *desc)
 Constructs a Pin object.
 
virtual ~Pin ()
 Destructor for the Pin object.
 

Static Public Member Functions

static const std::map< Numbering, std::string > & numberings ()
 Returns the map of available numbering schemes and their names.
 
static const std::string & numberingName (Numbering n)
 Returns the name of a numbering scheme.
 
static const std::string & typeName (Type t)
 Returns the name of a given pin type.
 
static const std::map< Type, std::string > & types ()
 Returns the map of available pin types and their names.
 
static const std::map< Pull, std::string > & pulls ()
 Returns the map of available pull configurations and their names.
 
static const std::string & pullName (Pull n)
 Returns the name of a specific pull configuration.
 

Protected Member Functions

GpioDevicedevice () const
 Returns the underlying GPIO device.
 
bool open ()
 Opens the pin for use.
 
void close ()
 Closes the pin and releases resources.
 
 Pin (Private &dd)
 Constructs a Pin object from a Private data reference.
 

Protected Attributes

std::unique_ptr< Privated_ptr
 Unique pointer to the private implementation.
 

Detailed Description

Represents a general-purpose input/output (GPIO) pin and its configuration.

The Pin class provides an abstraction for a GPIO pin, allowing configuration of its mode, pull-up/down resistors, edge detection, and other properties. It supports various numbering schemes and pin types, and provides methods for digital and analog I/O, interrupt handling, and device management.

Note
This class is intended to be used with the Connector and Gpio classes for hardware access.

Definition at line 68 of file gpiopin.h.

Member Typedef Documentation

◆ Event

Alias for Gpio2::LineEvent, representing a GPIO event.

Definition at line 228 of file gpiopin.h.

◆ Isr

Piduino::Pin::Isr

Interrupt service routine callback type.

Parameters
eventThe GPIO event.
userDataUser data pointer.

Definition at line 487 of file gpiopin.h.

Member Enumeration Documentation

◆ Edge

Enumerates the possible edge detection types for interrupts.

Enumerator
EdgeNone 

No edge detection.

EdgeRising 

Detect rising edge.

EdgeFalling 

Detect falling edge.

EdgeBoth 

Detect both rising and falling edges.

EdgeUnknown 

Unknown or uninitialized edge type.

Definition at line 109 of file gpiopin.h.

◆ Mode

Enumerates the possible modes for a pin.

Enumerator
ModeInput 

Pin is configured as input.

ModeOutput 

Pin is configured as output.

ModeDisabled 

Pin is disabled.

ModePwm 

Pin is configured for PWM output.

ModeAlt0 

Alternate function 0.

ModeAlt1 

Alternate function 1.

ModeAlt2 

Alternate function 2.

ModeAlt3 

Alternate function 3.

ModeAlt4 

Alternate function 4.

ModeAlt5 

Alternate function 5.

ModeAlt6 

Alternate function 6.

ModeAlt7 

Alternate function 7.

ModeAlt8 

Alternate function 8.

ModeAlt9 

Alternate function 9.

ModeUnknown 

Unknown or uninitialized mode.

Definition at line 76 of file gpiopin.h.

◆ Numbering

Enumerates the possible pin numbering schemes.

Enumerator
NumberingLogical 

Logical numbering.

NumberingMcu 

MCU-specific numbering.

NumberingSystem 

System numbering.

NumberingUnknown 

Unknown or uninitialized numbering.

Definition at line 121 of file gpiopin.h.

◆ Pull

Enumerates the possible pull resistor configurations.

Enumerator
PullOff 

No pull resistor.

PullDown 

Pull-down resistor enabled.

PullUp 

Pull-up resistor enabled.

PullUnknown 

Unknown or uninitialized pull configuration.

Definition at line 98 of file gpiopin.h.

◆ Type

Enumerates the possible types of pins.

Enumerator
TypeGpio 

General-purpose I/O pin.

TypePower 

Power pin.

TypeUsb 

USB pin.

TypeSound 

Sound pin.

TypeVideo 

Video pin.

TypeNotConnected 

Not connected.

TypeNet 

Network pin.

TypeUnknown 

Unknown or uninitialized type.

Definition at line 132 of file gpiopin.h.

Constructor & Destructor Documentation

◆ Pin() [1/2]

Piduino::Pin::Pin ( Connector parent,
const Descriptor desc 
)

Constructs a Pin object.

Parameters
parentPointer to the parent Connector.
descPointer to the pin Descriptor.

◆ ~Pin()

virtual Piduino::Pin::~Pin ( )
virtual

Destructor for the Pin object.

◆ Pin() [2/2]

Piduino::Pin::Pin ( Private dd)
protected

Constructs a Pin object from a Private data reference.

Parameters
ddReference to the Private data.

Member Function Documentation

◆ accessLayer()

AccessLayer Piduino::Pin::accessLayer ( ) const

Returns the access layer used by the pin.

Returns
The access layer.

◆ analogWrite()

void Piduino::Pin::analogWrite ( long  value)

Writes an analog value to the pin (PWM or DAC).

Parameters
valueThe analog value.

◆ attachInterrupt() [1/2]

void Piduino::Pin::attachInterrupt ( Isr  isr,
Edge  edge,
int  debounce_ms,
void *  userData = nullptr 
)

Attaches an interrupt handler with debounce.

Parameters
isrThe interrupt service routine.
edgeThe edge to detect.
debounce_msDebounce time in milliseconds.
userDataOptional user data pointer.

◆ attachInterrupt() [2/2]

void Piduino::Pin::attachInterrupt ( Isr  isr,
Edge  edge,
void *  userData = nullptr 
)

Attaches an interrupt handler to the pin.

Parameters
isrThe interrupt service routine.
edgeThe edge to detect.
userDataOptional user data pointer.

◆ chipNumber()

int Piduino::Pin::chipNumber ( ) const

Returns the chip number for the pin.

Returns
The chip number.

◆ chipOffset()

int Piduino::Pin::chipOffset ( ) const

Returns the offset within the chip.

Returns
The chip offset.

◆ close()

void Piduino::Pin::close ( )
protected

Closes the pin and releases resources.

◆ column()

int Piduino::Pin::column ( ) const

Returns the column position of the pin.

Returns
The column.

◆ connector()

Connector * Piduino::Pin::connector ( ) const

Returns the parent connector of the pin.

Returns
Pointer to the Connector.

◆ dac()

Converter * Piduino::Pin::dac ( )

Returns the DAC converter associated with the pin.

Returns
Pointer to the DAC converter.

◆ detachInterrupt()

void Piduino::Pin::detachInterrupt ( )

Detaches the interrupt handler from the pin.

◆ device()

GpioDevice * Piduino::Pin::device ( ) const
protected

Returns the underlying GPIO device.

Returns
Pointer to the GpioDevice.

◆ drive()

int Piduino::Pin::drive ( )

Returns the drive strength of the pin.

Returns
The drive strength.

◆ enableGpioDev()

bool Piduino::Pin::enableGpioDev ( bool  enable = true)

Enables or disables the GPIO device.

Parameters
enableTrue to enable, false to disable.
Returns
True on success, false otherwise.

◆ flags()

unsigned int Piduino::Pin::flags ( ) const

Gets the capability flags of the GPIO Pin.

If the type of pin is not Gpio, this function returns 0. The capability flags indicate the features supported by the GPIO device, such as toggling, pull resistor reading, alternate function reading, drive strength setting, waiting for interrupts, active low configuration, and debounce support.

Returns
The capability flags as a bitwise OR of the GpioDevice::Flags enum values.

◆ gpio()

Gpio * Piduino::Pin::gpio ( ) const

Returns the GPIO object associated with the pin.

Returns
Pointer to the Gpio object.

◆ id()

long long Piduino::Pin::id ( ) const

Returns the unique identifier of the pin.

Returns
The pin ID.

◆ isDebug()

bool Piduino::Pin::isDebug ( ) const

Checks if debug mode is enabled for the pin.

Returns
True if debug is enabled, false otherwise.

◆ isGpioDevEnabled()

bool Piduino::Pin::isGpioDevEnabled ( ) const

Checks if the GPIO device is enabled.

Returns
True if enabled, false otherwise.

◆ isOpen()

bool Piduino::Pin::isOpen ( ) const

Checks if the pin is open.

Returns
True if open, false otherwise.

◆ logicalNumber()

int Piduino::Pin::logicalNumber ( ) const

Returns the logical pin number.

Returns
The logical number.

◆ mcuNumber()

int Piduino::Pin::mcuNumber ( ) const

Returns the MCU-specific pin number.

Returns
The MCU number.

◆ mode()

Mode Piduino::Pin::mode ( ) const

Returns the current mode of the pin.

Returns
The pin mode.

◆ modeName() [1/2]

const std::string & Piduino::Pin::modeName ( )

Returns the name of the current mode.

Returns
Reference to the mode name.

◆ modeName() [2/2]

const std::string & Piduino::Pin::modeName ( Mode  mode) const

Returns the name of a specific mode.

Parameters
modeThe mode.
Returns
Reference to the mode name.

◆ modes()

const std::map< Mode, std::string > & Piduino::Pin::modes ( ) const

Returns the map of available modes and their names.

Returns
Reference to the mode map.

◆ name() [1/2]

const std::string & Piduino::Pin::name ( ) const

Returns the default name of the pin.

Returns
Reference to the pin name.

◆ name() [2/2]

const std::string & Piduino::Pin::name ( Mode  mode) const

Returns the name of the pin for a specific mode.

Parameters
modeThe mode.
Returns
Reference to the mode-specific name.

◆ number()

int Piduino::Pin::number ( Numbering  numbering) const

Returns the pin number according to the specified numbering scheme.

Parameters
numberingThe numbering scheme.
Returns
The pin number.

◆ numberingName()

static const std::string & Piduino::Pin::numberingName ( Numbering  n)
static

Returns the name of a numbering scheme.

Parameters
nThe numbering scheme.
Returns
Reference to the numbering name.

◆ numberings()

static const std::map< Numbering, std::string > & Piduino::Pin::numberings ( )
static

Returns the map of available numbering schemes and their names.

Returns
Reference to the numbering map.

◆ open()

bool Piduino::Pin::open ( )
protected

Opens the pin for use.

Returns
True on success, false otherwise.

◆ physicalNumber()

int Piduino::Pin::physicalNumber ( ) const

Returns the physical pin number.

Returns
The physical number.

◆ pull()

Pull Piduino::Pin::pull ( ) const

Returns the current pull resistor configuration.

Returns
The pull configuration.

◆ pullName() [1/2]

const std::string & Piduino::Pin::pullName ( )

Returns the name of the current pull configuration.

Returns
Reference to the pull name.

◆ pullName() [2/2]

static const std::string & Piduino::Pin::pullName ( Pull  n)
static

Returns the name of a specific pull configuration.

Parameters
nThe pull configuration.
Returns
Reference to the pull name.

◆ pulls()

static const std::map< Pull, std::string > & Piduino::Pin::pulls ( )
static

Returns the map of available pull configurations and their names.

Returns
Reference to the pull map.

◆ read()

bool Piduino::Pin::read ( ) const

Reads the digital value from the pin.

Returns
The value read (true for high, false for low).

◆ release()

void Piduino::Pin::release ( )

Releases the pin, closing any open resources.

◆ resetDac()

void Piduino::Pin::resetDac ( )

Resets the DAC converter for the pin.

◆ row()

int Piduino::Pin::row ( ) const

Returns the row position of the pin.

Returns
The row.

◆ setDac()

bool Piduino::Pin::setDac ( Converter dac)

Sets the DAC converter for the pin.

Parameters
dacPointer to the DAC converter.
Returns
True on success, false otherwise.

◆ setDebug()

void Piduino::Pin::setDebug ( bool  enable)

Enables or disables debug mode for the pin.

Parameters
enableTrue to enable, false to disable.

◆ setDrive()

void Piduino::Pin::setDrive ( int  drive)

Sets the drive strength of the pin.

Parameters
driveThe drive strength.

◆ setMode()

void Piduino::Pin::setMode ( Mode  mode)

Sets the mode of the pin.

Parameters
modeThe mode to set.

◆ setPull()

void Piduino::Pin::setPull ( Pull  pull)

Sets the pull resistor configuration.

Parameters
pullThe pull configuration.

◆ systemNumber()

int Piduino::Pin::systemNumber ( ) const

Returns the system pin number.

Returns
The system number.

◆ toggle()

void Piduino::Pin::toggle ( )

Toggles the digital output value of the pin.

◆ type()

Type Piduino::Pin::type ( ) const

Returns the type of the pin.

Returns
The pin type.

◆ typeName() [1/2]

const std::string & Piduino::Pin::typeName ( ) const

Returns the name of the pin type.

Returns
Reference to the type name.

◆ typeName() [2/2]

static const std::string & Piduino::Pin::typeName ( Type  t)
static

Returns the name of a given pin type.

Parameters
tThe pin type.
Returns
Reference to the type name.

◆ types()

static const std::map< Type, std::string > & Piduino::Pin::types ( )
static

Returns the map of available pin types and their names.

Returns
Reference to the type map.

◆ waitForInterrupt() [1/3]

void Piduino::Pin::waitForInterrupt ( Edge  edge,
Event event,
int  timeout_ms = -1 
)

Waits for an interrupt event and returns the event data.

Parameters
edgeThe edge to detect.
eventReference to store the event data.
timeout_msTimeout in milliseconds (-1 for infinite).

◆ waitForInterrupt() [2/3]

void Piduino::Pin::waitForInterrupt ( Edge  edge,
int  debounce_ms,
Event event,
int  timeout_ms = -1 
)

Waits for an interrupt event with debounce and returns the event data.

Parameters
edgeThe edge to detect.
debounce_msDebounce time in milliseconds.
eventReference to store the event data.
timeout_msTimeout in milliseconds (-1 for infinite).

◆ waitForInterrupt() [3/3]

void Piduino::Pin::waitForInterrupt ( Edge  edge,
int  timeout_ms = -1 
)

Waits for an interrupt event on the pin.

Parameters
edgeThe edge to detect.
timeout_msTimeout in milliseconds (-1 for infinite).

◆ write()

void Piduino::Pin::write ( bool  value)

Writes a digital value to the pin.

Parameters
valueThe value to write (true for high, false for low).

Member Data Documentation

◆ d_ptr

std::unique_ptr<Private> Piduino::Pin::d_ptr
protected

Unique pointer to the private implementation.

Definition at line 646 of file gpiopin.h.