Browse Source

refactor(usb): Report USB status w/o HID output.

xmkb
Pete Johanson 4 years ago
parent
commit
bbf5a5905a
  1. 2
      app/CMakeLists.txt
  2. 6
      app/Kconfig
  3. 6
      app/include/zmk/usb.h
  4. 2
      app/src/endpoints.c
  5. 19
      app/src/usb.c

2
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_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_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_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_BLE app PRIVATE src/hog.c)
target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/rgb_underglow.c) target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/rgb_underglow.c)
target_sources(app PRIVATE src/endpoints.c) target_sources(app PRIVATE src/endpoints.c)

6
app/Kconfig

@ -21,12 +21,16 @@ menuconfig ZMK_USB
select USB_DEVICE_STACK select USB_DEVICE_STACK
select USB_DEVICE_HID select USB_DEVICE_HID
if ZMK_USB if USB
config ZMK_USB_INIT_PRIORITY config ZMK_USB_INIT_PRIORITY
int "Init Priority" int "Init Priority"
default 50 default 50
endif
if ZMK_USB
config USB_NUMOF_EP_WRITE_RETRIES config USB_NUMOF_EP_WRITE_RETRIES
default 10 default 10

6
app/include/zmk/usb_hid.h → app/include/zmk/usb.h

@ -12,8 +12,8 @@
#include <zmk/keys.h> #include <zmk/keys.h>
#include <zmk/hid.h> #include <zmk/hid.h>
int zmk_usb_hid_init(); enum usb_dc_status_code zmk_usb_get_status();
enum usb_dc_status_code zmk_usb_hid_get_status();
#ifdef CONFIG_ZMK_USB
int zmk_usb_hid_send_report(u8_t *report, size_t len); int zmk_usb_hid_send_report(u8_t *report, size_t len);
#endif /* CONFIG_ZMK_USB */

2
app/src/endpoints.c

@ -6,7 +6,7 @@
#include <zmk/endpoints.h> #include <zmk/endpoints.h>
#include <zmk/hid.h> #include <zmk/hid.h>
#include <zmk/usb_hid.h> #include <zmk/usb.h>
#include <zmk/hog.h> #include <zmk/hog.h>
#include <logging/log.h> #include <logging/log.h>

19
app/src/usb_hid.c → 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; static enum usb_dc_status_code usb_status = USB_DC_UNKNOWN;
#ifdef CONFIG_ZMK_USB
static struct device *hid_dev; static struct device *hid_dev;
static K_SEM_DEFINE(hid_sem, 1, 1); static K_SEM_DEFINE(hid_sem, 1, 1);
@ -28,8 +30,6 @@ static const struct hid_ops ops = {
.int_in_ready = in_ready_cb, .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) { int zmk_usb_hid_send_report(const u8_t *report, size_t len) {
switch (usb_status) { switch (usb_status) {
case USB_DC_SUSPEND: 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; int usb_enable_ret;
#ifdef CONFIG_ZMK_USB
hid_dev = device_get_binding("HID_0"); hid_dev = device_get_binding("HID_0");
if (hid_dev == NULL) { if (hid_dev == NULL) {
LOG_ERR("Unable to locate HID device"); 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_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) { if (usb_enable_ret != 0) {
LOG_ERR("Unable to enable USB"); LOG_ERR("Unable to enable USB");
@ -76,4 +83,4 @@ static int zmk_usb_hid_init(struct device *_arg) {
return 0; 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);
Loading…
Cancel
Save