InES Hardware Abstraction Layer
hal_gpio.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2  * -- _____ ______ _____ -
3  * -- |_ _| | ____|/ ____| -
4  * -- | | _ __ | |__ | (___ Institute of Embedded Systems -
5  * -- | | | '_ \| __| \___ \ Zurich University of -
6  * -- _| |_| | | | |____ ____) | Applied Sciences -
7  * -- |_____|_| |_|______|_____/ 8401 Winterthur, Switzerland -
8  * ------------------------------------------------------------------------- */
18 /* Re-definition guard */
19 #ifndef _HAL_GPIO_H
20 #define _HAL_GPIO_H
21 
22 
23 /* User includes */
24 #include "reg_stm32f4xx.h"
25 #include "hal_common.h"
26 
27 
28 /* -- Type definitions
29  * ------------------------------------------------------------------------- */
30 
35 typedef enum {
36  HAL_GPIO_MODE_IN = 0x00,
41 
42 
47 typedef enum {
48  HAL_GPIO_OUT_SPEED_2MHZ = 0x00,
53 
54 
59 typedef enum {
60  HAL_GPIO_OUT_TYPE_PP = 0x00,
63 
64 
69 typedef enum {
70  HAL_GPIO_PUPD_NOPULL = 0x00,
74 
75 
80 typedef enum {
81  /* AF0 */
82  HAL_GPIO_AF_RTC50HZ = 0x00,
83  HAL_GPIO_AF_MCO = 0x00,
84  HAL_GPIO_AF_TAMPER = 0x00,
85  HAL_GPIO_AF_SWJ = 0x00,
86  HAL_GPIO_AF_TRACE = 0x00,
87  /* AF 1 */
88  HAL_GPIO_AF_TIM1 = 0x01,
89  HAL_GPIO_AF_TIM2 = 0x01,
90  /* AF 2 */
91  HAL_GPIO_AF_TIM3 = 0x02,
92  HAL_GPIO_AF_TIM4 = 0x02,
93  HAL_GPIO_AF_TIM5 = 0x02,
94  /* AF 3 */
95  HAL_GPIO_AF_TIM8 = 0x03,
96  HAL_GPIO_AF_TIM9 = 0x03,
97  HAL_GPIO_AF_TIM10 = 0x03,
98  HAL_GPIO_AF_TIM11 = 0x03,
99  /* AF 4 */
100  HAL_GPIO_AF_I2C1 = 0x04,
101  HAL_GPIO_AF_I2C2 = 0x04,
102  HAL_GPIO_AF_I2C3 = 0x04,
103  /* AF 5 */
104  HAL_GPIO_AF_SPI1 = 0x05,
105  HAL_GPIO_AF_SPI2 = 0x05,
106  HAL_GPIO_AF_SPI4 = 0x05,
107  HAL_GPIO_AF_SPI5 = 0x05,
108  HAL_GPIO_AF_SPI6 = 0x05,
109  /* AF 6 */
110  HAL_GPIO_AF_SPI3 = 0x06,
111  HAL_GPIO_AF_SAI1 = 0x06,
112  /* AF 7 */
113  HAL_GPIO_AF_USART1 = 0x07,
114  HAL_GPIO_AF_USART2 = 0x07,
115  HAL_GPIO_AF_USART3 = 0x07,
116  HAL_GPIO_AF_I2S3ext = 0x07,
117  /* AF 8 */
118  HAL_GPIO_AF_UART4 = 0x08,
119  HAL_GPIO_AF_UART5 = 0x08,
120  HAL_GPIO_AF_USART6 = 0x08,
121  HAL_GPIO_AF_UART7 = 0x08,
122  HAL_GPIO_AF_UART8 = 0x08,
123  /* AF 9 */
124  HAL_GPIO_AF_CAN1 = 0x09,
125  HAL_GPIO_AF_CAN2 = 0x09,
126  HAL_GPIO_AF_TIM12 = 0x09,
127  HAL_GPIO_AF_TIM13 = 0x09,
128  HAL_GPIO_AF_TIM14 = 0x09,
129  /* AF 10 */
130  HAL_GPIO_AF_OTG_FS = 0x0a,
131  HAL_GPIO_AF_OTG_HS = 0x0a,
132  /* AF 11 */
133  HAL_GPIO_AF_ETH = 0x0b,
134  /* AF 12 */
135  HAL_GPIO_AF_FMC = 0x0c,
136  HAL_GPIO_AF_OTG_HS_FS = 0x0c,
137  HAL_GPIO_AF_SDIO = 0x0c,
138  /* AF 13 */
139  HAL_GPIO_AF_DCMI = 0x0d,
140  /* AF 14 */
141  HAL_GPIO_AF_LTDC = 0x0e,
142  /* AF 15 */
143  HAL_GPIO_AF_EVENTOUT = 0x0f
144 } hal_gpio_af_t;
145 
146 
151 typedef enum {
152  HAL_GPIO_PIN_0 = 0x0001,
153  HAL_GPIO_PIN_1 = 0x0002,
154  HAL_GPIO_PIN_2 = 0x0004,
155  HAL_GPIO_PIN_3 = 0x0008,
156  HAL_GPIO_PIN_4 = 0x0010,
157  HAL_GPIO_PIN_5 = 0x0020,
158  HAL_GPIO_PIN_6 = 0x0040,
159  HAL_GPIO_PIN_7 = 0x0080,
160  HAL_GPIO_PIN_8 = 0x0100,
161  HAL_GPIO_PIN_9 = 0x0200,
162  HAL_GPIO_PIN_10 = 0x0400,
163  HAL_GPIO_PIN_11 = 0x0800,
164  HAL_GPIO_PIN_12 = 0x1000,
165  HAL_GPIO_PIN_13 = 0x2000,
166  HAL_GPIO_PIN_14 = 0x4000,
167  HAL_GPIO_PIN_15 = 0x8000,
168  HAL_GPIO_PIN_All = 0xffff,
170 
171 
176 typedef enum {
181 
182 
187 typedef struct {
188  uint16_t pins;
189  hal_gpio_pupd_t pupd;
191 
192 
197 typedef struct {
198  uint16_t pins;
199  hal_gpio_pupd_t pupd;
200  hal_gpio_out_speed_t out_speed;
201  hal_gpio_out_type_t out_type;
203 
204 
205 /* -- Public function declarations
206  * ------------------------------------------------------------------------- */
207 
212 void hal_gpio_reset(reg_gpio_t *port)
213 __attribute__((deprecated("Please use GPIOx_RESET().")));
214 
221 
228 
235 
243  hal_gpio_af_t af_mode,
244  hal_gpio_output_t init);
245 
251 uint16_t hal_gpio_input_read(reg_gpio_t *port);
252 
258 uint16_t hal_gpio_output_read(reg_gpio_t *port);
259 
265 void hal_gpio_output_write(reg_gpio_t *port, uint16_t value);
266 
272 void hal_gpio_bit_set(reg_gpio_t *port, uint16_t pins);
273 
279 void hal_gpio_bit_reset(reg_gpio_t *port, uint16_t pins);
280 
286 void hal_gpio_bit_toggle(reg_gpio_t *port, uint16_t pins);
287 
295 void hal_gpio_irq_set(reg_gpio_t *port,
296  uint16_t pins,
297  hal_gpio_trg_t edge,
298  hal_bool_t status);
299 
305 hal_bool_t hal_gpio_irq_status(uint16_t pin);
306 
311 void hal_gpio_irq_clear(uint16_t pin);
312 
313 #endif
hal_bool_t hal_gpio_irq_status(uint16_t pin)
Return status if specified GPIO interrupt.
hal_gpio_out_speed_t
Available GPIO output speed.
Definition: hal_gpio.h:47
void hal_gpio_bit_reset(reg_gpio_t *port, uint16_t pins)
Resets the specified pins of the output port.
Definition: hal_gpio.h:72
void hal_gpio_init_analog(reg_gpio_t *port, hal_gpio_input_t init)
Initializes a port as analog input.
void hal_gpio_init_input(reg_gpio_t *port, hal_gpio_input_t init)
Initializes a port as input.
Registries for STM32F4xx.
Definition: hal_gpio.h:177
hal_gpio_mode_t
Mode of GPIO port.
Definition: hal_gpio.h:35
hal_gpio_pin_t
Defines the available pins of a GPIO port.
Definition: hal_gpio.h:151
Definition: hal_gpio.h:38
Definition: hal_gpio.h:37
void hal_gpio_irq_set(reg_gpio_t *port, uint16_t pins, hal_gpio_trg_t edge, hal_bool_t status)
Enables interrupt on specified GPIO pins.
Definition: hal_gpio.h:49
hal_gpio_pupd_t
Available pull-up/down modes.
Definition: hal_gpio.h:69
void hal_gpio_irq_clear(uint16_t pin)
Clear specified GPIO interrupt.
Initialisation structure for gpio input mode.
Definition: hal_gpio.h:187
Definition: hal_gpio.h:71
Definition: hal_gpio.h:178
uint16_t hal_gpio_input_read(reg_gpio_t *port)
Reads the specified GPIO input data port.
void hal_gpio_bit_set(reg_gpio_t *port, uint16_t pins)
Sets the specified pins of the output port.
void hal_gpio_bit_toggle(reg_gpio_t *port, uint16_t pins)
Toggles the specified pins of the output port.
Definition: hal_gpio.h:179
Common #defines and typedefs.
Definition: hal_gpio.h:39
void hal_gpio_reset(reg_gpio_t *port) __attribute__((deprecated("Please use GPIOx_RESET().")))
Resets gpio port to default values.
Definition: hal_gpio.h:61
hal_gpio_af_t
Defines the available alternate function modes.
Definition: hal_gpio.h:80
Initialisation structure for gpio output and af mode.
Definition: hal_gpio.h:197
uint16_t hal_gpio_output_read(reg_gpio_t *port)
Reads the specified GPIO output data port.
hal_bool_t
Often used TRUE / FALSE type.
Definition: hal_common.h:31
hal_gpio_trg_t
Defines the polarity on wich the interrupt should be triggered.
Definition: hal_gpio.h:176
void hal_gpio_init_output(reg_gpio_t *port, hal_gpio_output_t init)
Initializes a port as output.
Definition: hal_gpio.h:51
Representation of GPIO register.
Definition: reg_stm32f4xx.h:194
void hal_gpio_init_alternate(reg_gpio_t *port, hal_gpio_af_t af_mode, hal_gpio_output_t init)
Initializes a port in alternate function mode.
void hal_gpio_output_write(reg_gpio_t *port, uint16_t value)
Writes to the specified GPIO output port.
hal_gpio_out_type_t
Output mode.
Definition: hal_gpio.h:59
Definition: hal_gpio.h:50