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 
9 #pragma once
10 
21 #include <stdalign.h>
22 #include <stdint.h>
23 #include "periph_cpu.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 /* Hide this from Doxygen to avoid merging implementation details into
30  * public view on type */
31 #ifndef DOXYGEN
32 
33 #if !defined(CPU_FAM_STM32F1)
34 /* For the STM32F1 GPIO peripheral, the gpio_ll_switch_dir is not supported */
35 # define HAVE_GPIO_LL_PREPARE_SWITCH_DIR
36 #endif
37 
38 #define HAVE_GPIO_PULL_STRENGTH_T
39 typedef enum {
41  GPIO_PULL_WEAK = 0,
42  GPIO_PULL_STRONG = 0,
45 
46 #define HAVE_GPIO_DRIVE_STRENGTH_T
47 typedef enum {
49  GPIO_DRIVE_WEAK = 0,
53 
54 /* Modern STM32 GPIO config registers with the OSPEEDR register support full
55  * 4 slew rates, legacy STM32F1 style only have three slew rates. We define
56  * slow and fast to the same value, so that we have three options:
57  * 1. SLOWEST: 2 MHZ
58  * 2. SLOW: 10 MHZ
59  * 3. FAST/FASTEST: 50 MHz
60  */
61 #if defined(GPIO_OSPEEDR_OSPEED0) || defined(GPIO_OSPEEDER_OSPEEDR0) \
62  || defined(GPIO_OSPEEDER_OSPEED0) || defined(GPIO_OSPEEDR_OSPEEDR0)
63 # define STM32_HAS_OSPEED 1
64 #else
65 # define STM32_HAS_OSPEED 0
66 #endif
67 
68 #define HAVE_GPIO_SLEW_T
69 #if STM32_HAS_OSPEED
70 typedef enum {
72  GPIO_SLEW_SLOW = 1,
73  GPIO_SLEW_FAST = 2,
75 } gpio_slew_t;
76 #else
77 typedef enum {
79  GPIO_SLEW_SLOW = 0,
80  GPIO_SLEW_FAST = 1,
82 } gpio_slew_t;
83 #endif
84 
85 #define HAVE_GPIO_IRQ_TRIG_T
86 /*
87  * Layout:
88  * 7 6 5 4 3 2 1 0
89  * +-+-+-+-+-+-+-+-+
90  * | RFU |T|L|H|
91  * +-+-+-+-+-+-+-+-+
92  *
93  * RFU = Reserved for future use
94  * T = Trigger mode (1 = Level triggered, 0 = Edge triggered)
95  * L = Low (1 = low level / falling edge)
96  * H = High (1 = high level / rising edge)
97  *
98  * Note: This layout overlaps with gpio_flank_t by intent
99  */
100 typedef enum {
104  GPIO_TRIGGER_LEVEL = 0x4,
105  GPIO_TRIGGER_LEVEL_HIGH = GPIO_TRIGGER_LEVEL | GPIO_TRIGGER_EDGE_RISING,
106  GPIO_TRIGGER_LEVEL_LOW = GPIO_TRIGGER_LEVEL | GPIO_TRIGGER_EDGE_FALLING,
108 
112 typedef enum {
113  GPIOX_MODER_INPUT = 0x0,
114  GPIOX_MODER_OUTPUT = 0x1,
115  GPIOX_MODER_AF = 0x2,
116  GPIOX_MODER_ANALOG = 0x3,
117 } gpiox_moder_t;
118 
122 #define GPIO_STATE_T_OPEN_DRAIN_FLAG 0x4
126 #define GPIO_STATE_T_MODER_Msk 0x3
127 
128 #define HAVE_GPIO_STATE_T
129 typedef enum {
130  GPIO_INPUT = GPIOX_MODER_INPUT,
131  GPIO_OUTPUT_PUSH_PULL = GPIOX_MODER_OUTPUT,
132  GPIO_OUTPUT_OPEN_DRAIN = GPIOX_MODER_OUTPUT | GPIO_STATE_T_OPEN_DRAIN_FLAG,
133  GPIO_USED_BY_PERIPHERAL = GPIOX_MODER_AF,
134  GPIO_DISCONNECT = GPIOX_MODER_ANALOG,
136 } gpio_state_t;
137 
138 #define HAVE_GPIO_PULL_T
139 typedef enum {
141  GPIO_PULL_UP,
144 } gpio_pull_t;
145 
146 #define HAVE_GPIO_CONF_T
147 typedef union gpio_conf_stm32 gpio_conf_t;
148 
149 #endif /* ndef Doxygen */
150 
156  uint8_t bits;
157  struct {
189  bool initial_value : 1;
190  };
191 };
192 
193 #ifdef __cplusplus
194 }
195 #endif
196 
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:155
gpio_pull_t pull
Pull resistor configuration.
Definition: cpu_gpio_ll.h:165
gpio_state_t state
State of the pin.
Definition: cpu_gpio_ll.h:161
bool initial_value
Initial value of the output.
Definition: cpu_gpio_ll.h:189
gpio_slew_t slew_rate
Configure the slew rate of outputs.
Definition: cpu_gpio_ll.h:175
uint8_t bits
the raw bits
Definition: cpu_gpio_ll.h:156