diff options
author | Joel Spadin <joelspadin@gmail.com> | 2020-10-11 17:03:21 -0500 |
---|---|---|
committer | Joel Spadin <joelspadin@gmail.com> | 2020-10-28 18:15:05 -0500 |
commit | 1d369ffa73ae63af821d012b1c2ab4a07a5dc9c7 (patch) | |
tree | 409067d51461b939cccbc4381d7185921444a545 /app/include | |
parent | dfb69d8727e01cb9ee855ac2d1cb7a6da1d6aa85 (diff) |
feat: only send HID reports to one endpoint
Added some utility functions and an event for tracking the state of the
USB connection.
Updated endpoints.c to select a single endpoint to send HID reports to
based on the status of the USB and BLE connections. Partially fixes #206.
Future commits will add a user setting to control which endpoint is used if
both USB and BLE are ready.
Diffstat (limited to 'app/include')
-rw-r--r-- | app/include/zmk/events/usb-conn-state-changed.h | 20 | ||||
-rw-r--r-- | app/include/zmk/usb.h | 12 |
2 files changed, 31 insertions, 1 deletions
diff --git a/app/include/zmk/events/usb-conn-state-changed.h b/app/include/zmk/events/usb-conn-state-changed.h new file mode 100644 index 0000000..d6cc698 --- /dev/null +++ b/app/include/zmk/events/usb-conn-state-changed.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include <zephyr.h> +#include <usb/usb_device.h> + +#include <zmk/event-manager.h> +#include <zmk/usb.h> + +struct usb_conn_state_changed { + struct zmk_event_header header; + enum zmk_usb_conn_state conn_state; +}; + +ZMK_EVENT_DECLARE(usb_conn_state_changed);
\ No newline at end of file diff --git a/app/include/zmk/usb.h b/app/include/zmk/usb.h index 452fd54..30461de 100644 --- a/app/include/zmk/usb.h +++ b/app/include/zmk/usb.h @@ -12,8 +12,18 @@ #include <zmk/keys.h> #include <zmk/hid.h> +enum zmk_usb_conn_state { + ZMK_USB_CONN_NONE, + ZMK_USB_CONN_POWERED, + ZMK_USB_CONN_HID, +}; + enum usb_dc_status_code zmk_usb_get_status(); +enum zmk_usb_conn_state zmk_usb_get_conn_state(); + +static inline bool zmk_usb_is_powered() { return zmk_usb_get_conn_state() != ZMK_USB_CONN_NONE; } +static inline bool zmk_usb_is_hid_ready() { return zmk_usb_get_conn_state() == ZMK_USB_CONN_HID; } #ifdef CONFIG_ZMK_USB -int zmk_usb_hid_send_report(u8_t *report, size_t len); +int zmk_usb_hid_send_report(const u8_t *report, size_t len); #endif /* CONFIG_ZMK_USB */
\ No newline at end of file |