]> git.gir.st - tmk_keyboard.git/blob - pjrc/usb.h
added copyright and license notice.
[tmk_keyboard.git] / pjrc / usb.h
1 /* USB Keyboard Plus Debug Channel Example for Teensy USB Development Board
2 * http://www.pjrc.com/teensy/usb_keyboard.html
3 * Copyright (c) 2009 PJRC.COM, LLC
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23
24 #ifndef USB_H
25 #define USB_H 1
26
27 #include <stdint.h>
28 #include <stdbool.h>
29 #include <avr/io.h>
30
31
32 extern bool remote_wakeup;
33 extern bool suspend;
34
35 void usb_init(void); // initialize everything
36 uint8_t usb_configured(void); // is the USB port configured
37 void usb_remote_wakeup(void);
38
39
40 #define EP_TYPE_CONTROL 0x00
41 #define EP_TYPE_BULK_IN 0x81
42 #define EP_TYPE_BULK_OUT 0x80
43 #define EP_TYPE_INTERRUPT_IN 0xC1
44 #define EP_TYPE_INTERRUPT_OUT 0xC0
45 #define EP_TYPE_ISOCHRONOUS_IN 0x41
46 #define EP_TYPE_ISOCHRONOUS_OUT 0x40
47
48 #define EP_SINGLE_BUFFER 0x02
49 #define EP_DOUBLE_BUFFER 0x06
50
51 #define EP_SIZE(s) ((s) == 64 ? 0x30 : \
52 ((s) == 32 ? 0x20 : \
53 ((s) == 16 ? 0x10 : \
54 0x00)))
55
56 #define MAX_ENDPOINT 4
57
58 #define LSB(n) (n & 255)
59 #define MSB(n) ((n >> 8) & 255)
60
61 #if defined(__AVR_AT90USB162__)
62 #define HW_CONFIG()
63 #define PLL_CONFIG() (PLLCSR = ((1<<PLLE)|(1<<PLLP0)))
64 #define USB_CONFIG() (USBCON = (1<<USBE))
65 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
66 #elif defined(__AVR_ATmega32U4__)
67 #define HW_CONFIG() (UHWCON = 0x01)
68 #define PLL_CONFIG() (PLLCSR = 0x12)
69 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
70 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
71 #elif defined(__AVR_AT90USB646__)
72 #define HW_CONFIG() (UHWCON = 0x81)
73 #define PLL_CONFIG() (PLLCSR = 0x1A)
74 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
75 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
76 #elif defined(__AVR_AT90USB1286__)
77 #define HW_CONFIG() (UHWCON = 0x81)
78 #define PLL_CONFIG() (PLLCSR = 0x16)
79 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
80 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
81 #endif
82
83 // standard control endpoint request types
84 #define GET_STATUS 0
85 #define CLEAR_FEATURE 1
86 #define SET_FEATURE 3
87 #define SET_ADDRESS 5
88 #define GET_DESCRIPTOR 6
89 #define GET_CONFIGURATION 8
90 #define SET_CONFIGURATION 9
91 #define GET_INTERFACE 10
92 #define SET_INTERFACE 11
93 // HID (human interface device)
94 #define HID_GET_REPORT 1
95 #define HID_GET_IDLE 2
96 #define HID_GET_PROTOCOL 3
97 #define HID_SET_REPORT 9
98 #define HID_SET_IDLE 10
99 #define HID_SET_PROTOCOL 11
100 #define HID_REPORT_INPUT 1
101 #define HID_REPORT_OUTPUT 2
102 #define HID_REPORT_FEATURE 3
103 // CDC (communication class device)
104 #define CDC_SET_LINE_CODING 0x20
105 #define CDC_GET_LINE_CODING 0x21
106 #define CDC_SET_CONTROL_LINE_STATE 0x22
107 // HID feature selectors
108 #define DEVICE_REMOTE_WAKEUP 1
109 #define ENDPOINT_HALT 0
110 #define TEST_MODE 2
111
112
113 /*------------------------------------------------------------------*
114 * Keyboard descriptor setting
115 *------------------------------------------------------------------*/
116 #define KBD_INTERFACE 0
117 #define KBD_ENDPOINT 1
118 #define KBD_SIZE 8
119 #define KBD_BUFFER EP_DOUBLE_BUFFER
120 #define KBD_REPORT_KEYS (KBD_SIZE - 2)
121
122 // secondary keyboard
123 #ifdef USB_NKRO_ENABLE
124 #define KBD2_INTERFACE 4
125 #define KBD2_ENDPOINT 5
126 #define KBD2_SIZE 16
127 #define KBD2_BUFFER EP_DOUBLE_BUFFER
128 #define KBD2_REPORT_KEYS (KBD2_SIZE - 1)
129 #endif
130
131 #endif
Imprint / Impressum