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
@@ -84,6 +84,7 @@ set(BOOTLOADER_SRC
|
||||
../usb_bsp.c
|
||||
../usb_driver.cpp
|
||||
../flash_driver.cpp
|
||||
../stm32_exti_driver.cpp
|
||||
init.c
|
||||
boot.cpp
|
||||
bin_files.cpp
|
||||
|
||||
@@ -217,15 +217,12 @@ void bootloaderInitApp()
|
||||
|
||||
RCC_APB1PeriphClockCmd(ROTARY_ENCODER_RCC_APB1Periph | LCD_RCC_APB1Periph |
|
||||
BACKLIGHT_RCC_APB1Periph |
|
||||
INTERRUPT_xMS_RCC_APB1Periph |
|
||||
AUX_SERIAL_RCC_APB1Periph |
|
||||
AUX2_SERIAL_RCC_APB1Periph | SD_RCC_APB1Periph,
|
||||
INTERRUPT_xMS_RCC_APB1Periph | SD_RCC_APB1Periph,
|
||||
ENABLE);
|
||||
|
||||
RCC_APB2PeriphClockCmd(LCD_RCC_APB2Periph | BACKLIGHT_RCC_APB2Periph |
|
||||
RCC_APB2Periph_SYSCFG | AUX_SERIAL_RCC_APB2Periph |
|
||||
AUX2_SERIAL_RCC_APB2Periph,
|
||||
ENABLE);
|
||||
RCC_APB2PeriphClockCmd(
|
||||
LCD_RCC_APB2Periph | BACKLIGHT_RCC_APB2Periph | RCC_APB2Periph_SYSCFG,
|
||||
ENABLE);
|
||||
|
||||
#if defined(HAVE_BOARD_BOOTLOADER_INIT)
|
||||
boardBootloaderInit();
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "stm32_exti_driver.h"
|
||||
#include "mixer_scheduler.h"
|
||||
#include "board.h"
|
||||
#include "debug.h"
|
||||
@@ -32,6 +33,17 @@
|
||||
|
||||
volatile HeartbeatCapture heartbeatCapture;
|
||||
|
||||
static void trigger_intmodule_heartbeat()
|
||||
{
|
||||
heartbeatCapture.timestamp = getTmr2MHz();
|
||||
#if defined(DEBUG_LATENCY)
|
||||
heartbeatCapture.count++;
|
||||
#endif
|
||||
|
||||
mixerSchedulerResetTimer();
|
||||
mixerSchedulerISRTrigger();
|
||||
}
|
||||
|
||||
void init_intmodule_heartbeat()
|
||||
{
|
||||
TRACE("init_intmodule_heartbeat");
|
||||
@@ -54,11 +66,7 @@ void init_intmodule_heartbeat()
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init(&EXTI_InitStructure);
|
||||
|
||||
NVIC_SetPriority(INTMODULE_HEARTBEAT_EXTI_IRQn,
|
||||
// Highest priority interrupt
|
||||
configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
|
||||
|
||||
NVIC_EnableIRQ(INTMODULE_HEARTBEAT_EXTI_IRQn);
|
||||
stm32_exti_enable(INTMODULE_HEARTBEAT_EXTI_LINE, trigger_intmodule_heartbeat);
|
||||
heartbeatCapture.valid = true;
|
||||
}
|
||||
|
||||
@@ -67,9 +75,7 @@ void stop_intmodule_heartbeat()
|
||||
TRACE("stop_intmodule_heartbeat");
|
||||
heartbeatCapture.valid = false;
|
||||
|
||||
#if !defined(INTMODULE_HEARTBEAT_REUSE_INTERRUPT_ROTARY_ENCODER)
|
||||
NVIC_DisableIRQ(INTMODULE_HEARTBEAT_EXTI_IRQn);
|
||||
#endif
|
||||
stm32_exti_disable(INTMODULE_HEARTBEAT_EXTI_LINE);
|
||||
|
||||
EXTI_InitTypeDef EXTI_InitStructure;
|
||||
EXTI_StructInit(&EXTI_InitStructure);
|
||||
@@ -80,27 +86,4 @@ void stop_intmodule_heartbeat()
|
||||
EXTI_Init(&EXTI_InitStructure);
|
||||
}
|
||||
|
||||
void check_intmodule_heartbeat()
|
||||
{
|
||||
if (EXTI_GetITStatus(INTMODULE_HEARTBEAT_EXTI_LINE) != RESET) {
|
||||
heartbeatCapture.timestamp = getTmr2MHz();
|
||||
#if defined(DEBUG_LATENCY)
|
||||
heartbeatCapture.count++;
|
||||
#endif
|
||||
EXTI_ClearITPendingBit(INTMODULE_HEARTBEAT_EXTI_LINE);
|
||||
|
||||
mixerSchedulerResetTimer();
|
||||
mixerSchedulerISRTrigger();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(INTMODULE_HEARTBEAT) && !defined(INTMODULE_HEARTBEAT_REUSE_INTERRUPT_ROTARY_ENCODER)
|
||||
extern "C" void INTMODULE_HEARTBEAT_EXTI_IRQHandler()
|
||||
{
|
||||
check_intmodule_heartbeat();
|
||||
#if defined(TELEMETRY_EXTI_REUSE_INTERRUPT_INTMODULE_HEARTBEAT)
|
||||
check_telemetry_exti();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -70,22 +70,11 @@ void pwrInit()
|
||||
hardwareOptions.pcbrev = PCBREV_VALUE();
|
||||
#endif
|
||||
|
||||
#if defined(TRAINER_DETECT_GPIO_PIN)
|
||||
GPIO_InitStructure.GPIO_Pin = TRAINER_DETECT_GPIO_PIN;
|
||||
GPIO_Init(TRAINER_DETECT_GPIO, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
#if defined(SD_PRESENT_GPIO_PIN)
|
||||
GPIO_ResetBits(SD_PRESENT_GPIO, SD_PRESENT_GPIO_PIN);
|
||||
GPIO_InitStructure.GPIO_Pin = SD_PRESENT_GPIO_PIN;
|
||||
GPIO_Init(SD_PRESENT_GPIO, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
#if defined(INTMODULE_USART) && defined(TRAINER_MODULE_CPPM)
|
||||
GPIO_SetBits(TRAINER_MODULE_CPPM_GPIO, TRAINER_MODULE_CPPM_GPIO_PIN);
|
||||
GPIO_InitStructure.GPIO_Pin = TRAINER_MODULE_CPPM_GPIO_PIN;
|
||||
GPIO_Init(TRAINER_MODULE_CPPM_GPIO, &GPIO_InitStructure);
|
||||
#endif
|
||||
}
|
||||
|
||||
void pwrOn()
|
||||
|
||||
@@ -19,10 +19,11 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "stm32_exti_driver.h"
|
||||
#include "board.h"
|
||||
|
||||
#include "hal.h"
|
||||
#include "board_common.h"
|
||||
#include "heartbeat_driver.h"
|
||||
|
||||
#if !defined(BOOT)
|
||||
#include "opentx.h"
|
||||
@@ -31,51 +32,6 @@
|
||||
volatile rotenc_t rotencValue = 0;
|
||||
volatile uint32_t rotencDt = 0;
|
||||
|
||||
void rotaryEncoderInit()
|
||||
{
|
||||
ROTARY_ENCODER_TIMER->ARR = 99; // 100uS
|
||||
ROTARY_ENCODER_TIMER->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 1000000 - 1; // 1uS
|
||||
ROTARY_ENCODER_TIMER->CCER = 0;
|
||||
ROTARY_ENCODER_TIMER->CCMR1 = 0;
|
||||
ROTARY_ENCODER_TIMER->EGR = 0;
|
||||
ROTARY_ENCODER_TIMER->CR1 = 0;
|
||||
ROTARY_ENCODER_TIMER->DIER |= TIM_DIER_UIE;
|
||||
|
||||
SYSCFG_EXTILineConfig(ROTARY_ENCODER_EXTI_PortSource, ROTARY_ENCODER_EXTI_PinSource1);
|
||||
|
||||
#if defined(ROTARY_ENCODER_EXTI_LINE2)
|
||||
SYSCFG_EXTILineConfig(ROTARY_ENCODER_EXTI_PortSource, ROTARY_ENCODER_EXTI_PinSource2);
|
||||
#endif
|
||||
|
||||
EXTI_InitTypeDef EXTI_InitStructure;
|
||||
EXTI_StructInit(&EXTI_InitStructure);
|
||||
EXTI_InitStructure.EXTI_Line = ROTARY_ENCODER_EXTI_LINE1;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init(&EXTI_InitStructure);
|
||||
|
||||
#if defined(ROTARY_ENCODER_EXTI_LINE2)
|
||||
EXTI_InitStructure.EXTI_Line = ROTARY_ENCODER_EXTI_LINE2;
|
||||
EXTI_Init(&EXTI_InitStructure);
|
||||
#endif
|
||||
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
NVIC_InitStructure.NVIC_IRQChannel = ROTARY_ENCODER_EXTI_IRQn1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 8;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; /* Not used as 4 bits are used for the pre-emption priority. */;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
#if defined(ROTARY_ENCODER_EXTI_IRQn2)
|
||||
NVIC_InitStructure.NVIC_IRQChannel = ROTARY_ENCODER_EXTI_IRQn2;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
#endif
|
||||
|
||||
NVIC_EnableIRQ(ROTARY_ENCODER_TIMER_IRQn);
|
||||
NVIC_SetPriority(ROTARY_ENCODER_TIMER_IRQn, 7);
|
||||
}
|
||||
|
||||
#if defined(BOOT)
|
||||
#define INC_ROT 1
|
||||
#define INC_ROT_2 2
|
||||
@@ -147,39 +103,39 @@ void rotaryEncoderStartDelay()
|
||||
ROTARY_ENCODER_TIMER->CR1 = TIM_CR1_CEN | TIM_CR1_URS;
|
||||
}
|
||||
|
||||
extern "C" void ROTARY_ENCODER_EXTI_IRQHandler1(void)
|
||||
void rotaryEncoderInit()
|
||||
{
|
||||
#if !defined(BOOT) && defined(TELEMETRY_EXTI_REUSE_INTERRUPT_ROTARY_ENCODER)
|
||||
check_telemetry_exti();
|
||||
#endif
|
||||
rotencPosition = ROTARY_ENCODER_POSITION();
|
||||
|
||||
if (EXTI_GetITStatus(ROTARY_ENCODER_EXTI_LINE1) != RESET) {
|
||||
rotaryEncoderStartDelay();
|
||||
EXTI_ClearITPendingBit(ROTARY_ENCODER_EXTI_LINE1);
|
||||
}
|
||||
ROTARY_ENCODER_TIMER->ARR = 99; // 100uS
|
||||
ROTARY_ENCODER_TIMER->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 1000000 - 1; // 1uS
|
||||
ROTARY_ENCODER_TIMER->CCER = 0;
|
||||
ROTARY_ENCODER_TIMER->CCMR1 = 0;
|
||||
ROTARY_ENCODER_TIMER->EGR = 0;
|
||||
ROTARY_ENCODER_TIMER->CR1 = 0;
|
||||
ROTARY_ENCODER_TIMER->DIER |= TIM_DIER_UIE;
|
||||
|
||||
#if !defined(ROTARY_ENCODER_EXTI_IRQn2)
|
||||
if (EXTI_GetITStatus(ROTARY_ENCODER_EXTI_LINE2) != RESET) {
|
||||
rotaryEncoderStartDelay();
|
||||
EXTI_ClearITPendingBit(ROTARY_ENCODER_EXTI_LINE2);
|
||||
}
|
||||
#endif
|
||||
SYSCFG_EXTILineConfig(ROTARY_ENCODER_EXTI_PortSource, ROTARY_ENCODER_EXTI_PinSource1);
|
||||
SYSCFG_EXTILineConfig(ROTARY_ENCODER_EXTI_PortSource, ROTARY_ENCODER_EXTI_PinSource2);
|
||||
|
||||
#if !defined(BOOT) && defined(INTMODULE_HEARTBEAT_REUSE_INTERRUPT_ROTARY_ENCODER)
|
||||
check_intmodule_heartbeat();
|
||||
#endif
|
||||
EXTI_InitTypeDef EXTI_InitStructure;
|
||||
EXTI_StructInit(&EXTI_InitStructure);
|
||||
EXTI_InitStructure.EXTI_Line = ROTARY_ENCODER_EXTI_LINE1;
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init(&EXTI_InitStructure);
|
||||
|
||||
EXTI_InitStructure.EXTI_Line = ROTARY_ENCODER_EXTI_LINE2;
|
||||
EXTI_Init(&EXTI_InitStructure);
|
||||
|
||||
stm32_exti_enable(ROTARY_ENCODER_EXTI_LINE1, rotaryEncoderStartDelay);
|
||||
stm32_exti_enable(ROTARY_ENCODER_EXTI_LINE2, rotaryEncoderStartDelay);
|
||||
|
||||
NVIC_EnableIRQ(ROTARY_ENCODER_TIMER_IRQn);
|
||||
NVIC_SetPriority(ROTARY_ENCODER_TIMER_IRQn, 7);
|
||||
}
|
||||
|
||||
#if defined(ROTARY_ENCODER_EXTI_IRQn2)
|
||||
extern "C" void ROTARY_ENCODER_EXTI_IRQHandler2(void)
|
||||
{
|
||||
if (EXTI_GetITStatus(ROTARY_ENCODER_EXTI_LINE2) != RESET) {
|
||||
rotaryEncoderStartDelay();
|
||||
EXTI_ClearITPendingBit(ROTARY_ENCODER_EXTI_LINE2);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
extern "C" void ROTARY_ENCODER_TIMER_IRQHandler(void)
|
||||
{
|
||||
ROTARY_ENCODER_TIMER->SR &= ~TIM_SR_UIF;
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program 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.
|
||||
*/
|
||||
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_exti_driver.h"
|
||||
#include "hal.h"
|
||||
|
||||
#define _EXTI_HANDLERS(irq_name) _handlers_ ## irq_name
|
||||
|
||||
#define _PR_MASK(first, last) (((1 << (last - first + 1))-1))
|
||||
|
||||
#define _DEFINE_EXTI_IRQ_HANDLER(irq_name, first, last) \
|
||||
static stm32_exti_handler_t _EXTI_HANDLERS(irq_name) [last - first + 1] = { 0 }; \
|
||||
extern "C" void irq_name ## Handler() \
|
||||
{ \
|
||||
/* Read Pending register */ \
|
||||
/* (shifted by start line) */ \
|
||||
uint32_t pr = LL_EXTI_ReadReg(PR) >> first; \
|
||||
pr &= _PR_MASK(first,last); \
|
||||
while (pr) { \
|
||||
uint32_t i = POSITION_VAL(pr); \
|
||||
/* Clear Pending Flag */ \
|
||||
LL_EXTI_ClearFlag_0_31(1 << (first + i)); \
|
||||
pr &= ~(1 << i); \
|
||||
/* ... and trigger handler */ \
|
||||
stm32_exti_handler_t h_fct = _EXTI_HANDLERS(irq_name) [i]; \
|
||||
if (h_fct) h_fct(); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define _SET_EXTI_IRQ_HANDLER(irq_name, first, last, line_pos, cb) \
|
||||
if (line_pos >= first && line_pos <= last) { \
|
||||
_EXTI_HANDLERS(irq_name)[line_pos - first] = cb; \
|
||||
NVIC_SetPriority(irq_name ## n, irq_name ## _Priority); \
|
||||
NVIC_EnableIRQ(irq_name ## n); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define _CLEAR_EXTI_IRQ_HANDLER(irq_name, first, last, line_pos) \
|
||||
if (line_pos >= first && line_pos <= last) { \
|
||||
_EXTI_HANDLERS(irq_name)[line_pos - first] = nullptr; \
|
||||
if (!_has_handler(_EXTI_HANDLERS(irq_name), last - first + 1)) { \
|
||||
NVIC_DisableIRQ(irq_name ## n); \
|
||||
} \
|
||||
return; \
|
||||
}
|
||||
|
||||
#if defined(USE_EXTI1_IRQ)
|
||||
_DEFINE_EXTI_IRQ_HANDLER(EXTI1_IRQ, 1, 1);
|
||||
#endif
|
||||
|
||||
#if defined(USE_EXTI9_5_IRQ)
|
||||
_DEFINE_EXTI_IRQ_HANDLER(EXTI9_5_IRQ, 5, 9);
|
||||
#endif
|
||||
|
||||
#if defined(USE_EXTI15_10_IRQ)
|
||||
_DEFINE_EXTI_IRQ_HANDLER(EXTI15_10_IRQ, 10, 15);
|
||||
#endif
|
||||
|
||||
static bool _has_handler(stm32_exti_handler_t* _handlers, uint8_t len)
|
||||
{
|
||||
for (uint8_t i = 0; i < len; i++)
|
||||
if (_handlers[i]) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void stm32_exti_enable(uint32_t line, stm32_exti_handler_t cb)
|
||||
{
|
||||
uint32_t line_pos = POSITION_VAL(line);
|
||||
|
||||
#if defined(USE_EXTI1_IRQ)
|
||||
_SET_EXTI_IRQ_HANDLER(EXTI1_IRQ, 1, 1, line_pos, cb);
|
||||
#endif
|
||||
|
||||
#if defined(USE_EXTI9_5_IRQ)
|
||||
_SET_EXTI_IRQ_HANDLER(EXTI9_5_IRQ, 5, 9, line_pos, cb);
|
||||
#endif
|
||||
|
||||
#if defined(USE_EXTI15_10_IRQ)
|
||||
_SET_EXTI_IRQ_HANDLER(EXTI15_10_IRQ, 10, 15, line_pos, cb);
|
||||
#endif
|
||||
}
|
||||
|
||||
void stm32_exti_disable(uint32_t line)
|
||||
{
|
||||
uint32_t line_pos = POSITION_VAL(line);
|
||||
|
||||
#if defined(USE_EXTI1_IRQ)
|
||||
_CLEAR_EXTI_IRQ_HANDLER(EXTI1_IRQ, 1, 1, line_pos);
|
||||
#endif
|
||||
|
||||
#if defined(USE_EXTI9_5_IRQ)
|
||||
_CLEAR_EXTI_IRQ_HANDLER(EXTI9_5_IRQ, 5, 9, line_pos);
|
||||
#endif
|
||||
|
||||
#if defined(USE_EXTI15_10_IRQ)
|
||||
_CLEAR_EXTI_IRQ_HANDLER(EXTI15_10_IRQ, 10, 15, line_pos);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Prior to use this driver, please make sure the proper macros are defined in hal.h:
|
||||
//
|
||||
// - If 'USE_EXTIm_n_IRQ' is defined,
|
||||
// 'EXTIm_n_IRQHandler' will be handled by this driver.
|
||||
//
|
||||
// - If 'USE_EXTIn_IRQ' is defined,
|
||||
// 'EXTIn_IRQHandler' will be handled by this driver.
|
||||
|
||||
typedef void (*stm32_exti_handler_t)();
|
||||
|
||||
// Set callback and enable IRQ
|
||||
void stm32_exti_enable(uint32_t line, stm32_exti_handler_t cb);
|
||||
|
||||
// Reset callback and disable IRQ if no more handlers
|
||||
void stm32_exti_disable(uint32_t line);
|
||||
@@ -22,6 +22,21 @@
|
||||
#include "stm32_pulse_driver.h"
|
||||
#include "definitions.h"
|
||||
|
||||
static void enable_tim_clock(TIM_TypeDef* TIMx)
|
||||
{
|
||||
if (TIMx == TIM1) {
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM1);
|
||||
} else if (TIMx == TIM2) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
|
||||
} else if (TIMx == TIM3) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
|
||||
} else if (TIMx == TIM4) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4);
|
||||
} else if (TIMx == TIM8) {
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM8);
|
||||
}
|
||||
}
|
||||
|
||||
void stm32_pulse_init(const stm32_pulse_timer_t* tim)
|
||||
{
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
@@ -37,33 +52,56 @@ void stm32_pulse_init(const stm32_pulse_timer_t* tim)
|
||||
// 0.5uS (2Mhz)
|
||||
timInit.Prescaler = tim->TIM_Prescaler;
|
||||
timInit.Autoreload = 65535;
|
||||
|
||||
enable_tim_clock(tim->TIMx);
|
||||
LL_TIM_Init(tim->TIMx, &timInit);
|
||||
|
||||
// Enable DMA IRQ
|
||||
NVIC_EnableIRQ(tim->DMA_IRQn);
|
||||
NVIC_SetPriority(tim->DMA_IRQn, 7);
|
||||
if (tim->DMAx) {
|
||||
// Enable DMA IRQ
|
||||
NVIC_EnableIRQ(tim->DMA_IRQn);
|
||||
NVIC_SetPriority(tim->DMA_IRQn, 7);
|
||||
}
|
||||
|
||||
// Enable timer IRQ
|
||||
NVIC_EnableIRQ(tim->TIM_IRQn);
|
||||
NVIC_SetPriority(tim->TIM_IRQn, 7);
|
||||
}
|
||||
|
||||
static void disable_tim_clock(TIM_TypeDef* TIMx)
|
||||
{
|
||||
if (TIMx == TIM1) {
|
||||
LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_TIM1);
|
||||
} else if (TIMx == TIM2) {
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_TIM2);
|
||||
} else if (TIMx == TIM3) {
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_TIM3);
|
||||
} else if (TIMx == TIM4) {
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_TIM4);
|
||||
} else if (TIMx == TIM8) {
|
||||
LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_TIM8);
|
||||
}
|
||||
}
|
||||
|
||||
void stm32_pulse_deinit(const stm32_pulse_timer_t* tim)
|
||||
{
|
||||
// Disable IRQs
|
||||
NVIC_DisableIRQ(tim->DMA_IRQn);
|
||||
if (tim->DMAx) {
|
||||
NVIC_DisableIRQ(tim->DMA_IRQn);
|
||||
}
|
||||
NVIC_DisableIRQ(tim->TIM_IRQn);
|
||||
|
||||
// De-init DMA & timer
|
||||
LL_DMA_DeInit(tim->DMAx, tim->DMA_Stream);
|
||||
LL_TIM_DeInit(tim->TIMx);
|
||||
|
||||
// Reconfigure pin as output
|
||||
if (tim->DMAx) {
|
||||
LL_DMA_DeInit(tim->DMAx, tim->DMA_Stream);
|
||||
}
|
||||
LL_TIM_DeInit(tim->TIMx);
|
||||
disable_tim_clock(tim->TIMx);
|
||||
|
||||
// Reconfigure pin as input
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
|
||||
pinInit.Pin = tim->GPIO_Pin;
|
||||
pinInit.Mode = LL_GPIO_MODE_OUTPUT;
|
||||
pinInit.Mode = LL_GPIO_MODE_INPUT;
|
||||
LL_GPIO_Init(tim->GPIOx, &pinInit);
|
||||
}
|
||||
|
||||
@@ -140,9 +178,15 @@ static void set_compare_reg(const stm32_pulse_timer_t* tim, uint32_t val)
|
||||
case LL_TIM_CHANNEL_CH1N:
|
||||
LL_TIM_OC_SetCompareCH1(tim->TIMx, val);
|
||||
break;
|
||||
case LL_TIM_CHANNEL_CH2:
|
||||
LL_TIM_OC_SetCompareCH2(tim->TIMx, val);
|
||||
break;
|
||||
case LL_TIM_CHANNEL_CH3:
|
||||
LL_TIM_OC_SetCompareCH3(tim->TIMx, val);
|
||||
break;
|
||||
case LL_TIM_CHANNEL_CH4:
|
||||
LL_TIM_OC_SetCompareCH4(tim->TIMx, val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,3 +311,13 @@ void stm32_pulse_tim_update_isr(const stm32_pulse_timer_t* tim)
|
||||
// Halt pulses by forcing to inactive level
|
||||
set_oc_mode(tim, LL_TIM_OCMODE_FORCED_INACTIVE);
|
||||
}
|
||||
|
||||
// input mode
|
||||
void stm32_pulse_config_input(const stm32_pulse_timer_t* tim)
|
||||
{
|
||||
LL_TIM_IC_InitTypeDef icInit;
|
||||
LL_TIM_IC_StructInit(&icInit);
|
||||
icInit.ICActiveInput = LL_TIM_ACTIVEINPUT_DIRECTTI;
|
||||
icInit.ICFilter = LL_TIM_IC_FILTER_FDIV1_N8;
|
||||
LL_TIM_IC_Init(tim->TIMx, tim->TIM_Channel, &icInit);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@ struct stm32_pulse_timer_t {
|
||||
void stm32_pulse_init(const stm32_pulse_timer_t* tim);
|
||||
void stm32_pulse_deinit(const stm32_pulse_timer_t* tim);
|
||||
|
||||
void stm32_pulse_config_input(const stm32_pulse_timer_t* tim);
|
||||
|
||||
void stm32_pulse_config_output(const stm32_pulse_timer_t* tim, bool polarity,
|
||||
uint32_t ocmode, uint32_t cmp_val);
|
||||
|
||||
@@ -64,7 +66,8 @@ void stm32_pulse_tim_update_isr(const stm32_pulse_timer_t* tim);
|
||||
|
||||
#define __STM32_PULSE_IS_TIMER_CHANNEL_SUPPORTED(ch) \
|
||||
((ch) == LL_TIM_CHANNEL_CH1 || (ch) == LL_TIM_CHANNEL_CH1N || \
|
||||
(ch) == LL_TIM_CHANNEL_CH3)
|
||||
(ch) == LL_TIM_CHANNEL_CH2 || (ch) == LL_TIM_CHANNEL_CH3 || \
|
||||
(ch) == LL_TIM_CHANNEL_CH4)
|
||||
|
||||
#define __STM32_PULSE_IS_DMA_STREAM_SUPPORTED(stream) \
|
||||
((stream) == LL_DMA_STREAM_1 || (stream) == LL_DMA_STREAM_5 || \
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -0,0 +1,340 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program 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.
|
||||
*/
|
||||
|
||||
#include "stm32_pulse_driver.h"
|
||||
#include "hal/trainer_driver.h"
|
||||
#include "hal.h"
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#define __IS_TRAINER_TIMER_OUT_CHANNEL_SUPPORTED(ch) \
|
||||
(((ch) == LL_TIM_CHANNEL_CH1 || (ch) == LL_TIM_CHANNEL_CH2 || \
|
||||
(ch) == LL_TIM_CHANNEL_CH3 || (ch) == LL_TIM_CHANNEL_CH4) && \
|
||||
__STM32_PULSE_IS_TIMER_CHANNEL_SUPPORTED(ch))
|
||||
|
||||
#define __IS_TRAINER_TIMER_IN_CHANNEL_SUPPORTED(ch) \
|
||||
((ch) == LL_TIM_CHANNEL_CH1 || (ch) == LL_TIM_CHANNEL_CH2 || \
|
||||
(ch) == LL_TIM_CHANNEL_CH3 || (ch) == LL_TIM_CHANNEL_CH4)
|
||||
|
||||
#if defined(TRAINER_GPIO)
|
||||
|
||||
static_assert(__IS_TRAINER_TIMER_OUT_CHANNEL_SUPPORTED(TRAINER_OUT_TIMER_Channel),
|
||||
"Unsupported trainer timer output channel");
|
||||
|
||||
static_assert(__IS_TRAINER_TIMER_IN_CHANNEL_SUPPORTED(TRAINER_IN_TIMER_Channel),
|
||||
"Unsupported trainer timer input channel");
|
||||
#else
|
||||
void init_trainer_ppm() {}
|
||||
void stop_trainer_ppm() {}
|
||||
void init_trainer_capture() {}
|
||||
void stop_trainer_capture() {}
|
||||
#endif
|
||||
|
||||
static void (*_trainer_timer_isr)();
|
||||
static const stm32_pulse_timer_t* _trainer_timer;
|
||||
|
||||
void init_trainer()
|
||||
{
|
||||
#if defined(TRAINER_DETECT_GPIO_PIN)
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
|
||||
pinInit.Pin = TRAINER_DETECT_GPIO_PIN;
|
||||
pinInit.Mode = LL_GPIO_MODE_INPUT;
|
||||
pinInit.Pull = LL_GPIO_PULL_UP;
|
||||
LL_GPIO_Init(TRAINER_DETECT_GPIO, &pinInit);
|
||||
#endif
|
||||
|
||||
_trainer_timer = nullptr;
|
||||
_trainer_timer_isr = nullptr;
|
||||
}
|
||||
|
||||
static inline bool trainer_check_isr_flag(const stm32_pulse_timer_t* tim)
|
||||
{
|
||||
switch (tim->TIM_Channel) {
|
||||
case LL_TIM_CHANNEL_CH1:
|
||||
if (LL_TIM_IsEnabledIT_CC1(tim->TIMx) &&
|
||||
LL_TIM_IsActiveFlag_CC1(tim->TIMx)) {
|
||||
LL_TIM_ClearFlag_CC1(tim->TIMx);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case LL_TIM_CHANNEL_CH2:
|
||||
if (LL_TIM_IsEnabledIT_CC2(tim->TIMx) &&
|
||||
LL_TIM_IsActiveFlag_CC2(tim->TIMx)) {
|
||||
LL_TIM_ClearFlag_CC2(tim->TIMx);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case LL_TIM_CHANNEL_CH3:
|
||||
if (LL_TIM_IsEnabledIT_CC3(tim->TIMx) &&
|
||||
LL_TIM_IsActiveFlag_CC3(tim->TIMx)) {
|
||||
LL_TIM_ClearFlag_CC3(tim->TIMx);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case LL_TIM_CHANNEL_CH4:
|
||||
if (LL_TIM_IsEnabledIT_CC4(tim->TIMx) &&
|
||||
LL_TIM_IsActiveFlag_CC4(tim->TIMx)) {
|
||||
LL_TIM_ClearFlag_CC4(tim->TIMx);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void trainer_in_isr()
|
||||
{
|
||||
// proceed only if the channel flag was set
|
||||
// and the IRQ was enabled
|
||||
if (!trainer_check_isr_flag(_trainer_timer))
|
||||
return;
|
||||
|
||||
uint16_t capture = 0;
|
||||
switch(_trainer_timer->TIM_Channel) {
|
||||
case LL_TIM_CHANNEL_CH1:
|
||||
capture = LL_TIM_IC_GetCaptureCH1(_trainer_timer->TIMx);
|
||||
break;
|
||||
case LL_TIM_CHANNEL_CH2:
|
||||
capture = LL_TIM_IC_GetCaptureCH2(_trainer_timer->TIMx);
|
||||
break;
|
||||
case LL_TIM_CHANNEL_CH3:
|
||||
capture = LL_TIM_IC_GetCaptureCH3(_trainer_timer->TIMx);
|
||||
break;
|
||||
case LL_TIM_CHANNEL_CH4:
|
||||
capture = LL_TIM_IC_GetCaptureCH4(_trainer_timer->TIMx);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
captureTrainerPulses(capture);
|
||||
}
|
||||
|
||||
static void _stop_trainer(const stm32_pulse_timer_t* tim)
|
||||
{
|
||||
stm32_pulse_deinit(tim);
|
||||
_trainer_timer_isr = nullptr;
|
||||
_trainer_timer = nullptr;
|
||||
}
|
||||
|
||||
static void _init_trainer_capture(const stm32_pulse_timer_t* tim)
|
||||
{
|
||||
// set proper ISR handler first
|
||||
_trainer_timer = tim;
|
||||
_trainer_timer_isr = trainer_in_isr;
|
||||
|
||||
stm32_pulse_init(tim);
|
||||
stm32_pulse_config_input(tim);
|
||||
|
||||
switch (tim->TIM_Channel) {
|
||||
case LL_TIM_CHANNEL_CH1:
|
||||
LL_TIM_EnableIT_CC1(tim->TIMx);
|
||||
break;
|
||||
case LL_TIM_CHANNEL_CH2:
|
||||
LL_TIM_EnableIT_CC2(tim->TIMx);
|
||||
break;
|
||||
case LL_TIM_CHANNEL_CH3:
|
||||
LL_TIM_EnableIT_CC1(tim->TIMx);
|
||||
break;
|
||||
case LL_TIM_CHANNEL_CH4:
|
||||
LL_TIM_EnableIT_CC2(tim->TIMx);
|
||||
break;
|
||||
}
|
||||
|
||||
LL_TIM_EnableCounter(tim->TIMx);
|
||||
}
|
||||
|
||||
#if defined(TRAINER_GPIO)
|
||||
|
||||
static const stm32_pulse_timer_t trainerOutputTimer = {
|
||||
.GPIOx = TRAINER_GPIO,
|
||||
.GPIO_Pin = TRAINER_OUT_GPIO_PIN,
|
||||
.GPIO_Alternate = TRAINER_GPIO_AF,
|
||||
.TIMx = TRAINER_TIMER,
|
||||
.TIM_Prescaler = __LL_TIM_CALC_PSC(TRAINER_TIMER_FREQ, 2000000),
|
||||
.TIM_Channel = TRAINER_OUT_TIMER_Channel,
|
||||
.TIM_IRQn = TRAINER_TIMER_IRQn,
|
||||
.DMAx = nullptr,
|
||||
.DMA_Stream = 0,
|
||||
.DMA_Channel = 0,
|
||||
.DMA_IRQn = (IRQn_Type)0,
|
||||
};
|
||||
|
||||
static void trainerSendNextFrame()
|
||||
{
|
||||
stm32_pulse_set_polarity(&trainerOutputTimer, GET_TRAINER_PPM_POLARITY());
|
||||
|
||||
// load the first period: next reload when CC compare event triggers
|
||||
trainerPulsesData.ppm.ptr = trainerPulsesData.ppm.pulses;
|
||||
TRAINER_TIMER->ARR = *(trainerPulsesData.ppm.ptr++);
|
||||
|
||||
switch (trainerOutputTimer.TIM_Channel) {
|
||||
case LL_TIM_CHANNEL_CH1:
|
||||
LL_TIM_EnableIT_CC1(trainerOutputTimer.TIMx);
|
||||
break;
|
||||
case LL_TIM_CHANNEL_CH2:
|
||||
LL_TIM_EnableIT_CC2(trainerOutputTimer.TIMx);
|
||||
break;
|
||||
case LL_TIM_CHANNEL_CH3:
|
||||
LL_TIM_EnableIT_CC3(trainerOutputTimer.TIMx);
|
||||
break;
|
||||
case LL_TIM_CHANNEL_CH4:
|
||||
LL_TIM_EnableIT_CC4(trainerOutputTimer.TIMx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void trainer_out_isr()
|
||||
{
|
||||
// proceed only if the channel flag was set
|
||||
// and the IRQ was enabled
|
||||
if (!trainer_check_isr_flag(_trainer_timer))
|
||||
return;
|
||||
|
||||
if (*trainerPulsesData.ppm.ptr) {
|
||||
// load next period
|
||||
LL_TIM_SetAutoReload(_trainer_timer->TIMx,
|
||||
*(trainerPulsesData.ppm.ptr++));
|
||||
} else {
|
||||
setupPulsesPPMTrainer();
|
||||
trainerSendNextFrame();
|
||||
}
|
||||
}
|
||||
|
||||
void init_trainer_ppm()
|
||||
{
|
||||
// set proper ISR handler first
|
||||
_trainer_timer = &trainerOutputTimer;
|
||||
_trainer_timer_isr = trainer_out_isr;
|
||||
|
||||
stm32_pulse_init(&trainerOutputTimer);
|
||||
stm32_pulse_config_output(&trainerOutputTimer, GET_TRAINER_PPM_POLARITY(),
|
||||
LL_TIM_OCMODE_PWM1, GET_TRAINER_PPM_DELAY() * 2);
|
||||
|
||||
setupPulsesPPMTrainer();
|
||||
trainerSendNextFrame();
|
||||
|
||||
LL_TIM_EnableCounter(trainerOutputTimer.TIMx);
|
||||
}
|
||||
|
||||
void stop_trainer_ppm()
|
||||
{
|
||||
_stop_trainer(&trainerOutputTimer);
|
||||
}
|
||||
|
||||
static const stm32_pulse_timer_t trainerInputTimer = {
|
||||
.GPIOx = TRAINER_GPIO,
|
||||
.GPIO_Pin = TRAINER_IN_GPIO_PIN,
|
||||
.GPIO_Alternate = TRAINER_GPIO_AF,
|
||||
.TIMx = TRAINER_TIMER,
|
||||
.TIM_Prescaler = __LL_TIM_CALC_PSC(TRAINER_TIMER_FREQ, 2000000),
|
||||
.TIM_Channel = TRAINER_IN_TIMER_Channel,
|
||||
.TIM_IRQn = TRAINER_TIMER_IRQn,
|
||||
.DMAx = nullptr,
|
||||
.DMA_Stream = 0,
|
||||
.DMA_Channel = 0,
|
||||
.DMA_IRQn = (IRQn_Type)0,
|
||||
};
|
||||
|
||||
void init_trainer_capture()
|
||||
{
|
||||
_init_trainer_capture(&trainerInputTimer);
|
||||
}
|
||||
|
||||
void stop_trainer_capture()
|
||||
{
|
||||
_stop_trainer(&trainerInputTimer);
|
||||
}
|
||||
|
||||
#endif // TRAINER_GPIO
|
||||
|
||||
bool is_trainer_connected()
|
||||
{
|
||||
#if defined(TRAINER_DETECT_GPIO_PIN)
|
||||
bool set = LL_GPIO_IsInputPinSet(TRAINER_DETECT_GPIO, TRAINER_DETECT_GPIO_PIN);
|
||||
#if defined(TRAINER_DETECT_INVERTED)
|
||||
return !set;
|
||||
#else
|
||||
return set;
|
||||
#endif
|
||||
#else // TRAINER_DETECT_GPIO_PIN
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(TRAINER_GPIO) || (defined(TRAINER_MODULE_CPPM) && \
|
||||
!defined(TRAINER_MODULE_CPPM_TIMER_IRQHandler))
|
||||
|
||||
#if !defined(TRAINER_TIMER_IRQHandler)
|
||||
#error "Missing TRAINER_TIMER_IRQHandler definition"
|
||||
#endif
|
||||
|
||||
extern "C" void TRAINER_TIMER_IRQHandler()
|
||||
{
|
||||
DEBUG_INTERRUPT(INT_TRAINER);
|
||||
|
||||
if (_trainer_timer && _trainer_timer_isr)
|
||||
_trainer_timer_isr();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(TRAINER_MODULE_CPPM)
|
||||
|
||||
static_assert(__IS_TRAINER_TIMER_IN_CHANNEL_SUPPORTED(TRAINER_MODULE_CPPM_TIMER_Channel),
|
||||
"Unsupported trainer timer input channel");
|
||||
|
||||
static const stm32_pulse_timer_t trainerModuleTimer = {
|
||||
.GPIOx = TRAINER_MODULE_CPPM_GPIO,
|
||||
.GPIO_Pin = TRAINER_MODULE_CPPM_GPIO_PIN,
|
||||
.GPIO_Alternate = TRAINER_MODULE_CPPM_GPIO_AF,
|
||||
.TIMx = TRAINER_MODULE_CPPM_TIMER,
|
||||
.TIM_Prescaler = __LL_TIM_CALC_PSC(TRAINER_MODULE_CCPM_FREQ, 2000000),
|
||||
.TIM_Channel = TRAINER_MODULE_CPPM_TIMER_Channel,
|
||||
.TIM_IRQn = TRAINER_MODULE_CPPM_TIMER_IRQn,
|
||||
.DMAx = nullptr,
|
||||
.DMA_Stream = 0,
|
||||
.DMA_Channel = 0,
|
||||
.DMA_IRQn = (IRQn_Type)0,
|
||||
};
|
||||
|
||||
void init_trainer_module_cppm()
|
||||
{
|
||||
_init_trainer_capture(&trainerModuleTimer);
|
||||
}
|
||||
|
||||
void stop_trainer_module_cppm()
|
||||
{
|
||||
_stop_trainer(&trainerModuleTimer);
|
||||
}
|
||||
|
||||
#if defined(TRAINER_MODULE_CPPM_TIMER_IRQHandler)
|
||||
extern "C" void TRAINER_MODULE_CPPM_TIMER_IRQHandler()
|
||||
{
|
||||
DEBUG_INTERRUPT(INT_TRAINER);
|
||||
|
||||
if (_trainer_timer && _trainer_timer_isr)
|
||||
_trainer_timer_isr();
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TRAINER_MODULE_CPPM
|
||||
Reference in New Issue
Block a user