Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures 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  if (port == 0)
78  IO0DIR |= gpios;
79  else if (port == 1)
80  IO1DIR |= gpios;
81 }
82 
88 static inline void gpio_setup_input(uint32_t port, uint32_t gpios) {
89  if (port == 0)
90  IO0DIR &= ~gpios;
91  else if (port == 1)
92  IO1DIR &= ~gpios;
93 }
94 
100 static inline void gpio_set(uint32_t port, uint32_t gpios) {
101  if (port == 0)
102  IO0SET = gpios;
103  else if (port == 1)
104  IO1SET = gpios;
105 }
106 
112 static inline void gpio_clear(uint32_t port, uint32_t gpios) {
113  if (port == 0)
114  IO0CLR = gpios;
115  else if (port == 1)
116  IO1CLR = gpios;
117 }
118 
124 static inline void gpio_toggle(uint32_t port, uint32_t gpios) {
125  if (port == 0) {
126  uint32_t set_gpios = IO0PIN;
127  // clear selected gpio pins which are currently set
128  IO0CLR = set_gpios & gpios;
129  // set selected gpio pins which are currently cleared
130  IO0SET = ~set_gpios & gpios;
131  }
132  else if (port == 1) {
133  uint32_t set_gpios = IO1PIN;
134  // clear selected gpio pins which are currently set
135  IO1CLR = set_gpios & gpios;
136  // set selected gpio pins which are currently cleared
137  IO1SET = ~set_gpios & gpios;
138  }
139 }
140 
146 static inline uint32_t gpio_get(uint32_t port, uint32_t gpios) {
147  if (port == 0) {
148  return IO0PIN & gpios;
149  }
150  else if (port == 1) {
151  return IO1PIN & gpios;
152  }
153 }
154 
155 #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:124
static void gpio_set(uint32_t port, uint32_t gpios)
Set one or more pins of the given GPIO port to high level.
Definition: gpio_arch.h:100
static void gpio_clear(uint32_t port, uint32_t gpios)
Clear one or more pins of the given GPIO port to low level.
Definition: gpio_arch.h:112
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
static uint32_t gpio_get(uint32_t port, uint32_t gpios)
Read the value of one or more pins of the given GPIO port.
Definition: gpio_arch.h:146
static void gpio_setup_output(uint32_t port, uint32_t gpios)
Setup one or more pins of the given GPIO port as outputs.
Definition: gpio_arch.h:76
#define IO1CLR
Definition: LPC21xx.h:340
static void gpio_setup_input(uint32_t port, uint32_t gpios)
Setup one or more pins of the given GPIO port as inputs.
Definition: gpio_arch.h:88
#define IO0PIN
Definition: LPC21xx.h:333
#define IO1DIR
Definition: LPC21xx.h:339