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

GPIO configuration and service functions. More...

#include <stdbool.h>
#include <stdint.h>
#include <avr/io.h>
#include <avr/wdt.h>
#include <util/delay.h>
#include "gpio.h"
Include dependency graph for gpio.c:

Functions

void init_gpio_module (const struct gpio_mapping *const mappings, const uint8_t mappings_size)
 
void configure_gpio_pin (const struct gpio_pin *const pin, const enum gpio_type type)
 Configures a GPIO pin. More...
 
bool poll_gpio_input (const struct gpio_pin pin, const enum gpio_type type)
 Polls a GPIO input pin. More...
 
enum gpio_input_event poll_gpio_input_timeout (const struct gpio_pin pin, const enum gpio_type type, uint8_t timeout)
 Polls a GPIO input pin with timeout. More...
 

Variables

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

Detailed Description

GPIO configuration and service functions.

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

◆ init_gpio_module()

void init_gpio_module ( const struct gpio_mapping *const  mappings,
const uint8_t  mappings_size 
)

◆ 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