5 #include <avr/interrupt.h>
13 static volatile bool lastLeftA;
14 static volatile bool lastLeftB;
15 static volatile bool lastRightA;
16 static volatile bool lastRightB;
18 static volatile bool errorLeft;
19 static volatile bool errorRight;
23 static volatile uint16_t countLeft;
24 static volatile uint16_t countRight;
28 bool newLeftB = FastGPIO::Pin<LEFT_B>::isInputHigh();
29 bool newLeftA = FastGPIO::Pin<LEFT_XOR>::isInputHigh() ^ newLeftB;
31 countLeft += (newLeftA ^ lastLeftB) - (lastLeftA ^ newLeftB);
33 if((lastLeftA ^ newLeftA) & (lastLeftB ^ newLeftB))
42 static void rightISR()
44 bool newRightB = FastGPIO::Pin<RIGHT_B>::isInputHigh();
45 bool newRightA = FastGPIO::Pin<RIGHT_XOR>::isInputHigh() ^ newRightB;
47 countRight += (newRightA ^ lastRightB) - (lastRightA ^ newRightB);
49 if((lastRightA ^ newRightA) & (lastRightB ^ newRightB))
54 lastRightA = newRightA;
55 lastRightB = newRightB;
58 void Zumo32U4Encoders::init2()
61 FastGPIO::Pin<LEFT_XOR>::setInputPulledUp();
62 FastGPIO::Pin<LEFT_B>::setInputPulledUp();
63 FastGPIO::Pin<RIGHT_XOR>::setInputPulledUp();
64 FastGPIO::Pin<RIGHT_B>::setInputPulledUp();
69 PCMSK0 = (1 << PCINT4);
75 attachInterrupt(4, rightISR, CHANGE);
80 lastLeftB = FastGPIO::Pin<LEFT_B>::isInputHigh();
81 lastLeftA = FastGPIO::Pin<LEFT_XOR>::isInputHigh() ^ lastLeftB;
85 lastRightB = FastGPIO::Pin<RIGHT_B>::isInputHigh();
86 lastRightA = FastGPIO::Pin<RIGHT_XOR>::isInputHigh() ^ lastRightB;
96 int16_t counts = countLeft;
106 int16_t counts = countRight;
116 int16_t counts = countLeft;
127 int16_t counts = countRight;
137 bool error = errorLeft;
146 bool error = errorRight;
static int16_t getCountsLeft()
static int16_t getCountsAndResetRight()
static int16_t getCountsAndResetLeft()
static bool checkErrorRight()
static bool checkErrorLeft()
static int16_t getCountsRight()