From bbf5a5905a973d6d23457d2e7bf15bf6bac234c3 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Sun, 4 Oct 2020 18:18:44 -0400 Subject: [PATCH] refactor(usb): Report USB status w/o HID output. --- app/CMakeLists.txt | 2 +- app/Kconfig | 6 +++++- app/include/zmk/{usb_hid.h => usb.h} | 6 +++--- app/src/endpoints.c | 2 +- app/src/{usb_hid.c => usb.c} | 19 +++++++++++++------ 5 files changed, 23 insertions(+), 12 deletions(-) rename app/include/zmk/{usb_hid.h => usb.h} (73%) rename app/src/{usb_hid.c => usb.c} (77%) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 3e0560b7..5c77c54f 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -54,7 +54,7 @@ target_sources_ifdef(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL app PRIVATE src/split/ target_sources_ifdef(CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL app PRIVATE src/split/bluetooth/central.c) target_sources_ifdef(CONFIG_ZMK_KSCAN_MOCK_DRIVER app PRIVATE src/kscan_mock.c) target_sources_ifdef(CONFIG_ZMK_KSCAN_COMPOSITE_DRIVER app PRIVATE src/kscan_composite.c) -target_sources_ifdef(CONFIG_ZMK_USB app PRIVATE src/usb_hid.c) +target_sources_ifdef(CONFIG_USB app PRIVATE src/usb.c) target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/hog.c) target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/rgb_underglow.c) target_sources(app PRIVATE src/endpoints.c) diff --git a/app/Kconfig b/app/Kconfig index ccd40da5..9398fce1 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -21,12 +21,16 @@ menuconfig ZMK_USB select USB_DEVICE_STACK select USB_DEVICE_HID -if ZMK_USB +if USB config ZMK_USB_INIT_PRIORITY int "Init Priority" default 50 +endif + +if ZMK_USB + config USB_NUMOF_EP_WRITE_RETRIES default 10 diff --git a/app/include/zmk/usb_hid.h b/app/include/zmk/usb.h similarity index 73% rename from app/include/zmk/usb_hid.h rename to app/include/zmk/usb.h index 83a45407..452fd54d 100644 --- a/app/include/zmk/usb_hid.h +++ b/app/include/zmk/usb.h @@ -12,8 +12,8 @@ #include #include -int zmk_usb_hid_init(); - -enum usb_dc_status_code zmk_usb_hid_get_status(); +enum usb_dc_status_code zmk_usb_get_status(); +#ifdef CONFIG_ZMK_USB int zmk_usb_hid_send_report(u8_t *report, size_t len); +#endif /* CONFIG_ZMK_USB */ \ No newline at end of file diff --git a/app/src/endpoints.c b/app/src/endpoints.c index ae785870..79d294ef 100644 --- a/app/src/endpoints.c +++ b/app/src/endpoints.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include diff --git a/app/src/usb_hid.c b/app/src/usb.c similarity index 77% rename from app/src/usb_hid.c rename to app/src/usb.c index 64addaea..434b3d4d 100644 --- a/app/src/usb_hid.c +++ b/app/src/usb.c @@ -18,6 +18,8 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); static enum usb_dc_status_code usb_status = USB_DC_UNKNOWN; +#ifdef CONFIG_ZMK_USB + static struct device *hid_dev; static K_SEM_DEFINE(hid_sem, 1, 1); @@ -28,8 +30,6 @@ static const struct hid_ops ops = { .int_in_ready = in_ready_cb, }; -enum usb_dc_status_code zmk_usb_hid_get_status() { return usb_status; } - int zmk_usb_hid_send_report(const u8_t *report, size_t len) { switch (usb_status) { case USB_DC_SUSPEND: @@ -51,11 +51,16 @@ int zmk_usb_hid_send_report(const u8_t *report, size_t len) { } } -void usb_hid_status_cb(enum usb_dc_status_code status, const u8_t *params) { usb_status = status; }; +#endif /* CONFIG_ZMK_USB */ + +enum usb_dc_status_code zmk_usb_get_status() { return usb_status; } -static int zmk_usb_hid_init(struct device *_arg) { +void usb_status_cb(enum usb_dc_status_code status, const u8_t *params) { usb_status = status; }; + +static int zmk_usb_init(struct device *_arg) { int usb_enable_ret; +#ifdef CONFIG_ZMK_USB hid_dev = device_get_binding("HID_0"); if (hid_dev == NULL) { LOG_ERR("Unable to locate HID device"); @@ -66,7 +71,9 @@ static int zmk_usb_hid_init(struct device *_arg) { usb_hid_init(hid_dev); - usb_enable_ret = usb_enable(usb_hid_status_cb); +#endif /* CONFIG_ZMK_USB */ + + usb_enable_ret = usb_enable(usb_status_cb); if (usb_enable_ret != 0) { LOG_ERR("Unable to enable USB"); @@ -76,4 +83,4 @@ static int zmk_usb_hid_init(struct device *_arg) { return 0; } -SYS_INIT(zmk_usb_hid_init, APPLICATION, CONFIG_ZMK_USB_INIT_PRIORITY); +SYS_INIT(zmk_usb_init, APPLICATION, CONFIG_ZMK_USB_INIT_PRIORITY);