Rotary encoder refactoring
This commit is contained in:
@@ -188,6 +188,13 @@ if(NOT PCB STREQUAL XLITE)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(PCB STREQUAL X9E OR PCB STREQUAL X7 OR PCB STREQUAL X3)
|
||||
set(TARGET_SRC
|
||||
${TARGET_SRC}
|
||||
../common/arm/stm32/rotary_encoder_driver.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
if(PCB STREQUAL X9E OR PCB STREQUAL X7 OR PCB STREQUAL XLITE OR PCB STREQUAL XLITES)
|
||||
add_definitions(-DBLUETOOTH)
|
||||
set(TARGET_SRC
|
||||
|
||||
@@ -88,10 +88,6 @@ void interrupt5ms()
|
||||
per10ms();
|
||||
DEBUG_TIMER_STOP(debugTimerPer10ms);
|
||||
}
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
checkRotaryEncoder();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(SIMU)
|
||||
@@ -143,28 +139,53 @@ void sportUpdatePowerOff()
|
||||
void boardInit()
|
||||
{
|
||||
#if !defined(SIMU)
|
||||
RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph | PCBREV_RCC_AHB1Periph |
|
||||
KEYS_RCC_AHB1Periph | LCD_RCC_AHB1Periph |
|
||||
AUDIO_RCC_AHB1Periph | BACKLIGHT_RCC_AHB1Periph |
|
||||
ADC_RCC_AHB1Periph | I2C_RCC_AHB1Periph |
|
||||
SD_RCC_AHB1Periph | HAPTIC_RCC_AHB1Periph |
|
||||
INTMODULE_RCC_AHB1Periph | EXTMODULE_RCC_AHB1Periph |
|
||||
TELEMETRY_RCC_AHB1Periph | SPORT_UPDATE_RCC_AHB1Periph |
|
||||
SERIAL_RCC_AHB1Periph | TRAINER_RCC_AHB1Periph |
|
||||
HEARTBEAT_RCC_AHB1Periph | BT_RCC_AHB1Periph | GYRO_RCC_AHB1Periph,
|
||||
RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph |
|
||||
PCBREV_RCC_AHB1Periph |
|
||||
KEYS_RCC_AHB1Periph |
|
||||
LCD_RCC_AHB1Periph |
|
||||
AUDIO_RCC_AHB1Periph |
|
||||
BACKLIGHT_RCC_AHB1Periph |
|
||||
ADC_RCC_AHB1Periph |
|
||||
I2C_RCC_AHB1Periph |
|
||||
SD_RCC_AHB1Periph |
|
||||
HAPTIC_RCC_AHB1Periph |
|
||||
INTMODULE_RCC_AHB1Periph |
|
||||
EXTMODULE_RCC_AHB1Periph |
|
||||
TELEMETRY_RCC_AHB1Periph |
|
||||
SPORT_UPDATE_RCC_AHB1Periph |
|
||||
SERIAL_RCC_AHB1Periph |
|
||||
TRAINER_RCC_AHB1Periph |
|
||||
HEARTBEAT_RCC_AHB1Periph |
|
||||
BT_RCC_AHB1Periph |
|
||||
GYRO_RCC_AHB1Periph,
|
||||
ENABLE);
|
||||
|
||||
RCC_APB1PeriphClockCmd(LCD_RCC_APB1Periph | AUDIO_RCC_APB1Periph | ADC_RCC_APB1Periph |
|
||||
BACKLIGHT_RCC_APB1Periph | HAPTIC_RCC_APB1Periph | INTERRUPT_xMS_RCC_APB1Periph |
|
||||
TIMER_2MHz_RCC_APB1Periph | I2C_RCC_APB1Periph |
|
||||
SD_RCC_APB1Periph | TRAINER_RCC_APB1Periph |
|
||||
TELEMETRY_RCC_APB1Periph | SERIAL_RCC_APB1Periph |
|
||||
INTMODULE_RCC_APB1Periph | BT_RCC_APB1Periph | GYRO_RCC_APB1Periph, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(LCD_RCC_APB1Periph |
|
||||
AUDIO_RCC_APB1Periph |
|
||||
ADC_RCC_APB1Periph |
|
||||
BACKLIGHT_RCC_APB1Periph |
|
||||
HAPTIC_RCC_APB1Periph |
|
||||
INTERRUPT_xMS_RCC_APB1Periph |
|
||||
TIMER_2MHz_RCC_APB1Periph |
|
||||
I2C_RCC_APB1Periph |
|
||||
SD_RCC_APB1Periph |
|
||||
TRAINER_RCC_APB1Periph |
|
||||
TELEMETRY_RCC_APB1Periph |
|
||||
SERIAL_RCC_APB1Periph |
|
||||
INTMODULE_RCC_APB1Periph |
|
||||
BT_RCC_APB1Periph |
|
||||
GYRO_RCC_APB1Periph,
|
||||
ENABLE);
|
||||
|
||||
RCC_APB2PeriphClockCmd(BACKLIGHT_RCC_APB2Periph | ADC_RCC_APB2Periph |
|
||||
HAPTIC_RCC_APB2Periph | INTMODULE_RCC_APB2Periph |
|
||||
EXTMODULE_RCC_APB2Periph | HEARTBEAT_RCC_APB2Periph |
|
||||
BT_RCC_APB2Periph, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG |
|
||||
BACKLIGHT_RCC_APB2Periph |
|
||||
ADC_RCC_APB2Periph |
|
||||
HAPTIC_RCC_APB2Periph |
|
||||
INTMODULE_RCC_APB2Periph |
|
||||
EXTMODULE_RCC_APB2Periph |
|
||||
HEARTBEAT_RCC_APB2Periph |
|
||||
BT_RCC_APB2Periph,
|
||||
ENABLE);
|
||||
|
||||
#if defined(BLUETOOTH)
|
||||
bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE, true);
|
||||
@@ -181,6 +202,11 @@ void boardInit()
|
||||
#endif
|
||||
|
||||
keysInit();
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
rotaryEncoderInit();
|
||||
#endif
|
||||
|
||||
delaysInit();
|
||||
|
||||
#if NUM_PWMSTICKS > 0
|
||||
|
||||
@@ -39,7 +39,9 @@ extern "C" {
|
||||
#if defined(STM32F4)
|
||||
#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_tim.h"
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_adc.h"
|
||||
#include "STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries/STM32F4xx_StdPeriph_Driver/inc/stm32f4xx_spi.h"
|
||||
@@ -54,7 +56,9 @@ extern "C" {
|
||||
#else
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Include/stm32f2xx.h"
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_rcc.h"
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_syscfg.h"
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_gpio.h"
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_exti.h"
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_tim.h"
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_adc.h"
|
||||
#include "STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/inc/stm32f2xx_spi.h"
|
||||
@@ -420,7 +424,8 @@ uint32_t readTrims(void);
|
||||
#if defined(PCBX9E) || defined(PCBX7) || defined(PCBX3)
|
||||
// Rotary Encoder driver
|
||||
#define ROTARY_ENCODER_NAVIGATION
|
||||
void checkRotaryEncoder(void);
|
||||
void rotaryEncoderInit(void);
|
||||
void rotaryEncoderCheck(void);
|
||||
#endif
|
||||
|
||||
// WDT driver
|
||||
|
||||
@@ -81,28 +81,51 @@
|
||||
|
||||
// Rotary Encoder
|
||||
#if defined(PCBX9E)
|
||||
#define ENC_GPIO GPIOD
|
||||
#define ENC_GPIO_PIN_A GPIO_Pin_12 // PD.12
|
||||
#define ENC_GPIO_PIN_B GPIO_Pin_13 // PD.13
|
||||
#define ROTARY_ENCODER_POSITION() (ENC_GPIO->IDR >> 12) & 0x03
|
||||
#define ROTARY_ENCODER_GPIO GPIOD
|
||||
#define ROTARY_ENCODER_GPIO_PIN_A GPIO_Pin_12 // PD.12
|
||||
#define ROTARY_ENCODER_GPIO_PIN_B GPIO_Pin_13 // PD.13
|
||||
#define ROTARY_ENCODER_POSITION() (ROTARY_ENCODER_GPIO->IDR >> 12) & 0x03
|
||||
#define ROTARY_ENCODER_EXTI_LINE1 EXTI_Line12
|
||||
#define ROTARY_ENCODER_EXTI_LINE2 EXTI_Line13
|
||||
#define ROTARY_ENCODER_EXTI_IRQn1 EXTI15_10_IRQn
|
||||
#define ROTARY_ENCODER_EXTI_IRQHandler1 EXTI15_10_IRQHandler
|
||||
#define ROTARY_ENCODER_EXTI_PortSource EXTI_PortSourceGPIOD
|
||||
#define ROTARY_ENCODER_EXTI_PinSource1 EXTI_PinSource12
|
||||
#define ROTARY_ENCODER_EXTI_PinSource2 EXTI_PinSource13
|
||||
#elif defined(PCBX7)
|
||||
#define ENC_GPIO GPIOE
|
||||
#define ENC_GPIO_PIN_A GPIO_Pin_9 // PE.09
|
||||
#define ENC_GPIO_PIN_B GPIO_Pin_11 // PE.11
|
||||
#define ROTARY_ENCODER_POSITION() (((ENC_GPIO->IDR >> 10) & 0x02) + ((ENC_GPIO->IDR >> 9) & 0x01))
|
||||
#define ROTARY_ENCODER_GPIO GPIOE
|
||||
#define ROTARY_ENCODER_GPIO_PIN_A GPIO_Pin_9 // PE.09
|
||||
#define ROTARY_ENCODER_GPIO_PIN_B GPIO_Pin_11 // PE.11
|
||||
#define ROTARY_ENCODER_POSITION() (((ROTARY_ENCODER_GPIO->IDR >> 10) & 0x02) + ((ROTARY_ENCODER_GPIO->IDR >> 9) & 0x01))
|
||||
#define ROTARY_ENCODER_EXTI_LINE1 EXTI_Line9
|
||||
#define ROTARY_ENCODER_EXTI_LINE2 EXTI_Line11
|
||||
#define ROTARY_ENCODER_EXTI_IRQn1 EXTI9_5_IRQn
|
||||
#define ROTARY_ENCODER_EXTI_IRQHandler1 EXTI9_5_IRQHandler
|
||||
#define ROTARY_ENCODER_EXTI_IRQn2 EXTI15_10_IRQn
|
||||
#define ROTARY_ENCODER_EXTI_IRQHandler2 EXTI15_10_IRQHandler
|
||||
#define ROTARY_ENCODER_EXTI_PortSource EXTI_PortSourceGPIOE
|
||||
#define ROTARY_ENCODER_EXTI_PinSource1 EXTI_PinSource9
|
||||
#define ROTARY_ENCODER_EXTI_PinSource2 EXTI_PinSource11
|
||||
#elif defined(PCBX3)
|
||||
#define ENC_GPIO GPIOE
|
||||
#define ENC_GPIO_PIN_A GPIO_Pin_10 // PE.10
|
||||
#define ENC_GPIO_PIN_B GPIO_Pin_12 // PE.12
|
||||
#define ROTARY_ENCODER_POSITION() (((ENC_GPIO->IDR >> 12) & 0x01) + ((ENC_GPIO->IDR >> 9) & 0x02))
|
||||
#define ROTARY_ENCODER_GPIO GPIOE
|
||||
#define ROTARY_ENCODER_GPIO_PIN_A GPIO_Pin_10 // PE.10
|
||||
#define ROTARY_ENCODER_GPIO_PIN_B GPIO_Pin_12 // PE.12
|
||||
#define ROTARY_ENCODER_POSITION() (((ROTARY_ENCODER_GPIO->IDR >> 12) & 0x01) + ((ROTARY_ENCODER_GPIO->IDR >> 9) & 0x02))
|
||||
#define ROTARY_ENCODER_EXTI_LINE1 EXTI_Line10
|
||||
#define ROTARY_ENCODER_EXTI_LINE2 EXTI_Line12
|
||||
#define ROTARY_ENCODER_EXTI_IRQn1 EXTI15_10_IRQn
|
||||
#define ROTARY_ENCODER_EXTI_IRQHandler1 EXTI15_10_IRQHandler
|
||||
#define ROTARY_ENCODER_EXTI_PortSource EXTI_PortSourceGPIOE
|
||||
#define ROTARY_ENCODER_EXTI_PinSource1 EXTI_PinSource10
|
||||
#define ROTARY_ENCODER_EXTI_PinSource2 EXTI_PinSource12
|
||||
#endif
|
||||
|
||||
// This is for SIMU: reuse rotary encoder pins to map UP and DOWN keyboard keys
|
||||
#if defined(SIMU) && (defined(PCBX9E) || defined(PCBX7) || defined(PCBX3))
|
||||
#define KEYS_GPIO_REG_PLUS ENC_GPIO->IDR
|
||||
#define KEYS_GPIO_PIN_PLUS ENC_GPIO_PIN_A
|
||||
#define KEYS_GPIO_REG_MINUS ENC_GPIO->IDR
|
||||
#define KEYS_GPIO_PIN_MINUS ENC_GPIO_PIN_B
|
||||
#define KEYS_GPIO_REG_PLUS ROTARY_ENCODER_GPIO->IDR
|
||||
#define KEYS_GPIO_PIN_PLUS ROTARY_ENCODER_GPIO_PIN_A
|
||||
#define KEYS_GPIO_REG_MINUS ROTARY_ENCODER_GPIO->IDR
|
||||
#define KEYS_GPIO_PIN_MINUS ROTARY_ENCODER_GPIO_PIN_B
|
||||
#endif
|
||||
|
||||
// Trims
|
||||
@@ -403,7 +426,7 @@
|
||||
#define KEYS_GPIOA_PINS (SWITCHES_GPIO_PIN_M_L)
|
||||
#define KEYS_GPIOB_PINS (SWITCHES_GPIO_PIN_N_H | SWITCHES_GPIO_PIN_N_L | SWITCHES_GPIO_PIN_R_H)
|
||||
#define KEYS_GPIOC_PINS (TRIMS_GPIO_PIN_RVD | TRIMS_GPIO_PIN_RVU | TRIMS_GPIO_PIN_RHL | TRIMS_GPIO_PIN_RHR)
|
||||
#define KEYS_GPIOD_PINS (KEYS_GPIO_PIN_MENU | KEYS_GPIO_PIN_EXIT | KEYS_GPIO_PIN_PAGE | SWITCHES_GPIO_PIN_A_H | SWITCHES_GPIO_PIN_A_L | ENC_GPIO_PIN_A | ENC_GPIO_PIN_B)
|
||||
#define KEYS_GPIOD_PINS (KEYS_GPIO_PIN_MENU | KEYS_GPIO_PIN_EXIT | KEYS_GPIO_PIN_PAGE | SWITCHES_GPIO_PIN_A_H | SWITCHES_GPIO_PIN_A_L | ROTARY_ENCODER_GPIO_PIN_A | ROTARY_ENCODER_GPIO_PIN_B)
|
||||
#define KEYS_GPIOE_PINS (TRIMS_GPIO_PIN_LVU | TRIMS_GPIO_PIN_LVD | SWITCHES_GPIO_PIN_D_H | SWITCHES_GPIO_PIN_D_L| SWITCHES_GPIO_PIN_E_H | SWITCHES_GPIO_PIN_E_L | SWITCHES_GPIO_PIN_F | SWITCHES_GPIO_PIN_I_L | SWITCHES_GPIO_PIN_L_H | SWITCHES_GPIO_PIN_L_L | SWITCHES_GPIO_PIN_M_H | SWITCHES_GPIO_PIN_O_L | SWITCHES_GPIO_PIN_R_L)
|
||||
#define KEYS_GPIOF_PINS (KEYS_GPIO_PIN_ENTER | SWITCHES_GPIO_PIN_C_H | SWITCHES_GPIO_PIN_C_L | SWITCHES_GPIO_PIN_G_H | SWITCHES_GPIO_PIN_G_L | SWITCHES_GPIO_PIN_H | SWITCHES_GPIO_PIN_I_H | SWITCHES_GPIO_PIN_O_H | SWITCHES_GPIO_PIN_P_H | SWITCHES_GPIO_PIN_P_L | SWITCHES_GPIO_PIN_Q_H | SWITCHES_GPIO_PIN_Q_L)
|
||||
#define KEYS_GPIOG_PINS (TRIMS_GPIO_PIN_LHL | TRIMS_GPIO_PIN_LHR| SWITCHES_GPIO_PIN_B_H | SWITCHES_GPIO_PIN_B_L | SWITCHES_GPIO_PIN_J_H | SWITCHES_GPIO_PIN_J_L | SWITCHES_GPIO_PIN_K_H | SWITCHES_GPIO_PIN_K_L)
|
||||
@@ -431,7 +454,7 @@
|
||||
#define KEYS_GPIOA_PINS SWITCHES_GPIO_PIN_B_H
|
||||
#define KEYS_GPIOC_PINS (TRIMS_GPIO_PIN_LHR | TRIMS_GPIO_PIN_RVD | TRIMS_GPIO_PIN_RVU)
|
||||
#define KEYS_GPIOD_PINS (TRIMS_GPIO_PIN_LHL | KEYS_GPIO_PIN_MENU | KEYS_GPIO_PIN_EXIT | KEYS_GPIO_PIN_PAGE | SWITCHES_GPIO_PIN_C_L | SWITCHES_GPIO_PIN_H)
|
||||
#define KEYS_GPIOE_PINS (ENC_GPIO_PIN_A | ENC_GPIO_PIN_B | KEYS_GPIO_PIN_ENTER | TRIMS_GPIO_PIN_RHR | TRIMS_GPIO_PIN_RHL | TRIMS_GPIO_PIN_LVD | TRIMS_GPIO_PIN_LVU | SWITCHES_GPIO_PIN_C_H | SWITCHES_GPIO_PIN_D_L | SWITCHES_GPIO_PIN_D_H | SWITCHES_GPIO_PIN_B_L | SWITCHES_GPIO_PIN_A_L | SWITCHES_GPIO_PIN_A_H | SWITCHES_GPIO_PIN_F)
|
||||
#define KEYS_GPIOE_PINS (ROTARY_ENCODER_GPIO_PIN_A | ROTARY_ENCODER_GPIO_PIN_B | KEYS_GPIO_PIN_ENTER | TRIMS_GPIO_PIN_RHR | TRIMS_GPIO_PIN_RHL | TRIMS_GPIO_PIN_LVD | TRIMS_GPIO_PIN_LVU | SWITCHES_GPIO_PIN_C_H | SWITCHES_GPIO_PIN_D_L | SWITCHES_GPIO_PIN_D_H | SWITCHES_GPIO_PIN_B_L | SWITCHES_GPIO_PIN_A_L | SWITCHES_GPIO_PIN_A_H | SWITCHES_GPIO_PIN_F)
|
||||
#elif defined(PCBX3)
|
||||
#define KEYS_RCC_AHB1Periph (RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE)
|
||||
#define KEYS_GPIOA_PINS (GPIO_Pin_5)
|
||||
|
||||
@@ -20,10 +20,6 @@
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
uint32_t rotencPosition;
|
||||
#endif
|
||||
|
||||
uint32_t readKeys()
|
||||
{
|
||||
uint32_t result = 0;
|
||||
@@ -114,27 +110,6 @@ bool keyDown()
|
||||
return readKeys() || readTrims();
|
||||
}
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
void checkRotaryEncoder()
|
||||
{
|
||||
uint32_t newpos = ROTARY_ENCODER_POSITION();
|
||||
if (newpos != rotencPosition && !keyState(KEY_ENTER)) {
|
||||
if ((rotencPosition & 0x01) ^ ((newpos & 0x02) >> 1)) {
|
||||
--rotencValue[0];
|
||||
}
|
||||
else {
|
||||
++rotencValue[0];
|
||||
}
|
||||
rotencPosition = newpos;
|
||||
#if !defined(BOOT)
|
||||
if (g_eeGeneral.backlightMode & e_backlight_mode_keys) {
|
||||
backlightOn();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* TODO common to ARM */
|
||||
void readKeysAndTrims()
|
||||
{
|
||||
@@ -289,8 +264,4 @@ void keysInit()
|
||||
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOG_PINS;
|
||||
GPIO_Init(GPIOG, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
rotencPosition = ROTARY_ENCODER_POSITION();
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user