]> git.gir.st - tmk_keyboard.git/blob - usb.h
changed wait time for volume control.
[tmk_keyboard.git] / usb.h
1 #ifndef USB_H
2 #define USB_H 1
3
4 #include <stdint.h>
5 #include <stdbool.h>
6 #include <avr/io.h>
7
8
9 void usb_init(void); // initialize everything
10 uint8_t usb_configured(void); // is the USB port configured
11 void usb_remote_wakeup(void);
12
13
14
15
16 #define EP_TYPE_CONTROL 0x00
17 #define EP_TYPE_BULK_IN 0x81
18 #define EP_TYPE_BULK_OUT 0x80
19 #define EP_TYPE_INTERRUPT_IN 0xC1
20 #define EP_TYPE_INTERRUPT_OUT 0xC0
21 #define EP_TYPE_ISOCHRONOUS_IN 0x41
22 #define EP_TYPE_ISOCHRONOUS_OUT 0x40
23
24 #define EP_SINGLE_BUFFER 0x02
25 #define EP_DOUBLE_BUFFER 0x06
26
27 #define EP_SIZE(s) ((s) == 64 ? 0x30 : \
28 ((s) == 32 ? 0x20 : \
29 ((s) == 16 ? 0x10 : \
30 0x00)))
31
32 #define MAX_ENDPOINT 4
33
34 #define LSB(n) (n & 255)
35 #define MSB(n) ((n >> 8) & 255)
36
37 #if defined(__AVR_AT90USB162__)
38 #define HW_CONFIG()
39 #define PLL_CONFIG() (PLLCSR = ((1<<PLLE)|(1<<PLLP0)))
40 #define USB_CONFIG() (USBCON = (1<<USBE))
41 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
42 #elif defined(__AVR_ATmega32U4__)
43 #define HW_CONFIG() (UHWCON = 0x01)
44 #define PLL_CONFIG() (PLLCSR = 0x12)
45 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
46 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
47 #elif defined(__AVR_AT90USB646__)
48 #define HW_CONFIG() (UHWCON = 0x81)
49 #define PLL_CONFIG() (PLLCSR = 0x1A)
50 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
51 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
52 #elif defined(__AVR_AT90USB1286__)
53 #define HW_CONFIG() (UHWCON = 0x81)
54 #define PLL_CONFIG() (PLLCSR = 0x16)
55 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
56 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
57 #endif
58
59 // standard control endpoint request types
60 #define GET_STATUS 0
61 #define CLEAR_FEATURE 1
62 #define SET_FEATURE 3
63 #define SET_ADDRESS 5
64 #define GET_DESCRIPTOR 6
65 #define GET_CONFIGURATION 8
66 #define SET_CONFIGURATION 9
67 #define GET_INTERFACE 10
68 #define SET_INTERFACE 11
69 // HID (human interface device)
70 #define HID_GET_REPORT 1
71 #define HID_GET_IDLE 2
72 #define HID_GET_PROTOCOL 3
73 #define HID_SET_REPORT 9
74 #define HID_SET_IDLE 10
75 #define HID_SET_PROTOCOL 11
76 #define HID_REPORT_INPUT 1
77 #define HID_REPORT_OUTPUT 2
78 #define HID_REPORT_FEATURE 3
79 // CDC (communication class device)
80 #define CDC_SET_LINE_CODING 0x20
81 #define CDC_GET_LINE_CODING 0x21
82 #define CDC_SET_CONTROL_LINE_STATE 0x22
83 // HID feature selectors
84 #define DEVICE_REMOTE_WAKEUP 1
85 #define ENDPOINT_HALT 0
86 #define TEST_MODE 2
87
88
89 extern bool remote_wakeup;
90 extern bool suspend;
91
92 #endif
Imprint / Impressum