Prusa MINI Firmware overview
gpio.h
Go to the documentation of this file.
1 // gpio.h
2 #ifndef _GPIO_H
3 #define _GPIO_H
4 
5 #include "stm32f4xx_hal.h"
6 
7 //pin definitions (PA-PE)
8 #define PA0 0
9 #define PA1 1
10 #define PA2 2
11 #define PA3 3
12 #define PA4 4
13 #define PA5 5
14 #define PA6 6
15 #define PA7 7
16 #define PA8 8
17 #define PA9 9
18 #define PA10 10
19 #define PA11 11
20 #define PA12 12
21 #define PA13 13
22 #define PA14 14
23 #define PA15 15
24 #define PB0 16
25 #define PB1 17
26 #define PB2 18
27 #define PB3 19
28 #define PB4 20
29 #define PB5 21
30 #define PB6 22
31 #define PB7 23
32 #define PB8 24
33 #define PB9 25
34 #define PB10 26
35 #define PB11 27
36 #define PB12 28
37 #define PB13 29
38 #define PB14 30
39 #define PB15 31
40 #define PC0 32
41 #define PC1 33
42 #define PC2 34
43 #define PC3 35
44 #define PC4 36
45 #define PC5 37
46 #define PC6 38
47 #define PC7 39
48 #define PC8 40
49 #define PC9 41
50 #define PC10 42
51 #define PC11 43
52 #define PC12 44
53 #define PC13 45
54 #define PC14 46
55 #define PC15 47
56 #define PD0 48
57 #define PD1 49
58 #define PD2 50
59 #define PD3 51
60 #define PD4 52
61 #define PD5 53
62 #define PD6 54
63 #define PD7 55
64 #define PD8 56
65 #define PD9 57
66 #define PD10 58
67 #define PD11 59
68 #define PD12 60
69 #define PD13 61
70 #define PD14 62
71 #define PD15 63
72 #define PE0 64
73 #define PE1 65
74 #define PE2 66
75 #define PE3 67
76 #define PE4 68
77 #define PE5 69
78 #define PE6 70
79 #define PE7 71
80 #define PE8 72
81 #define PE9 73
82 #define PE10 74
83 #define PE11 75
84 #define PE12 76
85 #define PE13 77
86 #define PE14 78
87 #define PE15 79
88 
89 //port of pin8
90 static inline GPIO_TypeDef *gpio_port(uint8_t pin8) {
91  return (GPIO_TypeDef *)(GPIOA_BASE + (GPIOB_BASE - GPIOA_BASE) * (pin8 >> 4));
92 }
93 
94 static inline int gpio_get(uint8_t pin8) {
95  return (HAL_GPIO_ReadPin(gpio_port(pin8), (1 << (pin8 & 0x0f))) != GPIO_PIN_RESET) ? 1 : 0;
96 }
97 
98 static inline void gpio_set(uint8_t pin8, int state) {
99  HAL_GPIO_WritePin(gpio_port(pin8), (1 << (pin8 & 0x0f)), state ? GPIO_PIN_SET : GPIO_PIN_RESET);
100 }
101 
102 static inline void gpio_init(uint8_t pin8, uint32_t mode, uint32_t pull, uint32_t speed) {
103  GPIO_InitTypeDef GPIO_InitStruct = { 0 };
104  GPIO_InitStruct.Pin = (1 << (pin8 & 0x0f));
105  GPIO_InitStruct.Mode = mode;
106  GPIO_InitStruct.Pull = pull;
107  GPIO_InitStruct.Speed = speed;
108  HAL_GPIO_Init(gpio_port(pin8), &GPIO_InitStruct);
109 }
110 
111 #endif //_GPIO_H
GPIO_InitTypeDef::Mode
uint32_t Mode
Definition: stm32f4xx_hal_gpio.h:68
state
static volatile fsensor_t state
Definition: filament_sensor.c:23
GPIO_InitTypeDef::Pull
uint32_t Pull
Definition: stm32f4xx_hal_gpio.h:71
gpio_get
static int gpio_get(uint8_t pin8)
Definition: gpio.h:94
GPIO_PIN_SET
Definition: stm32f4xx_hal_gpio.h:87
GPIO_PIN_RESET
Definition: stm32f4xx_hal_gpio.h:86
gpio_init
static void gpio_init(uint8_t pin8, uint32_t mode, uint32_t pull, uint32_t speed)
Definition: gpio.h:102
HAL_GPIO_ReadPin
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
HAL_GPIO_Init
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
HAL_GPIO_WritePin
void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
uint8_t
const uint8_t[]
Definition: 404_html.c:3
stm32f4xx_hal.h
This file contains all the functions prototypes for the HAL module driver.
GPIO_InitTypeDef::Pin
uint32_t Pin
Definition: stm32f4xx_hal_gpio.h:65
GPIO_InitTypeDef::Speed
uint32_t Speed
Definition: stm32f4xx_hal_gpio.h:74
gpio_set
static void gpio_set(uint8_t pin8, int state)
Definition: gpio.h:98
mode
png_structrp int mode
Definition: png.h:1139
gpio_port
static GPIO_TypeDef * gpio_port(uint8_t pin8)
Definition: gpio.h:90
GPIO_InitTypeDef
GPIO Init structure definition.
Definition: stm32f4xx_hal_gpio.h:63