aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/action_util.c6
-rw-r--r--common/command.c4
-rw-r--r--common/host.c2
-rw-r--r--common/host.h3
-rw-r--r--protocol/lufa/lufa.c47
-rw-r--r--protocol/pjrc/usb.c18
-rw-r--r--protocol/pjrc/usb_keyboard.c11
-rw-r--r--protocol/pjrc/usb_keyboard.h2
8 files changed, 47 insertions, 46 deletions
diff --git a/common/action_util.c b/common/action_util.c
index 99a3adaab..ebe7150dc 100644
--- a/common/action_util.c
+++ b/common/action_util.c
@@ -67,7 +67,7 @@ void send_keyboard_report(void) {
67void add_key(uint8_t key) 67void add_key(uint8_t key)
68{ 68{
69#ifdef NKRO_ENABLE 69#ifdef NKRO_ENABLE
70 if (keyboard_nkro) { 70 if (keyboard_nkro && keyboard_protocol) {
71 add_key_bit(key); 71 add_key_bit(key);
72 return; 72 return;
73 } 73 }
@@ -78,7 +78,7 @@ void add_key(uint8_t key)
78void del_key(uint8_t key) 78void del_key(uint8_t key)
79{ 79{
80#ifdef NKRO_ENABLE 80#ifdef NKRO_ENABLE
81 if (keyboard_nkro) { 81 if (keyboard_nkro && keyboard_protocol) {
82 del_key_bit(key); 82 del_key_bit(key);
83 return; 83 return;
84 } 84 }
@@ -151,7 +151,7 @@ uint8_t has_anymod(void)
151uint8_t get_first_key(void) 151uint8_t get_first_key(void)
152{ 152{
153#ifdef NKRO_ENABLE 153#ifdef NKRO_ENABLE
154 if (keyboard_nkro) { 154 if (keyboard_nkro && keyboard_protocol) {
155 uint8_t i = 0; 155 uint8_t i = 0;
156 for (; i < REPORT_BITS && !keyboard_report->nkro.bits[i]; i++) 156 for (; i < REPORT_BITS && !keyboard_report->nkro.bits[i]; i++)
157 ; 157 ;
diff --git a/common/command.c b/common/command.c
index f6f276951..d2f8eb832 100644
--- a/common/command.c
+++ b/common/command.c
@@ -301,13 +301,13 @@ static bool command_common(uint8_t code)
301 case KC_S: 301 case KC_S:
302 print("\n\n----- Status -----\n"); 302 print("\n\n----- Status -----\n");
303 print_val_hex8(host_keyboard_leds()); 303 print_val_hex8(host_keyboard_leds());
304 print_val_hex8(keyboard_protocol);
305 print_val_hex8(keyboard_idle);
304#ifdef PROTOCOL_PJRC 306#ifdef PROTOCOL_PJRC
305 print_val_hex8(UDCON); 307 print_val_hex8(UDCON);
306 print_val_hex8(UDIEN); 308 print_val_hex8(UDIEN);
307 print_val_hex8(UDINT); 309 print_val_hex8(UDINT);
308 print_val_hex8(usb_keyboard_leds); 310 print_val_hex8(usb_keyboard_leds);
309 print_val_hex8(usb_keyboard_protocol);
310 print_val_hex8(usb_keyboard_idle_config);
311 print_val_hex8(usb_keyboard_idle_count); 311 print_val_hex8(usb_keyboard_idle_count);
312#endif 312#endif
313 313
diff --git a/common/host.c b/common/host.c
index 1eafef75c..2e56971bd 100644
--- a/common/host.c
+++ b/common/host.c
@@ -24,7 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
24 24
25 25
26#ifdef NKRO_ENABLE 26#ifdef NKRO_ENABLE
27bool keyboard_nkro = false; 27bool keyboard_nkro = true;
28#endif 28#endif
29 29
30static host_driver_t *driver; 30static host_driver_t *driver;
diff --git a/common/host.h b/common/host.h
index 8ff262985..a56e6c3b0 100644
--- a/common/host.h
+++ b/common/host.h
@@ -32,6 +32,9 @@ extern "C" {
32extern bool keyboard_nkro; 32extern bool keyboard_nkro;
33#endif 33#endif
34 34
35uint8_t keyboard_idle;
36uint8_t keyboard_protocol;
37
35 38
36/* host driver */ 39/* host driver */
37void host_set_driver(host_driver_t *driver); 40void host_set_driver(host_driver_t *driver);
diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c
index 86e9f23d1..a43a552a8 100644
--- a/protocol/lufa/lufa.c
+++ b/protocol/lufa/lufa.c
@@ -52,8 +52,8 @@
52#include "descriptor.h" 52#include "descriptor.h"
53#include "lufa.h" 53#include "lufa.h"
54 54
55static uint8_t idle_duration = 0; 55uint8_t keyboard_idle = 0;
56static uint8_t protocol_report = 1; 56uint8_t keyboard_protocol = 1;
57static uint8_t keyboard_led_stats = 0; 57static uint8_t keyboard_led_stats = 0;
58 58
59static report_keyboard_t keyboard_report_sent; 59static report_keyboard_t keyboard_report_sent;
@@ -290,21 +290,26 @@ void EVENT_USB_Device_ControlRequest(void)
290 case HID_REQ_GetProtocol: 290 case HID_REQ_GetProtocol:
291 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) 291 if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
292 { 292 {
293 Endpoint_ClearSETUP(); 293 if (USB_ControlRequest.wIndex == KEYBOARD_INTERFACE) {
294 while (!(Endpoint_IsINReady())); 294 Endpoint_ClearSETUP();
295 Endpoint_Write_8(protocol_report); 295 while (!(Endpoint_IsINReady()));
296 Endpoint_ClearIN(); 296 Endpoint_Write_8(keyboard_protocol);
297 Endpoint_ClearStatusStage(); 297 Endpoint_ClearIN();
298 Endpoint_ClearStatusStage();
299 }
298 } 300 }
299 301
300 break; 302 break;
301 case HID_REQ_SetProtocol: 303 case HID_REQ_SetProtocol:
302 if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) 304 if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
303 { 305 {
304 Endpoint_ClearSETUP(); 306 if (USB_ControlRequest.wIndex == KEYBOARD_INTERFACE) {
305 Endpoint_ClearStatusStage(); 307 Endpoint_ClearSETUP();
308 Endpoint_ClearStatusStage();
306 309
307 protocol_report = ((USB_ControlRequest.wValue & 0xFF) != 0x00); 310 keyboard_protocol = ((USB_ControlRequest.wValue & 0xFF) != 0x00);
311 clear_keyboard();
312 }
308 } 313 }
309 314
310 break; 315 break;
@@ -314,7 +319,7 @@ void EVENT_USB_Device_ControlRequest(void)
314 Endpoint_ClearSETUP(); 319 Endpoint_ClearSETUP();
315 Endpoint_ClearStatusStage(); 320 Endpoint_ClearStatusStage();
316 321
317 idle_duration = ((USB_ControlRequest.wValue & 0xFF00) >> 8); 322 keyboard_idle = ((USB_ControlRequest.wValue & 0xFF00) >> 8);
318 } 323 }
319 324
320 break; 325 break;
@@ -323,7 +328,7 @@ void EVENT_USB_Device_ControlRequest(void)
323 { 328 {
324 Endpoint_ClearSETUP(); 329 Endpoint_ClearSETUP();
325 while (!(Endpoint_IsINReady())); 330 while (!(Endpoint_IsINReady()));
326 Endpoint_Write_8(idle_duration); 331 Endpoint_Write_8(keyboard_idle);
327 Endpoint_ClearIN(); 332 Endpoint_ClearIN();
328 Endpoint_ClearStatusStage(); 333 Endpoint_ClearStatusStage();
329 } 334 }
@@ -349,32 +354,28 @@ static void send_keyboard(report_keyboard_t *report)
349 354
350 /* Select the Keyboard Report Endpoint */ 355 /* Select the Keyboard Report Endpoint */
351#ifdef NKRO_ENABLE 356#ifdef NKRO_ENABLE
352 if (keyboard_nkro) { 357 if (keyboard_nkro && keyboard_protocol) {
358 /* Report protocol - NKRO */
353 Endpoint_SelectEndpoint(NKRO_IN_EPNUM); 359 Endpoint_SelectEndpoint(NKRO_IN_EPNUM);
354 360
355 /* Check if write ready for a polling interval around 1ms */ 361 /* Check if write ready for a polling interval around 1ms */
356 while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(4); 362 while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(4);
357 if (!Endpoint_IsReadWriteAllowed()) return; 363 if (!Endpoint_IsReadWriteAllowed()) return;
364
365 /* Write Keyboard Report Data */
366 Endpoint_Write_Stream_LE(report, NKRO_EPSIZE, NULL);
358 } 367 }
359 else 368 else
360#endif 369#endif
361 { 370 {
371 /* Boot protocol */
362 Endpoint_SelectEndpoint(KEYBOARD_IN_EPNUM); 372 Endpoint_SelectEndpoint(KEYBOARD_IN_EPNUM);
363 373
364 /* Check if write ready for a polling interval around 10ms */ 374 /* Check if write ready for a polling interval around 10ms */
365 while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40); 375 while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40);
366 if (!Endpoint_IsReadWriteAllowed()) return; 376 if (!Endpoint_IsReadWriteAllowed()) return;
367 }
368 377
369 /* Write Keyboard Report Data */ 378 /* Write Keyboard Report Data */
370#ifdef NKRO_ENABLE
371 if (keyboard_nkro) {
372 Endpoint_Write_Stream_LE(report, NKRO_EPSIZE, NULL);
373 }
374 else
375#endif
376 {
377 /* boot mode */
378 Endpoint_Write_Stream_LE(report, KEYBOARD_EPSIZE, NULL); 379 Endpoint_Write_Stream_LE(report, KEYBOARD_EPSIZE, NULL);
379 } 380 }
380 381
diff --git a/protocol/pjrc/usb.c b/protocol/pjrc/usb.c
index 393b36f78..b09ad3f23 100644
--- a/protocol/pjrc/usb.c
+++ b/protocol/pjrc/usb.c
@@ -38,6 +38,7 @@
38#include "sleep_led.h" 38#include "sleep_led.h"
39#endif 39#endif
40#include "suspend.h" 40#include "suspend.h"
41#include "action.h"
41#include "action_util.h" 42#include "action_util.h"
42 43
43 44
@@ -692,20 +693,20 @@ ISR(USB_GEN_vect)
692 } 693 }
693 /* TODO: should keep IDLE rate on each keyboard interface */ 694 /* TODO: should keep IDLE rate on each keyboard interface */
694#ifdef NKRO_ENABLE 695#ifdef NKRO_ENABLE
695 if (!keyboard_nkro && usb_keyboard_idle_config && (++div4 & 3) == 0) { 696 if (!keyboard_nkro && keyboard_idle && (++div4 & 3) == 0) {
696#else 697#else
697 if (usb_keyboard_idle_config && (++div4 & 3) == 0) { 698 if (keyboard_idle && (++div4 & 3) == 0) {
698#endif 699#endif
699 UENUM = KBD_ENDPOINT; 700 UENUM = KBD_ENDPOINT;
700 if (UEINTX & (1<<RWAL)) { 701 if (UEINTX & (1<<RWAL)) {
701 usb_keyboard_idle_count++; 702 usb_keyboard_idle_count++;
702 if (usb_keyboard_idle_count == usb_keyboard_idle_config) { 703 if (usb_keyboard_idle_count == keyboard_idle) {
703 usb_keyboard_idle_count = 0; 704 usb_keyboard_idle_count = 0;
704 /* TODO: fix keyboard_report inconsistency */ 705 /* TODO: fix keyboard_report inconsistency */
705/* To avoid Mac SET_IDLE behaviour. 706/* To avoid Mac SET_IDLE behaviour.
706 UEDATX = keyboard_report_prev->mods; 707 UEDATX = keyboard_report_prev->mods;
707 UEDATX = 0; 708 UEDATX = 0;
708 uint8_t keys = usb_keyboard_protocol ? KBD_REPORT_KEYS : 6; 709 uint8_t keys = keyboard_protocol ? KBD_REPORT_KEYS : 6;
709 for (uint8_t i=0; i<keys; i++) { 710 for (uint8_t i=0; i<keys; i++) {
710 UEDATX = keyboard_report_prev->keys[i]; 711 UEDATX = keyboard_report_prev->keys[i];
711 } 712 }
@@ -901,13 +902,13 @@ ISR(USB_COM_vect)
901 } 902 }
902 if (bRequest == HID_GET_IDLE) { 903 if (bRequest == HID_GET_IDLE) {
903 usb_wait_in_ready(); 904 usb_wait_in_ready();
904 UEDATX = usb_keyboard_idle_config; 905 UEDATX = keyboard_idle;
905 usb_send_in(); 906 usb_send_in();
906 return; 907 return;
907 } 908 }
908 if (bRequest == HID_GET_PROTOCOL) { 909 if (bRequest == HID_GET_PROTOCOL) {
909 usb_wait_in_ready(); 910 usb_wait_in_ready();
910 UEDATX = usb_keyboard_protocol; 911 UEDATX = keyboard_protocol;
911 usb_send_in(); 912 usb_send_in();
912 return; 913 return;
913 } 914 }
@@ -921,14 +922,15 @@ ISR(USB_COM_vect)
921 return; 922 return;
922 } 923 }
923 if (bRequest == HID_SET_IDLE) { 924 if (bRequest == HID_SET_IDLE) {
924 usb_keyboard_idle_config = (wValue >> 8); 925 keyboard_idle = (wValue >> 8);
925 usb_keyboard_idle_count = 0; 926 usb_keyboard_idle_count = 0;
926 //usb_wait_in_ready(); 927 //usb_wait_in_ready();
927 usb_send_in(); 928 usb_send_in();
928 return; 929 return;
929 } 930 }
930 if (bRequest == HID_SET_PROTOCOL) { 931 if (bRequest == HID_SET_PROTOCOL) {
931 usb_keyboard_protocol = wValue; 932 keyboard_protocol = wValue;
933 clear_keyboard();
932 //usb_wait_in_ready(); 934 //usb_wait_in_ready();
933 usb_send_in(); 935 usb_send_in();
934 return; 936 return;
diff --git a/protocol/pjrc/usb_keyboard.c b/protocol/pjrc/usb_keyboard.c
index de798fcc2..c11995db6 100644
--- a/protocol/pjrc/usb_keyboard.c
+++ b/protocol/pjrc/usb_keyboard.c
@@ -34,12 +34,12 @@
34// protocol setting from the host. We use exactly the same report 34// protocol setting from the host. We use exactly the same report
35// either way, so this variable only stores the setting since we 35// either way, so this variable only stores the setting since we
36// are required to be able to report which setting is in use. 36// are required to be able to report which setting is in use.
37uint8_t usb_keyboard_protocol=1; 37uint8_t keyboard_protocol=1;
38 38
39// the idle configuration, how often we send the report to the 39// the idle configuration, how often we send the report to the
40// host (ms * 4) even when it hasn't changed 40// host (ms * 4) even when it hasn't changed
41// Windows and Linux set 0 while OS X sets 6(24ms) by SET_IDLE request. 41// Windows and Linux set 0 while OS X sets 6(24ms) by SET_IDLE request.
42uint8_t usb_keyboard_idle_config=125; 42uint8_t keyobard_idle=125;
43 43
44// count until idle timeout 44// count until idle timeout
45uint8_t usb_keyboard_idle_count=0; 45uint8_t usb_keyboard_idle_count=0;
@@ -56,15 +56,12 @@ int8_t usb_keyboard_send_report(report_keyboard_t *report)
56 int8_t result = 0; 56 int8_t result = 0;
57 57
58#ifdef NKRO_ENABLE 58#ifdef NKRO_ENABLE
59 if (keyboard_nkro) 59 if (keyboard_nkro && keyboard_protocol)
60 result = send_report(report, KBD2_ENDPOINT, 0, KBD2_SIZE); 60 result = send_report(report, KBD2_ENDPOINT, 0, KBD2_SIZE);
61 else 61 else
62#endif 62#endif
63 { 63 {
64 if (usb_keyboard_protocol) 64 result = send_report(report, KBD_ENDPOINT, 0, KBD_SIZE);
65 result = send_report(report, KBD_ENDPOINT, 0, KBD_SIZE);
66 else
67 result = send_report(report, KBD_ENDPOINT, 0, 6);
68 } 65 }
69 66
70 if (result) return result; 67 if (result) return result;
diff --git a/protocol/pjrc/usb_keyboard.h b/protocol/pjrc/usb_keyboard.h
index c362ca3b8..9b798e9a8 100644
--- a/protocol/pjrc/usb_keyboard.h
+++ b/protocol/pjrc/usb_keyboard.h
@@ -30,8 +30,6 @@
30#include "host.h" 30#include "host.h"
31 31
32 32
33extern uint8_t usb_keyboard_protocol;
34extern uint8_t usb_keyboard_idle_config;
35extern uint8_t usb_keyboard_idle_count; 33extern uint8_t usb_keyboard_idle_count;
36extern volatile uint8_t usb_keyboard_leds; 34extern volatile uint8_t usb_keyboard_leds;
37 35