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
27 extern "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 #if !defined(CPU_FAM_STM32F1)
35 /* For the STM32F1 GPIO peripheral, the gpio_ll_switch_dir is not supported */
36 # define HAVE_GPIO_LL_PREPARE_SWITCH_DIR
37 #endif
38 
39 #define HAVE_GPIO_PULL_STRENGTH_T
40 typedef enum {
42  GPIO_PULL_WEAK = 0,
43  GPIO_PULL_STRONG = 0,
46 
47 #define HAVE_GPIO_DRIVE_STRENGTH_T
48 typedef enum {
50  GPIO_DRIVE_WEAK = 0,
54 
55 /* Modern STM32 GPIO config registers with the OSPEEDR register support full
56  * 4 slew rates, legacy STM32F1 style only have three slew rates. We define
57  * slow and fast to the same value, so that we have three options:
58  * 1. SLOWEST: 2 MHZ
59  * 2. SLOW: 10 MHZ
60  * 3. FAST/FASTEST: 50 MHz
61  */
62 #if defined(GPIO_OSPEEDR_OSPEED0) || defined(GPIO_OSPEEDER_OSPEEDR0) \
63  || defined(GPIO_OSPEEDER_OSPEED0) || defined(GPIO_OSPEEDR_OSPEEDR0)
64 # define STM32_HAS_OSPEED 1
65 #else
66 # define STM32_HAS_OSPEED 0
67 #endif
68 
69 #define HAVE_GPIO_SLEW_T
70 #if STM32_HAS_OSPEED
71 typedef enum {
73  GPIO_SLEW_SLOW = 1,
74  GPIO_SLEW_FAST = 2,
76 } gpio_slew_t;
77 #else
78 typedef enum {
80  GPIO_SLEW_SLOW = 0,
81  GPIO_SLEW_FAST = 1,
83 } gpio_slew_t;
84 #endif
85 
86 #define HAVE_GPIO_IRQ_TRIG_T
87 /*
88  * Layout:
89  * 7 6 5 4 3 2 1 0
90  * +-+-+-+-+-+-+-+-+
91  * | RFU |T|L|H|
92  * +-+-+-+-+-+-+-+-+
93  *
94  * RFU = Reserved for future use
95  * T = Trigger mode (1 = Level triggered, 0 = Edge triggered)
96  * L = Low (1 = low level / falling edge)
97  * H = High (1 = high level / rising edge)
98  *
99  * Note: This layout overlaps with gpio_flank_t by intent
100  */
101 typedef enum {
105  GPIO_TRIGGER_LEVEL = 0x4,
106  GPIO_TRIGGER_LEVEL_HIGH = GPIO_TRIGGER_LEVEL | GPIO_TRIGGER_EDGE_RISING,
107  GPIO_TRIGGER_LEVEL_LOW = GPIO_TRIGGER_LEVEL | GPIO_TRIGGER_EDGE_FALLING,
109 
113 typedef enum {
114  GPIOX_MODER_INPUT = 0x0,
115  GPIOX_MODER_OUTPUT = 0x1,
116  GPIOX_MODER_AF = 0x2,
117  GPIOX_MODER_ANALOG = 0x3,
118 } gpiox_moder_t;
119 
123 #define GPIO_STATE_T_OPEN_DRAIN_FLAG 0x4
127 #define GPIO_STATE_T_MODER_Msk 0x3
128 
129 #define HAVE_GPIO_STATE_T
130 typedef enum {
131  GPIO_INPUT = GPIOX_MODER_INPUT,
132  GPIO_OUTPUT_PUSH_PULL = GPIOX_MODER_OUTPUT,
133  GPIO_OUTPUT_OPEN_DRAIN = GPIOX_MODER_OUTPUT | GPIO_STATE_T_OPEN_DRAIN_FLAG,
134  GPIO_USED_BY_PERIPHERAL = GPIOX_MODER_AF,
135  GPIO_DISCONNECT = GPIOX_MODER_ANALOG,
137 } gpio_state_t;
138 
139 #define HAVE_GPIO_PULL_T
140 typedef enum {
142  GPIO_PULL_UP,
145 } gpio_pull_t;
146 
147 #define HAVE_GPIO_CONF_T
148 typedef union gpio_conf_stm32 gpio_conf_t;
149 
150 #endif /* ndef Doxygen */
151 
157  uint8_t bits;
158  struct {
190  bool initial_value : 1;
191  };
192 };
193 
194 #ifdef __cplusplus
195 }
196 #endif
197 
198 #endif /* PERIPH_CPU_GPIO_LL_H */
gpio_irq_trig_t
Definition of possible IRQ triggers.
Definition: gpio_ll_irq.h:72
@ GPIO_TRIGGER_EDGE_FALLING
edge triggered IRQ on falling flanks only
Definition: gpio_ll_irq.h:73
@ GPIO_TRIGGER_LEVEL_HIGH
level triggered IRQ on high input
Definition: gpio_ll_irq.h:78
@ GPIO_TRIGGER_EDGE_RISING
edge triggered IRQ on rising flanks only
Definition: gpio_ll_irq.h:75
@ GPIO_TRIGGER_EDGE_BOTH
edge triggered IRQ on falling AND rising flanks
Definition: gpio_ll_irq.h:76
@ GPIO_TRIGGER_LEVEL_LOW
level triggered IRQ on low input
Definition: gpio_ll_irq.h:79
gpio_pull_t
Enumeration of pull resistor configurations.
Definition: gpio_ll.h:250
gpio_pull_strength_t
Enumeration of pull resistor values.
Definition: gpio_ll.h:268
gpio_state_t
Enumeration of GPIO states (direction)
Definition: gpio_ll.h:158
gpio_slew_t
Enumeration of slew rate settings.
Definition: gpio_ll.h:332
gpio_drive_strength_t
Enumeration of drive strength options.
Definition: gpio_ll.h:299
typedef gpio_conf_t
GPIO pin configuration.
Definition: gpio_ll.h:416
@ GPIO_FLOATING
No pull ups nor pull downs enabled.
Definition: gpio_ll.h:251
@ GPIO_PULL_KEEP
Keep the signal at current logic level with pull up/down resistors.
Definition: gpio_ll.h:254
@ GPIO_PULL_DOWN
Pull down resistor enabled.
Definition: gpio_ll.h:253
@ GPIO_PULL_UP
Pull up resistor enabled.
Definition: gpio_ll.h:252
@ GPIO_PULL_WEAKEST
Use the weakest (highest Ohm value) resistor.
Definition: gpio_ll.h:269
@ GPIO_PULL_WEAK
Use a weak pull resistor.
Definition: gpio_ll.h:270
@ GPIO_PULL_STRONG
Use a strong pull resistor.
Definition: gpio_ll.h:271
@ GPIO_PULL_STRONGEST
Use the strongest pull resistor.
Definition: gpio_ll.h:272
@ GPIO_OUTPUT_OPEN_SOURCE
Use pin as output in open emitter configuration.
Definition: gpio_ll.h:195
@ GPIO_USED_BY_PERIPHERAL
The GPIO pin is used by a peripheral.
Definition: gpio_ll.h:214
@ GPIO_OUTPUT_OPEN_DRAIN
Use pin as output in open collector configuration.
Definition: gpio_ll.h:182
@ GPIO_OUTPUT_PUSH_PULL
Use pin as output in push-pull configuration.
Definition: gpio_ll.h:169
@ GPIO_DISCONNECT
Disconnect pin from all peripherals.
Definition: gpio_ll.h:242
@ GPIO_INPUT
Use pin as input.
Definition: gpio_ll.h:201
@ GPIO_SLEW_SLOWEST
let the output voltage level rise/fall as slow as possible
Definition: gpio_ll.h:333
@ GPIO_SLEW_FAST
let the output voltage level rise/fall fast
Definition: gpio_ll.h:336
@ GPIO_SLEW_SLOW
let the output voltage level rise/fall slowly
Definition: gpio_ll.h:335
@ GPIO_SLEW_FASTEST
let the output voltage level rise/fall as fast as possible
Definition: gpio_ll.h:337
@ GPIO_DRIVE_STRONG
Use a strong drive strength.
Definition: gpio_ll.h:302
@ GPIO_DRIVE_WEAK
Use a weak drive strength.
Definition: gpio_ll.h:301
@ GPIO_DRIVE_STRONGEST
Use the strongest drive strength.
Definition: gpio_ll.h:303
@ GPIO_DRIVE_WEAKEST
Use the weakest drive strength.
Definition: gpio_ll.h:300
GPIO pin configuration for STM32 MCUs.
Definition: cpu_gpio_ll.h:156
gpio_pull_t pull
Pull resistor configuration.
Definition: cpu_gpio_ll.h:166
gpio_state_t state
State of the pin.
Definition: cpu_gpio_ll.h:162
bool initial_value
Initial value of the output.
Definition: cpu_gpio_ll.h:190
gpio_slew_t slew_rate
Configure the slew rate of outputs.
Definition: cpu_gpio_ll.h:176
uint8_t bits
the raw bits
Definition: cpu_gpio_ll.h:157