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>
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... | |
GPIO configuration and service functions.
enum gpio_input_event |
Possible GPIO input events.
enum gpio_type |
Function / type of a GPIO pin.
Configures a GPIO pin.
pin | the GPIO pin to configure |
type | the desired function / type of the pin |
|
inlinestatic |
Enables a GPIO output pin.
pin | the GPIO pin |
|
inlinestatic |
Disables a GPIO output pin.
pin | the GPIO pin |
|
inlinestatic |
Reads the state of a GPIO input pin.
pin | the GPIO pin |
true
if the input pin is driven high; false
otherwise
|
inlinestatic |
Sets a GPIO output pin to the specified state.
pin | the GPIO pin |
value | true enables the output; false disables it |
|
inlinestatic |
Toggles a GPIO output pin.
pin |
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.
mappings | an array of pin type mappings or NULL |
mappings_size | number of elements in the type mappings array or 0 |
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.