The Gpio class allows to interact with the GPIOs. More...
Header: | #include <Gpio> |
Inherits: |
enum | Direction { DirectionInput, DirectionOutput, DirectionInvalid } |
enum | Edge { EdgeFalling, EdgeRising, EdgeBoth, EdgeNone } |
enum | Value { ValueLow, ValueHigh, ValueInvalid } |
Gpio(const int & gpio, QObject * parent = nullptr) | |
~Gpio() | |
bool | activeLow() |
Gpio::Direction | direction() |
Gpio::Edge | edgeInterrupt() |
bool | exportGpio() |
QString | gpioDirectory() const |
int | gpioNumber() const |
bool | setActiveLow(bool activeLow) |
bool | setDirection(Gpio::Direction direction) |
bool | setEdgeInterrupt(Gpio::Edge edge) |
bool | setValue(Gpio::Value value) |
bool | unexportGpio() |
Gpio::Value | value() |
bool | isAvailable() |
The Gpio class allows to interact with the GPIOs.
A "General Purpose Input/Output" (GPIO) is a flexible software-controlled digital signal. They are provided from many kinds of chip, and are familiar to Linux developers working with embedded and custom hardware. Each GPIO represents a bit connected to a particular pin, or "ball" on Ball Grid Array (BGA) packages. Board schematics show which external hardware connects to which GPIOs. Drivers can be written generically, so that board setup code passes such pin configuration data to drivers (source).
General Purpose Input/Output (a.k.a. GPIO) is a generic pin on a chip whose behavior (including whether it is an input or output pin) can be controlled through this class. An object of of the Gpio class represents a pin.
Gpio *gpioOut = new Gpio(23, this); // Export Gpio if (!gpioOut->exportGpio()) { qWarning() << "Could not export Gpio" << gpioOut->gpioNumber(); gpioOut->deleteLater(); return; } // Configure Gpio direction if (!gpioOut->setDirection(PiGpio::DirectionOutput)) { qWarning() << "Could not set direction of Gpio" << gpioOut->gpioNumber(); gpioOut->deleteLater(); return; } gpioOut->setValue(Gpio::ValueHigh)
Gpio *gpioIn = new Gpio(24, this); // Export Gpio if (!gpioIn->exportGpio()) { qWarning() << "Could not export Gpio" << gpioIn->gpioNumber(); gpioIn->deleteLater(); return; } // Configure Gpio direction if (!gpioIn->setDirection(PiGpio::DirectionInput)) { qWarning() << "Could not set direction of Gpio" << gpioIn->gpioNumber(); gpioIn->deleteLater(); return; } qDebug() << "Current value" << (bool)gpioIn->value();
See also GpioMonitor.
This enum type specifies the dirction a Gpio.
Constant | Value | Description |
---|---|---|
Gpio::DirectionInput | 0 | The Gpio is configured as input. |
Gpio::DirectionOutput | 1 | The Gpio is configured as output. |
Gpio::DirectionInvalid | 2 | The direction is not valid. |
This enum type specifies the edge interrupt type of a Gpio.
Constant | Value | Description |
---|---|---|
Gpio::EdgeFalling | 0 | The Gpio reacts on falling edge interrupt. |
Gpio::EdgeRising | 1 | The Gpio reacts on rising edge interrupt. |
Gpio::EdgeBoth | 2 | The Gpio reacts on both, rising and falling edge interrupt. |
Gpio::EdgeNone | 3 | The Gpio does not react on interrupts. |
This enum type specifies the value a Gpio.
Constructs a Gpio object to represent a GPIO with the given gpio number and parent.
Destroys and unexports the Gpio.
Returns true if the logic of this Gpio is inverted (1 = low, 0 = high).
See also setActiveLow().
Returns the direction of this Gpio.
See also setDirection().
Returns the edge interrupt of this Gpio.
See also setEdgeInterrupt().
Returns true if this Gpio could be exported in the system file /sys/class/gpio/export
. If this Gpio is already exported, this function will return true.
Returns the directory /sys/class/gpio/gpio<number>
of this Gpio.
Returns the number of this Gpio.
Note: The Gpio number is mostly not equivalent with the pin number.
[static]
bool Gpio::isAvailable()Returns true if the directories /sys/class/gpio
and /sys/class/gpio/export
do exist.
This method allows to invert the logic of this Gpio. Returns true, if the GPIO could be set activeLow.
See also activeLow().
Returns true if the direction of this GPIO could be set.
See also direction() and Gpio::Direction.
Returns true if the edge of this GPIO could be set correctly. The edge parameter specifies, when an interrupt occurs.
See also edgeInterrupt().
Returns true if the digital value of this Gpio could be set correctly.
See also value().
Returns true if this Gpio could be unexported in the system file /sys/class/gpio/unexport
.
Returns the current digital value of this Gpio.
See also setValue().