Loading...
Searching...
No Matches
cpu_gpio_ll.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Otto-von-Guericke-Universität Magdeburg
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
19#ifndef PERIPH_CPU_GPIO_LL_H
20#define PERIPH_CPU_GPIO_LL_H
21
22#include <stdalign.h>
23#include <stdint.h>
24#include "periph_cpu.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/* Hide this from Doxygen to avoid merging implementation details into
31 * public view on type */
32#ifndef DOXYGEN
33
34#define HAVE_GPIO_PULL_STRENGTH_T
35typedef enum {
41
42#define HAVE_GPIO_DRIVE_STRENGTH_T
43typedef enum {
49
50/* Modern STM32 GPIO config registers with the OSPEEDR register support full
51 * 4 slew rates, legacy STM32F1 style only have three slew rates. We define
52 * slow and fast to the same value, so that we have three options:
53 * 1. SLOWEST: 2 MHZ
54 * 2. SLOW: 10 MHZ
55 * 3. FAST/FASTEST: 50 MHz
56 */
57#if defined(GPIO_OSPEEDR_OSPEED0) || defined(GPIO_OSPEEDER_OSPEEDR0) \
58 || defined(GPIO_OSPEEDER_OSPEED0) || defined(GPIO_OSPEEDR_OSPEEDR0)
59# define STM32_HAS_OSPEED 1
60#else
61# define STM32_HAS_OSPEED 0
62#endif
63
64#define HAVE_GPIO_SLEW_T
65#if STM32_HAS_OSPEED
66typedef enum {
72#else
73typedef enum {
79#endif
80
81#define HAVE_GPIO_IRQ_TRIG_T
82/*
83 * Layout:
84 * 7 6 5 4 3 2 1 0
85 * +-+-+-+-+-+-+-+-+
86 * | RFU |T|L|H|
87 * +-+-+-+-+-+-+-+-+
88 *
89 * RFU = Reserved for future use
90 * T = Trigger mode (1 = Level triggered, 0 = Edge triggered)
91 * L = Low (1 = low level / falling edge)
92 * H = High (1 = high level / rising edge)
93 *
94 * Note: This layout overlaps with gpio_flank_t by intent
95 */
96typedef enum {
100 GPIO_TRIGGER_LEVEL = 0x4,
104
108typedef enum {
109 GPIOX_MODER_INPUT = 0x0,
110 GPIOX_MODER_OUTPUT = 0x1,
111 GPIOX_MODER_AF = 0x2,
112 GPIOX_MODER_ANALOG = 0x3,
113} gpiox_moder_t;
114
118#define GPIO_STATE_T_OPEN_DRAIN_FLAG 0x4
122#define GPIO_STATE_T_MODER_Msk 0x3
123
124#define HAVE_GPIO_STATE_T
125typedef enum {
126 GPIO_INPUT = GPIOX_MODER_INPUT,
127 GPIO_OUTPUT_PUSH_PULL = GPIOX_MODER_OUTPUT,
128 GPIO_OUTPUT_OPEN_DRAIN = GPIOX_MODER_OUTPUT | GPIO_STATE_T_OPEN_DRAIN_FLAG,
129 GPIO_USED_BY_PERIPHERAL = GPIOX_MODER_AF,
130 GPIO_DISCONNECT = GPIOX_MODER_ANALOG,
133
134#define HAVE_GPIO_PULL_T
135typedef enum {
141
142#define HAVE_GPIO_CONF_T
143typedef union gpio_conf_stm32 gpio_conf_t;
144
145#endif /* ndef Doxygen */
146
152 uint8_t bits;
153 struct {
186 };
187};
188
189#ifdef __cplusplus
190}
191#endif
192
193#endif /* PERIPH_CPU_GPIO_LL_H */
gpio_irq_trig_t
Definition of possible IRQ triggers.
Definition gpio_ll_irq.h:62
@ GPIO_TRIGGER_EDGE_FALLING
edge triggered IRQ on falling flanks only
Definition gpio_ll_irq.h:63
@ GPIO_TRIGGER_LEVEL_HIGH
level triggered IRQ on high input
Definition gpio_ll_irq.h:68
@ GPIO_TRIGGER_EDGE_RISING
edge triggered IRQ on rising flanks only
Definition gpio_ll_irq.h:65
@ GPIO_TRIGGER_EDGE_BOTH
edge triggered IRQ on falling AND rising flanks
Definition gpio_ll_irq.h:66
@ GPIO_TRIGGER_LEVEL_LOW
level triggered IRQ on low input
Definition gpio_ll_irq.h:69
gpio_pull_t
Enumeration of pull resistor configurations.
Definition gpio_ll.h:225
gpio_pull_strength_t
Enumeration of pull resistor values.
Definition gpio_ll.h:243
gpio_state_t
Enumeration of GPIO states (direction)
Definition gpio_ll.h:133
gpio_slew_t
Enumeration of slew rate settings.
Definition gpio_ll.h:307
gpio_drive_strength_t
Enumeration of drive strength options.
Definition gpio_ll.h:274
typedef gpio_conf_t
GPIO pin configuration.
Definition gpio_ll.h:391
@ GPIO_FLOATING
No pull ups nor pull downs enabled.
Definition gpio_ll.h:226
@ GPIO_PULL_KEEP
Keep the signal at current logic level with pull up/down resistors.
Definition gpio_ll.h:229
@ GPIO_PULL_DOWN
Pull down resistor enabled.
Definition gpio_ll.h:228
@ GPIO_PULL_UP
Pull up resistor enabled.
Definition gpio_ll.h:227
@ GPIO_PULL_WEAKEST
Use the weakest (highest Ohm value) resistor.
Definition gpio_ll.h:244
@ GPIO_PULL_WEAK
Use a weak pull resistor.
Definition gpio_ll.h:245
@ GPIO_PULL_STRONG
Use a strong pull resistor.
Definition gpio_ll.h:246
@ GPIO_PULL_STRONGEST
Use the strongest pull resistor.
Definition gpio_ll.h:247
@ GPIO_OUTPUT_OPEN_SOURCE
Use pin as output in open emitter configuration.
Definition gpio_ll.h:170
@ GPIO_USED_BY_PERIPHERAL
The GPIO pin is used by a peripheral.
Definition gpio_ll.h:189
@ GPIO_OUTPUT_OPEN_DRAIN
Use pin as output in open collector configuration.
Definition gpio_ll.h:157
@ GPIO_OUTPUT_PUSH_PULL
Use pin as output in push-pull configuration.
Definition gpio_ll.h:144
@ GPIO_DISCONNECT
Disconnect pin from all peripherals.
Definition gpio_ll.h:217
@ GPIO_INPUT
Use pin as input.
Definition gpio_ll.h:176
@ GPIO_SLEW_SLOWEST
let the output voltage level rise/fall as slow as possible
Definition gpio_ll.h:308
@ GPIO_SLEW_FAST
let the output voltage level rise/fall fast
Definition gpio_ll.h:311
@ GPIO_SLEW_SLOW
let the output voltage level rise/fall slowly
Definition gpio_ll.h:310
@ GPIO_SLEW_FASTEST
let the output voltage level rise/fall as fast as possible
Definition gpio_ll.h:312
@ GPIO_DRIVE_STRONG
Use a strong drive strength.
Definition gpio_ll.h:277
@ GPIO_DRIVE_WEAK
Use a weak drive strength.
Definition gpio_ll.h:276
@ GPIO_DRIVE_STRONGEST
Use the strongest drive strength.
Definition gpio_ll.h:278
@ GPIO_DRIVE_WEAKEST
Use the weakest drive strength.
Definition gpio_ll.h:275
GPIO pin configuration for STM32 MCUs.
gpio_pull_t pull
Pull resistor configuration.
gpio_state_t state
State of the pin.
bool initial_value
Initial value of the output.
gpio_slew_t slew_rate
Configure the slew rate of outputs.
uint8_t bits
the raw bits