uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
|
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"
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... | |
GPIO configuration and service functions.
Configures a GPIO pin.
pin | the GPIO pin to configure |
type | the desired function / type of the pin |
void init_gpio_module | ( | const struct gpio_mapping *const | mappings, |
const uint8_t | mappings_size | ||
) |
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!
pin | the GPIO input pin to poll |
type | the GPIO input type (pull-up or pull-down) |
true
if the input pin reads logical 1 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.
pin | the GPIO input pin to poll |
type | the GPIO input type (pull-up or pull-down) |
timeout | the timeout in [s/10], or 0 for infinity |
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.