From cf970efb98c5af97955bfffbcebb3b065b16edc4 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Fri, 28 Aug 2020 14:15:16 -0400 Subject: feat(bluetooth): Proper bond management, identity support for non-splits * Add `bt` behavior that can be used to perform certain actions, such as next/prev identity, reset identity, etc. NOTE: Multiple identities is only supported for non-split shields, due to missing Zephyr identity functionality for dual central/peripheral devices. * Proper bond reset tied to action, that honors peripheral bonds, so folks can reset and pair to other hosts, without breaking bonds between splt halves. --- docs/docs/behavior/bluetooth.md | 82 +++++++++++++++++++++++++++++++++++++++++ docs/sidebars.js | 1 + 2 files changed, 83 insertions(+) create mode 100644 docs/docs/behavior/bluetooth.md (limited to 'docs') diff --git a/docs/docs/behavior/bluetooth.md b/docs/docs/behavior/bluetooth.md new file mode 100644 index 0000000..df8ec26 --- /dev/null +++ b/docs/docs/behavior/bluetooth.md @@ -0,0 +1,82 @@ +--- +title: Bluetooth Behavior +sidebar_label: Bluetooth +--- + +## Summary + +The bluetooth behavior allows management of various settings and states related to the bluetooth connection(s) +between the keyboard and the host. + +## Bluetooth Command Defines + +Bluetooth command defines are provided through the [`dt-bindings/zmk/bt.h`](https://github.com/zmkfirmware/zmk/blob/main/app/include/dt-bindings/zmk/bt.h) header, +which is added at the top of the keymap file: + +``` +#include +``` + +This will allow you to reference the actions defined in this header such as `BT_IDENT_CLR_CMD`. + +Here is a table describing the command for each define: + +| Define | Action | +| ------------------- | ----------------------------------------------------- | +| `BT_IDENT_CLR_CMD` | Clear paired keyboards (for the current identity)[^1] | +| `BT_IDENT_NEXT_CMD` | Switch to the next identity[^1] | +| `BT_IDENT_PREV_CMD` | Switch to the previous identity | +| `BT_IDENT_SEL_CMD` | Switch to a specific numbered identity | +| `BT_RST_CMD` | Hard reset of all bluetooth bonds | + +Because the `BT_IDENT_SEL_CMD` command takes an additional parameter, the numeric index of the identity to select, _all_ the commands for the bluetooth behavior must take that additional parameter, and ignore the value. To make this easier, +there are alias defines that add those default parameters for you: + +| Define | Action | +| --------------- | --------------------------------------------------------------------------------------- | +| `BT_IDENT_CLR` | Alias for `BT_IDENT_CLR_CMD 0` to clear paired keyboards (for the current identity)[^1] | +| `BT_IDENT_NEXT` | Alias for `BT_IDENT_NEXT_CMD 0` to switch to the next identity[^1] | +| `BT_IDENT_PREV` | Alias for `BT_IDENT_PREV_CMD 0` to switch to the previous identity | +| `BT_IDENT_SEL` | Alias for `BT_IDENT_SEL_CMD` to switch to a specific numbered identity | +| `BT_RST` | Alias for `BT_RST_CMD 0` to reset all bonds[^2] | + +[^1]: Multiple keyboard identities/profiles is only support on non-split keyboards as of this time. +[^2]: This may interrupt pairing between both halves of a split keyboard. For split keyboards, it is preferred to use the [/docs/bond-reset] combo to clear bonds on both devices + +## Bluetooth Behavior + +The bluetooth behavior completes an bluetooth action given on press. + +### Behavior Binding + +- Reference: `&bt` +- Parameter #1: The bluetooth command define, e.g. `BT_IDENT_CLR_CMD` or `BT_RST_CMD` +- Parameter #2: The parameter for the command, when used to identify an identity/profile to select, e.g. `0` + +### Examples + +1. Behavior to clear the paired host: + + ``` + &bt BT_IDENT_CLR + ``` + +1. Behavior to hard reset all bonded devices[^2]: + + ``` + &bt BT_IDENT_CLR + ``` + +Examples for non-split keyboards with multiple identities: + +1. Behavior to switch to the next identity: + + ``` + &bt BT_IDENT_NEXT + ``` + +1. Behavior to switch to the specific numbered identity: + + ``` + &bt BT_IDENT_SEL 1 + ``` diff --git a/docs/sidebars.js b/docs/sidebars.js index 6bd3aa4..ace7fa1 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -22,6 +22,7 @@ module.exports = { "behavior/hold-tap", "behavior/mod-tap", "behavior/reset", + "behavior/bluetooth", "behavior/lighting", ], Development: [ -- cgit v1.2.3 From fc0812bd2eb08d66819f38bafd1f5d00b933c87b Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 1 Sep 2020 23:22:30 -0400 Subject: fix(bluetooth): Remove identity, minimal `bt`. * Simplify the `bt` behavior to one current command `BT_CLEAR_BONDS_CMD`. * Simplify BLE code for split and non-split keyboards. * Remove keymap processing from split peripheral side. --- docs/docs/behavior/bluetooth.md | 58 ++++++++++------------------------------- 1 file changed, 14 insertions(+), 44 deletions(-) (limited to 'docs') diff --git a/docs/docs/behavior/bluetooth.md b/docs/docs/behavior/bluetooth.md index df8ec26..f605c96 100644 --- a/docs/docs/behavior/bluetooth.md +++ b/docs/docs/behavior/bluetooth.md @@ -6,7 +6,8 @@ sidebar_label: Bluetooth ## Summary The bluetooth behavior allows management of various settings and states related to the bluetooth connection(s) -between the keyboard and the host. +between the keyboard and the host. As of right now, there is only one such action support, but in the future +more will be added. ## Bluetooth Command Defines @@ -17,31 +18,20 @@ which is added at the top of the keymap file: #include ``` -This will allow you to reference the actions defined in this header such as `BT_IDENT_CLR_CMD`. +This will allow you to reference the actions defined in this header such as `BT_CLEAR_BONDS_CMD`. Here is a table describing the command for each define: -| Define | Action | -| ------------------- | ----------------------------------------------------- | -| `BT_IDENT_CLR_CMD` | Clear paired keyboards (for the current identity)[^1] | -| `BT_IDENT_NEXT_CMD` | Switch to the next identity[^1] | -| `BT_IDENT_PREV_CMD` | Switch to the previous identity | -| `BT_IDENT_SEL_CMD` | Switch to a specific numbered identity | -| `BT_RST_CMD` | Hard reset of all bluetooth bonds | +| Define | Action | +| -------------------- | --------------------------------------------------------- | +| `BT_CLEAR_BONDS_CMD` | Clear bond information between the keyboard and host [^1] | -Because the `BT_IDENT_SEL_CMD` command takes an additional parameter, the numeric index of the identity to select, _all_ the commands for the bluetooth behavior must take that additional parameter, and ignore the value. To make this easier, -there are alias defines that add those default parameters for you: +Because future bluetooth commands will take an additional parameter, it is recommended to use +the following alias in your keymap to avoid having to change it later. -| Define | Action | -| --------------- | --------------------------------------------------------------------------------------- | -| `BT_IDENT_CLR` | Alias for `BT_IDENT_CLR_CMD 0` to clear paired keyboards (for the current identity)[^1] | -| `BT_IDENT_NEXT` | Alias for `BT_IDENT_NEXT_CMD 0` to switch to the next identity[^1] | -| `BT_IDENT_PREV` | Alias for `BT_IDENT_PREV_CMD 0` to switch to the previous identity | -| `BT_IDENT_SEL` | Alias for `BT_IDENT_SEL_CMD` to switch to a specific numbered identity | -| `BT_RST` | Alias for `BT_RST_CMD 0` to reset all bonds[^2] | - -[^1]: Multiple keyboard identities/profiles is only support on non-split keyboards as of this time. -[^2]: This may interrupt pairing between both halves of a split keyboard. For split keyboards, it is preferred to use the [/docs/bond-reset] combo to clear bonds on both devices +| Define | Action | +| ---------------- | ---------------------------------------------------------------------- | +| `BT_CLEAR_BONDS` | Alias for `BT_CLEAR_BONDS_CMD 0` to clear the bond to the current host | ## Bluetooth Behavior @@ -50,33 +40,13 @@ The bluetooth behavior completes an bluetooth action given on press. ### Behavior Binding - Reference: `&bt` -- Parameter #1: The bluetooth command define, e.g. `BT_IDENT_CLR_CMD` or `BT_RST_CMD` -- Parameter #2: The parameter for the command, when used to identify an identity/profile to select, e.g. `0` +- Parameter #1: The bluetooth command define, e.g. `BT_CLEAR_BONDS_CMD` +- Parameter #2: (Reserved for future bluetooth command types) ### Examples 1. Behavior to clear the paired host: ``` - &bt BT_IDENT_CLR - ``` - -1. Behavior to hard reset all bonded devices[^2]: - - ``` - &bt BT_IDENT_CLR - ``` - -Examples for non-split keyboards with multiple identities: - -1. Behavior to switch to the next identity: - - ``` - &bt BT_IDENT_NEXT - ``` - -1. Behavior to switch to the specific numbered identity: - - ``` - &bt BT_IDENT_SEL 1 + &bt BT_CLEAR_BONDS ``` -- cgit v1.2.3 From 39f980a06dac1769e4f09abaf19d3ccbb4b34e67 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 8 Sep 2020 23:26:00 -0400 Subject: feat(bluetooth): Add back profiles, split fixes. * Add back in profiles, not using Zephyr BT identity infrastructure. * Restore additional `&bt` commands for profile operations. * Fix for split pairing and subscriptions, since Zephyr persists subscriptions across connects. * Remove keymap from peripheral builds, reduces firmware size, and avoids unneeded attempts to send HID data. --- docs/docs/behavior/bluetooth.md | 46 +++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 11 deletions(-) (limited to 'docs') diff --git a/docs/docs/behavior/bluetooth.md b/docs/docs/behavior/bluetooth.md index f605c96..4a121a3 100644 --- a/docs/docs/behavior/bluetooth.md +++ b/docs/docs/behavior/bluetooth.md @@ -6,8 +6,8 @@ sidebar_label: Bluetooth ## Summary The bluetooth behavior allows management of various settings and states related to the bluetooth connection(s) -between the keyboard and the host. As of right now, there is only one such action support, but in the future -more will be added. +between the keyboard and the host. By default, ZMK supports five "profiles" for selecting which bonded host +computer/laptop/keyboard should receive the keyboard input; many of the commands here operation on those profiles. ## Bluetooth Command Defines @@ -22,16 +22,22 @@ This will allow you to reference the actions defined in this header such as `BT_ Here is a table describing the command for each define: -| Define | Action | -| -------------------- | --------------------------------------------------------- | -| `BT_CLEAR_BONDS_CMD` | Clear bond information between the keyboard and host [^1] | +| Define | Action | +| -------------------- | ---------------------------------------------------------------------------------------------- | +| `BT_CLEAR_BONDS_CMD` | Clear bond information between the keyboard and host for the selected profile [^1] | +| `BT_PROF_NEXT_CMD` | Switch to the next profile, cycling through to the first one when the end is reached. | +| `BT_PROF_PREV_CMD` | Switch to the previous profile, cycling through to the last one when the beginning is reached. | +| `BT_PROF_SEL_CMD` | Select the 0-indexed profile by number. | -Because future bluetooth commands will take an additional parameter, it is recommended to use -the following alias in your keymap to avoid having to change it later. +Because at least one bluetooth commands takes an additional parameter, it is recommended to use +the following aliases in your keymap to avoid having to specify an ignored second parameter: -| Define | Action | -| ---------------- | ---------------------------------------------------------------------- | -| `BT_CLEAR_BONDS` | Alias for `BT_CLEAR_BONDS_CMD 0` to clear the bond to the current host | +| Define | Action | +| ---------------- | ---------------------------------------------------------------------------------------- | +| `BT_CLEAR_BONDS` | Alias for `BT_CLEAR_BONDS_CMD 0` to clear the current profile's bond to the current host | +| `BT_PROF_NEXT` | Alias for `BT_PROF_NEXT_CMD 0` to select the next profile | +| `BT_PROF_PREV` | Alias for `BT_PROF_PREV_CMD 0` to select the previous profile | +| `BT_PROF_SEL` | Alias for `BT_PROF_SEL_CMD` to select the given profile, e.g. `&bt BT_PROF_SEL 1` | ## Bluetooth Behavior @@ -45,8 +51,26 @@ The bluetooth behavior completes an bluetooth action given on press. ### Examples -1. Behavior to clear the paired host: +1. Behavior binding to clear the paired host for the selected profile: ``` &bt BT_CLEAR_BONDS ``` + +1. Behavior binding to select the next profile: + + ``` + &bt BT_PROF_NEXT + ``` + +1. Behavior binding to select the previous profile: + + ``` + &bt BT_PROF_NEXT + ``` + +1. Behavior binding to select the 2nd profile (passed parameters are [zero based](https://en.wikipedia.org/wiki/Zero-based_numbering)): + + ``` + &bt BT_PROF_SEL 1 + ``` -- cgit v1.2.3 From 6c8b0b53f0dbec695ab967ee947916875ed49352 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Sun, 13 Sep 2020 22:20:25 -0400 Subject: refactor(bluetooth): More concise names. --- docs/docs/behavior/bluetooth.md | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'docs') diff --git a/docs/docs/behavior/bluetooth.md b/docs/docs/behavior/bluetooth.md index 4a121a3..f802a9a 100644 --- a/docs/docs/behavior/bluetooth.md +++ b/docs/docs/behavior/bluetooth.md @@ -18,26 +18,26 @@ which is added at the top of the keymap file: #include ``` -This will allow you to reference the actions defined in this header such as `BT_CLEAR_BONDS_CMD`. +This will allow you to reference the actions defined in this header such as `BT_CLR_CMD`. Here is a table describing the command for each define: -| Define | Action | -| -------------------- | ---------------------------------------------------------------------------------------------- | -| `BT_CLEAR_BONDS_CMD` | Clear bond information between the keyboard and host for the selected profile [^1] | -| `BT_PROF_NEXT_CMD` | Switch to the next profile, cycling through to the first one when the end is reached. | -| `BT_PROF_PREV_CMD` | Switch to the previous profile, cycling through to the last one when the beginning is reached. | -| `BT_PROF_SEL_CMD` | Select the 0-indexed profile by number. | +| Define | Action | +| ------------ | ---------------------------------------------------------------------------------------------- | +| `BT_CLR_CMD` | Clear bond information between the keyboard and host for the selected profile [^1] | +| `BT_NXT_CMD` | Switch to the next profile, cycling through to the first one when the end is reached. | +| `BT_PRV_CMD` | Switch to the previous profile, cycling through to the last one when the beginning is reached. | +| `BT_SEL_CMD` | Select the 0-indexed profile by number. | Because at least one bluetooth commands takes an additional parameter, it is recommended to use the following aliases in your keymap to avoid having to specify an ignored second parameter: -| Define | Action | -| ---------------- | ---------------------------------------------------------------------------------------- | -| `BT_CLEAR_BONDS` | Alias for `BT_CLEAR_BONDS_CMD 0` to clear the current profile's bond to the current host | -| `BT_PROF_NEXT` | Alias for `BT_PROF_NEXT_CMD 0` to select the next profile | -| `BT_PROF_PREV` | Alias for `BT_PROF_PREV_CMD 0` to select the previous profile | -| `BT_PROF_SEL` | Alias for `BT_PROF_SEL_CMD` to select the given profile, e.g. `&bt BT_PROF_SEL 1` | +| Define | Action | +| -------- | -------------------------------------------------------------------------------- | +| `BT_CLR` | Alias for `BT_CLR_CMD 0` to clear the current profile's bond to the current host | +| `BT_NXT` | Alias for `BT_NXT_CMD 0` to select the next profile | +| `BT_PRV` | Alias for `BT_PRV_CMD 0` to select the previous profile | +| `BT_SEL` | Alias for `BT_SEL_CMD` to select the given profile, e.g. `&bt BT_SEL 1` | ## Bluetooth Behavior @@ -46,7 +46,7 @@ The bluetooth behavior completes an bluetooth action given on press. ### Behavior Binding - Reference: `&bt` -- Parameter #1: The bluetooth command define, e.g. `BT_CLEAR_BONDS_CMD` +- Parameter #1: The bluetooth command define, e.g. `BT_CLR_CMD` - Parameter #2: (Reserved for future bluetooth command types) ### Examples @@ -54,23 +54,23 @@ The bluetooth behavior completes an bluetooth action given on press. 1. Behavior binding to clear the paired host for the selected profile: ``` - &bt BT_CLEAR_BONDS + &bt BT_CLR ``` 1. Behavior binding to select the next profile: ``` - &bt BT_PROF_NEXT + &bt BT_NXT ``` 1. Behavior binding to select the previous profile: ``` - &bt BT_PROF_NEXT + &bt BT_NXT ``` 1. Behavior binding to select the 2nd profile (passed parameters are [zero based](https://en.wikipedia.org/wiki/Zero-based_numbering)): ``` - &bt BT_PROF_SEL 1 + &bt BT_SEL 1 ``` -- cgit v1.2.3