discoLight
Loading...
Searching...
No Matches
SWE4211RPi::GPIO Class Referenceabstract

GPIO GPIO wrapper classes for usage with C++ and wiringPi. More...

#include <GPIO.h>

Inheritance diagram for SWE4211RPi::GPIO:
Collaboration diagram for SWE4211RPi::GPIO:

Public Types

enum  DIRECTION { GPIO_IN , GPIO_OUT }
 
enum  VALUE { GPIO_LOW = 0 , GPIO_HIGH = 1 }
 
enum  EDGE { GPIO_NONE , GPIO_RISING , GPIO_FALLING , GPIO_BOTH }
 

Public Member Functions

virtual void setValue (GPIO::VALUE)=0
 
virtual GPIO::VALUE getValue ()=0
 
virtual void enableEdgeInterrupt (EDGE edgeType)=0
 
virtual void disableEdgeInterrupt ()=0
 
virtual int waitForEdge (int maxWait)
 
virtual struct timespec getRisingISRTimestamp ()
 
virtual struct timespec getFallingISRTimestamp ()
 
virtual void setCallbackMethod (CallbackType methodCallback)
 
virtual void callBackThreadHandler ()
 
virtual void handleInterruptDrivenGPIOPin ()=0
 
virtual int getPinNumber ()
 

Static Public Member Functions

static GPIO & getInstance (int number, DIRECTION dir, VALUE vale=GPIO_LOW)
 
static void freeInstance (GPIO &instance)
 

Static Public Attributes

static GPIO * gpio_instances [NUMBER_OF_GPIO_PINS+1]
 
static GenericThreadInfo * threadInstances [NUMBER_OF_GPIO_PINS+1]
 

Protected Attributes

int number =0
 
int instanceCount = 0
 
std::mutex mtx
 
std::condition_variable cv
 
std::condition_variable ccv
 
CallbackType methodCallback =nullptr
 
struct timespec isrRisingTimestamp
 
struct timespec isrFallingTimestamp
 

Detailed Description

GPIO GPIO wrapper classes for usage with C++ and wiringPi.

Member Enumeration Documentation

◆ 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.

Member Function Documentation

◆ callBackThreadHandler()

void SWE4211RPi::GPIO::callBackThreadHandler ( )
virtual

This method is used by the friend method to handle callback methods. It should never be invoked from outside of the class. In essence, what it will do a loop so long as the callback method is not NULL, invoking the callback method whenever an edge transitions.

Here is the caller graph for this function:

◆ disableEdgeInterrupt()

virtual void SWE4211RPi::GPIO::disableEdgeInterrupt ( )
pure virtual

This method will disable the edge interrupt for the given pin.

Implemented in SWE4211RPi::WiringPiGPIO.

◆ 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
edgeTypeThis is the edge type that is to be processed as an interrupt.

Implemented in SWE4211RPi::WiringPiGPIO.

◆ 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.

◆ 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()

virtual GPIO::VALUE SWE4211RPi::GPIO::getValue ( )
pure virtual

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.

Here is the caller graph for this function:

◆ 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.

Here is the caller graph for this function:

◆ 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.

Parameters
methodCallbackThis is a function pointer that is to be used on the callback.
Here is the call graph for this function:

◆ setValue()

virtual void SWE4211RPi::GPIO::setValue ( GPIO::VALUE  )
pure virtual

This method will drive an output pin to the appropriate value.

Parameters
Thisis the value that is to be written to the pin.

Implemented in SWE4211RPi::WiringPiGPIO.

Here is the caller graph for this function:

◆ 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 once at a time, as multiple invocations will result in non-deterministic behavior.

Parameters
maxWaitThis 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
maxWaitThis is the maximum blocked period in ms.
Returns
0 if the edge occurred or -1 if a timeout occurred.

Member Data Documentation

◆ cv

std::condition_variable SWE4211RPi::GPIO::cv
protected

These two condition variables are used internally to allow the invocation of a callback method and a block for edge method.

◆ 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

This is the number of references to the GPIO pin that have been returned.

◆ 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

CallbackType SWE4211RPi::GPIO::methodCallback =nullptr
protected

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.


The documentation for this class was generated from the following files: