Bsongis/rotary encoder delay (#6503)
Rotary encoder fixed on X10 / X12S
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
uint32_t rotencPosition;
|
||||
uint8_t rotencPosition;
|
||||
|
||||
void rotaryEncoderInit()
|
||||
{
|
||||
@@ -56,19 +56,29 @@ void rotaryEncoderInit()
|
||||
#endif
|
||||
|
||||
rotencPosition = ROTARY_ENCODER_POSITION();
|
||||
|
||||
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;
|
||||
NVIC_EnableIRQ(ROTARY_ENCODER_TIMER_IRQn);
|
||||
NVIC_SetPriority(ROTARY_ENCODER_TIMER_IRQn, 7);
|
||||
}
|
||||
|
||||
void rotaryEncoderCheck()
|
||||
{
|
||||
uint32_t newpos = ROTARY_ENCODER_POSITION();
|
||||
if (newpos != rotencPosition && !keyState(KEY_ENTER)) {
|
||||
if ((rotencPosition & 0x01) ^ ((newpos & 0x02) >> 1)) {
|
||||
uint8_t newPosition = ROTARY_ENCODER_POSITION();
|
||||
if (newPosition != rotencPosition && !keyState(KEY_ENTER)) {
|
||||
if ((rotencPosition & 0x01) ^ ((newPosition & 0x02) >> 1)) {
|
||||
--rotencValue;
|
||||
}
|
||||
else {
|
||||
++rotencValue;
|
||||
}
|
||||
rotencPosition = newpos;
|
||||
rotencPosition = newPosition;
|
||||
#if !defined(BOOT)
|
||||
if (g_eeGeneral.backlightMode & e_backlight_mode_keys) {
|
||||
backlightOn();
|
||||
@@ -77,16 +87,21 @@ void rotaryEncoderCheck()
|
||||
}
|
||||
}
|
||||
|
||||
void rotaryEncoderStartDelay()
|
||||
{
|
||||
ROTARY_ENCODER_TIMER->CR1 = TIM_CR1_CEN | TIM_CR1_URS;
|
||||
}
|
||||
|
||||
extern "C" void ROTARY_ENCODER_EXTI_IRQHandler1(void)
|
||||
{
|
||||
if (EXTI_GetITStatus(ROTARY_ENCODER_EXTI_LINE1) != RESET) {
|
||||
rotaryEncoderCheck();
|
||||
rotaryEncoderStartDelay();
|
||||
EXTI_ClearITPendingBit(ROTARY_ENCODER_EXTI_LINE1);
|
||||
}
|
||||
|
||||
#if !defined(ROTARY_ENCODER_EXTI_IRQn2)
|
||||
if (EXTI_GetITStatus(ROTARY_ENCODER_EXTI_LINE2) != RESET) {
|
||||
rotaryEncoderCheck();
|
||||
rotaryEncoderStartDelay();
|
||||
EXTI_ClearITPendingBit(ROTARY_ENCODER_EXTI_LINE2);
|
||||
}
|
||||
#endif
|
||||
@@ -100,8 +115,15 @@ extern "C" void ROTARY_ENCODER_EXTI_IRQHandler1(void)
|
||||
extern "C" void ROTARY_ENCODER_EXTI_IRQHandler2(void)
|
||||
{
|
||||
if (EXTI_GetITStatus(ROTARY_ENCODER_EXTI_LINE2) != RESET) {
|
||||
rotaryEncoderCheck();
|
||||
rotaryEncoderStartDelay();
|
||||
EXTI_ClearITPendingBit(ROTARY_ENCODER_EXTI_LINE2);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
extern "C" void ROTARY_ENCODER_TIMER_IRQHandler(void)
|
||||
{
|
||||
ROTARY_ENCODER_TIMER->SR &= ~TIM_SR_UIF;
|
||||
ROTARY_ENCODER_TIMER->CR1 = 0;
|
||||
rotaryEncoderCheck();
|
||||
}
|
||||
Reference in New Issue
Block a user