[Horus] Rotary encoder initialization now good

This commit is contained in:
Bertrand Songis
2016-01-25 18:40:21 +01:00
parent 48365f36a5
commit 07d62e39db
2 changed files with 12 additions and 14 deletions
+7 -10
View File
@@ -90,23 +90,18 @@ uint8_t keyDown()
}
int32_t rotencValue;
uint32_t rotencPosition;
void checkRotaryEncoder()
{
static uint32_t Rotary_position;
register uint32_t dummy ;
dummy = ENC_GPIO->IDR ; // Read Rotary encode
dummy >>= 10; // quick & dirty!
dummy &= 0x03 ; // pick out the two bits
if ( dummy != ( Rotary_position & 0x03 ) ) {
if ( ( Rotary_position & 0x01 ) ^ ( ( dummy & 0x02) >> 1 ) ) {
register uint32_t newpos = ROTARY_ENCODER_POSITION();
if (newpos != rotencPosition) {
if ((rotencPosition & 0x01) ^ ((newpos & 0x02) >> 1)) {
--rotencValue;
}
else {
++rotencValue;
}
Rotary_position &= ~0x03 ;
Rotary_position |= dummy ;
rotencPosition = newpos;
}
}
@@ -227,4 +222,6 @@ void keysInit()
GPIO_InitStructure.GPIO_Pin = KEYS_GPIOJ_PINS;
GPIO_Init(GPIOJ, &GPIO_InitStructure);
rotencPosition = ROTARY_ENCODER_POSITION();
}