Permalink
Browse files

add usb detection code

  • Loading branch information...
1 parent 73ce43d commit a8a9d14f1a6b83e4e298b212d4b48a47385eff7e @phooky committed Mar 6, 2014
Showing with 10 additions and 11 deletions.
  1. +9 −10 code/SnapPadv1/main.c
  2. +1 −1 code/SnapPadv1/timer.c
View
@@ -97,18 +97,17 @@ void main (void)
// Twinned pad and USB disconnected - TWINNED_SLAVE or TWINNED_MASTER (uart contention for role)
// First, scan the USB connection for ~100ms to see if the device is being enumerated.
- // TODO
-
+ bool usb_attached = false;
timer_reset();
- while (timer_msec() < 1000);
- leds_set_led(0,0xff);
- while (timer_msec() < 2000);
- leds_set_led(1,0xff);
- while (timer_msec() < 3000);
- leds_set_led(2,0xff);
- while (timer_msec() < 4000);
+ while (timer_msec() < 1000) {
+ uint8_t s = USB_connectionState();
+ if (s == ST_ENUM_ACTIVE) {
+ usb_attached = true;
+ break;
+ }
+ }
- cs = uart_determine_state(button_pressed_on_startup);
+ cs = uart_determine_state(usb_attached);
if (cs == CS_TWINNED_MASTER) {
View
@@ -14,7 +14,7 @@ void timer_init() {
// Set up msec timer
TA1CCR0 = 1000; // Count up to 1ms
TA1CCTL0 = 0x10; // Enable counter interrupts, bit 4=1
- TA1CTL = TASSEL_1 | MC_2 | ID1 | ID0; // Clock SMCLK, /8, continuous up mode
+ TA1CTL = TASSEL_1 | MC_1 | ID1 | ID0; // Clock SMCLK, /8, continuous up mode
TA1CTL |= TACLR; // Clear and restart clock
}

0 comments on commit a8a9d14

Please sign in to comment.