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>
23 #include "rgblight_reconfig.h"
25 #if (defined(RGB_MIDI) || defined(RGBLIGHT_ANIMATIONS)) && defined(RGBLIGHT_ENABLE)
26 # include "rgblight.h"
29 #define UART_BAUD_RATE 115200
31 /* This is from main.c of USBaspLoader */
32 static void initForUsbConnectivity(void) {
36 /* enforce USB re-enumerate: */
37 usbDeviceDisconnect(); /* do this while interrupts are disabled */
38 while (--i
) { /* fake USB disconnect for > 250 ms */
47 bool suspended
= false;
49 uint16_t last_timer
= timer_read();
53 // avoid unintentional changes of clock frequency in devices that have a
55 CLKPR
= 0x80, CLKPR
= 0;
58 uart_init(UART_BAUD_RATE
);
63 host_set_driver(vusb_driver());
65 debug("initForUsbConnectivity()\n");
66 initForUsbConnectivity();
71 if (usbSofCount
!= 0) {
74 last_timer
= timer_read();
76 // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1)
77 if (timer_elapsed(last_timer
) > 5) {
83 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
98 // TODO: configuration process is incosistent. it sometime fails.
99 // To prevent failing to configure NOT scan keyboard during configuration
100 if (usbConfiguration
&& usbInterruptIsReady()) {
103 vusb_transfer_keyboard();