![]() |
PIDUINO
|
Abstract base class for GPIO devices. More...
#include <gpiodevice.h>
Public Types | |
enum | { hasToggle = 0x00000001 , hasPullRead = 0x00000002 , hasAltRead = 0x00000004 , hasDrive = 0x00000008 , hasWfi = 0x00000010 , hasActiveLow = 0x00000020 , hasDebounce = 0x00000040 , useGpioMem = 0x00010000 } |
Public Member Functions | |
GpioDevice () | |
Public Constructor. | |
virtual | ~GpioDevice () |
Destructor. | |
virtual bool | open ()=0 |
Opens the GPIO device. | |
virtual void | close ()=0 |
Closes the GPIO device. | |
virtual void | write (const Pin *pin, bool v)=0 |
Writes a boolean value to a GPIO pin. | |
virtual bool | read (const Pin *pin) const =0 |
Reads the value of a GPIO pin. | |
virtual void | setMode (const Pin *pin, Pin::Mode m)=0 |
Sets the mode of a GPIO pin. | |
virtual Pin::Mode | mode (const Pin *pin) const =0 |
Gets the mode of a GPIO pin. | |
virtual void | setPull (const Pin *pin, Pin::Pull p)=0 |
Sets the pull-up/pull-down configuration of a GPIO pin. | |
virtual AccessLayer | preferedAccessLayer () const =0 |
Gets the preferred access layer for the GPIO device. | |
virtual const std::map< Pin::Mode, std::string > & | modes () const =0 |
Gets the supported modes for the GPIO device. | |
virtual void | toggle (const Pin *pin) |
Toggles the state of a GPIO pin. | |
virtual Pin::Pull | pull (const Pin *pin) const |
Gets the pull-up/pull-down configuration of a GPIO pin. | |
virtual void | setDrive (const Pin *pin, int d) |
Sets the drive strength of a GPIO pin. | |
virtual int | drive (const Pin *pin) const |
Gets the drive strength of a GPIO pin. | |
virtual int | waitForInterrupt (const Pin *pin, Pin::Edge edge, int timeout_ms) |
Waits for an interrupt on a GPIO pin. | |
virtual void | setDebounce (const Pin *pin, uint32_t debounce_ms) |
Sets the debounce period for the GPIO line. The default implementation does nothing. | |
virtual uint32_t | debounce (const Pin *pin) const |
Gets the debounce period for the GPIO line. | |
virtual void | setActiveLow (const Pin *pin, bool activeLow) |
Sets the active low configuration for a GPIO pin. | |
virtual bool | isActiveLow (const Pin *pin) const |
Checks if a GPIO pin is configured as active low. | |
virtual unsigned int | flags () const |
Gets the capability flags of the GPIO device. | |
virtual bool | isOpen () const |
Checks if the GPIO device is open. | |
virtual bool | isDebug () const |
Checks if the GPIO device is in debug mode. | |
virtual void | setDebug (bool enable) |
Sets the debug mode of the GPIO device. | |
Protected Member Functions | |
GpioDevice (Private &dd) | |
Protected Constructor. | |
Protected Attributes | |
std::unique_ptr< Private > | d_ptr |
A unique pointer to the private implementation (PIMPL idiom). | |
Abstract base class for GPIO devices.
This class provides an interface for GPIO device operations. It uses the PIMPL (Pointer to Implementation) pattern to hide implementation details. Derived classes should implement the pure virtual methods to provide specific functionality.
Definition at line 34 of file gpiodevice.h.
anonymous enum |
Enumerator | |
---|---|
hasToggle | |
hasPullRead | |
hasAltRead | |
hasDrive | |
hasWfi | |
hasActiveLow | |
hasDebounce | |
useGpioMem | Use /dev/gpiomem for GPIO access. |
Definition at line 252 of file gpiodevice.h.
Piduino::GpioDevice::GpioDevice | ( | ) |
Public Constructor.
Initializes a GpioDevice instance. This constructor is used by derived classes to initialize the base class.
|
virtual |
Destructor.
Cleans up resources used by the GpioDevice instance.
|
protected |
Protected Constructor.
Initializes a GpioDevice instance with a private implementation.
dd | Reference to the private implementation object. |
|
pure virtual |
Closes the GPIO device.
|
virtual |
Gets the debounce period for the GPIO line.
The default implementation returns 0.
pin | Pointer to the Pin object. |
|
virtual |
Gets the drive strength of a GPIO pin.
The default implementation returns 0.
pin | Pointer to the Pin object. |
|
virtual |
Gets the capability flags of the GPIO device.
|
virtual |
Checks if a GPIO pin is configured as active low.
This function checks the active low configuration of the specified GPIO pin. If the pin is configured as active low, it means that the pin is considered "active" when it is driven low (0V).
The default implementation returns false.
pin | Pointer to the Pin object. |
|
virtual |
Checks if the GPIO device is in debug mode.
|
virtual |
Checks if the GPIO device is open.
Gets the mode of a GPIO pin.
pin | Pointer to the Pin object. |
|
pure virtual |
Gets the supported modes for the GPIO device.
|
pure virtual |
Opens the GPIO device.
|
pure virtual |
Gets the preferred access layer for the GPIO device.
Gets the pull-up/pull-down configuration of a GPIO pin.
The default implementation returns PullUnknown.
pin | Pointer to the Pin object. |
|
pure virtual |
Reads the value of a GPIO pin.
pin | Pointer to the Pin object. |
|
virtual |
Sets the active low configuration for a GPIO pin.
This function is used to configure the pin's active low state. The active low state means that the pin is considered "active" when it is driven low (0V). This is useful for devices that are activated by a low signal, such as certain types of sensors or switches.
The default implementation does nothing.
pin | Pointer to the Pin object. |
activeLow | true to set the pin as active low, false otherwise. |
|
virtual |
Sets the debounce period for the GPIO line. The default implementation does nothing.
pin | Pointer to the Pin object. |
debounce_ms | The debounce period in milliseconds. |
|
virtual |
Sets the debug mode of the GPIO device.
enable | true to enable debug mode, false to disable it. |
|
virtual |
Sets the drive strength of a GPIO pin.
The default implementation does nothing.
pin | Pointer to the Pin object. |
d | Drive strength to set for the pin. |
Sets the mode of a GPIO pin.
pin | Pointer to the Pin object. |
m | Mode to set for the pin. |
Sets the pull-up/pull-down configuration of a GPIO pin.
pin | Pointer to the Pin object. |
p | Pull configuration to set for the pin. |
|
virtual |
Toggles the state of a GPIO pin.
The default implementation writes the inverse of the current pin value.
pin | Pointer to the Pin object. |
|
virtual |
Waits for an interrupt on a GPIO pin.
The default implementation return -1.
pin | Pointer to the Pin object. |
edge | The edge to wait for (rising, falling, or both). |
timeout_ms | The maximum wait time in milliseconds. -1 for infinite wait. |
|
pure virtual |
Writes a boolean value to a GPIO pin.
pin | Pointer to the Pin object. |
v | Boolean value to write to the pin (true for high, false for low). |
|
protected |
A unique pointer to the private implementation (PIMPL idiom).
This member variable is used to encapsulate the private details of the class implementation, ensuring a clean separation between the interface and implementation. It provides automatic memory management for the private data, ensuring proper cleanup when the owning object is destroyed.
Definition at line 318 of file gpiodevice.h.