Merge pull request #1886 from opentx/projectkk2glider/9xde_rotary_encoder_take2

Rotary encoder emulates PLUS and MINUS keys on X9DE
This commit is contained in:
Bertrand Songis
2014-11-30 13:04:40 -08:00
16 changed files with 161 additions and 36 deletions
+3
View File
@@ -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
+1 -1
View File
@@ -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;
}
}
+5
View File
@@ -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
+3 -3
View File
@@ -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
}
+4 -4
View File
@@ -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;
+10 -5
View File
@@ -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<EnumKeys>(this - keys);
}
void pauseEvents(uint8_t event)
{
event = EVT_KEY_MASK(event);
+2 -1
View File
@@ -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];
@@ -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<<i), (EnumKeys)enuk);
keys[enuk].input(in & (1<<i));
++enuk;
}
@@ -291,13 +291,13 @@ FORCEINLINE void readKeysAndTrims()
in = ~PINJ;
for (int i=0; i<8; i++) {
// INP_D_TRM_RH_UP 0 .. INP_D_TRM_LH_UP 7
keys[enuk].input(in & pgm_read_byte(crossTrim+i), (EnumKeys)enuk);
keys[enuk].input(in & pgm_read_byte(crossTrim+i));
++enuk;
}
#if defined(ROTARY_ENCODERS)
keys[BTN_REa].input(REA_DOWN(), BTN_REa);
keys[BTN_REb].input(REB_DOWN(), BTN_REb);
keys[BTN_REa].input(REA_DOWN());
keys[BTN_REb].input(REB_DOWN());
#endif
}
@@ -193,8 +193,8 @@ FORCEINLINE void readKeysAndTrims()
{
uint8_t enuk = KEY_MENU;
keys[BTN_REa].input(~PINJ & 0b00000001, BTN_REa);
keys[BTN_REb].input(~PINJ & 0b00000010, BTN_REb);
keys[BTN_REa].input(~PINJ & 0b00000001);
keys[BTN_REb].input(~PINJ & 0b00000010);
uint8_t tin = ~PINL;
uint8_t in;
@@ -203,7 +203,7 @@ FORCEINLINE void readKeysAndTrims()
for (int i=1; i<7; i++) {
//INP_B_KEY_MEN 1 .. INP_B_KEY_LFT 6
keys[enuk].input(in & (1<<i),(EnumKeys)enuk);
keys[enuk].input(in & (1<<i));
++enuk;
}
@@ -211,7 +211,7 @@ FORCEINLINE void readKeysAndTrims()
in = ~PINF;
for (int i=0; i<8; i++) {
// INP_D_TRM_RH_UP 0 .. INP_D_TRM_LH_UP 7
keys[enuk].input(in & pgm_read_byte(crossTrim+i),(EnumKeys)enuk);
keys[enuk].input(in & pgm_read_byte(crossTrim+i));
++enuk;
}
}
+3 -3
View File
@@ -125,20 +125,20 @@ void readKeysAndTrims()
register uint32_t i;
#if ROTARY_ENCODERS > 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;
}
}
+3 -3
View File
@@ -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<<i), (EnumKeys)enuk);
keys[enuk].input(in & (1<<i));
++enuk;
}
@@ -268,12 +268,12 @@ FORCEINLINE void readKeysAndTrims()
in = ~PIND;
for (int i=0; i<8; i++) {
// INP_D_TRM_RH_UP 0 .. INP_D_TRM_LH_UP 7
keys[enuk].input(in & pgm_read_byte(crossTrim+i), (EnumKeys)enuk);
keys[enuk].input(in & pgm_read_byte(crossTrim+i));
++enuk;
}
#if defined(ROTARY_ENCODER_NAVIGATION)
keys[enuk].input(ROTENC_DOWN(), (EnumKeys)enuk); // Rotary Enc. Switch
keys[enuk].input(ROTENC_DOWN()); // Rotary Enc. Switch
#endif
#if defined(NAVIGATION_STICKS)
@@ -105,6 +105,10 @@ void interrupt5ms()
pre_scale = 0 ;
per10ms();
}
#if defined(REV9E)
checkRotaryEncoder();
#endif
}
extern "C" void TIM8_TRG_COM_TIM14_IRQHandler()
@@ -131,6 +135,10 @@ void boardInit()
hapticInit();
#endif
#if defined(REV9E)
rotencInit();
#endif
#if defined(DEBUG)
DBGMCU_APB1PeriphConfig(DBGMCU_IWDG_STOP|DBGMCU_TIM1_STOP|DBGMCU_TIM2_STOP|DBGMCU_TIM3_STOP|DBGMCU_TIM6_STOP|DBGMCU_TIM8_STOP|DBGMCU_TIM10_STOP|DBGMCU_TIM13_STOP|DBGMCU_TIM14_STOP, ENABLE);
#endif
@@ -172,6 +172,13 @@ uint32_t readTrims(void);
#define DBLKEYS_PRESSED_RGT_UP(i) ((in & ((2<<KEY_ENTER) + (2<<KEY_MINUS))) == ((2<<KEY_ENTER) + (2<<KEY_MINUS)))
#define DBLKEYS_PRESSED_LFT_DWN(i) ((in & ((2<<KEY_PAGE) + (2<<KEY_EXIT))) == ((2<<KEY_PAGE) + (2<<KEY_EXIT)))
#if defined(REV9E)
// Rotary Encoder driver
void rotencInit();
void rotencEnd();
void checkRotaryEncoder();
#endif
// WDT driver
#if !defined(SIMU)
#define wdt_disable()
+2 -1
View File
@@ -258,7 +258,8 @@
#define PIN_PORTA 0x0000
#define PIN_PORTB 0x0100
#define PIN_PORTC 0x0200
#define PIN_PORTD 0x0300
#define PIN_PORTD 0x0300
#define PIN_PORTE 0x0400
#define PIN_PER_1 0x0010
#define PIN_PER_2 0x0020
#define PIN_PER_3 0x0030
+31 -6
View File
@@ -41,23 +41,29 @@
uint32_t readKeys()
{
register uint32_t d = GPIOD->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;
}
}
@@ -0,0 +1,70 @@
/*
* Authors (alphabetical order)
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Gabriel Birkus
* - Jean-Pierre Parisy
* - Karl Szmutny
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - 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 ;
}
}