9 extern bool remote_wakeup;
12 void usb_init(void); // initialize everything
13 uint8_t usb_configured(void); // is the USB port configured
14 void usb_remote_wakeup(void);
17 #define EP_TYPE_CONTROL 0x00
18 #define EP_TYPE_BULK_IN 0x81
19 #define EP_TYPE_BULK_OUT 0x80
20 #define EP_TYPE_INTERRUPT_IN 0xC1
21 #define EP_TYPE_INTERRUPT_OUT 0xC0
22 #define EP_TYPE_ISOCHRONOUS_IN 0x41
23 #define EP_TYPE_ISOCHRONOUS_OUT 0x40
25 #define EP_SINGLE_BUFFER 0x02
26 #define EP_DOUBLE_BUFFER 0x06
28 #define EP_SIZE(s) ((s) == 64 ? 0x30 : \
33 #define MAX_ENDPOINT 4
35 #define LSB(n) (n & 255)
36 #define MSB(n) ((n >> 8) & 255)
38 #if defined(__AVR_AT90USB162__)
40 #define PLL_CONFIG() (PLLCSR = ((1<<PLLE)|(1<<PLLP0)))
41 #define USB_CONFIG() (USBCON = (1<<USBE))
42 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
43 #elif defined(__AVR_ATmega32U4__)
44 #define HW_CONFIG() (UHWCON = 0x01)
45 #define PLL_CONFIG() (PLLCSR = 0x12)
46 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
47 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
48 #elif defined(__AVR_AT90USB646__)
49 #define HW_CONFIG() (UHWCON = 0x81)
50 #define PLL_CONFIG() (PLLCSR = 0x1A)
51 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
52 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
53 #elif defined(__AVR_AT90USB1286__)
54 #define HW_CONFIG() (UHWCON = 0x81)
55 #define PLL_CONFIG() (PLLCSR = 0x16)
56 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
57 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
60 // standard control endpoint request types
62 #define CLEAR_FEATURE 1
65 #define GET_DESCRIPTOR 6
66 #define GET_CONFIGURATION 8
67 #define SET_CONFIGURATION 9
68 #define GET_INTERFACE 10
69 #define SET_INTERFACE 11
70 // HID (human interface device)
71 #define HID_GET_REPORT 1
72 #define HID_GET_IDLE 2
73 #define HID_GET_PROTOCOL 3
74 #define HID_SET_REPORT 9
75 #define HID_SET_IDLE 10
76 #define HID_SET_PROTOCOL 11
77 #define HID_REPORT_INPUT 1
78 #define HID_REPORT_OUTPUT 2
79 #define HID_REPORT_FEATURE 3
80 // CDC (communication class device)
81 #define CDC_SET_LINE_CODING 0x20
82 #define CDC_GET_LINE_CODING 0x21
83 #define CDC_SET_CONTROL_LINE_STATE 0x22
84 // HID feature selectors
85 #define DEVICE_REMOTE_WAKEUP 1
86 #define ENDPOINT_HALT 0
90 /*------------------------------------------------------------------*
91 * Keyboard descriptor setting
92 *------------------------------------------------------------------*/
93 #define KBD_INTERFACE 0
94 #define KBD_ENDPOINT 1
96 #define KBD_BUFFER EP_DOUBLE_BUFFER
97 #define KBD_REPORT_KEYS (KBD_SIZE - 2)
100 #ifdef USB_NKRO_ENABLE
101 #define KBD2_INTERFACE 4
102 #define KBD2_ENDPOINT 5
104 #define KBD2_BUFFER EP_DOUBLE_BUFFER
105 #define KBD2_REPORT_KEYS (KBD2_SIZE - 1)