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
@@ -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;
}
}