diff --git a/radio/src/Makefile b/radio/src/Makefile index 008840870..2bf399ffd 100644 --- a/radio/src/Makefile +++ b/radio/src/Makefile @@ -823,6 +823,9 @@ ifeq ($(PCB), TARANIS) ifeq ($(SWR), YES) CPPDEFS += -DSWR endif + ifeq ($(PCBREV), REV9E) + CPPSRC += targets/taranis/rotenc_driver.cpp + endif endif CC = $(TRGT)gcc diff --git a/radio/src/bootloader/boot.cpp b/radio/src/bootloader/boot.cpp index 7ea8a9de0..c4edd59a3 100644 --- a/radio/src/bootloader/boot.cpp +++ b/radio/src/bootloader/boot.cpp @@ -198,7 +198,7 @@ void interrupt10ms(void) for (int i = 1; i < 7; i++) { uint8_t value = in & (1 << i); - keys[enuk].input(value, (EnumKeys) enuk); + keys[enuk].input(value); ++enuk; } } diff --git a/radio/src/gui/menus.h b/radio/src/gui/menus.h index 49fe6189a..1e4e5c6f0 100644 --- a/radio/src/gui/menus.h +++ b/radio/src/gui/menus.h @@ -462,8 +462,13 @@ void displayWarning(uint8_t event); #if defined(PCBTARANIS) #define KEY_MOVE_UP KEY_PLUS #define KEY_MOVE_DOWN KEY_MINUS +#if defined(REV9E) + #define CURSOR_MOVED_LEFT(event) (EVT_KEY_MASK(event) == KEY_MINUS) + #define CURSOR_MOVED_RIGHT(event) (EVT_KEY_MASK(event) == KEY_PLUS) +#else #define CURSOR_MOVED_LEFT(event) (EVT_KEY_MASK(event) == KEY_PLUS) #define CURSOR_MOVED_RIGHT(event) (EVT_KEY_MASK(event) == KEY_MINUS) +#endif #define CASE_EVT_ROTARY_MOVE_RIGHT CASE_EVT_ROTARY_LEFT #define CASE_EVT_ROTARY_MOVE_LEFT CASE_EVT_ROTARY_RIGHT #define IS_ROTARY_MOVE_RIGHT IS_ROTARY_LEFT diff --git a/radio/src/gui/view_telemetry.cpp b/radio/src/gui/view_telemetry.cpp index 4009a7d01..184d8b34b 100644 --- a/radio/src/gui/view_telemetry.cpp +++ b/radio/src/gui/view_telemetry.cpp @@ -579,14 +579,14 @@ void menuTelemetryFrsky(uint8_t event) killEvents(event); // no break; #endif - case EVT_KEY_BREAK(KEY_UP): + case EVT_KEY_FIRST(KEY_UP): decrTelemetryScreen(); break; #if defined(PCBTARANIS) case EVT_KEY_BREAK(KEY_PAGE): #endif - case EVT_KEY_BREAK(KEY_DOWN): + case EVT_KEY_FIRST(KEY_DOWN): incrTelemetryScreen(); break; @@ -627,7 +627,7 @@ void menuTelemetryFrsky(uint8_t event) displayRssiLine(); #else if (!displayTelemetryScreen()) { - putEvent(event == EVT_KEY_BREAK(KEY_UP) ? event : EVT_KEY_BREAK(KEY_DOWN)); + putEvent(event == EVT_KEY_FIRST(KEY_UP) ? event : EVT_KEY_FIRST(KEY_DOWN)); } #endif } diff --git a/radio/src/gui/view_text.cpp b/radio/src/gui/view_text.cpp index 47854bdbd..390754fb5 100644 --- a/radio/src/gui/view_text.cpp +++ b/radio/src/gui/view_text.cpp @@ -115,20 +115,20 @@ void menuTextView(uint8_t event) readTextFile(lines_count); break; - case EVT_KEY_BREAK(KEY_UP): + case EVT_KEY_FIRST(KEY_UP): if (s_pgOfs == 0) break; else s_pgOfs--; // no break; - case EVT_KEY_BREAK(KEY_DOWN): - if (event == EVT_KEY_BREAK(KEY_DOWN)) { + case EVT_KEY_FIRST(KEY_DOWN): + // if (event == EVT_KEY_BREAK(KEY_DOWN)) { if (s_pgOfs+LCD_LINES-1 >= lines_count) break; else ++s_pgOfs; - } + // } readTextFile(lines_count); break; diff --git a/radio/src/keys.cpp b/radio/src/keys.cpp index 532f47130..4d9fa3cc3 100644 --- a/radio/src/keys.cpp +++ b/radio/src/keys.cpp @@ -66,7 +66,7 @@ uint8_t getEvent() #define KEY_LONG_DELAY 32 Key keys[NUM_KEYS]; -void Key::input(bool val, EnumKeys enuk) +void Key::input(bool val) { uint8_t t_vals = m_vals ; t_vals <<= 1 ; @@ -77,7 +77,7 @@ void Key::input(bool val, EnumKeys enuk) if (m_state && m_vals==0) { //gerade eben sprung auf 0 if (m_state != KSTATE_KILLED) { - putEvent(EVT_KEY_BREAK(enuk)); + putEvent(EVT_KEY_BREAK(key())); } m_cnt = 0; m_state = KSTATE_OFF; @@ -91,7 +91,7 @@ void Key::input(bool val, EnumKeys enuk) break; //fallthrough case KSTATE_START: - putEvent(EVT_KEY_FIRST(enuk)); + putEvent(EVT_KEY_FIRST(key())); inactivity.counter = 0; m_state = KSTATE_RPTDELAY; m_cnt = 0; @@ -99,7 +99,7 @@ void Key::input(bool val, EnumKeys enuk) case KSTATE_RPTDELAY: // gruvin: delay state before first key repeat if (m_cnt == KEY_LONG_DELAY) { - putEvent(EVT_KEY_LONG(enuk)); + putEvent(EVT_KEY_LONG(key())); } if (m_cnt == 40) { m_state = 16; @@ -118,7 +118,7 @@ void Key::input(bool val, EnumKeys enuk) // no break case 1: if ((m_cnt & (m_state-1)) == 0) { - putEvent(EVT_KEY_REPT(enuk)); + putEvent(EVT_KEY_REPT(key())); } break; @@ -134,6 +134,11 @@ void Key::input(bool val, EnumKeys enuk) } } +EnumKeys Key::key() const +{ + return static_cast(this - keys); +} + void pauseEvents(uint8_t event) { event = EVT_KEY_MASK(event); diff --git a/radio/src/keys.h b/radio/src/keys.h index 30318b9ba..16bac5b55 100644 --- a/radio/src/keys.h +++ b/radio/src/keys.h @@ -256,10 +256,11 @@ class Key uint8_t m_cnt; uint8_t m_state; public: - void input(bool val, EnumKeys enuk); + void input(bool val); bool state() { return m_vals > 0; } void pauseEvents() { m_state = KSTATE_PAUSE; m_cnt = 0; } void killEvents() { m_state = KSTATE_KILLED; } + EnumKeys key() const; }; extern Key keys[NUM_KEYS]; diff --git a/radio/src/targets/gruvin9x/board_gruvin9x.cpp b/radio/src/targets/gruvin9x/board_gruvin9x.cpp index eb00ad7d0..8a6e0927d 100644 --- a/radio/src/targets/gruvin9x/board_gruvin9x.cpp +++ b/radio/src/targets/gruvin9x/board_gruvin9x.cpp @@ -147,7 +147,7 @@ ISR(USART1_RX_vect) resh = (resh >> 1) & 0x01; res = ((resh << 8) | resl); if((res == 0x180) | (res == 0x1C0)){ //button REb filter - keys[BTN_REa].input((res & 0x1C0) == 0x1C0, BTN_REa); + keys[BTN_REa].input((res & 0x1C0) == 0x1C0); } else if((res & 0x100) == 0x100){ //rotary filter vpotToChange = res & 0xEF; vpot_mod_state = 1; @@ -283,7 +283,7 @@ FORCEINLINE void readKeysAndTrims() in |= (tin & 0x30) >> 3; for (int i=1; i<7; i++) { // INP_B_KEY_MEN 1 .. INP_B_KEY_LFT 6 - keys[enuk].input(in & (1< 0 - keys[BTN_REa].input(REA_DOWN(), BTN_REa); + keys[BTN_REa].input(REA_DOWN()); #endif uint8_t enuk = KEY_MENU; uint8_t in = ~readKeys(); for (i = 1; i < 7; i++) { - keys[enuk].input(in & (1 << i), (EnumKeys) enuk); + keys[enuk].input(in & (1 << i)); ++enuk; } in = readTrims(); for (i = 1; i < 256; i <<= 1) { - keys[enuk].input(in & i, (EnumKeys) enuk); + keys[enuk].input(in & i); ++enuk; } } diff --git a/radio/src/targets/stock/board_stock.cpp b/radio/src/targets/stock/board_stock.cpp index eaf5f2201..c7114a979 100644 --- a/radio/src/targets/stock/board_stock.cpp +++ b/radio/src/targets/stock/board_stock.cpp @@ -260,7 +260,7 @@ FORCEINLINE void readKeysAndTrims() uint8_t in = ~PINB; for (int i=1; i<7; i++) { // INP_B_KEY_MEN 1 .. INP_B_KEY_LFT 6 - keys[enuk].input(in & (1<IDR; +#if !defined(REV9E) register uint32_t e = GPIOE->IDR; -#if defined(REV9E) +#else register uint32_t f = GPIOF->IDR; #endif register uint32_t result = 0; #if defined(REV9E) if (f & PIN_BUTTON_ENTER) - result |= 0x02 << KEY_ENTER; #else if (e & PIN_BUTTON_ENTER) - result |= 0x02 << KEY_ENTER; #endif + result |= 0x02 << KEY_ENTER; + +#if !defined(REV9E) if (e & PIN_BUTTON_PLUS) result |= 0x02 << KEY_PLUS; if (e & PIN_BUTTON_MINUS) result |= 0x02 << KEY_MINUS; +#else + result |= 0x02 << KEY_PLUS; + result |= 0x02 << KEY_MINUS; +#endif if (d & PIN_BUTTON_MENU) result |= 0x02 << KEY_MENU; @@ -121,6 +127,10 @@ uint8_t keyDown() return ~readKeys() & 0x7E ; } +#if defined(REV9E) +extern rotenc_t x9de_rotenc; +#endif + /* TODO common to ARM */ void readKeysAndTrims() { @@ -128,15 +138,30 @@ void readKeysAndTrims() uint8_t enuk = KEY_MENU; uint32_t in = ~readKeys(); - for (i = 1; i < 7; i++) { - keys[enuk].input(in & (1 << i), (EnumKeys) enuk); + for (i = 1; i <= TRM_BASE; i++) { + keys[enuk].input(in & (1 << i)); ++enuk; } +#if defined(REV9E) + static rotenc_t rePreviousValue; + rotenc_t reNewValue = (x9de_rotenc / ROTARY_ENCODER_GRANULARITY); + int8_t scrollRE = reNewValue - rePreviousValue; + if (scrollRE) { + rePreviousValue = reNewValue; + if (scrollRE < 0) { + putEvent(EVT_KEY_FIRST(KEY_MINUS)); + } + else { + putEvent(EVT_KEY_FIRST(KEY_PLUS)); + } + } +#endif + in = readTrims(); for (i = 1; i < 256; i <<= 1) { - keys[enuk].input(in & i, (EnumKeys)enuk); + keys[enuk].input(in & i); ++enuk; } } diff --git a/radio/src/targets/taranis/rotenc_driver.cpp b/radio/src/targets/taranis/rotenc_driver.cpp new file mode 100644 index 000000000..4c78257a4 --- /dev/null +++ b/radio/src/targets/taranis/rotenc_driver.cpp @@ -0,0 +1,70 @@ +/* + * 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( 0x0060, PIN_INPUT | PIN_PULLUP | PIN_PORTE ) ; +} + +void rotencEnd() +{ +} + +uint32_t Rotary_position; +rotenc_t x9de_rotenc; +void checkRotaryEncoder() +{ + register uint32_t dummy ; + + dummy = GPIOE->IDR ; // Read Rotary encoder ( PE6, PE5 ) + dummy >>= 5 ; + 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 ; + } +}