General Purpose I/O control. More...
General Purpose I/O control.
peripheral control over a single GPIO
Button Input (with internal Pullup resistor)
Output Example (perfect for blinking an LED)
#include <gpio.h>
Classes | |
struct | Config |
Configuration for a given GPIO. More... | |
Public Types | |
enum class | Mode { INPUT , OUTPUT , OPEN_DRAIN , ANALOG } |
Mode of operation for the specified GPIO. More... | |
enum class | Pull { NOPULL , PULLUP , PULLDOWN } |
Configures whether an internal Pull up or Pull down resistor is used. More... | |
enum class | Speed { LOW , MEDIUM , HIGH , VERY_HIGH } |
Output speed controls the drive strength, and slew rate of the pin. More... | |
Public Member Functions | |
GPIO () | |
void | Init () |
Initialize the GPIO using the internal Config struct. | |
void | Init (const Config &cfg) |
Initialize the GPIO from a Config struct. | |
void | Init (Pin p, const Config &cfg) |
Initialize the GPIO with a Configuration struct, and explicit pin. | |
void | Init (Pin p, Mode m=Mode::INPUT, Pull pu=Pull::NOPULL, Speed sp=Speed::LOW) |
Explicity initialize all configuration for the GPIO. | |
void | DeInit () |
Deinitializes the GPIO pin. | |
bool | Read () |
Reads the state of the GPIO. | |
void | Write (bool state) |
Changes the state of the GPIO hardware when configured as an OUTPUT. | |
void | Toggle () |
flips the current state of the GPIO. If it was HIGH, it will go LOW, and vice versa. | |
Config & | GetConfig () |
|
strong |
Mode of operation for the specified GPIO.
Enumerator | |
---|---|
INPUT | Input for reading state of pin |
OUTPUT | Output w/ push-pull configuration |
OPEN_DRAIN | Output w/ open-drain configuration |
ANALOG | Analog for connection to ADC or DAC peripheral |
|
strong |
Configures whether an internal Pull up or Pull down resistor is used.
Internal Pull up/down resistors are typically 40k ohms, and will be between 30k and 50k
When the Pin is configured in Analog mode, the pull up/down resistors are disabled by hardware.
Enumerator | |
---|---|
NOPULL | No pull up resistor |
PULLUP | Internal pull up enabled |
PULLDOWN | Internal pull down enabled |
|
strong |
|
inline |
Initialize the GPIO with a Configuration struct, and explicit pin.
p | Pin specifying the physical connection on the hardware |
cfg | reference to a Config struct populated with the desired settings. Config::pin will be overwritten |
void daisy::GPIO::Init | ( | Pin | p, |
Mode | m = Mode::INPUT , |
||
Pull | pu = Pull::NOPULL , |
||
Speed | sp = Speed::LOW |
||
) |
Explicity initialize all configuration for the GPIO.
p | Pin specifying the physical connection on the hardware |
m | Mode specifying the behavior of the GPIO (input, output, etc.). Defaults to Mode::INPUT |
pu | Pull up/down state for the GPIO. Defaults to Pull::NOPULL |
sp | Speed setting for drive strength/slew rate. Defaults to Speed::Slow |
bool daisy::GPIO::Read | ( | ) |
void daisy::GPIO::Toggle | ( | ) |
flips the current state of the GPIO. If it was HIGH, it will go LOW, and vice versa.
Changes the state of the GPIO hardware when configured as an OUTPUT.
state | setting true writes an output HIGH, while setting false writes an output LOW. |