uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
gpio.h
Go to the documentation of this file.
1 
4 /*
5  * Copyright 2012-2015 Sebastian Neuser
6  *
7  * This file is part of the uMIDI firmware.
8  *
9  * The uMIDI firmware is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * The uMIDI firmware is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with the uMIDI firmware. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef _GPIO_H
24 #define _GPIO_H
25 
26 
27 //---------------- includes ----------------//
28 #include <stdbool.h>
29 #include <stdint.h>
30 #include <avr/io.h>
31 
32 
33 //---------------- data types ----------------//
34 
38 {
42 };
43 
46 {
52 };
54 
57 struct gpio_pin
58 {
59  PORT_t* port;
60  uint8_t bit;
62 };
63 
66 {
67  const struct gpio_pin* pin;
68  enum gpio_type type;
69 };
70 
74 {
75  const struct gpio_pin pin2;
76  const struct gpio_pin pin3;
77  const struct gpio_pin pin4;
78  const struct gpio_pin pin5;
79  const struct gpio_pin pin6;
80  const struct gpio_pin pin7;
81  const struct gpio_pin pin8;
82  const struct gpio_pin pin9;
83 };
84 
86 struct jumpers
87 {
88  const struct gpio_pin jp2;
89  const struct gpio_pin jp3;
90  const struct gpio_pin jp4;
91  const struct gpio_pin jp5;
92 };
93 
95 struct gpio
96 {
97  const struct gpio_header header1;
98  const struct gpio_header header2;
99  const struct gpio_header header3;
100  const struct jumpers jumpers;
101 };
102 
103 
104 //---------------- public global variables ----------------//
114 extern const struct gpio gpio;
115 
116 
117 //---------------- functions and procedures ----------------//
118 
124 void configure_gpio_pin(const struct gpio_pin* pin, enum gpio_type type);
125 
133 void init_gpio_module(const struct gpio_mapping mappings[], uint8_t mappings_size);
134 
144 bool poll_gpio_input(const struct gpio_pin pin, enum gpio_type type);
145 
162 enum gpio_input_event poll_gpio_input_timeout(const struct gpio_pin pin, enum gpio_type type, uint8_t timeout);
163 
164 
165 //---------------- inline functions and procedures ----------------//
166 
170 static inline void gpio_drive_high(const struct gpio_pin pin) {
171  pin.port->OUT |= _BV(pin.bit);
172 }
173 
177 static inline void gpio_drive_low(const struct gpio_pin pin) {
178  pin.port->OUT &=~ _BV(pin.bit);
179 }
180 
185 static inline bool gpio_get(const struct gpio_pin pin) {
186  return pin.port->IN & _BV(pin.bit);
187 }
188 
194 static inline void gpio_set(const struct gpio_pin pin, bool value) {
195  value ? gpio_drive_high(pin) : gpio_drive_low(pin);
196 }
197 
200 static inline void gpio_toggle(const struct gpio_pin pin) {
201  pin.port->OUT ^= _BV(pin.bit);
202 }
203 
204 
205 //---------------- EOF ----------------//
206 #endif // _GPIO_H
207 
void configure_gpio_pin(const struct gpio_pin *pin, enum gpio_type type)
Configures a GPIO pin.
Definition: gpio.c:107
static void gpio_drive_high(const struct gpio_pin pin)
Enables a GPIO output pin.
Definition: gpio.h:170
The GPIO pin acts as an output.
Definition: gpio.h:50
Nothing happened :-(.
Definition: gpio.h:39
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.
Definition: gpio.c:139
This struct represents the four solder jumpers on the bottom side of the PCB.
Definition: gpio.h:86
static void gpio_toggle(const struct gpio_pin pin)
Toggles a GPIO output pin.
Definition: gpio.h:200
Configurations of the GPIO pins contained in one 10-pin header.
Definition: gpio.h:73
PORT_t * port
Definition: gpio.h:59
void init_gpio_module(const struct gpio_mapping mappings[], uint8_t mappings_size)
Initializes the GPIO module.
const struct gpio_pin * pin
GPIO pin to configure.
Definition: gpio.h:67
static void gpio_set(const struct gpio_pin pin, bool value)
Sets a GPIO output pin to the specified state.
Definition: gpio.h:194
Definition: gpio.h:51
static bool gpio_get(const struct gpio_pin pin)
Reads the state of a GPIO input pin.
Definition: gpio.h:185
uint8_t bit
The corresponding bit index in the configuration registers.
Definition: gpio.h:61
gpio_type
Function / type of a GPIO pin.
Definition: gpio.h:45
A GPIO input pin was seen logical "high" for some time.
Definition: gpio.h:41
The GPIO pin acts as an input and is pulled down.
Definition: gpio.h:48
static void gpio_drive_low(const struct gpio_pin pin)
Disables a GPIO output pin.
Definition: gpio.h:177
The GPIO pin acts as an input and is pulled up.
Definition: gpio.h:49
A GPIO input pin was seen logical "high" briefly.
Definition: gpio.h:40
bool poll_gpio_input(const struct gpio_pin pin, enum gpio_type type)
Polls a GPIO input pin.
Definition: gpio.c:134
Configurations for all available GPIO pins.
Definition: gpio.h:95
Configuration of a single GPIO pin.
Definition: gpio.h:57
Maps a GPIO pin to its designated type / function.
Definition: gpio.h:65
The GPIO pin acts as an input.
Definition: gpio.h:47
gpio_input_event
Possible GPIO input events.
Definition: gpio.h:37