X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=converter%2Fusb_usb%2Fusb_usb.cpp;h=086c90aed562b6b420f243a66e84af0d9e6a6c2e;hb=8345571e1df07cdbe612541baa9e4f3441ad3f9e;hp=969e89f357673feb4c9b7d12a7625426bc179234;hpb=338744ba2fdfdcd07824f325a8112e041d6cd0a5;p=max%2Ftmk_keyboard.git
diff --git a/converter/usb_usb/usb_usb.cpp b/converter/usb_usb/usb_usb.cpp
index 969e89f3..086c90ae 100644
--- a/converter/usb_usb/usb_usb.cpp
+++ b/converter/usb_usb/usb_usb.cpp
@@ -21,7 +21,7 @@ along with this program. If not, see .
// USB HID host
#include "Usb.h"
#include "usbhub.h"
-#include "hid.h"
+#include "usbhid.h"
#include "hidboot.h"
#include "parser.h"
@@ -32,6 +32,8 @@ along with this program. If not, see .
#include "timer.h"
#include "matrix.h"
#include "led.h"
+#include "host.h"
+#include "keyboard.h"
/* KEY CODE to Matrix
@@ -71,10 +73,10 @@ static bool matrix_is_mod =false;
USB usb_host;
USBHub hub1(&usb_host);
USBHub hub2(&usb_host);
-HIDBoot kbd1(&usb_host);
-HIDBoot kbd2(&usb_host);
-HIDBoot kbd3(&usb_host);
-HIDBoot kbd4(&usb_host);
+HIDBoot kbd1(&usb_host);
+HIDBoot kbd2(&usb_host);
+HIDBoot kbd3(&usb_host);
+HIDBoot kbd4(&usb_host);
KBDReportParser kbd_parser1;
KBDReportParser kbd_parser2;
KBDReportParser kbd_parser3;
@@ -85,6 +87,7 @@ 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);
@@ -151,6 +154,17 @@ uint8_t matrix_scan(void) {
dprintf("host.Task: %d\n", timer);
}
+ static uint8_t usb_state = 0;
+ if (usb_state != usb_host.getUsbTaskState()) {
+ usb_state = usb_host.getUsbTaskState();
+ dprintf("usb_state: %02X\n", usb_state);
+
+ // 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());
+ }
+ }
return 1;
}
@@ -214,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);
}