![]() |
PIDUINO
|
Represents a general-purpose input/output (GPIO) pin and its configuration. More...
#include <gpiopin.h>
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). | |
Converter * | dac () |
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. | |
Connector * | connector () const |
Returns the parent connector of the pin. | |
Gpio * | gpio () 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 | |
GpioDevice * | device () 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< Private > | d_ptr |
Unique pointer to the private implementation. | |
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.
Alias for Gpio2::LineEvent, representing a GPIO event.
Piduino::Pin::Isr |
enum Piduino::Pin::Edge |
enum Piduino::Pin::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. |
enum Piduino::Pin::Pull |
enum Piduino::Pin::Type |
Piduino::Pin::Pin | ( | Connector * | parent, |
const Descriptor * | desc | ||
) |
Constructs a Pin object.
parent | Pointer to the parent Connector. |
desc | Pointer to the pin Descriptor. |
|
virtual |
Destructor for the Pin object.
|
protected |
AccessLayer Piduino::Pin::accessLayer | ( | ) | const |
Returns the access layer used by the pin.
void Piduino::Pin::analogWrite | ( | long | value | ) |
Writes an analog value to the pin (PWM or DAC).
value | The analog value. |
void Piduino::Pin::attachInterrupt | ( | Isr | isr, |
Edge | edge, | ||
int | debounce_ms, | ||
void * | userData = nullptr |
||
) |
Attaches an interrupt handler with debounce.
isr | The interrupt service routine. |
edge | The edge to detect. |
debounce_ms | Debounce time in milliseconds. |
userData | Optional user data pointer. |
Attaches an interrupt handler to the pin.
isr | The interrupt service routine. |
edge | The edge to detect. |
userData | Optional user data pointer. |
int Piduino::Pin::chipNumber | ( | ) | const |
Returns the chip number for the pin.
int Piduino::Pin::chipOffset | ( | ) | const |
Returns the offset within the chip.
|
protected |
Closes the pin and releases resources.
int Piduino::Pin::column | ( | ) | const |
Returns the column position of the pin.
Connector * Piduino::Pin::connector | ( | ) | const |
Returns the parent connector of the pin.
Converter * Piduino::Pin::dac | ( | ) |
Returns the DAC converter associated with the pin.
void Piduino::Pin::detachInterrupt | ( | ) |
Detaches the interrupt handler from the pin.
|
protected |
Returns the underlying GPIO device.
int Piduino::Pin::drive | ( | ) |
Returns the drive strength of the pin.
bool Piduino::Pin::enableGpioDev | ( | bool | enable = true | ) |
Enables or disables the GPIO device.
enable | True to enable, false to disable. |
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.
Gpio * Piduino::Pin::gpio | ( | ) | const |
Returns the GPIO object associated with the pin.
long long Piduino::Pin::id | ( | ) | const |
Returns the unique identifier of the pin.
bool Piduino::Pin::isDebug | ( | ) | const |
Checks if debug mode is enabled for the pin.
bool Piduino::Pin::isGpioDevEnabled | ( | ) | const |
Checks if the GPIO device is enabled.
bool Piduino::Pin::isOpen | ( | ) | const |
Checks if the pin is open.
int Piduino::Pin::logicalNumber | ( | ) | const |
Returns the logical pin number.
int Piduino::Pin::mcuNumber | ( | ) | const |
Returns the MCU-specific pin number.
Mode Piduino::Pin::mode | ( | ) | const |
Returns the current mode of the pin.
const std::string & Piduino::Pin::modeName | ( | ) |
Returns the name of the current mode.
const std::string & Piduino::Pin::modeName | ( | Mode | mode | ) | const |
Returns the name of a specific mode.
mode | The mode. |
const std::map< Mode, std::string > & Piduino::Pin::modes | ( | ) | const |
Returns the map of available modes and their names.
const std::string & Piduino::Pin::name | ( | ) | const |
Returns the default name of the pin.
const std::string & Piduino::Pin::name | ( | Mode | mode | ) | const |
Returns the name of the pin for a specific mode.
mode | The mode. |
int Piduino::Pin::number | ( | Numbering | numbering | ) | const |
Returns the pin number according to the specified numbering scheme.
numbering | The numbering scheme. |
|
static |
Returns the name of a numbering scheme.
n | The numbering scheme. |
|
static |
Returns the map of available numbering schemes and their names.
|
protected |
Opens the pin for use.
int Piduino::Pin::physicalNumber | ( | ) | const |
Returns the physical pin number.
Pull Piduino::Pin::pull | ( | ) | const |
Returns the current pull resistor configuration.
const std::string & Piduino::Pin::pullName | ( | ) |
Returns the name of the current pull configuration.
|
static |
Returns the name of a specific pull configuration.
n | The pull configuration. |
|
static |
Returns the map of available pull configurations and their names.
bool Piduino::Pin::read | ( | ) | const |
Reads the digital value from the pin.
void Piduino::Pin::release | ( | ) |
Releases the pin, closing any open resources.
void Piduino::Pin::resetDac | ( | ) |
Resets the DAC converter for the pin.
int Piduino::Pin::row | ( | ) | const |
Returns the row position of the pin.
bool Piduino::Pin::setDac | ( | Converter * | dac | ) |
Sets the DAC converter for the pin.
dac | Pointer to the DAC converter. |
void Piduino::Pin::setDebug | ( | bool | enable | ) |
Enables or disables debug mode for the pin.
enable | True to enable, false to disable. |
void Piduino::Pin::setDrive | ( | int | drive | ) |
Sets the drive strength of the pin.
drive | The drive strength. |
void Piduino::Pin::setMode | ( | Mode | mode | ) |
Sets the mode of the pin.
mode | The mode to set. |
void Piduino::Pin::setPull | ( | Pull | pull | ) |
Sets the pull resistor configuration.
pull | The pull configuration. |
int Piduino::Pin::systemNumber | ( | ) | const |
Returns the system pin number.
void Piduino::Pin::toggle | ( | ) |
Toggles the digital output value of the pin.
Type Piduino::Pin::type | ( | ) | const |
Returns the type of the pin.
const std::string & Piduino::Pin::typeName | ( | ) | const |
Returns the name of the pin type.
|
static |
Returns the name of a given pin type.
t | The pin type. |
|
static |
Returns the map of available pin types and their names.
Waits for an interrupt event and returns the event data.
edge | The edge to detect. |
event | Reference to store the event data. |
timeout_ms | Timeout in milliseconds (-1 for infinite). |
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.
edge | The edge to detect. |
debounce_ms | Debounce time in milliseconds. |
event | Reference to store the event data. |
timeout_ms | Timeout in milliseconds (-1 for infinite). |
void Piduino::Pin::waitForInterrupt | ( | Edge | edge, |
int | timeout_ms = -1 |
||
) |
Waits for an interrupt event on the pin.
edge | The edge to detect. |
timeout_ms | Timeout in milliseconds (-1 for infinite). |
void Piduino::Pin::write | ( | bool | value | ) |
Writes a digital value to the pin.
value | The value to write (true for high, false for low). |