libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
gpio.h
Go to the documentation of this file.
1/** @defgroup gpio_defines GPIO Defines
2
3@brief <b>Defined Constants and Types for the LPC17xx General Purpose I/O</b>
4
5@ingroup LPC17xx_defines
6
7@version 1.0.0
8
9@author @htmlonly &copy; @endhtmlonly 2009 Uwe Hermann <uwe@hermann-uwe.de>
10
11@date 10 March 2013
12
13LGPL License Terms @ref lgpl_license
14 */
15/*
16 * This file is part of the libopencm3 project.
17 *
18 * Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
19 *
20 * This library is free software: you can redistribute it and/or modify
21 * it under the terms of the GNU Lesser General Public License as published by
22 * the Free Software Foundation, either version 3 of the License, or
23 * (at your option) any later version.
24 *
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public License
31 * along with this library. If not, see <http://www.gnu.org/licenses/>.
32 */
33
34#ifndef LPC17XX_GPIO_H
35#define LPC17XX_GPIO_H
36
37/**@{*/
38
41
42/* --- Convenience macros -------------------------------------------------- */
43
44/* GPIO port base addresses (for convenience) */
45#define GPIO0 GPIO_PIO0_BASE
46#define GPIO1 GPIO_PIO1_BASE
47#define GPIO2 GPIO_PIO2_BASE
48#define GPIO3 GPIO_PIO3_BASE
49#define GPIO4 GPIO_PIO4_BASE
50
51/* GPIO number definitions (for convenience) */
52#define GPIOPIN0 (1 << 0)
53#define GPIOPIN1 (1 << 1)
54#define GPIOPIN2 (1 << 2)
55#define GPIOPIN3 (1 << 3)
56#define GPIOPIN4 (1 << 4)
57#define GPIOPIN5 (1 << 5)
58#define GPIOPIN6 (1 << 6)
59#define GPIOPIN7 (1 << 7)
60#define GPIOPIN8 (1 << 8)
61#define GPIOPIN9 (1 << 9)
62#define GPIOPIN10 (1 << 10)
63#define GPIOPIN11 (1 << 11)
64#define GPIOPIN12 (1 << 12)
65#define GPIOPIN13 (1 << 13)
66#define GPIOPIN14 (1 << 14)
67#define GPIOPIN15 (1 << 15)
68#define GPIOPIN16 (1 << 16)
69#define GPIOPIN17 (1 << 17)
70#define GPIOPIN18 (1 << 18)
71#define GPIOPIN19 (1 << 19)
72#define GPIOPIN20 (1 << 20)
73#define GPIOPIN21 (1 << 21)
74#define GPIOPIN22 (1 << 22)
75#define GPIOPIN23 (1 << 23)
76#define GPIOPIN24 (1 << 24)
77#define GPIOPIN25 (1 << 25)
78#define GPIOPIN26 (1 << 26)
79#define GPIOPIN27 (1 << 27)
80#define GPIOPIN28 (1 << 28)
81#define GPIOPIN29 (1 << 29)
82#define GPIOPIN30 (1 << 30)
83#define GPIOPIN31 (1 << 31)
84
85/* --- GPIO registers ------------------------------------------------------ */
86
87/* GPIO data direction register (GPIOn_DIR) */
88#define GPIO_DIR(port) MMIO32((port) + 0x00)
89#define GPIO0_DIR GPIO_DIR(GPIO0)
90#define GPIO1_DIR GPIO_DIR(GPIO1)
91#define GPIO2_DIR GPIO_DIR(GPIO2)
92#define GPIO3_DIR GPIO_DIR(GPIO3)
93#define GPIO4_DIR GPIO_DIR(GPIO4)
94
95/* GPIO fast mask register (GPIOn_DIR) */
96#define GPIO_MASK(port) MMIO32((port) + 0x10)
97#define GPIO0_MASK GPIO_MASK(GPIO0)
98#define GPIO1_MASK GPIO_MASK(GPIO1)
99#define GPIO2_MASK GPIO_MASK(GPIO2)
100#define GPIO3_MASK GPIO_MASK(GPIO3)
101#define GPIO4_MASK GPIO_MASK(GPIO4)
102
103/* GPIO port pin value register (GPIOn_PIN) */
104#define GPIO_PIN(port) MMIO32((port) + 0x14)
105#define GPIO0_PIN GPIO_PIN(GPIO0)
106#define GPIO1_PIN GPIO_PIN(GPIO1)
107#define GPIO2_PIN GPIO_PIN(GPIO2)
108#define GPIO3_PIN GPIO_PIN(GPIO3)
109#define GPIO4_PIN GPIO_PIN(GPIO4)
110
111/* GPIO port output set register (GPIOn_SET) */
112#define GPIO_SET(port) MMIO32((port) + 0x18)
113#define GPIO0_SET GPIO_SET(GPIO0)
114#define GPIO1_SET GPIO_SET(GPIO1)
115#define GPIO2_SET GPIO_SET(GPIO2)
116#define GPIO3_SET GPIO_SET(GPIO3)
117#define GPIO4_SET GPIO_SET(GPIO4)
118
119/* GPIO port output clear register (GPIOn_CLR) */
120#define GPIO_CLR(port) MMIO32((port) + 0x1C)
121#define GPIO0_CLR GPIO_CLR(GPIO0)
122#define GPIO1_CLR GPIO_CLR(GPIO1)
123#define GPIO2_CLR GPIO_CLR(GPIO2)
124#define GPIO3_CLR GPIO_CLR(GPIO3)
125#define GPIO4_CLR GPIO_CLR(GPIO4)
126
127/* GPIO interrupt register map */
128/* Interrupt enable rising edge */
129#define GPIO0_IER MMIO32(GPIOINTERRUPT_BASE + 0x90)
130#define GPIO2_IER MMIO32(GPIOINTERRUPT_BASE + 0xB0)
131
132/* Interrupt enable falling edge */
133#define GPIO0_IEF MMIO32(GPIOINTERRUPT_BASE + 0x94)
134#define GPIO2_IEF MMIO32(GPIOINTERRUPT_BASE + 0xB4)
135
136/* Interrupt status rising edge */
137#define GPIO0_ISR MMIO32(GPIOINTERRUPT_BASE + 0x84)
138#define GPIO2_ISR MMIO32(GPIOINTERRUPT_BASE + 0xA4)
139
140/* Interrupt status falling edge */
141#define GPIO0_ISF MMIO32(GPIOINTERRUPT_BASE + 0x88)
142#define GPIO2_ISF MMIO32(GPIOINTERRUPT_BASE + 0xA8)
143
144/* Interrupt clear */
145#define GPIO0_IC MMIO32(GPIOINTERRUPT_BASE + 0x8C)
146#define GPIO1_IC MMIO32(GPIOINTERRUPT_BASE + 0xAC)
147
148/* Overall interrupt status */
149#define GPIO_IS MMIO32(GPIOINTERRUPT_BASE + 0x80)
150
152
153void gpio_set(uint32_t gpioport, uint32_t gpios);
154void gpio_clear(uint32_t gpioport, uint32_t gpios);
155
157
158/**@}*/
159
160#endif
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
void gpio_set(uint32_t gpioport, uint32_t gpios)
Definition: gpio.c:37
void gpio_clear(uint32_t gpioport, uint32_t gpios)
Definition: gpio.c:42