cpu_gpio_ll.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2021 Otto-von-Guericke-Universität Magdeburg
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
18 #include <stdalign.h>
19 #include <stdint.h>
20 #include "periph_cpu.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /* Hide this from Doxygen to avoid merging implementation details into
27  * public view on type */
28 #ifndef DOXYGEN
29 
30 #if !defined(CPU_FAM_STM32F1)
31 /* For the STM32F1 GPIO peripheral, the gpio_ll_switch_dir is not supported */
32 # define HAVE_GPIO_LL_PREPARE_SWITCH_DIR
33 #endif
34 
35 #define HAVE_GPIO_PULL_STRENGTH_T
36 typedef enum {
38  GPIO_PULL_WEAK = 0,
39  GPIO_PULL_STRONG = 0,
42 
43 #define HAVE_GPIO_DRIVE_STRENGTH_T
44 typedef enum {
46  GPIO_DRIVE_WEAK = 0,
50 
51 /* Modern STM32 GPIO config registers with the OSPEEDR register support full
52  * 4 slew rates, legacy STM32F1 style only have three slew rates. We define
53  * slow and fast to the same value, so that we have three options:
54  * 1. SLOWEST: 2 MHZ
55  * 2. SLOW: 10 MHZ
56  * 3. FAST/FASTEST: 50 MHz
57  */
58 #if defined(GPIO_OSPEEDR_OSPEED0) || defined(GPIO_OSPEEDER_OSPEEDR0) \
59  || defined(GPIO_OSPEEDER_OSPEED0) || defined(GPIO_OSPEEDR_OSPEEDR0)
60 # define STM32_HAS_OSPEED 1
61 #else
62 # define STM32_HAS_OSPEED 0
63 #endif
64 
65 #define HAVE_GPIO_SLEW_T
66 #if STM32_HAS_OSPEED
67 typedef enum {
69  GPIO_SLEW_SLOW = 1,
70  GPIO_SLEW_FAST = 2,
72 } gpio_slew_t;
73 #else
74 typedef enum {
76  GPIO_SLEW_SLOW = 0,
77  GPIO_SLEW_FAST = 1,
79 } gpio_slew_t;
80 #endif
81 
82 #define HAVE_GPIO_IRQ_TRIG_T
83 /*
84  * Layout:
85  * 7 6 5 4 3 2 1 0
86  * +-+-+-+-+-+-+-+-+
87  * | RFU |T|L|H|
88  * +-+-+-+-+-+-+-+-+
89  *
90  * RFU = Reserved for future use
91  * T = Trigger mode (1 = Level triggered, 0 = Edge triggered)
92  * L = Low (1 = low level / falling edge)
93  * H = High (1 = high level / rising edge)
94  *
95  * Note: This layout overlaps with gpio_flank_t by intent
96  */
97 typedef enum {
101  GPIO_TRIGGER_LEVEL = 0x4,
102  GPIO_TRIGGER_LEVEL_HIGH = GPIO_TRIGGER_LEVEL | GPIO_TRIGGER_EDGE_RISING,
103  GPIO_TRIGGER_LEVEL_LOW = GPIO_TRIGGER_LEVEL | GPIO_TRIGGER_EDGE_FALLING,
105 
109 typedef enum {
110  GPIOX_MODER_INPUT = 0x0,
111  GPIOX_MODER_OUTPUT = 0x1,
112  GPIOX_MODER_AF = 0x2,
113  GPIOX_MODER_ANALOG = 0x3,
114 } gpiox_moder_t;
115 
119 #define GPIO_STATE_T_OPEN_DRAIN_FLAG 0x4
123 #define GPIO_STATE_T_MODER_Msk 0x3
124 
125 #define HAVE_GPIO_STATE_T
126 typedef enum {
127  GPIO_INPUT = GPIOX_MODER_INPUT,
128  GPIO_OUTPUT_PUSH_PULL = GPIOX_MODER_OUTPUT,
129  GPIO_OUTPUT_OPEN_DRAIN = GPIOX_MODER_OUTPUT | GPIO_STATE_T_OPEN_DRAIN_FLAG,
130  GPIO_USED_BY_PERIPHERAL = GPIOX_MODER_AF,
131  GPIO_DISCONNECT = GPIOX_MODER_ANALOG,
133 } gpio_state_t;
134 
135 #define HAVE_GPIO_PULL_T
136 typedef enum {
138  GPIO_PULL_UP,
141 } gpio_pull_t;
142 
143 #define HAVE_GPIO_CONF_T
144 typedef union gpio_conf_stm32 gpio_conf_t;
145 
146 #endif /* ndef Doxygen */
147 
153  uint8_t bits;
154  struct {
186  bool initial_value : 1;
187  };
188 };
189 
190 #ifdef __cplusplus
191 }
192 #endif
193 
gpio_irq_trig_t
Definition of possible IRQ triggers.
Definition: gpio_ll_irq.h:71
@ GPIO_TRIGGER_EDGE_FALLING
edge triggered IRQ on falling flanks only
Definition: gpio_ll_irq.h:72
@ GPIO_TRIGGER_LEVEL_HIGH
level triggered IRQ on high input
Definition: gpio_ll_irq.h:77
@ GPIO_TRIGGER_EDGE_RISING
edge triggered IRQ on rising flanks only
Definition: gpio_ll_irq.h:74
@ GPIO_TRIGGER_EDGE_BOTH
edge triggered IRQ on falling AND rising flanks
Definition: gpio_ll_irq.h:75
@ GPIO_TRIGGER_LEVEL_LOW
level triggered IRQ on low input
Definition: gpio_ll_irq.h:78
gpio_pull_t
Enumeration of pull resistor configurations.
Definition: gpio_ll.h:257
gpio_pull_strength_t
Enumeration of pull resistor values.
Definition: gpio_ll.h:275
gpio_state_t
Enumeration of GPIO states (direction)
Definition: gpio_ll.h:165
gpio_slew_t
Enumeration of slew rate settings.
Definition: gpio_ll.h:339
gpio_drive_strength_t
Enumeration of drive strength options.
Definition: gpio_ll.h:306
typedef gpio_conf_t
GPIO pin configuration.
Definition: gpio_ll.h:423
@ GPIO_FLOATING
No pull ups nor pull downs enabled.
Definition: gpio_ll.h:258
@ GPIO_PULL_KEEP
Keep the signal at current logic level with pull up/down resistors.
Definition: gpio_ll.h:261
@ GPIO_PULL_DOWN
Pull down resistor enabled.
Definition: gpio_ll.h:260
@ GPIO_PULL_UP
Pull up resistor enabled.
Definition: gpio_ll.h:259
@ GPIO_PULL_WEAKEST
Use the weakest (highest Ohm value) resistor.
Definition: gpio_ll.h:276
@ GPIO_PULL_WEAK
Use a weak pull resistor.
Definition: gpio_ll.h:277
@ GPIO_PULL_STRONG
Use a strong pull resistor.
Definition: gpio_ll.h:278
@ GPIO_PULL_STRONGEST
Use the strongest pull resistor.
Definition: gpio_ll.h:279
@ GPIO_OUTPUT_OPEN_SOURCE
Use pin as output in open emitter configuration.
Definition: gpio_ll.h:202
@ GPIO_USED_BY_PERIPHERAL
The GPIO pin is used by a peripheral.
Definition: gpio_ll.h:221
@ GPIO_OUTPUT_OPEN_DRAIN
Use pin as output in open collector configuration.
Definition: gpio_ll.h:189
@ GPIO_OUTPUT_PUSH_PULL
Use pin as output in push-pull configuration.
Definition: gpio_ll.h:176
@ GPIO_DISCONNECT
Disconnect pin from all peripherals.
Definition: gpio_ll.h:249
@ GPIO_INPUT
Use pin as input.
Definition: gpio_ll.h:208
@ GPIO_SLEW_SLOWEST
let the output voltage level rise/fall as slow as possible
Definition: gpio_ll.h:340
@ GPIO_SLEW_FAST
let the output voltage level rise/fall fast
Definition: gpio_ll.h:343
@ GPIO_SLEW_SLOW
let the output voltage level rise/fall slowly
Definition: gpio_ll.h:342
@ GPIO_SLEW_FASTEST
let the output voltage level rise/fall as fast as possible
Definition: gpio_ll.h:344
@ GPIO_DRIVE_STRONG
Use a strong drive strength.
Definition: gpio_ll.h:309
@ GPIO_DRIVE_WEAK
Use a weak drive strength.
Definition: gpio_ll.h:308
@ GPIO_DRIVE_STRONGEST
Use the strongest drive strength.
Definition: gpio_ll.h:310
@ GPIO_DRIVE_WEAKEST
Use the weakest drive strength.
Definition: gpio_ll.h:307
GPIO pin configuration for STM32 MCUs.
Definition: cpu_gpio_ll.h:152
gpio_pull_t pull
Pull resistor configuration.
Definition: cpu_gpio_ll.h:162
gpio_state_t state
State of the pin.
Definition: cpu_gpio_ll.h:158
bool initial_value
Initial value of the output.
Definition: cpu_gpio_ll.h:186
gpio_slew_t slew_rate
Configure the slew rate of outputs.
Definition: cpu_gpio_ll.h:172
uint8_t bits
the raw bits
Definition: cpu_gpio_ll.h:153