HAL/LL: Generic EXTI & trainer driver
Changes: - generic EXTI driver - generic trainer driver - relocated rotary encoder timer (simple 100us delay) from TIM4 to TIM12 - taranis & horus use now TIM4 for trainer pulses - serial driver handles periph clocks for UARTs TODO: - SBUS on heartbeat pin (USART or soft-serial)
This commit is contained in:
committed by
Raphael Coeffic
parent
d4cd3d0ddf
commit
042d5091f2
@@ -22,6 +22,46 @@
|
||||
#include "stm32_usart_driver.h"
|
||||
#include <string.h>
|
||||
|
||||
static void enable_usart_clock(USART_TypeDef* USARTx)
|
||||
{
|
||||
if (USARTx == USART1) {
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
|
||||
} else if (USARTx == USART2) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART2);
|
||||
} else if (USARTx == USART3) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART3);
|
||||
} else if (USARTx == UART4) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_UART4);
|
||||
} else if (USARTx == USART6) {
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART6);
|
||||
}
|
||||
#if defined(UART7) // does not exist on F2
|
||||
else if (USARTx == UART7) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_UART7);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void disable_usart_clock(USART_TypeDef* USARTx)
|
||||
{
|
||||
if (USARTx == USART1) {
|
||||
LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_USART1);
|
||||
} else if (USARTx == USART2) {
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_USART2);
|
||||
} else if (USARTx == USART3) {
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_USART3);
|
||||
} else if (USARTx == UART4) {
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_UART4);
|
||||
} else if (USARTx == USART6) {
|
||||
LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_USART6);
|
||||
}
|
||||
#if defined(UART7) // does not exist on F2
|
||||
else if (USARTx == UART7) {
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_UART7);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void stm32_usart_init_rx_dma(const stm32_usart_t* usart, void* buffer, uint32_t length)
|
||||
{
|
||||
if (!usart->rxDMA) return;
|
||||
@@ -67,6 +107,7 @@ void stm32_usart_deinit_rx_dma(const stm32_usart_t* usart)
|
||||
|
||||
void stm32_usart_init(const stm32_usart_t* usart, const etx_serial_init* params)
|
||||
{
|
||||
enable_usart_clock(usart->USARTx);
|
||||
LL_USART_DeInit(usart->USARTx);
|
||||
LL_GPIO_Init(usart->GPIOx, (LL_GPIO_InitTypeDef*)usart->pinInit);
|
||||
|
||||
@@ -142,6 +183,7 @@ void stm32_usart_deinit(const stm32_usart_t* usart)
|
||||
}
|
||||
NVIC_DisableIRQ(usart->IRQn);
|
||||
LL_USART_DeInit(usart->USARTx);
|
||||
disable_usart_clock(usart->USARTx);
|
||||
|
||||
// Reconfigure pin as output
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
|
||||
Reference in New Issue
Block a user