summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2012-01-21 22:30:38 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2012-01-21 22:30:38 +0100
commit005e0ba51aafb6b26383fbd7df9000399c79098d (patch)
tree9b265a735276d7da262a6bd0851b2bf57776efff
parentd734fc168e94f0bdb42f6b28e702d5a909146cef (diff)
Added USB interrupt handler.
-rw-r--r--hal/interrupt.cpp8
-rw-r--r--hal/pin.h18
-rw-r--r--main.cpp40
3 files changed, 51 insertions, 15 deletions
diff --git a/hal/interrupt.cpp b/hal/interrupt.cpp
index 611b09c..ab9c89a 100644
--- a/hal/interrupt.cpp
+++ b/hal/interrupt.cpp
@@ -166,4 +166,12 @@ vector_t vectors[] __attribute__((section(".vectors"))) = {
interrupt<Interrupt::DMA2_Channel2>,
interrupt<Interrupt::DMA2_Channel3>,
interrupt<Interrupt::DMA2_Channel4_5>,
+ 0, // 60
+ 0, // 61
+ 0, // 62
+ 0, // 63
+ 0, // 64
+ 0, // 65
+ 0, // 66
+ interrupt<(Interrupt::IRQ)67>, // 67
};
diff --git a/hal/pin.h b/hal/pin.h
index 29ec158..4102e6a 100644
--- a/hal/pin.h
+++ b/hal/pin.h
@@ -59,6 +59,24 @@ class Pin {
}
}
};
+
+static Pin PA0(GPIOA, 0);
+static Pin PA1(GPIOA, 1);
+static Pin PA2(GPIOA, 2);
+static Pin PA3(GPIOA, 3);
+static Pin PA4(GPIOA, 4);
+static Pin PA5(GPIOA, 5);
+static Pin PA6(GPIOA, 6);
+static Pin PA7(GPIOA, 7);
+static Pin PA8(GPIOA, 8);
+static Pin PA9(GPIOA, 9);
+static Pin PA10(GPIOA, 10);
+static Pin PA11(GPIOA, 11);
+static Pin PA12(GPIOA, 12);
+static Pin PA13(GPIOA, 13);
+static Pin PA14(GPIOA, 14);
+static Pin PA15(GPIOA, 15);
+
static Pin PB0(GPIOB, 0);
static Pin PB1(GPIOB, 1);
static Pin PB2(GPIOB, 2);
diff --git a/main.cpp b/main.cpp
index 3ea82b8..2898f2b 100644
--- a/main.cpp
+++ b/main.cpp
@@ -13,6 +13,18 @@ static Pin& led_yellow = PD13;
static Pin& led_red = PD14;
static Pin& led_blue = PD15;
+static Pin& usb_dm = PA11;
+static Pin& usb_dp = PA12;
+static Pin& usb_vbus = PA9;
+
+template<>
+void interrupt<(Interrupt::IRQ)67>() {
+ led_blue.toggle();
+ led_red.toggle();
+
+ OTG_FS.reg.GINTSTS = 0xffffffff;
+}
+
int main() {
// Initialize system timer.
STK.LOAD = 168000000 / 8 / 1000; // 1000 Hz.
@@ -27,8 +39,19 @@ int main() {
led_red.set_mode(Pin::Output);
led_blue.set_mode(Pin::Output);
+ led_red.on();
+ led_blue.off();
+
+ usb_dm.set_mode(Pin::AF);
+ usb_dm.set_af(10);
+ usb_dp.set_mode(Pin::AF);
+ usb_dp.set_af(10);
+
RCC.enable(RCC.OTGFS);
-
+ Interrupt::enable((Interrupt::IRQ)67);
+
+ OTG_FS.reg.GAHBCFG = 1;
+
// USB configuration
OTG_FS.reg.GUSBCFG = (1 << 30) | (0xf << 10) | (1 << 9) | (1 << 8);
// FDMOD TRDT HNPCAP SRPCAP
@@ -46,20 +69,7 @@ int main() {
// VBUSBSEN
while(1) {
- led_green.on();
- Time::sleep(100);
- led_green.off();
-
- led_yellow.on();
- Time::sleep(100);
- led_yellow.off();
-
- led_red.on();
- Time::sleep(100);
- led_red.off();
-
- led_blue.on();
+ led_green.toggle();
Time::sleep(100);
- led_blue.off();
}
}