Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
gpio_arch.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Felix Ruess <felix.ruess@gmail.com>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
28 #ifndef GPIO_ARCH_H
29 #define GPIO_ARCH_H
30 
31 #include "std.h"
32 #include "LPC21xx.h"
33 
35 
36 #define GPIOA 0
37 #define GPIOB 1
38 
39 #define GPIO0 (1 << 0)
40 #define GPIO1 (1 << 1)
41 #define GPIO2 (1 << 2)
42 #define GPIO3 (1 << 3)
43 #define GPIO4 (1 << 4)
44 #define GPIO5 (1 << 5)
45 #define GPIO6 (1 << 6)
46 #define GPIO7 (1 << 7)
47 #define GPIO8 (1 << 8)
48 #define GPIO9 (1 << 9)
49 #define GPIO10 (1 << 10)
50 #define GPIO11 (1 << 11)
51 #define GPIO12 (1 << 12)
52 #define GPIO13 (1 << 13)
53 #define GPIO14 (1 << 14)
54 #define GPIO15 (1 << 15)
55 #define GPIO16 (1 << 16)
56 #define GPIO17 (1 << 17)
57 #define GPIO18 (1 << 18)
58 #define GPIO19 (1 << 19)
59 #define GPIO20 (1 << 20)
60 #define GPIO21 (1 << 21)
61 #define GPIO22 (1 << 22)
62 #define GPIO23 (1 << 23)
63 #define GPIO24 (1 << 24)
64 #define GPIO25 (1 << 25)
65 #define GPIO26 (1 << 26)
66 #define GPIO27 (1 << 27)
67 #define GPIO28 (1 << 28)
68 #define GPIO29 (1 << 29)
69 #define GPIO30 (1 << 30)
70 #define GPIO31 (1 << 31)
71 
72 
78 static inline void gpio_setup_output(gpio_port_t port, uint32_t gpios)
79 {
80  if (port == 0) {
81  IO0DIR |= gpios;
82  } else if (port == 1) {
83  IO1DIR |= gpios;
84  }
85 }
86 
92 static inline void gpio_setup_input(gpio_port_t port, uint32_t gpios)
93 {
94  if (port == 0) {
95  IO0DIR &= ~gpios;
96  } else if (port == 1) {
97  IO1DIR &= ~gpios;
98  }
99 }
100 
106 static inline void gpio_set(gpio_port_t port, uint32_t gpios)
107 {
108  if (port == 0) {
109  IO0SET = gpios;
110  } else if (port == 1) {
111  IO1SET = gpios;
112  }
113 }
114 
120 static inline void gpio_clear(gpio_port_t port, uint32_t gpios)
121 {
122  if (port == 0) {
123  IO0CLR = gpios;
124  } else if (port == 1) {
125  IO1CLR = gpios;
126  }
127 }
128 
134 static inline void gpio_toggle(gpio_port_t port, uint32_t gpios)
135 {
136  if (port == 0) {
137  uint32_t set_gpios = IO0PIN;
138  // clear selected gpio pins which are currently set
139  IO0CLR = set_gpios & gpios;
140  // set selected gpio pins which are currently cleared
141  IO0SET = ~set_gpios & gpios;
142  } else if (port == 1) {
143  uint32_t set_gpios = IO1PIN;
144  // clear selected gpio pins which are currently set
145  IO1CLR = set_gpios & gpios;
146  // set selected gpio pins which are currently cleared
147  IO1SET = ~set_gpios & gpios;
148  }
149 }
150 
156 static inline uint32_t gpio_get(gpio_port_t port, uint32_t gpios)
157 {
158  if (port == 0) {
159  return IO0PIN & gpios;
160  } else if (port == 1) {
161  return IO1PIN & gpios;
162  }
163 }
164 
165 #endif /* GPIO_ARCH_H */
LPC21xx.h
uint32_t
unsigned long uint32_t
Definition: types.h:18
gpio_set
void gpio_set(uint32_t port, uint16_t pin)
Set a gpio output to high level.
Definition: gpio_arch.c:35
std.h
gpio_clear
void gpio_clear(uint32_t port, uint16_t pin)
Clear a gpio output to low level.
Definition: gpio_arch.c:37
gpio_setup_input
void gpio_setup_input(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as inputs.
Definition: gpio_arch.c:40
IO0DIR
#define IO0DIR
Definition: LPC21xx.h:335
gpio_get
uint16_t gpio_get(uint32_t gpioport, uint16_t gpios)
Read a gpio value.
Definition: gpio_arch.c:39
IO0CLR
#define IO0CLR
Definition: LPC21xx.h:336
IO1CLR
#define IO1CLR
Definition: LPC21xx.h:340
IO1PIN
#define IO1PIN
Definition: LPC21xx.h:337
gpio_setup_output
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
Definition: gpio_arch.c:33
IO0SET
#define IO0SET
Definition: LPC21xx.h:334
IO0PIN
#define IO0PIN
Definition: LPC21xx.h:333
IO1SET
#define IO1SET
Definition: LPC21xx.h:338
gpio_toggle
static void gpio_toggle(gpio_port_t port, uint32_t gpios)
Toggle a one or more pins of the given GPIO port.
Definition: gpio_arch.h:134
IO1DIR
#define IO1DIR
Definition: LPC21xx.h:339
gpio_port_t
ioportid_t gpio_port_t
Abstract gpio port type for hardware independent part.
Definition: gpio_arch.h:39