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

Abstract base class for GPIO devices. More...

#include <gpiodevice.h>

Collaboration diagram for Piduino::GpioDevice:

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< Privated_ptr
 A unique pointer to the private implementation (PIMPL idiom).
 

Detailed Description

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.

Member Enumeration Documentation

◆ anonymous enum

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.

Constructor & Destructor Documentation

◆ GpioDevice() [1/2]

Piduino::GpioDevice::GpioDevice ( )

Public Constructor.

Initializes a GpioDevice instance. This constructor is used by derived classes to initialize the base class.

Note
This class uses the PIMPL pattern to hide implementation details.

◆ ~GpioDevice()

virtual Piduino::GpioDevice::~GpioDevice ( )
virtual

Destructor.

Cleans up resources used by the GpioDevice instance.

◆ GpioDevice() [2/2]

Piduino::GpioDevice::GpioDevice ( Private dd)
protected

Protected Constructor.

Initializes a GpioDevice instance with a private implementation.

Parameters
ddReference to the private implementation object.

Member Function Documentation

◆ close()

virtual void Piduino::GpioDevice::close ( )
pure virtual

Closes the GPIO device.

◆ debounce()

virtual uint32_t Piduino::GpioDevice::debounce ( const Pin pin) const
virtual

Gets the debounce period for the GPIO line.

The default implementation returns 0.

Parameters
pinPointer to the Pin object.
Returns
The debounce period in milliseconds.

◆ drive()

virtual int Piduino::GpioDevice::drive ( const Pin pin) const
virtual

Gets the drive strength of a GPIO pin.

The default implementation returns 0.

Note
If reimplemented, the hasDrive flag must be set.
Parameters
pinPointer to the Pin object.
Returns
The current drive strength of the pin.

◆ flags()

virtual unsigned int Piduino::GpioDevice::flags ( ) const
virtual

Gets the capability flags of the GPIO device.

Returns
The capability flags as a bitwise OR of the Flags enum values.
Note
The default implementation returns 0.

◆ isActiveLow()

virtual bool Piduino::GpioDevice::isActiveLow ( const Pin pin) const
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.

Parameters
pinPointer to the Pin object.
Returns
true if the pin is active low, false otherwise.

◆ isDebug()

virtual bool Piduino::GpioDevice::isDebug ( ) const
virtual

Checks if the GPIO device is in debug mode.

Returns
true if the device is in debug mode, false otherwise.

◆ isOpen()

virtual bool Piduino::GpioDevice::isOpen ( ) const
virtual

Checks if the GPIO device is open.

Returns
true if the device is open, false otherwise.

◆ mode()

virtual Pin::Mode Piduino::GpioDevice::mode ( const Pin pin) const
pure virtual

Gets the mode of a GPIO pin.

Parameters
pinPointer to the Pin object.
Returns
The current mode of the pin.

◆ modes()

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

Gets the supported modes for the GPIO device.

Returns
A map of supported modes and their corresponding string representations.

◆ open()

virtual bool Piduino::GpioDevice::open ( )
pure virtual

Opens the GPIO device.

Returns
true if the device was successfully opened, false otherwise.

◆ preferedAccessLayer()

virtual AccessLayer Piduino::GpioDevice::preferedAccessLayer ( ) const
pure virtual

Gets the preferred access layer for the GPIO device.

Returns
The preferred access layer.

◆ pull()

virtual Pin::Pull Piduino::GpioDevice::pull ( const Pin pin) const
virtual

Gets the pull-up/pull-down configuration of a GPIO pin.

The default implementation returns PullUnknown.

Note
If reimplemented, the hasPullRead flag must be set.
Parameters
pinPointer to the Pin object.
Returns
The current pull configuration of the pin.

◆ read()

virtual bool Piduino::GpioDevice::read ( const Pin pin) const
pure virtual

Reads the value of a GPIO pin.

Parameters
pinPointer to the Pin object.
Returns
Boolean value representing the pin state (true for high, false for low).

◆ setActiveLow()

virtual void Piduino::GpioDevice::setActiveLow ( const Pin pin,
bool  activeLow 
)
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.

Parameters
pinPointer to the Pin object.
activeLowtrue to set the pin as active low, false otherwise.
Note
If reimplemented, the hasActiveLow flag must be set.

◆ setDebounce()

virtual void Piduino::GpioDevice::setDebounce ( const Pin pin,
uint32_t  debounce_ms 
)
virtual

Sets the debounce period for the GPIO line. The default implementation does nothing.

Parameters
pinPointer to the Pin object.
debounce_msThe debounce period in milliseconds.

◆ setDebug()

virtual void Piduino::GpioDevice::setDebug ( bool  enable)
virtual

Sets the debug mode of the GPIO device.

Parameters
enabletrue to enable debug mode, false to disable it.

◆ setDrive()

virtual void Piduino::GpioDevice::setDrive ( const Pin pin,
int  d 
)
virtual

Sets the drive strength of a GPIO pin.

The default implementation does nothing.

Note
If reimplemented, the hasDrive flag must be set.
Parameters
pinPointer to the Pin object.
dDrive strength to set for the pin.

◆ setMode()

virtual void Piduino::GpioDevice::setMode ( const Pin pin,
Pin::Mode  m 
)
pure virtual

Sets the mode of a GPIO pin.

Parameters
pinPointer to the Pin object.
mMode to set for the pin.

◆ setPull()

virtual void Piduino::GpioDevice::setPull ( const Pin pin,
Pin::Pull  p 
)
pure virtual

Sets the pull-up/pull-down configuration of a GPIO pin.

Parameters
pinPointer to the Pin object.
pPull configuration to set for the pin.

◆ toggle()

virtual void Piduino::GpioDevice::toggle ( const Pin pin)
virtual

Toggles the state of a GPIO pin.

The default implementation writes the inverse of the current pin value.

Parameters
pinPointer to the Pin object.

◆ waitForInterrupt()

virtual int Piduino::GpioDevice::waitForInterrupt ( const Pin pin,
Pin::Edge  edge,
int  timeout_ms 
)
virtual

Waits for an interrupt on a GPIO pin.

The default implementation return -1.

Note
If reimplemented, the hasWfi flag must be set.
Parameters
pinPointer to the Pin object.
edgeThe edge to wait for (rising, falling, or both).
timeout_msThe maximum wait time in milliseconds. -1 for infinite wait.
Returns
1 if the interrupt occurred, 0 if the timeout occurred and -1 on error.
Note
The function should block until the interrupt occurs or the timeout

◆ write()

virtual void Piduino::GpioDevice::write ( const Pin pin,
bool  v 
)
pure virtual

Writes a boolean value to a GPIO pin.

Parameters
pinPointer to the Pin object.
vBoolean value to write to the pin (true for high, false for low).

Member Data Documentation

◆ d_ptr

std::unique_ptr<Private> Piduino::GpioDevice::d_ptr
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.