Loading...
Searching...
No Matches
cpu_gpio.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 Freie Universität Berlin
3 * 2017 OTA keys S.A.
4 *
5 * This file is subject to the terms and conditions of the GNU Lesser
6 * General Public License v2.1. See the file LICENSE in the top level
7 * directory for more details.
8 */
9
21#ifndef PERIPH_CPU_GPIO_H
22#define PERIPH_CPU_GPIO_H
23
24#include <stdint.h>
25#include "cpu.h"
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#ifndef DOXYGEN
36#define HAVE_GPIO_T
37typedef uint32_t gpio_t;
39#endif
40
44#define GPIO_UNDEF (0xffffffff)
45
49#if defined(CPU_FAM_STM32MP1)
50#define GPIO_PIN(x, y) ((GPIOA_BASE + (x << 12)) | y)
51#else
52#define GPIO_PIN(x, y) ((GPIOA_BASE + (x << 10)) | y)
53#endif
54
58enum {
59#ifdef GPIOA
60 PORT_A = 0,
61#endif
62#ifdef GPIOB
63 PORT_B = 1,
64#endif
65#ifdef GPIOC
66 PORT_C = 2,
67#endif
68#ifdef GPIOD
69 PORT_D = 3,
70#endif
71#ifdef GPIOE
72 PORT_E = 4,
73#endif
74#ifdef GPIOF
75 PORT_F = 5,
76#endif
77#ifdef GPIOG
78 PORT_G = 6,
79#endif
80#ifdef GPIOH
81 PORT_H = 7,
82#endif
83#ifdef GPIOI
84 PORT_I = 8,
85#endif
86#ifdef GPIOJ
87 PORT_J = 9,
88#endif
89#ifdef GPIOK
90 PORT_K = 10,
91#endif
92};
93
124
125#ifdef CPU_FAM_STM32F1
126#ifndef DOXYGEN
136#define GPIO_MODE(mode, cnf, odr) (mode | (cnf << 2) | (odr << 4))
137
144#define HAVE_GPIO_MODE_T
145typedef enum {
146 GPIO_IN = GPIO_MODE(0, 1, 0),
147 GPIO_IN_PD = GPIO_MODE(0, 2, 0),
148 GPIO_IN_PU = GPIO_MODE(0, 2, 1),
149 GPIO_OUT = GPIO_MODE(3, 0, 0),
150 GPIO_OD = GPIO_MODE(3, 1, 0),
151 GPIO_OD_PU = (0xff)
154#endif /* ndef DOXYGEN */
155
160#define HAVE_GPIO_PP_T
161typedef enum {
162 GPIO_NOPULL = 4,
163 GPIO_PULLUP = 9,
164 GPIO_PULLDOWN = 8
165} gpio_pp_t;
167#else /* CPU_FAM_STM32F1 */
176#define GPIO_MODE(io, pr, ot) ((io << 0) | (pr << 2) | (ot << 4))
177
178#ifndef DOXYGEN
183#define HAVE_GPIO_MODE_T
184typedef enum {
185 GPIO_IN = GPIO_MODE(0, 0, 0),
186 GPIO_IN_PD = GPIO_MODE(0, 2, 0),
187 GPIO_IN_PU = GPIO_MODE(0, 1, 0),
188 GPIO_OUT = GPIO_MODE(1, 0, 0),
189 GPIO_OD = GPIO_MODE(1, 0, 1),
190 GPIO_OD_PU = GPIO_MODE(1, 1, 1)
193#endif /* ndef DOXYGEN */
194#endif /* ndef CPU_FAM_STM32F1 */
195
196#ifndef DOXYGEN
201#define HAVE_GPIO_FLANK_T
202typedef enum {
203 GPIO_RISING = 1,
204 GPIO_FALLING = 2,
205 GPIO_BOTH = 3
208#endif /* ndef DOXYGEN */
209
216void gpio_init_af(gpio_t pin, gpio_af_t af);
217
223void gpio_init_analog(gpio_t pin);
224
225#ifdef __cplusplus
226}
227#endif
228
229#endif /* PERIPH_CPU_GPIO_H */
@ PORT_B
port B
Definition periph_cpu.h:48
@ PORT_G
port G
Definition periph_cpu.h:53
@ PORT_C
port C
Definition periph_cpu.h:49
@ PORT_F
port F
Definition periph_cpu.h:52
@ PORT_E
port E
Definition periph_cpu.h:51
@ PORT_A
port A
Definition periph_cpu.h:47
@ PORT_D
port D
Definition periph_cpu.h:50
@ PORT_K
port K
Definition periph_cpu.h:54
@ PORT_H
port H
Definition periph_cpu.h:52
@ PORT_J
port J
Definition periph_cpu.h:53
gpio_flank_t
Definition periph_cpu.h:180
@ GPIO_OUT
select GPIO MASK as output
Definition periph_cpu.h:165
@ GPIO_IN
select GPIO MASK as input
Definition periph_cpu.h:164
gpio_af_t
Available MUX values for configuring a pin's alternate function.
Definition cpu_gpio.h:97
@ GPIO_AF1
use alternate function 1
Definition cpu_gpio.h:103
@ GPIO_AF2
use alternate function 2
Definition cpu_gpio.h:104
@ GPIO_AF5
use alternate function 5
Definition cpu_gpio.h:107
@ GPIO_AF15
use alternate function 15
Definition cpu_gpio.h:118
@ GPIO_AF4
use alternate function 4
Definition cpu_gpio.h:106
@ GPIO_AF8
use alternate function 8
Definition cpu_gpio.h:111
@ GPIO_AF6
use alternate function 6
Definition cpu_gpio.h:108
@ GPIO_AF10
use alternate function 10
Definition cpu_gpio.h:113
@ GPIO_AF9
use alternate function 9
Definition cpu_gpio.h:112
@ GPIO_AF14
use alternate function 14
Definition cpu_gpio.h:117
@ GPIO_AF3
use alternate function 3
Definition cpu_gpio.h:105
@ GPIO_AF_UNDEF
an UNDEF value definition, e.g.
Definition cpu_gpio.h:121
@ GPIO_AF0
use alternate function 0
Definition cpu_gpio.h:102
@ GPIO_AF12
use alternate function 12
Definition cpu_gpio.h:115
@ GPIO_AF7
use alternate function 7
Definition cpu_gpio.h:109
@ GPIO_AF13
use alternate function 13
Definition cpu_gpio.h:116
@ GPIO_AF11
use alternate function 11
Definition cpu_gpio.h:114
#define GPIO_MODE(io, pr, ot)
Generate GPIO mode bitfields.
Definition cpu_gpio.h:176
void gpio_init_af(gpio_t pin, gpio_af_t af)
Configure the alternate function for the given pin.
void gpio_init_analog(gpio_t pin)
Configure the given pin to be used as ADC input.
gpio_af_t
Override alternative GPIO mode options.
Definition periph_cpu.h:166
@ GPIO_AF_OUT_OD
alternate function output - open-drain
Definition periph_cpu.h:168
@ GPIO_AF_OUT_PP
alternate function output - push-pull
Definition periph_cpu.h:167
gpio_mode_t
Available pin modes.
Definition periph_cpu.h:82