diff options
author | Pete Johanson <peter@peterjohanson.com> | 2020-08-16 22:39:26 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-16 22:39:26 -0400 |
commit | 8cd8933c87aadd2ce7b31c1367bfaad81fc2a36b (patch) | |
tree | 95b3ba6976ae8f0dc65108e5b2c543955d146c08 /app | |
parent | 3f1dfbaad1a867f59c13814a517e03dfce4d4223 (diff) | |
parent | 5b4e5a30c41ea6edfa592735fcf607c44b0b3243 (diff) |
Merge pull request #93 from careyk007/main
Wait for USB HID ready before sending reports
Diffstat (limited to 'app')
-rw-r--r-- | app/src/usb_hid.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/app/src/usb_hid.c b/app/src/usb_hid.c index 4c6dd4b..40511b0 100644 --- a/app/src/usb_hid.c +++ b/app/src/usb_hid.c @@ -15,6 +15,18 @@ static enum usb_dc_status_code usb_status; static struct device *hid_dev; +static K_SEM_DEFINE(hid_sem, 1, 1); + +static void in_ready_cb(void) +{ + k_sem_give(&hid_sem); +} + +static const struct hid_ops ops = +{ + .int_in_ready = in_ready_cb, +}; + int zmk_usb_hid_send_report(const u8_t *report, size_t len) { if (usb_status == USB_DC_SUSPEND) @@ -22,6 +34,7 @@ int zmk_usb_hid_send_report(const u8_t *report, size_t len) return usb_wakeup_request(); } + k_sem_take(&hid_sem, K_FOREVER); return hid_int_ep_write(hid_dev, report, len, NULL); } @@ -43,7 +56,7 @@ static int zmk_usb_hid_init(struct device *_arg) usb_hid_register_device(hid_dev, zmk_hid_report_desc, sizeof(zmk_hid_report_desc), - NULL); + &ops); usb_hid_init(hid_dev); |