Create set-home.md
[u360gts.git] / src / main / drivers / gpio_stm32f30x.c
blob279f1acee305be580a7f7d734199ed463ce5869a
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight 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.
9 * Cleanflight 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.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #include <stdbool.h>
19 #include <stdint.h>
21 #include "platform.h"
23 #include "build_config.h"
25 #include "gpio.h"
27 #define MODE_OFFSET 0
28 #define PUPD_OFFSET 2
29 #define OUTPUT_OFFSET 4
31 #define MODE_MASK ((1|2) << MODE_OFFSET)
32 #define PUPD_MASK ((1|2) << PUPD_OFFSET)
33 #define OUTPUT_MASK ((1|2) << OUTPUT_OFFSET)
35 //#define GPIO_Speed_10MHz GPIO_Speed_Level_1 Fast Speed:10MHz
36 //#define GPIO_Speed_2MHz GPIO_Speed_Level_2 Medium Speed:2MHz
37 //#define GPIO_Speed_50MHz GPIO_Speed_Level_3 High Speed:50MHz
39 void gpioInit(GPIO_TypeDef *gpio, gpio_config_t *config)
41 GPIO_InitTypeDef GPIO_InitStructure;
43 uint32_t pinIndex;
44 for (pinIndex = 0; pinIndex < 16; pinIndex++) {
45 // are we doing this pin?
46 uint32_t pinMask = (0x1 << pinIndex);
47 if (config->pin & pinMask) {
49 GPIO_InitStructure.GPIO_Pin = pinMask;
50 GPIO_InitStructure.GPIO_Mode = (config->mode & MODE_MASK) >> MODE_OFFSET;
52 GPIOSpeed_TypeDef speed = GPIO_Speed_10MHz;
53 switch (config->speed) {
54 case Speed_10MHz:
55 speed = GPIO_Speed_Level_1;
56 break;
57 case Speed_2MHz:
58 speed = GPIO_Speed_Level_2;
59 break;
60 case Speed_50MHz:
61 speed = GPIO_Speed_Level_3;
62 break;
65 GPIO_InitStructure.GPIO_Speed = speed;
66 GPIO_InitStructure.GPIO_OType = (config->mode & OUTPUT_MASK) >> OUTPUT_OFFSET;
67 GPIO_InitStructure.GPIO_PuPd = (config->mode & PUPD_MASK) >> PUPD_OFFSET;
68 GPIO_Init(gpio, &GPIO_InitStructure);
73 void gpioExtiLineConfig(uint8_t portsrc, uint8_t pinsrc)
75 SYSCFG_EXTILineConfig(portsrc, pinsrc);