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>
25 #define UART_BAUD_RATE 115200
28 /* This is from main.c of USBaspLoader */
29 static void initForUsbConnectivity(void)
34 /* enforce USB re-enumerate: */
35 usbDeviceDisconnect(); /* do this while interrupts are disabled */
36 while(--i){ /* fake USB disconnect for > 250 ms */
46 bool suspended = false;
48 uint16_t last_timer = timer_read();
51 CLKPR = 0x80, CLKPR = 0;
53 uart_init(UART_BAUD_RATE);
57 host_set_driver(vusb_driver());
59 debug("initForUsbConnectivity()\n");
60 initForUsbConnectivity();
65 if (usbSofCount != 0) {
68 last_timer = timer_read();
70 // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1)
71 if (timer_elapsed(last_timer) > 5) {
77 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
92 // TODO: configuration process is incosistent. it sometime fails.
93 // To prevent failing to configure NOT scan keyboard during configuration
94 if (usbConfiguration && usbInterruptIsReady()) {
97 vusb_transfer_keyboard();