Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
34 #define GPIOA 0
35 #define GPIOB 1
36 
37 #define GPIO0 (1 << 0)
38 #define GPIO1 (1 << 1)
39 #define GPIO2 (1 << 2)
40 #define GPIO3 (1 << 3)
41 #define GPIO4 (1 << 4)
42 #define GPIO5 (1 << 5)
43 #define GPIO6 (1 << 6)
44 #define GPIO7 (1 << 7)
45 #define GPIO8 (1 << 8)
46 #define GPIO9 (1 << 9)
47 #define GPIO10 (1 << 10)
48 #define GPIO11 (1 << 11)
49 #define GPIO12 (1 << 12)
50 #define GPIO13 (1 << 13)
51 #define GPIO14 (1 << 14)
52 #define GPIO15 (1 << 15)
53 #define GPIO16 (1 << 16)
54 #define GPIO17 (1 << 17)
55 #define GPIO18 (1 << 18)
56 #define GPIO19 (1 << 19)
57 #define GPIO20 (1 << 20)
58 #define GPIO21 (1 << 21)
59 #define GPIO22 (1 << 22)
60 #define GPIO23 (1 << 23)
61 #define GPIO24 (1 << 24)
62 #define GPIO25 (1 << 25)
63 #define GPIO26 (1 << 26)
64 #define GPIO27 (1 << 27)
65 #define GPIO28 (1 << 28)
66 #define GPIO29 (1 << 29)
67 #define GPIO30 (1 << 30)
68 #define GPIO31 (1 << 31)
69 
70 
76 static inline void gpio_setup_output(uint32_t port, uint32_t gpios)
77 {
78  if (port == 0) {
79  IO0DIR |= gpios;
80  } else if (port == 1) {
81  IO1DIR |= gpios;
82  }
83 }
84 
90 static inline void gpio_setup_input(uint32_t port, uint32_t gpios)
91 {
92  if (port == 0) {
93  IO0DIR &= ~gpios;
94  } else if (port == 1) {
95  IO1DIR &= ~gpios;
96  }
97 }
98 
104 static inline void gpio_set(uint32_t port, uint32_t gpios)
105 {
106  if (port == 0) {
107  IO0SET = gpios;
108  } else if (port == 1) {
109  IO1SET = gpios;
110  }
111 }
112 
118 static inline void gpio_clear(uint32_t port, uint32_t gpios)
119 {
120  if (port == 0) {
121  IO0CLR = gpios;
122  } else if (port == 1) {
123  IO1CLR = gpios;
124  }
125 }
126 
132 static inline void gpio_toggle(uint32_t port, uint32_t gpios)
133 {
134  if (port == 0) {
135  uint32_t set_gpios = IO0PIN;
136  // clear selected gpio pins which are currently set
137  IO0CLR = set_gpios & gpios;
138  // set selected gpio pins which are currently cleared
139  IO0SET = ~set_gpios & gpios;
140  } else if (port == 1) {
141  uint32_t set_gpios = IO1PIN;
142  // clear selected gpio pins which are currently set
143  IO1CLR = set_gpios & gpios;
144  // set selected gpio pins which are currently cleared
145  IO1SET = ~set_gpios & gpios;
146  }
147 }
148 
154 static inline uint32_t gpio_get(uint32_t port, uint32_t gpios)
155 {
156  if (port == 0) {
157  return IO0PIN & gpios;
158  } else if (port == 1) {
159  return IO1PIN & gpios;
160  }
161 }
162 
163 #endif /* GPIO_ARCH_H */
#define IO1SET
Definition: LPC21xx.h:338
static void gpio_toggle(uint32_t port, uint32_t gpios)
Toggle a one or more pins of the given GPIO port.
Definition: gpio_arch.h:132
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
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
void gpio_set(uint32_t port, uint16_t pin)
Set a gpio output to high level.
Definition: gpio_ardrone.c:54
void gpio_clear(uint32_t port, uint16_t pin)
Clear a gpio output to low level.
Definition: gpio_ardrone.c:70
unsigned long uint32_t
Definition: types.h:18
#define IO0CLR
Definition: LPC21xx.h:336
#define IO0SET
Definition: LPC21xx.h:334
#define IO0DIR
Definition: LPC21xx.h:335
#define IO1PIN
Definition: LPC21xx.h:337
uint16_t gpio_get(uint32_t gpioport, uint16_t gpios)
Read a gpio value.
Definition: gpio_ardrone.c:120
#define IO1CLR
Definition: LPC21xx.h:340
#define IO0PIN
Definition: LPC21xx.h:333
#define IO1DIR
Definition: LPC21xx.h:339