Rotary encoder refactoring
This commit is contained in:
@@ -36,7 +36,6 @@ if (PCB STREQUAL X10)
|
||||
../common/arm/stm32/adc_driver.cpp
|
||||
../common/arm/stm32/sticks_pwm_driver.cpp
|
||||
)
|
||||
|
||||
set(BITMAPS_TARGET x10_bitmaps)
|
||||
set(FONTS_TARGET x10_fonts)
|
||||
set(LCD_DRIVER lcd_driver.cpp)
|
||||
@@ -133,6 +132,7 @@ set(TARGET_SRC
|
||||
trainer_driver.cpp
|
||||
../common/arm/stm32/intmodule_serial_driver.cpp
|
||||
../common/arm/stm32/bluetooth_driver.cpp
|
||||
../common/arm/stm32/rotary_encoder_driver.cpp
|
||||
)
|
||||
|
||||
set(FIRMWARE_TARGET_SRC
|
||||
|
||||
@@ -86,10 +86,6 @@ void interrupt1ms()
|
||||
per10ms();
|
||||
DEBUG_TIMER_STOP(debugTimerPer10ms);
|
||||
}
|
||||
|
||||
DEBUG_TIMER_START(debugTimerRotEnc);
|
||||
checkRotaryEncoder();
|
||||
DEBUG_TIMER_STOP(debugTimerRotEnc);
|
||||
}
|
||||
|
||||
extern "C" void INTERRUPT_xMS_IRQHandler()
|
||||
@@ -168,7 +164,8 @@ void boardInit()
|
||||
BACKLIGHT_RCC_APB1Periph,
|
||||
ENABLE);
|
||||
|
||||
RCC_APB2PeriphClockCmd(LCD_RCC_APB2Periph |
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG |
|
||||
LCD_RCC_APB2Periph |
|
||||
ADC_RCC_APB2Periph |
|
||||
HAPTIC_RCC_APB2Periph |
|
||||
INTMODULE_RCC_APB2Periph |
|
||||
@@ -196,6 +193,7 @@ void boardInit()
|
||||
memset(&g_FATFS_Obj, 0, sizeof(g_FATFS_Obj));
|
||||
|
||||
keysInit();
|
||||
rotaryEncoderInit();
|
||||
|
||||
#if NUM_PWMSTICKS > 0
|
||||
sticksPwmInit();
|
||||
|
||||
@@ -37,7 +37,9 @@ extern "C" {
|
||||
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_rcc.h"
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_syscfg.h"
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_gpio.h"
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_exti.h"
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_spi.h"
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_i2c.h"
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_rtc.h"
|
||||
@@ -344,7 +346,8 @@ uint32_t readTrims(void);
|
||||
|
||||
// Rotary encoder driver
|
||||
#define ROTARY_ENCODER_NAVIGATION
|
||||
void checkRotaryEncoder(void);
|
||||
void rotaryEncoderInit(void);
|
||||
void rotaryEncoderCheck(void);
|
||||
|
||||
// WDT driver
|
||||
#define WDTO_500MS 500
|
||||
|
||||
@@ -62,6 +62,13 @@
|
||||
#define ROTARY_ENCODER_GPIO_PIN_A GPIO_Pin_11 // PH.11
|
||||
#define ROTARY_ENCODER_GPIO_PIN_B GPIO_Pin_10 // PH.10
|
||||
#define ROTARY_ENCODER_POSITION() ((ROTARY_ENCODER_GPIO->IDR >> 10) & 0x03)
|
||||
#define ROTARY_ENCODER_EXTI_LINE1 EXTI_Line11
|
||||
#define ROTARY_ENCODER_EXTI_LINE2 EXTI_Line10
|
||||
#define ROTARY_ENCODER_EXTI_IRQn1 EXTI15_10_IRQn
|
||||
#define ROTARY_ENCODER_EXTI_IRQHandler1 EXTI15_10_IRQHandler
|
||||
#define ROTARY_ENCODER_EXTI_PortSource EXTI_PortSourceGPIOH
|
||||
#define ROTARY_ENCODER_EXTI_PinSource1 EXTI_PinSource11
|
||||
#define ROTARY_ENCODER_EXTI_PinSource2 EXTI_PinSource10
|
||||
|
||||
// Switches
|
||||
#define SWITCHES_GPIO_REG_A_H GPIOH->IDR
|
||||
|
||||
@@ -20,68 +20,6 @@
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
/*
|
||||
* Rotary encoder handling based on state table:
|
||||
* Copyright (C) by Ben Buxton
|
||||
*
|
||||
* This includes the state table definition bellow
|
||||
* as well as the implementation of checkRotaryEncoder().
|
||||
*
|
||||
* The below state table has, for each state (row), the new state
|
||||
* to set based on the next encoder output. From left to right in,
|
||||
* the table, the encoder outputs are 00, 01, 10, 11, and the value
|
||||
* in that position is the new state to set.
|
||||
*/
|
||||
|
||||
#define R_START 0x0
|
||||
#define DIR_CW 0x10
|
||||
#define DIR_CCW 0x20
|
||||
|
||||
// Use the half-step state table (emits a code at 00 and 11)
|
||||
#define R_CCW_BEGIN 0x1
|
||||
#define R_CW_BEGIN 0x2
|
||||
#define R_START_M 0x3
|
||||
#define R_CW_BEGIN_M 0x4
|
||||
#define R_CCW_BEGIN_M 0x5
|
||||
const unsigned char rotenc_table[6][4] = {
|
||||
// R_START (00)
|
||||
{R_START_M, R_CW_BEGIN, R_CCW_BEGIN, R_START},
|
||||
// R_CCW_BEGIN
|
||||
{R_START_M | DIR_CCW, R_START, R_CCW_BEGIN, R_START},
|
||||
// R_CW_BEGIN
|
||||
{R_START_M | DIR_CW, R_CW_BEGIN, R_START, R_START},
|
||||
// R_START_M (11)
|
||||
{R_START_M, R_CCW_BEGIN_M, R_CW_BEGIN_M, R_START},
|
||||
// R_CW_BEGIN_M
|
||||
{R_START_M, R_START_M, R_CW_BEGIN_M, R_START | DIR_CW},
|
||||
// R_CCW_BEGIN_M
|
||||
{R_START_M, R_CCW_BEGIN_M, R_START_M, R_START | DIR_CCW},
|
||||
};
|
||||
|
||||
void checkRotaryEncoder()
|
||||
{
|
||||
static uint8_t state = 0;
|
||||
uint32_t pins = ROTARY_ENCODER_POSITION();
|
||||
|
||||
state = rotenc_table[state & 0x0F][pins];
|
||||
if ((state & 0x30) && !keyState(KEY_ENTER)) {
|
||||
if ((state & 0x30) == DIR_CW) {
|
||||
--rotencValue[0];
|
||||
}
|
||||
else {
|
||||
++rotencValue[0];
|
||||
}
|
||||
#if !defined(BOOT)
|
||||
if (g_eeGeneral.backlightMode & e_backlight_mode_keys)
|
||||
backlightOn();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* End of the rotary encoder handler code
|
||||
*/
|
||||
|
||||
uint32_t readKeys()
|
||||
{
|
||||
uint32_t result = 0;
|
||||
|
||||
Reference in New Issue
Block a user