diff options
Diffstat (limited to 'protocol/pjrc/usb.h')
| -rw-r--r-- | protocol/pjrc/usb.h | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/protocol/pjrc/usb.h b/protocol/pjrc/usb.h new file mode 100644 index 000000000..0eb58fc39 --- /dev/null +++ b/protocol/pjrc/usb.h | |||
| @@ -0,0 +1,137 @@ | |||
| 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 | #if defined (__AVR_AT90USB162__) || defined (__AVR_AT90USB82__) | ||
| 57 | # define MAX_ENDPOINT 4 | ||
| 58 | # define UERST_MASK 0x1E | ||
| 59 | #else | ||
| 60 | # define MAX_ENDPOINT 6 | ||
| 61 | # define UERST_MASK 0x7E | ||
| 62 | #endif | ||
| 63 | |||
| 64 | #define LSB(n) (n & 255) | ||
| 65 | #define MSB(n) ((n >> 8) & 255) | ||
| 66 | |||
| 67 | #if defined(__AVR_AT90USB162__) | ||
| 68 | #define HW_CONFIG() | ||
| 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))) | ||
| 87 | #endif | ||
| 88 | |||
| 89 | // standard control endpoint request types | ||
| 90 | #define GET_STATUS 0 | ||
| 91 | #define CLEAR_FEATURE 1 | ||
| 92 | #define SET_FEATURE 3 | ||
| 93 | #define SET_ADDRESS 5 | ||
| 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 | ||
| 116 | #define TEST_MODE 2 | ||
| 117 | |||
| 118 | |||
| 119 | /*------------------------------------------------------------------* | ||
| 120 | * Keyboard descriptor setting | ||
| 121 | *------------------------------------------------------------------*/ | ||
| 122 | #define KBD_INTERFACE 0 | ||
| 123 | #define KBD_ENDPOINT 1 | ||
| 124 | #define KBD_SIZE 8 | ||
| 125 | #define KBD_BUFFER EP_DOUBLE_BUFFER | ||
| 126 | #define KBD_REPORT_KEYS (KBD_SIZE - 2) | ||
| 127 | |||
| 128 | // secondary keyboard | ||
| 129 | #ifdef NKRO_ENABLE | ||
| 130 | #define KBD2_INTERFACE 4 | ||
| 131 | #define KBD2_ENDPOINT 5 | ||
| 132 | #define KBD2_SIZE 16 | ||
| 133 | #define KBD2_BUFFER EP_DOUBLE_BUFFER | ||
| 134 | #define KBD2_REPORT_KEYS (KBD2_SIZE - 1) | ||
| 135 | #endif | ||
| 136 | |||
| 137 | #endif | ||
