summaryrefslogtreecommitdiff
path: root/tmk_core/protocol/vusb
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/protocol/vusb')
-rw-r--r--tmk_core/protocol/vusb/protocol.c89
-rw-r--r--tmk_core/protocol/vusb/vusb.c17
-rw-r--r--tmk_core/protocol/vusb/vusb.h1
3 files changed, 51 insertions, 56 deletions
diff --git a/tmk_core/protocol/vusb/protocol.c b/tmk_core/protocol/vusb/protocol.c
index 1f64561274..6178d48ef2 100644
--- a/tmk_core/protocol/vusb/protocol.c
+++ b/tmk_core/protocol/vusb/protocol.c
@@ -22,7 +22,7 @@
#include "keyboard.h"
#include "host.h"
#include "timer.h"
-#include "print.h"
+#include "debug.h"
#include "suspend.h"
#include "wait.h"
#include "sendchar.h"
@@ -53,7 +53,7 @@ static void initForUsbConnectivity(void) {
usbDeviceConnect();
}
-static void vusb_send_remote_wakeup(void) {
+static inline void vusb_send_remote_wakeup(void) {
cli();
uint8_t ddr_orig = USBDDR;
@@ -72,9 +72,7 @@ static void vusb_send_remote_wakeup(void) {
bool vusb_suspended = false;
-static void vusb_suspend(void) {
- vusb_suspended = true;
-
+static inline void vusb_suspend(void) {
#ifdef SLEEP_LED_ENABLE
sleep_led_enable();
#endif
@@ -82,16 +80,13 @@ static void vusb_suspend(void) {
suspend_power_down();
}
-#if USB_COUNT_SOF
-static void vusb_wakeup(void) {
- vusb_suspended = false;
+static inline void vusb_wakeup(void) {
suspend_wakeup_init();
-# ifdef SLEEP_LED_ENABLE
+#ifdef SLEEP_LED_ENABLE
sleep_led_disable();
-# endif
-}
#endif
+}
/** \brief Setup USB
*
@@ -125,49 +120,67 @@ void protocol_post_init(void) {
wait_ms(50);
}
-void protocol_task(void) {
+static inline bool should_do_suspend(void) {
#if USB_COUNT_SOF
if (usbSofCount != 0) {
- usbSofCount = 0;
- sof_timer = timer_read();
- if (vusb_suspended) {
- vusb_wakeup();
- }
+ usbSofCount = 0;
+ sof_timer = timer_read();
+ vusb_suspended = false;
} else {
// Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1)
if (!vusb_suspended && timer_elapsed(sof_timer) > 5) {
- vusb_suspend();
+ vusb_suspended = true;
}
}
#endif
- if (vusb_suspended) {
- vusb_suspend();
- if (suspend_wakeup_condition()) {
- vusb_send_remote_wakeup();
- }
- } else {
- usbPoll();
+ return vusb_suspended;
+}
- // TODO: configuration process is inconsistent. it sometime fails.
- // To prevent failing to configure NOT scan keyboard during configuration
- if (usbConfiguration && usbInterruptIsReady()) {
- keyboard_task();
+void protocol_task(void) {
+#if !defined(NO_USB_STARTUP_CHECK)
+ if (should_do_suspend()) {
+ dprintln("suspending keyboard");
+ while (should_do_suspend()) {
+ vusb_suspend();
+ if (suspend_wakeup_condition()) {
+ vusb_send_remote_wakeup();
+
+# if USB_SUSPEND_WAKEUP_DELAY > 0
+ // Some hubs, kvm switches, and monitors do
+ // weird things, with USB device state bouncing
+ // around wildly on wakeup, yielding race
+ // conditions that can corrupt the keyboard state.
+ //
+ // Pause for a while to let things settle...
+ wait_ms(USB_SUSPEND_WAKEUP_DELAY);
+# endif
+ }
}
+ vusb_wakeup();
+ }
+#endif
+
+ usbPoll();
+
+ // TODO: configuration process is inconsistent. it sometime fails.
+ // To prevent failing to configure NOT scan keyboard during configuration
+ if (usbConfiguration && usbInterruptIsReady()) {
+ keyboard_task();
+ }
#ifdef RAW_ENABLE
- usbPoll();
+ usbPoll();
- if (usbConfiguration && usbInterruptIsReady4()) {
- raw_hid_task();
- }
+ if (usbConfiguration && usbInterruptIsReady4()) {
+ raw_hid_task();
+ }
#endif
#ifdef CONSOLE_ENABLE
- usbPoll();
+ usbPoll();
- if (usbConfiguration && usbInterruptIsReady3()) {
- console_task();
- }
-#endif
+ if (usbConfiguration && usbInterruptIsReady3()) {
+ console_task();
}
+#endif
}
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index d09b2f19b7..cfeeed3712 100644
--- a/tmk_core/protocol/vusb/vusb.c
+++ b/tmk_core/protocol/vusb/vusb.c
@@ -717,13 +717,6 @@ const PROGMEM uchar console_hid_report[] = {
0x95, CONSOLE_BUFFER_SIZE, // Report Count
0x75, 0x08, // Report Size (8)
0x81, 0x02, // Input (Data, Variable, Absolute)
- // Data from host
- 0x09, 0x76, // Usage (Vendor Defined)
- 0x15, 0x00, // Logical Minimum (0x00)
- 0x26, 0xFF, 0x00, // Logical Maximum (0x00FF)
- 0x95, CONSOLE_BUFFER_SIZE, // Report Count
- 0x75, 0x08, // Report Size (8)
- 0x91, 0x02, // Output (Data)
0xC0 // End Collection
};
#endif
@@ -991,16 +984,6 @@ const PROGMEM usbConfigurationDescriptor_t usbConfigurationDescriptor = {
.wMaxPacketSize = CONSOLE_EPSIZE,
.bInterval = 0x01
},
- .consoleOUTEndpoint = {
- .header = {
- .bLength = sizeof(usbEndpointDescriptor_t),
- .bDescriptorType = USBDESCR_ENDPOINT
- },
- .bEndpointAddress = (USBRQ_DIR_HOST_TO_DEVICE | USB_CFG_EP3_NUMBER),
- .bmAttributes = 0x03,
- .wMaxPacketSize = CONSOLE_EPSIZE,
- .bInterval = 0x01
- }
# endif
};
diff --git a/tmk_core/protocol/vusb/vusb.h b/tmk_core/protocol/vusb/vusb.h
index ae17e5e014..4750e95bf2 100644
--- a/tmk_core/protocol/vusb/vusb.h
+++ b/tmk_core/protocol/vusb/vusb.h
@@ -114,7 +114,6 @@ typedef struct usbConfigurationDescriptor {
usbInterfaceDescriptor_t consoleInterface;
usbHIDDescriptor_t consoleHID;
usbEndpointDescriptor_t consoleINEndpoint;
- usbEndpointDescriptor_t consoleOUTEndpoint;
#endif
} __attribute__((packed)) usbConfigurationDescriptor_t;