From 1d369ffa73ae63af821d012b1c2ab4a07a5dc9c7 Mon Sep 17 00:00:00 2001 From: Joel Spadin Date: Sun, 11 Oct 2020 17:03:21 -0500 Subject: 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. --- app/include/zmk/events/usb-conn-state-changed.h | 20 ++++++++++++++++++++ app/include/zmk/usb.h | 12 +++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 app/include/zmk/events/usb-conn-state-changed.h (limited to 'app/include') 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 +#include + +#include +#include + +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 #include +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 -- cgit v1.2.3 From 8f666cecc9717b3fbbe2f5f34375b6a45b8965fd Mon Sep 17 00:00:00 2001 From: Joel Spadin Date: Sun, 11 Oct 2020 18:38:39 -0500 Subject: feat(endpoints): clear HID report on endpoint change This prevents stuck keys when switching endpoints by clearing everything in the HID report and sending one last report before switching to the new endpoint. --- app/include/zmk/hid.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/include') diff --git a/app/include/zmk/hid.h b/app/include/zmk/hid.h index 744de98..04b12e1 100644 --- a/app/include/zmk/hid.h +++ b/app/include/zmk/hid.h @@ -165,9 +165,11 @@ int zmk_hid_register_mods(zmk_mod_flags modifiers); int zmk_hid_unregister_mods(zmk_mod_flags modifiers); int zmk_hid_keypad_press(zmk_key key); int zmk_hid_keypad_release(zmk_key key); +void zmk_hid_keypad_clear(); int zmk_hid_consumer_press(zmk_key key); int zmk_hid_consumer_release(zmk_key key); +void zmk_hid_consumer_clear(); struct zmk_hid_keypad_report *zmk_hid_get_keypad_report(); struct zmk_hid_consumer_report *zmk_hid_get_consumer_report(); -- cgit v1.2.3 From b538e605321791568aa25f0bd534ebcb30da92c2 Mon Sep 17 00:00:00 2001 From: Joel Spadin Date: Sat, 24 Oct 2020 13:39:02 -0500 Subject: feat(endpoints): update on BLE profile change Added zmk_ble_active_profile_is_connected() to allow code outside ble.c to check the status of the active profile, and changed the ble_active_profile_changed event to also notify when the active profile connects or disconnects. Changed endpoint selection to to also update when the active profile changes, connects, or disconnects. --- app/include/zmk/ble.h | 1 + 1 file changed, 1 insertion(+) (limited to 'app/include') diff --git a/app/include/zmk/ble.h b/app/include/zmk/ble.h index 1cf71a7..56980c6 100644 --- a/app/include/zmk/ble.h +++ b/app/include/zmk/ble.h @@ -15,6 +15,7 @@ int zmk_ble_prof_prev(); int zmk_ble_prof_select(u8_t index); bt_addr_le_t *zmk_ble_active_profile_addr(); +bool zmk_ble_active_profile_is_connected(); char *zmk_ble_active_profile_name(); int zmk_ble_unpair_all(); -- cgit v1.2.3 From 600bba25f049b1fa161b2372b2a47762164c7fcd Mon Sep 17 00:00:00 2001 From: Joel Spadin Date: Sat, 24 Oct 2020 16:28:58 -0500 Subject: feat(endpoints): add preferred endpoint setting Added a new setting to remember the user's preferred endpoint. When both USB and BLE are connected, the preferred endpoint will be used. Added a new behavior to control this setting. It supports commands: &end END_USB - Prefer USB output &end END_BLE - Prefer BLE output &end END_TOG - Toggle between USB and BLE --- app/include/dt-bindings/zmk/endpoints.h | 13 +++++++++++++ app/include/zmk/endpoints.h | 8 ++++++++ 2 files changed, 21 insertions(+) create mode 100644 app/include/dt-bindings/zmk/endpoints.h (limited to 'app/include') diff --git a/app/include/dt-bindings/zmk/endpoints.h b/app/include/dt-bindings/zmk/endpoints.h new file mode 100644 index 0000000..3bba972 --- /dev/null +++ b/app/include/dt-bindings/zmk/endpoints.h @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#define ENDPOINT_TOGGLE_CMD 0 +#define ENDPOINT_USB_CMD 1 +#define ENDPOINT_BLE_CMD 2 + +#define END_TOG ENDPOINT_TOGGLE_CMD +#define END_USB ENDPOINT_USB_CMD +#define END_BLE ENDPOINT_BLE_CMD \ No newline at end of file diff --git a/app/include/zmk/endpoints.h b/app/include/zmk/endpoints.h index aad6265..aad688e 100644 --- a/app/include/zmk/endpoints.h +++ b/app/include/zmk/endpoints.h @@ -9,4 +9,12 @@ #include #include +enum zmk_endpoint { + ZMK_ENDPOINT_USB, + ZMK_ENDPOINT_BLE, +}; + +int zmk_endpoints_select(enum zmk_endpoint endpoint); +int zmk_endpoints_toggle(); + int zmk_endpoints_send_report(u8_t usage_report); -- cgit v1.2.3 From 2fe1fbb526d9190e478999f36adbcfcf4a8847b2 Mon Sep 17 00:00:00 2001 From: Joel Spadin Date: Tue, 27 Oct 2020 13:49:28 -0500 Subject: feat(endpoints): rename behavior to outputs "Outputs" is probably easier for most people to understand than "endpoints". --- app/include/dt-bindings/zmk/endpoints.h | 13 ------------- app/include/dt-bindings/zmk/outputs.h | 13 +++++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-) delete mode 100644 app/include/dt-bindings/zmk/endpoints.h create mode 100644 app/include/dt-bindings/zmk/outputs.h (limited to 'app/include') diff --git a/app/include/dt-bindings/zmk/endpoints.h b/app/include/dt-bindings/zmk/endpoints.h deleted file mode 100644 index 3bba972..0000000 --- a/app/include/dt-bindings/zmk/endpoints.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2020 The ZMK Contributors - * - * SPDX-License-Identifier: MIT - */ - -#define ENDPOINT_TOGGLE_CMD 0 -#define ENDPOINT_USB_CMD 1 -#define ENDPOINT_BLE_CMD 2 - -#define END_TOG ENDPOINT_TOGGLE_CMD -#define END_USB ENDPOINT_USB_CMD -#define END_BLE ENDPOINT_BLE_CMD \ No newline at end of file diff --git a/app/include/dt-bindings/zmk/outputs.h b/app/include/dt-bindings/zmk/outputs.h new file mode 100644 index 0000000..c9a34ae --- /dev/null +++ b/app/include/dt-bindings/zmk/outputs.h @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#define OUTPUT_TOGGLE_CMD 0 +#define OUTPUT_USB_CMD 1 +#define OUTPUT_BLE_CMD 2 + +#define OUT_TOG OUTPUT_TOGGLE_CMD +#define OUT_USB OUTPUT_USB_CMD +#define OUT_BLE OUTPUT_BLE_CMD \ No newline at end of file -- cgit v1.2.3 From 440d09fd45fa59de481837825d27635819ad1c37 Mon Sep 17 00:00:00 2001 From: Joel Spadin Date: Wed, 28 Oct 2020 18:10:47 -0500 Subject: feat(endpoints): simplify behavior constants --- app/include/dt-bindings/zmk/outputs.h | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'app/include') diff --git a/app/include/dt-bindings/zmk/outputs.h b/app/include/dt-bindings/zmk/outputs.h index c9a34ae..f24380f 100644 --- a/app/include/dt-bindings/zmk/outputs.h +++ b/app/include/dt-bindings/zmk/outputs.h @@ -4,10 +4,6 @@ * SPDX-License-Identifier: MIT */ -#define OUTPUT_TOGGLE_CMD 0 -#define OUTPUT_USB_CMD 1 -#define OUTPUT_BLE_CMD 2 - -#define OUT_TOG OUTPUT_TOGGLE_CMD -#define OUT_USB OUTPUT_USB_CMD -#define OUT_BLE OUTPUT_BLE_CMD \ No newline at end of file +#define OUT_TOG 0 +#define OUT_USB 1 +#define OUT_BLE 2 \ No newline at end of file -- cgit v1.2.3