2017-05-13 08:21:47 -07:00
|
|
|
/*
|
|
|
|
Copyright (c) 2017 Daniel Fekete
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2017-04-09 21:55:07 -07:00
|
|
|
#if defined(STM32F0) || defined(STM32F2) || defined(STM32F3) || defined(STM32F4) || \
|
|
|
|
defined(STM32F7) || defined(STM32L0) || defined(STM32L1) || defined(STM32L4)
|
|
|
|
|
2017-04-11 11:32:37 -07:00
|
|
|
#include "stm32_gpio_af.h"
|
2017-04-09 21:55:07 -07:00
|
|
|
|
2017-04-17 11:57:28 -07:00
|
|
|
int8_t stm32AfGet(const stm32_af_pin_list_type list[], int size, const void *instance, const GPIO_TypeDef *port, const uint32_t pin) {
|
2017-04-09 21:55:07 -07:00
|
|
|
for(int i=0; i<size; i++) {
|
|
|
|
if (instance == list[i].instance
|
|
|
|
&& port == list[i].port
|
|
|
|
&& pin == list[i].pin) {
|
|
|
|
|
|
|
|
return list[i].alternate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-17 11:57:28 -07:00
|
|
|
void stm32AfInit(const stm32_af_pin_list_type list[], int size, const void *instance, GPIO_TypeDef *port, uint32_t pin, uint32_t mode, uint32_t pull) {
|
2017-04-16 06:40:46 -07:00
|
|
|
if (stm32_pwm_disable_callback != NULL) {
|
|
|
|
(*stm32_pwm_disable_callback)(port, pin);
|
|
|
|
}
|
2017-04-11 08:40:07 -07:00
|
|
|
if (port == NULL) {
|
2017-04-17 11:57:28 -07:00
|
|
|
port = stm32AfGetDefault(list, size, instance, &pin);
|
2017-04-11 08:40:07 -07:00
|
|
|
}
|
2017-05-22 22:01:24 -07:00
|
|
|
stm32GpioClockEnable(port);
|
2017-04-11 08:40:07 -07:00
|
|
|
|
|
|
|
GPIO_InitTypeDef GPIO_InitStruct;
|
|
|
|
GPIO_InitStruct.Pin = pin;
|
|
|
|
GPIO_InitStruct.Mode = mode;
|
|
|
|
GPIO_InitStruct.Pull = pull;
|
2017-06-13 08:18:05 -07:00
|
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; // Slow signal slew rate to keep noise to minimum
|
2017-04-17 11:57:28 -07:00
|
|
|
GPIO_InitStruct.Alternate = stm32AfGet(list, size, instance, port, pin);
|
2017-04-11 08:40:07 -07:00
|
|
|
HAL_GPIO_Init(port, &GPIO_InitStruct);
|
2017-04-09 21:55:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|