NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gpio.h
Go to the documentation of this file.
1 /*
2  * This file is part of Ninjaflight.
3  *
4  * Ninjaflight is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Ninjaflight is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Ninjaflight. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #pragma once
19 
20 #if defined(STM32F10X)
21 typedef enum
22 {
23  Mode_AIN = 0x0,
24  Mode_IN_FLOATING = 0x04,
25  Mode_IPD = 0x28,
26  Mode_IPU = 0x48,
27  Mode_Out_OD = 0x14,
28  Mode_Out_PP = 0x10,
29  Mode_AF_OD = 0x1C,
30  Mode_AF_PP = 0x18
31 } GPIO_Mode;
32 #endif
33 
34 #ifdef STM32F303xC
35 
36 /*
37 typedef enum
38 {
39  GPIO_Mode_IN = 0x00, // GPIO Input Mode
40  GPIO_Mode_OUT = 0x01, // GPIO Output Mode
41  GPIO_Mode_AF = 0x02, // GPIO Alternate function Mode
42  GPIO_Mode_AN = 0x03 // GPIO Analog In/Out Mode
43 }GPIOMode_TypeDef;
44 
45 typedef enum
46 {
47  GPIO_OType_PP = 0x00,
48  GPIO_OType_OD = 0x01
49 }GPIOOType_TypeDef;
50 
51 typedef enum
52 {
53  GPIO_PuPd_NOPULL = 0x00,
54  GPIO_PuPd_UP = 0x01,
55  GPIO_PuPd_DOWN = 0x02
56 }GPIOPuPd_TypeDef;
57 */
58 
59 typedef enum
60 {
61  Mode_AIN = (GPIO_PuPd_NOPULL << 2) | GPIO_Mode_AN,
62  Mode_IN_FLOATING = (GPIO_PuPd_NOPULL << 2) | GPIO_Mode_IN,
63  Mode_IPD = (GPIO_PuPd_DOWN << 2) | GPIO_Mode_IN,
64  Mode_IPU = (GPIO_PuPd_UP << 2) | GPIO_Mode_IN,
65  Mode_Out_OD = (GPIO_OType_OD << 4) | GPIO_Mode_OUT,
66  Mode_Out_PP = (GPIO_OType_PP << 4) | GPIO_Mode_OUT,
67  Mode_AF_OD = (GPIO_OType_OD << 4) | GPIO_Mode_AF,
68  Mode_AF_PP = (GPIO_OType_PP << 4) | GPIO_Mode_AF,
69  Mode_AF_PP_PD = (GPIO_OType_PP << 4) | (GPIO_PuPd_DOWN << 2) | GPIO_Mode_AF,
70  Mode_AF_PP_PU = (GPIO_OType_PP << 4) | (GPIO_PuPd_UP << 2) | GPIO_Mode_AF
71 } GPIO_Mode;
72 #endif
73 
74 typedef enum
75 {
79 } GPIO_Speed;
80 
81 typedef enum
82 {
83  Pin_0 = 0x0001,
84  Pin_1 = 0x0002,
85  Pin_2 = 0x0004,
86  Pin_3 = 0x0008,
87  Pin_4 = 0x0010,
88  Pin_5 = 0x0020,
89  Pin_6 = 0x0040,
90  Pin_7 = 0x0080,
91  Pin_8 = 0x0100,
92  Pin_9 = 0x0200,
93  Pin_10 = 0x0400,
94  Pin_11 = 0x0800,
95  Pin_12 = 0x1000,
96  Pin_13 = 0x2000,
97  Pin_14 = 0x4000,
98  Pin_15 = 0x8000,
99  Pin_All = 0xFFFF
100 } GPIO_Pin;
101 
102 typedef struct
103 {
104  uint16_t pin;
107 } gpio_config_t;
108 
109 #ifndef UNIT_TEST
110 static inline void digitalHi(GPIO_TypeDef *p, uint16_t i) { p->BSRR = i; }
111 static inline void digitalLo(GPIO_TypeDef *p, uint16_t i) { p->BRR = i; }
112 static inline void digitalToggle(GPIO_TypeDef *p, uint16_t i) { p->ODR ^= i; }
113 static inline uint16_t digitalIn(GPIO_TypeDef *p, uint16_t i) {return (uint16_t)(p->IDR & i); }
114 #endif
115 
117 void gpioExtiLineConfig(uint8_t portsrc, uint8_t pinsrc);
118 void gpioPinRemapConfig(uint32_t remap, bool enable);
Definition: gpio.h:95
GPIO_Mode mode
Definition: gpio.h:105
Definition: config.h:81
GPIO_Speed speed
Definition: gpio.h:106
Definition: gpio.h:85
Definition: gpio.h:98
Definition: gpio.h:92
Definition: gpio.h:96
GPIO_TypeDef * gpio
Definition: light_led_stm32f10x.c:32
Definition: platform.h:40
Definition: gpio.h:83
uint16_t pin
Definition: gpio.h:104
Definition: gpio.h:102
Definition: gpio.h:86
Definition: platform.h:43
Definition: gpio.h:88
Definition: gpio.h:97
Definition: gpio.h:84
void gpioPinRemapConfig(uint32_t remap, bool enable)
Definition: gpio_stm32f10x.c:72
Definition: gpio.h:87
Definition: gpio.h:78
GPIO_Pin
Definition: gpio.h:81
Definition: gpio.h:93
GPIO_Speed
Definition: gpio.h:74
Definition: gpio.h:90
Definition: gpio.h:94
Definition: gpio.h:76
GPIO_Mode
Definition: platform.h:37
Definition: gpio.h:77
void gpioExtiLineConfig(uint8_t portsrc, uint8_t pinsrc)
Definition: gpio_stm32f10x.c:57
Definition: gpio.h:99
void gpioInit(GPIO_TypeDef *gpio, const gpio_config_t *config)
Definition: gpio_stm32f10x.c:25
Definition: gpio.h:89
Definition: gpio.h:91