]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/protocol/vusb/main.c
2 * Project: hid-mouse, a very simple HID example
3 * Author: Christian Starkjohann
4 * Creation Date: 2008-04-07
6 * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
7 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 * This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $
11 #include <avr/interrupt.h>
13 #include <avr/sleep.h>
14 #include <util/delay.h>
26 #define UART_BAUD_RATE 115200
29 /* This is from main.c of USBaspLoader */
30 static void initForUsbConnectivity(void)
35 /* enforce USB re-enumerate: */
36 usbDeviceDisconnect(); /* do this while interrupts are disabled */
37 while(--i
){ /* fake USB disconnect for > 250 ms */
45 void usb_remote_wakeup(void) {
48 int8_t ddr_orig
= USBDDR
;
49 USBOUT
|= (1 << USBMINUS
);
50 USBDDR
= ddr_orig
| USBMASK
;
57 USBOUT
&= ~(1 << USBMINUS
);
64 bool suspended
= false;
66 uint16_t last_timer
= timer_read();
69 CLKPR
= 0x80, CLKPR
= 0;
71 uart_init(UART_BAUD_RATE
);
75 host_set_driver(vusb_driver());
77 debug("initForUsbConnectivity()\n");
78 initForUsbConnectivity();
83 if (usbSofCount
!= 0) {
86 last_timer
= timer_read();
88 // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1)
89 if (timer_elapsed(last_timer
) > 5) {
97 // TODO: configuration process is incosistent. it sometime fails.
98 // To prevent failing to configure NOT scan keyboard during configuration
99 if (usbConfiguration
&& usbInterruptIsReady()) {
102 vusb_transfer_keyboard();
103 } else if (suspend_wakeup_condition()) {