aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doxygen-todo1
-rw-r--r--tmk_core/common/command.c24
-rw-r--r--tmk_core/protocol/bluefruit.mk18
-rw-r--r--tmk_core/protocol/bluefruit/main.c47
-rw-r--r--tmk_core/protocol/pjrc.mk35
-rw-r--r--tmk_core/protocol/pjrc/MEMO.txt25
-rw-r--r--tmk_core/protocol/pjrc/main.c72
-rw-r--r--tmk_core/protocol/pjrc/pjrc.c58
-rw-r--r--tmk_core/protocol/pjrc/pjrc.h25
-rw-r--r--tmk_core/protocol/pjrc/usb.c970
-rw-r--r--tmk_core/protocol/pjrc/usb.h131
-rw-r--r--tmk_core/protocol/pjrc/usb_debug.c98
-rw-r--r--tmk_core/protocol/pjrc/usb_debug.h39
-rw-r--r--tmk_core/protocol/pjrc/usb_extra.c62
-rw-r--r--tmk_core/protocol/pjrc/usb_extra.h44
-rw-r--r--tmk_core/protocol/pjrc/usb_keyboard.c114
-rw-r--r--tmk_core/protocol/pjrc/usb_keyboard.h38
-rw-r--r--tmk_core/protocol/pjrc/usb_mouse.c83
-rw-r--r--tmk_core/protocol/pjrc/usb_mouse.h47
-rw-r--r--tmk_core/readme.md9
20 files changed, 5 insertions, 1935 deletions
diff --git a/doxygen-todo b/doxygen-todo
index 0f3010ffa..6483b47c6 100644
--- a/doxygen-todo
+++ b/doxygen-todo
@@ -6,7 +6,6 @@ tmk_core/protocol/lufa
6tmk_core/protocol/midi 6tmk_core/protocol/midi
7tmk_core/protocol/midi/bytequeue 7tmk_core/protocol/midi/bytequeue
8tmk_core/protocol/midi/Config 8tmk_core/protocol/midi/Config
9tmk_core/protocol/pjrc
10tmk_core/protocol/usb_hid 9tmk_core/protocol/usb_hid
11tmk_core/protocol/vusb 10tmk_core/protocol/vusb
12tmk_core/tool 11tmk_core/tool
diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c
index 0d6661d60..900de5410 100644
--- a/tmk_core/common/command.c
+++ b/tmk_core/common/command.c
@@ -43,13 +43,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
43# include "mousekey.h" 43# include "mousekey.h"
44#endif 44#endif
45 45
46#ifdef PROTOCOL_PJRC
47# include "usb_keyboard.h"
48# ifdef EXTRAKEY_ENABLE
49# include "usb_extra.h"
50# endif
51#endif
52
53#ifdef PROTOCOL_VUSB 46#ifdef PROTOCOL_VUSB
54# include "usbdrv.h" 47# include "usbdrv.h"
55#endif 48#endif
@@ -165,9 +158,6 @@ static void print_version(void) {
165 /* build options */ 158 /* build options */
166 print("OPTIONS:" 159 print("OPTIONS:"
167 160
168#ifdef PROTOCOL_PJRC
169 " PJRC"
170#endif
171#ifdef PROTOCOL_LUFA 161#ifdef PROTOCOL_LUFA
172 " LUFA" 162 " LUFA"
173#endif 163#endif
@@ -217,20 +207,6 @@ static void print_status(void) {
217 print_val_hex8(keymap_config.nkro); 207 print_val_hex8(keymap_config.nkro);
218#endif 208#endif
219 print_val_hex32(timer_read32()); 209 print_val_hex32(timer_read32());
220
221#ifdef PROTOCOL_PJRC
222 print_val_hex8(UDCON);
223 print_val_hex8(UDIEN);
224 print_val_hex8(UDINT);
225 print_val_hex8(usb_keyboard_leds);
226 print_val_hex8(usb_keyboard_idle_count);
227#endif
228
229#ifdef PROTOCOL_PJRC
230# if USB_COUNT_SOF
231 print_val_hex8(usbSofCount);
232# endif
233#endif
234 return; 210 return;
235} 211}
236 212
diff --git a/tmk_core/protocol/bluefruit.mk b/tmk_core/protocol/bluefruit.mk
index e1c5fff77..13a0693c5 100644
--- a/tmk_core/protocol/bluefruit.mk
+++ b/tmk_core/protocol/bluefruit.mk
@@ -1,27 +1,11 @@
1BLUEFRUIT_DIR = protocol/bluefruit 1BLUEFRUIT_DIR = protocol/bluefruit
2PJRC_DIR = protocol/pjrc
3 2
4SRC += $(BLUEFRUIT_DIR)/main.c \ 3SRC += $(BLUEFRUIT_DIR)/main.c \
5 $(BLUEFRUIT_DIR)/bluefruit.c \ 4 $(BLUEFRUIT_DIR)/bluefruit.c \
6 serial_uart.c \ 5 serial_uart.c
7 $(PJRC_DIR)/pjrc.c \
8 $(PJRC_DIR)/usb_keyboard.c \
9 $(PJRC_DIR)/usb_debug.c \
10 $(PJRC_DIR)/usb.c
11
12# Option modules
13ifdef $(or MOUSEKEY_ENABLE, PS2_MOUSE_ENABLE)
14 SRC += $(PJRC_DIR)/usb_mouse.c
15endif
16
17ifdef EXTRAKEY_ENABLE
18 SRC += $(PJRC_DIR)/usb_extra.c
19endif
20 6
21# Search Path 7# Search Path
22VPATH += $(TMK_DIR)/$(BLUEFRUIT_DIR) 8VPATH += $(TMK_DIR)/$(BLUEFRUIT_DIR)
23#VPATH += $(TMK_DIR)/$(BLUEFRUIT_DIR)/usb_debug_only 9#VPATH += $(TMK_DIR)/$(BLUEFRUIT_DIR)/usb_debug_only
24VPATH += $(TMK_DIR)/$(PJRC_DIR)
25 10
26OPT_DEFS += -DPROTOCOL_BLUEFRUIT 11OPT_DEFS += -DPROTOCOL_BLUEFRUIT
27OPT_DEFS += -DPROTOCOL_PJRC
diff --git a/tmk_core/protocol/bluefruit/main.c b/tmk_core/protocol/bluefruit/main.c
index 3adcab4f4..aca46206d 100644
--- a/tmk_core/protocol/bluefruit/main.c
+++ b/tmk_core/protocol/bluefruit/main.c
@@ -24,7 +24,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
24#include <util/delay.h> 24#include <util/delay.h>
25#include "../serial.h" 25#include "../serial.h"
26#include "keyboard.h" 26#include "keyboard.h"
27#include "usb.h"
28#include "host.h" 27#include "host.h"
29#include "timer.h" 28#include "timer.h"
30#include "print.h" 29#include "print.h"
@@ -32,14 +31,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
32#include "sendchar.h" 31#include "sendchar.h"
33#include "suspend.h" 32#include "suspend.h"
34#include "bluefruit.h" 33#include "bluefruit.h"
35#include "pjrc.h"
36 34
37#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) 35#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
38 36
39#define HOST_DRIVER_NOT_SET 0
40#define BLUEFRUIT_HOST_DRIVER 1
41#define PJRC_HOST_DRIVER 2
42
43int main(void) { 37int main(void) {
44 CPU_PRESCALE(0); 38 CPU_PRESCALE(0);
45 39
@@ -51,27 +45,11 @@ int main(void) {
51 45
52 print_set_sendchar(sendchar); 46 print_set_sendchar(sendchar);
53 47
54 // usb_init();
55 // _delay_ms(2000);
56 // while (!usb_configured()) /* wait */
57
58 keyboard_setup(); 48 keyboard_setup();
59 49
60 dprintf("Initializing keyboard...\n"); 50 dprintf("Initializing keyboard...\n");
61 keyboard_init(); 51 keyboard_init();
62 52
63 // This implementation is pretty simplistic... if the USB connection
64 // is not configured, choose the Bluefruit, otherwise use USB
65 // Definitely would prefer to have this driven by an input pin and make
66 // it switch dynamically - BCG
67 // if (!usb_configured()) {
68
69 // // Send power to Bluefruit... Adafruit says it takes 27 mA, I think
70 // // the pins should provide 40 mA, but just in case I switch the
71 // // Bluefruit using a transistor - BCG
72 // DDRB = _BV(PB6);
73 // PORTB |= _BV(PB6);
74
75 dprintf("Setting host driver to bluefruit...\n"); 53 dprintf("Setting host driver to bluefruit...\n");
76 host_set_driver(bluefruit_driver()); 54 host_set_driver(bluefruit_driver());
77 55
@@ -106,29 +84,4 @@ int main(void) {
106 while (1) { 84 while (1) {
107 keyboard_task(); 85 keyboard_task();
108 } 86 }
109
110 // } else {
111
112 // // I'm not smart enough to get this done with LUFA - BCG
113 // dprintf("Setting host driver to PJRC...\n");
114 // host_set_driver(pjrc_driver());
115 // #ifdef SLEEP_LED_ENABLE
116 // sleep_led_init();
117 // #endif
118 // // wait an extra second for the PC's operating system
119 // // to load drivers and do whatever it does to actually
120 // // be ready for input
121 // _delay_ms(1000);
122 // PORTB = ~_BV(PB0);
123 // dprintf("Starting main loop");
124 // while (1) {
125 // while (suspend) {
126 // suspend_power_down();
127 // if (remote_wakeup && suspend_wakeup_condition()) {
128 // usb_remote_wakeup();
129 // }
130 // }
131 // keyboard_task();
132 // }
133 // }
134} 87}
diff --git a/tmk_core/protocol/pjrc.mk b/tmk_core/protocol/pjrc.mk
deleted file mode 100644
index 7c0c1fa85..000000000
--- a/tmk_core/protocol/pjrc.mk
+++ /dev/null
@@ -1,35 +0,0 @@
1PJRC_DIR = protocol/pjrc
2
3SRC += $(PJRC_DIR)/main.c \
4 $(PJRC_DIR)/pjrc.c \
5 $(PJRC_DIR)/usb_keyboard.c \
6 $(PJRC_DIR)/usb_debug.c \
7 $(PJRC_DIR)/usb.c
8
9# Option modules
10ifdef MOUSEKEY_ENABLE
11 SRC += $(PJRC_DIR)/usb_mouse.c
12endif
13
14ifdef ADB_MOUSE_ENABLE
15 SRC += $(PJRC_DIR)/usb_mouse.c
16endif
17
18ifdef PS2_MOUSE_ENABLE
19 SRC += $(PJRC_DIR)/usb_mouse.c
20endif
21
22ifdef EXTRAKEY_ENABLE
23 SRC += $(PJRC_DIR)/usb_extra.c
24endif
25
26
27ifdef POINTING_DEVICE_ENABLE
28 SRC += $(PJRC_DIR)/usb_mouse.c
29endif
30
31# Search Path
32VPATH += $(TMK_DIR)/$(PJRC_DIR)
33
34# This indicates using LUFA stack
35OPT_DEFS += -DPROTOCOL_PJRC
diff --git a/tmk_core/protocol/pjrc/MEMO.txt b/tmk_core/protocol/pjrc/MEMO.txt
deleted file mode 100644
index b0f059831..000000000
--- a/tmk_core/protocol/pjrc/MEMO.txt
+++ /dev/null
@@ -1,25 +0,0 @@
1Endpoint configuration
2----------------------
30 Control endpoint
41 keyboard
52 mouse
63 debug
74 extra key(consumer/system)
85 nkro keyboard(supported only on ATmega32U4/16U4 and AT90USB64/128)
9
10
11ATmega32U4/16U4, AT90USB64/128
12• Endpoint 0:programmable size FIFO up to 64 bytes, default control endpoint
13• Endpoints 1 programmable size FIFO up to 256 bytes in ping-pong mode.
14• Endpoints 2 to 6: programmable size FIFO up to 64 bytes in ping-pong mode.
15
16AT90USB82/162, ATmega8U2/16U2/32U2
17• Endpoint 0:programmable size FIFO up to 64 bytes, default control endpoint
18• Endpoints 1 and 2: programmable size FIFO up to 64 bytes.
19• Endpoints 3 and 4: programmable size FIFO up to 64 bytes with ping-pong mode.
20
21ping-pong mode means double buffer feature.
22
23
24NOTE: ATmega8U2/16U2/32U2 is not supported with PJRC stack at this time.
25TODO: Macro definition for ATmega8U2/16U2/32U2 in usb.h
diff --git a/tmk_core/protocol/pjrc/main.c b/tmk_core/protocol/pjrc/main.c
deleted file mode 100644
index d16051c5f..000000000
--- a/tmk_core/protocol/pjrc/main.c
+++ /dev/null
@@ -1,72 +0,0 @@
1/* Keyboard example with debug channel, for Teensy USB Development Board
2 * http://www.pjrc.com/teensy/usb_keyboard.html
3 * Copyright (c) 2008 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#include <stdbool.h>
25#include <avr/io.h>
26#include <avr/interrupt.h>
27#include <avr/wdt.h>
28#include <util/delay.h>
29#include "keyboard.h"
30#include "usb.h"
31#include "matrix.h"
32#include "print.h"
33#include "debug.h"
34#include "sendchar.h"
35#include "util.h"
36#include "suspend.h"
37#include "host.h"
38#include "pjrc.h"
39
40#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
41
42int main(void) {
43 // set for 16 MHz clock
44 CPU_PRESCALE(0);
45
46 keyboard_setup();
47
48 // Initialize the USB, and then wait for the host to set configuration.
49 // If the Teensy is powered without a PC connected to the USB port,
50 // this will wait forever.
51 usb_init();
52 while (!usb_configured()) /* wait */
53 ;
54
55 print_set_sendchar(sendchar);
56
57 keyboard_init();
58 host_set_driver(pjrc_driver());
59#ifdef SLEEP_LED_ENABLE
60 sleep_led_init();
61#endif
62 while (1) {
63 while (suspend) {
64 suspend_power_down();
65 if (remote_wakeup && suspend_wakeup_condition()) {
66 usb_remote_wakeup();
67 }
68 }
69
70 keyboard_task();
71 }
72}
diff --git a/tmk_core/protocol/pjrc/pjrc.c b/tmk_core/protocol/pjrc/pjrc.c
deleted file mode 100644
index 60932f59e..000000000
--- a/tmk_core/protocol/pjrc/pjrc.c
+++ /dev/null
@@ -1,58 +0,0 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include <stdint.h>
19#include "usb_keyboard.h"
20#include "usb_mouse.h"
21#include "usb_extra.h"
22#include "host_driver.h"
23#include "pjrc.h"
24
25/*------------------------------------------------------------------*
26 * Host driver
27 *------------------------------------------------------------------*/
28static uint8_t keyboard_leds(void);
29static void send_keyboard(report_keyboard_t *report);
30static void send_mouse(report_mouse_t *report);
31static void send_system(uint16_t data);
32static void send_consumer(uint16_t data);
33
34static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
35
36host_driver_t *pjrc_driver(void) { return &driver; }
37
38static uint8_t keyboard_leds(void) { return usb_keyboard_leds; }
39
40static void send_keyboard(report_keyboard_t *report) { usb_keyboard_send_report(report); }
41
42static void send_mouse(report_mouse_t *report) {
43#ifdef MOUSE_ENABLE
44 usb_mouse_send(report->x, report->y, report->v, report->h, report->buttons);
45#endif
46}
47
48static void send_system(uint16_t data) {
49#ifdef EXTRAKEY_ENABLE
50 usb_extra_system_send(data);
51#endif
52}
53
54static void send_consumer(uint16_t data) {
55#ifdef EXTRAKEY_ENABLE
56 usb_extra_consumer_send(data);
57#endif
58}
diff --git a/tmk_core/protocol/pjrc/pjrc.h b/tmk_core/protocol/pjrc/pjrc.h
deleted file mode 100644
index 08a1ede18..000000000
--- a/tmk_core/protocol/pjrc/pjrc.h
+++ /dev/null
@@ -1,25 +0,0 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef PJRC_H
19#define PJRC_H
20
21#include "host_driver.h"
22
23host_driver_t *pjrc_driver(void);
24
25#endif
diff --git a/tmk_core/protocol/pjrc/usb.c b/tmk_core/protocol/pjrc/usb.c
deleted file mode 100644
index 22fbcfdcd..000000000
--- a/tmk_core/protocol/pjrc/usb.c
+++ /dev/null
@@ -1,970 +0,0 @@
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#include <stdint.h>
25#include <stdbool.h>
26#include <avr/io.h>
27#include <avr/pgmspace.h>
28#include <avr/interrupt.h>
29#include "usb.h"
30#include "usb_keyboard.h"
31#include "usb_mouse.h"
32#include "usb_debug.h"
33#include "usb_extra.h"
34#include "led.h"
35#include "print.h"
36#include "util.h"
37#ifdef SLEEP_LED_ENABLE
38# include "sleep_led.h"
39#endif
40#include "suspend.h"
41#include "action.h"
42#include "action_util.h"
43
44#ifdef NKRO_ENABLE
45# include "keycode_config.h"
46
47extern keymap_config_t keymap_config;
48#endif
49
50/**************************************************************************
51 *
52 * Configurable Options
53 *
54 **************************************************************************/
55
56// You can change these to give your code its own name.
57#ifndef MANUFACTURER
58# define STR_MANUFACTURER L"t.m.k."
59#else
60# define STR_MANUFACTURER LSTR(MANUFACTURER)
61#endif
62#ifndef PRODUCT
63# define STR_PRODUCT L"t.m.k. keyboard"
64#else
65# define STR_PRODUCT LSTR(PRODUCT)
66#endif
67
68// Mac OS-X and Linux automatically load the correct drivers. On
69// Windows, even though the driver is supplied by Microsoft, an
70// INF file is needed to load the driver. These numbers need to
71// match the INF file.
72#ifndef VENDOR_ID
73# define VENDOR_ID 0xFEED
74#endif
75
76#ifndef PRODUCT_ID
77# define PRODUCT_ID 0xBABE
78#endif
79
80#ifndef DEVICE_VER
81# define DEVICE_VER 0x0100
82#endif
83
84// USB devices are supposed to implment a halt feature, which is
85// rarely (if ever) used. If you comment this line out, the halt
86// code will be removed, saving 102 bytes of space (gcc 4.3.0).
87// This is not strictly USB compliant, but works with all major
88// operating systems.
89#define SUPPORT_ENDPOINT_HALT
90
91/**************************************************************************
92 *
93 * Endpoint Buffer Configuration
94 *
95 **************************************************************************/
96
97#define ENDPOINT0_SIZE 32
98
99bool remote_wakeup = false;
100bool suspend = false;
101
102// 0:control endpoint is enabled automatically by controller.
103static const uint8_t PROGMEM endpoint_config_table[] = {
104 // enable, UECFG0X(type, direction), UECFG1X(size, bank, allocation)
105 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(KBD_SIZE) | KBD_BUFFER, // 1
106#ifdef MOUSE_ENABLE
107 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(MOUSE_SIZE) | MOUSE_BUFFER, // 2
108#else
109 0, // 2
110#endif
111#ifdef CONSOLE_ENABLE
112 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(DEBUG_TX_SIZE) | DEBUG_TX_BUFFER, // 3
113#else
114 0,
115#endif
116#ifdef EXTRAKEY_ENABLE
117 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(EXTRA_SIZE) | EXTRA_BUFFER, // 4
118#else
119 0, // 4
120#endif
121#ifdef NKRO_ENABLE
122 1, EP_TYPE_INTERRUPT_IN, EP_SIZE(KBD2_SIZE) | KBD2_BUFFER, // 5
123#else
124 0, // 5
125#endif
126 0, // 6
127};
128
129/**************************************************************************
130 *
131 * Descriptor Data
132 *
133 **************************************************************************/
134
135// Descriptors are the data that your computer reads when it auto-detects
136// this USB device (called "enumeration" in USB lingo). The most commonly
137// changed items are editable at the top of this file. Changing things
138// in here should only be done by those who've read chapter 9 of the USB
139// spec and relevant portions of any USB class specifications!
140
141static const uint8_t PROGMEM device_descriptor[] = {
142 18, // bLength
143 1, // bDescriptorType
144 0x00,
145 0x02, // bcdUSB
146 0, // bDeviceClass
147 0, // bDeviceSubClass
148 0, // bDeviceProtocol
149 ENDPOINT0_SIZE, // bMaxPacketSize0
150 LSB(VENDOR_ID),
151 MSB(VENDOR_ID), // idVendor
152 LSB(PRODUCT_ID),
153 MSB(PRODUCT_ID), // idProduct
154 LSB(DEVICE_VER),
155 MSB(DEVICE_VER), // bcdDevice
156 1, // iManufacturer
157 2, // iProduct
158 0, // iSerialNumber
159 1 // bNumConfigurations
160};
161
162// Keyboard Protocol 1, HID 1.11 spec, Appendix B, page 59-60
163static const uint8_t PROGMEM keyboard_hid_report_desc[] = {
164 0x05, 0x01, // Usage Page (Generic Desktop),
165 0x09, 0x06, // Usage (Keyboard),
166 0xA1, 0x01, // Collection (Application),
167 0x75, 0x01, // Report Size (1),
168 0x95, 0x08, // Report Count (8),
169 0x05, 0x07, // Usage Page (Key Codes),
170 0x19, 0xE0, // Usage Minimum (224),
171 0x29, 0xE7, // Usage Maximum (231),
172 0x15, 0x00, // Logical Minimum (0),
173 0x25, 0x01, // Logical Maximum (1),
174 0x81, 0x02, // Input (Data, Variable, Absolute), ;Modifier byte
175 0x95, 0x01, // Report Count (1),
176 0x75, 0x08, // Report Size (8),
177 0x81, 0x03, // Input (Constant), ;Reserved byte
178 0x95, 0x05, // Report Count (5),
179 0x75, 0x01, // Report Size (1),
180 0x05, 0x08, // Usage Page (LEDs),
181 0x19, 0x01, // Usage Minimum (1),
182 0x29, 0x05, // Usage Maximum (5),
183 0x91, 0x02, // Output (Data, Variable, Absolute), ;LED report
184 0x95, 0x01, // Report Count (1),
185 0x75, 0x03, // Report Size (3),
186 0x91, 0x03, // Output (Constant), ;LED report padding
187 0x95, KBD_REPORT_KEYS, // Report Count (),
188 0x75, 0x08, // Report Size (8),
189 0x15, 0x00, // Logical Minimum (0),
190 0x25, 0xFF, // Logical Maximum(255),
191 0x05, 0x07, // Usage Page (Key Codes),
192 0x19, 0x00, // Usage Minimum (0),
193 0x29, 0xFF, // Usage Maximum (255),
194 0x81, 0x00, // Input (Data, Array),
195 0xc0 // End Collection
196};
197#ifdef NKRO_ENABLE
198static const uint8_t PROGMEM keyboard2_hid_report_desc[] = {
199 0x05, 0x01, // Usage Page (Generic Desktop),
200 0x09, 0x06, // Usage (Keyboard),
201 0xA1, 0x01, // Collection (Application),
202 // bitmap of modifiers
203 0x75, 0x01, // Report Size (1),
204 0x95, 0x08, // Report Count (8),
205 0x05, 0x07, // Usage Page (Key Codes),
206 0x19, 0xE0, // Usage Minimum (224),
207 0x29, 0xE7, // Usage Maximum (231),
208 0x15, 0x00, // Logical Minimum (0),
209 0x25, 0x01, // Logical Maximum (1),
210 0x81, 0x02, // Input (Data, Variable, Absolute), ;Modifier byte
211 // LED output report
212 0x95, 0x05, // Report Count (5),
213 0x75, 0x01, // Report Size (1),
214 0x05, 0x08, // Usage Page (LEDs),
215 0x19, 0x01, // Usage Minimum (1),
216 0x29, 0x05, // Usage Maximum (5),
217 0x91, 0x02, // Output (Data, Variable, Absolute),
218 0x95, 0x01, // Report Count (1),
219 0x75, 0x03, // Report Size (3),
220 0x91, 0x03, // Output (Constant),
221 // bitmap of keys
222 0x95, KBD2_REPORT_KEYS * 8, // Report Count (),
223 0x75, 0x01, // Report Size (1),
224 0x15, 0x00, // Logical Minimum (0),
225 0x25, 0x01, // Logical Maximum(1),
226 0x05, 0x07, // Usage Page (Key Codes),
227 0x19, 0x00, // Usage Minimum (0),
228 0x29, KBD2_REPORT_KEYS * 8 - 1, // Usage Maximum (),
229 0x81, 0x02, // Input (Data, Variable, Absolute),
230 0xc0 // End Collection
231};
232#endif
233
234#ifdef MOUSE_ENABLE
235// Mouse Protocol 1, HID 1.11 spec, Appendix B, page 59-60, with wheel extension
236// http://www.microchip.com/forums/tm.aspx?high=&m=391435&mpage=1#391521
237// http://www.keil.com/forum/15671/
238// http://www.microsoft.com/whdc/device/input/wheel.mspx
239static const uint8_t PROGMEM mouse_hid_report_desc[] = {
240 /* mouse */
241 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
242 0x09, 0x02, // USAGE (Mouse)
243 0xa1, 0x01, // COLLECTION (Application)
244 // 0x85, REPORT_ID_MOUSE, // REPORT_ID (1)
245 0x09, 0x01, // USAGE (Pointer)
246 0xa1, 0x00, // COLLECTION (Physical)
247 // ---------------------------- Buttons
248 0x05, 0x09, // USAGE_PAGE (Button)
249 0x19, 0x01, // USAGE_MINIMUM (Button 1)
250 0x29, 0x05, // USAGE_MAXIMUM (Button 5)
251 0x15, 0x00, // LOGICAL_MINIMUM (0)
252 0x25, 0x01, // LOGICAL_MAXIMUM (1)
253 0x75, 0x01, // REPORT_SIZE (1)
254 0x95, 0x05, // REPORT_COUNT (5)
255 0x81, 0x02, // INPUT (Data,Var,Abs)
256 0x75, 0x03, // REPORT_SIZE (3)
257 0x95, 0x01, // REPORT_COUNT (1)
258 0x81, 0x03, // INPUT (Cnst,Var,Abs)
259 // ---------------------------- X,Y position
260 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
261 0x09, 0x30, // USAGE (X)
262 0x09, 0x31, // USAGE (Y)
263 0x15, 0x81, // LOGICAL_MINIMUM (-127)
264 0x25, 0x7f, // LOGICAL_MAXIMUM (127)
265 0x75, 0x08, // REPORT_SIZE (8)
266 0x95, 0x02, // REPORT_COUNT (2)
267 0x81, 0x06, // INPUT (Data,Var,Rel)
268 // ---------------------------- Vertical wheel
269 0x09, 0x38, // USAGE (Wheel)
270 0x15, 0x81, // LOGICAL_MINIMUM (-127)
271 0x25, 0x7f, // LOGICAL_MAXIMUM (127)
272 0x35, 0x00, // PHYSICAL_MINIMUM (0) - reset physical
273 0x45, 0x00, // PHYSICAL_MAXIMUM (0)
274 0x75, 0x08, // REPORT_SIZE (8)
275 0x95, 0x01, // REPORT_COUNT (1)
276 0x81, 0x06, // INPUT (Data,Var,Rel)
277 // ---------------------------- Horizontal wheel
278 0x05, 0x0c, // USAGE_PAGE (Consumer Devices)
279 0x0a, 0x38, 0x02, // USAGE (AC Pan)
280 0x15, 0x81, // LOGICAL_MINIMUM (-127)
281 0x25, 0x7f, // LOGICAL_MAXIMUM (127)
282 0x75, 0x08, // REPORT_SIZE (8)
283 0x95, 0x01, // REPORT_COUNT (1)
284 0x81, 0x06, // INPUT (Data,Var,Rel)
285 0xc0, // END_COLLECTION
286 0xc0, // END_COLLECTION
287};
288#endif
289
290static const uint8_t PROGMEM debug_hid_report_desc[] = {
291 0x06, 0x31, 0xFF, // Usage Page 0xFF31 (vendor defined)
292 0x09, 0x74, // Usage 0x74
293 0xA1, 0x53, // Collection 0x53
294 0x75, 0x08, // report size = 8 bits
295 0x15, 0x00, // logical minimum = 0
296 0x26, 0xFF, 0x00, // logical maximum = 255
297 0x95, DEBUG_TX_SIZE, // report count
298 0x09, 0x75, // usage
299 0x81, 0x02, // Input (array)
300 0xC0 // end collection
301};
302
303#ifdef EXTRAKEY_ENABLE
304// audio controls & system controls
305// http://www.microsoft.com/whdc/archive/w2kbd.mspx
306static const uint8_t PROGMEM extra_hid_report_desc[] = {
307 /* system control */
308 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
309 0x09, 0x80, // USAGE (System Control)
310 0xa1, 0x01, // COLLECTION (Application)
311 0x85, REPORT_ID_SYSTEM, // REPORT_ID (2)
312 0x15, 0x01, // LOGICAL_MINIMUM (0x1)
313 0x25, 0xb7, // LOGICAL_MAXIMUM (0xb7)
314 0x19, 0x01, // USAGE_MINIMUM (0x1)
315 0x29, 0xb7, // USAGE_MAXIMUM (0xb7)
316 0x75, 0x10, // REPORT_SIZE (16)
317 0x95, 0x01, // REPORT_COUNT (1)
318 0x81, 0x00, // INPUT (Data,Array,Abs)
319 0xc0, // END_COLLECTION
320 /* consumer */
321 0x05, 0x0c, // USAGE_PAGE (Consumer Devices)
322 0x09, 0x01, // USAGE (Consumer Control)
323 0xa1, 0x01, // COLLECTION (Application)
324 0x85, REPORT_ID_CONSUMER, // REPORT_ID (3)
325 0x15, 0x01, // LOGICAL_MINIMUM (0x1)
326 0x26, 0x9c, 0x02, // LOGICAL_MAXIMUM (0x29c)
327 0x19, 0x01, // USAGE_MINIMUM (0x1)
328 0x2a, 0x9c, 0x02, // USAGE_MAXIMUM (0x29c)
329 0x75, 0x10, // REPORT_SIZE (16)
330 0x95, 0x01, // REPORT_COUNT (1)
331 0x81, 0x00, // INPUT (Data,Array,Abs)
332 0xc0, // END_COLLECTION
333};
334#endif
335
336#define KBD_HID_DESC_NUM 0
337#define KBD_HID_DESC_OFFSET (9 + (9 + 9 + 7) * KBD_HID_DESC_NUM + 9)
338
339#ifdef MOUSE_ENABLE
340# define MOUSE_HID_DESC_NUM (KBD_HID_DESC_NUM + 1)
341# define MOUSE_HID_DESC_OFFSET (9 + (9 + 9 + 7) * MOUSE_HID_DESC_NUM + 9)
342#else
343# define MOUSE_HID_DESC_NUM (KBD_HID_DESC_NUM + 0)
344#endif
345
346#ifdef CONSOLE_ENABLE
347# define DEBUG_HID_DESC_NUM (MOUSE_HID_DESC_NUM + 1)
348# define DEBUG_HID_DESC_OFFSET (9 + (9 + 9 + 7) * DEBUG_HID_DESC_NUM + 9)
349#else
350# define DEBUG_HID_DESC_NUM (MOUSE_HID_DESC_NUM + 0)
351#endif
352
353#ifdef EXTRAKEY_ENABLE
354# define EXTRA_HID_DESC_NUM (DEBUG_HID_DESC_NUM + 1)
355# define EXTRA_HID_DESC_OFFSET (9 + (9 + 9 + 7) * EXTRA_HID_DESC_NUM + 9)
356#else
357# define EXTRA_HID_DESC_NUM (DEBUG_HID_DESC_NUM + 0)
358#endif
359
360#ifdef NKRO_ENABLE
361# define KBD2_HID_DESC_NUM (EXTRA_HID_DESC_NUM + 1)
362# define KBD2_HID_DESC_OFFSET (9 + (9 + 9 + 7) * EXTRA_HID_DESC_NUM + 9)
363#else
364# define KBD2_HID_DESC_NUM (EXTRA_HID_DESC_NUM + 0)
365#endif
366
367#define NUM_INTERFACES (KBD2_HID_DESC_NUM + 1)
368#define CONFIG1_DESC_SIZE (9 + (9 + 9 + 7) * NUM_INTERFACES)
369static const uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
370 // configuration descriptor, USB spec 9.6.3, page 264-266, Table 9-10
371 9, // bLength;
372 2, // bDescriptorType;
373 LSB(CONFIG1_DESC_SIZE), // wTotalLength
374 MSB(CONFIG1_DESC_SIZE),
375 NUM_INTERFACES, // bNumInterfaces
376 1, // bConfigurationValue
377 0, // iConfiguration
378 0xA0, // bmAttributes
379 50, // bMaxPower
380
381 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
382 9, // bLength
383 4, // bDescriptorType
384 KBD_INTERFACE, // bInterfaceNumber
385 0, // bAlternateSetting
386 1, // bNumEndpoints
387 0x03, // bInterfaceClass (0x03 = HID)
388 0x01, // bInterfaceSubClass (0x01 = Boot)
389 0x01, // bInterfaceProtocol (0x01 = Keyboard)
390 0, // iInterface
391 // HID descriptor, HID 1.11 spec, section 6.2.1
392 9, // bLength
393 0x21, // bDescriptorType
394 0x11, 0x01, // bcdHID
395 0, // bCountryCode
396 1, // bNumDescriptors
397 0x22, // bDescriptorType
398 sizeof(keyboard_hid_report_desc), // wDescriptorLength
399 0,
400 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
401 7, // bLength
402 5, // bDescriptorType
403 KBD_ENDPOINT | 0x80, // bEndpointAddress
404 0x03, // bmAttributes (0x03=intr)
405 KBD_SIZE, 0, // wMaxPacketSize
406 10, // bInterval
407
408#ifdef MOUSE_ENABLE
409 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
410 9, // bLength
411 4, // bDescriptorType
412 MOUSE_INTERFACE, // bInterfaceNumber
413 0, // bAlternateSetting
414 1, // bNumEndpoints
415 0x03, // bInterfaceClass (0x03 = HID)
416 // ThinkPad T23 BIOS doesn't work with boot mouse.
417 0x00, // bInterfaceSubClass (0x01 = Boot)
418 0x00, // bInterfaceProtocol (0x02 = Mouse)
419 /*
420 0x01, // bInterfaceSubClass (0x01 = Boot)
421 0x02, // bInterfaceProtocol (0x02 = Mouse)
422 */
423 0, // iInterface
424 // HID descriptor, HID 1.11 spec, section 6.2.1
425 9, // bLength
426 0x21, // bDescriptorType
427 0x11, 0x01, // bcdHID
428 0, // bCountryCode
429 1, // bNumDescriptors
430 0x22, // bDescriptorType
431 sizeof(mouse_hid_report_desc), // wDescriptorLength
432 0,
433 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
434 7, // bLength
435 5, // bDescriptorType
436 MOUSE_ENDPOINT | 0x80, // bEndpointAddress
437 0x03, // bmAttributes (0x03=intr)
438 MOUSE_SIZE, 0, // wMaxPacketSize
439 1, // bInterval
440#endif
441
442#ifdef CONSOLE_ENABLE
443 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
444 9, // bLength
445 4, // bDescriptorType
446 DEBUG_INTERFACE, // bInterfaceNumber
447 0, // bAlternateSetting
448 1, // bNumEndpoints
449 0x03, // bInterfaceClass (0x03 = HID)
450 0x00, // bInterfaceSubClass
451 0x00, // bInterfaceProtocol
452 0, // iInterface
453 // HID descriptor, HID 1.11 spec, section 6.2.1
454 9, // bLength
455 0x21, // bDescriptorType
456 0x11, 0x01, // bcdHID
457 0, // bCountryCode
458 1, // bNumDescriptors
459 0x22, // bDescriptorType
460 sizeof(debug_hid_report_desc), // wDescriptorLength
461 0,
462 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
463 7, // bLength
464 5, // bDescriptorType
465 DEBUG_TX_ENDPOINT | 0x80, // bEndpointAddress
466 0x03, // bmAttributes (0x03=intr)
467 DEBUG_TX_SIZE, 0, // wMaxPacketSize
468 1, // bInterval
469#endif
470
471#ifdef EXTRAKEY_ENABLE
472 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
473 9, // bLength
474 4, // bDescriptorType
475 EXTRA_INTERFACE, // bInterfaceNumber
476 0, // bAlternateSetting
477 1, // bNumEndpoints
478 0x03, // bInterfaceClass (0x03 = HID)
479 0x00, // bInterfaceSubClass
480 0x00, // bInterfaceProtocol
481 0, // iInterface
482 // HID descriptor, HID 1.11 spec, section 6.2.1
483 9, // bLength
484 0x21, // bDescriptorType
485 0x11, 0x01, // bcdHID
486 0, // bCountryCode
487 1, // bNumDescriptors
488 0x22, // bDescriptorType
489 sizeof(extra_hid_report_desc), // wDescriptorLength
490 0,
491 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
492 7, // bLength
493 5, // bDescriptorType
494 EXTRA_ENDPOINT | 0x80, // bEndpointAddress
495 0x03, // bmAttributes (0x03=intr)
496 EXTRA_SIZE, 0, // wMaxPacketSize
497 10, // bInterval
498#endif
499
500#ifdef NKRO_ENABLE
501 // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
502 9, // bLength
503 4, // bDescriptorType
504 KBD2_INTERFACE, // bInterfaceNumber
505 0, // bAlternateSetting
506 1, // bNumEndpoints
507 0x03, // bInterfaceClass (0x03 = HID)
508 0x00, // bInterfaceSubClass (0x01 = Boot)
509 0x00, // bInterfaceProtocol (0x01 = Keyboard)
510 0, // iInterface
511 // HID descriptor, HID 1.11 spec, section 6.2.1
512 9, // bLength
513 0x21, // bDescriptorType
514 0x11, 0x01, // bcdHID
515 0, // bCountryCode
516 1, // bNumDescriptors
517 0x22, // bDescriptorType
518 sizeof(keyboard2_hid_report_desc), // wDescriptorLength
519 0,
520 // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
521 7, // bLength
522 5, // bDescriptorType
523 KBD2_ENDPOINT | 0x80, // bEndpointAddress
524 0x03, // bmAttributes (0x03=intr)
525 KBD2_SIZE, 0, // wMaxPacketSize
526 1, // bInterval
527#endif
528};
529
530// If you're desperate for a little extra code memory, these strings
531// can be completely removed if iManufacturer, iProduct, iSerialNumber
532// in the device desciptor are changed to zeros.
533struct usb_string_descriptor_struct {
534 uint8_t bLength;
535 uint8_t bDescriptorType;
536 int16_t wString[];
537};
538static const struct usb_string_descriptor_struct PROGMEM string0 = {4, 3, {0x0409}};
539static const struct usb_string_descriptor_struct PROGMEM string1 = {sizeof(STR_MANUFACTURER), 3, STR_MANUFACTURER};
540static const struct usb_string_descriptor_struct PROGMEM string2 = {sizeof(STR_PRODUCT), 3, STR_PRODUCT};
541
542// This table defines which descriptor data is sent for each specific
543// request from the host (in wValue and wIndex).
544static const struct descriptor_list_struct {
545 uint16_t wValue; // descriptor type
546 uint16_t wIndex;
547 const uint8_t *addr;
548 uint8_t length;
549} PROGMEM descriptor_list[] = {
550 // DEVICE descriptor
551 {0x0100, 0x0000, device_descriptor, sizeof(device_descriptor)},
552 // CONFIGURATION descriptor
553 {0x0200, 0x0000, config1_descriptor, sizeof(config1_descriptor)},
554 // HID/REPORT descriptors
555 {0x2100, KBD_INTERFACE, config1_descriptor + KBD_HID_DESC_OFFSET, 9},
556 {0x2200, KBD_INTERFACE, keyboard_hid_report_desc, sizeof(keyboard_hid_report_desc)},
557#ifdef MOUSE_ENABLE
558 {0x2100, MOUSE_INTERFACE, config1_descriptor + MOUSE_HID_DESC_OFFSET, 9},
559 {0x2200, MOUSE_INTERFACE, mouse_hid_report_desc, sizeof(mouse_hid_report_desc)},
560#endif
561#ifdef CONSOLE_ENABLE
562 {0x2100, DEBUG_INTERFACE, config1_descriptor + DEBUG_HID_DESC_OFFSET, 9},
563 {0x2200, DEBUG_INTERFACE, debug_hid_report_desc, sizeof(debug_hid_report_desc)},
564#endif
565#ifdef EXTRAKEY_ENABLE
566 {0x2100, EXTRA_INTERFACE, config1_descriptor + EXTRA_HID_DESC_OFFSET, 9},
567 {0x2200, EXTRA_INTERFACE, extra_hid_report_desc, sizeof(extra_hid_report_desc)},
568#endif
569#ifdef NKRO_ENABLE
570 {0x2100, KBD2_INTERFACE, config1_descriptor + KBD2_HID_DESC_OFFSET, 9},
571 {0x2200, KBD2_INTERFACE, keyboard2_hid_report_desc, sizeof(keyboard2_hid_report_desc)},
572#endif
573 // STRING descriptors
574 {0x0300, 0x0000, (const uint8_t *)&string0, 4},
575 {0x0301, 0x0409, (const uint8_t *)&string1, sizeof(STR_MANUFACTURER)},
576 {0x0302, 0x0409, (const uint8_t *)&string2, sizeof(STR_PRODUCT)}};
577#define NUM_DESC_LIST (sizeof(descriptor_list) / sizeof(struct descriptor_list_struct))
578
579/**************************************************************************
580 *
581 * Variables - these are the only non-stack RAM usage
582 *
583 **************************************************************************/
584
585// zero when we are not configured, non-zero when enumerated
586static volatile uint8_t usb_configuration = 0;
587
588/**************************************************************************
589 *
590 * Public Functions - these are the API intended for the user
591 *
592 **************************************************************************/
593
594// initialize USB
595void usb_init(void) {
596 HW_CONFIG();
597 USB_FREEZE(); // enable USB
598 PLL_CONFIG(); // config PLL
599 while (!(PLLCSR & (1 << PLOCK)))
600 ; // wait for PLL lock
601 USB_CONFIG(); // start USB clock
602 UDCON = 0; // enable attach resistor
603 usb_configuration = 0;
604 suspend = false;
605 UDIEN = (1 << EORSTE) | (1 << SOFE) | (1 << SUSPE) | (1 << WAKEUPE);
606 sei();
607}
608
609// return 0 if the USB is not configured, or the configuration
610// number selected by the HOST
611uint8_t usb_configured(void) { return usb_configuration && !suspend; }
612
613void usb_remote_wakeup(void) {
614 UDCON |= (1 << RMWKUP);
615 while (UDCON & (1 << RMWKUP))
616 ;
617}
618
619/**************************************************************************
620 *
621 * Private Functions - not intended for general user consumption....
622 *
623 **************************************************************************/
624
625// USB Device Interrupt - handle all device-level events
626// the transmit buffer flushing is triggered by the start of frame
627//
628ISR(USB_GEN_vect) {
629 uint8_t intbits, t;
630 static uint8_t div4 = 0;
631
632 intbits = UDINT;
633 UDINT = 0;
634 if ((intbits & (1 << SUSPI)) && (UDIEN & (1 << SUSPE)) && usb_configuration) {
635#ifdef SLEEP_LED_ENABLE
636 sleep_led_enable();
637#endif
638 UDIEN &= ~(1 << SUSPE);
639 UDIEN |= (1 << WAKEUPE);
640 suspend = true;
641 }
642 if ((intbits & (1 << WAKEUPI)) && (UDIEN & (1 << WAKEUPE)) && usb_configuration) {
643 suspend_wakeup_init();
644#ifdef SLEEP_LED_ENABLE
645 sleep_led_disable();
646 // NOTE: converters may not accept this
647 led_set(host_keyboard_leds());
648#endif
649
650 UDIEN |= (1 << SUSPE);
651 UDIEN &= ~(1 << WAKEUPE);
652 suspend = false;
653 }
654 if (intbits & (1 << EORSTI)) {
655 UENUM = 0;
656 UECONX = 1;
657 UECFG0X = EP_TYPE_CONTROL;
658 UECFG1X = EP_SIZE(ENDPOINT0_SIZE) | EP_SINGLE_BUFFER;
659 UEIENX = (1 << RXSTPE);
660 usb_configuration = 0;
661 }
662 if ((intbits & (1 << SOFI)) && usb_configuration) {
663 t = debug_flush_timer;
664 if (t) {
665 debug_flush_timer = --t;
666 if (!t) {
667 UENUM = DEBUG_TX_ENDPOINT;
668 while ((UEINTX & (1 << RWAL))) {
669 UEDATX = 0;
670 }
671 UEINTX = 0x3A;
672 }
673 }
674 /* TODO: should keep IDLE rate on each keyboard interface */
675#ifdef NKRO_ENABLE
676 if (!keymap_config.nkro && keyboard_idle && (++div4 & 3) == 0) {
677#else
678 if (keyboard_idle && (++div4 & 3) == 0) {
679#endif
680 UENUM = KBD_ENDPOINT;
681 if (UEINTX & (1 << RWAL)) {
682 usb_keyboard_idle_count++;
683 if (usb_keyboard_idle_count == keyboard_idle) {
684 usb_keyboard_idle_count = 0;
685 /* TODO: fix keyboard_report inconsistency */
686 /* To avoid Mac SET_IDLE behaviour.
687 UEDATX = keyboard_report_prev->mods;
688 UEDATX = 0;
689 uint8_t keys = keyboard_protocol ? KBD_REPORT_KEYS : 6;
690 for (uint8_t i=0; i<keys; i++) {
691 UEDATX = keyboard_report_prev->keys[i];
692 }
693 UEINTX = 0x3A;
694 */
695 }
696 }
697 }
698 }
699}
700
701// Misc functions to wait for ready and send/receive packets
702static inline void usb_wait_in_ready(void) {
703 while (!(UEINTX & (1 << TXINI)))
704 ;
705}
706static inline void usb_send_in(void) { UEINTX = ~(1 << TXINI); }
707static inline void usb_wait_receive_out(void) {
708 while (!(UEINTX & (1 << RXOUTI)))
709 ;
710}
711static inline void usb_ack_out(void) { UEINTX = ~(1 << RXOUTI); }
712
713// USB Endpoint Interrupt - endpoint 0 is handled here. The
714// other endpoints are manipulated by the user-callable
715// functions, and the start-of-frame interrupt.
716//
717ISR(USB_COM_vect) {
718 uint8_t intbits;
719 const uint8_t *list;
720 const uint8_t *cfg;
721 uint8_t i, n, len, en;
722 uint8_t bmRequestType;
723 uint8_t bRequest;
724 uint16_t wValue;
725 uint16_t wIndex;
726 uint16_t wLength;
727 uint16_t desc_val;
728 const uint8_t *desc_addr;
729 uint8_t desc_length;
730
731 UENUM = 0;
732 intbits = UEINTX;
733 if (intbits & (1 << RXSTPI)) {
734 bmRequestType = UEDATX;
735 bRequest = UEDATX;
736 wValue = UEDATX;
737 wValue |= (UEDATX << 8);
738 wIndex = UEDATX;
739 wIndex |= (UEDATX << 8);
740 wLength = UEDATX;
741 wLength |= (UEDATX << 8);
742 UEINTX = ~((1 << RXSTPI) | (1 << RXOUTI) | (1 << TXINI));
743 if (bRequest == GET_DESCRIPTOR) {
744 list = (const uint8_t *)descriptor_list;
745 for (i = 0;; i++) {
746 if (i >= NUM_DESC_LIST) {
747 UECONX = (1 << STALLRQ) | (1 << EPEN); // stall
748 return;
749 }
750 desc_val = pgm_read_word(list);
751 if (desc_val != wValue) {
752 list += sizeof(struct descriptor_list_struct);
753 continue;
754 }
755 list += 2;
756 desc_val = pgm_read_word(list);
757 if (desc_val != wIndex) {
758 list += sizeof(struct descriptor_list_struct) - 2;
759 continue;
760 }
761 list += 2;
762 desc_addr = (const uint8_t *)pgm_read_word(list);
763 list += 2;
764 desc_length = pgm_read_byte(list);
765 break;
766 }
767 len = (wLength < 256) ? wLength : 255;
768 if (len > desc_length) len = desc_length;
769 do {
770 // wait for host ready for IN packet
771 do {
772 i = UEINTX;
773 } while (!(i & ((1 << TXINI) | (1 << RXOUTI))));
774 if (i & (1 << RXOUTI)) return; // abort
775 // send IN packet
776 n = len < ENDPOINT0_SIZE ? len : ENDPOINT0_SIZE;
777 for (i = n; i; i--) {
778 UEDATX = pgm_read_byte(desc_addr++);
779 }
780 len -= n;
781 usb_send_in();
782 } while (len || n == ENDPOINT0_SIZE);
783 return;
784 }
785 if (bRequest == SET_ADDRESS) {
786 usb_send_in();
787 usb_wait_in_ready();
788 UDADDR = wValue | (1 << ADDEN);
789 return;
790 }
791 if (bRequest == SET_CONFIGURATION && bmRequestType == 0) {
792 usb_configuration = wValue;
793 usb_send_in();
794 cfg = endpoint_config_table;
795 for (i = 1; i <= MAX_ENDPOINT; i++) {
796 UENUM = i;
797 en = pgm_read_byte(cfg++);
798 if (en) {
799 UECONX = (1 << EPEN);
800 UECFG0X = pgm_read_byte(cfg++);
801 UECFG1X = pgm_read_byte(cfg++);
802 } else {
803 UECONX = 0;
804 }
805 }
806 UERST = UERST_MASK;
807 UERST = 0;
808 return;
809 }
810 if (bRequest == GET_CONFIGURATION && bmRequestType == 0x80) {
811 usb_wait_in_ready();
812 UEDATX = usb_configuration;
813 usb_send_in();
814 return;
815 }
816
817 if (bRequest == GET_STATUS) {
818 usb_wait_in_ready();
819 i = 0;
820#ifdef SUPPORT_ENDPOINT_HALT
821 if (bmRequestType == 0x82) {
822 UENUM = wIndex;
823 if (UECONX & (1 << STALLRQ)) i = 1;
824 UENUM = 0;
825 }
826#endif
827 UEDATX = i;
828 UEDATX = 0;
829 usb_send_in();
830 return;
831 }
832 if (bRequest == CLEAR_FEATURE || bRequest == SET_FEATURE) {
833#ifdef SUPPORT_ENDPOINT_HALT
834 if (bmRequestType == 0x02 && wValue == ENDPOINT_HALT) {
835 i = wIndex & 0x7F;
836 if (i >= 1 && i <= MAX_ENDPOINT) {
837 usb_send_in();
838 UENUM = i;
839 if (bRequest == SET_FEATURE) {
840 UECONX = (1 << STALLRQ) | (1 << EPEN);
841 } else {
842 UECONX = (1 << STALLRQC) | (1 << RSTDT) | (1 << EPEN);
843 UERST = (1 << i);
844 UERST = 0;
845 }
846 return;
847 }
848 }
849#endif
850 if (bmRequestType == 0x00 && wValue == DEVICE_REMOTE_WAKEUP) {
851 if (bRequest == SET_FEATURE) {
852 remote_wakeup = true;
853 } else {
854 remote_wakeup = false;
855 }
856 usb_send_in();
857 return;
858 }
859 }
860 if (wIndex == KBD_INTERFACE) {
861 if (bmRequestType == 0xA1) {
862 if (bRequest == HID_GET_REPORT) {
863 usb_wait_in_ready();
864 UEDATX = keyboard_report->mods;
865 UEDATX = 0;
866 for (i = 0; i < 6; i++) {
867 UEDATX = keyboard_report->keys[i];
868 }
869 usb_send_in();
870 return;
871 }
872 if (bRequest == HID_GET_IDLE) {
873 usb_wait_in_ready();
874 UEDATX = keyboard_idle;
875 usb_send_in();
876 return;
877 }
878 if (bRequest == HID_GET_PROTOCOL) {
879 usb_wait_in_ready();
880 UEDATX = keyboard_protocol;
881 usb_send_in();
882 return;
883 }
884 }
885 if (bmRequestType == 0x21) {
886 if (bRequest == HID_SET_REPORT) {
887 usb_wait_receive_out();
888 usb_keyboard_leds = UEDATX;
889 usb_ack_out();
890 usb_send_in();
891 return;
892 }
893 if (bRequest == HID_SET_IDLE) {
894 keyboard_idle = (wValue >> 8);
895 usb_keyboard_idle_count = 0;
896 // usb_wait_in_ready();
897 usb_send_in();
898 return;
899 }
900 if (bRequest == HID_SET_PROTOCOL) {
901 keyboard_protocol = wValue;
902#ifdef NKRO_ENABLE
903 keymap_config.nkro = !!keyboard_protocol;
904#endif
905 clear_keyboard();
906 // usb_wait_in_ready();
907 usb_send_in();
908 return;
909 }
910 }
911 }
912#ifdef MOUSE_ENABLE
913 if (wIndex == MOUSE_INTERFACE) {
914 if (bmRequestType == 0xA1) {
915 if (bRequest == HID_GET_REPORT) {
916 if (wValue == HID_REPORT_INPUT) {
917 usb_wait_in_ready();
918 UEDATX = 0;
919 UEDATX = 0;
920 UEDATX = 0;
921 UEDATX = 0;
922 usb_send_in();
923 return;
924 }
925 if (wValue == HID_REPORT_FEATURE) {
926 usb_wait_in_ready();
927 UEDATX = 0x05;
928 usb_send_in();
929 return;
930 }
931 }
932 if (bRequest == HID_GET_PROTOCOL) {
933 usb_wait_in_ready();
934 UEDATX = usb_mouse_protocol;
935 usb_send_in();
936 return;
937 }
938 }
939 if (bmRequestType == 0x21) {
940 if (bRequest == HID_SET_PROTOCOL) {
941 usb_mouse_protocol = wValue;
942 usb_send_in();
943 return;
944 }
945 }
946 }
947#endif
948 if (wIndex == DEBUG_INTERFACE) {
949 if (bRequest == HID_GET_REPORT && bmRequestType == 0xA1) {
950 len = wLength;
951 do {
952 // wait for host ready for IN packet
953 do {
954 i = UEINTX;
955 } while (!(i & ((1 << TXINI) | (1 << RXOUTI))));
956 if (i & (1 << RXOUTI)) return; // abort
957 // send IN packet
958 n = len < ENDPOINT0_SIZE ? len : ENDPOINT0_SIZE;
959 for (i = n; i; i--) {
960 UEDATX = 0;
961 }
962 len -= n;
963 usb_send_in();
964 } while (len || n == ENDPOINT0_SIZE);
965 return;
966 }
967 }
968 }
969 UECONX = (1 << STALLRQ) | (1 << EPEN); // stall
970}
diff --git a/tmk_core/protocol/pjrc/usb.h b/tmk_core/protocol/pjrc/usb.h
deleted file mode 100644
index 50654dccf..000000000
--- a/tmk_core/protocol/pjrc/usb.h
+++ /dev/null
@@ -1,131 +0,0 @@
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
31extern bool remote_wakeup;
32extern bool suspend;
33
34void usb_init(void); // initialize everything
35uint8_t usb_configured(void); // is the USB port configured
36void usb_remote_wakeup(void);
37
38#define EP_TYPE_CONTROL 0x00
39#define EP_TYPE_BULK_IN 0x81
40#define EP_TYPE_BULK_OUT 0x80
41#define EP_TYPE_INTERRUPT_IN 0xC1
42#define EP_TYPE_INTERRUPT_OUT 0xC0
43#define EP_TYPE_ISOCHRONOUS_IN 0x41
44#define EP_TYPE_ISOCHRONOUS_OUT 0x40
45
46#define EP_SINGLE_BUFFER 0x02
47#define EP_DOUBLE_BUFFER 0x06
48
49#define EP_SIZE(s) ((s) == 64 ? 0x30 : ((s) == 32 ? 0x20 : ((s) == 16 ? 0x10 : 0x00)))
50
51#if defined(__AVR_AT90USB162__) || defined(__AVR_AT90USB82__)
52# define MAX_ENDPOINT 4
53# define UERST_MASK 0x1E
54#else
55# define MAX_ENDPOINT 6
56# define UERST_MASK 0x7E
57#endif
58
59#define LSB(n) (n & 255)
60#define MSB(n) ((n >> 8) & 255)
61
62#if defined(__AVR_AT90USB162__)
63# define HW_CONFIG()
64# define PLL_CONFIG() (PLLCSR = ((1 << PLLE) | (1 << PLLP0)))
65# define USB_CONFIG() (USBCON = (1 << USBE))
66# define USB_FREEZE() (USBCON = ((1 << USBE) | (1 << FRZCLK)))
67#elif defined(__AVR_ATmega32U4__)
68# define HW_CONFIG() (UHWCON = 0x01)
69# define PLL_CONFIG() (PLLCSR = 0x12)
70# define USB_CONFIG() (USBCON = ((1 << USBE) | (1 << OTGPADE)))
71# define USB_FREEZE() (USBCON = ((1 << USBE) | (1 << FRZCLK)))
72#elif defined(__AVR_AT90USB646__)
73# define HW_CONFIG() (UHWCON = 0x81)
74# define PLL_CONFIG() (PLLCSR = 0x1A)
75# define USB_CONFIG() (USBCON = ((1 << USBE) | (1 << OTGPADE)))
76# define USB_FREEZE() (USBCON = ((1 << USBE) | (1 << FRZCLK)))
77#elif defined(__AVR_AT90USB1286__)
78# define HW_CONFIG() (UHWCON = 0x81)
79# define PLL_CONFIG() (PLLCSR = 0x16)
80# define USB_CONFIG() (USBCON = ((1 << USBE) | (1 << OTGPADE)))
81# define USB_FREEZE() (USBCON = ((1 << USBE) | (1 << FRZCLK)))
82#endif
83
84// standard control endpoint request types
85#define GET_STATUS 0
86#define CLEAR_FEATURE 1
87#define SET_FEATURE 3
88#define SET_ADDRESS 5
89#define GET_DESCRIPTOR 6
90#define GET_CONFIGURATION 8
91#define SET_CONFIGURATION 9
92#define GET_INTERFACE 10
93#define SET_INTERFACE 11
94// HID (human interface device)
95#define HID_GET_REPORT 1
96#define HID_GET_IDLE 2
97#define HID_GET_PROTOCOL 3
98#define HID_SET_REPORT 9
99#define HID_SET_IDLE 10
100#define HID_SET_PROTOCOL 11
101#define HID_REPORT_INPUT 1
102#define HID_REPORT_OUTPUT 2
103#define HID_REPORT_FEATURE 3
104// CDC (communication class device)
105#define CDC_SET_LINE_CODING 0x20
106#define CDC_GET_LINE_CODING 0x21
107#define CDC_SET_CONTROL_LINE_STATE 0x22
108// HID feature selectors
109#define DEVICE_REMOTE_WAKEUP 1
110#define ENDPOINT_HALT 0
111#define TEST_MODE 2
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_SINGLE_BUFFER
120#define KBD_REPORT_KEYS (KBD_SIZE - 2)
121
122// secondary keyboard
123#ifdef 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
diff --git a/tmk_core/protocol/pjrc/usb_debug.c b/tmk_core/protocol/pjrc/usb_debug.c
deleted file mode 100644
index 7e78d96c3..000000000
--- a/tmk_core/protocol/pjrc/usb_debug.c
+++ /dev/null
@@ -1,98 +0,0 @@
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#include <avr/interrupt.h>
25#include "sendchar.h"
26#include "usb_debug.h"
27
28// the time remaining before we transmit any partially full
29// packet, or send a zero length packet.
30volatile uint8_t debug_flush_timer = 0;
31
32int8_t sendchar(uint8_t c) {
33 static uint8_t previous_timeout = 0;
34 uint8_t timeout, intr_state;
35
36 // if we're not online (enumerated and configured), error
37 if (!usb_configured()) return -1;
38 // interrupts are disabled so these functions can be
39 // used from the main program or interrupt context,
40 // even both in the same program!
41 intr_state = SREG;
42 cli();
43 UENUM = DEBUG_TX_ENDPOINT;
44 // if we gave up due to timeout before, don't wait again
45 if (previous_timeout) {
46 if (!(UEINTX & (1 << RWAL))) {
47 SREG = intr_state;
48 return -1;
49 }
50 previous_timeout = 0;
51 }
52 // wait for the FIFO to be ready to accept data
53 timeout = UDFNUML + 4;
54 while (1) {
55 // are we ready to transmit?
56 if (UEINTX & (1 << RWAL)) break;
57 SREG = intr_state;
58 // have we waited too long?
59 if (UDFNUML == timeout) {
60 previous_timeout = 1;
61 return -1;
62 }
63 // has the USB gone offline?
64 if (!usb_configured()) return -1;
65 // get ready to try checking again
66 intr_state = SREG;
67 cli();
68 UENUM = DEBUG_TX_ENDPOINT;
69 }
70 // actually write the byte into the FIFO
71 UEDATX = c;
72 // if this completed a packet, transmit it now!
73 if (!(UEINTX & (1 << RWAL))) {
74 UEINTX = 0x3A;
75 debug_flush_timer = 0;
76 } else {
77 debug_flush_timer = 2;
78 }
79 SREG = intr_state;
80 return 0;
81}
82
83// immediately transmit any buffered output.
84void usb_debug_flush_output(void) {
85 uint8_t intr_state;
86
87 intr_state = SREG;
88 cli();
89 if (debug_flush_timer) {
90 UENUM = DEBUG_TX_ENDPOINT;
91 while ((UEINTX & (1 << RWAL))) {
92 UEDATX = 0;
93 }
94 UEINTX = 0x3A;
95 debug_flush_timer = 0;
96 }
97 SREG = intr_state;
98}
diff --git a/tmk_core/protocol/pjrc/usb_debug.h b/tmk_core/protocol/pjrc/usb_debug.h
deleted file mode 100644
index efe075fa9..000000000
--- a/tmk_core/protocol/pjrc/usb_debug.h
+++ /dev/null
@@ -1,39 +0,0 @@
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_DEBUG_H
25#define USB_DEBUG_H 1
26
27#include <stdint.h>
28#include "usb.h"
29
30#define DEBUG_INTERFACE 2
31#define DEBUG_TX_ENDPOINT 3
32#define DEBUG_TX_SIZE 32
33#define DEBUG_TX_BUFFER EP_DOUBLE_BUFFER
34
35extern volatile uint8_t debug_flush_timer;
36
37void usb_debug_flush_output(void); // immediately transmit any buffered output
38
39#endif
diff --git a/tmk_core/protocol/pjrc/usb_extra.c b/tmk_core/protocol/pjrc/usb_extra.c
deleted file mode 100644
index 1745e651c..000000000
--- a/tmk_core/protocol/pjrc/usb_extra.c
+++ /dev/null
@@ -1,62 +0,0 @@
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#include <util/delay.h>
25#include <avr/interrupt.h>
26#include "host.h"
27#include "usb_extra.h"
28
29int8_t usb_extra_send(uint8_t report_id, uint16_t data) {
30 uint8_t intr_state, timeout;
31
32 if (!usb_configured()) return -1;
33 intr_state = SREG;
34 cli();
35 UENUM = EXTRA_ENDPOINT;
36 timeout = UDFNUML + 50;
37 while (1) {
38 // are we ready to transmit?
39 if (UEINTX & (1 << RWAL)) break;
40 SREG = intr_state;
41 // has the USB gone offline?
42 if (!usb_configured()) return -1;
43 // have we waited too long?
44 if (UDFNUML == timeout) return -1;
45 // get ready to try checking again
46 intr_state = SREG;
47 cli();
48 UENUM = EXTRA_ENDPOINT;
49 }
50
51 UEDATX = report_id;
52 UEDATX = data & 0xFF;
53 UEDATX = (data >> 8) & 0xFF;
54
55 UEINTX = 0x3A;
56 SREG = intr_state;
57 return 0;
58}
59
60int8_t usb_extra_consumer_send(uint16_t bits) { return usb_extra_send(REPORT_ID_CONSUMER, bits); }
61
62int8_t usb_extra_system_send(uint16_t bits) { return usb_extra_send(REPORT_ID_SYSTEM, bits); }
diff --git a/tmk_core/protocol/pjrc/usb_extra.h b/tmk_core/protocol/pjrc/usb_extra.h
deleted file mode 100644
index 674d582ac..000000000
--- a/tmk_core/protocol/pjrc/usb_extra.h
+++ /dev/null
@@ -1,44 +0,0 @@
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_EXTRA_H
25#define USB_EXTRA_H 1
26/*
27 * Enhanced keyboard features for Windows:
28 * Audio control and System control
29 *
30 * http://www.microsoft.com/whdc/archive/w2kbd.mspx
31 */
32
33#include <stdint.h>
34#include "usb.h"
35
36#define EXTRA_INTERFACE 3
37#define EXTRA_ENDPOINT 4
38#define EXTRA_SIZE 8
39#define EXTRA_BUFFER EP_DOUBLE_BUFFER
40
41int8_t usb_extra_consumer_send(uint16_t bits);
42int8_t usb_extra_system_send(uint16_t bits);
43
44#endif
diff --git a/tmk_core/protocol/pjrc/usb_keyboard.c b/tmk_core/protocol/pjrc/usb_keyboard.c
deleted file mode 100644
index 31856d0fd..000000000
--- a/tmk_core/protocol/pjrc/usb_keyboard.c
+++ /dev/null
@@ -1,114 +0,0 @@
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#include <avr/interrupt.h>
25#include <avr/pgmspace.h>
26#include "keycode.h"
27#include "usb_keyboard.h"
28#include "print.h"
29#include "debug.h"
30#include "util.h"
31#include "host.h"
32
33#ifdef NKRO_ENABLE
34# include "keycode_config.h"
35
36extern keymap_config_t keymap_config;
37#endif
38
39// protocol setting from the host. We use exactly the same report
40// either way, so this variable only stores the setting since we
41// are required to be able to report which setting is in use.
42uint8_t keyboard_protocol = 1;
43
44// the idle configuration, how often we send the report to the
45// host (ms * 4) even when it hasn't changed
46// Windows and Linux set 0 while OS X sets 6(24ms) by SET_IDLE request.
47uint8_t keyboard_idle = 125;
48
49// count until idle timeout
50uint8_t usb_keyboard_idle_count = 0;
51
52// 1=num lock, 2=caps lock, 4=scroll lock, 8=compose, 16=kana
53volatile uint8_t usb_keyboard_leds = 0;
54
55static inline int8_t send_report(report_keyboard_t *report, uint8_t endpoint, uint8_t keys_start, uint8_t keys_end);
56
57int8_t usb_keyboard_send_report(report_keyboard_t *report) {
58 int8_t result = 0;
59
60#ifdef NKRO_ENABLE
61 if (keymap_config.nkro)
62 result = send_report(report, KBD2_ENDPOINT, 0, KBD2_SIZE);
63 else
64#endif
65 {
66 result = send_report(report, KBD_ENDPOINT, 0, KBD_SIZE);
67 }
68
69 if (result) return result;
70 usb_keyboard_idle_count = 0;
71 usb_keyboard_print_report(report);
72 return 0;
73}
74
75void usb_keyboard_print_report(report_keyboard_t *report) {
76 if (!debug_keyboard) return;
77 print("keys: ");
78 for (int i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
79 phex(report->keys[i]);
80 print(" ");
81 }
82 print(" mods: ");
83 phex(report->mods);
84 print("\n");
85}
86
87static inline int8_t send_report(report_keyboard_t *report, uint8_t endpoint, uint8_t keys_start, uint8_t keys_end) {
88 uint8_t intr_state, timeout;
89
90 if (!usb_configured()) return -1;
91 intr_state = SREG;
92 cli();
93 UENUM = endpoint;
94 timeout = UDFNUML + 50;
95 while (1) {
96 // are we ready to transmit?
97 if (UEINTX & (1 << RWAL)) break;
98 SREG = intr_state;
99 // has the USB gone offline?
100 if (!usb_configured()) return -1;
101 // have we waited too long?
102 if (UDFNUML == timeout) return -1;
103 // get ready to try checking again
104 intr_state = SREG;
105 cli();
106 UENUM = endpoint;
107 }
108 for (uint8_t i = keys_start; i < keys_end; i++) {
109 UEDATX = report->raw[i];
110 }
111 UEINTX = 0x3A;
112 SREG = intr_state;
113 return 0;
114}
diff --git a/tmk_core/protocol/pjrc/usb_keyboard.h b/tmk_core/protocol/pjrc/usb_keyboard.h
deleted file mode 100644
index 919685fde..000000000
--- a/tmk_core/protocol/pjrc/usb_keyboard.h
+++ /dev/null
@@ -1,38 +0,0 @@
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_KEYBOARD_H
25#define USB_KEYBOARD_H 1
26
27#include <stdint.h>
28#include <stdbool.h>
29#include "usb.h"
30#include "host.h"
31
32extern uint8_t usb_keyboard_idle_count;
33extern volatile uint8_t usb_keyboard_leds;
34
35int8_t usb_keyboard_send_report(report_keyboard_t *report);
36void usb_keyboard_print_report(report_keyboard_t *report);
37
38#endif
diff --git a/tmk_core/protocol/pjrc/usb_mouse.c b/tmk_core/protocol/pjrc/usb_mouse.c
deleted file mode 100644
index 9e3639571..000000000
--- a/tmk_core/protocol/pjrc/usb_mouse.c
+++ /dev/null
@@ -1,83 +0,0 @@
1/* USB Mouse Plus Debug Channel Example for Teensy USB Development Board
2 * http://www.pjrc.com/teensy/usb_mouse.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#include <avr/interrupt.h>
25#include <util/delay.h>
26#include "usb_mouse.h"
27#include "print.h"
28#include "debug.h"
29
30uint8_t usb_mouse_protocol = 1;
31
32int8_t usb_mouse_send(int8_t x, int8_t y, int8_t wheel_v, int8_t wheel_h, uint8_t buttons) {
33 uint8_t intr_state, timeout;
34
35 if (!usb_configured()) return -1;
36 if (x == -128) x = -127;
37 if (y == -128) y = -127;
38 if (wheel_v == -128) wheel_v = -127;
39 if (wheel_h == -128) wheel_h = -127;
40 intr_state = SREG;
41 cli();
42 UENUM = MOUSE_ENDPOINT;
43 timeout = UDFNUML + 50;
44 while (1) {
45 // are we ready to transmit?
46 if (UEINTX & (1 << RWAL)) break;
47 SREG = intr_state;
48 // has the USB gone offline?
49 if (!usb_configured()) return -1;
50 // have we waited too long?
51 if (UDFNUML == timeout) return -1;
52 // get ready to try checking again
53 intr_state = SREG;
54 cli();
55 UENUM = MOUSE_ENDPOINT;
56 }
57 UEDATX = buttons;
58 UEDATX = x;
59 UEDATX = y;
60 if (usb_mouse_protocol) {
61 UEDATX = wheel_v;
62 UEDATX = wheel_h;
63 }
64
65 UEINTX = 0x3A;
66 SREG = intr_state;
67 return 0;
68}
69
70void usb_mouse_print(int8_t x, int8_t y, int8_t wheel_v, int8_t wheel_h, uint8_t buttons) {
71 if (!debug_mouse) return;
72 print("usb_mouse[btn|x y v h]: ");
73 phex(buttons);
74 print("|");
75 phex(x);
76 print(" ");
77 phex(y);
78 print(" ");
79 phex(wheel_v);
80 print(" ");
81 phex(wheel_h);
82 print("\n");
83}
diff --git a/tmk_core/protocol/pjrc/usb_mouse.h b/tmk_core/protocol/pjrc/usb_mouse.h
deleted file mode 100644
index ba7df230d..000000000
--- a/tmk_core/protocol/pjrc/usb_mouse.h
+++ /dev/null
@@ -1,47 +0,0 @@
1/* USB Mouse Plus Debug Channel Example for Teensy USB Development Board
2 * http://www.pjrc.com/teensy/usb_mouse.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_MOUSE_H
25#define USB_MOUSE_H 1
26
27#include <stdint.h>
28#include <stdbool.h>
29#include "usb.h"
30
31#define MOUSE_INTERFACE 1
32#define MOUSE_ENDPOINT 2
33#define MOUSE_SIZE 8
34#define MOUSE_BUFFER EP_SINGLE_BUFFER
35
36#define MOUSE_BTN1 (1 << 0)
37#define MOUSE_BTN2 (1 << 1)
38#define MOUSE_BTN3 (1 << 2)
39#define MOUSE_BTN4 (1 << 3)
40#define MOUSE_BTN5 (1 << 4)
41
42extern uint8_t usb_mouse_protocol;
43
44int8_t usb_mouse_send(int8_t x, int8_t y, int8_t wheel_v, int8_t wheel_h, uint8_t buttons);
45void usb_mouse_print(int8_t x, int8_t y, int8_t wheel_v, int8_t wheel_h, uint8_t buttons);
46
47#endif
diff --git a/tmk_core/readme.md b/tmk_core/readme.md
index a3783fe37..71b8d2e9f 100644
--- a/tmk_core/readme.md
+++ b/tmk_core/readme.md
@@ -48,7 +48,7 @@ Complete firmwares for various keyboards and protocol converters.
48License 48License
49------- 49-------
50**GPLv2** or later. Some protocol files are under **Modified BSD License**. 50**GPLv2** or later. Some protocol files are under **Modified BSD License**.
51LUFA, PJRC and V-USB stack have their own license respectively. 51ChibiOS, LUFA and V-USB stack have their own license respectively.
52 52
53 53
54 54
@@ -85,9 +85,9 @@ Architecture
85 / /| Keys/Mouse | Protocol |d| | Action | | | Protocol | 85 / /| Keys/Mouse | Protocol |d| | Action | | | Protocol |
86 /__________/ |<-----------| LUFA |r| | Layer, Tap | | | Matrix | 86 /__________/ |<-----------| LUFA |r| | Layer, Tap | | | Matrix |
87 |.--------.| | LED | V-USB |i| |-------------| | | PS/2,IBM | __________________ 87 |.--------.| | LED | V-USB |i| |-------------| | | PS/2,IBM | __________________
88 || || |----------->| PJRC |v| | Keymap | | | ADB,M0110| Keys / /_/_/_/_/_/_/_/ /| 88 || || |----------->| iWRAP(BT)|v| | Keymap | | | ADB,M0110| Keys / /_/_/_/_/_/_/_/ /|
89 || Host || | Console | iWRAP(BT)|e| | Mousekey | | | SUN/NEWS |<----------/ /_/_/_/_/_/_/_/ / / 89 || Host || | Console | UART |e| | Mousekey | | | SUN/NEWS |<----------/ /_/_/_/_/_/_/_/ / /
90 ||________||/.<-----------| UART |r| | Report | | | X68K/PC98| Control / /_/_/_/_/_/_/_/ / / 90 ||________||/.<-----------| |r| | Report | | | X68K/PC98| Control / /_/_/_/_/_/_/_/ / /
91 `_========_'/| |---------------------------------------------|-------->/___ /_______/ ___/ / 91 `_========_'/| |---------------------------------------------|-------->/___ /_______/ ___/ /
92 |_o______o_|/ | Sendchar, Print, Debug, Command, ... | |_________________|/ 92 |_o______o_|/ | Sendchar, Print, Debug, Command, ... | |_________________|/
93 +---------------------------------------------+ Keyboard 93 +---------------------------------------------+ Keyboard
@@ -133,7 +133,6 @@ Files and Directories
133 133
134### Keyboard Protocols 134### Keyboard Protocols
135* lufa/ - LUFA USB stack 135* lufa/ - LUFA USB stack
136* pjrc/ - PJRC USB stack
137* vusb/ - Objective Development V-USB 136* vusb/ - Objective Development V-USB
138* iwrap/ - Bluetooth HID for Bluegiga iWRAP 137* iwrap/ - Bluetooth HID for Bluegiga iWRAP
139* ps2.c - PS/2 protocol 138* ps2.c - PS/2 protocol