mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-22 07:45:29 +03:00
STM32F4: Drivers
This commit is contained in:
parent
96757c18a2
commit
7ca39bbde6
29 changed files with 2082 additions and 282 deletions
76
src/main/drivers/gpio_stm32f4xx.c
Normal file
76
src/main/drivers/gpio_stm32f4xx.c
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* This file is part of Cleanflight.
|
||||
*
|
||||
* Cleanflight is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Cleanflight is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#include "build_config.h"
|
||||
|
||||
#include "gpio.h"
|
||||
|
||||
#define MODE_OFFSET 0
|
||||
#define PUPD_OFFSET 2
|
||||
#define OUTPUT_OFFSET 4
|
||||
|
||||
#define MODE_MASK ((1|2))
|
||||
#define PUPD_MASK ((1|2))
|
||||
#define OUTPUT_MASK ((1|2))
|
||||
|
||||
//#define GPIO_Speed_10MHz GPIO_Speed_Level_1 Fast Speed:10MHz
|
||||
//#define GPIO_Speed_2MHz GPIO_Speed_Level_2 Medium Speed:2MHz
|
||||
//#define GPIO_Speed_50MHz GPIO_Speed_Level_3 High Speed:50MHz
|
||||
|
||||
void gpioInit(GPIO_TypeDef *gpio, gpio_config_t *config)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
uint32_t pinIndex;
|
||||
for (pinIndex = 0; pinIndex < 16; pinIndex++) {
|
||||
// are we doing this pin?
|
||||
uint32_t pinMask = (0x1 << pinIndex);
|
||||
if (config->pin & pinMask) {
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = pinMask;
|
||||
GPIO_InitStructure.GPIO_Mode = (config->mode >> MODE_OFFSET) & MODE_MASK;
|
||||
|
||||
GPIOSpeed_TypeDef speed = GPIO_Medium_Speed;
|
||||
switch (config->speed) {
|
||||
case Speed_10MHz:
|
||||
speed = GPIO_Medium_Speed;
|
||||
break;
|
||||
case Speed_2MHz:
|
||||
speed = GPIO_Low_Speed;
|
||||
break;
|
||||
case Speed_50MHz:
|
||||
speed = GPIO_Fast_Speed;
|
||||
break;
|
||||
}
|
||||
|
||||
GPIO_InitStructure.GPIO_Speed = speed;
|
||||
GPIO_InitStructure.GPIO_OType = (config->mode >> OUTPUT_OFFSET) & OUTPUT_MASK;
|
||||
GPIO_InitStructure.GPIO_PuPd = (config->mode >> PUPD_OFFSET) & PUPD_MASK;
|
||||
GPIO_Init(gpio, &GPIO_InitStructure);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void gpioExtiLineConfig(uint8_t portsrc, uint8_t pinsrc)
|
||||
{
|
||||
SYSCFG_EXTILineConfig(portsrc, pinsrc);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue