Skip to content

Class daisy::GPIO

ClassList > daisy > GPIO

General Purpose I/O control. More...

  • #include <gpio.h>

Classes

Type Name
struct Config
Configuration for a given GPIO .

Public Types

Type Name
enum Mode
Mode of operation for the specified GPIO .
enum Pull
Configures whether an internal Pull up or Pull down resistor is used.
enum Speed
Output speed controls the drive strength, and slew rate of the pin.

Public Functions

Type Name
void DeInit ()
Deinitializes the GPIO pin.
GPIO ()
Config & GetConfig ()
void Init ()
Initialize the GPIO using the internalConfig struct.
void Init (const Config & cfg)
Initialize the GPIO from aConfig 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 .
bool Read ()
Reads the state of the GPIO .
void Toggle ()
flips the current state of the GPIO . If it was HIGH, it will go LOW, and vice versa.
void Write (bool state)
Changes the state of the GPIO hardware when configured as an OUTPUT.

Detailed Description

peripheral control over a single GPIO

Button Input (with internal Pullup resistor)


Output Example (perfect for blinking an LED)


Public Types Documentation

enum Mode

Mode of operation for the specified GPIO .

enum daisy::GPIO::Mode {
    INPUT,
    OUTPUT,
    OPEN_DRAIN,
    ANALOG
};


enum Pull

Configures whether an internal Pull up or Pull down resistor is used.

enum daisy::GPIO::Pull {
    NOPULL,
    PULLUP,
    PULLDOWN
};

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.


enum Speed

Output speed controls the drive strength, and slew rate of the pin.

enum daisy::GPIO::Speed {
    LOW,
    MEDIUM,
    HIGH,
    VERY_HIGH
};


Public Functions Documentation

function DeInit

Deinitializes the GPIO pin.

void daisy::GPIO::DeInit () 


function GPIO

inline daisy::GPIO::GPIO () 

function GetConfig

inline Config & daisy::GPIO::GetConfig () 

Return a reference to the internal Config struct


function Init [¼]

Initialize the GPIO using the internalConfig struct.

void daisy::GPIO::Init () 


function Init [2/4]

Initialize the GPIO from aConfig struct.

void daisy::GPIO::Init (
    const  Config & cfg
) 

Parameters:

  • cfg reference to a Config struct populated with the desired settings

function Init [¾]

Initialize the GPIO with a Configuration struct, and explicit pin.

void daisy::GPIO::Init (
    Pin p,
    const  Config & cfg
) 

Parameters:

  • 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

function Init [4/4]

Explicity initialize all configuration for the GPIO .

void daisy::GPIO::Init (
    Pin p,
    Mode m=Mode::INPUT,
    Pull pu=Pull::NOPULL,
    Speed sp=Speed::LOW
) 

Parameters:

  • 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

function Read

Reads the state of the GPIO .

bool daisy::GPIO::Read () 

Returns:

State of the GPIO unless Mode is set to Mode::Analog, then always false


function Toggle

flips the current state of the GPIO . If it was HIGH, it will go LOW, and vice versa.

void daisy::GPIO::Toggle () 


function Write

Changes the state of the GPIO hardware when configured as an OUTPUT.

void daisy::GPIO::Write (
    bool state
) 

Parameters:

  • state setting true writes an output HIGH, while setting false writes an output LOW.


The documentation for this class was generated from the following file external-docs/libDaisy/src/per/gpio.h