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
10#pragma once
11
22
23#include <stdint.h>
24#include "cpu.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#ifndef DOXYGEN
35#define HAVE_GPIO_T
36typedef uint32_t gpio_t;
38#endif
39
43#define GPIO_UNDEF (0xffffffff)
44
48#if defined(CPU_FAM_STM32MP1)
49#define GPIO_PIN(x, y) ((GPIOA_BASE + (x << 12)) | y)
50#else
51#define GPIO_PIN(x, y) ((GPIOA_BASE + (x << 10)) | y)
52#endif
53
57enum {
58#ifdef GPIOA
59 PORT_A = 0,
60#endif
61#ifdef GPIOB
62 PORT_B = 1,
63#endif
64#ifdef GPIOC
65 PORT_C = 2,
66#endif
67#ifdef GPIOD
68 PORT_D = 3,
69#endif
70#ifdef GPIOE
71 PORT_E = 4,
72#endif
73#ifdef GPIOF
74 PORT_F = 5,
75#endif
76#ifdef GPIOG
77 PORT_G = 6,
78#endif
79#ifdef GPIOH
80 PORT_H = 7,
81#endif
82#ifdef GPIOI
83 PORT_I = 8,
84#endif
85#ifdef GPIOJ
86 PORT_J = 9,
87#endif
88#ifdef GPIOK
89 PORT_K = 10,
90#endif
91};
92
123
124#ifdef CPU_FAM_STM32F1
125#ifndef DOXYGEN
135#define GPIO_MODE(mode, cnf, odr) (mode | (cnf << 2) | (odr << 4))
136
143#define HAVE_GPIO_MODE_T
144typedef enum {
145 GPIO_IN = GPIO_MODE(0, 1, 0),
146 GPIO_IN_PD = GPIO_MODE(0, 2, 0),
147 GPIO_IN_PU = GPIO_MODE(0, 2, 1),
148 GPIO_OUT = GPIO_MODE(3, 0, 0),
149 GPIO_OD = GPIO_MODE(3, 1, 0),
150 GPIO_OD_PU = (0xff)
153#endif /* ndef DOXYGEN */
154
159#define HAVE_GPIO_PP_T
160typedef enum {
161 GPIO_NOPULL = 4,
162 GPIO_PULLUP = 9,
163 GPIO_PULLDOWN = 8
164} gpio_pp_t;
166#else /* CPU_FAM_STM32F1 */
175#define GPIO_MODE(io, pr, ot) ((io << 0) | (pr << 2) | (ot << 4))
176
177#ifndef DOXYGEN
182#define HAVE_GPIO_MODE_T
183typedef enum {
184 GPIO_IN = GPIO_MODE(0, 0, 0),
185 GPIO_IN_PD = GPIO_MODE(0, 2, 0),
186 GPIO_IN_PU = GPIO_MODE(0, 1, 0),
187 GPIO_OUT = GPIO_MODE(1, 0, 0),
188 GPIO_OD = GPIO_MODE(1, 0, 1),
189 GPIO_OD_PU = GPIO_MODE(1, 1, 1)
192#endif /* ndef DOXYGEN */
193#endif /* ndef CPU_FAM_STM32F1 */
194
195#ifndef DOXYGEN
200#define HAVE_GPIO_FLANK_T
201typedef enum {
202 GPIO_RISING = 1,
203 GPIO_FALLING = 2,
204 GPIO_BOTH = 3
207#endif /* ndef DOXYGEN */
208
215void gpio_init_af(gpio_t pin, gpio_af_t af);
216
222void gpio_init_analog(gpio_t pin);
223
224#ifdef __cplusplus
225}
226#endif
227
@ PORT_B
port B
Definition periph_cpu.h:47
@ PORT_G
port G
Definition periph_cpu.h:52
@ PORT_C
port C
Definition periph_cpu.h:48
@ PORT_F
port F
Definition periph_cpu.h:51
@ PORT_E
port E
Definition periph_cpu.h:50
@ PORT_A
port A
Definition periph_cpu.h:46
@ PORT_D
port D
Definition periph_cpu.h:49
@ PORT_K
port K
Definition periph_cpu.h:53
@ PORT_H
port H
Definition periph_cpu.h:51
@ PORT_J
port J
Definition periph_cpu.h:52
gpio_flank_t
Definition periph_cpu.h:179
@ GPIO_OUT
select GPIO MASK as output
Definition periph_cpu.h:164
@ GPIO_IN
select GPIO MASK as input
Definition periph_cpu.h:163
@ GPIO_AF1
use alternate function 1
Definition cpu_gpio.h:102
@ GPIO_AF2
use alternate function 2
Definition cpu_gpio.h:103
@ GPIO_AF5
use alternate function 5
Definition cpu_gpio.h:106
@ GPIO_AF15
use alternate function 15
Definition cpu_gpio.h:117
@ GPIO_AF4
use alternate function 4
Definition cpu_gpio.h:105
@ GPIO_AF8
use alternate function 8
Definition cpu_gpio.h:110
@ GPIO_AF6
use alternate function 6
Definition cpu_gpio.h:107
@ GPIO_AF10
use alternate function 10
Definition cpu_gpio.h:112
@ GPIO_AF9
use alternate function 9
Definition cpu_gpio.h:111
@ GPIO_AF14
use alternate function 14
Definition cpu_gpio.h:116
@ GPIO_AF3
use alternate function 3
Definition cpu_gpio.h:104
@ GPIO_AF_UNDEF
an UNDEF value definition, e.g.
Definition cpu_gpio.h:120
@ GPIO_AF0
use alternate function 0
Definition cpu_gpio.h:101
@ GPIO_AF12
use alternate function 12
Definition cpu_gpio.h:114
@ GPIO_AF7
use alternate function 7
Definition cpu_gpio.h:108
@ GPIO_AF13
use alternate function 13
Definition cpu_gpio.h:115
@ GPIO_AF11
use alternate function 11
Definition cpu_gpio.h:113
#define GPIO_MODE(io, pr, ot)
Generate GPIO mode bitfields.
Definition cpu_gpio.h:175
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:165
@ GPIO_AF_OUT_OD
alternate function output - open-drain
Definition periph_cpu.h:167
@ GPIO_AF_OUT_PP
alternate function output - push-pull
Definition periph_cpu.h:166
gpio_mode_t
Available pin modes.
Definition periph_cpu.h:91