Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Files at this revision

API Documentation at this revision

Comitter:
vanshg
Date:
Sat May 06 22:49:31 2017 +0000
Parent:
9:1d8e4da058cd
Child:
11:8fc2b703086b
Commit message:
Added interrupts for dip switch.; Added stm324xxx.h header; Began configuration for Tim2 and Tim5

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
--- 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();
--- a/main.h	Sat May 06 01:31:44 2017 +0000
+++ b/main.h	Sat May 06 22:49:31 2017 +0000
@@ -55,4 +55,24 @@
 int gyroY = 0;
 int gyroZ = 0;
 
+InterruptIn dipButton1(PB_15);
+InterruptIn dipButton2(PB_10);
+InterruptIn dipButton3(PB_9);
+InterruptIn dipButton4(PB_12);
+
+void enableButton1();
+void enableButton2();
+void enableButton3();
+void enableButton4();
+void disableButton1();
+void disableButton2();
+void disableButton3();
+void disableButton4();
+
+int dipFlags = 0;
+#define BUTTON1_FLAG 0x0001
+#define BUTTON2_FLAG 0x0010
+#define BUTTON3_FLAG 0x0100
+#define BUTTON4_FLAG 0x1000
+
 #endif
\ No newline at end of file