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);
19 #define EP_TYPE_CONTROL 0x00
20 #define EP_TYPE_BULK_IN 0x81
21 #define EP_TYPE_BULK_OUT 0x80
22 #define EP_TYPE_INTERRUPT_IN 0xC1
23 #define EP_TYPE_INTERRUPT_OUT 0xC0
24 #define EP_TYPE_ISOCHRONOUS_IN 0x41
25 #define EP_TYPE_ISOCHRONOUS_OUT 0x40
27 #define EP_SINGLE_BUFFER 0x02
28 #define EP_DOUBLE_BUFFER 0x06
30 #define EP_SIZE(s) ((s) == 64 ? 0x30 : \
35 #define MAX_ENDPOINT 4
37 #define LSB(n) (n & 255)
38 #define MSB(n) ((n >> 8) & 255)
40 #if defined(__AVR_AT90USB162__)
42 #define PLL_CONFIG() (PLLCSR = ((1<<PLLE)|(1<<PLLP0)))
43 #define USB_CONFIG() (USBCON = (1<<USBE))
44 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
45 #elif defined(__AVR_ATmega32U4__)
46 #define HW_CONFIG() (UHWCON = 0x01)
47 #define PLL_CONFIG() (PLLCSR = 0x12)
48 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
49 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
50 #elif defined(__AVR_AT90USB646__)
51 #define HW_CONFIG() (UHWCON = 0x81)
52 #define PLL_CONFIG() (PLLCSR = 0x1A)
53 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
54 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
55 #elif defined(__AVR_AT90USB1286__)
56 #define HW_CONFIG() (UHWCON = 0x81)
57 #define PLL_CONFIG() (PLLCSR = 0x16)
58 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
59 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
62 // standard control endpoint request types
64 #define CLEAR_FEATURE 1
67 #define GET_DESCRIPTOR 6
68 #define GET_CONFIGURATION 8
69 #define SET_CONFIGURATION 9
70 #define GET_INTERFACE 10
71 #define SET_INTERFACE 11
72 // HID (human interface device)
73 #define HID_GET_REPORT 1
74 #define HID_GET_IDLE 2
75 #define HID_GET_PROTOCOL 3
76 #define HID_SET_REPORT 9
77 #define HID_SET_IDLE 10
78 #define HID_SET_PROTOCOL 11
79 #define HID_REPORT_INPUT 1
80 #define HID_REPORT_OUTPUT 2
81 #define HID_REPORT_FEATURE 3
82 // CDC (communication class device)
83 #define CDC_SET_LINE_CODING 0x20
84 #define CDC_GET_LINE_CODING 0x21
85 #define CDC_SET_CONTROL_LINE_STATE 0x22
86 // HID feature selectors
87 #define DEVICE_REMOTE_WAKEUP 1
88 #define ENDPOINT_HALT 0