uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
Data Structures | Enumerations | Functions | Variables
gpio.h File Reference

GPIO configuration and service functions. More...

#include <stdbool.h>
#include <stdint.h>
#include <avr/io.h>
Include dependency graph for gpio.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  gpio_pin
 Configuration of a single GPIO pin. More...
 
struct  gpio_mapping
 Maps a GPIO pin to its designated type / function. More...
 
struct  gpio_header
 Configurations of the GPIO pins contained in one 10-pin header. More...
 
struct  jumpers
 This struct represents the four solder jumpers on the bottom side of the PCB. More...
 
struct  gpio
 Configurations for all available GPIO pins. More...
 

Enumerations

enum  gpio_input_event { GPIO_INPUT_EVENT_NONE, GPIO_INPUT_EVENT_SHORT, GPIO_INPUT_EVENT_LONG }
 Possible GPIO input events. More...
 
enum  gpio_type {
  GPIO_INPUT, GPIO_INPUT_PULLDOWN, GPIO_INPUT_PULLUP, GPIO_OUTPUT,
  GPIO_UNUSED
}
 Function / type of a GPIO pin. More...
 

Functions

void configure_gpio_pin (const struct gpio_pin *pin, enum gpio_type type)
 Configures a GPIO pin. More...
 
void init_gpio_module (const struct gpio_mapping mappings[], uint8_t mappings_size)
 Initializes the GPIO module. More...
 
bool poll_gpio_input (const struct gpio_pin pin, enum gpio_type type)
 Polls a GPIO input pin. More...
 
enum gpio_input_event poll_gpio_input_timeout (const struct gpio_pin pin, enum gpio_type type, uint8_t timeout)
 Polls a GPIO input pin with timeout. More...
 
static void gpio_drive_high (const struct gpio_pin pin)
 Enables a GPIO output pin. More...
 
static void gpio_drive_low (const struct gpio_pin pin)
 Disables a GPIO output pin. More...
 
static bool gpio_get (const struct gpio_pin pin)
 Reads the state of a GPIO input pin. More...
 
static void gpio_set (const struct gpio_pin pin, bool value)
 Sets a GPIO output pin to the specified state. More...
 
static void gpio_toggle (const struct gpio_pin pin)
 Toggles a GPIO output pin. More...
 

Variables

const struct gpio gpio
 A global structure with all available GPIO pins. More...
 

Detailed Description

GPIO configuration and service functions.

Enumeration Type Documentation

◆ gpio_input_event

Possible GPIO input events.

See also
poll_gpio_input_timeout
Enumerator
GPIO_INPUT_EVENT_NONE 

Nothing happened :-(.

GPIO_INPUT_EVENT_SHORT 

A GPIO input pin was seen logical "high" briefly.

GPIO_INPUT_EVENT_LONG 

A GPIO input pin was seen logical "high" for some time.

◆ gpio_type

enum gpio_type

Function / type of a GPIO pin.

Enumerator
GPIO_INPUT 

The GPIO pin acts as an input.

GPIO_INPUT_PULLDOWN 

The GPIO pin acts as an input and is pulled down.

GPIO_INPUT_PULLUP 

The GPIO pin acts as an input and is pulled up.

GPIO_OUTPUT 

The GPIO pin acts as an output.

GPIO_UNUSED 

The GPIO pin is not used Unused pins are configured as inputs with pull-down

Function Documentation

◆ configure_gpio_pin()

void configure_gpio_pin ( const struct gpio_pin pin,
enum gpio_type  type 
)

Configures a GPIO pin.

Parameters
pinthe GPIO pin to configure
typethe desired function / type of the pin

◆ gpio_drive_high()

static void gpio_drive_high ( const struct gpio_pin  pin)
inlinestatic

Enables a GPIO output pin.

Parameters
pinthe GPIO pin

◆ gpio_drive_low()

static void gpio_drive_low ( const struct gpio_pin  pin)
inlinestatic

Disables a GPIO output pin.

Parameters
pinthe GPIO pin

◆ gpio_get()

static bool gpio_get ( const struct gpio_pin  pin)
inlinestatic

Reads the state of a GPIO input pin.

Parameters
pinthe GPIO pin
Returns
true if the input pin is driven high; false otherwise

◆ gpio_set()

static void gpio_set ( const struct gpio_pin  pin,
bool  value 
)
inlinestatic

Sets a GPIO output pin to the specified state.

Parameters
pinthe GPIO pin
valuetrue enables the output; false disables it

◆ gpio_toggle()

static void gpio_toggle ( const struct gpio_pin  pin)
inlinestatic

Toggles a GPIO output pin.

Parameters
pin

◆ init_gpio_module()

void init_gpio_module ( const struct gpio_mapping  mappings[],
uint8_t  mappings_size 
)

Initializes the GPIO module.

Configures all available GPIO pins to a standard configuration. If an array of pin type mappings was supplied, those are also applied.

Parameters
mappingsan array of pin type mappings or NULL
mappings_sizenumber of elements in the type mappings array or 0

◆ poll_gpio_input()

bool poll_gpio_input ( const struct gpio_pin  pin,
enum gpio_type  type 
)

Polls a GPIO input pin.

Automatically de-bounces the pin if it is detected as active and returns as soon as the input returns to logical 0. Warning: Uses busy waiting!

Parameters
pinthe GPIO input pin to poll
typethe GPIO input type (pull-up or pull-down)
Returns
true if the input pin reads logical 1
See also
poll_gpio_input_timeout

◆ poll_gpio_input_timeout()

enum gpio_input_event poll_gpio_input_timeout ( const struct gpio_pin  pin,
enum gpio_type  type,
uint8_t  timeout 
)

Polls a GPIO input pin with timeout.

Reads and de-bounces an input pin and measures how long it is in logical high-state continuously. After a given amount of time the function announces the event by returning GPIO_INPUT_EVENT_LONG. If the input pin returns to low before the timeout was reached, GPIO_INPUT_EVENT_SHORT is returned. This function uses busy waiting, so all background tasks are stalled until the timeout is reached. When the timeout is set to zero, this function blocks until the input pin reads logical low again, which is what poll_gpio_input does.

Parameters
pinthe GPIO input pin to poll
typethe GPIO input type (pull-up or pull-down)
timeoutthe timeout in [s/10], or 0 for infinity
Returns
the detected input event or GPIO_INPUT_EVENT_NONE

Variable Documentation

◆ gpio

const struct gpio gpio

A global structure with all available GPIO pins.

This data structure provides a nice way to address GPIO pins. The pins are grouped into three headers with eight pins each and a group for the four solder jumpers - exactly representing the hardware interface. You can use these aliases to configure the pins you need and to get / set the state of the pin.

See also
configure_gpio_pin
init_gpio_module
gpio_get
gpio_set