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
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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
32 extern bool remote_wakeup;
35 void usb_init(void); // initialize everything
36 uint8_t usb_configured(void); // is the USB port configured
37 void usb_remote_wakeup(void);
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
48 #define EP_SINGLE_BUFFER 0x02
49 #define EP_DOUBLE_BUFFER 0x06
51 #define EP_SIZE(s) ((s) == 64 ? 0x30 : \
56 #if defined (__AVR_AT90USB162__) || defined (__AVR_AT90USB82__)
57 # define MAX_ENDPOINT 4
58 # define UERST_MASK 0x1E
60 # define MAX_ENDPOINT 6
61 # define UERST_MASK 0x7E
64 #define LSB(n) (n & 255)
65 #define MSB(n) ((n >> 8) & 255)
67 #if defined(__AVR_AT90USB162__)
69 #define PLL_CONFIG() (PLLCSR = ((1<<PLLE)|(1<<PLLP0)))
70 #define USB_CONFIG() (USBCON = (1<<USBE))
71 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
72 #elif defined(__AVR_ATmega32U4__)
73 #define HW_CONFIG() (UHWCON = 0x01)
74 #define PLL_CONFIG() (PLLCSR = 0x12)
75 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
76 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
77 #elif defined(__AVR_AT90USB646__)
78 #define HW_CONFIG() (UHWCON = 0x81)
79 #define PLL_CONFIG() (PLLCSR = 0x1A)
80 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
81 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
82 #elif defined(__AVR_AT90USB1286__)
83 #define HW_CONFIG() (UHWCON = 0x81)
84 #define PLL_CONFIG() (PLLCSR = 0x16)
85 #define USB_CONFIG() (USBCON = ((1<<USBE)|(1<<OTGPADE)))
86 #define USB_FREEZE() (USBCON = ((1<<USBE)|(1<<FRZCLK)))
89 // standard control endpoint request types
91 #define CLEAR_FEATURE 1
94 #define GET_DESCRIPTOR 6
95 #define GET_CONFIGURATION 8
96 #define SET_CONFIGURATION 9
97 #define GET_INTERFACE 10
98 #define SET_INTERFACE 11
99 // HID (human interface device)
100 #define HID_GET_REPORT 1
101 #define HID_GET_IDLE 2
102 #define HID_GET_PROTOCOL 3
103 #define HID_SET_REPORT 9
104 #define HID_SET_IDLE 10
105 #define HID_SET_PROTOCOL 11
106 #define HID_REPORT_INPUT 1
107 #define HID_REPORT_OUTPUT 2
108 #define HID_REPORT_FEATURE 3
109 // CDC (communication class device)
110 #define CDC_SET_LINE_CODING 0x20
111 #define CDC_GET_LINE_CODING 0x21
112 #define CDC_SET_CONTROL_LINE_STATE 0x22
113 // HID feature selectors
114 #define DEVICE_REMOTE_WAKEUP 1
115 #define ENDPOINT_HALT 0
119 /*------------------------------------------------------------------*
120 * Keyboard descriptor setting
121 *------------------------------------------------------------------*/
122 #define KBD_INTERFACE 0
123 #define KBD_ENDPOINT 1
125 #define KBD_BUFFER EP_DOUBLE_BUFFER
126 #define KBD_REPORT_KEYS (KBD_SIZE - 2)
128 // secondary keyboard
130 #define KBD2_INTERFACE 4
131 #define KBD2_ENDPOINT 5
133 #define KBD2_BUFFER EP_DOUBLE_BUFFER
134 #define KBD2_REPORT_KEYS (KBD2_SIZE - 1)