Rotary encoder emulates PLUS and MINUS keys

This commit is contained in:
Damjan Adamic
2014-11-30 19:46:44 +01:00
parent b64d200c94
commit 9980d11740
10 changed files with 75 additions and 20 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
+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];
@@ -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;
}
}