]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - converter/usb_usb/usb_usb.cpp
usb_usb: Order of init prevents uneeded bus reset
[max/tmk_keyboard.git] / converter / usb_usb / usb_usb.cpp
index 26721de0a5e2f9a63e9fd02c3dc6829262a52d4a..757509118cae70bc19fc133313d4efff7e9a5288 100644 (file)
@@ -21,7 +21,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 // USB HID host
 #include "Usb.h"
 #include "usbhub.h"
-#include "hid.h"
+#include "usbhid.h"
 #include "hidboot.h"
 #include "parser.h"
 
@@ -71,22 +71,23 @@ static bool matrix_is_mod =false;
  * This supports two cascaded hubs and four keyboards
  */
 USB usb_host;
-USBHub hub1(&usb_host);
-USBHub hub2(&usb_host);
-HIDBoot<HID_PROTOCOL_KEYBOARD>    kbd1(&usb_host);
-HIDBoot<HID_PROTOCOL_KEYBOARD>    kbd2(&usb_host);
-HIDBoot<HID_PROTOCOL_KEYBOARD>    kbd3(&usb_host);
-HIDBoot<HID_PROTOCOL_KEYBOARD>    kbd4(&usb_host);
+HIDBoot<USB_HID_PROTOCOL_KEYBOARD>    kbd1(&usb_host);
+HIDBoot<USB_HID_PROTOCOL_KEYBOARD>    kbd2(&usb_host);
+HIDBoot<USB_HID_PROTOCOL_KEYBOARD>    kbd3(&usb_host);
+HIDBoot<USB_HID_PROTOCOL_KEYBOARD>    kbd4(&usb_host);
 KBDReportParser kbd_parser1;
 KBDReportParser kbd_parser2;
 KBDReportParser kbd_parser3;
 KBDReportParser kbd_parser4;
+USBHub hub1(&usb_host);
+USBHub hub2(&usb_host);
 
 
 uint8_t matrix_rows(void) { return MATRIX_ROWS; }
 uint8_t matrix_cols(void) { return MATRIX_COLS; }
 bool matrix_has_ghost(void) { return false; }
 void matrix_init(void) {
+    debug_enable = true;
     // USB Host Shield setup
     usb_host.Init();
     kbd1.SetReportParser(0, (HIDReportParser*)&kbd_parser1);
@@ -160,6 +161,7 @@ uint8_t matrix_scan(void) {
 
         // restore LED state when keyboard comes up
         if (usb_state == USB_STATE_RUNNING) {
+            dprintf("speed: %s\n", usb_host.getVbusState()==FSHOST ? "full" : "low");
             keyboard_set_leds(host_keyboard_leds());
         }
     }
@@ -226,8 +228,8 @@ void matrix_print(void) {
 
 void led_set(uint8_t usb_led)
 {
-    kbd1.SetReport(0, 0, 2, 0, 1, &usb_led);
-    kbd2.SetReport(0, 0, 2, 0, 1, &usb_led);
-    kbd3.SetReport(0, 0, 2, 0, 1, &usb_led);
-    kbd4.SetReport(0, 0, 2, 0, 1, &usb_led);
+    if (kbd1.isReady()) kbd1.SetReport(0, 0, 2, 0, 1, &usb_led);
+    if (kbd2.isReady()) kbd2.SetReport(0, 0, 2, 0, 1, &usb_led);
+    if (kbd3.isReady()) kbd3.SetReport(0, 0, 2, 0, 1, &usb_led);
+    if (kbd4.isReady()) kbd4.SetReport(0, 0, 2, 0, 1, &usb_led);
 }