Mouse code for the MacroRat
Diff: main.cpp
- Revision:
- 10:810d1849da9d
- Parent:
- 9:1d8e4da058cd
- Child:
- 11:8fc2b703086b
diff -r 1d8e4da058cd -r 810d1849da9d main.cpp --- a/main.cpp Sat May 06 01:31:44 2017 +0000 +++ b/main.cpp Sat May 06 22:49:31 2017 +0000 @@ -6,6 +6,7 @@ #include <stdlib.h> #include "ITG3200.h" +#include "stm32f4xx.h" #include "QEI.h" // PID @@ -75,8 +76,31 @@ { } - - +} + +void enableButton1() { + dipFlags |= BUTTON1_FLAG; +} +void enableButton2() { + dipFlags |= BUTTON2_FLAG; +} +void enableButton3() { + dipFlags |= BUTTON3_FLAG; +} +void enableButton4() { + dipFlags |= BUTTON4_FLAG; +} +void disableButton1() { + dipFlags &= ~BUTTON1_FLAG; +} +void disableButton2() { + dipFlags &= ~BUTTON2_FLAG; +} +void disableButton3() { + dipFlags &= ~BUTTON3_FLAG; +} +void disableButton4() { + dipFlags &= ~BUTTON4_FLAG; } int main() @@ -107,6 +131,23 @@ // PB_3 is B of left QEI encoder0( PA_5, PB_3, NC, PULSES, QEI::X4_ENCODING ); QEI encoder1( PA_1, PA_0, NC, PULSES, QEI::X4_ENCODING ); + + // TODO: Setting all the registers and what not for Quadrature Encoders + RCC->APB1ENR |= 0x1001; // Enable clock for Tim2 (Bit 0) and Tim5 (Bit 3) + RCC->AHB1ENR |= 0x11; // Enable GPIO port clock enables for Tim2(A) and Tim5(B) + GPIOA->AFR[0] |= 0x10; // Set GPIO alternate function modes for Tim2 + GPIOB->AFR[0] |= 0x100; // Set GPIO alternate function modes for Tim5 + + dipButton1.rise(&enableButton1); + dipButton2.rise(&enableButton2); + dipButton3.rise(&enableButton3); + dipButton4.rise(&enableButton4); + + dipButton1.fall(&disableButton1); + dipButton2.fall(&disableButton2); + dipButton3.fall(&disableButton3); + dipButton4.fall(&disableButton4); + while (1) { moveForwardUntilWallIr();