Abstract GPIO wrapper class for usage with C++. Derived classes implement the pin access for a specific library (wiringPi or lgpio).
More...
#include <GPIO.h>
|
| enum | DIRECTION { GPIO_IN
, GPIO_OUT
} |
| |
| enum | VALUE { GPIO_LOW = 0
, GPIO_HIGH = 1
} |
| |
| enum | EDGE { GPIO_NONE
, GPIO_RISING
, GPIO_FALLING
, GPIO_BOTH
} |
| |
Abstract GPIO wrapper class for usage with C++. Derived classes implement the pin access for a specific library (wiringPi or lgpio).
◆ DIRECTION
This enumeration sets up the pin to either be an input or an output pin.
◆ EDGE
This enumeration is used to define whether an ISR is fired based on transitions in pin values.
◆ VALUE
This enumeration defines the values on the pin as being either high or low.
◆ GPIO()
| SWE4211RPi::GPIO::GPIO |
( |
| ) |
|
This is the default constructor. Pin setup is done by the derived class constructor.
◆ ~GPIO()
| SWE4211RPi::GPIO::~GPIO |
( |
| ) |
|
|
virtual |
This is the destructor. Any pin cleanup is done by the derived class destructor.
◆ callBackThreadHandler()
| void SWE4211RPi::GPIO::callBackThreadHandler |
( |
| ) |
|
|
virtual |
This method is the body of the callback thread started by setCallbackMethod(). It should never be invoked from outside of the class. In essence, it will loop so long as the callback method is not NULL, waiting for an edge and then invoking the callback method.
◆ disableEdgeInterrupt()
| virtual void SWE4211RPi::GPIO::disableEdgeInterrupt |
( |
| ) |
|
|
pure virtual |
◆ enableEdgeInterrupt()
| virtual void SWE4211RPi::GPIO::enableEdgeInterrupt |
( |
EDGE |
edgeType | ) |
|
|
pure virtual |
This method will enable an interrupt to be processed based upon edges. In doing this, callbacks can be made based upon the GPIO pin changing state and methods can block for IO purposes.
- Parameters
-
| edgeType | This is the edge type that is to be processed as an interrupt. |
Implemented in SWE4211RPi::WiringPiGPIO.
◆ freeInstance()
| void SWE4211RPi::GPIO::freeInstance |
( |
GPIO & |
instance | ) |
|
|
static |
This method releases a reference obtained from getInstance(). The behavior when the last reference is released depends on the library selected in GPIOcfg.h.
- Parameters
-
| instance | This is the instance that is to be released. |
This method releases a reference obtained from getInstance(). With lgpio, the reference count is decremented and the instance is deleted when it reaches zero. With wiringPi, this method currently does nothing.
- Parameters
-
| instance | This is the instance that is to be released. |
◆ getFallingISRTimestamp()
| struct timespec SWE4211RPi::GPIO::getFallingISRTimestamp |
( |
| ) |
|
|
virtual |
This method will obtain the timestamp from the last time the pin transitioned low.
- Returns
- The timestamp of the transition will be returned.
◆ getInstance()
This method returns the GPIO instance for the given pin. If an instance already exists for the pin, its reference count is incremented and the existing instance is returned (the dir and value parameters are ignored in that case). Otherwise a new instance of the library-specific class selected in GPIOcfg.h is created.
- Parameters
-
| number | This is the Raspberry Pi GPIO number, from 0 to NUMBER_OF_GPIO_PINS. |
| dir | This is the direction for the pin, either input or output. |
| vale | This is the initial value for an output pin. |
- Returns
- A reference to the GPIO instance for the pin.
This method returns the GPIO instance for the given pin. If an instance already exists for the pin, its reference count is incremented and the existing instance is returned (the dir and value parameters are ignored in that case). Otherwise a new instance of the library-specific class selected in GPIOcfg.h is created.
- Parameters
-
| number | This is the Raspberry Pi GPIO number, from 0 to NUMBER_OF_GPIO_PINS. |
| dir | This is the direction for the pin, either input or output. |
| value | This is the initial value for an output pin. |
- Returns
- A reference to the GPIO instance for the pin.
◆ getPinNumber()
| int SWE4211RPi::GPIO::getPinNumber |
( |
| ) |
|
|
virtual |
This method will obtain the GPIO Pin number associated with this instance of the GPIO class.
- Returns
- The unique pin number identifying the pin will be returned.
◆ getRisingISRTimestamp()
| struct timespec SWE4211RPi::GPIO::getRisingISRTimestamp |
( |
| ) |
|
|
virtual |
This method will obtain the timestamp from the last time the pin transitioned high.
- Returns
- The timestamp of the transition will be returned.
◆ getValue()
This method will return the current state of this GPIO pin.
- Returns
- The return will be high or low depending on the state of the pin.
Implemented in SWE4211RPi::WiringPiGPIO.
◆ handleInterruptDrivenGPIOPin()
| virtual void SWE4211RPi::GPIO::handleInterruptDrivenGPIOPin |
( |
| ) |
|
|
pure virtual |
This method will be invoked if an interrupt is enabled whenever a transition in pin value occurs.
Implemented in SWE4211RPi::WiringPiGPIO.
◆ setCallbackMethod()
| void SWE4211RPi::GPIO::setCallbackMethod |
( |
CallbackType |
methodCallback | ) |
|
|
virtual |
This method will set the callback handler. If this is NULL, no method will be invoked. However, if it is non-NULL and the class triggers on edges, the method described here will be called when an edge transition occurs. The first time a non-NULL callback is set, a new thread is started to make the callbacks. Setting the callback back to NULL causes that thread to exit after the next edge.
- Parameters
-
| methodCallback | This is a function pointer that is to be used on the callback. |
This method will set the callback handler. If this is NULL, no method will be invoked. However, if it is non-NULL and the class triggers on edges, the method described here will be called when an edge transition occurs.
- Parameters
-
| methodCallback | This is a function pointer that is to be used on the callback. |
◆ setValue()
| virtual void SWE4211RPi::GPIO::setValue |
( |
GPIO::VALUE |
value | ) |
|
|
pure virtual |
This method will drive an output pin to the appropriate value.
- Parameters
-
| value | This is the value that is to be written to the pin. |
Implemented in SWE4211RPi::WiringPiGPIO.
◆ waitForEdge()
| int SWE4211RPi::GPIO::waitForEdge |
( |
int |
maxWait | ) |
|
|
virtual |
This method will block the calling thread for up to maxWait ms unless an edge occurs. Note that this should only be called by one thread at a time, as multiple invocations will result in non-deterministic behavior. Edge interrupts must be enabled with enableEdgeInterrupt() for an edge to be detected.
- Parameters
-
| maxWait | This is the maximum blocked period in ms. |
- Returns
- 0 if the edge occurred or -1 if a timeout occurred.
This method will block the calling thread for up to maxWait ms unless an edge occurs.
- Parameters
-
| maxWait | This is the maximum blocked period in ms. |
- Returns
- 0 if the edge occurred or -1 if a timeout occurred.
◆ ccv
| std::condition_variable SWE4211RPi::GPIO::ccv |
|
protected |
This condition variable is notified on each edge. It is used to wake the callback thread so that it can invoke the callback method.
◆ cv
| std::condition_variable SWE4211RPi::GPIO::cv |
|
protected |
This condition variable is notified on each edge. It is used to wake a thread blocked in waitForEdge().
◆ gpio_instances
| GPIO * SWE4211RPi::GPIO::gpio_instances |
|
static |
This static variable keeps track of the GPIO instances as they are instantiated. It is used to ensure that we can reference a given instance based upon the GPIO number of the given pin.
◆ instanceCount
| int SWE4211RPi::GPIO::instanceCount = 0 |
|
protected |
◆ isrFallingTimestamp
| struct timespec SWE4211RPi::GPIO::isrFallingTimestamp |
|
protected |
This is a timestamp marked when a falling edge is detected within the system, if the system is setup to handle edges.
◆ isrRisingTimestamp
| struct timespec SWE4211RPi::GPIO::isrRisingTimestamp |
|
protected |
This is a timestamp marked when a rising edge is detected within the system, if the system is setup to handle edges.
◆ methodCallback
This is a callback variable that is used to invoke a method when a transition in the GPIO value occurs.
◆ mtx
| std::mutex SWE4211RPi::GPIO::mtx |
|
protected |
This is a mutex that is used to protect critical resources within this class.
◆ number
| int SWE4211RPi::GPIO::number =0 |
|
protected |
This is the GPIO pin number for the given pin.
◆ threadInstances
This static variable holds thread diagnostic information for the thread that services edge interrupts on each pin. An entry is created the first time an interrupt fires on the given pin, so that the interrupt thread appears in the thread diagnostic printout.
This static variable holds thread diagnostic information for the interrupt thread of each pin.
The documentation for this class was generated from the following files:
- /media/sf_lwshare/20262027SWE4211AllLabSolutions/Lab11/solution/pi/src/gpio/provided/GPIO.h
- /media/sf_lwshare/20262027SWE4211AllLabSolutions/Lab11/solution/pi/src/gpio/provided/GPIO.cpp