Rotary encoder refactoring
This commit is contained in:
@@ -475,10 +475,7 @@ void boardInit()
|
||||
|
||||
eepromInit();
|
||||
|
||||
#if defined(ROTARY_ENCODERS)
|
||||
rotencInit();
|
||||
#endif
|
||||
|
||||
rotaryEncoderInit();
|
||||
init_SDcard();
|
||||
}
|
||||
#else
|
||||
|
||||
@@ -38,11 +38,10 @@ void boardInit(void);
|
||||
#define boardOff() pwrOff()
|
||||
|
||||
// Rotary Encoder driver
|
||||
void rotencInit();
|
||||
void rotencEnd();
|
||||
void rotaryEncoderInit();
|
||||
void rotaryEncoderEnd();
|
||||
|
||||
#if !defined(REVX) && !defined(AR9X)
|
||||
#define ROTARY_ENCODERS 1
|
||||
#define ROTARY_ENCODER_NAVIGATION
|
||||
#define REA_DOWN() (!(PIOB->PIO_PDSR & 0x40))
|
||||
#else
|
||||
@@ -74,10 +73,6 @@ enum EnumKeys
|
||||
TRM_RH_UP,
|
||||
TRM_LAST = TRM_RH_UP,
|
||||
|
||||
#if defined(ROTARY_ENCODERS)
|
||||
BTN_REa,
|
||||
#endif
|
||||
|
||||
NUM_KEYS
|
||||
};
|
||||
|
||||
|
||||
@@ -109,10 +109,6 @@ void readKeysAndTrims()
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
#if ROTARY_ENCODERS > 0
|
||||
keys[BTN_REa].input(REA_DOWN());
|
||||
#endif
|
||||
|
||||
uint8_t index = 0;
|
||||
uint8_t keys_input = readKeys();
|
||||
for (i = 1; i < 7; i++) {
|
||||
|
||||
@@ -20,38 +20,38 @@
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
void rotencInit()
|
||||
void rotaryEncoderInit()
|
||||
{
|
||||
configure_pins( PIO_PC19 | PIO_PC21, PIN_ENABLE | PIN_INPUT | PIN_PORTC | PIN_PULLUP ) ; // 19 and 21 are rotary encoder
|
||||
configure_pins( PIO_PB6, PIN_ENABLE | PIN_INPUT | PIN_PORTB | PIN_PULLUP ) ; // rotary encoder switch
|
||||
PIOC->PIO_IER = PIO_PC19 | PIO_PC21 ;
|
||||
NVIC_EnableIRQ(PIOC_IRQn) ;
|
||||
configure_pins(PIO_PC19 | PIO_PC21, PIN_ENABLE | PIN_INPUT | PIN_PORTC | PIN_PULLUP); // 19 and 21 are rotary encoder
|
||||
configure_pins(PIO_PB6, PIN_ENABLE | PIN_INPUT | PIN_PORTB | PIN_PULLUP); // rotary encoder switch
|
||||
PIOC->PIO_IER = PIO_PC19 | PIO_PC21;
|
||||
NVIC_EnableIRQ(PIOC_IRQn);
|
||||
}
|
||||
|
||||
void rotencEnd()
|
||||
void rotaryEncoderEnd()
|
||||
{
|
||||
NVIC_DisableIRQ(PIOC_IRQn) ;
|
||||
PIOC->PIO_IDR = PIO_PC19 | PIO_PC21 ;
|
||||
NVIC_DisableIRQ(PIOC_IRQn);
|
||||
PIOC->PIO_IDR = PIO_PC19 | PIO_PC21;
|
||||
}
|
||||
|
||||
volatile uint32_t Rotary_position ;
|
||||
volatile uint32_t Rotary_position;
|
||||
extern "C" void PIOC_IRQHandler()
|
||||
{
|
||||
uint32_t dummy;
|
||||
|
||||
dummy = PIOC->PIO_ISR ; // Read and clear status register
|
||||
(void) dummy ; // Discard value - prevents compiler warning
|
||||
dummy = PIOC->PIO_ISR; // Read and clear status register
|
||||
(void) dummy; // Discard value - prevents compiler warning
|
||||
|
||||
dummy = PIOC->PIO_PDSR ; // Read Rotary encoder (PC19, PC21)
|
||||
dummy >>= 19 ;
|
||||
dummy &= 0x05 ; // pick out the three bits
|
||||
if ( dummy != ( Rotary_position & 0x05 ) ) {
|
||||
if ( ( Rotary_position & 0x01 ) ^ ( ( dummy & 0x04) >> 2 ) )
|
||||
incRotaryEncoder(0, -1);
|
||||
dummy = PIOC->PIO_PDSR; // Read Rotary encoder (PC19, PC21)
|
||||
dummy >>= 19;
|
||||
dummy &= 0x05; // pick out the three bits
|
||||
if (dummy != (Rotary_position & 0x05)) {
|
||||
if ((Rotary_position & 0x01) ^ ((dummy & 0x04) >> 2))
|
||||
rotencValue -= 1;
|
||||
else
|
||||
incRotaryEncoder(0, +1);
|
||||
rotencValue += 1;
|
||||
|
||||
Rotary_position &= ~0x45 ;
|
||||
Rotary_position |= dummy ;
|
||||
Rotary_position &= ~0x45;
|
||||
Rotary_position |= dummy;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user