comparison Output/usbMuxUart/output_com.c @ 447:56237ba5da6f

Adding auto-restart support whenever USB gets into an odd state - Somewhat aggresive, may cause restarts if the keyboard/OS hasn't fully intialized the keyboard - Added GET_IDLE handling and correct usage of SET_IDLE - Initial implementation of idle send, commented out as it causes issues on Mac OSX for sleeping (keyboard has been working without it) - MacOSX seems to have some sort of data corruption on the USB link, not sure why (other OSs have no issues) - Cleaned up some code - Added a longer sleep after the resume sequence to prevent possible issues sending keys too soon (may need to be increased more) Ipad support now seems flaky, though Mac, Windows seems solid. Init sequence on Linux seems slow, even though there are no errors.
author Jacob Alexander <haata@kiibohd.com>
date Fri, 27 May 2016 01:21:57 -0700
parents 380e1f0123d0
children 45feb80a2ad1
comparison
equal deleted inserted replaced
446:f570ab7c861a 447:56237ba5da6f
35 #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) 35 #elif defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
36 #include <arm/uart_serial.h> 36 #include <arm/uart_serial.h>
37 #include <arm/usb_dev.h> 37 #include <arm/usb_dev.h>
38 #include <arm/usb_keyboard.h> 38 #include <arm/usb_keyboard.h>
39 #include <arm/usb_serial.h> 39 #include <arm/usb_serial.h>
40 #include "arm/usb_mouse.h"
40 #endif 41 #endif
41 42
42 // KLL 43 // KLL
43 #include <kll_defs.h> 44 #include <kll_defs.h>
44 45
139 // Indicate if USB should send update 140 // Indicate if USB should send update
140 USBMouseChangeState USBMouse_Changed = 0; 141 USBMouseChangeState USBMouse_Changed = 0;
141 142
142 // the idle configuration, how often we send the report to the 143 // the idle configuration, how often we send the report to the
143 // host (ms * 4) even when it hasn't changed 144 // host (ms * 4) even when it hasn't changed
144 uint8_t USBKeys_Idle_Config = 125; 145 // 0 - Disables
145 146 uint8_t USBKeys_Idle_Config = 0;
146 // count until idle timeout 147
148 // Count until idle timeout
149 uint32_t USBKeys_Idle_Expiry = 0;
147 uint8_t USBKeys_Idle_Count = 0; 150 uint8_t USBKeys_Idle_Count = 0;
148 151
149 // Indicates whether the Output module is fully functional 152 // Indicates whether the Output module is fully functional
150 // 0 - Not fully functional, 1 - Fully functional 153 // 0 - Not fully functional, 1 - Fully functional
151 // 0 is often used to show that a USB cable is not plugged in (but has power) 154 // 0 is often used to show that a USB cable is not plugged in (but has power)
651 // Boot Mode Only, unset stale keys 654 // Boot Mode Only, unset stale keys
652 if ( USBKeys_Protocol == 0 ) 655 if ( USBKeys_Protocol == 0 )
653 for ( uint8_t c = USBKeys_Sent; c < USB_BOOT_MAX_KEYS; c++ ) 656 for ( uint8_t c = USBKeys_Sent; c < USB_BOOT_MAX_KEYS; c++ )
654 USBKeys_Keys[c] = 0; 657 USBKeys_Keys[c] = 0;
655 658
659 // XXX - Behaves oddly on Mac OSX, might help with corrupted packets specific to OSX? -HaaTa
660 /*
661 // Check if idle count has been exceed, this forces usb_keyboard_send and usb_mouse_send to update
662 // TODO Add joystick as well (may be endpoint specific, currently not kept track of)
663 if ( usb_configuration && USBKeys_Idle_Config && (
664 USBKeys_Idle_Expiry < systick_millis_count ||
665 USBKeys_Idle_Expiry + USBKeys_Idle_Config * 4 >= systick_millis_count ) )
666 {
667 USBKeys_Changed = USBKeyChangeState_All;
668 USBMouse_Changed = USBMouseChangeState_All;
669 }
670 */
671
672 // Process mouse actions
673 while ( USBMouse_Changed )
674 usb_mouse_send();
675
656 // Send keypresses while there are pending changes 676 // Send keypresses while there are pending changes
657 while ( USBKeys_Changed ) 677 while ( USBKeys_Changed )
658 usb_keyboard_send(); 678 usb_keyboard_send();
659 679
660 // Clear keys sent 680 // Clear keys sent