Rotary encoder refactoring
This commit is contained in:
@@ -8,7 +8,9 @@ if(PCB STREQUAL X12S OR PCB STREQUAL X10)
|
||||
../f4/system_stm32f4xx.c
|
||||
../../../../../targets/${TARGET_DIR}/startup_stm32f42_43xxx.s
|
||||
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rcc.c
|
||||
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_syscfg.c
|
||||
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.c
|
||||
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_exti.c
|
||||
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_spi.c
|
||||
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_fmc.c
|
||||
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_ltdc.c
|
||||
@@ -23,7 +25,9 @@ elseif(PCB STREQUAL X9E)
|
||||
../f4/system_stm32f4xx.c
|
||||
../../../../../targets/${TARGET_DIR}/startup_stm32f40_41xxx.s
|
||||
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rcc.c
|
||||
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_syscfg.c
|
||||
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.c
|
||||
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_exti.c
|
||||
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_spi.c
|
||||
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_i2c.c
|
||||
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/misc.c
|
||||
@@ -34,7 +38,9 @@ else()
|
||||
../f2/system_stm32f2xx.c
|
||||
../../../../../${STM32LIB_DIR}/CMSIS/Device/ST/STM32F2xx/Source/Templates/gcc_ride7/startup_stm32f2xx.s
|
||||
../../../../../${STM32LIB_DIR}/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_rcc.c
|
||||
../../../../../${STM32LIB_DIR}/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_syscfg.c
|
||||
../../../../../${STM32LIB_DIR}/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_gpio.c
|
||||
../../../../../${STM32LIB_DIR}/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_exti.c
|
||||
../../../../../${STM32LIB_DIR}/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_spi.c
|
||||
../../../../../${STM32LIB_DIR}/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_i2c.c
|
||||
../../../../../${STM32LIB_DIR}/STM32F2xx_StdPeriph_Driver/src/misc.c
|
||||
@@ -78,6 +84,13 @@ set(BOOTLOADER_SRC
|
||||
bin_files.cpp
|
||||
)
|
||||
|
||||
if(PCB STREQUAL X12S OR PCB STREQUAL X10 OR PCB STREQUAL X9E OR PCB STREQUAL X7 OR PCB STREQUAL X3)
|
||||
set(BOOTLOADER_SRC
|
||||
${BOOTLOADER_SRC}
|
||||
../../../../../targets/common/arm/stm32/rotary_encoder_driver.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT (PCB STREQUAL X10 OR PCB STREQUAL X12S))
|
||||
set(BOOTLOADER_SRC
|
||||
${BOOTLOADER_SRC}
|
||||
|
||||
@@ -50,7 +50,7 @@ const uint8_t bootloaderVersion[] __attribute__ ((section(".version"), used)) =
|
||||
{ 'B', 'O', 'O', 'T', '1', '0' };
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
volatile rotenc_t rotencValue[1] = {0};
|
||||
volatile rotenc_t rotencValue = 0;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
@@ -86,18 +86,12 @@ void interrupt10ms(void)
|
||||
}
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
checkRotaryEncoder();
|
||||
static rotenc_t rePreviousValue;
|
||||
rotenc_t reNewValue = (rotencValue[0] / ROTARY_ENCODER_GRANULARITY);
|
||||
rotenc_t reNewValue = (rotencValue / ROTARY_ENCODER_GRANULARITY);
|
||||
int8_t scrollRE = reNewValue - rePreviousValue;
|
||||
if (scrollRE) {
|
||||
rePreviousValue = reNewValue;
|
||||
if (scrollRE < 0) {
|
||||
putEvent(EVT_KEY_FIRST(KEY_UP)); //EVT_ROTARY_LEFT
|
||||
}
|
||||
else {
|
||||
putEvent(EVT_KEY_FIRST(KEY_DOWN)); //EVT_ROTARY_RIGHT
|
||||
}
|
||||
putEvent(scrollRE < 0 ? EVT_KEY_FIRST(KEY_UP) : EVT_KEY_FIRST(KEY_DOWN));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -221,6 +215,10 @@ int main()
|
||||
|
||||
keysInit();
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
rotaryEncoderInit();
|
||||
#endif
|
||||
|
||||
// wait for inputs to stabilize
|
||||
for (uint32_t i = 0; i < 50000; i += 1) {
|
||||
wdt_reset();
|
||||
|
||||
@@ -11,8 +11,10 @@ set(STM32LIB_SRC
|
||||
CMSIS/Device/ST/STM32F2xx/Source/Templates/gcc_ride7/startup_stm32f2xx.s
|
||||
STM32F2xx_StdPeriph_Driver/src/misc.c
|
||||
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_gpio.c
|
||||
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_exti.c
|
||||
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_dbgmcu.c
|
||||
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_rcc.c
|
||||
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_syscfg.c
|
||||
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_spi.c
|
||||
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_i2c.c
|
||||
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_dma.c
|
||||
|
||||
@@ -10,8 +10,10 @@ set(STM32LIB_SRC
|
||||
${STM32LIB_SRC}
|
||||
STM32F4xx_StdPeriph_Driver/src/misc.c
|
||||
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_gpio.c
|
||||
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_exti.c
|
||||
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_dbgmcu.c
|
||||
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_rcc.c
|
||||
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_syscfg.c
|
||||
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_spi.c
|
||||
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_i2c.c
|
||||
STM32F4xx_StdPeriph_Driver/src/stm32f4xx_dma.c
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* 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 "opentx.h"
|
||||
|
||||
uint32_t rotencPosition;
|
||||
|
||||
void rotaryEncoderInit()
|
||||
{
|
||||
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
|
||||
|
||||
rotencPosition = ROTARY_ENCODER_POSITION();
|
||||
}
|
||||
|
||||
void rotaryEncoderCheck()
|
||||
{
|
||||
uint32_t newpos = ROTARY_ENCODER_POSITION();
|
||||
if (newpos != rotencPosition && !keyState(KEY_ENTER)) {
|
||||
if ((rotencPosition & 0x01) ^ ((newpos & 0x02) >> 1)) {
|
||||
--rotencValue;
|
||||
}
|
||||
else {
|
||||
++rotencValue;
|
||||
}
|
||||
rotencPosition = newpos;
|
||||
#if !defined(BOOT)
|
||||
if (g_eeGeneral.backlightMode & e_backlight_mode_keys) {
|
||||
backlightOn();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void ROTARY_ENCODER_EXTI_IRQHandler1(void)
|
||||
{
|
||||
if (EXTI_GetITStatus(ROTARY_ENCODER_EXTI_LINE1) != RESET) {
|
||||
rotaryEncoderCheck();
|
||||
EXTI_ClearITPendingBit(ROTARY_ENCODER_EXTI_LINE1);
|
||||
}
|
||||
|
||||
#if !defined(ROTARY_ENCODER_EXTI_IRQn2)
|
||||
if (EXTI_GetITStatus(ROTARY_ENCODER_EXTI_LINE2) != RESET) {
|
||||
rotaryEncoderCheck();
|
||||
EXTI_ClearITPendingBit(ROTARY_ENCODER_EXTI_LINE2);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(ROTARY_ENCODER_EXTI_IRQn2)
|
||||
extern "C" void ROTARY_ENCODER_EXTI_IRQHandler2(void)
|
||||
{
|
||||
if (EXTI_GetITStatus(ROTARY_ENCODER_EXTI_LINE2) != RESET) {
|
||||
rotaryEncoderCheck();
|
||||
EXTI_ClearITPendingBit(ROTARY_ENCODER_EXTI_LINE2);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user