aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/protocol
diff options
context:
space:
mode:
authorstein3 <stein3@gmail.com>2020-10-06 07:15:41 -0700
committerstein3 <stein3@gmail.com>2020-10-06 07:15:41 -0700
commit2e402741a89c5eec8cf30c966ce6f36d6ec9249b (patch)
tree3592e8c5e6bd19943ae55db7fc02a5f755afbb51 /tmk_core/protocol
parent3e5e4f74272c610bb9fa737f674f8e65ed6100ca (diff)
parent2013f6313430b977e557e482d30daa279a46e75d (diff)
downloadqmk_firmware-2e402741a89c5eec8cf30c966ce6f36d6ec9249b.tar.gz
qmk_firmware-2e402741a89c5eec8cf30c966ce6f36d6ec9249b.zip
Merge branch 'master' into meteor
Diffstat (limited to 'tmk_core/protocol')
-rw-r--r--tmk_core/protocol/chibios/main.c1
-rw-r--r--tmk_core/protocol/chibios/usb_main.c85
-rw-r--r--tmk_core/protocol/iwrap.mk32
-rw-r--r--tmk_core/protocol/iwrap/iWRAP4.txt376
-rw-r--r--tmk_core/protocol/iwrap/iWRAP5.txt356
-rw-r--r--tmk_core/protocol/iwrap/iwrap.c420
-rw-r--r--tmk_core/protocol/iwrap/iwrap.h47
-rw-r--r--tmk_core/protocol/iwrap/main.c412
-rw-r--r--tmk_core/protocol/iwrap/mux_exit.rb7
-rw-r--r--tmk_core/protocol/iwrap/suart.S156
-rw-r--r--tmk_core/protocol/iwrap/suart.h8
-rw-r--r--tmk_core/protocol/iwrap/wd.h161
-rw-r--r--tmk_core/protocol/lufa.mk25
-rw-r--r--tmk_core/protocol/lufa/adafruit_ble.cpp4
-rw-r--r--tmk_core/protocol/lufa/adafruit_ble.h27
-rw-r--r--tmk_core/protocol/lufa/bluetooth.c38
-rw-r--r--tmk_core/protocol/lufa/bluetooth.h48
-rw-r--r--tmk_core/protocol/lufa/lufa.c314
-rw-r--r--tmk_core/protocol/lufa/lufa.h4
-rw-r--r--tmk_core/protocol/lufa/outputselect.c14
-rw-r--r--tmk_core/protocol/lufa/outputselect.h6
-rw-r--r--tmk_core/protocol/serial.h5
-rw-r--r--tmk_core/protocol/usb_descriptor.c121
-rw-r--r--tmk_core/protocol/usb_descriptor.h20
-rw-r--r--tmk_core/protocol/vusb.mk7
-rw-r--r--tmk_core/protocol/vusb/main.c37
-rw-r--r--tmk_core/protocol/vusb/sendchar_usart.c19
-rw-r--r--tmk_core/protocol/vusb/usbconfig.h20
-rw-r--r--tmk_core/protocol/vusb/vusb.c144
29 files changed, 546 insertions, 2368 deletions
diff --git a/tmk_core/protocol/chibios/main.c b/tmk_core/protocol/chibios/main.c
index 7d32c16ed..a0d28f9af 100644
--- a/tmk_core/protocol/chibios/main.c
+++ b/tmk_core/protocol/chibios/main.c
@@ -35,6 +35,7 @@
35 35
36#ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP 36#ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP
37// Change this to be TRUE once we've migrated keyboards to the new init system 37// Change this to be TRUE once we've migrated keyboards to the new init system
38// Remember to change docs/platformdev_chibios_earlyinit.md as well.
38# define EARLY_INIT_PERFORM_BOOTLOADER_JUMP FALSE 39# define EARLY_INIT_PERFORM_BOOTLOADER_JUMP FALSE
39#endif 40#endif
40 41
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index 65bd291be..ae33e86a7 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -47,6 +47,10 @@
47extern keymap_config_t keymap_config; 47extern keymap_config_t keymap_config;
48#endif 48#endif
49 49
50#ifdef JOYSTICK_ENABLE
51# include "joystick.h"
52#endif
53
50/* --------------------------------------------------------- 54/* ---------------------------------------------------------
51 * Global interface variables and declarations 55 * Global interface variables and declarations
52 * --------------------------------------------------------- 56 * ---------------------------------------------------------
@@ -62,7 +66,7 @@ extern keymap_config_t keymap_config;
62 66
63uint8_t keyboard_idle __attribute__((aligned(2))) = 0; 67uint8_t keyboard_idle __attribute__((aligned(2))) = 0;
64uint8_t keyboard_protocol __attribute__((aligned(2))) = 1; 68uint8_t keyboard_protocol __attribute__((aligned(2))) = 1;
65uint8_t keyboard_led_stats = 0; 69uint8_t keyboard_led_state = 0;
66volatile uint16_t keyboard_idle_count = 0; 70volatile uint16_t keyboard_idle_count = 0;
67static virtual_timer_t keyboard_idle_timer; 71static virtual_timer_t keyboard_idle_timer;
68static void keyboard_idle_timer_cb(void *arg); 72static void keyboard_idle_timer_cb(void *arg);
@@ -247,6 +251,9 @@ typedef struct {
247#ifdef VIRTSER_ENABLE 251#ifdef VIRTSER_ENABLE
248 usb_driver_config_t serial_driver; 252 usb_driver_config_t serial_driver;
249#endif 253#endif
254#ifdef JOYSTICK_ENABLE
255 usb_driver_config_t joystick_driver;
256#endif
250 }; 257 };
251 usb_driver_config_t array[0]; 258 usb_driver_config_t array[0];
252 }; 259 };
@@ -283,6 +290,14 @@ static usb_driver_configs_t drivers = {
283# define CDC_OUT_MODE USB_EP_MODE_TYPE_BULK 290# define CDC_OUT_MODE USB_EP_MODE_TYPE_BULK
284 .serial_driver = QMK_USB_DRIVER_CONFIG(CDC, CDC_NOTIFICATION_EPNUM, false), 291 .serial_driver = QMK_USB_DRIVER_CONFIG(CDC, CDC_NOTIFICATION_EPNUM, false),
285#endif 292#endif
293
294#ifdef JOYSTICK_ENABLE
295# define JOYSTICK_IN_CAPACITY 4
296# define JOYSTICK_OUT_CAPACITY 4
297# define JOYSTICK_IN_MODE USB_EP_MODE_TYPE_BULK
298# define JOYSTICK_OUT_MODE USB_EP_MODE_TYPE_BULK
299 .joystick_driver = QMK_USB_DRIVER_CONFIG(JOYSTICK, 0, false),
300#endif
286}; 301};
287 302
288#define NUM_USB_DRIVERS (sizeof(drivers) / sizeof(usb_driver_config_t)) 303#define NUM_USB_DRIVERS (sizeof(drivers) / sizeof(usb_driver_config_t))
@@ -386,10 +401,10 @@ static void set_led_transfer_cb(USBDriver *usbp) {
386 if (usbp->setup[6] == 2) { /* LSB(wLength) */ 401 if (usbp->setup[6] == 2) { /* LSB(wLength) */
387 uint8_t report_id = set_report_buf[0]; 402 uint8_t report_id = set_report_buf[0];
388 if ((report_id == REPORT_ID_KEYBOARD) || (report_id == REPORT_ID_NKRO)) { 403 if ((report_id == REPORT_ID_KEYBOARD) || (report_id == REPORT_ID_NKRO)) {
389 keyboard_led_stats = set_report_buf[1]; 404 keyboard_led_state = set_report_buf[1];
390 } 405 }
391 } else { 406 } else {
392 keyboard_led_stats = set_report_buf[0]; 407 keyboard_led_state = set_report_buf[0];
393 } 408 }
394} 409}
395 410
@@ -610,7 +625,7 @@ static void keyboard_idle_timer_cb(void *arg) {
610} 625}
611 626
612/* LED status */ 627/* LED status */
613uint8_t keyboard_leds(void) { return keyboard_led_stats; } 628uint8_t keyboard_leds(void) { return keyboard_led_state; }
614 629
615/* prepare and start sending a report IN 630/* prepare and start sending a report IN
616 * not callable from ISR or locked state */ 631 * not callable from ISR or locked state */
@@ -796,9 +811,7 @@ int8_t sendchar(uint8_t c) {
796} 811}
797#endif /* CONSOLE_ENABLE */ 812#endif /* CONSOLE_ENABLE */
798 813
799void _putchar(char character) { 814void _putchar(char character) { sendchar(character); }
800 sendchar(character);
801}
802 815
803#ifdef RAW_ENABLE 816#ifdef RAW_ENABLE
804void raw_hid_send(uint8_t *data, uint8_t length) { 817void raw_hid_send(uint8_t *data, uint8_t length) {
@@ -869,3 +882,61 @@ void virtser_task(void) {
869} 882}
870 883
871#endif 884#endif
885
886#ifdef JOYSTICK_ENABLE
887
888void send_joystick_packet(joystick_t *joystick) {
889 joystick_report_t rep = {
890# if JOYSTICK_AXES_COUNT > 0
891 .axes =
892 {
893 joystick->axes[0],
894
895# if JOYSTICK_AXES_COUNT >= 2
896 joystick->axes[1],
897# endif
898# if JOYSTICK_AXES_COUNT >= 3
899 joystick->axes[2],
900# endif
901# if JOYSTICK_AXES_COUNT >= 4
902 joystick->axes[3],
903# endif
904# if JOYSTICK_AXES_COUNT >= 5
905 joystick->axes[4],
906# endif
907# if JOYSTICK_AXES_COUNT >= 6
908 joystick->axes[5],
909# endif
910 },
911# endif // JOYSTICK_AXES_COUNT>0
912
913# if JOYSTICK_BUTTON_COUNT > 0
914 .buttons =
915 {
916 joystick->buttons[0],
917
918# if JOYSTICK_BUTTON_COUNT > 8
919 joystick->buttons[1],
920# endif
921# if JOYSTICK_BUTTON_COUNT > 16
922 joystick->buttons[2],
923# endif
924# if JOYSTICK_BUTTON_COUNT > 24
925 joystick->buttons[3],
926# endif
927 }
928# endif // JOYSTICK_BUTTON_COUNT>0
929 };
930
931 // chnWrite(&drivers.joystick_driver.driver, (uint8_t *)&rep, sizeof(rep));
932 osalSysLock();
933 if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
934 osalSysUnlock();
935 return;
936 }
937
938 usbStartTransmitI(&USB_DRIVER, JOYSTICK_IN_EPNUM, (uint8_t *)&rep, sizeof(joystick_report_t));
939 osalSysUnlock();
940}
941
942#endif
diff --git a/tmk_core/protocol/iwrap.mk b/tmk_core/protocol/iwrap.mk
deleted file mode 100644
index 934235bd8..000000000
--- a/tmk_core/protocol/iwrap.mk
+++ /dev/null
@@ -1,32 +0,0 @@
1IWRAP_DIR = protocol/iwrap
2
3OPT_DEFS += -DPROTOCOL_IWRAP
4
5SRC += $(IWRAP_DIR)/main.c \
6 $(IWRAP_DIR)/iwrap.c \
7 $(IWRAP_DIR)/suart.S \
8 $(COMMON_DIR)/sendchar_uart.c \
9 $(COMMON_DIR)/uart.c
10
11# Search Path
12VPATH += $(TMK_DIR)/protocol/iwrap
13
14
15# TODO: compatible with LUFA and PJRC
16# V-USB
17#
18VUSB_DIR = protocol/vusb
19
20# Path to the V-USB library
21VUSB_PATH = $(LIB_PATH)/vusb
22
23SRC += $(VUSB_DIR)/vusb.c \
24 $(VUSB_PATH)/usbdrv/usbdrv.c \
25 $(VUSB_PATH)/usbdrv/usbdrvasm.S \
26 $(VUSB_PATH)/usbdrv/oddebug.c
27
28# Search Path
29VPATH += $(TMK_PATH)/$(VUSB_DIR)
30VPATH += $(VUSB_PATH)
31
32OPT_DEFS += -DPROTOCOL_VUSB
diff --git a/tmk_core/protocol/iwrap/iWRAP4.txt b/tmk_core/protocol/iwrap/iWRAP4.txt
deleted file mode 100644
index 2a062d9d9..000000000
--- a/tmk_core/protocol/iwrap/iWRAP4.txt
+++ /dev/null
@@ -1,376 +0,0 @@
1Bulegiga WT12
2=============
3WT12 is a bluetooth module from Bluegiga. http://www.bluegiga.com/
4
5iWRAP
6 higher layer interface for bluetooth firmware
7 communicate with UART
8
9iWRAP HID
10default setting
11 115200 8bit/n/1/n
12
13
14TODO
15----
16KiCAD circuit/PCB design
17power saving
18 AVR sleep(15ms by watch dog timer)
19 WT12 sleep
20 measuring current consumption
21 measuring battery life of normal usage/idle/intensive usage
22software reset/bootloarder
23LED indicator(chaging/paring/connecting)
24license confirmation of suart.c
25consumer page is not working
26authenticate method/SSP
27SPP keyboard support
28SPP debug console support
29mouse wheel feature request to Bluegiga
30
31
32Problems
33--------
34power consumption
35no consumer page support(bug?)
36no mouse wheel support
37no paring management
38no interactive auth method
39
40
41UART hardware flow control
42--------------------------
43(iWRAP4 User Guide 9.5)
44Hardware flow control is enabled by default and it should not be disabled unless mandatory, because without the hardware flow control the data transmission may not be reliable.
45If the hardware flow control is enabled from PS-keys, but no flow control is used, the following steps should be implemented in the hardware design:
46- CTS pin must be grounded
47- RTS pin must be left floating
48
49
50Power Saving
51------------
52power consume
53 without opimization: 4hr to shutdown(310mAh)
54 2011/08/25: 9hr(310mAh) SNIFF MASTER sleep/WDTO_120MS
55
56measure current consumption
57 HHKB keyswitch matrix board
58 idle
59 scanning
60 Bluegiga WT12 module
61 SLEEP command
62 deep sleep on/off in config bits
63
64HHKB keyswich
65 how to power off
66 I/O pin configuration when sleeping
67 FET switch for 5V regulator
68
69Bluetooth module
70 power off when in USB mode
71 power off by FET switch
72
73AVR configuration
74 unused pins
75 ADC
76
77
78
79SET CONTROL CONFIG
80------------------
81 SET CONTROL CONFIG 4810
82 SET CONTROL CONFIG LIST
83 SET CONTROL CONFIG 0000 0000 4910 DEEP_SLEEP KLUDGE INTERACTIVE_PIN UART_LATENCY
84
85 Bit14 UART low latency
86 Bit11 Interactive pairing mode
87 Bit04 Deep sleep
88
89
90Reconnection
91------------
92SET CONTROL AUTOCALL 1124 5000 HID
93 1124 HID service class
94 5000 interval ms
95
96HID profile
97-----------
98This is needed to configure only once.
99 SET PROFILE HID ON
100 RESET
101
102HID class
103---------
104 SET BT CLASS 005C0 // keyboard/mouse combined devie
105
106Pairing Security
107----------------
108Secure Simple Pairing(SSP)
109 SET BT SSP 2 0 // Enables SSP for keyboard and Man-in-the-middle protection
110 SET BT SSP 3 0 // Enables SSP just works mode
111
112for keyboard with SSP
113 SET BT AUTH * 0000
114 SET BT SSP 2 0
115 SET CONTROL CONFIG 800
116 RESET
117
118for keyboard without SSP
119 SET BT AUTH * 0000
120 SET CONTROL CONFIG 800
121 RESET
122
123AUTH
124 AUTH xx:xx:xx:xx:xx:xx? // Pairing request event
125 AUTH xx:xx:xx:xx:xx:xx 0000
126
127 SSP PASSKEY 78:dd:08:b7:e4:a2 ?
128 SSP PASSKEY 78:dd:08:b7:e4:a2 xxxxx
129 (SSP COMPLETE 78:dd:08:b7:e4:a2 HCI_ERROR_AUTH_FAIL // failed)
130 RING 0 78:dd:08:b7:e4:a2 11 HID
131
132Connecton
133 RING xx:xx:xx:xx:xx:xx xx HID // connection event
134
135 KILL xx:xx:xx:xx:xx:xx
136
137Mode
138----
139Command mode
140Data mode
141 Raw mode
142 (Simple mode not for a real keyboard)
143
144Raw mode
145 Keyboard:
146 0x9f, length(10), 0xa1, 0x01, mods, 0x00, key1, key2, key3, key4, key5, key6
147
148 Mouse:
149 0x9f, length(5), 0xa1, 0x02, buttons, X, Y
150
151 Consumer page:
152 0x9f, length(5), 0xa1, 0x03, bitfield1, bitfield2, bitfield3
153
154 consumer page suage
155 Bitfield 1:
156 0x01 Volume Increment
157 0x02 Volume Decrement
158 0x04 Mute
159 0x08 Play/Pause
160 0x10 Scan Next Track
161 0x20 Scan Previous Track
162 0x40 Stop
163 0x80 Eject
164 Bitfield 2:
165 0x01 Email Reader
166 0x02 Application Control Search
167 0x04 AC Bookmarks
168 0x08 AC Home
169 0x10 AC Back
170 0x20 AC Forward
171 0x40 AC Stop
172 0x80 AC Refresh
173 Bitfield 3:
174 0x01 Application Launch Generic Consumer Control
175 0x02 AL Internet Browser
176 0x04 AL Calculator
177 0x08 AL Terminal Lock / Screensaver
178 0x10 AL Local Machine Browser
179 0x20 AC Minimize
180 0x40 Record
181 0x80 Rewind
182
183
184
185
186
1872011/07/13
188set
189SET BT BDADDR 00:07:80:47:22:14
190SET BT NAME HHKB pro BT
191SET BT CLASS 0005c0
192SET BT AUTH * 0000
193SET BT IDENT BT:47 f000 4.1.0 Bluegiga iWRAP
194SET BT LAP 9e8b33
195SET BT PAGEMODE 4 2000 1
196SET BT PAIR 78:dd:08:b7:e4:a2 a191189cd7e51030ad6a07848ce879bb
197SET BT POWER 3 3 3
198SET BT ROLE 0 f 7d00
199SET BT SNIFF 0 20 1 8
200SET BT SSP 2 1
201SET BT MTU 667
202SET CONTROL AUTOCALL 1124 3000 HID
203SET CONTROL BAUD 38400,8n1
204SET CONTROL CD 00 0
205SET CONTROL ECHO 7
206SET CONTROL ESCAPE 43 00 1
207SET CONTROL GAIN 0 5
208SET CONTROL INIT SET CONTROL MUX 0
209SET CONTROL MSC DTE 00 00 00 00 00 00
210SET CONTROL MUX 1
211SET CONTROL PIO 00 00
212SET CONTROL READY 00
213SET PROFILE HID f HID
214SET
215
216info config
217
218!!! THIS IS BETA RELEASE AND MAY BE USED FOR EVALUATION PURPOSES ONLY !!!
219
220WRAP THOR AI (4.1.0 build 435)
221Copyright (c) 2003-2011 Bluegiga Technologies Inc.
222Compiled on Jun 28 2011 17:19:51, running on WT12-A module, psr v31
223 AVRCP BGIO FTP HFP HFP_AG HID HID_CONSUMER_PAGE HSP LEDS MAP OTA PBAP PIO=0x00fc SSP SUBRATE TEST VOLUME
224 - BOCK3 version 435 (Jun 28 2011 17:19:37) (max acl/sco 7/1)
225 - Bluetooth version 2.1, Power class 2
226 - Loader 4279, firmware 6297 (56-bit encryption), native execution mode
227 - up 0 days, 06:23, 2 connections (pool 2)
228 - User configuration:
229&028a = 0001 0000 0000 0011 0024 0000 0000 0010 0000 0080 0000 0000 0080 005f 009b 0034 00fb 0006
230&028b = 0000 0bb8
231&028d = 0001
232&0295 = 0000 0005 000b 0000 0003 0000 0000 0000 0000 0000 0000
233&0298 = a006
234&0299 = 0000 0000
235&02a3 = 0030 0030 0030 0030
236&02a4 = 009d 0000
237&02a5 = 0053 0045 0054 0020 0043 004f 004e 0054 0052 004f 004c 0020 004d 0055 0058 0020 0030
238&02a7 = 0000 05c0
239&02a8 = 4910 0000 0000
240&02aa = 0004 2000 0001 0033 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
241&02ac = 0000 0000 002b 0000 0000 0000 0000 0000 0000 0000 0002 0000 0000 0000 0010 0000 0000 0000 0000 029b 0000 0000 0000 0000
242&02ad = 4848 424b 7020 6f72 4220 0054
243&02b3 = 0005 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003
244&02b7 = 000f 4948 0044
245&02bb = 8000
246READY.
247
248
249
250
2512011/07/07 settings:
252set
253SET BT BDADDR 00:07:80:47:22:14
254SET BT NAME HHKB Pro BT
255SET BT CLASS 0005c0
256SET BT AUTH * 000
257SET BT IDENT BT:47 f000 4.0.0 Bluegiga iWRAP
258SET BT LAP 9e8b33
259SET BT PAGEMODE 4 2000 1
260SET BT PAIR 78:dd:08:b7:e4:a2 9e54d0aabb1b4d73cfccddb1ea4ef2d6
261SET BT POWER 3 3 3
262SET BT ROLE 0 f 7d00
263SET BT SNIFF 0 20 1 8
264SET BT SSP 3 0
265SET BT MTU 667
266SET CONTROL BAUD 38400,8n1
267SET CONTROL CD 00 0
268SET CONTROL ECHO 7
269SET CONTROL ESCAPE 255 00 1
270SET CONTROL GAIN 0 5
271SET CONTROL INIT set control mux 0
272SET CONTROL MSC DTE 00 00 00 00 00 00
273SET CONTROL PREAMP 1 1
274SET CONTROL READY 00
275SET PROFILE HID HID
276SET PROFILE SPP Bluetooth Serial Port
277SET
278
279info config
280WRAP THOR AI (4.0.0 build 317)
281Copyright (c) 2003-2010 Bluegiga Technologies Inc.
282Compiled on Apr 20 2010 16:44:28, running on WT12-A module, psr v31
283 AVRCP FTP PBAP PIO=0x00fc SSP SUBRATE VOLUME
284 - BOCK3 version 317 (Apr 20 2010 16:44:21) (max acl/sco 7/1)
285 - Bluetooth version 2.1, Power class 2
286 - Loader 4279, firmware 6297 (56-bit encryption), native execution mode
287 - up 0 days, 00:00, 0 connections (pool 1)
288 - User configuration:
289&028c = 0001 0020 0000 0001 0008 0000
290&028d = 0000
291&0296 = 0047 0001 f000 0400 6c42 6575 6967 6167 6920 5257 5041
292&0298 = c006
293&02a3 = 0030 0030 0030
294&02a4 = 009d 0000
295&02a5 = 0073 0065 0074 0020 0063 006f 006e 0074 0072 006f 006c 0020 006d 0075 0078 0020 0030
296&02a7 = 0000 05c0
297&02a8 = 0800 0000 0000
298&02ac = 0000 0000 00ff 0000 0000 0000 0000 0000 0000 0000 0002 0000 0000 0000 0010 0000 0000 0000 0000 029b 0000 0000 0000 0000
299&02ad = 4848 424b 5020 6f72 4220 0054
300&02b3 = 0004 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003
301&02b7 = 0000
302&02bb = 6c42 6575 6f74 746f 2068 6553 6972 6c61 5020 726f 0074
303READY.
304
305
306
3072011/08/23:
308SET BT BDADDR 00:07:80:47:22:14
309SET BT NAME HHKB pro BT
310SET BT CLASS 0005c0
311SET BT AUTH * 0000
312SET BT IDENT BT:47 f000 4.1.0 Bluegiga iWRAP
313SET BT LAP 9e8b33
314SET BT PAGEMODE 4 2000 1
315SET BT PAIRCOUNT 4
316SET BT POWER 3 3 3
317SET BT ROLE 1 f 12c0
318SET BT SNIFF 10 2 1 8
319SET BT SSP 3 0
320SET BT MTU 667
321SET CONTROL BAUD 38400,8n1
322SET CONTROL CD 00 0
323SET CONTROL ECHO 7
324SET CONTROL ESCAPE 43 00 1
325SET CONTROL GAIN 0 5
326SET CONTROL INIT SET CONTROL MUX 0
327SET CONTROL MSC DTE 00 00 00 00 00 00
328SET CONTROL MUX 1
329SET CONTROL PIO 00 00
330SET CONTROL READY 00
331SET PROFILE HID 7 HIDKeyboardMouse
332SET
333
334SET CONTROL CONFIG 0000 0004 481e CLOCK_CACHE INTERLACED_INQ INTERLACED_PAGE DEEP_SLEEP INTERACTIVE_PIN UART_LATENCY 23D_NOKLUDGE
335
336
337
3382011/08/25:
339SET BT BDADDR 00:07:80:47:22:14
340SET BT NAME HHKB pro BT
341SET BT CLASS 0005c0
342
343SET BT IDENT BT:47 f000 4.1.0 Bluegiga iWRAP
344SET BT LAP 9e8b33
345SET BT PAGEMODE 4 2000 1
346SET BT PAIRCOUNT 4
347SET BT PAIR 78:dd:08:b7:e4:a2 0be83335a03fed8ededae42e99554e28
348SET BT POWER 3 3 3
349SET BT ROLE 1 f 12c0
350SET BT SNIFF 100 20 1 8
351SET BT SSP 3 0
352SET BT MTU 667
353SET CONTROL BAUD 38400,8n1
354SET CONTROL CD 00 0
355SET CONTROL ECHO 7
356SET CONTROL ESCAPE - 20 1
357SET CONTROL GAIN 0 5
358SET CONTROL INIT SET CONTROL MUX 0
359SET CONTROL MSC DTE 00 00 00 00 00 00
360SET CONTROL MUX 1
361SET CONTROL PIO 00 00
362SET CONTROL READY 00
363SET PROFILE HID f HIDKeyboardMouse
364SET
365
366
367SET CONTROL CONFIG 0000 0000 490e CLOCK_CACHE INTERLACED_INQ INTERLACED_PAGE KLUDGE INTERACTIVE_PIN UART_LATENCY
368
369
3702011/09/08:
371SET CONTROL CONFIG 0000 0000 410e CLOCK_CACHE INTERLACED_INQ INTERLACED_PAGE KLUDGE UART_LATENCY
372
373 Removed INTERACTIVE_PIN to avoid interactive auth and use SET BT AUTH pin(0000).
374
375
376EOF
diff --git a/tmk_core/protocol/iwrap/iWRAP5.txt b/tmk_core/protocol/iwrap/iWRAP5.txt
deleted file mode 100644
index ce3310f1b..000000000
--- a/tmk_core/protocol/iwrap/iWRAP5.txt
+++ /dev/null
@@ -1,356 +0,0 @@
1Terminology
2===========
3PSM
4HIDP HID Protocol
5L2CAP Logical Link Control Adaptation Protocol
6MTU Maximum Transmission Unit
7
8
9
10HID Protocol
11============
123 of HID_SPEC_V11.pdf
13
14Channel
15-------
16Control channel PSM=0x0011
17Interrupt channel PSM=0x0013
18
19Message
20-------
21HANDSHAKE(0)
22HID_CONTROL(1)
23
24GET_REPORT(4)
25 Host requests report(DATA payload on Control channel) from Device
26 Size Desc
27 ------------------------------------------------------------------------------
28 HIDP-Hdr 1 7..4: HIDP Message TYpe(4: GET_REPORT)
29 3: Size(1:2-octed buffer size, 0:size of the report)
30 2: 0
31 1..0: Report Type(1:input, 2:output, 3: feature)
32 ReportID 1 Optional
33 BufferSize 2 Optional(specified when Size=1)
34
35SET_REPORT(5)
36GET_PROTOCOL(6)
37SET_PROTOCOL(7)
38
39DATA(A)
40 Input/Output Report: All DATA payloads flow on Interrupt channel.
41 Other: flows on Control channel.
42 Size Desc
43 ------------------------------------------------------------------------------
44 HIDP-Hdr 1 7..4 0xA
45 3..2 Reserved(0)
46 1..0 Report Type(0:Other, 1:Input, 2:Output, 3:Feature)
47 Payload N Data
48
49
50
51
52Boot Protocol
53=============
543.3.2
55No report descriptor, fixed report descriptors defined.
56
57Device ReportID Size
58---------------------------------
59Reserved 0
60Keyboard 1 9octets
61Mouse 2 4octets
62Reserved 3-255
63
64Report descriptor
65-----------------
66Report ID is added to USB HID boot protocol descriptor.
67Boot Protocol device doesn't need to supply descriptors. and can send extra data on end of boot report this data will be ignored unless host supports report descriptor.
68
69Report Protocol devices can have specific descriptors. Using Boot protocol descriptor followed by extra data may be useful for compatibility to Boot protocol only supported host.
70
71NOTE:
72Bluegiga HID sample say report ID of mouse is 1 but 2?
73Bluegiga HID sample say report ID of consumer page is 2 but 3?
74** mouse.desc and consumer.desc were fixed.
75 size
76keyboard.desc 67 0x43
77mouse.desc 60 0x3c
78consumer.desc 82 0x52
79combo.desc 209 0xd1
80
81
82
83SDP
84===
85attributes(3.3.2)
86----------
87HIDDeviceSubclass
88 which type is supported in Boot Protocol Mode
89 7 6
90 ---
91 0 1 Keyboard
92 1 0 Pointing device
93 1 1 Combo keyboard/pointing device
94
95HIDBootDevice
96 TRUE
97HIDReconnectInitiate
98 TRUE
99
100
101Class of Device/Service
102=======================
103http://phys.sci.hokudai.ac.jp/LABS/yts/pic/GB002/Bluetooth_assigned_numbers_baseband.pdf
104
1050x0005C0 Keyboard and Pointing deivce(combo)
106
107
108 23 16 15 8 7 0
109 ---------------------------------
110 Service |Major |Minor |Format
111
112 Format type
113 1 0
114 ---
115 0 0
116
117 Minor Device Class of Peripheral Major
118 7 6
119 ---
120 0 1 Keyboard
121 1 0 Pointing device
122 1 1 Combo keyboard/pointing device
123
124
125 Major device classes
126 12 11 10 9 8
127 --------------
128 0 0 0 0 0 Miscellaneous
129 0 0 0 0 1 Computer
130 0 0 0 1 0 Phone
131 0 0 0 1 1 LAN /Network Access point
132 0 0 1 0 0 Audio/Video (headset,speaker,stereo, video display, vcr.....
133 0 0 1 0 1 *Peripheral (mouse, joystick, keyboards, ..... )
134 0 0 1 1 0 Imaging (printing, scanner, camera, display, ...)
135 1 1 1 1 1 Uncategorized, specific device code not specified
136 X X X X X All other values reserved
137
138
139 Major service classes
140 bit
141 --------------------------------------
142 13 Limited Discoverable Mode [Ref #1]
143 14 (reserved)
144 15 (reserved)
145 16 Positioning (Location identification)
146 17 Networking (LAN, Ad hoc, ...)
147 18 Rendering (Printing, Speaker, ...)
148 19 Capturing (Scanner, Microphone, ...)
149 20 Object Transfer (v-Inbox, v-Folder, ...)
150 21 Audio (Speaker, Microphone, Headset service, ...)
151 22 Telephony (Cordless telephony, Modem, Headset service, ...)
152 23 Information (WEB-server, WAP-server, ...)
153
154
155
156
157Authentication SSP
158-------------------
159SET BT SSP 2 0 PASS KEY entering
160SET BT SSP 3 0 NO PASS KEY entering
161SET BT SSP <capabilities> <mitm>
162 <capabilities>: 0:display only 1:display+yes/no button 2:keyboard only 3:none
163SET BT SSP 2 1 # 2:keyboard only 1:Man-in-the-middle protection is needed
164SET BT SSP 2 0 # 2:keyboard only 0:Man-in-the-middle protection is not needed
165
166
167SET BT SSP 2 1
168 bond only if MITM protection is supported by host
169SET BT SSP 2 0
170 bond even if MITM protection is not supported by host
171
172On Windows 'Add device' causes SSP PASSKEY event on iWRAP
173 SSP PASSKEY 78:dd:08:b7:e4:a2 ?
174
175If device has display(0 or 1) this event occurs. User should be shown this code on the device.
176 SSP CONFIRM 78:dd:08:b7:e4:a2 517572
177
178
179SET BT SSP 3 0
180 No input/output, No MITM protection.
181 Without procedure of authentication the divice is bond to host.
182
183
184Connect
185=======
186CALL 78:dd:08:b7:e4:a2 11 HID
187
188
189Setting
190========
191Following settings need to be done before wiring into keyboard.
192- UART speed: 38400bps(115200bps didn't work with software serial)
193- No SSP procedure(without MITM protection)
194- No Power Saving
195
196# clear pairing record and set default
197SET BT PAIR *
198SET RESET
199
200SET CONTROL INIT SET CONTROL MUX 0
201SET CONTROL BAUD 38400,8n1
202SET BT NAME TMK Blootooth WT12
203SET BT CLASS 0005c0
204SET BT AUTH * 0000
205SET BT SSP 3 0
206SET CONTROL CONFIG 4800
207SET PROFILE HID 0f c0 0100 00 en 0409 TMK Bluetooth keyboard(WT12)
208SET PROFILE SPP
209
210# power saving?
211SET BT SNIFF 100 20 1 8
212
213
214# Report Descriptor
215# combo keyboard + mouse + consumer
216HID SET d2 05010906a1010507850119e029e715002501750195088102950175088101950575010508850119012905910295017503910395067508150025650507190029658100c005010902a1010901a1008502050919012908150025017501950881020501093009311581257f750895028106093895018106050c0a380295018106c0c0050c0901a1018503050c1500250109e909ea09e209cd19b529b87501950881020a8a010a21020a2a021a23022a27027501950881020a83010a96010a92010a9e010a94010a060209b209b4750195088102c0
217
218
219
220SET PROFILE HID
221---------------
222 SET PROFILE HID 0d c0 100 0 en 0409 HHKB pro Bluetooth keyboard
223 {function bit} uint8
224 {subclass} uint8
225 {version} uint16
226 {country} uint8
227 {BTlang} char[2]
228 {USBlang} uint16
229 {name} string
230
231
232SET BT CLASS
233------------
234 See Class of Device
235 composite device: keyboard and mouse
236 SET BT CLASS 005c0
237
238
239
240
241
242
243----------
244after setting
245----------
246set
247SET BT BDADDR 00:07:80:47:22:14
248SET BT NAME TMK Blootooth WT12
249SET BT CLASS 0005c0
250SET BT AUTH * 0000
251SET BT IDENT BT:47 f000 5.0.1 Bluegiga iWRAP
252SET BT LAP 9e8b33
253SET BT PAGEMODE 4 2000 1
254SET BT PAIR 78:dd:08:b7:e4:a2 9e3d85c91bcae73fef8cc10bec18b42f
255SET BT POWER 3 3 3
256SET BT ROLE 0 f 7d00
257SET BT SNIFF 0 20 1 8
258SET BT SSP 3 0
259SET BT MTU 667
260SET CONTROL BAUD 38400,8n1
261SET CONTROL CD 00 0
262SET CONTROL ECHO 7
263SET CONTROL ESCAPE 43 00 1
264SET CONTROL GAIN 0 5
265SET CONTROL INIT SET CONTROL MUX 0
266SET CONTROL MSC DTE 00 00 00 00 00 00
267SET CONTROL MUX 1
268SET CONTROL PIO 00 00
269SET CONTROL READY 00
270SET PROFILE HID 0f c0 0100 00 en 0409 TMK Bluetooth keyboard(WT12)
271SET
272
273set control config list
274SET CONTROL CONFIG 0000 0000 0000 4900 KLUDGE INTERACTIVE_PIN UART_LATENCY
275
276
277info config
278WRAP THOR AI (5.0.1 build 620)
279Copyright (c) 2003-2012 Bluegiga Technologies Inc.
280Compiled on Oct 1 2012 10:56:21, running on WT12-A module, psr v31
281 BGIO FTP HFP HFP_AG HID HID_CONSUMER_PAGE HSP MAP MDP OTA PBAP PIO=0x00fc SSP SUBRATE TEST VOLUME
282 - BOCK4 version 620 (Oct 1 2012 10:56:03) (max acl/sco 7/1)
283 - Bluetooth version 3.0, Power class 2
284 - Loader 8615, firmware 8825 (56-bit encryption), native execution mode
285 - up 0 days, 01:50, 2 connections (pool 2)
286 - User configuration:
287&028d = 0001
288&0295 = 0000 0005 000b 0000 0003 0000 0000 0000 0000 0000 0000
289&0298 = c053
290&0299 = 0000 0000
291&02a3 = 0030 0030 0030 0030
292&02a4 = 009d 0000
293&02a5 = 0053 0045 0054 0020 0043 004f 004e 0054 0052 004f 004c 0020 004d 0055 0058 0020 0030
294&02a7 = 0000 05c0
295&02a8 = 0800 0000 0000 0000
296&02aa = 0004 2000 0001 0033 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
297&02ac = 0000 0000 002b 0000 0000 0000 0000 0000 0000 0000 0002 0000 0000 0000 0010 0000 0000 0000 0000 029b 0000 0000 0000 0000
298&02ad = 4d54 204b 6c42 6f6f 6f74 746f 2068 5457 3231
299&02b0 = fa65 b0aa 934a 077b a600 d1cc fe58 8dd5
300&02b3 = 0004 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0003 0005 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0005
301&02b7 = 000f 00c0 0100 0000 0065 006e 0409 4d54 204b 6c42 6575 6f74 746f &02bb = 8000
302READY.
303----------
304
305
306
307-----
308After 5.0.1 Firmware update
309Firmware: ai-5.0.1-620-25b.bc4.dfu
310PSR: wt12-a.ai-5.0.1-620-25b.psrf
311-----
312info config
313WRAP THOR AI (5.0.1 build 620)
314Copyright (c) 2003-2012 Bluegiga Technologies Inc.
315Compiled on Oct 1 2012 10:56:21, running on WT12-A module, psr v31
316 BGIO FTP HFP HFP_AG HID HID_CONSUMER_PAGE HSP MAP MDP OTA PBAP PIO=0x00fc SSP SUBRATE TEST VOLUME
317 - BOCK4 version 620 (Oct 1 2012 10:56:03) (max acl/sco 7/1)
318 - Bluetooth version 3.0, Power class 2
319 - Loader 8615, firmware 8825 (56-bit encryption), native execution mode
320 - up 0 days, 00:03, 0 connections (pool 1)
321 - User configuration:
322&0295 = 0000 0005 000b 0000 0003 0000 0000 0000 0000 0000 0000
323&0299 = 0000 0000
324&02aa = 0004 2000 0001 0033 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
325&02ac = 0000 0000 002b 0000 0000 0000 0000 0000 0000 0000 0002 0000 0000 0000 0010 0000 0000 0000 0000 029b 0000 0000 0000 0000
326&02ad = 5457 3231 412d
327&02b0 = fa65 b0aa 934a 077b a600 d1cc fe58 8dd5
328READY.
329
330set
331SET BT BDADDR 00:07:80:47:22:14
332SET BT NAME WT12-A
333SET BT CLASS 001f00
334SET BT IDENT BT:47 f000 5.0.1 Bluegiga iWRAP
335SET BT LAP 9e8b33
336SET BT PAGEMODE 4 2000 1
337SET BT PAIR 78:dd:08:b7:e4:a2 af18f81faa107e6dd068762ef921f48b
338SET BT POWER 3 3 3
339SET BT ROLE 0 f 7d00
340SET BT SNIFF 0 20 1 8
341SET BT SSP 3 0
342SET BT MTU 667
343SET CONTROL BAUD 115200,8n1
344SET CONTROL CD 00 0
345SET CONTROL ECHO 7
346SET CONTROL ESCAPE 43 00 1
347SET CONTROL GAIN 0 5
348SET CONTROL MSC DTE 00 00 00 00 00 00
349SET CONTROL PIO 00 00
350SET CONTROL READY 00
351SET PROFILE SPP Bluetooth Serial Port
352SET
353
354set control config list
355SET CONTROL CONFIG 0000 0000 0000 0100 KLUDGE
356---------
diff --git a/tmk_core/protocol/iwrap/iwrap.c b/tmk_core/protocol/iwrap/iwrap.c
deleted file mode 100644
index 4d0ca5756..000000000
--- a/tmk_core/protocol/iwrap/iwrap.c
+++ /dev/null
@@ -1,420 +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/* host driver for Bulegiga iWRAP */
19/* Bluegiga BT12
20 * Connections
21 * Hardware UART Software UART BlueTooth
22 * PC=====UART=======AVR=====SUART====iWRAP(BT12)-----------PC
23 *
24 * - Hardware UART for Debug Console to communicate iWRAP
25 * - Software UART for iWRAP control to send keyboard/mouse data
26 */
27
28#include <stdint.h>
29#include <string.h>
30#include <avr/interrupt.h>
31#include <util/delay.h>
32#include "keycode.h"
33#include "suart.h"
34#include "uart.h"
35#include "report.h"
36#include "host_driver.h"
37#include "iwrap.h"
38#include "print.h"
39
40/* iWRAP MUX mode utils. 3.10 HID raw mode(iWRAP_HID_Application_Note.pdf) */
41#define MUX_HEADER(LINK, LENGTH) \
42 do { \
43 xmit(0xbf); /* SOF */ \
44 xmit(LINK); /* Link */ \
45 xmit(0x00); /* Flags */ \
46 xmit(LENGTH); /* Length */ \
47 } while (0)
48#define MUX_FOOTER(LINK) xmit(LINK ^ 0xff)
49
50static uint8_t connected = 0;
51// static uint8_t channel = 1;
52
53/* iWRAP buffer */
54#define MUX_BUF_SIZE 64
55static char buf[MUX_BUF_SIZE];
56static uint8_t snd_pos = 0;
57
58#define MUX_RCV_BUF_SIZE 256
59static char rcv_buf[MUX_RCV_BUF_SIZE];
60static uint8_t rcv_head = 0;
61static uint8_t rcv_tail = 0;
62
63/* receive buffer */
64static void rcv_enq(char c) {
65 uint8_t next = (rcv_head + 1) % MUX_RCV_BUF_SIZE;
66 if (next != rcv_tail) {
67 rcv_buf[rcv_head] = c;
68 rcv_head = next;
69 }
70}
71
72static char rcv_deq(void) {
73 char c = 0;
74 if (rcv_head != rcv_tail) {
75 c = rcv_buf[rcv_tail++];
76 rcv_tail %= MUX_RCV_BUF_SIZE;
77 }
78 return c;
79}
80
81/*
82static char rcv_peek(void)
83{
84 if (rcv_head == rcv_tail)
85 return 0;
86 return rcv_buf[rcv_tail];
87}
88*/
89
90static void rcv_clear(void) { rcv_tail = rcv_head = 0; }
91
92/* iWRAP response */
93ISR(PCINT1_vect, ISR_BLOCK) // recv() runs away in case of ISR_NOBLOCK
94{
95 if ((SUART_IN_PIN & (1 << SUART_IN_BIT))) return;
96
97 static volatile uint8_t mux_state = 0xff;
98 static volatile uint8_t mux_link = 0xff;
99 uint8_t c = recv();
100 switch (mux_state) {
101 case 0xff: // SOF
102 if (c == 0xbf) mux_state--;
103 break;
104 case 0xfe: // Link
105 mux_state--;
106 mux_link = c;
107 break;
108 case 0xfd: // Flags
109 mux_state--;
110 break;
111 case 0xfc: // Length
112 mux_state = c;
113 break;
114 case 0x00:
115 mux_state = 0xff;
116 mux_link = 0xff;
117 break;
118 default:
119 if (mux_state--) {
120 uart_putchar(c);
121 rcv_enq(c);
122 }
123 }
124}
125
126/*------------------------------------------------------------------*
127 * iWRAP communication
128 *------------------------------------------------------------------*/
129void iwrap_init(void) {
130 // reset iWRAP if in already MUX mode after AVR software-reset
131 iwrap_send("RESET");
132 iwrap_mux_send("RESET");
133 _delay_ms(3000);
134 iwrap_send("\r\nSET CONTROL MUX 1\r\n");
135 _delay_ms(500);
136 iwrap_check_connection();
137}
138
139void iwrap_mux_send(const char *s) {
140 rcv_clear();
141 MUX_HEADER(0xff, strlen((char *)s));
142 iwrap_send(s);
143 MUX_FOOTER(0xff);
144}
145
146void iwrap_send(const char *s) {
147 while (*s) xmit(*s++);
148}
149
150/* send buffer */
151void iwrap_buf_add(uint8_t c) {
152 // need space for '\0'
153 if (snd_pos < MUX_BUF_SIZE - 1) buf[snd_pos++] = c;
154}
155
156void iwrap_buf_del(void) {
157 if (snd_pos) snd_pos--;
158}
159
160void iwrap_buf_send(void) {
161 buf[snd_pos] = '\0';
162 snd_pos = 0;
163 iwrap_mux_send(buf);
164}
165
166void iwrap_call(void) {
167 char *p;
168
169 iwrap_mux_send("SET BT PAIR");
170 _delay_ms(500);
171
172 p = rcv_buf + rcv_tail;
173 while (!strncmp(p, "SET BT PAIR", 11)) {
174 p += 7;
175 strncpy(p, "CALL", 4);
176 strncpy(p + 22, " 11 HID\n\0", 9);
177 print_S(p);
178 iwrap_mux_send(p);
179 // TODO: skip to next line
180 p += 57;
181
182 DEBUG_LED_CONFIG;
183 DEBUG_LED_ON;
184 _delay_ms(500);
185 DEBUG_LED_OFF;
186 _delay_ms(500);
187 DEBUG_LED_ON;
188 _delay_ms(500);
189 DEBUG_LED_OFF;
190 _delay_ms(500);
191 DEBUG_LED_ON;
192 _delay_ms(500);
193 DEBUG_LED_OFF;
194 _delay_ms(500);
195 DEBUG_LED_ON;
196 _delay_ms(500);
197 DEBUG_LED_OFF;
198 _delay_ms(500);
199 DEBUG_LED_ON;
200 _delay_ms(500);
201 DEBUG_LED_OFF;
202 _delay_ms(500);
203 }
204 iwrap_check_connection();
205}
206
207void iwrap_kill(void) {
208 char c;
209 iwrap_mux_send("LIST");
210 _delay_ms(500);
211
212 while ((c = rcv_deq()) && c != '\n')
213 ;
214 if (strncmp(rcv_buf + rcv_tail, "LIST ", 5)) {
215 print("no connection to kill.\n");
216 return;
217 }
218 // skip 10 'space' chars
219 for (uint8_t i = 10; i; i--)
220 while ((c = rcv_deq()) && c != ' ')
221 ;
222
223 char *p = rcv_buf + rcv_tail - 5;
224 strncpy(p, "KILL ", 5);
225 strncpy(p + 22, "\n\0", 2);
226 print_S(p);
227 iwrap_mux_send(p);
228 _delay_ms(500);
229
230 iwrap_check_connection();
231}
232
233void iwrap_unpair(void) {
234 iwrap_mux_send("SET BT PAIR");
235 _delay_ms(500);
236
237 char *p = rcv_buf + rcv_tail;
238 if (!strncmp(p, "SET BT PAIR", 11)) {
239 strncpy(p + 29, "\n\0", 2);
240 print_S(p);
241 iwrap_mux_send(p);
242 }
243}
244
245void iwrap_sleep(void) { iwrap_mux_send("SLEEP"); }
246
247void iwrap_sniff(void) {}
248
249void iwrap_subrate(void) {}
250
251bool iwrap_failed(void) {
252 if (strncmp(rcv_buf, "SYNTAX ERROR", 12))
253 return true;
254 else
255 return false;
256}
257
258uint8_t iwrap_connected(void) { return connected; }
259
260uint8_t iwrap_check_connection(void) {
261 iwrap_mux_send("LIST");
262 _delay_ms(100);
263
264 if (strncmp(rcv_buf, "LIST ", 5) || !strncmp(rcv_buf, "LIST 0", 6))
265 connected = 0;
266 else
267 connected = 1;
268 return connected;
269}
270
271/*------------------------------------------------------------------*
272 * Host driver
273 *------------------------------------------------------------------*/
274static uint8_t keyboard_leds(void);
275static void send_keyboard(report_keyboard_t *report);
276static void send_mouse(report_mouse_t *report);
277static void send_system(uint16_t data);
278static void send_consumer(uint16_t data);
279
280static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_system, send_consumer};
281
282host_driver_t *iwrap_driver(void) { return &driver; }
283
284static uint8_t keyboard_leds(void) { return 0; }
285
286static void send_keyboard(report_keyboard_t *report) {
287 if (!iwrap_connected() && !iwrap_check_connection()) return;
288 MUX_HEADER(0x01, 0x0c);
289 // HID raw mode header
290 xmit(0x9f);
291 xmit(0x0a); // Length
292 xmit(0xa1); // DATA(Input)
293 xmit(0x01); // Report ID
294 xmit(report->mods);
295 xmit(0x00); // reserved byte(always 0)
296 xmit(report->keys[0]);
297 xmit(report->keys[1]);
298 xmit(report->keys[2]);
299 xmit(report->keys[3]);
300 xmit(report->keys[4]);
301 xmit(report->keys[5]);
302 MUX_FOOTER(0x01);
303}
304
305static void send_mouse(report_mouse_t *report) {
306#if defined(MOUSEKEY_ENABLE) || defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
307 if (!iwrap_connected() && !iwrap_check_connection()) return;
308 MUX_HEADER(0x01, 0x09);
309 // HID raw mode header
310 xmit(0x9f);
311 xmit(0x07); // Length
312 xmit(0xa1); // DATA(Input)
313 xmit(0x02); // Report ID
314 xmit(report->buttons);
315 xmit(report->x);
316 xmit(report->y);
317 xmit(report->v);
318 xmit(report->h);
319 MUX_FOOTER(0x01);
320#endif
321}
322
323static void send_system(uint16_t data) { /* not supported */
324}
325
326static void send_consumer(uint16_t data) {
327#ifdef EXTRAKEY_ENABLE
328 static uint16_t last_data = 0;
329 uint8_t bits1 = 0;
330 uint8_t bits2 = 0;
331 uint8_t bits3 = 0;
332
333 if (!iwrap_connected() && !iwrap_check_connection()) return;
334 if (data == last_data) return;
335 last_data = data;
336
337 // 3.10 HID raw mode(iWRAP_HID_Application_Note.pdf)
338 switch (data) {
339 case AUDIO_VOL_UP:
340 bits1 = 0x01;
341 break;
342 case AUDIO_VOL_DOWN:
343 bits1 = 0x02;
344 break;
345 case AUDIO_MUTE:
346 bits1 = 0x04;
347 break;
348 case TRANSPORT_PLAY_PAUSE:
349 bits1 = 0x08;
350 break;
351 case TRANSPORT_NEXT_TRACK:
352 bits1 = 0x10;
353 break;
354 case TRANSPORT_PREV_TRACK:
355 bits1 = 0x20;
356 break;
357 case TRANSPORT_STOP:
358 bits1 = 0x40;
359 break;
360 case TRANSPORT_EJECT:
361 bits1 = 0x80;
362 break;
363 case AL_EMAIL:
364 bits2 = 0x01;
365 break;
366 case AC_SEARCH:
367 bits2 = 0x02;
368 break;
369 case AC_BOOKMARKS:
370 bits2 = 0x04;
371 break;
372 case AC_HOME:
373 bits2 = 0x08;
374 break;
375 case AC_BACK:
376 bits2 = 0x10;
377 break;
378 case AC_FORWARD:
379 bits2 = 0x20;
380 break;
381 case AC_STOP:
382 bits2 = 0x40;
383 break;
384 case AC_REFRESH:
385 bits2 = 0x80;
386 break;
387 case AL_CC_CONFIG:
388 bits3 = 0x01;
389 break;
390 case AL_CALCULATOR:
391 bits3 = 0x04;
392 break;
393 case AL_LOCK:
394 bits3 = 0x08;
395 break;
396 case AL_LOCAL_BROWSER:
397 bits3 = 0x10;
398 break;
399 case AC_MINIMIZE:
400 bits3 = 0x20;
401 break;
402 case TRANSPORT_RECORD:
403 bits3 = 0x40;
404 break;
405 case TRANSPORT_REWIND:
406 bits3 = 0x80;
407 break;
408 }
409
410 MUX_HEADER(0x01, 0x07);
411 xmit(0x9f);
412 xmit(0x05); // Length
413 xmit(0xa1); // DATA(Input)
414 xmit(0x03); // Report ID
415 xmit(bits1);
416 xmit(bits2);
417 xmit(bits3);
418 MUX_FOOTER(0x01);
419#endif
420}
diff --git a/tmk_core/protocol/iwrap/iwrap.h b/tmk_core/protocol/iwrap/iwrap.h
deleted file mode 100644
index 51f2b5670..000000000
--- a/tmk_core/protocol/iwrap/iwrap.h
+++ /dev/null
@@ -1,47 +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 IWRAP_H
19#define IWRAP_H
20
21#include <stdint.h>
22#include <stdbool.h>
23#include "host_driver.h"
24
25/* enable iWRAP MUX mode */
26#define MUX_MODE
27
28host_driver_t *iwrap_driver(void);
29
30void iwrap_init(void);
31void iwrap_send(const char *s);
32void iwrap_mux_send(const char *s);
33void iwrap_buf_send(void);
34void iwrap_buf_add(uint8_t c);
35void iwrap_buf_del(void);
36
37void iwrap_call(void);
38void iwrap_kill(void);
39void iwrap_unpair(void);
40void iwrap_sleep(void);
41void iwrap_sniff(void);
42void iwrap_subrate(void);
43bool iwrap_failed(void);
44uint8_t iwrap_connected(void);
45uint8_t iwrap_check_connection(void);
46
47#endif
diff --git a/tmk_core/protocol/iwrap/main.c b/tmk_core/protocol/iwrap/main.c
deleted file mode 100644
index 4048a9791..000000000
--- a/tmk_core/protocol/iwrap/main.c
+++ /dev/null
@@ -1,412 +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#include <stdint.h>
18#include <avr/interrupt.h>
19#include <avr/io.h>
20//#include <avr/wdt.h>
21#include "wd.h" // in order to use watchdog in interrupt mode
22#include <avr/sleep.h>
23#include <util/delay.h>
24#include <avr/power.h>
25#include "keyboard.h"
26#include "matrix.h"
27#include "host.h"
28#include "action.h"
29#include "iwrap.h"
30#ifdef PROTOCOL_VUSB
31# include "vusb.h"
32# include <usbdrv/usbdrv.h>
33#endif
34#include "uart.h"
35#include "suart.h"
36#include "timer.h"
37#include "debug.h"
38#include "keycode.h"
39#include "command.h"
40
41static void sleep(uint8_t term);
42static bool console(void);
43static bool console_command(uint8_t c);
44static uint8_t key2asc(uint8_t key);
45
46/*
47static void set_prr(void)
48{
49 power_adc_disable();
50 power_spi_disable();
51 power_twi_disable();
52#ifndef TIMER_H
53 //power_timer0_disable(); // used in timer.c
54#endif
55 power_timer1_disable();
56 power_timer2_disable();
57}
58*/
59
60/*
61static void pullup_pins(void)
62{
63 // DDRs are set to 0(input) by default.
64#ifdef PORTA
65 PORTA = 0xFF;
66#endif
67 PORTB = 0xFF;
68 PORTC = 0xFF;
69 PORTD = 0xFF;
70#ifdef PORTE
71 PORTE = 0xFF;
72#endif
73#ifdef PORTE
74 PORTF = 0xFF;
75#endif
76}
77*/
78
79#ifdef PROTOCOL_VUSB
80static void disable_vusb(void) {
81 // disable interrupt & disconnect to prevent host from enumerating
82 USB_INTR_ENABLE &= ~(1 << USB_INTR_ENABLE_BIT);
83 usbDeviceDisconnect();
84}
85
86static void enable_vusb(void) {
87 USB_INTR_ENABLE |= (1 << USB_INTR_ENABLE_BIT);
88 usbDeviceConnect();
89}
90
91static void init_vusb(void) {
92 uint8_t i = 0;
93
94 usbInit();
95 disable_vusb();
96 /* fake USB disconnect for > 250 ms */
97 while (--i) {
98 _delay_ms(1);
99 }
100 enable_vusb();
101}
102#endif
103
104void change_driver(host_driver_t *driver) {
105 /*
106 host_clear_keyboard_report();
107 host_swap_keyboard_report();
108 host_clear_keyboard_report();
109 host_send_keyboard_report();
110 */
111 clear_keyboard();
112 _delay_ms(1000);
113 host_set_driver(driver);
114}
115
116static bool sleeping = false;
117static bool insomniac = false; // TODO: should be false for power saving
118static uint16_t last_timer = 0;
119
120int main(void) {
121 MCUSR = 0;
122 clock_prescale_set(clock_div_1);
123 WD_SET(WD_OFF);
124
125 // power saving: the result is worse than nothing... why?
126 // pullup_pins();
127 // set_prr();
128
129#ifdef PROTOCOL_VUSB
130 disable_vusb();
131#endif
132 uart_init(115200);
133 keyboard_init();
134 print("\nSend BREAK for UART Console Commands.\n");
135
136 // TODO: move to iWRAP/suart file
137 print("suart init\n");
138 // suart init
139 // PC4: Tx Output IDLE(Hi)
140 PORTC |= (1 << 4);
141 DDRC |= (1 << 4);
142 // PC5: Rx Input(pull-up)
143 PORTC |= (1 << 5);
144 DDRC &= ~(1 << 5);
145 // suart receive interrut(PC5/PCINT13)
146 PCMSK1 = 0b00100000;
147 PCICR = 0b00000010;
148
149 host_set_driver(iwrap_driver());
150
151 print("iwrap_init()\n");
152 iwrap_init();
153 iwrap_call();
154
155 last_timer = timer_read();
156 while (true) {
157#ifdef PROTOCOL_VUSB
158 if (host_get_driver() == vusb_driver()) usbPoll();
159#endif
160 keyboard_task();
161#ifdef PROTOCOL_VUSB
162 if (host_get_driver() == vusb_driver()) vusb_transfer_keyboard();
163#endif
164 // TODO: depricated
165 if (matrix_is_modified() || console()) {
166 last_timer = timer_read();
167 sleeping = false;
168 } else if (!sleeping && timer_elapsed(last_timer) > 4000) {
169 sleeping = true;
170 iwrap_check_connection();
171 }
172
173 // TODO: suspend.h
174 if (host_get_driver() == iwrap_driver()) {
175 if (sleeping && !insomniac) {
176 _delay_ms(1); // wait for UART to send
177 iwrap_sleep();
178 sleep(WDTO_60MS);
179 }
180 }
181 }
182}
183
184static void sleep(uint8_t term) {
185 WD_SET(WD_IRQ, term);
186
187 cli();
188 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
189 sleep_enable();
190 sleep_bod_disable();
191 sei();
192 sleep_cpu();
193 sleep_disable();
194
195 WD_SET(WD_OFF);
196}
197
198static bool console(void) {
199 // Send to Bluetoot module WT12
200 static bool breaked = false;
201 if (!uart_available())
202 return false;
203 else {
204 uint8_t c;
205 c = uart_getchar();
206 uart_putchar(c);
207 switch (c) {
208 case 0x00: // BREAK signal
209 if (!breaked) {
210 print("break(? for help): ");
211 breaked = true;
212 }
213 break;
214 case '\r':
215 uart_putchar('\n');
216 iwrap_buf_send();
217 break;
218 case '\b':
219 iwrap_buf_del();
220 break;
221 default:
222 if (breaked) {
223 print("\n");
224 console_command(c);
225 breaked = false;
226 } else {
227 iwrap_buf_add(c);
228 }
229 break;
230 }
231 return true;
232 }
233}
234
235bool command_extra(uint8_t code) { return console_command(key2asc(code)); }
236
237static bool console_command(uint8_t c) {
238 switch (c) {
239 case 'h':
240 case '?':
241 print("\nCommands for Bluetooth(WT12/iWRAP):\n");
242 print("r: reset. software reset by watchdog\n");
243 print("i: insomniac. prevent KB from sleeping\n");
244 print("c: iwrap_call. CALL for BT connection.\n");
245#ifdef PROTOCOL_VUSB
246 print("u: USB mode. switch to USB.\n");
247 print("w: BT mode. switch to Bluetooth.\n");
248#endif
249 print("k: kill first connection.\n");
250 print("Del: unpair first pairing.\n");
251 print("\n");
252 return 0;
253 case 'r':
254 print("reset\n");
255 WD_AVR_RESET();
256 return 1;
257 case 'i':
258 insomniac = !insomniac;
259 if (insomniac)
260 print("insomniac\n");
261 else
262 print("not insomniac\n");
263 return 1;
264 case 'c':
265 print("iwrap_call()\n");
266 iwrap_call();
267 return 1;
268#ifdef PROTOCOL_VUSB
269 case 'u':
270 print("USB mode\n");
271 init_vusb();
272 change_driver(vusb_driver());
273 // iwrap_kill();
274 // iwrap_sleep();
275 // disable suart receive interrut(PC5/PCINT13)
276 PCMSK1 &= ~(0b00100000);
277 PCICR &= ~(0b00000010);
278 return 1;
279 case 'w':
280 print("iWRAP mode\n");
281 change_driver(iwrap_driver());
282 disable_vusb();
283 // enable suart receive interrut(PC5/PCINT13)
284 PCMSK1 |= 0b00100000;
285 PCICR |= 0b00000010;
286 return 1;
287#endif
288 case 'k':
289 print("kill\n");
290 iwrap_kill();
291 return 1;
292 case 0x7F: // DELETE
293 print("unpair\n");
294 iwrap_unpair();
295 return 1;
296 }
297 return 0;
298}
299
300// convert keycode into ascii charactor
301static uint8_t key2asc(uint8_t key) {
302 switch (key) {
303 case KC_A:
304 return 'a';
305 case KC_B:
306 return 'b';
307 case KC_C:
308 return 'c';
309 case KC_D:
310 return 'd';
311 case KC_E:
312 return 'e';
313 case KC_F:
314 return 'f';
315 case KC_G:
316 return 'g';
317 case KC_H:
318 return 'h';
319 case KC_I:
320 return 'i';
321 case KC_J:
322 return 'j';
323 case KC_K:
324 return 'k';
325 case KC_L:
326 return 'l';
327 case KC_M:
328 return 'm';
329 case KC_N:
330 return 'n';
331 case KC_O:
332 return 'o';
333 case KC_P:
334 return 'p';
335 case KC_Q:
336 return 'q';
337 case KC_R:
338 return 'r';
339 case KC_S:
340 return 's';
341 case KC_T:
342 return 't';
343 case KC_U:
344 return 'u';
345 case KC_V:
346 return 'v';
347 case KC_W:
348 return 'w';
349 case KC_X:
350 return 'x';
351 case KC_Y:
352 return 'y';
353 case KC_Z:
354 return 'z';
355 case KC_1:
356 return '1';
357 case KC_2:
358 return '2';
359 case KC_3:
360 return '3';
361 case KC_4:
362 return '4';
363 case KC_5:
364 return '5';
365 case KC_6:
366 return '6';
367 case KC_7:
368 return '7';
369 case KC_8:
370 return '8';
371 case KC_9:
372 return '9';
373 case KC_0:
374 return '0';
375 case KC_ENTER:
376 return '\n';
377 case KC_ESCAPE:
378 return 0x1B;
379 case KC_BSPACE:
380 return '\b';
381 case KC_TAB:
382 return '\t';
383 case KC_SPACE:
384 return ' ';
385 case KC_MINUS:
386 return '-';
387 case KC_EQUAL:
388 return '=';
389 case KC_LBRACKET:
390 return '[';
391 case KC_RBRACKET:
392 return ']';
393 case KC_BSLASH:
394 return '\\';
395 case KC_NONUS_HASH:
396 return '#';
397 case KC_SCOLON:
398 return ';';
399 case KC_QUOTE:
400 return '\'';
401 case KC_GRAVE:
402 return '`';
403 case KC_COMMA:
404 return ',';
405 case KC_DOT:
406 return '.';
407 case KC_SLASH:
408 return '/';
409 default:
410 return 0x00;
411 }
412}
diff --git a/tmk_core/protocol/iwrap/mux_exit.rb b/tmk_core/protocol/iwrap/mux_exit.rb
deleted file mode 100644
index 1f6be48af..000000000
--- a/tmk_core/protocol/iwrap/mux_exit.rb
+++ /dev/null
@@ -1,7 +0,0 @@
1#
2# Rescue from Bluegiga iWRAP MUX mode
3# 6.75 of iWRAP5_User_Guid.pdf
4#
5[0xBF, 0xFF, 0x00, 0x11, 0x53, 0x45, 0x54, 0x20, 0x43, 0x4f, 0x4e, 0x54, 0x52, 0x4f, 0x4c, 0x20, 0x4d, 0x55, 0x58, 0x20, 0x30, 0x00].each do |x|
6 print x.chr
7end
diff --git a/tmk_core/protocol/iwrap/suart.S b/tmk_core/protocol/iwrap/suart.S
deleted file mode 100644
index a873515e1..000000000
--- a/tmk_core/protocol/iwrap/suart.S
+++ /dev/null
@@ -1,156 +0,0 @@
1;---------------------------------------------------------------------------;
2; Software implemented UART module ;
3; (C)ChaN, 2005 (http://elm-chan.org/) ;
4;---------------------------------------------------------------------------;
5; Bit rate settings:
6;
7; 1MHz 2MHz 4MHz 6MHz 8MHz 10MHz 12MHz 16MHz 20MHz
8; 2.4kbps 138 - - - - - - - -
9; 4.8kbps 68 138 - - - - - - -
10; 9.6kbps 33 68 138 208 - - - - -
11; 19.2kbps - 33 68 102 138 173 208 - -
12; 38.4kbps - - 33 50 68 85 102 138 172
13; 57.6kbps - - 21 33 44 56 68 91 114
14; 115.2kbps - - - - 21 27 33 44 56
15
16.nolist
17#include <avr/io.h>
18.list
19
20#define BPS 102 /* Bit delay. (see above table) */
21#define BIDIR 0 /* 0:Separated Tx/Rx, 1:Shared Tx/Rx */
22
23#define OUT_1 sbi _SFR_IO_ADDR(SUART_OUT_PORT), SUART_OUT_BIT /* Output 1 */
24#define OUT_0 cbi _SFR_IO_ADDR(SUART_OUT_PORT), SUART_OUT_BIT /* Output 0 */
25#define SKIP_IN_1 sbis _SFR_IO_ADDR(SUART_IN_PIN), SUART_IN_BIT /* Skip if 1 */
26#define SKIP_IN_0 sbic _SFR_IO_ADDR(SUART_IN_PIN), SUART_IN_BIT /* Skip if 0 */
27
28
29
30#ifdef SPM_PAGESIZE
31.macro _LPMI reg
32 lpm \reg, Z+
33.endm
34.macro _MOVW dh,dl, sh,sl
35 movw \dl, \sl
36.endm
37#else
38.macro _LPMI reg
39 lpm
40 mov \reg, r0
41 adiw ZL, 1
42.endm
43.macro _MOVW dh,dl, sh,sl
44 mov \dl, \sl
45 mov \dh, \sh
46.endm
47#endif
48
49
50
51;---------------------------------------------------------------------------;
52; Transmit a byte in serial format of N81
53;
54;Prototype: void xmit (uint8_t data);
55;Size: 16 words
56
57.global xmit
58.func xmit
59xmit:
60#if BIDIR
61 ldi r23, BPS-1 ;Pre-idle time for bidirectional data line
625: dec r23 ;
63 brne 5b ;/
64#endif
65 in r0, _SFR_IO_ADDR(SREG) ;Save flags
66
67 com r24 ;C = start bit
68 ldi r25, 10 ;Bit counter
69 cli ;Start critical section
70
711: ldi r23, BPS-1 ;----- Bit transferring loop
722: dec r23 ;Wait for a bit time
73 brne 2b ;/
74 brcs 3f ;MISO = bit to be sent
75 OUT_1 ;
763: brcc 4f ;
77 OUT_0 ;/
784: lsr r24 ;Get next bit into C
79 dec r25 ;All bits sent?
80 brne 1b ; no, coutinue
81
82 out _SFR_IO_ADDR(SREG), r0 ;End of critical section
83 ret
84.endfunc
85
86
87
88;---------------------------------------------------------------------------;
89; Receive a byte
90;
91;Prototype: uint8_t rcvr (void);
92;Size: 19 words
93
94.global rcvr
95.func rcvr
96rcvr:
97 in r0, _SFR_IO_ADDR(SREG) ;Save flags
98
99 ldi r24, 0x80 ;Receiving shift reg
100 cli ;Start critical section
101
1021: SKIP_IN_1 ;Wait for idle
103 rjmp 1b
1042: SKIP_IN_0 ;Wait for start bit
105 rjmp 2b
106 ldi r25, BPS/2 ;Wait for half bit time
1073: dec r25
108 brne 3b
109
1104: ldi r25, BPS ;----- Bit receiving loop
1115: dec r25 ;Wait for a bit time
112 brne 5b ;/
113 lsr r24 ;Next bit
114 SKIP_IN_0 ;Get a data bit into r24.7
115 ori r24, 0x80
116 brcc 4b ;All bits received? no, continue
117
118 out _SFR_IO_ADDR(SREG), r0 ;End of critical section
119 ret
120.endfunc
121
122
123; Not wait for start bit. This should be called after detecting start bit.
124.global recv
125.func recv
126recv:
127 in r0, _SFR_IO_ADDR(SREG) ;Save flags
128
129 ldi r24, 0x80 ;Receiving shift reg
130 cli ;Start critical section
131
132;1: SKIP_IN_1 ;Wait for idle
133; rjmp 1b
134;2: SKIP_IN_0 ;Wait for start bit
135; rjmp 2b
136 ldi r25, BPS/2 ;Wait for half bit time
1373: dec r25
138 brne 3b
139
1404: ldi r25, BPS ;----- Bit receiving loop
1415: dec r25 ;Wait for a bit time
142 brne 5b ;/
143 lsr r24 ;Next bit
144 SKIP_IN_0 ;Get a data bit into r24.7
145 ori r24, 0x80
146 brcc 4b ;All bits received? no, continue
147
148 ldi r25, BPS/2 ;Wait for half bit time
1496: dec r25
150 brne 6b
1517: SKIP_IN_1 ;Wait for stop bit
152 rjmp 7b
153
154 out _SFR_IO_ADDR(SREG), r0 ;End of critical section
155 ret
156.endfunc
diff --git a/tmk_core/protocol/iwrap/suart.h b/tmk_core/protocol/iwrap/suart.h
deleted file mode 100644
index c634bbc2f..000000000
--- a/tmk_core/protocol/iwrap/suart.h
+++ /dev/null
@@ -1,8 +0,0 @@
1#ifndef SUART
2#define SUART
3
4void xmit(uint8_t);
5uint8_t rcvr(void);
6uint8_t recv(void);
7
8#endif /* SUART */
diff --git a/tmk_core/protocol/iwrap/wd.h b/tmk_core/protocol/iwrap/wd.h
deleted file mode 100644
index 083d6d44d..000000000
--- a/tmk_core/protocol/iwrap/wd.h
+++ /dev/null
@@ -1,161 +0,0 @@
1/* This is from http://www.mtcnet.net/~henryvm/wdt/ */
2#ifndef _AVR_WD_H_
3#define _AVR_WD_H_
4
5#include <avr/io.h>
6
7/*
8Copyright (c) 2009, Curt Van Maanen
9
10Permission to use, copy, modify, and/or distribute this software for any
11purpose with or without fee is hereby granted, provided that the above
12copyright notice and this permission notice appear in all copies.
13
14THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21
22
23include usage-
24 #include "wd.h" //if in same directory as project
25 #include <avr/wd.h> //if wd.h is in avr directory
26
27set watchdog modes and prescale
28
29usage-
30 WD_SET(mode,[timeout]); //prescale always set
31
32modes-
33 WD_OFF disabled
34 WD_RST normal reset mode
35 WD_IRQ interrupt only mode (if supported)
36 WD_RST_IRQ interrupt+reset mode (if supported)
37
38timeout-
39 WDTO_15MS default if no timeout provided
40 WDTO_30MS
41 WDTO_60MS
42 WDTO_120MS
43 WDTO_250MS
44 WDTO_500MS
45 WDTO_1S
46 WDTO_2S
47 WDTO_4S (if supported)
48 WDTO_8S (if supported)
49
50examples-
51 WD_SET(WD_RST,WDTO_1S); //reset mode, 1s timeout
52 WD_SET(WD_OFF); //watchdog disabled (if not fused on)
53 WD_SET(WD_RST); //reset mode, 15ms (default timeout)
54 WD_SET(WD_IRQ,WDTO_120MS); //interrupt only mode, 120ms timeout
55 WD_SET(WD_RST_IRQ,WDTO_2S); //interrupt+reset mode, 2S timeout
56
57
58for enhanced watchdogs, if the watchdog is not being used WDRF should be
59cleared on every power up or reset, along with disabling the watchdog-
60 WD_DISABLE(); //clear WDRF, then turn off watchdog
61
62*/
63
64// reset registers to the same name (MCUCSR)
65#if !defined(MCUCSR)
66# define MCUCSR MCUSR
67#endif
68
69// watchdog registers to the same name (WDTCSR)
70#if !defined(WDTCSR)
71# define WDTCSR WDTCR
72#endif
73
74// if enhanced watchdog, define irq values, create disable macro
75#if defined(WDIF)
76# define WD_IRQ 0xC0
77# define WD_RST_IRQ 0xC8
78# define WD_DISABLE() \
79 do { \
80 MCUCSR &= ~(1 << WDRF); \
81 WD_SET(WD_OFF); \
82 } while (0)
83#endif
84
85// all watchdogs
86#define WD_RST 8
87#define WD_OFF 0
88
89// prescale values
90#define WDTO_15MS 0
91#define WDTO_30MS 1
92#define WDTO_60MS 2
93#define WDTO_120MS 3
94#define WDTO_250MS 4
95#define WDTO_500MS 5
96#define WDTO_1S 6
97#define WDTO_2S 7
98
99// prescale values for avrs with WDP3
100#if defined(WDP3)
101# define WDTO_4S 0x20
102# define WDTO_8S 0x21
103#endif
104
105// watchdog reset
106#define WDR() __asm__ __volatile__("wdr")
107
108// avr reset using watchdog
109#define WD_AVR_RESET() \
110 do { \
111 __asm__ __volatile__("cli"); \
112 WD_SET_UNSAFE(WD_RST); \
113 while (1) \
114 ; \
115 } while (0)
116
117/*set the watchdog-
1181. save SREG
1192. turn off irq's
1203. reset watchdog timer
1214. enable watchdog change
1225. write watchdog value
1236. restore SREG (restoring irq status)
124*/
125#define WD_SET(val, ...) \
126 __asm__ __volatile__("in __tmp_reg__,__SREG__" \
127 "\n\t" \
128 "cli" \
129 "\n\t" \
130 "wdr" \
131 "\n\t" \
132 "sts %[wdreg],%[wden]" \
133 "\n\t" \
134 "sts %[wdreg],%[wdval]" \
135 "\n\t" \
136 "out __SREG__,__tmp_reg__" \
137 "\n\t" \
138 : \
139 : [ wdreg ] "M"(&WDTCSR), [ wden ] "r"((uint8_t)(0x18)), [ wdval ] "r"((uint8_t)(val | (__VA_ARGS__ + 0))) \
140 : "r0")
141
142/*set the watchdog when I bit in SREG known to be clear-
1431. reset watchdog timer
1442. enable watchdog change
1455. write watchdog value
146*/
147#define WD_SET_UNSAFE(val, ...) \
148 __asm__ __volatile__("wdr" \
149 "\n\t" \
150 "sts %[wdreg],%[wden]" \
151 "\n\t" \
152 "sts %[wdreg],%[wdval]" \
153 "\n\t" \
154 : \
155 : [ wdreg ] "M"(&WDTCSR), [ wden ] "r"((uint8_t)(0x18)), [ wdval ] "r"((uint8_t)(val | (__VA_ARGS__ + 0))))
156
157// for compatibility with avr/wdt.h
158#define wdt_enable(val) WD_SET(WD_RST, val)
159#define wdt_disable() WD_SET(WD_OFF)
160
161#endif /* _AVR_WD_H_ */
diff --git a/tmk_core/protocol/lufa.mk b/tmk_core/protocol/lufa.mk
index d87802992..1cc1fa04e 100644
--- a/tmk_core/protocol/lufa.mk
+++ b/tmk_core/protocol/lufa.mk
@@ -15,33 +15,28 @@ else
15endif 15endif
16 16
17LUFA_SRC = lufa.c \ 17LUFA_SRC = lufa.c \
18 usb_descriptor.c \ 18 usb_descriptor.c \
19 outputselect.c \ 19 $(LUFA_SRC_USB)
20 $(LUFA_SRC_USB)
21 20
22ifeq ($(strip $(MIDI_ENABLE)), yes) 21ifeq ($(strip $(MIDI_ENABLE)), yes)
23 include $(TMK_PATH)/protocol/midi.mk 22 include $(TMK_PATH)/protocol/midi.mk
24endif 23endif
25 24
26ifeq ($(strip $(BLUETOOTH_ENABLE)), yes) 25ifeq ($(strip $(BLUETOOTH_ENABLE)), yes)
27 LUFA_SRC += $(LUFA_DIR)/bluetooth.c \ 26 LUFA_SRC += outputselect.c \
28 $(TMK_DIR)/protocol/serial_uart.c 27 $(TMK_DIR)/protocol/serial_uart.c
29endif 28endif
30 29
31ifeq ($(strip $(BLUETOOTH)), AdafruitBLE) 30ifeq ($(strip $(BLUETOOTH)), AdafruitBLE)
32 LUFA_SRC += spi_master.c 31 LUFA_SRC += spi_master.c \
33 LUFA_SRC += analog.c 32 analog.c \
34 LUFA_SRC += $(LUFA_DIR)/adafruit_ble.cpp 33 outputselect.c \
35endif 34 $(LUFA_DIR)/adafruit_ble.cpp
36
37ifeq ($(strip $(BLUETOOTH)), AdafruitEZKey)
38 LUFA_SRC += $(LUFA_DIR)/bluetooth.c \
39 $(TMK_DIR)/protocol/serial_uart.c
40endif 35endif
41 36
42ifeq ($(strip $(BLUETOOTH)), RN42) 37ifeq ($(strip $(BLUETOOTH)), RN42)
43 LUFA_SRC += $(LUFA_DIR)/bluetooth.c \ 38 LUFA_SRC += outputselect.c \
44 $(TMK_DIR)/protocol/serial_uart.c 39 $(TMK_DIR)/protocol/serial_uart.c
45endif 40endif
46 41
47ifeq ($(strip $(VIRTSER_ENABLE)), yes) 42ifeq ($(strip $(VIRTSER_ENABLE)), yes)
diff --git a/tmk_core/protocol/lufa/adafruit_ble.cpp b/tmk_core/protocol/lufa/adafruit_ble.cpp
index b07407f38..79b35fca3 100644
--- a/tmk_core/protocol/lufa/adafruit_ble.cpp
+++ b/tmk_core/protocol/lufa/adafruit_ble.cpp
@@ -38,7 +38,7 @@
38 38
39#ifdef SAMPLE_BATTERY 39#ifdef SAMPLE_BATTERY
40# ifndef BATTERY_LEVEL_PIN 40# ifndef BATTERY_LEVEL_PIN
41# define BATTERY_LEVEL_PIN 7 41# define BATTERY_LEVEL_PIN B5
42# endif 42# endif
43#endif 43#endif
44 44
@@ -556,7 +556,7 @@ void adafruit_ble_task(void) {
556 if (timer_elapsed(state.last_battery_update) > BatteryUpdateInterval && resp_buf.empty()) { 556 if (timer_elapsed(state.last_battery_update) > BatteryUpdateInterval && resp_buf.empty()) {
557 state.last_battery_update = timer_read(); 557 state.last_battery_update = timer_read();
558 558
559 state.vbat = analogRead(BATTERY_LEVEL_PIN); 559 state.vbat = analogReadPin(BATTERY_LEVEL_PIN);
560 } 560 }
561#endif 561#endif
562} 562}
diff --git a/tmk_core/protocol/lufa/adafruit_ble.h b/tmk_core/protocol/lufa/adafruit_ble.h
index cef46fe9f..9dfc9b435 100644
--- a/tmk_core/protocol/lufa/adafruit_ble.h
+++ b/tmk_core/protocol/lufa/adafruit_ble.h
@@ -2,18 +2,19 @@
2 * Author: Wez Furlong, 2016 2 * Author: Wez Furlong, 2016
3 * Supports the Adafruit BLE board built around the nRF51822 chip. 3 * Supports the Adafruit BLE board built around the nRF51822 chip.
4 */ 4 */
5
5#pragma once 6#pragma once
6#ifdef MODULE_ADAFRUIT_BLE
7# include <stdbool.h>
8# include <stdint.h>
9# include <string.h>
10 7
11# include "config_common.h" 8#include <stdbool.h>
12# include "progmem.h" 9#include <stdint.h>
10#include <string.h>
11
12#include "config_common.h"
13#include "progmem.h"
13 14
14# ifdef __cplusplus 15#ifdef __cplusplus
15extern "C" { 16extern "C" {
16# endif 17#endif
17 18
18/* Instruct the module to enable HID keyboard support and reset */ 19/* Instruct the module to enable HID keyboard support and reset */
19extern bool adafruit_ble_enable_keyboard(void); 20extern bool adafruit_ble_enable_keyboard(void);
@@ -40,12 +41,12 @@ extern bool adafruit_ble_send_keys(uint8_t hid_modifier_mask, uint8_t *keys, uin
40 * (milliseconds) */ 41 * (milliseconds) */
41extern bool adafruit_ble_send_consumer_key(uint16_t keycode, int hold_duration); 42extern bool adafruit_ble_send_consumer_key(uint16_t keycode, int hold_duration);
42 43
43# ifdef MOUSE_ENABLE 44#ifdef MOUSE_ENABLE
44/* Send a mouse/wheel movement report. 45/* Send a mouse/wheel movement report.
45 * The parameters are signed and indicate positive of negative direction 46 * The parameters are signed and indicate positive of negative direction
46 * change. */ 47 * change. */
47extern bool adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons); 48extern bool adafruit_ble_send_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan, uint8_t buttons);
48# endif 49#endif
49 50
50/* Compute battery voltage by reading an analog pin. 51/* Compute battery voltage by reading an analog pin.
51 * Returns the integer number of millivolts */ 52 * Returns the integer number of millivolts */
@@ -54,8 +55,6 @@ extern uint32_t adafruit_ble_read_battery_voltage(void);
54extern bool adafruit_ble_set_mode_leds(bool on); 55extern bool adafruit_ble_set_mode_leds(bool on);
55extern bool adafruit_ble_set_power_level(int8_t level); 56extern bool adafruit_ble_set_power_level(int8_t level);
56 57
57# ifdef __cplusplus 58#ifdef __cplusplus
58} 59}
59# endif 60#endif
60
61#endif // MODULE_ADAFRUIT_BLE
diff --git a/tmk_core/protocol/lufa/bluetooth.c b/tmk_core/protocol/lufa/bluetooth.c
deleted file mode 100644
index 5eb52860b..000000000
--- a/tmk_core/protocol/lufa/bluetooth.c
+++ /dev/null
@@ -1,38 +0,0 @@
1/*
2Bluefruit Protocol for TMK firmware
3Author: Benjamin Gould, 2013
4 Jack Humbert, 2015
5Based on code Copyright 2011 Jun Wako <wakojun@gmail.com>
6This program is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 2 of the License, or
9(at your option) any later version.
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
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 "report.h"
20#include "print.h"
21#include "debug.h"
22#include "bluetooth.h"
23
24void bluefruit_keyboard_print_report(report_keyboard_t *report) {
25 if (!debug_keyboard) return;
26 dprintf("keys: ");
27 for (int i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
28 debug_hex8(report->keys[i]);
29 dprintf(" ");
30 }
31 dprintf(" mods: ");
32 debug_hex8(report->mods);
33 dprintf(" reserved: ");
34 debug_hex8(report->reserved);
35 dprintf("\n");
36}
37
38void bluefruit_serial_send(uint8_t data) { serial_send(data); } \ No newline at end of file
diff --git a/tmk_core/protocol/lufa/bluetooth.h b/tmk_core/protocol/lufa/bluetooth.h
deleted file mode 100644
index 081271a4e..000000000
--- a/tmk_core/protocol/lufa/bluetooth.h
+++ /dev/null
@@ -1,48 +0,0 @@
1/*
2Bluefruit Protocol for TMK firmware
3Author: Benjamin Gould, 2013
4 Jack Humbert, 2015
5Based on code Copyright 2011 Jun Wako <wakojun@gmail.com>
6This program is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 2 of the License, or
9(at your option) any later version.
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
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 BLUETOOTH_H
19#define BLUETOOTH_H
20
21#include "../serial.h"
22
23void bluefruit_serial_send(uint8_t data);
24
25/*
26+-----------------+-------------------+-------+
27| Consumer Key | Bit Map | Hex |
28+-----------------+-------------------+-------+
29| Home | 00000001 00000000 | 01 00 |
30| KeyboardLayout | 00000010 00000000 | 02 00 |
31| Search | 00000100 00000000 | 04 00 |
32| Snapshot | 00001000 00000000 | 08 00 |
33| VolumeUp | 00010000 00000000 | 10 00 |
34| VolumeDown | 00100000 00000000 | 20 00 |
35| Play/Pause | 01000000 00000000 | 40 00 |
36| Fast Forward | 10000000 00000000 | 80 00 |
37| Rewind | 00000000 00000001 | 00 01 |
38| Scan Next Track | 00000000 00000010 | 00 02 |
39| Scan Prev Track | 00000000 00000100 | 00 04 |
40| Random Play | 00000000 00001000 | 00 08 |
41| Stop | 00000000 00010000 | 00 10 |
42+-------------------------------------+-------+
43*/
44#define CONSUMER2BLUEFRUIT(usage) (usage == AUDIO_MUTE ? 0x0000 : (usage == AUDIO_VOL_UP ? 0x1000 : (usage == AUDIO_VOL_DOWN ? 0x2000 : (usage == TRANSPORT_NEXT_TRACK ? 0x0002 : (usage == TRANSPORT_PREV_TRACK ? 0x0004 : (usage == TRANSPORT_STOP ? 0x0010 : (usage == TRANSPORT_STOP_EJECT ? 0x0000 : (usage == TRANSPORT_PLAY_PAUSE ? 0x4000 : (usage == AL_CC_CONFIG ? 0x0000 : (usage == AL_EMAIL ? 0x0000 : (usage == AL_CALCULATOR ? 0x0000 : (usage == AL_LOCAL_BROWSER ? 0x0000 : (usage == AC_SEARCH ? 0x0400 : (usage == AC_HOME ? 0x0100 : (usage == AC_BACK ? 0x0000 : (usage == AC_FORWARD ? 0x0000 : (usage == AC_STOP ? 0x0000 : (usage == AC_REFRESH ? 0x0000 : (usage == AC_BOOKMARKS ? 0x0000 : 0)))))))))))))))))))
45
46#define CONSUMER2RN42(usage) (usage == AUDIO_MUTE ? 0x0040 : (usage == AUDIO_VOL_UP ? 0x0010 : (usage == AUDIO_VOL_DOWN ? 0x0020 : (usage == TRANSPORT_NEXT_TRACK ? 0x0100 : (usage == TRANSPORT_PREV_TRACK ? 0x0200 : (usage == TRANSPORT_STOP ? 0x0400 : (usage == TRANSPORT_STOP_EJECT ? 0x0800 : (usage == TRANSPORT_PLAY_PAUSE ? 0x0080 : (usage == AL_EMAIL ? 0x0200 : (usage == AL_LOCAL_BROWSER ? 0x8000 : (usage == AC_SEARCH ? 0x0400 : (usage == AC_HOME ? 0x0100 : 0))))))))))))
47
48#endif
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index 374add20f..cec004402 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -53,7 +53,6 @@
53#include "lufa.h" 53#include "lufa.h"
54#include "quantum.h" 54#include "quantum.h"
55#include <util/atomic.h> 55#include <util/atomic.h>
56#include "outputselect.h"
57 56
58#ifdef NKRO_ENABLE 57#ifdef NKRO_ENABLE
59# include "keycode_config.h" 58# include "keycode_config.h"
@@ -66,10 +65,11 @@ extern keymap_config_t keymap_config;
66#endif 65#endif
67 66
68#ifdef BLUETOOTH_ENABLE 67#ifdef BLUETOOTH_ENABLE
68# include "outputselect.h"
69# ifdef MODULE_ADAFRUIT_BLE 69# ifdef MODULE_ADAFRUIT_BLE
70# include "adafruit_ble.h" 70# include "adafruit_ble.h"
71# else 71# else
72# include "bluetooth.h" 72# include "../serial.h"
73# endif 73# endif
74#endif 74#endif
75 75
@@ -85,10 +85,54 @@ extern keymap_config_t keymap_config;
85# include "raw_hid.h" 85# include "raw_hid.h"
86#endif 86#endif
87 87
88#ifdef JOYSTICK_ENABLE
89# include "joystick.h"
90#endif
91
92// https://cdn.sparkfun.com/datasheets/Wireless/Bluetooth/bluetooth_cr_UG-v1.0r.pdf#G7.663734
93static inline uint16_t CONSUMER2RN42(uint16_t usage) {
94 switch (usage) {
95 case AC_HOME:
96 return 0x0001;
97 case AL_EMAIL:
98 return 0x0002;
99 case AC_SEARCH:
100 return 0x0004;
101 case AL_KEYBOARD_LAYOUT:
102 return 0x0008;
103 case AUDIO_VOL_UP:
104 return 0x0010;
105 case AUDIO_VOL_DOWN:
106 return 0x0020;
107 case AUDIO_MUTE:
108 return 0x0040;
109 case TRANSPORT_PLAY_PAUSE:
110 return 0x0080;
111 case TRANSPORT_NEXT_TRACK:
112 return 0x0100;
113 case TRANSPORT_PREV_TRACK:
114 return 0x0200;
115 case TRANSPORT_STOP:
116 return 0x0400;
117 case TRANSPORT_EJECT:
118 return 0x0800;
119 case TRANSPORT_FAST_FORWARD:
120 return 0x1000;
121 case TRANSPORT_REWIND:
122 return 0x2000;
123 case TRANSPORT_STOP_EJECT:
124 return 0x4000;
125 case AL_LOCAL_BROWSER:
126 return 0x8000;
127 default:
128 return 0;
129 }
130}
131
88uint8_t keyboard_idle = 0; 132uint8_t keyboard_idle = 0;
89/* 0: Boot Protocol, 1: Report Protocol(default) */ 133/* 0: Boot Protocol, 1: Report Protocol(default) */
90uint8_t keyboard_protocol = 1; 134uint8_t keyboard_protocol = 1;
91static uint8_t keyboard_led_stats = 0; 135static uint8_t keyboard_led_state = 0;
92 136
93static report_keyboard_t keyboard_report_sent; 137static report_keyboard_t keyboard_report_sent;
94 138
@@ -103,30 +147,30 @@ host_driver_t lufa_driver = {
103}; 147};
104 148
105#ifdef VIRTSER_ENABLE 149#ifdef VIRTSER_ENABLE
150// clang-format off
151
106USB_ClassInfo_CDC_Device_t cdc_device = { 152USB_ClassInfo_CDC_Device_t cdc_device = {
107 .Config = 153 .Config = {
108 { 154 .ControlInterfaceNumber = CCI_INTERFACE,
109 .ControlInterfaceNumber = CCI_INTERFACE, 155 .DataINEndpoint = {
110 .DataINEndpoint = 156 .Address = (CDC_IN_EPNUM | ENDPOINT_DIR_IN),
111 { 157 .Size = CDC_EPSIZE,
112 .Address = CDC_IN_EPADDR, 158 .Banks = 1
113 .Size = CDC_EPSIZE,
114 .Banks = 1,
115 },
116 .DataOUTEndpoint =
117 {
118 .Address = CDC_OUT_EPADDR,
119 .Size = CDC_EPSIZE,
120 .Banks = 1,
121 },
122 .NotificationEndpoint =
123 {
124 .Address = CDC_NOTIFICATION_EPADDR,
125 .Size = CDC_NOTIFICATION_EPSIZE,
126 .Banks = 1,
127 },
128 }, 159 },
160 .DataOUTEndpoint = {
161 .Address = (CDC_OUT_EPNUM | ENDPOINT_DIR_OUT),
162 .Size = CDC_EPSIZE,
163 .Banks = 1
164 },
165 .NotificationEndpoint = {
166 .Address = (CDC_NOTIFICATION_EPNUM | ENDPOINT_DIR_IN),
167 .Size = CDC_NOTIFICATION_EPSIZE,
168 .Banks = 1
169 }
170 }
129}; 171};
172
173// clang-format on
130#endif 174#endif
131 175
132#ifdef RAW_ENABLE 176#ifdef RAW_ENABLE
@@ -254,7 +298,7 @@ static void Console_Task(void) {
254 // fill empty bank 298 // fill empty bank
255 while (Endpoint_IsReadWriteAllowed()) Endpoint_Write_8(0); 299 while (Endpoint_IsReadWriteAllowed()) Endpoint_Write_8(0);
256 300
257 // flash senchar packet 301 // flush sendchar packet
258 if (Endpoint_IsINReady()) { 302 if (Endpoint_IsINReady()) {
259 Endpoint_ClearIN(); 303 Endpoint_ClearIN();
260 } 304 }
@@ -264,6 +308,70 @@ static void Console_Task(void) {
264#endif 308#endif
265 309
266/******************************************************************************* 310/*******************************************************************************
311 * Joystick
312 ******************************************************************************/
313#ifdef JOYSTICK_ENABLE
314void send_joystick_packet(joystick_t *joystick) {
315 uint8_t timeout = 255;
316
317 joystick_report_t r = {
318# if JOYSTICK_AXES_COUNT > 0
319 .axes =
320 {
321 joystick->axes[0],
322
323# if JOYSTICK_AXES_COUNT >= 2
324 joystick->axes[1],
325# endif
326# if JOYSTICK_AXES_COUNT >= 3
327 joystick->axes[2],
328# endif
329# if JOYSTICK_AXES_COUNT >= 4
330 joystick->axes[3],
331# endif
332# if JOYSTICK_AXES_COUNT >= 5
333 joystick->axes[4],
334# endif
335# if JOYSTICK_AXES_COUNT >= 6
336 joystick->axes[5],
337# endif
338 },
339# endif // JOYSTICK_AXES_COUNT>0
340
341# if JOYSTICK_BUTTON_COUNT > 0
342 .buttons =
343 {
344 joystick->buttons[0],
345
346# if JOYSTICK_BUTTON_COUNT > 8
347 joystick->buttons[1],
348# endif
349# if JOYSTICK_BUTTON_COUNT > 16
350 joystick->buttons[2],
351# endif
352# if JOYSTICK_BUTTON_COUNT > 24
353 joystick->buttons[3],
354# endif
355 }
356# endif // JOYSTICK_BUTTON_COUNT>0
357 };
358
359 /* Select the Joystick Report Endpoint */
360 Endpoint_SelectEndpoint(JOYSTICK_IN_EPNUM);
361
362 /* Check if write ready for a polling interval around 10ms */
363 while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40);
364 if (!Endpoint_IsReadWriteAllowed()) return;
365
366 /* Write Joystick Report Data */
367 Endpoint_Write_Stream_LE(&r, sizeof(joystick_report_t), NULL);
368
369 /* Finalize the stream transfer to send the last packet */
370 Endpoint_ClearIN();
371}
372#endif
373
374/*******************************************************************************
267 * USB Events 375 * USB Events
268 ******************************************************************************/ 376 ******************************************************************************/
269/* 377/*
@@ -370,45 +478,51 @@ void EVENT_USB_Device_StartOfFrame(void) {
370void EVENT_USB_Device_ConfigurationChanged(void) { 478void EVENT_USB_Device_ConfigurationChanged(void) {
371 bool ConfigSuccess = true; 479 bool ConfigSuccess = true;
372 480
373 /* Setup Keyboard HID Report Endpoints */
374#ifndef KEYBOARD_SHARED_EP 481#ifndef KEYBOARD_SHARED_EP
375 ConfigSuccess &= ENDPOINT_CONFIG(KEYBOARD_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, KEYBOARD_EPSIZE, ENDPOINT_BANK_SINGLE); 482 /* Setup keyboard report endpoint */
483 ConfigSuccess &= Endpoint_ConfigureEndpoint((KEYBOARD_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, KEYBOARD_EPSIZE, 1);
376#endif 484#endif
377 485
378#if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP) 486#if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
379 /* Setup Mouse HID Report Endpoint */ 487 /* Setup mouse report endpoint */
380 ConfigSuccess &= ENDPOINT_CONFIG(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, MOUSE_EPSIZE, ENDPOINT_BANK_SINGLE); 488 ConfigSuccess &= Endpoint_ConfigureEndpoint((MOUSE_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, MOUSE_EPSIZE, 1);
381#endif 489#endif
382 490
383#ifdef SHARED_EP_ENABLE 491#ifdef SHARED_EP_ENABLE
384 /* Setup Shared HID Report Endpoint */ 492 /* Setup shared report endpoint */
385 ConfigSuccess &= ENDPOINT_CONFIG(SHARED_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, SHARED_EPSIZE, ENDPOINT_BANK_SINGLE); 493 ConfigSuccess &= Endpoint_ConfigureEndpoint((SHARED_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, SHARED_EPSIZE, 1);
386#endif 494#endif
387 495
388#ifdef RAW_ENABLE 496#ifdef RAW_ENABLE
389 /* Setup Raw HID Report Endpoints */ 497 /* Setup raw HID endpoints */
390 ConfigSuccess &= ENDPOINT_CONFIG(RAW_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, RAW_EPSIZE, ENDPOINT_BANK_SINGLE); 498 ConfigSuccess &= Endpoint_ConfigureEndpoint((RAW_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, RAW_EPSIZE, 1);
391 ConfigSuccess &= ENDPOINT_CONFIG(RAW_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, RAW_EPSIZE, ENDPOINT_BANK_SINGLE); 499 ConfigSuccess &= Endpoint_ConfigureEndpoint((RAW_OUT_EPNUM | ENDPOINT_DIR_OUT), EP_TYPE_INTERRUPT, RAW_EPSIZE, 1);
392#endif 500#endif
393 501
394#ifdef CONSOLE_ENABLE 502#ifdef CONSOLE_ENABLE
395 /* Setup Console HID Report Endpoints */ 503 /* Setup console endpoint */
396 ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE); 504 ConfigSuccess &= Endpoint_ConfigureEndpoint((CONSOLE_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, CONSOLE_EPSIZE, 1);
397# if 0 505# if 0
398 ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT, 506 ConfigSuccess &= Endpoint_ConfigureEndpoint((CONSOLE_OUT_EPNUM | ENDPOINT_DIR_OUT), EP_TYPE_INTERRUPT, CONSOLE_EPSIZE, 1);
399 CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE);
400# endif 507# endif
401#endif 508#endif
402 509
403#ifdef MIDI_ENABLE 510#ifdef MIDI_ENABLE
404 ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_IN_EPADDR, EP_TYPE_BULK, MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE); 511 /* Setup MIDI stream endpoints */
405 ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_OUT_EPADDR, EP_TYPE_BULK, MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE); 512 ConfigSuccess &= Endpoint_ConfigureEndpoint((MIDI_STREAM_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_BULK, MIDI_STREAM_EPSIZE, 1);
513 ConfigSuccess &= Endpoint_ConfigureEndpoint((MIDI_STREAM_OUT_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_BULK, MIDI_STREAM_EPSIZE, 1);
406#endif 514#endif
407 515
408#ifdef VIRTSER_ENABLE 516#ifdef VIRTSER_ENABLE
409 ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPADDR, EP_TYPE_INTERRUPT, CDC_NOTIFICATION_EPSIZE, ENDPOINT_BANK_SINGLE); 517 /* Setup virtual serial endpoints */
410 ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_OUT_EPADDR, EP_TYPE_BULK, CDC_EPSIZE, ENDPOINT_BANK_SINGLE); 518 ConfigSuccess &= Endpoint_ConfigureEndpoint((CDC_NOTIFICATION_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, CDC_NOTIFICATION_EPSIZE, 1);
411 ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_IN_EPADDR, EP_TYPE_BULK, CDC_EPSIZE, ENDPOINT_BANK_SINGLE); 519 ConfigSuccess &= Endpoint_ConfigureEndpoint((CDC_OUT_EPNUM | ENDPOINT_DIR_OUT), EP_TYPE_BULK, CDC_EPSIZE, 1);
520 ConfigSuccess &= Endpoint_ConfigureEndpoint((CDC_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_BULK, CDC_EPSIZE, 1);
521#endif
522
523#ifdef JOYSTICK_ENABLE
524 /* Setup joystick endpoint */
525 ConfigSuccess &= Endpoint_ConfigureEndpoint((JOYSTICK_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, JOYSTICK_EPSIZE, 1);
412#endif 526#endif
413} 527}
414 528
@@ -472,10 +586,10 @@ void EVENT_USB_Device_ControlRequest(void) {
472 uint8_t report_id = Endpoint_Read_8(); 586 uint8_t report_id = Endpoint_Read_8();
473 587
474 if (report_id == REPORT_ID_KEYBOARD || report_id == REPORT_ID_NKRO) { 588 if (report_id == REPORT_ID_KEYBOARD || report_id == REPORT_ID_NKRO) {
475 keyboard_led_stats = Endpoint_Read_8(); 589 keyboard_led_state = Endpoint_Read_8();
476 } 590 }
477 } else { 591 } else {
478 keyboard_led_stats = Endpoint_Read_8(); 592 keyboard_led_state = Endpoint_Read_8();
479 } 593 }
480 594
481 Endpoint_ClearOUT(); 595 Endpoint_ClearOUT();
@@ -545,7 +659,7 @@ void EVENT_USB_Device_ControlRequest(void) {
545 * 659 *
546 * FIXME: Needs doc 660 * FIXME: Needs doc
547 */ 661 */
548static uint8_t keyboard_leds(void) { return keyboard_led_stats; } 662static uint8_t keyboard_leds(void) { return keyboard_led_state; }
549 663
550/** \brief Send Keyboard 664/** \brief Send Keyboard
551 * 665 *
@@ -553,35 +667,29 @@ static uint8_t keyboard_leds(void) { return keyboard_led_stats; }
553 */ 667 */
554static void send_keyboard(report_keyboard_t *report) { 668static void send_keyboard(report_keyboard_t *report) {
555 uint8_t timeout = 255; 669 uint8_t timeout = 255;
556 uint8_t where = where_to_send();
557 670
558#ifdef BLUETOOTH_ENABLE 671#ifdef BLUETOOTH_ENABLE
672 uint8_t where = where_to_send();
673
559 if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) { 674 if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
560# ifdef MODULE_ADAFRUIT_BLE 675# ifdef MODULE_ADAFRUIT_BLE
561 adafruit_ble_send_keys(report->mods, report->keys, sizeof(report->keys)); 676 adafruit_ble_send_keys(report->mods, report->keys, sizeof(report->keys));
562# elif MODULE_RN42 677# elif MODULE_RN42
563 bluefruit_serial_send(0xFD); 678 serial_send(0xFD);
564 bluefruit_serial_send(0x09); 679 serial_send(0x09);
565 bluefruit_serial_send(0x01); 680 serial_send(0x01);
566 bluefruit_serial_send(report->mods); 681 serial_send(report->mods);
567 bluefruit_serial_send(report->reserved); 682 serial_send(report->reserved);
568 for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
569 bluefruit_serial_send(report->keys[i]);
570 }
571# else
572 bluefruit_serial_send(0xFD);
573 bluefruit_serial_send(report->mods);
574 bluefruit_serial_send(report->reserved);
575 for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) { 683 for (uint8_t i = 0; i < KEYBOARD_REPORT_KEYS; i++) {
576 bluefruit_serial_send(report->keys[i]); 684 serial_send(report->keys[i]);
577 } 685 }
578# endif 686# endif
579 } 687 }
580#endif
581 688
582 if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) { 689 if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) {
583 return; 690 return;
584 } 691 }
692#endif
585 693
586 /* Select the Keyboard Report Endpoint */ 694 /* Select the Keyboard Report Endpoint */
587 uint8_t ep = KEYBOARD_IN_EPNUM; 695 uint8_t ep = KEYBOARD_IN_EPNUM;
@@ -617,30 +725,31 @@ static void send_keyboard(report_keyboard_t *report) {
617static void send_mouse(report_mouse_t *report) { 725static void send_mouse(report_mouse_t *report) {
618#ifdef MOUSE_ENABLE 726#ifdef MOUSE_ENABLE
619 uint8_t timeout = 255; 727 uint8_t timeout = 255;
620 uint8_t where = where_to_send();
621 728
622# ifdef BLUETOOTH_ENABLE 729# ifdef BLUETOOTH_ENABLE
730 uint8_t where = where_to_send();
731
623 if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) { 732 if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
624# ifdef MODULE_ADAFRUIT_BLE 733# ifdef MODULE_ADAFRUIT_BLE
625 // FIXME: mouse buttons 734 // FIXME: mouse buttons
626 adafruit_ble_send_mouse_move(report->x, report->y, report->v, report->h, report->buttons); 735 adafruit_ble_send_mouse_move(report->x, report->y, report->v, report->h, report->buttons);
627# else 736# else
628 bluefruit_serial_send(0xFD); 737 serial_send(0xFD);
629 bluefruit_serial_send(0x00); 738 serial_send(0x00);
630 bluefruit_serial_send(0x03); 739 serial_send(0x03);
631 bluefruit_serial_send(report->buttons); 740 serial_send(report->buttons);
632 bluefruit_serial_send(report->x); 741 serial_send(report->x);
633 bluefruit_serial_send(report->y); 742 serial_send(report->y);
634 bluefruit_serial_send(report->v); // should try sending the wheel v here 743 serial_send(report->v); // should try sending the wheel v here
635 bluefruit_serial_send(report->h); // should try sending the wheel h here 744 serial_send(report->h); // should try sending the wheel h here
636 bluefruit_serial_send(0x00); 745 serial_send(0x00);
637# endif 746# endif
638 } 747 }
639# endif
640 748
641 if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) { 749 if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) {
642 return; 750 return;
643 } 751 }
752# endif
644 753
645 /* Select the Mouse Report Endpoint */ 754 /* Select the Mouse Report Endpoint */
646 Endpoint_SelectEndpoint(MOUSE_IN_EPNUM); 755 Endpoint_SelectEndpoint(MOUSE_IN_EPNUM);
@@ -695,9 +804,9 @@ static void send_system(uint16_t data) {
695 */ 804 */
696static void send_consumer(uint16_t data) { 805static void send_consumer(uint16_t data) {
697#ifdef EXTRAKEY_ENABLE 806#ifdef EXTRAKEY_ENABLE
807# ifdef BLUETOOTH_ENABLE
698 uint8_t where = where_to_send(); 808 uint8_t where = where_to_send();
699 809
700# ifdef BLUETOOTH_ENABLE
701 if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) { 810 if (where == OUTPUT_BLUETOOTH || where == OUTPUT_USB_AND_BT) {
702# ifdef MODULE_ADAFRUIT_BLE 811# ifdef MODULE_ADAFRUIT_BLE
703 adafruit_ble_send_consumer_key(data, 0); 812 adafruit_ble_send_consumer_key(data, 0);
@@ -706,32 +815,18 @@ static void send_consumer(uint16_t data) {
706 if (data == last_data) return; 815 if (data == last_data) return;
707 last_data = data; 816 last_data = data;
708 uint16_t bitmap = CONSUMER2RN42(data); 817 uint16_t bitmap = CONSUMER2RN42(data);
709 bluefruit_serial_send(0xFD); 818 serial_send(0xFD);
710 bluefruit_serial_send(0x03); 819 serial_send(0x03);
711 bluefruit_serial_send(0x03); 820 serial_send(0x03);
712 bluefruit_serial_send(bitmap & 0xFF); 821 serial_send(bitmap & 0xFF);
713 bluefruit_serial_send((bitmap >> 8) & 0xFF); 822 serial_send((bitmap >> 8) & 0xFF);
714# else
715 static uint16_t last_data = 0;
716 if (data == last_data) return;
717 last_data = data;
718 uint16_t bitmap = CONSUMER2BLUEFRUIT(data);
719 bluefruit_serial_send(0xFD);
720 bluefruit_serial_send(0x00);
721 bluefruit_serial_send(0x02);
722 bluefruit_serial_send((bitmap >> 8) & 0xFF);
723 bluefruit_serial_send(bitmap & 0xFF);
724 bluefruit_serial_send(0x00);
725 bluefruit_serial_send(0x00);
726 bluefruit_serial_send(0x00);
727 bluefruit_serial_send(0x00);
728# endif 823# endif
729 } 824 }
730# endif
731 825
732 if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) { 826 if (where != OUTPUT_USB && where != OUTPUT_USB_AND_BT) {
733 return; 827 return;
734 } 828 }
829# endif
735 830
736 send_extra(REPORT_ID_CONSUMER, data); 831 send_extra(REPORT_ID_CONSUMER, data);
737#endif 832#endif
@@ -808,25 +903,26 @@ ERROR_EXIT:
808 ******************************************************************************/ 903 ******************************************************************************/
809 904
810#ifdef MIDI_ENABLE 905#ifdef MIDI_ENABLE
906// clang-format off
907
811USB_ClassInfo_MIDI_Device_t USB_MIDI_Interface = { 908USB_ClassInfo_MIDI_Device_t USB_MIDI_Interface = {
812 .Config = 909 .Config = {
813 { 910 .StreamingInterfaceNumber = AS_INTERFACE,
814 .StreamingInterfaceNumber = AS_INTERFACE, 911 .DataINEndpoint = {
815 .DataINEndpoint = 912 .Address = (MIDI_STREAM_IN_EPNUM | ENDPOINT_DIR_IN),
816 { 913 .Size = MIDI_STREAM_EPSIZE,
817 .Address = MIDI_STREAM_IN_EPADDR, 914 .Banks = 1
818 .Size = MIDI_STREAM_EPSIZE,
819 .Banks = 1,
820 },
821 .DataOUTEndpoint =
822 {
823 .Address = MIDI_STREAM_OUT_EPADDR,
824 .Size = MIDI_STREAM_EPSIZE,
825 .Banks = 1,
826 },
827 }, 915 },
916 .DataOUTEndpoint = {
917 .Address = (MIDI_STREAM_OUT_EPNUM | ENDPOINT_DIR_OUT),
918 .Size = MIDI_STREAM_EPSIZE,
919 .Banks = 1
920 }
921 }
828}; 922};
829 923
924// clang-format on
925
830void send_midi_packet(MIDI_EventPacket_t *event) { MIDI_Device_SendEventPacket(&USB_MIDI_Interface, event); } 926void send_midi_packet(MIDI_EventPacket_t *event) { MIDI_Device_SendEventPacket(&USB_MIDI_Interface, event); }
831 927
832bool recv_midi_packet(MIDI_EventPacket_t *const event) { return MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, event); } 928bool recv_midi_packet(MIDI_EventPacket_t *const event) { return MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, event); }
@@ -945,7 +1041,7 @@ int main(void) {
945 setup_usb(); 1041 setup_usb();
946 sei(); 1042 sei();
947 1043
948#if defined(MODULE_ADAFRUIT_EZKEY) || defined(MODULE_RN42) 1044#if defined(MODULE_RN42)
949 serial_init(); 1045 serial_init();
950#endif 1046#endif
951 1047
diff --git a/tmk_core/protocol/lufa/lufa.h b/tmk_core/protocol/lufa/lufa.h
index 82a5f8e05..71fd7aad8 100644
--- a/tmk_core/protocol/lufa/lufa.h
+++ b/tmk_core/protocol/lufa/lufa.h
@@ -69,8 +69,4 @@ extern host_driver_t lufa_driver;
69# define MIDI_SYSEX_BUFFER (API_SYSEX_MAX_SIZE + API_SYSEX_MAX_SIZE / 7 + (API_SYSEX_MAX_SIZE % 7 ? 1 : 0)) 69# define MIDI_SYSEX_BUFFER (API_SYSEX_MAX_SIZE + API_SYSEX_MAX_SIZE / 7 + (API_SYSEX_MAX_SIZE % 7 ? 1 : 0))
70#endif 70#endif
71 71
72#define ENDPOINT_BANK_SINGLE 1
73#define ENDPOINT_BANK_DOUBLE 2
74#define ENDPOINT_CONFIG(epnum, eptype, epdir, epsize, epbank) Endpoint_ConfigureEndpoint((epdir) | (epnum), eptype, epsize, epbank)
75
76#endif 72#endif
diff --git a/tmk_core/protocol/lufa/outputselect.c b/tmk_core/protocol/lufa/outputselect.c
index b115ea969..f758c6528 100644
--- a/tmk_core/protocol/lufa/outputselect.c
+++ b/tmk_core/protocol/lufa/outputselect.c
@@ -12,8 +12,12 @@ You should have received a copy of the GNU General Public License
12along with this program. If not, see <http://www.gnu.org/licenses/>. 12along with this program. If not, see <http://www.gnu.org/licenses/>.
13*/ 13*/
14 14
15#include "lufa.h"
16#include "outputselect.h" 15#include "outputselect.h"
16
17#if defined(PROTOCOL_LUFA)
18# include "lufa.h"
19#endif
20
17#ifdef MODULE_ADAFRUIT_BLE 21#ifdef MODULE_ADAFRUIT_BLE
18# include "adafruit_ble.h" 22# include "adafruit_ble.h"
19#endif 23#endif
@@ -35,12 +39,18 @@ void set_output(uint8_t output) {
35 */ 39 */
36__attribute__((weak)) void set_output_user(uint8_t output) {} 40__attribute__((weak)) void set_output_user(uint8_t output) {}
37 41
42static bool is_usb_configured(void) {
43#if defined(PROTOCOL_LUFA)
44 return USB_DeviceState == DEVICE_STATE_Configured;
45#endif
46}
47
38/** \brief Auto Detect Output 48/** \brief Auto Detect Output
39 * 49 *
40 * FIXME: Needs doc 50 * FIXME: Needs doc
41 */ 51 */
42uint8_t auto_detect_output(void) { 52uint8_t auto_detect_output(void) {
43 if (USB_DeviceState == DEVICE_STATE_Configured) { 53 if (is_usb_configured()) {
44 return OUTPUT_USB; 54 return OUTPUT_USB;
45 } 55 }
46 56
diff --git a/tmk_core/protocol/lufa/outputselect.h b/tmk_core/protocol/lufa/outputselect.h
index 24fe4daa2..7f7ed00b9 100644
--- a/tmk_core/protocol/lufa/outputselect.h
+++ b/tmk_core/protocol/lufa/outputselect.h
@@ -12,6 +12,10 @@ You should have received a copy of the GNU General Public License
12along with this program. If not, see <http://www.gnu.org/licenses/>. 12along with this program. If not, see <http://www.gnu.org/licenses/>.
13*/ 13*/
14 14
15#pragma once
16
17#include <stdint.h>
18
15enum outputs { 19enum outputs {
16 OUTPUT_AUTO, 20 OUTPUT_AUTO,
17 21
@@ -37,4 +41,4 @@ enum outputs {
37void set_output(uint8_t output); 41void set_output(uint8_t output);
38void set_output_user(uint8_t output); 42void set_output_user(uint8_t output);
39uint8_t auto_detect_output(void); 43uint8_t auto_detect_output(void);
40uint8_t where_to_send(void); \ No newline at end of file 44uint8_t where_to_send(void);
diff --git a/tmk_core/protocol/serial.h b/tmk_core/protocol/serial.h
index 93ac99898..b70d117d7 100644
--- a/tmk_core/protocol/serial.h
+++ b/tmk_core/protocol/serial.h
@@ -35,13 +35,10 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35POSSIBILITY OF SUCH DAMAGE. 35POSSIBILITY OF SUCH DAMAGE.
36*/ 36*/
37 37
38#ifndef SERIAL_H 38#pragma once
39#define SERIAL_H
40 39
41/* host role */ 40/* host role */
42void serial_init(void); 41void serial_init(void);
43uint8_t serial_recv(void); 42uint8_t serial_recv(void);
44int16_t serial_recv2(void); 43int16_t serial_recv2(void);
45void serial_send(uint8_t data); 44void serial_send(uint8_t data);
46
47#endif
diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c
index 8c71dd1dd..f5d32445d 100644
--- a/tmk_core/protocol/usb_descriptor.c
+++ b/tmk_core/protocol/usb_descriptor.c
@@ -279,6 +279,63 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] = {
279}; 279};
280#endif 280#endif
281 281
282#ifdef JOYSTICK_ENABLE
283# if JOYSTICK_AXES_COUNT == 0 && JOYSTICK_BUTTON_COUNT == 0
284# error Need at least one axis or button for joystick
285# endif
286const USB_Descriptor_HIDReport_Datatype_t PROGMEM JoystickReport[] = {
287 HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
288 HID_RI_USAGE(8, 0x04), // Joystick
289 HID_RI_COLLECTION(8, 0x01), // Application
290 HID_RI_COLLECTION(8, 0x00), // Physical
291 HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
292# if JOYSTICK_AXES_COUNT >= 1
293 HID_RI_USAGE(8, 0x30), // X
294# endif
295# if JOYSTICK_AXES_COUNT >= 2
296 HID_RI_USAGE(8, 0x31), // Y
297# endif
298# if JOYSTICK_AXES_COUNT >= 3
299 HID_RI_USAGE(8, 0x32), // Z
300# endif
301# if JOYSTICK_AXES_COUNT >= 4
302 HID_RI_USAGE(8, 0x33), // Rx
303# endif
304# if JOYSTICK_AXES_COUNT >= 5
305 HID_RI_USAGE(8, 0x34), // Ry
306# endif
307# if JOYSTICK_AXES_COUNT >= 6
308 HID_RI_USAGE(8, 0x35), // Rz
309# endif
310# if JOYSTICK_AXES_COUNT >= 1
311 HID_RI_LOGICAL_MINIMUM(8, -127),
312 HID_RI_LOGICAL_MAXIMUM(8, 127),
313 HID_RI_REPORT_COUNT(8, JOYSTICK_AXES_COUNT),
314 HID_RI_REPORT_SIZE(8, 0x08),
315 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
316# endif
317
318# if JOYSTICK_BUTTON_COUNT >= 1
319 HID_RI_USAGE_PAGE(8, 0x09), // Button
320 HID_RI_USAGE_MINIMUM(8, 0x01),
321 HID_RI_USAGE_MAXIMUM(8, JOYSTICK_BUTTON_COUNT),
322 HID_RI_LOGICAL_MINIMUM(8, 0x00),
323 HID_RI_LOGICAL_MAXIMUM(8, 0x01),
324 HID_RI_REPORT_COUNT(8, JOYSTICK_BUTTON_COUNT),
325 HID_RI_REPORT_SIZE(8, 0x01),
326 HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
327
328# if (JOYSTICK_BUTTON_COUNT % 8) != 0
329 HID_RI_REPORT_COUNT(8, 8 - (JOYSTICK_BUTTON_COUNT % 8)),
330 HID_RI_REPORT_SIZE(8, 0x01),
331 HID_RI_INPUT(8, HID_IOF_CONSTANT),
332# endif
333# endif
334 HID_RI_END_COLLECTION(0),
335 HID_RI_END_COLLECTION(0)
336};
337#endif
338
282/* 339/*
283 * Device descriptor 340 * Device descriptor
284 */ 341 */
@@ -288,7 +345,7 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = {
288 .Type = DTYPE_Device 345 .Type = DTYPE_Device
289 }, 346 },
290 .USBSpecification = VERSION_BCD(1, 1, 0), 347 .USBSpecification = VERSION_BCD(1, 1, 0),
291 348
292#if VIRTSER_ENABLE 349#if VIRTSER_ENABLE
293 .Class = USB_CSCP_IADDeviceClass, 350 .Class = USB_CSCP_IADDeviceClass,
294 .SubClass = USB_CSCP_IADDeviceSubclass, 351 .SubClass = USB_CSCP_IADDeviceSubclass,
@@ -673,7 +730,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
673 .Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t), 730 .Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t),
674 .Type = DTYPE_Endpoint 731 .Type = DTYPE_Endpoint
675 }, 732 },
676 .EndpointAddress = MIDI_STREAM_OUT_EPADDR, 733 .EndpointAddress = (ENDPOINT_DIR_OUT | MIDI_STREAM_OUT_EPNUM),
677 .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), 734 .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
678 .EndpointSize = MIDI_STREAM_EPSIZE, 735 .EndpointSize = MIDI_STREAM_EPSIZE,
679 .PollingIntervalMS = 0x05 736 .PollingIntervalMS = 0x05
@@ -696,7 +753,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
696 .Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t), 753 .Size = sizeof(USB_Audio_Descriptor_StreamEndpoint_Std_t),
697 .Type = DTYPE_Endpoint 754 .Type = DTYPE_Endpoint
698 }, 755 },
699 .EndpointAddress = MIDI_STREAM_IN_EPADDR, 756 .EndpointAddress = (ENDPOINT_DIR_IN | MIDI_STREAM_IN_EPNUM),
700 .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), 757 .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
701 .EndpointSize = MIDI_STREAM_EPSIZE, 758 .EndpointSize = MIDI_STREAM_EPSIZE,
702 .PollingIntervalMS = 0x05 759 .PollingIntervalMS = 0x05
@@ -774,7 +831,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
774 .Size = sizeof(USB_Descriptor_Endpoint_t), 831 .Size = sizeof(USB_Descriptor_Endpoint_t),
775 .Type = DTYPE_Endpoint 832 .Type = DTYPE_Endpoint
776 }, 833 },
777 .EndpointAddress = CDC_NOTIFICATION_EPADDR, 834 .EndpointAddress = (ENDPOINT_DIR_IN | CDC_NOTIFICATION_EPNUM),
778 .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), 835 .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
779 .EndpointSize = CDC_NOTIFICATION_EPSIZE, 836 .EndpointSize = CDC_NOTIFICATION_EPSIZE,
780 .PollingIntervalMS = 0xFF 837 .PollingIntervalMS = 0xFF
@@ -797,7 +854,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
797 .Size = sizeof(USB_Descriptor_Endpoint_t), 854 .Size = sizeof(USB_Descriptor_Endpoint_t),
798 .Type = DTYPE_Endpoint 855 .Type = DTYPE_Endpoint
799 }, 856 },
800 .EndpointAddress = CDC_OUT_EPADDR, 857 .EndpointAddress = (ENDPOINT_DIR_OUT | CDC_OUT_EPNUM),
801 .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), 858 .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
802 .EndpointSize = CDC_EPSIZE, 859 .EndpointSize = CDC_EPSIZE,
803 .PollingIntervalMS = 0x05 860 .PollingIntervalMS = 0x05
@@ -807,12 +864,52 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
807 .Size = sizeof(USB_Descriptor_Endpoint_t), 864 .Size = sizeof(USB_Descriptor_Endpoint_t),
808 .Type = DTYPE_Endpoint 865 .Type = DTYPE_Endpoint
809 }, 866 },
810 .EndpointAddress = CDC_IN_EPADDR, 867 .EndpointAddress = (ENDPOINT_DIR_IN | CDC_IN_EPNUM),
811 .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), 868 .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
812 .EndpointSize = CDC_EPSIZE, 869 .EndpointSize = CDC_EPSIZE,
813 .PollingIntervalMS = 0x05 870 .PollingIntervalMS = 0x05
814 }, 871 },
815#endif 872#endif
873
874 /*
875 * Joystick
876 */
877#ifdef JOYSTICK_ENABLE
878 .Joystick_Interface = {
879 .Header = {
880 .Size = sizeof(USB_Descriptor_Interface_t),
881 .Type = DTYPE_Interface
882 },
883 .InterfaceNumber = JOYSTICK_INTERFACE,
884 .AlternateSetting = 0x00,
885 .TotalEndpoints = 1,
886 .Class = HID_CSCP_HIDClass,
887 .SubClass = HID_CSCP_NonBootSubclass,
888 .Protocol = HID_CSCP_NonBootProtocol,
889 .InterfaceStrIndex = NO_DESCRIPTOR
890 },
891 .Joystick_HID = {
892 .Header = {
893 .Size = sizeof(USB_HID_Descriptor_HID_t),
894 .Type = HID_DTYPE_HID
895 },
896 .HIDSpec = VERSION_BCD(1, 1, 1),
897 .CountryCode = 0x00,
898 .TotalReportDescriptors = 1,
899 .HIDReportType = HID_DTYPE_Report,
900 .HIDReportLength = sizeof(JoystickReport)
901 },
902 .Joystick_INEndpoint = {
903 .Header = {
904 .Size = sizeof(USB_Descriptor_Endpoint_t),
905 .Type = DTYPE_Endpoint
906 },
907 .EndpointAddress = (ENDPOINT_DIR_IN | JOYSTICK_IN_EPNUM),
908 .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
909 .EndpointSize = JOYSTICK_EPSIZE,
910 .PollingIntervalMS = USB_POLLING_INTERVAL_MS
911 }
912#endif
816}; 913};
817 914
818/* 915/*
@@ -945,6 +1042,12 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const
945 1042
946 break; 1043 break;
947#endif 1044#endif
1045#ifdef JOYSTICK_ENABLE
1046 case JOYSTICK_INTERFACE:
1047 Address = &ConfigurationDescriptor.Joystick_HID;
1048 Size = sizeof(USB_HID_Descriptor_HID_t);
1049 break;
1050#endif
948 } 1051 }
949 1052
950 break; 1053 break;
@@ -989,6 +1092,12 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const
989 1092
990 break; 1093 break;
991#endif 1094#endif
1095#ifdef JOYSTICK_ENABLE
1096 case JOYSTICK_INTERFACE:
1097 Address = &JoystickReport;
1098 Size = sizeof(JoystickReport);
1099 break;
1100#endif
992 } 1101 }
993 1102
994 break; 1103 break;
diff --git a/tmk_core/protocol/usb_descriptor.h b/tmk_core/protocol/usb_descriptor.h
index b2423fa7e..79dd87014 100644
--- a/tmk_core/protocol/usb_descriptor.h
+++ b/tmk_core/protocol/usb_descriptor.h
@@ -123,6 +123,13 @@ typedef struct {
123 USB_Descriptor_Endpoint_t CDC_DataOutEndpoint; 123 USB_Descriptor_Endpoint_t CDC_DataOutEndpoint;
124 USB_Descriptor_Endpoint_t CDC_DataInEndpoint; 124 USB_Descriptor_Endpoint_t CDC_DataInEndpoint;
125#endif 125#endif
126
127#ifdef JOYSTICK_ENABLE
128 // Joystick HID Interface
129 USB_Descriptor_Interface_t Joystick_Interface;
130 USB_HID_Descriptor_HID_t Joystick_HID;
131 USB_Descriptor_Endpoint_t Joystick_INEndpoint;
132#endif
126} USB_Descriptor_Configuration_t; 133} USB_Descriptor_Configuration_t;
127 134
128/* 135/*
@@ -164,6 +171,9 @@ enum usb_interfaces {
164 CDI_INTERFACE, 171 CDI_INTERFACE,
165#endif 172#endif
166 173
174#if defined(JOYSTICK_ENABLE)
175 JOYSTICK_INTERFACE,
176#endif
167 TOTAL_INTERFACES 177 TOTAL_INTERFACES
168}; 178};
169 179
@@ -212,17 +222,16 @@ enum usb_endpoints {
212#ifdef MIDI_ENABLE 222#ifdef MIDI_ENABLE
213 MIDI_STREAM_IN_EPNUM = NEXT_EPNUM, 223 MIDI_STREAM_IN_EPNUM = NEXT_EPNUM,
214 MIDI_STREAM_OUT_EPNUM = NEXT_EPNUM, 224 MIDI_STREAM_OUT_EPNUM = NEXT_EPNUM,
215# define MIDI_STREAM_IN_EPADDR (ENDPOINT_DIR_IN | MIDI_STREAM_IN_EPNUM)
216# define MIDI_STREAM_OUT_EPADDR (ENDPOINT_DIR_OUT | MIDI_STREAM_OUT_EPNUM)
217#endif 225#endif
218 226
219#ifdef VIRTSER_ENABLE 227#ifdef VIRTSER_ENABLE
220 CDC_NOTIFICATION_EPNUM = NEXT_EPNUM, 228 CDC_NOTIFICATION_EPNUM = NEXT_EPNUM,
221 CDC_IN_EPNUM = NEXT_EPNUM, 229 CDC_IN_EPNUM = NEXT_EPNUM,
222 CDC_OUT_EPNUM = NEXT_EPNUM, 230 CDC_OUT_EPNUM = NEXT_EPNUM,
223# define CDC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | CDC_NOTIFICATION_EPNUM) 231#endif
224# define CDC_IN_EPADDR (ENDPOINT_DIR_IN | CDC_IN_EPNUM) 232#ifdef JOYSTICK_ENABLE
225# define CDC_OUT_EPADDR (ENDPOINT_DIR_OUT | CDC_OUT_EPNUM) 233 JOYSTICK_IN_EPNUM = NEXT_EPNUM,
234 JOYSTICK_OUT_EPNUM = NEXT_EPNUM,
226#endif 235#endif
227}; 236};
228 237
@@ -248,6 +257,7 @@ enum usb_endpoints {
248#define MIDI_STREAM_EPSIZE 64 257#define MIDI_STREAM_EPSIZE 64
249#define CDC_NOTIFICATION_EPSIZE 8 258#define CDC_NOTIFICATION_EPSIZE 8
250#define CDC_EPSIZE 16 259#define CDC_EPSIZE 16
260#define JOYSTICK_EPSIZE 8
251 261
252uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const void** const DescriptorAddress); 262uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const void** const DescriptorAddress);
253#endif 263#endif
diff --git a/tmk_core/protocol/vusb.mk b/tmk_core/protocol/vusb.mk
index 5e564f748..1de600308 100644
--- a/tmk_core/protocol/vusb.mk
+++ b/tmk_core/protocol/vusb.mk
@@ -9,13 +9,6 @@ SRC += $(VUSB_DIR)/main.c \
9 $(VUSB_PATH)/usbdrv/usbdrvasm.S \ 9 $(VUSB_PATH)/usbdrv/usbdrvasm.S \
10 $(VUSB_PATH)/usbdrv/oddebug.c 10 $(VUSB_PATH)/usbdrv/oddebug.c
11 11
12ifneq ($(strip $(CONSOLE_ENABLE)), yes)
13ifndef NO_UART
14SRC += $(COMMON_DIR)/sendchar_uart.c \
15 $(COMMON_DIR)/uart.c
16endif
17endif
18
19# Search Path 12# Search Path
20VPATH += $(TMK_PATH)/$(VUSB_DIR) 13VPATH += $(TMK_PATH)/$(VUSB_DIR)
21VPATH += $(VUSB_PATH) 14VPATH += $(VUSB_PATH)
diff --git a/tmk_core/protocol/vusb/main.c b/tmk_core/protocol/vusb/main.c
index b4063273d..a57df5ce0 100644
--- a/tmk_core/protocol/vusb/main.c
+++ b/tmk_core/protocol/vusb/main.c
@@ -7,19 +7,22 @@
7 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) 7 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
8 * This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $ 8 * This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $
9 */ 9 */
10
10#include <stdint.h> 11#include <stdint.h>
12
11#include <avr/interrupt.h> 13#include <avr/interrupt.h>
14#include <avr/power.h>
12#include <avr/wdt.h> 15#include <avr/wdt.h>
13#include <avr/sleep.h> 16#include <avr/sleep.h>
14#include <util/delay.h> 17
15#include <usbdrv/usbdrv.h> 18#include <usbdrv/usbdrv.h>
16#include <usbdrv/oddebug.h> 19
17#include "vusb.h" 20#include "vusb.h"
21
18#include "keyboard.h" 22#include "keyboard.h"
19#include "host.h" 23#include "host.h"
20#include "timer.h" 24#include "timer.h"
21#include "uart.h" 25#include "print.h"
22#include "debug.h"
23#include "suspend.h" 26#include "suspend.h"
24#include "wait.h" 27#include "wait.h"
25#include "sendchar.h" 28#include "sendchar.h"
@@ -28,8 +31,6 @@
28# include "sleep_led.h" 31# include "sleep_led.h"
29#endif 32#endif
30 33
31#define UART_BAUD_RATE 115200
32
33#ifdef CONSOLE_ENABLE 34#ifdef CONSOLE_ENABLE
34void console_task(void); 35void console_task(void);
35#endif 36#endif
@@ -47,7 +48,7 @@ static void initForUsbConnectivity(void) {
47 usbDeviceDisconnect(); /* do this while interrupts are disabled */ 48 usbDeviceDisconnect(); /* do this while interrupts are disabled */
48 while (--i) { /* fake USB disconnect for > 250 ms */ 49 while (--i) { /* fake USB disconnect for > 250 ms */
49 wdt_reset(); 50 wdt_reset();
50 _delay_ms(1); 51 wait_ms(1);
51 } 52 }
52 usbDeviceConnect(); 53 usbDeviceConnect();
53} 54}
@@ -60,7 +61,7 @@ static void usb_remote_wakeup(void) {
60 USBDDR = ddr_orig | USBMASK; 61 USBDDR = ddr_orig | USBMASK;
61 USBOUT ^= USBMASK; 62 USBOUT ^= USBMASK;
62 63
63 _delay_ms(25); 64 wait_ms(25);
64 65
65 USBOUT ^= USBMASK; 66 USBOUT ^= USBMASK;
66 USBDDR = ddr_orig; 67 USBDDR = ddr_orig;
@@ -74,7 +75,6 @@ static void usb_remote_wakeup(void) {
74 * FIXME: Needs doc 75 * FIXME: Needs doc
75 */ 76 */
76static void setup_usb(void) { 77static void setup_usb(void) {
77 // debug("initForUsbConnectivity()\n");
78 initForUsbConnectivity(); 78 initForUsbConnectivity();
79 79
80 // for Console_Task 80 // for Console_Task
@@ -95,10 +95,7 @@ int main(void) {
95#ifdef CLKPR 95#ifdef CLKPR
96 // avoid unintentional changes of clock frequency in devices that have a 96 // avoid unintentional changes of clock frequency in devices that have a
97 // clock prescaler 97 // clock prescaler
98 CLKPR = 0x80, CLKPR = 0; 98 clock_prescale_set(clock_div_1);
99#endif
100#ifndef NO_UART
101 uart_init(UART_BAUD_RATE);
102#endif 99#endif
103 keyboard_setup(); 100 keyboard_setup();
104 101
@@ -113,7 +110,6 @@ int main(void) {
113 sleep_led_init(); 110 sleep_led_init();
114#endif 111#endif
115 112
116 debug("main loop\n");
117 while (1) { 113 while (1) {
118#if USB_COUNT_SOF 114#if USB_COUNT_SOF
119 if (usbSofCount != 0) { 115 if (usbSofCount != 0) {
@@ -130,19 +126,6 @@ int main(void) {
130# ifdef SLEEP_LED_ENABLE 126# ifdef SLEEP_LED_ENABLE
131 sleep_led_enable(); 127 sleep_led_enable();
132# endif 128# endif
133 /*
134 uart_putchar('S');
135 _delay_ms(1);
136 cli();
137 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
138 sleep_enable();
139 sleep_bod_disable();
140 sei();
141 sleep_cpu();
142 sleep_disable();
143 _delay_ms(10);
144 uart_putchar('W');
145 */
146 } 129 }
147 } 130 }
148#endif 131#endif
diff --git a/tmk_core/protocol/vusb/sendchar_usart.c b/tmk_core/protocol/vusb/sendchar_usart.c
deleted file mode 100644
index a920a9a53..000000000
--- a/tmk_core/protocol/vusb/sendchar_usart.c
+++ /dev/null
@@ -1,19 +0,0 @@
1/*
2 * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
3 * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
4 */
5#include <stdint.h>
6#include <usbdrv/oddebug.h>
7#include "sendchar.h"
8
9#if DEBUG_LEVEL > 0
10/* from oddebug.c */
11int8_t sendchar(uint8_t c) {
12 while (!(ODDBG_USR & (1 << ODDBG_UDRE)))
13 ; /* wait for data register empty */
14 ODDBG_UDR = c;
15 return 1;
16}
17#else
18int8_t sendchar(uint8_t c) { return 1; }
19#endif
diff --git a/tmk_core/protocol/vusb/usbconfig.h b/tmk_core/protocol/vusb/usbconfig.h
index dcef7584c..041f7bd09 100644
--- a/tmk_core/protocol/vusb/usbconfig.h
+++ b/tmk_core/protocol/vusb/usbconfig.h
@@ -85,9 +85,19 @@ section at the end of this file).
85/* If the so-called endpoint 3 is used, it can now be configured to any other 85/* If the so-called endpoint 3 is used, it can now be configured to any other
86 * endpoint number (except 0) with this macro. Default if undefined is 3. 86 * endpoint number (except 0) with this macro. Default if undefined is 3.
87 */ 87 */
88#define USB_CFG_HAVE_INTRIN_ENDPOINT4 1
89/* Define this to 1 if you want to compile a version with three endpoints: The
90 * default control endpoint 0, an interrupt-in endpoint 4 (or the number
91 * configured below) and a catch-all default interrupt-in endpoint as above.
92 * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature.
93 */
94#define USB_CFG_EP4_NUMBER 4
95/* If the so-called endpoint 4 is used, it can now be configured to any other
96 * endpoint number (except 0) with this macro. Default if undefined is 4.
97 */
88/* #define USB_INITIAL_DATATOKEN USBPID_DATA1 */ 98/* #define USB_INITIAL_DATATOKEN USBPID_DATA1 */
89/* The above macro defines the startup condition for data toggling on the 99/* The above macro defines the startup condition for data toggling on the
90 * interrupt/bulk endpoints 1 and 3. Defaults to USBPID_DATA1. 100 * interrupt/bulk endpoints 1, 3 and 4. Defaults to USBPID_DATA1.
91 * Since the token is toggled BEFORE sending any data, the first packet is 101 * Since the token is toggled BEFORE sending any data, the first packet is
92 * sent with the oposite value of this configuration! 102 * sent with the oposite value of this configuration!
93 */ 103 */
@@ -100,10 +110,10 @@ section at the end of this file).
100#define USB_CFG_SUPPRESS_INTR_CODE 0 110#define USB_CFG_SUPPRESS_INTR_CODE 0
101/* Define this to 1 if you want to declare interrupt-in endpoints, but don't 111/* Define this to 1 if you want to declare interrupt-in endpoints, but don't
102 * want to send any data over them. If this macro is defined to 1, functions 112 * want to send any data over them. If this macro is defined to 1, functions
103 * usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if 113 * usbSetInterrupt(), usbSetInterrupt3() and usbSetInterrupt4() are omitted.
104 * you need the interrupt-in endpoints in order to comply to an interface 114 * This is useful if you need the interrupt-in endpoints in order to comply
105 * (e.g. HID), but never want to send any data. This option saves a couple 115 * to an interface (e.g. HID), but never want to send any data. This option
106 * of bytes in flash memory and the transmit buffers in RAM. 116 * saves a couple of bytes in flash memory and the transmit buffers in RAM.
107 */ 117 */
108#define USB_CFG_IS_SELF_POWERED 0 118#define USB_CFG_IS_SELF_POWERED 0
109/* Define this to 1 if the device has its own power supply. Set it to 0 if the 119/* Define this to 1 if the device has its own power supply. Set it to 0 if the
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index 5feff889a..77bbbd7bd 100644
--- a/tmk_core/protocol/vusb/vusb.c
+++ b/tmk_core/protocol/vusb/vusb.c
@@ -15,10 +15,12 @@ You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>. 15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17 17
18#include <avr/wdt.h>
19#include <util/delay.h>
20#include <stdint.h> 18#include <stdint.h>
19
20#include <avr/wdt.h>
21
21#include <usbdrv/usbdrv.h> 22#include <usbdrv/usbdrv.h>
23
22#include "usbconfig.h" 24#include "usbconfig.h"
23#include "host.h" 25#include "host.h"
24#include "report.h" 26#include "report.h"
@@ -26,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
26#include "vusb.h" 28#include "vusb.h"
27#include "print.h" 29#include "print.h"
28#include "debug.h" 30#include "debug.h"
31#include "wait.h"
29#include "usb_descriptor_common.h" 32#include "usb_descriptor_common.h"
30 33
31#ifdef RAW_ENABLE 34#ifdef RAW_ENABLE
@@ -56,16 +59,20 @@ enum usb_interfaces {
56#ifdef CONSOLE_ENABLE 59#ifdef CONSOLE_ENABLE
57 CONSOLE_INTERFACE = NEXT_INTERFACE, 60 CONSOLE_INTERFACE = NEXT_INTERFACE,
58#endif 61#endif
59 TOTAL_INTERFACES = NEXT_INTERFACE, 62 TOTAL_INTERFACES = NEXT_INTERFACE
60}; 63};
61 64
62#define MAX_INTERFACES 2 65#define MAX_INTERFACES 3
63 66
64#if (NEXT_INTERFACE - 1) > MAX_INTERFACES 67#if (NEXT_INTERFACE - 1) > MAX_INTERFACES
65# error There are not enough available interfaces to support all functions. Please disable one or more of the following: Mouse Keys, Extra Keys, Raw HID, Console 68# error There are not enough available interfaces to support all functions. Please disable one or more of the following: Mouse Keys, Extra Keys, Raw HID, Console
66#endif 69#endif
67 70
68static uint8_t vusb_keyboard_leds = 0; 71#if (defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)) && CONSOLE_ENABLE
72# error Mouse/Extra Keys share an endpoint with Console. Please disable one of the two.
73#endif
74
75static uint8_t keyboard_led_state = 0;
69static uint8_t vusb_idle_rate = 0; 76static uint8_t vusb_idle_rate = 0;
70 77
71/* Keyboard report send buffer */ 78/* Keyboard report send buffer */
@@ -74,13 +81,7 @@ static report_keyboard_t kbuf[KBUF_SIZE];
74static uint8_t kbuf_head = 0; 81static uint8_t kbuf_head = 0;
75static uint8_t kbuf_tail = 0; 82static uint8_t kbuf_tail = 0;
76 83
77typedef struct { 84static report_keyboard_t keyboard_report_sent;
78 uint8_t modifier;
79 uint8_t reserved;
80 uint8_t keycode[6];
81} keyboard_report_t;
82
83static keyboard_report_t keyboard_report; // sent to PC
84 85
85#define VUSB_TRANSFER_KEYBOARD_MAX_TRIES 10 86#define VUSB_TRANSFER_KEYBOARD_MAX_TRIES 10
86 87
@@ -92,19 +93,13 @@ void vusb_transfer_keyboard(void) {
92 usbSetInterrupt((void *)&kbuf[kbuf_tail], sizeof(report_keyboard_t)); 93 usbSetInterrupt((void *)&kbuf[kbuf_tail], sizeof(report_keyboard_t));
93 kbuf_tail = (kbuf_tail + 1) % KBUF_SIZE; 94 kbuf_tail = (kbuf_tail + 1) % KBUF_SIZE;
94 if (debug_keyboard) { 95 if (debug_keyboard) {
95 print("V-USB: kbuf["); 96 dprintf("V-USB: kbuf[%d->%d](%02X)\n", kbuf_tail, kbuf_head, (kbuf_head < kbuf_tail) ? (KBUF_SIZE - kbuf_tail + kbuf_head) : (kbuf_head - kbuf_tail));
96 pdec(kbuf_tail);
97 print("->");
98 pdec(kbuf_head);
99 print("](");
100 phex((kbuf_head < kbuf_tail) ? (KBUF_SIZE - kbuf_tail + kbuf_head) : (kbuf_head - kbuf_tail));
101 print(")\n");
102 } 97 }
103 } 98 }
104 break; 99 break;
105 } 100 }
106 usbPoll(); 101 usbPoll();
107 _delay_ms(1); 102 wait_ms(1);
108 } 103 }
109} 104}
110 105
@@ -125,16 +120,16 @@ void raw_hid_send(uint8_t *data, uint8_t length) {
125 120
126 uint8_t *temp = data; 121 uint8_t *temp = data;
127 for (uint8_t i = 0; i < 4; i++) { 122 for (uint8_t i = 0; i < 4; i++) {
128 while (!usbInterruptIsReady3()) { 123 while (!usbInterruptIsReady4()) {
129 usbPoll(); 124 usbPoll();
130 } 125 }
131 usbSetInterrupt3(temp, 8); 126 usbSetInterrupt4(temp, 8);
132 temp += 8; 127 temp += 8;
133 } 128 }
134 while (!usbInterruptIsReady3()) { 129 while (!usbInterruptIsReady4()) {
135 usbPoll(); 130 usbPoll();
136 } 131 }
137 usbSetInterrupt3(0, 0); 132 usbSetInterrupt4(0, 0);
138} 133}
139 134
140__attribute__((weak)) void raw_hid_receive(uint8_t *data, uint8_t length) { 135__attribute__((weak)) void raw_hid_receive(uint8_t *data, uint8_t length) {
@@ -218,7 +213,7 @@ static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_sy
218 213
219host_driver_t *vusb_driver(void) { return &driver; } 214host_driver_t *vusb_driver(void) { return &driver; }
220 215
221static uint8_t keyboard_leds(void) { return vusb_keyboard_leds; } 216static uint8_t keyboard_leds(void) { return keyboard_led_state; }
222 217
223static void send_keyboard(report_keyboard_t *report) { 218static void send_keyboard(report_keyboard_t *report) {
224 uint8_t next = (kbuf_head + 1) % KBUF_SIZE; 219 uint8_t next = (kbuf_head + 1) % KBUF_SIZE;
@@ -226,12 +221,13 @@ static void send_keyboard(report_keyboard_t *report) {
226 kbuf[kbuf_head] = *report; 221 kbuf[kbuf_head] = *report;
227 kbuf_head = next; 222 kbuf_head = next;
228 } else { 223 } else {
229 debug("kbuf: full\n"); 224 dprint("kbuf: full\n");
230 } 225 }
231 226
232 // NOTE: send key strokes of Macro 227 // NOTE: send key strokes of Macro
233 usbPoll(); 228 usbPoll();
234 vusb_transfer_keyboard(); 229 vusb_transfer_keyboard();
230 keyboard_report_sent = *report;
235} 231}
236 232
237typedef struct { 233typedef struct {
@@ -288,36 +284,35 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) {
288 284
289 if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { /* class request type */ 285 if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { /* class request type */
290 if (rq->bRequest == USBRQ_HID_GET_REPORT) { 286 if (rq->bRequest == USBRQ_HID_GET_REPORT) {
291 debug("GET_REPORT:"); 287 dprint("GET_REPORT:");
292 /* we only have one report type, so don't look at wValue */ 288 if (rq->wIndex.word == KEYBOARD_INTERFACE) {
293 usbMsgPtr = (usbMsgPtr_t)&keyboard_report; 289 usbMsgPtr = (usbMsgPtr_t)&keyboard_report_sent;
294 return sizeof(keyboard_report); 290 return sizeof(keyboard_report_sent);
291 }
295 } else if (rq->bRequest == USBRQ_HID_GET_IDLE) { 292 } else if (rq->bRequest == USBRQ_HID_GET_IDLE) {
296 debug("GET_IDLE: "); 293 dprint("GET_IDLE:");
297 // debug_hex(vusb_idle_rate);
298 usbMsgPtr = (usbMsgPtr_t)&vusb_idle_rate; 294 usbMsgPtr = (usbMsgPtr_t)&vusb_idle_rate;
299 return 1; 295 return 1;
300 } else if (rq->bRequest == USBRQ_HID_SET_IDLE) { 296 } else if (rq->bRequest == USBRQ_HID_SET_IDLE) {
301 vusb_idle_rate = rq->wValue.bytes[1]; 297 vusb_idle_rate = rq->wValue.bytes[1];
302 debug("SET_IDLE: "); 298 dprintf("SET_IDLE: %02X", vusb_idle_rate);
303 debug_hex(vusb_idle_rate);
304 } else if (rq->bRequest == USBRQ_HID_SET_REPORT) { 299 } else if (rq->bRequest == USBRQ_HID_SET_REPORT) {
305 debug("SET_REPORT: "); 300 dprint("SET_REPORT:");
306 // Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard) 301 // Report Type: 0x02(Out)/ReportID: 0x00(none) && Interface: 0(keyboard)
307 if (rq->wValue.word == 0x0200 && rq->wIndex.word == 0) { 302 if (rq->wValue.word == 0x0200 && rq->wIndex.word == KEYBOARD_INTERFACE) {
308 debug("SET_LED: "); 303 dprint("SET_LED:");
309 last_req.kind = SET_LED; 304 last_req.kind = SET_LED;
310 last_req.len = rq->wLength.word; 305 last_req.len = rq->wLength.word;
311 } 306 }
312 return USB_NO_MSG; // to get data in usbFunctionWrite 307 return USB_NO_MSG; // to get data in usbFunctionWrite
313 } else { 308 } else {
314 debug("UNKNOWN:"); 309 dprint("UNKNOWN:");
315 } 310 }
316 } else { 311 } else {
317 debug("VENDOR:"); 312 dprint("VENDOR:");
318 /* no vendor specific requests implemented */ 313 /* no vendor specific requests implemented */
319 } 314 }
320 debug("\n"); 315 dprint("\n");
321 return 0; /* default for not implemented requests: return no data back to host */ 316 return 0; /* default for not implemented requests: return no data back to host */
322} 317}
323 318
@@ -327,10 +322,8 @@ uchar usbFunctionWrite(uchar *data, uchar len) {
327 } 322 }
328 switch (last_req.kind) { 323 switch (last_req.kind) {
329 case SET_LED: 324 case SET_LED:
330 debug("SET_LED: "); 325 dprintf("SET_LED: %02X\n", data[0]);
331 debug_hex(data[0]); 326 keyboard_led_state = data[0];
332 debug("\n");
333 vusb_keyboard_leds = data[0];
334 last_req.len = 0; 327 last_req.len = 0;
335 return 1; 328 return 1;
336 break; 329 break;
@@ -346,13 +339,13 @@ void usbFunctionWriteOut(uchar *data, uchar len) {
346#ifdef RAW_ENABLE 339#ifdef RAW_ENABLE
347 // Data from host must be divided every 8bytes 340 // Data from host must be divided every 8bytes
348 if (len != 8) { 341 if (len != 8) {
349 debug("RAW: invalid length"); 342 dprint("RAW: invalid length\n");
350 raw_output_received_bytes = 0; 343 raw_output_received_bytes = 0;
351 return; 344 return;
352 } 345 }
353 346
354 if (raw_output_received_bytes + len > RAW_BUFFER_SIZE) { 347 if (raw_output_received_bytes + len > RAW_BUFFER_SIZE) {
355 debug("RAW: buffer full"); 348 dprint("RAW: buffer full\n");
356 raw_output_received_bytes = 0; 349 raw_output_received_bytes = 0;
357 } else { 350 } else {
358 for (uint8_t i = 0; i < 8; i++) { 351 for (uint8_t i = 0; i < 8; i++) {
@@ -408,29 +401,6 @@ const PROGMEM uchar keyboard_hid_report[] = {
408 0xC0 // End Collection 401 0xC0 // End Collection
409}; 402};
410 403
411#ifdef RAW_ENABLE
412const PROGMEM uchar raw_hid_report[] = {
413 0x06, RAW_USAGE_PAGE_LO, RAW_USAGE_PAGE_HI, // Usage Page (Vendor Defined)
414 0x09, RAW_USAGE_ID, // Usage (Vendor Defined)
415 0xA1, 0x01, // Collection (Application)
416 // Data to host
417 0x09, 0x62, // Usage (Vendor Defined)
418 0x15, 0x00, // Logical Minimum (0)
419 0x26, 0xFF, 0x00, // Logical Maximum (255)
420 0x95, RAW_BUFFER_SIZE, // Report Count
421 0x75, 0x08, // Report Size (8)
422 0x81, 0x02, // Input (Data, Variable, Absolute)
423 // Data from host
424 0x09, 0x63, // Usage (Vendor Defined)
425 0x15, 0x00, // Logical Minimum (0)
426 0x26, 0xFF, 0x00, // Logical Maximum (255)
427 0x95, RAW_BUFFER_SIZE, // Report Count
428 0x75, 0x08, // Report Size (8)
429 0x91, 0x02, // Output (Data, Variable, Absolute)
430 0xC0 // End Collection
431};
432#endif
433
434#if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE) 404#if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE)
435const PROGMEM uchar mouse_extra_hid_report[] = { 405const PROGMEM uchar mouse_extra_hid_report[] = {
436# ifdef MOUSE_ENABLE 406# ifdef MOUSE_ENABLE
@@ -515,6 +485,29 @@ const PROGMEM uchar mouse_extra_hid_report[] = {
515}; 485};
516#endif 486#endif
517 487
488#ifdef RAW_ENABLE
489const PROGMEM uchar raw_hid_report[] = {
490 0x06, RAW_USAGE_PAGE_LO, RAW_USAGE_PAGE_HI, // Usage Page (Vendor Defined)
491 0x09, RAW_USAGE_ID, // Usage (Vendor Defined)
492 0xA1, 0x01, // Collection (Application)
493 // Data to host
494 0x09, 0x62, // Usage (Vendor Defined)
495 0x15, 0x00, // Logical Minimum (0)
496 0x26, 0xFF, 0x00, // Logical Maximum (255)
497 0x95, RAW_BUFFER_SIZE, // Report Count
498 0x75, 0x08, // Report Size (8)
499 0x81, 0x02, // Input (Data, Variable, Absolute)
500 // Data from host
501 0x09, 0x63, // Usage (Vendor Defined)
502 0x15, 0x00, // Logical Minimum (0)
503 0x26, 0xFF, 0x00, // Logical Maximum (255)
504 0x95, RAW_BUFFER_SIZE, // Report Count
505 0x75, 0x08, // Report Size (8)
506 0x91, 0x02, // Output (Data, Variable, Absolute)
507 0xC0 // End Collection
508};
509#endif
510
518#if defined(CONSOLE_ENABLE) 511#if defined(CONSOLE_ENABLE)
519const PROGMEM uchar console_hid_report[] = { 512const PROGMEM uchar console_hid_report[] = {
520 0x06, 0x31, 0xFF, // Usage Page (Vendor Defined - PJRC Teensy compatible) 513 0x06, 0x31, 0xFF, // Usage Page (Vendor Defined - PJRC Teensy compatible)
@@ -694,7 +687,7 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
694 .bLength = sizeof(usbEndpointDescriptor_t), 687 .bLength = sizeof(usbEndpointDescriptor_t),
695 .bDescriptorType = USBDESCR_ENDPOINT 688 .bDescriptorType = USBDESCR_ENDPOINT
696 }, 689 },
697 .bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | USB_CFG_EP3_NUMBER), 690 .bEndpointAddress = (USBRQ_DIR_DEVICE_TO_HOST | USB_CFG_EP4_NUMBER),
698 .bmAttributes = 0x03, 691 .bmAttributes = 0x03,
699 .wMaxPacketSize = RAW_EPSIZE, 692 .wMaxPacketSize = RAW_EPSIZE,
700 .bInterval = USB_POLLING_INTERVAL_MS 693 .bInterval = USB_POLLING_INTERVAL_MS
@@ -704,7 +697,7 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
704 .bLength = sizeof(usbEndpointDescriptor_t), 697 .bLength = sizeof(usbEndpointDescriptor_t),
705 .bDescriptorType = USBDESCR_ENDPOINT 698 .bDescriptorType = USBDESCR_ENDPOINT
706 }, 699 },
707 .bEndpointAddress = (USBRQ_DIR_HOST_TO_DEVICE | USB_CFG_EP3_NUMBER), 700 .bEndpointAddress = (USBRQ_DIR_HOST_TO_DEVICE | USB_CFG_EP4_NUMBER),
708 .bmAttributes = 0x03, 701 .bmAttributes = 0x03,
709 .wMaxPacketSize = RAW_EPSIZE, 702 .wMaxPacketSize = RAW_EPSIZE,
710 .bInterval = USB_POLLING_INTERVAL_MS 703 .bInterval = USB_POLLING_INTERVAL_MS
@@ -805,14 +798,6 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
805USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) { 798USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) {
806 usbMsgLen_t len = 0; 799 usbMsgLen_t len = 0;
807 800
808 /*
809 debug("usbFunctionDescriptor: ");
810 debug_hex(rq->bmRequestType); debug(" ");
811 debug_hex(rq->bRequest); debug(" ");
812 debug_hex16(rq->wValue.word); debug(" ");
813 debug_hex16(rq->wIndex.word); debug(" ");
814 debug_hex16(rq->wLength.word); debug("\n");
815 */
816 switch (rq->wValue.bytes[1]) { 801 switch (rq->wValue.bytes[1]) {
817 case USBDESCR_DEVICE: 802 case USBDESCR_DEVICE:
818 usbMsgPtr = (usbMsgPtr_t)&usbDeviceDescriptor; 803 usbMsgPtr = (usbMsgPtr_t)&usbDeviceDescriptor;
@@ -896,6 +881,5 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) {
896 } 881 }
897 break; 882 break;
898 } 883 }
899 // debug("desc len: "); debug_hex(len); debug("\n");
900 return len; 884 return len;
901} 885}