From 005e0ba51aafb6b26383fbd7df9000399c79098d Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sat, 21 Jan 2012 22:30:38 +0100 Subject: Added USB interrupt handler. --- main.cpp | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'main.cpp') 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(); } } -- cgit v1.2.3