diff options
Diffstat (limited to 'protocol/vusb/main.c')
| -rw-r--r-- | protocol/vusb/main.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/protocol/vusb/main.c b/protocol/vusb/main.c new file mode 100644 index 000000000..1bf9035b3 --- /dev/null +++ b/protocol/vusb/main.c | |||
| @@ -0,0 +1,99 @@ | |||
| 1 | /* Name: main.c | ||
| 2 | * Project: hid-mouse, a very simple HID example | ||
| 3 | * Author: Christian Starkjohann | ||
| 4 | * Creation Date: 2008-04-07 | ||
| 5 | * Tabsize: 4 | ||
| 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 $ | ||
| 9 | */ | ||
| 10 | #include <stdint.h> | ||
| 11 | #include <avr/interrupt.h> | ||
| 12 | #include <avr/wdt.h> | ||
| 13 | #include <avr/sleep.h> | ||
| 14 | #include <util/delay.h> | ||
| 15 | #include "usbdrv.h" | ||
| 16 | #include "oddebug.h" | ||
| 17 | #include "vusb.h" | ||
| 18 | #include "keyboard.h" | ||
| 19 | #include "host.h" | ||
| 20 | #include "timer.h" | ||
| 21 | #include "uart.h" | ||
| 22 | #include "debug.h" | ||
| 23 | |||
| 24 | |||
| 25 | #define UART_BAUD_RATE 115200 | ||
| 26 | |||
| 27 | |||
| 28 | /* This is from main.c of USBaspLoader */ | ||
| 29 | static void initForUsbConnectivity(void) | ||
| 30 | { | ||
| 31 | uint8_t i = 0; | ||
| 32 | |||
| 33 | usbInit(); | ||
| 34 | /* enforce USB re-enumerate: */ | ||
| 35 | usbDeviceDisconnect(); /* do this while interrupts are disabled */ | ||
| 36 | while(--i){ /* fake USB disconnect for > 250 ms */ | ||
| 37 | wdt_reset(); | ||
| 38 | _delay_ms(1); | ||
| 39 | } | ||
| 40 | usbDeviceConnect(); | ||
| 41 | sei(); | ||
| 42 | } | ||
| 43 | |||
| 44 | int main(void) | ||
| 45 | { | ||
| 46 | bool suspended = false; | ||
| 47 | #if USB_COUNT_SOF | ||
| 48 | uint16_t last_timer = timer_read(); | ||
| 49 | #endif | ||
| 50 | |||
| 51 | CLKPR = 0x80, CLKPR = 0; | ||
| 52 | #ifndef PS2_USE_USART | ||
| 53 | uart_init(UART_BAUD_RATE); | ||
| 54 | #endif | ||
| 55 | |||
| 56 | debug_enable = true; | ||
| 57 | print_enable = true; | ||
| 58 | |||
| 59 | debug("keyboard_init()\n"); | ||
| 60 | keyboard_init(); | ||
| 61 | host_set_driver(vusb_driver()); | ||
| 62 | |||
| 63 | debug("initForUsbConnectivity()\n"); | ||
| 64 | initForUsbConnectivity(); | ||
| 65 | |||
| 66 | debug("main loop\n"); | ||
| 67 | while (1) { | ||
| 68 | #if USB_COUNT_SOF | ||
| 69 | if (usbSofCount != 0) { | ||
| 70 | suspended = false; | ||
| 71 | usbSofCount = 0; | ||
| 72 | last_timer = timer_read(); | ||
| 73 | } else { | ||
| 74 | // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1) | ||
| 75 | if (timer_elapsed(last_timer) > 5) { | ||
| 76 | suspended = true; | ||
| 77 | /* | ||
| 78 | uart_putchar('S'); | ||
| 79 | _delay_ms(1); | ||
| 80 | cli(); | ||
| 81 | set_sleep_mode(SLEEP_MODE_PWR_DOWN); | ||
| 82 | sleep_enable(); | ||
| 83 | sleep_bod_disable(); | ||
| 84 | sei(); | ||
| 85 | sleep_cpu(); | ||
| 86 | sleep_disable(); | ||
| 87 | _delay_ms(10); | ||
| 88 | uart_putchar('W'); | ||
| 89 | */ | ||
| 90 | } | ||
| 91 | } | ||
| 92 | #endif | ||
| 93 | if (!suspended) | ||
| 94 | usbPoll(); | ||
| 95 | keyboard_proc(); | ||
| 96 | if (!suspended) | ||
| 97 | vusb_transfer_keyboard(); | ||
| 98 | } | ||
| 99 | } | ||
