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 SWM050 General Purpose I/O</b>
4 *
5 * @ingroup SWM050_defines
6 *
7 * LGPL License Terms @ref lgpl_license
8 */
9/*
10 * This file is part of the libopencm3 project.
11 *
12 * Copyright (C) 2019 Icenowy Zheng <icenowy@aosc.io>
13 * Copyright (C) 2019 Caleb Szalacinski <contact@skiboy.net>
14 *
15 * This library is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public License
26 * along with this library. If not, see <http://www.gnu.org/licenses/>.
27 */
28/**@{*/
29#ifndef LIBOPENCM3_GPIO_H
30#define LIBOPENCM3_GPIO_H
33
34/* GPIO number definitions (for convenience) */
35/** @defgroup gpio_pin_id GPIO Pin Identifiers
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 GPIO_ALL 0x3ff
48/**@}*/
49
50/* GPIO direction definitions */
51/** @defgroup gpio_dir GPIO Pin Direction
52@{*/
56};
57/**@}*/
58
59/* GPIO polarity definitions */
60/** @defgroup gpio_pol GPIO Polarity
61@{*/
65};
66/*@}*/
67
68/* GPIO interrupt trigger definitions */
69/** @defgroup gpio_trig_type GPIO Interrupt Trigger Type
70@{*/
74};
75/*@}*/
76
77/* GPIO interrupt mask definitions */
78/** @defgroup gpio_int_masked GPIO Interrupt Mask
79@{*/
83};
84/*@}*/
85
86/* GPIO Registers */
87/** @defgroup gpio_registers GPIO Registers
88@{*/
89/** Data register */
90#define GPIO_ADATA MMIO32(GPIO_BASE + 0x0)
91/** Direction register */
92#define GPIO_ADIR MMIO32(GPIO_BASE + 0x4)
93/** Interrupt enable register */
94#define GPIO_INTEN_A MMIO32(GPIO_BASE + 0x30)
95/** Interrupt mask register */
96#define GPIO_INTMASK_A MMIO32(GPIO_BASE + 0x34)
97/** Interrupt trigger mode register */
98#define GPIO_INTLEVEL_A MMIO32(GPIO_BASE + 0x38)
99/** Interrupt polarity register */
100#define GPIO_INTPOLARITY_A MMIO32(GPIO_BASE + 0x3c)
101/** Interrupt status after masking */
102#define GPIO_INTSTAT_A MMIO32(GPIO_BASE + 0x40)
103/** Interrupt status before masking */
104#define GPIO_RAWINTSTAT_A MMIO32(GPIO_BASE + 0x44)
105/** Interrupt clear register */
106#define GPIO_INTEOI_A MMIO32(GPIO_BASE + 0x48)
107/** External register (wat) */
108#define GPIO_AEXT MMIO32(GPIO_BASE + 0x4c)
109/*@}*/
110
112
113void gpio_set(uint16_t gpios);
114void gpio_clear(uint16_t gpios);
115uint16_t gpio_get(uint16_t gpios);
116void gpio_toggle(uint16_t gpios);
117
118void gpio_input(uint16_t gpios);
119void gpio_output(uint16_t gpios);
120
121void gpio_int_enable(uint16_t gpios, bool en);
122void gpio_int_mask(uint16_t gpios, enum gpio_int_masked masked);
123void gpio_int_type(uint16_t gpios, enum gpio_trig_type type);
124void gpio_int_pol(uint16_t gpios, enum gpio_pol pol);
125uint16_t gpio_int_status(void);
126uint16_t gpio_int_raw_status(void);
127void gpio_int_clear(uint16_t gpios);
128
130
131#endif
132/**@}*/
#define END_DECLS
Definition: common.h:34
#define BEGIN_DECLS
Definition: common.h:33
gpio_dir
Definition: gpio.h:53
@ GPIO_INPUT
Definition: gpio.h:54
@ GPIO_OUTPUT
Definition: gpio.h:55
gpio_int_masked
Definition: gpio.h:80
@ GPIO_UNMASKED
Definition: gpio.h:81
@ GPIO_MASKED
Definition: gpio.h:82
gpio_pol
Definition: gpio.h:62
@ GPIO_POL_LOW
Definition: gpio.h:63
@ GPIO_POL_HIGH
Definition: gpio.h:64
void gpio_int_clear(uint16_t gpios)
Clear the specified pin interrupts.
Definition: gpio.c:249
void gpio_int_type(uint16_t gpios, enum gpio_trig_type type)
Sets whether the pins are edge triggered or level triggered.
Definition: gpio.c:178
uint16_t gpio_get(uint16_t gpios)
Read a Group of Pins.
Definition: gpio.c:71
void gpio_int_mask(uint16_t gpios, enum gpio_int_masked masked)
Sets bits in the interrupt mask.
Definition: gpio.c:155
void gpio_output(uint16_t gpios)
Set the direction of a Group of Pins to Output.
Definition: gpio.c:114
void gpio_int_enable(uint16_t gpios, bool en)
Sets the pins as external interrupts, rather than normal GPIO.
Definition: gpio.c:132
void gpio_set(uint16_t gpios)
Set a Group of Pins.
Definition: gpio.c:42
void gpio_int_pol(uint16_t gpios, enum gpio_pol pol)
Sets the interrupt trigger polarity.
Definition: gpio.c:200
uint16_t gpio_int_status(void)
Gets the masked interrupt status.
Definition: gpio.c:219
void gpio_input(uint16_t gpios)
Set the direction of a Group of Pins to Input.
Definition: gpio.c:100
void gpio_clear(uint16_t gpios)
Clear a Group of Pins.
Definition: gpio.c:57
void gpio_toggle(uint16_t gpios)
Toggle a Group of Pins.
Definition: gpio.c:85
uint16_t gpio_int_raw_status(void)
Gets the raw unmasked interrupt status.
Definition: gpio.c:233
gpio_trig_type
Definition: gpio.h:71
@ GPIO_TRIG_LEVEL
Definition: gpio.h:72
@ GPIO_TRIG_EDGE
Definition: gpio.h:73