From b58fff12610c4fc5bf59501af9e5909d54bd6b4f Mon Sep 17 00:00:00 2001 From: bsongis Date: Wed, 1 Jul 2015 19:27:37 +0200 Subject: [PATCH] [Taranis X9E] We need to have a VARIANT in eeprom to recognize a Taranis from a Taranis X9E EEPROM --- radio/src/Makefile | 22 ++---- radio/src/eeprom_rlc.cpp | 14 ++-- radio/src/targets/taranis/board_taranis.cpp | 1 - radio/src/targets/taranis/board_taranis.h | 2 +- radio/src/targets/taranis/bootloader/Makefile | 4 - radio/src/targets/taranis/hal.h | 7 +- radio/src/targets/taranis/keys_driver.cpp | 74 +++++++++++++------ radio/src/targets/taranis/rotenc_driver.cpp | 70 ------------------ 8 files changed, 70 insertions(+), 124 deletions(-) delete mode 100644 radio/src/targets/taranis/rotenc_driver.cpp diff --git a/radio/src/Makefile b/radio/src/Makefile index 4fa3d694e..8cc747757 100644 --- a/radio/src/Makefile +++ b/radio/src/Makefile @@ -894,16 +894,17 @@ ifeq ($(PCB), TARANIS) PPM_LIMITS_SYMETRICAL = YES PPM_CENTER_ADJUSTABLE = YES DSM2 = PPM - CPPDEFS += -DPCBTARANIS -DCPUARM -DCPUSTM32 -DVIRTUALINPUTS -DLUAINPUTS -DXCURVES -DEEPROM_RLC -DEEPROM_VARIANT=0 -DAUDIO -DPXX + CPPDEFS += -DPCBTARANIS -DCPUARM -DCPUSTM32 -DVIRTUALINPUTS -DLUAINPUTS -DXCURVES -DEEPROM_RLC -DAUDIO -DPXX INCDIRS += targets/taranis $(THIRDPARTY) $(COOSDIR) $(COOSDIR)/kernel $(COOSDIR)/portable CPPDEFS += -DHSE_VALUE=12000000 ifeq ($(PCBREV), REV9E) STM32LIBPATH = $(THIRDPARTY)/STM32F4xx_DSP_StdPeriph_Lib_V1.4.0/Libraries - CPPDEFS += -DSTM32F4 -DSTM32F40_41xxx + CPPDEFS += -DSTM32F4 -DSTM32F40_41xxx -DEEPROM_VARIANT=32768 INCDIRS += $(STM32LIBPATH)/CMSIS/Device/ST/STM32F4xx/Include $(STM32LIBPATH)/CMSIS/Include $(STM32LIBPATH)/STM32F4xx_StdPeriph_Driver/inc LDSCRIPT = targets/taranis/stm32f4_flash.ld else STM32LIBPATH= $(THIRDPARTY)/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries + CPPDEFS += -DEEPROM_VARIANT=0 INCDIRS += $(STM32LIBPATH)/STM32F2xx_StdPeriph_Driver/inc $(STM32LIBPATH)/CMSIS/Device/ST/STM32F2xx/Include $(STM32LIBPATH)/CMSIS/include LDSCRIPT = targets/taranis/stm32f2_flash.ld endif @@ -1016,9 +1017,6 @@ ifeq ($(PCB), TARANIS) ifeq ($(MIXERS_MONITOR), YES) CPPDEFS += -DMIXERS_MONITOR endif - ifeq ($(PCBREV), REV9E) - CPPSRC += targets/taranis/rotenc_driver.cpp - endif endif CC = $(TRGT)gcc @@ -1801,16 +1799,6 @@ gtest-all.o : $(GTEST_SRCS_) $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GTEST_DIR)/include -c \ $(GTEST_DIR)/src/gtest-all.cc -gtest_main.o : $(GTEST_SRCS_) - $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) -I$(GTEST_DIR)/include -c \ - $(GTEST_DIR)/src/gtest_main.cc - -gtest.a : gtest-all.o - $(AR) $(ARFLAGS) $@ $^ - -gtest_main.a : gtest-all.o gtest_main.o - $(AR) $(ARFLAGS) $@ $^ - # Builds a sample test. A test should link with either gtest.a or # gtest_main.a, depending on whether it defines its own main() # function. @@ -1818,6 +1806,6 @@ gtest_main.a : gtest-all.o gtest_main.o #use all .cpp files from tests/ dir GTEST_TESTS_SRCS = $(shell find tests/ -type f -name '*.cpp') -gtests: allsimusrc.cpp $(GTEST_TESTS_SRCS) targets/simu/simpgmspace.cpp *.h gtest_main.a - g++ -std=gnu++0x $(CPPFLAGS) $(SIMUCPPFLAGS) allsimusrc.cpp $(LUASRC) $(GTEST_TESTS_SRCS) targets/simu/simpgmspace.cpp -I$(GTEST_DIR) ${INCFLAGS} -I$(GTEST_DIR)/include -I/usr/include/qt4 -o gtests -lpthread -MD -DSIMU -lQtCore -lQtGui gtest_main.a -fexceptions +gtests: allsimusrc.cpp $(GTEST_TESTS_SRCS) targets/simu/simpgmspace.cpp *.h gtest-all.o + g++ -std=gnu++0x $(CPPFLAGS) $(SIMUCPPFLAGS) allsimusrc.cpp $(LUASRC) $(GTEST_TESTS_SRCS) targets/simu/simpgmspace.cpp -I$(GTEST_DIR) ${INCFLAGS} -I$(GTEST_DIR)/include -I/usr/include/qt4 -o gtests -lpthread -MD -DSIMU -lQtCore -lQtGui gtest-all.o -fexceptions diff --git a/radio/src/eeprom_rlc.cpp b/radio/src/eeprom_rlc.cpp index 45a30e5a9..00ef379aa 100644 --- a/radio/src/eeprom_rlc.cpp +++ b/radio/src/eeprom_rlc.cpp @@ -893,12 +893,6 @@ void RlcFile::DisplayProgressBar(uint8_t x) } #endif -#if defined(PCBSTD) - #define CHECK_EEPROM_VARIANT() (g_eeGeneral.variant == EEPROM_VARIANT) -#else - #define CHECK_EEPROM_VARIANT() (1) -#endif - // For conversions ... #if defined(CPUARM) void loadGeneralSettings() @@ -921,13 +915,17 @@ bool eeLoadGeneral() theFile.openRlc(FILE_GENERAL); if (theFile.readRlc((uint8_t*)&g_eeGeneral, 1) == 1 && g_eeGeneral.version == EEPROM_VER) { theFile.openRlc(FILE_GENERAL); - if (theFile.readRlc((uint8_t*)&g_eeGeneral, sizeof(g_eeGeneral)) <= sizeof(EEGeneral) && CHECK_EEPROM_VARIANT()) { + if (theFile.readRlc((uint8_t*)&g_eeGeneral, sizeof(g_eeGeneral)) <= sizeof(EEGeneral) && g_eeGeneral.variant == EEPROM_VARIANT) { return true; } } #if defined(PCBTARANIS) - if (g_eeGeneral.version != EEPROM_VER) { + if (g_eeGeneral.variant != EEPROM_VARIANT) { + TRACE("EEPROM variant %d instead of %d", g_eeGeneral.variant, EEPROM_VARIANT); + return false; + } + else if (g_eeGeneral.version != EEPROM_VER) { TRACE("EEPROM version %d instead of %d", g_eeGeneral.version, EEPROM_VER); if (!eeConvert()) { return false; diff --git a/radio/src/targets/taranis/board_taranis.cpp b/radio/src/targets/taranis/board_taranis.cpp index 3cc4cafe8..862b5293f 100644 --- a/radio/src/targets/taranis/board_taranis.cpp +++ b/radio/src/targets/taranis/board_taranis.cpp @@ -140,7 +140,6 @@ void boardInit() #endif #if defined(REV9E) - rotencInit(); bt_open(); #endif diff --git a/radio/src/targets/taranis/board_taranis.h b/radio/src/targets/taranis/board_taranis.h index 607f1bbfd..44ae02b46 100644 --- a/radio/src/targets/taranis/board_taranis.h +++ b/radio/src/targets/taranis/board_taranis.h @@ -337,7 +337,7 @@ void bt_wakeup(void); // Top LCD driver #if defined(REV9E) void topLcdInit(void); -void topLcdOff(); +void topLcdOff(void); void topLcdRefreshStart(void); void topLcdRefreshEnd(void); void setTopFirstTimer(int32_t value); diff --git a/radio/src/targets/taranis/bootloader/Makefile b/radio/src/targets/taranis/bootloader/Makefile index a31f87ddf..84e78cfb6 100755 --- a/radio/src/targets/taranis/bootloader/Makefile +++ b/radio/src/targets/taranis/bootloader/Makefile @@ -179,10 +179,6 @@ CPPSRC = ../lcd_driver.cpp \ ../../../strhelpers.cpp \ boot.cpp -ifeq ($(PCBREV), REV9E) - CPPSRC += ../rotenc_driver.cpp -endif - # List ASM source files here ifeq ($(PCBREV), REV9E) diff --git a/radio/src/targets/taranis/hal.h b/radio/src/targets/taranis/hal.h index bab5be759..cb71133b8 100644 --- a/radio/src/targets/taranis/hal.h +++ b/radio/src/targets/taranis/hal.h @@ -26,6 +26,11 @@ #define KEYS_GPIO_PIN_PAGE GPIO_Pin_3 // PD.02 #define KEYS_GPIO_PIN_EXIT GPIO_Pin_2 // PD.03 +// Rotary Encoder +#define ENC_GPIO GPIOD +#define ENC_GPIO_PIN_A GPIO_Pin_12 // PD.12 +#define ENC_GPIO_PIN_B GPIO_Pin_13 // PD.13 + // Trims #if defined(REV9E) #define TRIMS_GPIO_REG_LHL GPIOG->IDR @@ -208,7 +213,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) + #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_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) diff --git a/radio/src/targets/taranis/keys_driver.cpp b/radio/src/targets/taranis/keys_driver.cpp index 27988085d..4eb9a0404 100644 --- a/radio/src/targets/taranis/keys_driver.cpp +++ b/radio/src/targets/taranis/keys_driver.cpp @@ -98,7 +98,29 @@ uint8_t keyDown() } #if defined(REV9E) -extern rotenc_t x9de_rotenc; +uint32_t Rotary_position; +rotenc_t x9de_rotenc; +void checkRotaryEncoder() +{ + register uint32_t dummy ; + + dummy = ENC_GPIO->IDR; // Read Rotary encoder + dummy >>= 12; // quick & dirty! + dummy &= 0x03; + if ( dummy != ( Rotary_position & 0x03 ) ) + { + if ( ( Rotary_position & 0x01 ) ^ ( ( dummy & 0x02) >> 1 ) ) + { + --x9de_rotenc; + } + else + { + ++x9de_rotenc; + } + Rotary_position &= ~0x03 ; + Rotary_position |= dummy ; + } +} #endif /* TODO common to ARM */ @@ -230,38 +252,46 @@ bool switchState(EnumKeys enuk) } #endif -#if !defined(SIMU) void keysInit() { - GPIO_InitTypeDef GPIO_InitStructure; + GPIO_InitTypeDef GPIO_InitStructure; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; + GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; + GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ; - GPIO_InitStructure.GPIO_Pin = KEYS_GPIOA_PINS; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ; - GPIO_Init(GPIOA, &GPIO_InitStructure); +#if defined(KEYS_GPIOA_PINS) + GPIO_InitStructure.GPIO_Pin = KEYS_GPIOA_PINS; + GPIO_Init(GPIOA, &GPIO_InitStructure); +#endif - GPIO_InitStructure.GPIO_Pin = KEYS_GPIOB_PINS; - GPIO_Init(GPIOB, &GPIO_InitStructure); +#if defined(KEYS_GPIOB_PINS) + GPIO_InitStructure.GPIO_Pin = KEYS_GPIOB_PINS; + GPIO_Init(GPIOB, &GPIO_InitStructure); +#endif - GPIO_InitStructure.GPIO_Pin = KEYS_GPIOC_PINS; - GPIO_Init(GPIOC, &GPIO_InitStructure); +#if defined(KEYS_GPIOC_PINS) + GPIO_InitStructure.GPIO_Pin = KEYS_GPIOC_PINS; + GPIO_Init(GPIOC, &GPIO_InitStructure); +#endif - GPIO_InitStructure.GPIO_Pin = KEYS_GPIOD_PINS; - GPIO_Init(GPIOD, &GPIO_InitStructure); +#if defined(KEYS_GPIOD_PINS) + GPIO_InitStructure.GPIO_Pin = KEYS_GPIOD_PINS; + GPIO_Init(GPIOD, &GPIO_InitStructure); +#endif - GPIO_InitStructure.GPIO_Pin = KEYS_GPIOE_PINS; - GPIO_Init(GPIOE, &GPIO_InitStructure); +#if defined(KEYS_GPIOE_PINS) + GPIO_InitStructure.GPIO_Pin = KEYS_GPIOE_PINS; + GPIO_Init(GPIOE, &GPIO_InitStructure); +#endif #if defined(KEYS_GPIOF_PINS) - GPIO_InitStructure.GPIO_Pin = KEYS_GPIOF_PINS; - GPIO_Init(GPIOF, &GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = KEYS_GPIOF_PINS; + GPIO_Init(GPIOF, &GPIO_InitStructure); #endif #if defined(KEYS_GPIOG_PINS) - GPIO_InitStructure.GPIO_Pin = KEYS_GPIOG_PINS; - GPIO_Init(GPIOG, &GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = KEYS_GPIOG_PINS; + GPIO_Init(GPIOG, &GPIO_InitStructure); #endif } -#endif diff --git a/radio/src/targets/taranis/rotenc_driver.cpp b/radio/src/targets/taranis/rotenc_driver.cpp deleted file mode 100644 index 419dbe37f..000000000 --- a/radio/src/targets/taranis/rotenc_driver.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Authors (alphabetical order) - * - Andre Bernet - * - Andreas Weitl - * - Bertrand Songis - * - Bryan J. Rentoul (Gruvin) - * - Cameron Weeks - * - Erez Raviv - * - Gabriel Birkus - * - Jean-Pierre Parisy - * - Karl Szmutny - * - Michael Blandford - * - Michal Hlavinka - * - Pat Mackenzie - * - Philip Moss - * - Rob Thomson - * - Romolo Manfredini - * - Thomas Husterer - * - * opentx is based on code named - * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, - * er9x by Erez Raviv: http://code.google.com/p/er9x/, - * and the original (and ongoing) project by - * Thomas Husterer, th9x: http://code.google.com/p/th9x/ - * - * 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" - -void rotencInit() -{ - configure_pins( GPIO_Pin_12|GPIO_Pin_13, PIN_INPUT | PIN_PULLUP | PIN_PORTD ) ; -} - -void rotencEnd() -{ -} - -uint32_t Rotary_position; -rotenc_t x9de_rotenc; -void checkRotaryEncoder() -{ - register uint32_t dummy ; - - dummy = GPIOD->IDR ; // Read Rotary encoder ( PE6, PE5 ) - dummy >>= 12 ; - dummy &= 0x03 ; // pick out the two bits - if ( dummy != ( Rotary_position & 0x03 ) ) - { - if ( ( Rotary_position & 0x01 ) ^ ( ( dummy & 0x02) >> 1 ) ) - { - --x9de_rotenc; - } - else - { - ++x9de_rotenc; - } - Rotary_position &= ~0x03 ; - Rotary_position |= dummy ; - } -}