Bsongis/rotary encoder delay (#6503)
Rotary encoder fixed on X10 / X12S
This commit is contained in:
@@ -128,6 +128,7 @@ set(TARGET_SRC
|
||||
led_driver.cpp
|
||||
extmodule_driver.cpp
|
||||
trainer_driver.cpp
|
||||
../common/arm/stm32/timers_driver.cpp
|
||||
../common/arm/stm32/intmodule_serial_driver.cpp
|
||||
../common/arm/stm32/bluetooth_driver.cpp
|
||||
../common/arm/stm32/rotary_encoder_driver.cpp
|
||||
|
||||
@@ -41,60 +41,6 @@ void watchdogInit(unsigned int duration)
|
||||
IWDG->KR = 0xCCCC; // start
|
||||
}
|
||||
|
||||
// Start TIMER7 at 2000000Hz
|
||||
void init2MhzTimer()
|
||||
{
|
||||
TIMER_2MHz_TIMER->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 2000000 - 1; // 0.5 uS, 2 MHz
|
||||
TIMER_2MHz_TIMER->ARR = 65535;
|
||||
TIMER_2MHz_TIMER->CR2 = 0;
|
||||
TIMER_2MHz_TIMER->CR1 = TIM_CR1_CEN;
|
||||
}
|
||||
|
||||
// Starts TIMER at 1000Hz
|
||||
void init1msTimer()
|
||||
{
|
||||
INTERRUPT_xMS_TIMER->ARR = 999; // 1mS in uS
|
||||
INTERRUPT_xMS_TIMER->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 1000000 - 1; // 1uS
|
||||
INTERRUPT_xMS_TIMER->CCER = 0;
|
||||
INTERRUPT_xMS_TIMER->CCMR1 = 0;
|
||||
INTERRUPT_xMS_TIMER->EGR = 0;
|
||||
INTERRUPT_xMS_TIMER->CR1 = 5;
|
||||
INTERRUPT_xMS_TIMER->DIER |= 1;
|
||||
NVIC_EnableIRQ(INTERRUPT_xMS_IRQn);
|
||||
NVIC_SetPriority(INTERRUPT_xMS_IRQn, 7);
|
||||
}
|
||||
|
||||
// TODO use the same than board_sky9x.cpp
|
||||
void interrupt1ms()
|
||||
{
|
||||
static uint8_t pre_scale; // Used to get 10 Hz counter
|
||||
|
||||
++pre_scale;
|
||||
|
||||
#if defined(HAPTIC)
|
||||
if (pre_scale == 5 || pre_scale == 10) {
|
||||
DEBUG_TIMER_START(debugTimerHaptic);
|
||||
HAPTIC_HEARTBEAT();
|
||||
DEBUG_TIMER_STOP(debugTimerHaptic);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (pre_scale == 10) {
|
||||
pre_scale = 0;
|
||||
DEBUG_TIMER_START(debugTimerPer10ms);
|
||||
DEBUG_TIMER_SAMPLE(debugTimerPer10msPeriod);
|
||||
per10ms();
|
||||
DEBUG_TIMER_STOP(debugTimerPer10ms);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void INTERRUPT_xMS_IRQHandler()
|
||||
{
|
||||
INTERRUPT_xMS_TIMER->SR &= ~TIM_SR_UIF;
|
||||
interrupt1ms();
|
||||
DEBUG_INTERRUPT(INT_1MS);
|
||||
}
|
||||
|
||||
#if defined(SEMIHOSTING)
|
||||
extern "C" void initialise_monitor_handles();
|
||||
#endif
|
||||
@@ -150,7 +96,8 @@ void boardInit()
|
||||
SPORT_UPDATE_RCC_AHB1Periph,
|
||||
ENABLE);
|
||||
|
||||
RCC_APB1PeriphClockCmd(INTERRUPT_xMS_RCC_APB1Periph |
|
||||
RCC_APB1PeriphClockCmd(ROTARY_ENCODER_RCC_APB1Periph |
|
||||
INTERRUPT_xMS_RCC_APB1Periph |
|
||||
ADC_RCC_APB1Periph |
|
||||
TIMER_2MHz_RCC_APB1Periph |
|
||||
AUDIO_RCC_APB1Periph |
|
||||
@@ -208,7 +155,7 @@ void boardInit()
|
||||
backlightInit();
|
||||
|
||||
init2MhzTimer();
|
||||
init1msTimer();
|
||||
init5msTimer();
|
||||
usbInit();
|
||||
hapticInit();
|
||||
|
||||
|
||||
@@ -112,6 +112,10 @@ void boardPreInit(void);
|
||||
void boardInit(void);
|
||||
void boardOff(void);
|
||||
|
||||
// Timers driver
|
||||
void init2MhzTimer();
|
||||
void init5msTimer();
|
||||
|
||||
// Delays driver
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
#endif
|
||||
|
||||
// Rotary Encoder
|
||||
#define ROTARY_ENCODER_RCC_APB1Periph RCC_APB1Periph_TIM4
|
||||
#define ROTARY_ENCODER_GPIO GPIOH
|
||||
#define ROTARY_ENCODER_GPIO_PIN_A GPIO_Pin_11 // PH.11
|
||||
#define ROTARY_ENCODER_GPIO_PIN_B GPIO_Pin_10 // PH.10
|
||||
@@ -65,6 +66,9 @@
|
||||
#define ROTARY_ENCODER_EXTI_PortSource EXTI_PortSourceGPIOH
|
||||
#define ROTARY_ENCODER_EXTI_PinSource1 EXTI_PinSource11
|
||||
#define ROTARY_ENCODER_EXTI_PinSource2 EXTI_PinSource10
|
||||
#define ROTARY_ENCODER_TIMER TIM4
|
||||
#define ROTARY_ENCODER_TIMER_IRQn TIM4_IRQn
|
||||
#define ROTARY_ENCODER_TIMER_IRQHandler TIM4_IRQHandler
|
||||
|
||||
// Switches
|
||||
#define STORAGE_SWITCH_A
|
||||
|
||||
Reference in New Issue
Block a user