From 44358798d3dae71cc1af118e5a5bc5792f9f7761 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Fri, 15 Mar 2024 21:00:37 +0000 Subject: [PATCH 01/45] feat: Add ability to fetch battery voltage. * To be able to use the Zephyr `voltage-divider` driver, add a mode for fetching raw voltage from the sensor and do state of charge calculation outside of the driver. --- app/Kconfig | 14 ++++++++++++++ app/src/battery.c | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/app/Kconfig b/app/Kconfig index c430bcb2..21e97ac6 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -383,6 +383,20 @@ config ZMK_BATTERY_REPORTING select ZMK_LOW_PRIORITY_WORK_QUEUE imply BT_BAS if ZMK_BLE +if ZMK_BATTERY_REPORTING + +choice ZMK_BATTERY_REPORTING_FETCH_MODE + prompt "Battery Reporting Fetch Mode" + +config ZMK_BATTERY_REPORTING_FETCH_MODE_STATE_OF_CHARGE + bool "State of charge" + +config ZMK_BATTERY_REPORTING_FETCH_MODE_LITHIUM_VOLTAGE + bool "Lithium Voltage" + +endchoice +endif + config ZMK_IDLE_TIMEOUT int "Milliseconds of inactivity before entering idle state (OLED shutoff, etc)" default 30000 diff --git a/app/src/battery.c b/app/src/battery.c index 1295f822..ae79d5f7 100644 --- a/app/src/battery.c +++ b/app/src/battery.c @@ -34,11 +34,29 @@ static const struct device *const battery = DEVICE_DT_GET(DT_CHOSEN(zmk_battery) static const struct device *battery; #endif +#if IS_ENABLED(CONFIG_ZMK_BATTERY_REPORTING_FETCH_MODE_LITHIUM_VOLTAGE) +static uint8_t lithium_ion_mv_to_pct(int16_t bat_mv) { + // Simple linear approximation of a battery based off adafruit's discharge graph: + // https://learn.adafruit.com/li-ion-and-lipoly-batteries/voltages + + if (bat_mv >= 4200) { + return 100; + } else if (bat_mv <= 3450) { + return 0; + } + + return bat_mv * 2 / 15 - 459; +} + +#endif // IS_ENABLED(CONFIG_ZMK_BATTERY_REPORTING_FETCH_MODE_LITHIUM_VOLTAGE) + static int zmk_battery_update(const struct device *battery) { struct sensor_value state_of_charge; + int rc; - int rc = sensor_sample_fetch_chan(battery, SENSOR_CHAN_GAUGE_STATE_OF_CHARGE); +#if IS_ENABLED(CONFIG_ZMK_BATTERY_REPORTING_FETCH_MODE_STATE_OF_CHARGE) + rc = sensor_sample_fetch_chan(battery, SENSOR_CHAN_GAUGE_STATE_OF_CHARGE); if (rc != 0) { LOG_DBG("Failed to fetch battery values: %d", rc); return rc; @@ -50,6 +68,28 @@ static int zmk_battery_update(const struct device *battery) { LOG_DBG("Failed to get battery state of charge: %d", rc); return rc; } +#elif IS_ENABLED(CONFIG_ZMK_BATTERY_REPORTING_FETCH_MODE_LITHIUM_VOLTAGE) + rc = sensor_sample_fetch_chan(battery, SENSOR_CHAN_VOLTAGE); + if (rc != 0) { + LOG_DBG("Failed to fetch battery values: %d", rc); + return rc; + } + + struct sensor_value voltage; + rc = sensor_channel_get(battery, SENSOR_CHAN_VOLTAGE, &voltage); + + if (rc != 0) { + LOG_DBG("Failed to get battery voltage: %d", rc); + return rc; + } + + uint16_t mv = voltage.val1 * 1000 + (voltage.val2 / 1000); + state_of_charge.val1 = lithium_ion_mv_to_pct(mv); + + LOG_DBG("State of change %d from %d mv", state_of_charge.val1, mv); +#else +#error "Not a supported reporting fetch mode" +#endif if (last_state_of_charge != state_of_charge.val1) { last_state_of_charge = state_of_charge.val1; From f2d8b9b0a31398d9880de6a960b41e3603b3b837 Mon Sep 17 00:00:00 2001 From: Thomas Huber <113915837+huber-th@users.noreply.github.com> Date: Wed, 20 Mar 2024 07:18:44 -0700 Subject: [PATCH 02/45] feat(docs): Add Behavior overview page Co-authored-by: Cem Aksoylar --- docs/docs/behaviors/index.mdx | 82 +++++++++++++++++++++++++++++++++++ docs/sidebars.js | 1 + 2 files changed, 83 insertions(+) create mode 100644 docs/docs/behaviors/index.mdx diff --git a/docs/docs/behaviors/index.mdx b/docs/docs/behaviors/index.mdx new file mode 100644 index 00000000..32f4b29a --- /dev/null +++ b/docs/docs/behaviors/index.mdx @@ -0,0 +1,82 @@ +--- +title: Behavior Overview +sidebar_label: Overview +--- + +# Behaviors Overview + +"Behaviors" are bindings that are assigned to and triggered by key positions on keymap layers, sensors (like an encoder) or combos. They describe what happens e.g. when a certain key position is pressed or released, or an encoder triggers a rotation event. They can also be recursively invoked by other behaviors, such as macros. + +Below is a summary of pre-defined behavior bindings and user-definable behaviors available in ZMK, with references to documentation pages describing them. + +## Key press behaviors + +| Binding | Behavior | Description | +| ------------- | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `&kp` | [Key Press](key-press.md) | Send keycodes to the connected host when a key is pressed | +| `&mt` | [Mod Tap](mod-tap.md) | Sends a different key press depending on whether a key is held or tapped | +| `&kt` | [Key Toggle](key-toggle.md) | Toggles the press of a key. If the key is not currently pressed, key toggle will press it, holding it until the key toggle is pressed again or the key is released in some other way. If the key is currently pressed, key toggle will release it | +| `&sk` | [Sticky Key](sticky-key.md) | Stays pressed until another key is pressed, then is released. It is often used for modifier keys like shift, which allows typing capital letters without holding it down | +| `&gresc` | [Grave Escape](mod-morph.md#behavior-binding) | Sends Grave Accent `` ` `` keycode if shift or GUI is held, sends Escape keycode otherwise | +| `&caps_word` | [Caps Word](caps-word.md) | Behaves similar to caps lock, but automatically deactivates when any key not in a continue list is pressed, or if the caps word key is pressed again | +| `&key_repeat` | [Key Repeat](key-repeat.md) | Sends again whatever keycode was last sent | + +## Miscellaneous behaviors + +| Binding | Behavior | Description | +| -------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | +| `&trans` | [Transparent](misc.md#transparent) | Passes the key press down to the next active layer in the stack for processing | +| `&none` | [None](misc.md#none) | Swallows and stops the key press, no keycode will be sent nor will the key press be passed down to the next active layer in the stack | + +## Layer navigation behaviors + +| Binding | Behavior | Description | +| ------- | -------------------------------------------- | -------------------------------------------------------------------------------------------------------- | +| `&mo` | [Momentary Layer](layers.md#momentary-layer) | Enables a layer while a key is pressed | +| `<` | [Layer-tap](layers.md#layer-tap) | Enables a layer when a key is held, and outputs a key press when the key is only tapped for a short time | +| `&to` | [To Layer](layers.md#to-layer) | Enables a layer and disables all other layers except the default layer | +| `&tog` | [Toggle Layer](layers.md#toggle-layer) | Enables a layer until the layer is manually disabled | +| `&sl` | [Sticky Layer](sticky-layer.md) | Activates a layer until another key is pressed, then deactivates it | + +## Mouse emulation behaviors + +| Binding | Behavior | Description | +| ------- | ----------------------------------------------------------- | ------------------------------- | +| `&mkp` | [Mouse Button Press](mouse-emulation.md#mouse-button-press) | Emulates pressing mouse buttons | + +## Reset behaviors + +| Binding | Behavior | Description | +| ------------- | --------------------------------- | ---------------------------------------------------------------------------------------- | +| `&sys_reset` | [Reset](reset.md#reset) | Resets the keyboard and re-runs the firmware flashed to the device | +| `&bootloader` | [Bootloader](reset.md#bootloader) | Resets the keyboard and puts it into bootloader mode, allowing you to flash new firmware | + +## Output selection behaviors + +| Binding | Behavior | Description | +| ------- | -------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | +| `&bt` | [Bluetooth](bluetooth.md#bluetooth-behavior) | Completes a bluetooth action given on press, for example switching between devices | +| `&out` | [Output Selection](outputs.md#output-selection-behavior) | Allows selecting whether output is sent to the USB or bluetooth connection when both are connected | + +## Lighting behaviors + +| Binding | Behavior | Description | +| --------- | ---------------------------------------------- | ---------------------------------------------------------------------------- | +| `&rgb_ug` | [RGB Underglow](underglow.md#behavior-binding) | Controls the RGB underglow, usually placed underneath the keyboard | +| `&bl` | [Backlight](backlight.md#behavior-binding) | Controls the keyboard backlighting, usually placed through or under switches | + +## Power management behaviors + +| Binding | Behavior | Description | +| ------------ | --------------------------------------------- | --------------------------------------------------------------- | +| `&ext_power` | [Power management](power.md#behavior-binding) | Allows enabling or disabling the VCC power output to save power | + +## User-defined behaviors + +| Behavior | Description | +| ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| [Macros](macros.md) | Allows configuring a list of other behaviors to invoke when the key is pressed and/or released | +| [Hold-Tap](hold-tap.mdx) | Invokes different behaviors depending on key press duration or interrupting keys. This is the basis for [layer-tap](layers.md#layer-tap) and [mod-tap](mod-tap.md) | +| [Tap Dance](tap-dance.mdx) | Invokes different behaviors corresponding to how many times a key is pressed | +| [Mod-Morph](mod-morph.md) | Invokes different behaviors depending on whether a specified modifier is held during a key press | +| [Sensor Rotation](sensor-rotate.md) | Invokes different behaviors depending on whether a sensor is rotated clockwise or counter-clockwise | diff --git a/docs/sidebars.js b/docs/sidebars.js index 284eb09b..37613d56 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -22,6 +22,7 @@ module.exports = { "features/beta-testing", ], Behaviors: [ + "behaviors/index", "behaviors/key-press", "behaviors/layers", "behaviors/misc", From c684cee76f6732d1da3dc23564b64e9a1ea08671 Mon Sep 17 00:00:00 2001 From: Cem Aksoylar Date: Sun, 24 Mar 2024 17:58:20 -0700 Subject: [PATCH 03/45] refactor(docs): Refer to overview page for behaviors --- docs/docs/development/new-behavior.mdx | 2 +- docs/docs/development/new-shield.mdx | 2 +- docs/docs/features/keymaps.mdx | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/docs/development/new-behavior.mdx b/docs/docs/development/new-behavior.mdx index cabc417f..914abf52 100644 --- a/docs/docs/development/new-behavior.mdx +++ b/docs/docs/development/new-behavior.mdx @@ -8,7 +8,7 @@ import TabItem from "@theme/TabItem"; ## Overview -This document outlines how to develop a behavior for ZMK and prepare the changes for a pull request. +This document outlines how to develop a [behavior](../behaviors/index.mdx) for ZMK and prepare the changes for a pull request. Behaviors are assigned to key positions and determine what happens when they are pressed and released. They are implemented in Zephyr as "devices": they consist of a devicetree binding file, which specifies the properties of the behavior, and a driver written in C code. This allows for the ability to create unique instances of these behaviors in [keymaps](../features/keymaps.mdx) or devicetree-source-include files (`.dtsi`). While instances of behaviors stored in keymaps are created by end-users for their personal needs, the instances that live in the .dtsi files are stored and documented in ZMK directly, which removes the need for end-users to set up common use-cases of these behaviors in their personal keymaps. diff --git a/docs/docs/development/new-shield.mdx b/docs/docs/development/new-shield.mdx index 2cd82bc6..e99332a8 100644 --- a/docs/docs/development/new-shield.mdx +++ b/docs/docs/development/new-shield.mdx @@ -386,7 +386,7 @@ The two `#include` lines at the top of the keymap are required in order to bring ### Keymap Behaviors -For the full documentation on the available behaviors for use in keymaps, start with reviewing [`kp`](../behaviors/key-press.md) and then use the sidebar to review the others available within ZMK. +For documentation on the available behaviors for use in keymaps, see the [overview page for behaviors](../behaviors/index.mdx). ## Metadata diff --git a/docs/docs/features/keymaps.mdx b/docs/docs/features/keymaps.mdx index c8d46ef9..105ca794 100644 --- a/docs/docs/features/keymaps.mdx +++ b/docs/docs/features/keymaps.mdx @@ -33,7 +33,7 @@ For example, the simplest behavior in ZMK is the "key press" behavior, which res (a certain spot on the keyboard), and when that position is pressed, send a keycode to the host, and when the key position is released, updates the host to notify of the keycode being released. -For the full set of possible behaviors, start at the [Key Press](../behaviors/key-press.md) behavior. +For the full set of possible behaviors, see the [overview page for behaviors](../behaviors/index.mdx). ## Layers @@ -128,11 +128,9 @@ that defines just one layer for this keymap: Each layer should have: -1. A `bindings` property this will be a list of behavior bindings, one for each key position for the keyboard. +1. A `bindings` property this will be a list of [behavior bindings](../behaviors/index.mdx), one for each key position for the keyboard. 1. (Optional) A `sensor-bindings` property that will be a list of behavior bindings for each sensor on the keyboard. (Currently, only encoders are supported as sensor hardware, but in the future devices like trackpoints would be supported the same way) -For the full set of possible behaviors, start at the [Key Press](../behaviors/key-press.md) behavior. - ### Complete Example Putting this all together, a complete [`kyria.keymap`](https://github.com/zmkfirmware/zmk/blob/main/app/boards/shields/kyria/kyria.keymap) looks like: From 94c3b9a24607c966e28d44b6634c6084a21f84b2 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Sun, 24 Mar 2024 21:09:16 +0000 Subject: [PATCH 04/45] feat(build): Allow specifying snippets for a build. * Allow using snippets https://docs.zephyrproject.org/latest/build/snippets/using.html for user builds in a `snippets` array properly. --- .github/workflows/build-user-config.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-user-config.yml b/.github/workflows/build-user-config.yml index d8ea057e..c3e4789d 100644 --- a/.github/workflows/build-user-config.yml +++ b/.github/workflows/build-user-config.yml @@ -65,6 +65,7 @@ jobs: board: ${{ matrix.board }} shield: ${{ matrix.shield }} artifact_name: ${{ matrix.artifact-name }} + snippet: ${{ matrix.snippet }} run: | if [ -e zephyr/module.yml ]; then export zmk_load_arg=" -DZMK_EXTRA_MODULES='${GITHUB_WORKSPACE}'" @@ -75,7 +76,12 @@ jobs: echo "base_dir=${GITHUB_WORKSPACE}" >> $GITHUB_ENV fi + if [ -n "${snippet}" ]; then + extra_west_args="-S \"${snippet}\"" + fi + echo "zephyr_version=${ZEPHYR_VERSION}" >> $GITHUB_ENV + echo "extra_west_args=${extra_west_args}" >> $GITHUB_ENV echo "extra_cmake_args=${shield:+-DSHIELD=\"$shield\"}${zmk_load_arg}" >> $GITHUB_ENV echo "display_name=${shield:+$shield - }${board}" >> $GITHUB_ENV echo "artifact_name=${artifact_name:-${shield:+$shield-}${board}-zmk}" >> $GITHUB_ENV @@ -120,7 +126,7 @@ jobs: - name: West Build (${{ env.display_name }}) working-directory: ${{ env.base_dir }} shell: sh -x {0} - run: west build -s zmk/app -d "${{ env.build_dir }}" -b "${{ matrix.board }}" -- -DZMK_CONFIG=${{ env.base_dir }}/${{ inputs.config_path }} ${{ env.extra_cmake_args }} ${{ matrix.cmake-args }} + run: west build -s zmk/app -d "${{ env.build_dir }}" -b "${{ matrix.board }}" ${{ env.extra_west_args }} -- -DZMK_CONFIG=${{ env.base_dir }}/${{ inputs.config_path }} ${{ env.extra_cmake_args }} ${{ matrix.cmake-args }} - name: ${{ env.display_name }} Kconfig file run: | From e806cd6da1cd8239f6bf549f2956c567c31cccbc Mon Sep 17 00:00:00 2001 From: Thomas Huber <113915837+huber-th@users.noreply.github.com> Date: Wed, 27 Mar 2024 14:20:53 -0700 Subject: [PATCH 05/45] feat(gitignore): add clangd cache folder --- .gitignore | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index 4ddd0852..1ef282a9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,14 @@ /zephyr /zmk-config /build + +# macOS *.DS_Store + +# Python __pycache__ .python-version .venv + +# clangd +app/.cache/ From 58ccc5970dc804857d81609857d4217278ec025c Mon Sep 17 00:00:00 2001 From: Thomas Huber <113915837+huber-th@users.noreply.github.com> Date: Wed, 27 Mar 2024 14:16:34 -0700 Subject: [PATCH 06/45] fix(build): Modify function return type Change return type of `sticky_key_timeout` function to `void` given it does not return any value to remove compiler warnings. --- app/src/behaviors/behavior_sticky_key.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/behaviors/behavior_sticky_key.c b/app/src/behaviors/behavior_sticky_key.c index 2c279c3b..b0e9f3ed 100644 --- a/app/src/behaviors/behavior_sticky_key.c +++ b/app/src/behaviors/behavior_sticky_key.c @@ -121,7 +121,7 @@ static inline int release_sticky_key_behavior(struct active_sticky_key *sticky_k return behavior_keymap_binding_released(&binding, event); } -static inline int on_sticky_key_timeout(struct active_sticky_key *sticky_key) { +static inline void on_sticky_key_timeout(struct active_sticky_key *sticky_key) { // If the key is lazy, a release is not needed on timeout if (sticky_key->config->lazy) { clear_sticky_key(sticky_key); From adb3a13dc583e1876d5aa17da0ade4c1024cad7d Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 15 Mar 2023 21:48:30 -0400 Subject: [PATCH 07/45] feat: Add soft on/off support. Initial work on a soft on/off support for ZMK. Triggering soft off puts the device into deep sleep with only a specific GPIO pin configured to wake the device, avoiding waking from other key presses in the matrix like the normal deep sleep. Co-authored-by: Cem Aksoylar --- app/CMakeLists.txt | 4 + app/Kconfig | 9 + app/Kconfig.behaviors | 10 + app/dts/behaviors.dtsi | 1 + app/dts/behaviors/soft_off.dtsi | 15 ++ .../bindings/zmk,behavior-key-scanned.yaml | 31 +++ app/dts/bindings/zmk,behavior-key.yaml | 31 +++ .../bindings/zmk,soft-off-wakeup-sources.yaml | 14 ++ app/dts/bindings/zmk,wakeup-trigger-key.yaml | 18 ++ app/include/zmk/pm.h | 9 + app/src/behavior_key.c | 159 ++++++++++++++ app/src/behavior_key_scanned.c | 194 ++++++++++++++++++ app/src/kscan.c | 6 + app/src/pm.c | 59 ++++++ app/src/wakeup_trigger_key.c | 87 ++++++++ docs/docs/behaviors/soft-off.md | 38 ++++ docs/docs/development/new-shield.mdx | 1 + docs/docs/features/soft-off.md | 164 +++++++++++++++ docs/sidebars.js | 2 + 19 files changed, 852 insertions(+) create mode 100644 app/dts/behaviors/soft_off.dtsi create mode 100644 app/dts/bindings/zmk,behavior-key-scanned.yaml create mode 100644 app/dts/bindings/zmk,behavior-key.yaml create mode 100644 app/dts/bindings/zmk,soft-off-wakeup-sources.yaml create mode 100644 app/dts/bindings/zmk,wakeup-trigger-key.yaml create mode 100644 app/include/zmk/pm.h create mode 100644 app/src/behavior_key.c create mode 100644 app/src/behavior_key_scanned.c create mode 100644 app/src/pm.c create mode 100644 app/src/wakeup_trigger_key.c create mode 100644 docs/docs/behaviors/soft-off.md create mode 100644 docs/docs/features/soft-off.md diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index b12d0474..ac83091c 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -29,7 +29,11 @@ target_sources(app PRIVATE src/matrix_transform.c) target_sources(app PRIVATE src/sensors.c) target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/wpm.c) target_sources(app PRIVATE src/event_manager.c) +target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_KEY app PRIVATE src/behavior_key.c) +target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_KEY_SCANNED app PRIVATE src/behavior_key_scanned.c) +target_sources_ifdef(CONFIG_ZMK_PM_SOFT_OFF app PRIVATE src/pm.c) target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/ext_power_generic.c) +target_sources_ifdef(CONFIG_ZMK_WAKEUP_TRIGGER_KEY app PRIVATE src/wakeup_trigger_key.c) target_sources(app PRIVATE src/events/activity_state_changed.c) target_sources(app PRIVATE src/events/position_state_changed.c) target_sources(app PRIVATE src/events/sensor_event.c) diff --git a/app/Kconfig b/app/Kconfig index 21e97ac6..60a959d4 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -423,6 +423,15 @@ config ZMK_EXT_POWER bool "Enable support to control external power output" default y +config ZMK_PM_SOFT_OFF + bool "Soft-off support" + select PM_DEVICE + +config ZMK_WAKEUP_TRIGGER_KEY + bool "Hardware supported wakeup (GPIO)" + default y + depends on DT_HAS_ZMK_WAKEUP_TRIGGER_KEY_ENABLED && ZMK_PM_SOFT_OFF + #Power Management endmenu diff --git a/app/Kconfig.behaviors b/app/Kconfig.behaviors index 7a1e44f6..e5e0c4d7 100644 --- a/app/Kconfig.behaviors +++ b/app/Kconfig.behaviors @@ -1,6 +1,16 @@ # Copyright (c) 2023 The ZMK Contributors # SPDX-License-Identifier: MIT +config ZMK_BEHAVIOR_KEY + bool + default y + depends on DT_HAS_ZMK_BEHAVIOR_KEY_ENABLED + +config ZMK_BEHAVIOR_KEY_SCANNED + bool + default y + depends on DT_HAS_ZMK_BEHAVIOR_KEY_SCANNED_ENABLED + config ZMK_BEHAVIOR_KEY_TOGGLE bool default y diff --git a/app/dts/behaviors.dtsi b/app/dts/behaviors.dtsi index 23f2fee2..fde75271 100644 --- a/app/dts/behaviors.dtsi +++ b/app/dts/behaviors.dtsi @@ -20,3 +20,4 @@ #include #include #include +#include diff --git a/app/dts/behaviors/soft_off.dtsi b/app/dts/behaviors/soft_off.dtsi new file mode 100644 index 00000000..fa6571a1 --- /dev/null +++ b/app/dts/behaviors/soft_off.dtsi @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +/ { + behaviors { + /omit-if-no-ref/ soft_off: behavior_soft_off { + compatible = "zmk,behavior-soft-off"; + label = "SOFTOFF"; + #binding-cells = <0>; + }; + }; +}; diff --git a/app/dts/bindings/zmk,behavior-key-scanned.yaml b/app/dts/bindings/zmk,behavior-key-scanned.yaml new file mode 100644 index 00000000..bdb3abaf --- /dev/null +++ b/app/dts/bindings/zmk,behavior-key-scanned.yaml @@ -0,0 +1,31 @@ +# Copyright (c) 2023 The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: | + Driver for a dedicated key triggered by matrix scanning for invoking a connected behavior. + +compatible: "zmk,behavior-key-scanned" + +include: base.yaml + +properties: + key: + type: phandle + required: true + description: The GPIO key that triggers wake via interrupt + bindings: + type: phandle + required: true + description: The GPIO key that triggers wake via interrupt + debounce-press-ms: + type: int + default: 5 + description: Debounce time for key press in milliseconds. Use 0 for eager debouncing. + debounce-release-ms: + type: int + default: 5 + description: Debounce time for key release in milliseconds. + debounce-scan-period-ms: + type: int + default: 1 + description: Time between reads in milliseconds when any key is pressed. diff --git a/app/dts/bindings/zmk,behavior-key.yaml b/app/dts/bindings/zmk,behavior-key.yaml new file mode 100644 index 00000000..ff7a585e --- /dev/null +++ b/app/dts/bindings/zmk,behavior-key.yaml @@ -0,0 +1,31 @@ +# Copyright (c) 2023 The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: | + Driver for a dedicated key for invoking a connected behavior. + +compatible: "zmk,behavior-key" + +include: base.yaml + +properties: + key: + type: phandle + required: true + description: The GPIO key that triggers wake via interrupt + bindings: + type: phandle + required: true + description: The GPIO key that triggers wake via interrupt + debounce-press-ms: + type: int + default: 5 + description: Debounce time for key press in milliseconds. Use 0 for eager debouncing. + debounce-release-ms: + type: int + default: 5 + description: Debounce time for key release in milliseconds. + debounce-scan-period-ms: + type: int + default: 1 + description: Time between reads in milliseconds when any key is pressed. diff --git a/app/dts/bindings/zmk,soft-off-wakeup-sources.yaml b/app/dts/bindings/zmk,soft-off-wakeup-sources.yaml new file mode 100644 index 00000000..f98039a0 --- /dev/null +++ b/app/dts/bindings/zmk,soft-off-wakeup-sources.yaml @@ -0,0 +1,14 @@ +# Copyright (c) 2023 The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: | + Description of all possible wakeup-sources from a forces + soft-off state. + +compatible: "zmk,soft-off-wakeup-sources" + +properties: + wakeup-sources: + type: phandles + required: true + description: List of wakeup-sources that should be enabled to wake the system from forces soft-off state. diff --git a/app/dts/bindings/zmk,wakeup-trigger-key.yaml b/app/dts/bindings/zmk,wakeup-trigger-key.yaml new file mode 100644 index 00000000..fa7636d1 --- /dev/null +++ b/app/dts/bindings/zmk,wakeup-trigger-key.yaml @@ -0,0 +1,18 @@ +# Copyright (c) 2023 The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: | + Driver for a dedicated key for waking the device from sleep + +compatible: "zmk,wakeup-trigger-key" + +include: base.yaml + +properties: + trigger: + type: phandle + required: true + description: The GPIO key that triggers wake via interrupt + extra-gpios: + type: phandle-array + description: Optional set of pins that should be set active before sleeping. diff --git a/app/include/zmk/pm.h b/app/include/zmk/pm.h new file mode 100644 index 00000000..dff217af --- /dev/null +++ b/app/include/zmk/pm.h @@ -0,0 +1,9 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +int zmk_pm_soft_off(void); \ No newline at end of file diff --git a/app/src/behavior_key.c b/app/src/behavior_key.c new file mode 100644 index 00000000..3633ce39 --- /dev/null +++ b/app/src/behavior_key.c @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#define DT_DRV_COMPAT zmk_behavior_key + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +struct behavior_key_config { + struct zmk_debounce_config debounce_config; + int32_t debounce_scan_period_ms; + struct gpio_dt_spec key; +}; + +struct behavior_key_data { + struct zmk_behavior_binding binding; + struct zmk_debounce_state debounce_state; + struct gpio_callback key_callback; + const struct device *dev; + struct k_work_delayable update_work; + uint32_t read_time; +}; + +static void bk_enable_interrupt(const struct device *dev) { + const struct behavior_key_config *config = dev->config; + + gpio_pin_interrupt_configure_dt(&config->key, GPIO_INT_LEVEL_ACTIVE); +} + +static void bk_disable_interrupt(const struct device *dev) { + const struct behavior_key_config *config = dev->config; + + gpio_pin_interrupt_configure_dt(&config->key, GPIO_INT_DISABLE); +} + +static void bk_read(const struct device *dev) { + const struct behavior_key_config *config = dev->config; + struct behavior_key_data *data = dev->data; + + zmk_debounce_update(&data->debounce_state, gpio_pin_get_dt(&config->key), + config->debounce_scan_period_ms, &config->debounce_config); + + if (zmk_debounce_get_changed(&data->debounce_state)) { + const bool pressed = zmk_debounce_is_pressed(&data->debounce_state); + + struct zmk_behavior_binding_event event = {.position = INT32_MAX, + .timestamp = k_uptime_get()}; + + if (pressed) { + behavior_keymap_binding_pressed(&data->binding, event); + } else { + behavior_keymap_binding_released(&data->binding, event); + } + } + + if (zmk_debounce_is_active(&data->debounce_state)) { + data->read_time += config->debounce_scan_period_ms; + + k_work_reschedule(&data->update_work, K_TIMEOUT_ABS_MS(data->read_time)); + } else { + bk_enable_interrupt(dev); + } +} + +static void bk_update_work(struct k_work *work) { + struct k_work_delayable *dwork = CONTAINER_OF(work, struct k_work_delayable, work); + struct behavior_key_data *data = CONTAINER_OF(dwork, struct behavior_key_data, update_work); + bk_read(data->dev); +} + +static void bk_gpio_irq_callback(const struct device *port, struct gpio_callback *cb, + const gpio_port_pins_t pin) { + struct behavior_key_data *data = CONTAINER_OF(cb, struct behavior_key_data, key_callback); + + bk_disable_interrupt(data->dev); + + data->read_time = k_uptime_get(); + k_work_reschedule(&data->update_work, K_NO_WAIT); +} + +static int behavior_key_init(const struct device *dev) { + const struct behavior_key_config *config = dev->config; + struct behavior_key_data *data = dev->data; + + if (!device_is_ready(config->key.port)) { + LOG_ERR("GPIO port is not ready"); + return -ENODEV; + } + + k_work_init_delayable(&data->update_work, bk_update_work); + data->dev = dev; + + gpio_pin_configure_dt(&config->key, GPIO_INPUT); + gpio_init_callback(&data->key_callback, bk_gpio_irq_callback, BIT(config->key.pin)); + gpio_add_callback(config->key.port, &data->key_callback); + + while (gpio_pin_get_dt(&config->key)) { + k_sleep(K_MSEC(100)); + } + + bk_enable_interrupt(dev); + + return 0; +} + +static int behavior_key_pm_action(const struct device *dev, enum pm_device_action action) { + const struct behavior_key_config *config = dev->config; + struct behavior_key_data *data = dev->data; + + int ret; + + switch (action) { + case PM_DEVICE_ACTION_SUSPEND: + bk_disable_interrupt(dev); + ret = gpio_remove_callback(config->key.port, &data->key_callback); + break; + case PM_DEVICE_ACTION_RESUME: + ret = gpio_add_callback(config->key.port, &data->key_callback); + bk_enable_interrupt(dev); + break; + default: + ret = -ENOTSUP; + break; + } + + return ret; +} + +#define BK_INST(n) \ + const struct behavior_key_config bk_config_##n = { \ + .key = GPIO_DT_SPEC_GET(DT_INST_PHANDLE(n, key), gpios), \ + .debounce_config = \ + { \ + .debounce_press_ms = DT_INST_PROP(n, debounce_press_ms), \ + .debounce_release_ms = DT_INST_PROP(n, debounce_release_ms), \ + }, \ + .debounce_scan_period_ms = DT_INST_PROP(n, debounce_scan_period_ms), \ + }; \ + struct behavior_key_data bk_data_##n = { \ + .binding = ZMK_KEYMAP_EXTRACT_BINDING(0, DT_DRV_INST(n)), \ + }; \ + PM_DEVICE_DT_INST_DEFINE(n, behavior_key_pm_action); \ + DEVICE_DT_INST_DEFINE(n, behavior_key_init, PM_DEVICE_DT_INST_GET(n), &bk_data_##n, \ + &bk_config_##n, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL); + +DT_INST_FOREACH_STATUS_OKAY(BK_INST) diff --git a/app/src/behavior_key_scanned.c b/app/src/behavior_key_scanned.c new file mode 100644 index 00000000..c961b292 --- /dev/null +++ b/app/src/behavior_key_scanned.c @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#define DT_DRV_COMPAT zmk_behavior_key_scanned + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +struct behavior_key_scanned_config { + struct zmk_debounce_config debounce_config; + int32_t debounce_scan_period_ms; + struct gpio_dt_spec key; +}; + +struct behavior_key_scanned_data { + struct zmk_behavior_binding binding; + struct zmk_debounce_state debounce_state; + struct gpio_callback key_callback; + const struct device *dev; + struct k_work_delayable update_work; + uint32_t read_time; + bool pin_active; + bool active_scan_detected; + struct k_sem sem; +}; + +static void bks_enable_interrupt(const struct device *dev, bool active_scanning) { + const struct behavior_key_scanned_config *config = dev->config; + + gpio_pin_interrupt_configure_dt(&config->key, active_scanning ? GPIO_INT_EDGE_TO_ACTIVE + : GPIO_INT_LEVEL_ACTIVE); +} + +static void bks_disable_interrupt(const struct device *dev) { + const struct behavior_key_scanned_config *config = dev->config; + + gpio_pin_interrupt_configure_dt(&config->key, GPIO_INT_DISABLE); +} + +static void bks_read(const struct device *dev) { + const struct behavior_key_scanned_config *config = dev->config; + struct behavior_key_scanned_data *data = dev->data; + + if (k_sem_take(&data->sem, K_NO_WAIT) < 0) { + // k_work_reschedule(&data->update_work, K_NO_WAIT); + return; + } + + zmk_debounce_update(&data->debounce_state, data->active_scan_detected, + config->debounce_scan_period_ms, &config->debounce_config); + + if (zmk_debounce_get_changed(&data->debounce_state)) { + const bool pressed = zmk_debounce_is_pressed(&data->debounce_state); + + struct zmk_behavior_binding_event event = {.position = INT32_MAX, + .timestamp = k_uptime_get()}; + + if (pressed) { + behavior_keymap_binding_pressed(&data->binding, event); + } else { + behavior_keymap_binding_released(&data->binding, event); + } + } + + if (zmk_debounce_is_active(&data->debounce_state)) { + data->active_scan_detected = false; + data->read_time += config->debounce_scan_period_ms; + + k_work_schedule(&data->update_work, K_TIMEOUT_ABS_MS(data->read_time)); + } else { + bks_enable_interrupt(dev, false); + } + + k_sem_give(&data->sem); +} + +static void bks_update_work(struct k_work *work) { + struct k_work_delayable *dwork = CONTAINER_OF(work, struct k_work_delayable, work); + struct behavior_key_scanned_data *data = + CONTAINER_OF(dwork, struct behavior_key_scanned_data, update_work); + bks_read(data->dev); +} + +static void bks_gpio_irq_callback(const struct device *port, struct gpio_callback *cb, + const gpio_port_pins_t pin) { + struct behavior_key_scanned_data *data = + CONTAINER_OF(cb, struct behavior_key_scanned_data, key_callback); + const struct behavior_key_scanned_config *config = data->dev->config; + + uint32_t time = k_uptime_get(); + + if (k_sem_take(&data->sem, K_MSEC(10)) < 0) { + LOG_ERR("FAILED TO TAKE THE SEMAPHORE"); + // Do more? + return; + } + + data->active_scan_detected = true; + data->read_time = time; + + if (!zmk_debounce_is_active(&data->debounce_state)) { + // When we get that very first interrupt, we need to schedule the update checks to fall in + // between each of the real scans, so we can do our checks for state *after* each scan has + // occurred. + k_work_reschedule(&data->update_work, + K_TIMEOUT_ABS_MS(time + (config->debounce_scan_period_ms / 2))); + + bks_enable_interrupt(data->dev, true); + } + + k_sem_give(&data->sem); +} + +static int behavior_key_scanned_init(const struct device *dev) { + const struct behavior_key_scanned_config *config = dev->config; + struct behavior_key_scanned_data *data = dev->data; + + if (!device_is_ready(config->key.port)) { + LOG_ERR("GPIO port is not ready"); + return -ENODEV; + } + + k_work_init_delayable(&data->update_work, bks_update_work); + k_sem_init(&data->sem, 1, 1); + data->dev = dev; + + gpio_pin_configure_dt(&config->key, GPIO_INPUT); + gpio_init_callback(&data->key_callback, bks_gpio_irq_callback, BIT(config->key.pin)); + gpio_add_callback(config->key.port, &data->key_callback); + + while (gpio_pin_get_dt(&config->key)) { + k_sleep(K_MSEC(100)); + } + + bks_enable_interrupt(dev, false); + + return 0; +} + +static int behavior_key_scanned_pm_action(const struct device *dev, enum pm_device_action action) { + const struct behavior_key_scanned_config *config = dev->config; + struct behavior_key_scanned_data *data = dev->data; + + int ret; + + switch (action) { + case PM_DEVICE_ACTION_SUSPEND: + bks_disable_interrupt(dev); + ret = gpio_remove_callback(config->key.port, &data->key_callback); + break; + case PM_DEVICE_ACTION_RESUME: + ret = gpio_add_callback(config->key.port, &data->key_callback); + bks_enable_interrupt(dev, false); + break; + default: + ret = -ENOTSUP; + break; + } + + return ret; +} + +#define BK_INST(n) \ + const struct behavior_key_scanned_config bks_config_##n = { \ + .key = GPIO_DT_SPEC_GET(DT_INST_PHANDLE(n, key), gpios), \ + .debounce_config = \ + { \ + .debounce_press_ms = DT_INST_PROP(n, debounce_press_ms), \ + .debounce_release_ms = DT_INST_PROP(n, debounce_release_ms), \ + }, \ + .debounce_scan_period_ms = DT_INST_PROP(n, debounce_scan_period_ms), \ + }; \ + struct behavior_key_scanned_data bks_data_##n = { \ + .binding = ZMK_KEYMAP_EXTRACT_BINDING(0, DT_DRV_INST(n)), \ + }; \ + PM_DEVICE_DT_INST_DEFINE(n, behavior_key_scanned_pm_action); \ + DEVICE_DT_INST_DEFINE(n, behavior_key_scanned_init, PM_DEVICE_DT_INST_GET(n), &bks_data_##n, \ + &bks_config_##n, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ + NULL); + +DT_INST_FOREACH_STATUS_OKAY(BK_INST) diff --git a/app/src/kscan.c b/app/src/kscan.c index ff55290a..c04ce2d8 100644 --- a/app/src/kscan.c +++ b/app/src/kscan.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -75,6 +76,11 @@ int zmk_kscan_init(const struct device *dev) { kscan_config(dev, zmk_kscan_callback); kscan_enable_callback(dev); +#if IS_ENABLED(CONFIG_PM_DEVICE) + if (pm_device_wakeup_is_capable(dev)) { + pm_device_wakeup_enable(dev, true); + } +#endif // IS_ENABLED(CONFIG_PM_DEVICE) return 0; } diff --git a/app/src/pm.c b/app/src/pm.c new file mode 100644 index 00000000..af126239 --- /dev/null +++ b/app/src/pm.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include +#include + +#include +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +#define HAS_WAKERS DT_HAS_COMPAT_STATUS_OKAY(zmk_soft_off_wakeup_sources) + +#if HAS_WAKERS + +#define DEVICE_WITH_SEP(node_id, prop, idx) DEVICE_DT_GET(DT_PROP_BY_IDX(node_id, prop, idx)), + +const struct device *soft_off_wakeup_sources[] = { + DT_FOREACH_PROP_ELEM(DT_INST(0, zmk_soft_off_wakeup_sources), wakeup_sources, DEVICE_WITH_SEP)}; + +#endif + +int zmk_pm_soft_off(void) { +#if IS_ENABLED(CONFIG_PM_DEVICE) + size_t device_count; + const struct device *devs; + + device_count = z_device_get_all_static(&devs); + + // There may be some matrix/direct kscan devices that would be used for wakeup + // from normal "inactive goes to sleep" behavior, so disable them as wakeup devices + // and then suspend them so we're ready to take over setting up our system + // and then putting it into an off state. + for (int i = 0; i < device_count; i++) { + const struct device *dev = &devs[i]; + + LOG_DBG("soft-on-off pressed cb: suspend device"); + if (pm_device_wakeup_is_enabled(dev)) { + pm_device_wakeup_enable(dev, false); + } + pm_device_action_run(dev, PM_DEVICE_ACTION_SUSPEND); + } +#endif // IS_ENABLED(CONFIG_PM_DEVICE) + +#if HAS_WAKERS + for (int i = 0; i < ARRAY_SIZE(soft_off_wakeup_sources); i++) { + const struct device *dev = soft_off_wakeup_sources[i]; + pm_device_wakeup_enable(dev, true); + pm_device_action_run(dev, PM_DEVICE_ACTION_RESUME); + } +#endif // HAS_WAKERS + + LOG_DBG("soft-on-off interrupt: go to sleep"); + return pm_state_force(0U, &(struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0}); +} diff --git a/app/src/wakeup_trigger_key.c b/app/src/wakeup_trigger_key.c new file mode 100644 index 00000000..0cc4f250 --- /dev/null +++ b/app/src/wakeup_trigger_key.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include +#include + +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +#define DT_DRV_COMPAT zmk_wakeup_trigger_key + +struct wakeup_trigger_key_config { + struct gpio_dt_spec trigger; + size_t extra_gpios_count; + struct gpio_dt_spec extra_gpios[]; +}; + +static int zmk_wakeup_trigger_key_init(const struct device *dev) { +#if IS_ENABLED(CONFIG_PM_DEVICE) + pm_device_init_suspended(dev); + pm_device_wakeup_enable(dev, true); +#endif + + return 0; +} + +#if IS_ENABLED(CONFIG_PM_DEVICE) + +static int wakeup_trigger_key_pm_action(const struct device *dev, enum pm_device_action action) { + const struct wakeup_trigger_key_config *config = dev->config; + int ret = 0; + + switch (action) { + case PM_DEVICE_ACTION_RESUME: + ret = gpio_pin_interrupt_configure_dt(&config->trigger, GPIO_INT_LEVEL_ACTIVE); + if (ret < 0) { + LOG_ERR("Failed to configure wakeup trigger key GPIO pin interrupt (%d)", ret); + return ret; + } + + for (int i = 0; i < config->extra_gpios_count; i++) { + ret = gpio_pin_configure_dt(&config->extra_gpios[i], GPIO_OUTPUT_ACTIVE); + if (ret < 0) { + LOG_WRN("Failed to set extra GPIO pin active for waker (%d)", ret); + } + } + break; + case PM_DEVICE_ACTION_SUSPEND: + + ret = gpio_pin_interrupt_configure_dt(&config->trigger, GPIO_INT_DISABLE); + if (ret < 0) { + LOG_ERR("Failed to configure wakeup trigger key GPIO pin interrupt (%d)", ret); + return ret; + } + break; + default: + ret = -ENOTSUP; + break; + } + + return ret; +} + +#endif // IS_ENABLED(CONFIG_PM_DEVICE) + +#define WAKEUP_TRIGGER_EXTRA_GPIO_SPEC(idx, n) \ + GPIO_DT_SPEC_GET_BY_IDX(DT_DRV_INST(n), extra_gpios, idx) + +#define WAKEUP_TRIGGER_KEY_INST(n) \ + const struct wakeup_trigger_key_config wtk_cfg_##n = { \ + .trigger = GPIO_DT_SPEC_GET(DT_INST_PROP(n, trigger), gpios), \ + .extra_gpios = {LISTIFY(DT_PROP_LEN_OR(DT_DRV_INST(n), extra_gpios, 0), \ + WAKEUP_TRIGGER_EXTRA_GPIO_SPEC, (, ), n)}, \ + .extra_gpios_count = DT_PROP_LEN_OR(DT_DRV_INST(n), extra_gpios, 0), \ + }; \ + PM_DEVICE_DT_INST_DEFINE(n, wakeup_trigger_key_pm_action); \ + DEVICE_DT_INST_DEFINE(n, zmk_wakeup_trigger_key_init, PM_DEVICE_DT_INST_GET(n), NULL, \ + &wtk_cfg_##n, PRE_KERNEL_2, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL); + +DT_INST_FOREACH_STATUS_OKAY(WAKEUP_TRIGGER_KEY_INST) diff --git a/docs/docs/behaviors/soft-off.md b/docs/docs/behaviors/soft-off.md new file mode 100644 index 00000000..05374004 --- /dev/null +++ b/docs/docs/behaviors/soft-off.md @@ -0,0 +1,38 @@ +--- +title: Soft Off Behavior +sidebar_label: Soft Off +--- + +## Summary + +The soft off behavior is used to force the keyboard into an off state. Depending on the specific keyboard hardware, the keyboard can be turned back on again either with a dedicated on/off button that is available, or using the reset button found on the device. + +For more information, see the [Soft Off Feature](../features/soft-off.md) page. + +### Behavior Binding + +- Reference: `&soft_off` + +Example: + +``` +&soft_off +``` + +### Configuration + +#### Hold Time + +By default, the keyboard will be turned off as soon as the key bound to the behavior is released, even if the key is only tapped briefly. If you would prefer that the key need be held a certain amount of time before releasing, you can set the `hold-time-ms` to a non-zero value in your keymap: + +``` +&soft_off { + hold-time-ms = <5000>; // Only turn off it the key is held for 5 seconds or longer. +}; + +/ { + keymap { + ... + }; +}; +``` diff --git a/docs/docs/development/new-shield.mdx b/docs/docs/development/new-shield.mdx index e99332a8..867ccbc8 100644 --- a/docs/docs/development/new-shield.mdx +++ b/docs/docs/development/new-shield.mdx @@ -171,6 +171,7 @@ this might look something like: kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; diode-direction = "col2row"; + wakeup-source; col-gpios = <&pro_micro 15 GPIO_ACTIVE_HIGH> diff --git a/docs/docs/features/soft-off.md b/docs/docs/features/soft-off.md new file mode 100644 index 00000000..b0206825 --- /dev/null +++ b/docs/docs/features/soft-off.md @@ -0,0 +1,164 @@ +--- +title: Soft Off Feature +sidebar_label: Soft Off +--- + +Similar to the deep sleep feature that sends the keyboard into a low power state after a certain period of inactivity, the soft off feature is used to turn the keyboard on and off explicitly. Depending on the keyboard, this may be through a dedicated on/off push button, or merely through an additional binding in the keymap to turn the device off and the existing reset button to turn the device back on. + +The feature is intended as an alternative to using a hardware switch to physically cut power from the battery to the keyboard. This can be useful for existing PCBs not designed for wireless that don't have a power switch, or for new designs that favor a push button on/off like found on other devices. + +:::note + +The power off is accomplished by putting the MCU into a "soft off" state. Power is _not_ technically removed from the entire system, but the device will only be woken from the state by a few possible events. + +::: + +Once powered off, the keyboard will only wake up when: + +- You press the same button/sequence that you pressed to power off the keyboard, or +- You press a reset button found on the keyboard. + +## Soft Off With Existing Designs + +For existing designs, using soft off is as simple as placing the [Soft Off Behavior](../behaviors/soft-off.md) in your keymap and then invoking it. For splits, at least for now, you'll need to place it somewhere on each side of your keymap and trigger on both sides, starting from the peripheral side first. + +You can then wake up the keyboard by pressing the reset button once, and repeating this for each side for split keyboards. + +## Adding Soft On/Off To New Designs + +### Hardware Design + +ZMK's soft on/off requires a dedicated GPIO pin to be used to trigger powering off, and to wake the core from the +soft off state when it goes active again later. + +#### Simple Direct Pin + +The simplest way to achieve this is with a push button between a GPIO pin and ground. + +#### Matrix-Integrated Hardware Combo + +Another, more complicated option is to tie two of the switch outputs in the matrix together through an AND gate and connect that to the dedicated GPIO pin. This way you can use a key combination in your existing keyboard matrix to trigger soft on/off. To make this work best, the two switches used should both be driven by the same matrix input pin so that both will be active simultaneously on the AND gate inputs. The alternative is to use a combination of diodes and capacitors to ensure both pins are active/high at the same time even if scanning sets them high at different times. + +### Firmware Changes + +Several items work together to make both triggering soft off properly, and setting up the device to _wake_ from soft off work as expected. + +#### GPIO Key + +Zephyr's basic GPIO Key concept is used to configure the GPIO pin that will be used for both triggering soft off and waking the device later. Here is an example for a keyboard with a dedicated on/off push button that is a direct wire between the GPIO pin and ground: + +``` +/ { + keys { + compatible = "gpio-keys"; + wakeup_key: wakeup_key { + gpios = <&gpio0 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; + }; + }; +}; +``` + +GPIO keys are defined using child nodes under the `gpio-keys` compatible node. Each child needs just one property defined: + +- The `gpios` property should be a phandle-array with a fully defined GPIO pin and with the correct pull up/down and active high/low flags set. In the above example the soft on/off would be triggered by pulling the specified pin low, typically by pressing a switch that has the other leg connected to ground. + +#### Behavior Key + +Next, we will create a new "behavior key". Behavior keys are an easy way to tie a keymap behavior to a GPIO key outside of the normal keymap processing. They do _not_ do the normal keymap processing, so they are only suitable for use with basic behaviors, not complicated macros, hold-taps, etc. + +In this case, we will be creating a dedicated instance of the [Soft Off Behavior](../behaviors/soft-off.md) that will be used only for our hardware on/off button, then binding it to our key: + +``` +/ { + behaviors { + hw_soft_off: behavior_hw_soft_off { + compatible = "zmk,behavior-soft-off"; + #binding-cells = <0>; + label = "HW_SO"; + hold-time-ms = <5000>; + }; + }; + + soft_off_behavior_key { + compatible = "zmk,behavior-key"; + bindings = <&hw_soft_off>; + key = <&wakeup_key>; + }; +}; +``` + +Here are the properties for the behavior key node: + +- The `compatible` property for the node must be `zmk,behavior-key`. +- The `bindings` property is a phandle to the soft off behavior defined above. +- The `key` property is a phandle to the GPIO key defined earlier. + +If you have set up your on/off to be controlled by a matrix-integrated combo, the behavior key needs use a different driver that will handle detecting the pressed state when the pin is toggled by the other matrix kscan driver: + +``` +/ { + soft_off_behavior_key { + compatible = "zmk,behavior-key-scanned"; + status = "okay"; + bindings = <&hw_soft_off>; + key = <&wakeup_key>; + }; +}; +``` + +Note that the only difference from the `soft_off_behavior_key` definition for GPIO keys above is the `compatible` value of `zmk,behavior-key-scanned`. + +#### Wakeup Sources + +Zephyr has general support for the concept of a device as a "wakeup source", which ZMK has not previously used. Adding soft off requires properly updating the existing `kscan` devices with the `wakeup-source` property, e.g.: + +``` +/ { + kscan0: kscan_0 { + compatible = "zmk,kscan-gpio-matrix"; + label = "KSCAN"; + diode-direction = "col2row"; + wakeup-source; + + ... + }; +}; +``` + +#### Soft Off Waker + +Next, we need to add another device which will be enabled only when the keyboard is going into soft off state, and will configure the previously declared GPIO key with the correct interrupt configuration to wake the device from soft off once it is pressed. + +``` +/ { + wakeup_source: wakeup_source { + compatible = "zmk,wakeup-trigger-key"; + + trigger = <&wakeup_key>; + wakeup-source; + }; +}; +``` + +Here are the properties for the node: + +- The `compatible` property for the node must be `zmk,wakeup-trigger-key`. +- The `trigger` property is a phandle to the GPIO key defined earlier. +- The `wakeup-source` property signals to Zephyr this device should not be suspended during the shutdown procedure. +- An optional `output-gpios` property contains a list of GPIO pins (including the appropriate flags) to set active before going into power off, if needed to ensure the GPIO pin will trigger properly to wake the keyboard. This is only needed for matrix integrated combos. For those keyboards, the list should include the matrix output needs needed so the combo hardware is properly "driven" when the keyboard is off. + +Once that is declared, we will list it in an additional configuration section so that the ZMK soft off process knows it needs to enable this device as part of the soft off processing: + +``` +/ { + soft_off_wakers { + compatible = "zmk,soft-off-wakeup-sources"; + wakeup-sources = <&wakeup_source>; + }; +}; +``` + +Here are the properties for the node: + +- The `compatible` property for the node must be `zmk,soft-off-wakeup-sources`. +- The `wakeup-sources` property is a [phandle array](../config/index.md#devicetree-property-types) pointing to all the devices that should be enabled during the shutdown process to be sure they can later wake the keyboard. diff --git a/docs/sidebars.js b/docs/sidebars.js index 37613d56..ebf0aef7 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -19,6 +19,7 @@ module.exports = { "features/underglow", "features/backlight", "features/battery", + "features/soft-off", "features/beta-testing", ], Behaviors: [ @@ -44,6 +45,7 @@ module.exports = { "behaviors/underglow", "behaviors/backlight", "behaviors/power", + "behaviors/soft-off", ], Codes: [ "codes/index", From 738c3c0e3b3878ddaebafae65becdf5e5f68fe86 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 13 Sep 2023 19:58:53 +0000 Subject: [PATCH 08/45] feat(kscan): Add PM support to GPIO kscan drivers. * Add PM device hook to the kscan direct & matrix drivers. --- app/module/drivers/kscan/kscan_gpio_direct.c | 27 +++++++++++++++++++- app/module/drivers/kscan/kscan_gpio_matrix.c | 27 +++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/app/module/drivers/kscan/kscan_gpio_direct.c b/app/module/drivers/kscan/kscan_gpio_direct.c index b5e77f63..2bc35f4c 100644 --- a/app/module/drivers/kscan/kscan_gpio_direct.c +++ b/app/module/drivers/kscan/kscan_gpio_direct.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -318,6 +319,28 @@ static int kscan_direct_init(const struct device *dev) { return 0; } +#if IS_ENABLED(CONFIG_PM_DEVICE) + +static int kscan_direct_pm_action(const struct device *dev, enum pm_device_action action) { + int ret = 0; + + switch (action) { + case PM_DEVICE_ACTION_SUSPEND: + kscan_direct_disable(dev); + break; + case PM_DEVICE_ACTION_RESUME: + kscan_direct_enable(dev); + break; + default: + ret = -ENOTSUP; + break; + } + + return ret; +} + +#endif // IS_ENABLED(CONFIG_PM_DEVICE) + static const struct kscan_driver_api kscan_direct_api = { .config = kscan_direct_configure, .enable_callback = kscan_direct_enable, @@ -354,7 +377,9 @@ static const struct kscan_driver_api kscan_direct_api = { .toggle_mode = DT_INST_PROP(n, toggle_mode), \ }; \ \ - DEVICE_DT_INST_DEFINE(n, &kscan_direct_init, NULL, &kscan_direct_data_##n, \ + PM_DEVICE_DT_INST_DEFINE(n, kscan_direct_pm_action); \ + \ + DEVICE_DT_INST_DEFINE(n, &kscan_direct_init, PM_DEVICE_DT_INST_GET(n), &kscan_direct_data_##n, \ &kscan_direct_config_##n, POST_KERNEL, CONFIG_KSCAN_INIT_PRIORITY, \ &kscan_direct_api); diff --git a/app/module/drivers/kscan/kscan_gpio_matrix.c b/app/module/drivers/kscan/kscan_gpio_matrix.c index 6e91bf95..3917196e 100644 --- a/app/module/drivers/kscan/kscan_gpio_matrix.c +++ b/app/module/drivers/kscan/kscan_gpio_matrix.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -421,6 +422,28 @@ static int kscan_matrix_init(const struct device *dev) { return 0; } +#if IS_ENABLED(CONFIG_PM_DEVICE) + +static int kscan_matrix_pm_action(const struct device *dev, enum pm_device_action action) { + int ret = 0; + + switch (action) { + case PM_DEVICE_ACTION_SUSPEND: + kscan_matrix_disable(dev); + break; + case PM_DEVICE_ACTION_RESUME: + kscan_matrix_enable(dev); + break; + default: + ret = -ENOTSUP; + break; + } + + return ret; +} + +#endif // IS_ENABLED(CONFIG_PM_DEVICE) + static const struct kscan_driver_api kscan_matrix_api = { .config = kscan_matrix_configure, .enable_callback = kscan_matrix_enable, @@ -465,7 +488,9 @@ static const struct kscan_driver_api kscan_matrix_api = { .diode_direction = INST_DIODE_DIR(n), \ }; \ \ - DEVICE_DT_INST_DEFINE(n, &kscan_matrix_init, NULL, &kscan_matrix_data_##n, \ + PM_DEVICE_DT_INST_DEFINE(n, kscan_matrix_pm_action); \ + \ + DEVICE_DT_INST_DEFINE(n, &kscan_matrix_init, PM_DEVICE_DT_INST_GET(n), &kscan_matrix_data_##n, \ &kscan_matrix_config_##n, POST_KERNEL, CONFIG_KSCAN_INIT_PRIORITY, \ &kscan_matrix_api); From b19df0cbf053a88a9389bdf463df431e5b7e70a5 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 13 Sep 2023 20:01:02 +0000 Subject: [PATCH 09/45] feat(behaviors): Add soft off behavior. * New soft-off behavior that can be used to force the device into soft-off state with only certain configured wakeup devices. --- app/CMakeLists.txt | 1 + app/Kconfig.behaviors | 6 ++ app/dts/behaviors/soft_off.dtsi | 3 +- .../behaviors/zmk,behavior-soft-off.yaml | 14 ++++ app/src/behaviors/behavior_soft_off.c | 70 +++++++++++++++++++ 5 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 app/dts/bindings/behaviors/zmk,behavior-soft-off.yaml create mode 100644 app/src/behaviors/behavior_soft_off.c diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index ac83091c..bf7cfeef 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -42,6 +42,7 @@ target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/events/wpm_state_changed.c) target_sources_ifdef(CONFIG_USB_DEVICE_STACK app PRIVATE src/events/usb_conn_state_changed.c) target_sources(app PRIVATE src/behaviors/behavior_reset.c) target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/behaviors/behavior_ext_power.c) +target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_SOFT_OFF app PRIVATE src/behaviors/behavior_soft_off.c) if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL) target_sources(app PRIVATE src/hid.c) target_sources_ifdef(CONFIG_ZMK_MOUSE app PRIVATE src/mouse.c) diff --git a/app/Kconfig.behaviors b/app/Kconfig.behaviors index e5e0c4d7..7c30f50e 100644 --- a/app/Kconfig.behaviors +++ b/app/Kconfig.behaviors @@ -22,6 +22,12 @@ config ZMK_BEHAVIOR_MOUSE_KEY_PRESS depends on DT_HAS_ZMK_BEHAVIOR_MOUSE_KEY_PRESS_ENABLED imply ZMK_MOUSE +config ZMK_BEHAVIOR_SOFT_OFF + bool + default y + select ZMK_PM_SOFT_OFF + depends on DT_HAS_ZMK_BEHAVIOR_SOFT_OFF_ENABLED + config ZMK_BEHAVIOR_SENSOR_ROTATE_COMMON bool diff --git a/app/dts/behaviors/soft_off.dtsi b/app/dts/behaviors/soft_off.dtsi index fa6571a1..c68230f3 100644 --- a/app/dts/behaviors/soft_off.dtsi +++ b/app/dts/behaviors/soft_off.dtsi @@ -6,9 +6,8 @@ / { behaviors { - /omit-if-no-ref/ soft_off: behavior_soft_off { + soft_off: soft_off { compatible = "zmk,behavior-soft-off"; - label = "SOFTOFF"; #binding-cells = <0>; }; }; diff --git a/app/dts/bindings/behaviors/zmk,behavior-soft-off.yaml b/app/dts/bindings/behaviors/zmk,behavior-soft-off.yaml new file mode 100644 index 00000000..1467ede4 --- /dev/null +++ b/app/dts/bindings/behaviors/zmk,behavior-soft-off.yaml @@ -0,0 +1,14 @@ +# Copyright (c) 2023 The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: Soft-Off Behavior + +compatible: "zmk,behavior-soft-off" + +include: zero_param.yaml + +properties: + hold-time-ms: + type: int + required: false + description: Number of milliseconds the behavior must be held before releasing will actually trigger a soft-off. diff --git a/app/src/behaviors/behavior_soft_off.c b/app/src/behaviors/behavior_soft_off.c new file mode 100644 index 00000000..0f24a644 --- /dev/null +++ b/app/src/behaviors/behavior_soft_off.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2020 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#define DT_DRV_COMPAT zmk_behavior_soft_off + +#include +#include +#include + +#include +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +struct behavior_soft_off_config { + uint32_t hold_time_ms; +}; + +struct behavior_soft_off_data { + uint32_t press_start; +}; + +static int behavior_soft_off_init(const struct device *dev) { return 0; }; + +static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding, + struct zmk_behavior_binding_event event) { + const struct device *dev = zmk_behavior_get_binding(binding->behavior_dev); + struct behavior_soft_off_data *data = dev->data; + +#if IS_ENABLED(CONFIG_ZMK_SPLIT) && !IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) + zmk_pm_soft_off(); +#else + data->press_start = k_uptime_get(); +#endif + + return ZMK_BEHAVIOR_OPAQUE; +} + +static int on_keymap_binding_released(struct zmk_behavior_binding *binding, + struct zmk_behavior_binding_event event) { + const struct device *dev = zmk_behavior_get_binding(binding->behavior_dev); + struct behavior_soft_off_data *data = dev->data; + const struct behavior_soft_off_config *config = dev->config; + + if (config->hold_time_ms == 0 || (k_uptime_get() - data->press_start) >= config->hold_time_ms) { + zmk_pm_soft_off(); + } + + return ZMK_BEHAVIOR_OPAQUE; +} + +static const struct behavior_driver_api behavior_soft_off_driver_api = { + .binding_pressed = on_keymap_binding_pressed, + .binding_released = on_keymap_binding_released, + .locality = BEHAVIOR_LOCALITY_GLOBAL, +}; + +#define BSO_INST(n) \ + static const struct behavior_soft_off_config bso_config_##n = { \ + .hold_time_ms = DT_INST_PROP_OR(n, hold_time_ms, 0), \ + }; \ + static struct behavior_soft_off_data bso_data_##n = {}; \ + BEHAVIOR_DT_INST_DEFINE(0, behavior_soft_off_init, NULL, &bso_data_##n, &bso_config_##n, \ + APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ + &behavior_soft_off_driver_api); + +DT_INST_FOREACH_STATUS_OKAY(BSO_INST) From d3fffb9e8913105bc732eb9cbfbd380a9b98167e Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Sat, 16 Sep 2023 11:50:12 -0700 Subject: [PATCH 10/45] feat(shields): Add soft-off to the nrf52840dk ZMK Uno * Use Button 1 for soft off on the nrf52840 when using the ZMK Uno shield. --- .../boards/nrf52840dk_nrf52840.overlay | 43 ++++++++++++++++++- app/boards/shields/zmk_uno/zmk_uno.dtsi | 2 + 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay index 05c7ed9d..d08105c6 100644 --- a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay +++ b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay @@ -12,6 +12,15 @@ bias-pull-up; }; }; + + qdec_sleep: qdec_sleep { + group1 { + psels = , + ; + bias-pull-up; + low-power-enable; + }; + }; }; // Set up the QDEC hardware based driver and give it the same label as the deleted node. @@ -20,6 +29,38 @@ encoder: &qdec0 { led-pre = <0>; steps = <80>; pinctrl-0 = <&qdec_default>; - pinctrl-1 = <&qdec_default>; + pinctrl-1 = <&qdec_sleep>; pinctrl-names = "default", "sleep"; }; + +/ { + behaviors { + soft_off: soft_off { + compatible = "zmk,behavior-soft-off"; + #binding-cells = <0>; + status = "okay"; + }; + }; + + wakeup_source: wakeup_source { + compatible = "zmk,wakeup-trigger-key"; + status = "okay"; + + trigger = <&button0>; + wakeup-source; + }; + + soft_off_wakers { + compatible = "zmk,soft-off-wakeup-sources"; + status = "okay"; + + wakeup-sources = <&wakeup_source>; + }; + + soft_off_behavior_key { + compatible = "zmk,behavior-key"; + status = "okay"; + bindings = <&soft_off>; + key = <&button0>; + }; +}; \ No newline at end of file diff --git a/app/boards/shields/zmk_uno/zmk_uno.dtsi b/app/boards/shields/zmk_uno/zmk_uno.dtsi index 63deb06a..196ac8b5 100644 --- a/app/boards/shields/zmk_uno/zmk_uno.dtsi +++ b/app/boards/shields/zmk_uno/zmk_uno.dtsi @@ -124,6 +124,7 @@ nice_view_spi: &arduino_spi { kscan_matrix: kscan_matrix { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; @@ -141,6 +142,7 @@ nice_view_spi: &arduino_spi { kscan_direct: kscan_direct { compatible = "zmk,kscan-gpio-direct"; + wakeup-source; status = "disabled"; input-gpios From 860e53b33ac3b09b233a0ec4c6cb0621895fb16c Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Thu, 7 Dec 2023 00:36:02 +0000 Subject: [PATCH 11/45] refactor: Promote new endpoints API * Add ability for external callers to clear the current endpoint. --- app/include/zmk/endpoints.h | 2 ++ app/src/endpoints.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/include/zmk/endpoints.h b/app/include/zmk/endpoints.h index 70240183..f2aff2bc 100644 --- a/app/include/zmk/endpoints.h +++ b/app/include/zmk/endpoints.h @@ -73,3 +73,5 @@ int zmk_endpoints_send_report(uint16_t usage_page); #if IS_ENABLED(CONFIG_ZMK_MOUSE) int zmk_endpoints_send_mouse_report(); #endif // IS_ENABLE(CONFIG_ZMK_MOUSE) + +void zmk_endpoints_clear_current(void); diff --git a/app/src/endpoints.c b/app/src/endpoints.c index f8452d93..7c9d15a3 100644 --- a/app/src/endpoints.c +++ b/app/src/endpoints.c @@ -340,7 +340,7 @@ static int zmk_endpoints_init(void) { return 0; } -static void disconnect_current_endpoint(void) { +void zmk_endpoints_clear_current(void) { zmk_hid_keyboard_clear(); zmk_hid_consumer_clear(); #if IS_ENABLED(CONFIG_ZMK_MOUSE) @@ -356,7 +356,7 @@ static void update_current_endpoint(void) { if (!zmk_endpoint_instance_eq(new_instance, current_instance)) { // Cancel all current keypresses so keys don't stay held on the old endpoint. - disconnect_current_endpoint(); + zmk_endpoints_clear_current(); current_instance = new_instance; From 0d4d4fb2b5bdfd2b259febe14a9b1dfbf991872d Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Thu, 7 Dec 2023 00:37:31 +0000 Subject: [PATCH 12/45] feat(pm): Clear HID data before soft off. * Make sure the connected host has no held HID usages before we sleep. --- app/src/pm.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/pm.c b/app/src/pm.c index af126239..a78b6ae5 100644 --- a/app/src/pm.c +++ b/app/src/pm.c @@ -13,6 +13,8 @@ #include LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); +#include + #define HAS_WAKERS DT_HAS_COMPAT_STATUS_OKAY(zmk_soft_off_wakeup_sources) #if HAS_WAKERS @@ -29,6 +31,10 @@ int zmk_pm_soft_off(void) { size_t device_count; const struct device *devs; +#if !IS_ENABLED(CONFIG_ZMK_SPLIT) || IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) + zmk_endpoints_clear_current(); +#endif + device_count = z_device_get_all_static(&devs); // There may be some matrix/direct kscan devices that would be used for wakeup From e78249ee067910725cd7fcf447b016ce3cdcf318 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Thu, 7 Dec 2023 04:04:13 +0000 Subject: [PATCH 13/45] fix(bt): Fix BT tests after soft off work. * Move to explicit enable of `ZMK_PM_SOFT_OFF` to turn on the feature and use the behaviors, which matches how other features work, and helps with split and testing schemes. --- app/Kconfig.behaviors | 3 +-- .../shields/zmk_uno/boards/nrf52840dk_nrf52840.conf | 1 + app/dts/behaviors/soft_off.dtsi | 3 ++- docs/docs/config/power.md | 12 ++++++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.conf diff --git a/app/Kconfig.behaviors b/app/Kconfig.behaviors index 7c30f50e..18fd5c15 100644 --- a/app/Kconfig.behaviors +++ b/app/Kconfig.behaviors @@ -25,8 +25,7 @@ config ZMK_BEHAVIOR_MOUSE_KEY_PRESS config ZMK_BEHAVIOR_SOFT_OFF bool default y - select ZMK_PM_SOFT_OFF - depends on DT_HAS_ZMK_BEHAVIOR_SOFT_OFF_ENABLED + depends on DT_HAS_ZMK_BEHAVIOR_SOFT_OFF_ENABLED && ZMK_PM_SOFT_OFF config ZMK_BEHAVIOR_SENSOR_ROTATE_COMMON bool diff --git a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.conf b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.conf new file mode 100644 index 00000000..ac92c4d8 --- /dev/null +++ b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.conf @@ -0,0 +1 @@ +CONFIG_ZMK_PM_SOFT_OFF=y \ No newline at end of file diff --git a/app/dts/behaviors/soft_off.dtsi b/app/dts/behaviors/soft_off.dtsi index c68230f3..c88e1b51 100644 --- a/app/dts/behaviors/soft_off.dtsi +++ b/app/dts/behaviors/soft_off.dtsi @@ -6,8 +6,9 @@ / { behaviors { - soft_off: soft_off { + /omit-if-no-ref/ soft_off: soft_off { compatible = "zmk,behavior-soft-off"; + label = "SOFTOFF"; #binding-cells = <0>; }; }; diff --git a/docs/docs/config/power.md b/docs/docs/config/power.md index 75e1b26a..396456b2 100644 --- a/docs/docs/config/power.md +++ b/docs/docs/config/power.md @@ -24,6 +24,18 @@ Definition file: [zmk/app/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/ | `CONFIG_ZMK_SLEEP` | bool | Enable deep sleep support | n | | `CONFIG_ZMK_IDLE_SLEEP_TIMEOUT` | int | Milliseconds of inactivity before entering deep sleep | 900000 | +## Soft Off + +The [soft off feature](../features/soft-off.md) allows turning the keyboard on/off from either dedicated hardware of using the [`&soft_off` behavior](../behaviors/soft-off.md) to turn off and a reset button to turn back on again. + +### Kconfig + +Definition file: [zmk/app/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/app/Kconfig) + +| Config | Type | Description | Default | +| ------------------------ | ---- | ------------------------------------------------------------------- | ------- | +| `CONFIG_ZMK_PM_SOFT_OFF` | bool | Enable soft off functionality from the keymap of dedicated hardware | n | + ## External Power Control Driver for enabling or disabling power to peripherals such as displays and lighting. This driver must be configured to use [power management behaviors](../behaviors/power.md). From 96968514e378cd134889637ee3e0c6311e08e13a Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Sat, 9 Dec 2023 17:18:04 -0500 Subject: [PATCH 14/45] fix(docs): Apply suggestions from code review Co-authored-by: Cem Aksoylar --- docs/docs/config/kscan.md | 8 +++++++- docs/docs/config/power.md | 4 ++-- docs/docs/features/soft-off.md | 9 ++++----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/docs/docs/config/kscan.md b/docs/docs/config/kscan.md index b49529d9..3076edc0 100644 --- a/docs/docs/config/kscan.md +++ b/docs/docs/config/kscan.md @@ -79,6 +79,7 @@ Definition file: [zmk/app/module/dts/bindings/kscan/zmk,kscan-gpio-direct.yaml]( | `debounce-scan-period-ms` | int | Time between reads in milliseconds when any key is pressed. | 1 | | `poll-period-ms` | int | Time between reads in milliseconds when no key is pressed and `CONFIG_ZMK_KSCAN_DIRECT_POLLING` is enabled. | 10 | | `toggle-mode` | bool | Use toggle switch mode. | n | +| `wakeup-source` | bool | Mark this kscan instance as able to wake the keyboard from deep sleep | n | By default, a switch will drain current through the internal pull up/down resistor whenever it is pressed. This is not ideal for a toggle switch, where the switch may be left in the "pressed" state for a long time. Enabling `toggle-mode` will make the driver flip between pull up and down as the switch is toggled to optimize for power. @@ -89,6 +90,7 @@ Assuming the switches connect each GPIO pin to the ground, the [GPIO flags](http ```dts kscan0: kscan { compatible = "zmk,kscan-gpio-direct"; + wakeup-source; input-gpios = <&pro_micro 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> , <&pro_micro 5 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> @@ -123,6 +125,7 @@ Definition file: [zmk/app/module/dts/bindings/kscan/zmk,kscan-gpio-matrix.yaml]( | `debounce-scan-period-ms` | int | Time between reads in milliseconds when any key is pressed. | 1 | | `diode-direction` | string | The direction of the matrix diodes | `"row2col"` | | `poll-period-ms` | int | Time between reads in milliseconds when no key is pressed and `CONFIG_ZMK_KSCAN_MATRIX_POLLING` is enabled. | 10 | +| `wakeup-source` | bool | Mark this kscan instance as able to wake the keyboard from deep sleep | n | The `diode-direction` property must be one of: @@ -137,6 +140,7 @@ The output pins (e.g. columns for `col2row`) should have the flag `GPIO_ACTIVE_H ```dts kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; col-gpios = <&pro_micro 4 GPIO_ACTIVE_HIGH> @@ -177,6 +181,7 @@ Definition file: [zmk/app/module/dts/bindings/kscan/zmk,kscan-gpio-charlieplex.y | `debounce-release-ms` | int | Debounce time for key release in milliseconds. | 5 | | `debounce-scan-period-ms` | int | Time between reads in milliseconds when any key is pressed. | 1 | | `poll-period-ms` | int | Time between reads in milliseconds when no key is pressed and `interrupt-gpois` is not set. | 10 | +| `wakeup-source` | bool | Mark this kscan instance as able to wake the keyboard from deep sleep | n | Define the transform with a [matrix transform](#matrix-transform). The row is always the driven pin, and the column always the receiving pin (input to the controller). For example, in `RC(5,0)` power flows from the 6th pin in `gpios` to the 1st pin in `gpios`. @@ -450,7 +455,8 @@ Note that the entire addressable space does not need to be mapped. }; kscan0: kscan { - compatible = "zmk,kscan-gpio-charlieplex"; + compatible = "zmk,kscan-gpio-charlieplex";k + wakeup-source; interrupt-gpios = <&pro_micro 21 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN) >; gpios diff --git a/docs/docs/config/power.md b/docs/docs/config/power.md index 396456b2..1a142eb2 100644 --- a/docs/docs/config/power.md +++ b/docs/docs/config/power.md @@ -26,7 +26,7 @@ Definition file: [zmk/app/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/ ## Soft Off -The [soft off feature](../features/soft-off.md) allows turning the keyboard on/off from either dedicated hardware of using the [`&soft_off` behavior](../behaviors/soft-off.md) to turn off and a reset button to turn back on again. +The [soft off feature](../features/soft-off.md) allows turning the keyboard on/off from either dedicated hardware, or using the [`&soft_off` behavior](../behaviors/soft-off.md) to turn off and a reset button to turn back on again. ### Kconfig @@ -34,7 +34,7 @@ Definition file: [zmk/app/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/ | Config | Type | Description | Default | | ------------------------ | ---- | ------------------------------------------------------------------- | ------- | -| `CONFIG_ZMK_PM_SOFT_OFF` | bool | Enable soft off functionality from the keymap of dedicated hardware | n | +| `CONFIG_ZMK_PM_SOFT_OFF` | bool | Enable soft off functionality from the keymap or dedicated hardware | n | ## External Power Control diff --git a/docs/docs/features/soft-off.md b/docs/docs/features/soft-off.md index b0206825..a3a5d7a1 100644 --- a/docs/docs/features/soft-off.md +++ b/docs/docs/features/soft-off.md @@ -20,15 +20,15 @@ Once powered off, the keyboard will only wake up when: ## Soft Off With Existing Designs -For existing designs, using soft off is as simple as placing the [Soft Off Behavior](../behaviors/soft-off.md) in your keymap and then invoking it. For splits, at least for now, you'll need to place it somewhere on each side of your keymap and trigger on both sides, starting from the peripheral side first. +For existing designs, using soft off is as simple as placing the [Soft Off Behavior](../behaviors/soft-off.md) in your keymap and then invoking it. You can then wake up the keyboard by pressing the reset button once, and repeating this for each side for split keyboards. -## Adding Soft On/Off To New Designs +## Adding Dedicated Soft On/Off GPIO Pin To New Designs ### Hardware Design -ZMK's soft on/off requires a dedicated GPIO pin to be used to trigger powering off, and to wake the core from the +ZMK's dedicated soft on/off pin feature requires a dedicated GPIO pin to be used to trigger powering off, and to wake the core from the soft off state when it goes active again later. #### Simple Direct Pin @@ -71,10 +71,9 @@ In this case, we will be creating a dedicated instance of the [Soft Off Behavior ``` / { behaviors { - hw_soft_off: behavior_hw_soft_off { + hw_soft_off: hw_soft_off { compatible = "zmk,behavior-soft-off"; #binding-cells = <0>; - label = "HW_SO"; hold-time-ms = <5000>; }; }; From fceb0351a58622e7a89a649efdb387c1c2ea2df1 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 20 Dec 2023 18:08:40 -0800 Subject: [PATCH 15/45] refactor: Fixes for soft-off based on review. * Better naming for gpio-key behavior triggers. * Tweaks to scanned behavior trigger to avoid bad semaphore use, and reduce chance of issues with slowly scanned matrixes. * Various code cleanups of style issues. --- app/CMakeLists.txt | 6 +- app/Kconfig | 4 +- app/Kconfig.behaviors | 8 +- app/boards/shields/zmk_uno/Kconfig.defconfig | 3 + .../zmk_uno/boards/nrf52840dk_nrf52840.conf | 1 - .../boards/nrf52840dk_nrf52840.overlay | 4 +- app/dts/behaviors/soft_off.dtsi | 1 - ...aml => zmk,gpio-key-behavior-trigger.yaml} | 4 +- ....yaml => zmk,gpio-key-wakeup-trigger.yaml} | 2 +- ...mk,gpio-scanned-key-behavior-trigger.yaml} | 4 +- .../bindings/zmk,soft-off-wakeup-sources.yaml | 4 +- app/module/drivers/kscan/kscan_gpio_direct.c | 7 +- app/module/drivers/kscan/kscan_gpio_matrix.c | 7 +- app/src/behaviors/behavior_soft_off.c | 2 +- ...vior_key.c => gpio_key_behavior_trigger.c} | 100 ++++++++------- app/src/gpio_key_wakeup_trigger.c | 96 ++++++++++++++ ....c => gpio_scanned_key_behavior_trigger.c} | 118 ++++++++---------- app/src/pm.c | 4 +- app/src/wakeup_trigger_key.c | 87 ------------- docs/docs/config/kscan.md | 2 +- docs/docs/features/soft-off.md | 12 +- 21 files changed, 237 insertions(+), 239 deletions(-) delete mode 100644 app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.conf rename app/dts/bindings/{zmk,behavior-key.yaml => zmk,gpio-key-behavior-trigger.yaml} (86%) rename app/dts/bindings/{zmk,wakeup-trigger-key.yaml => zmk,gpio-key-wakeup-trigger.yaml} (90%) rename app/dts/bindings/{zmk,behavior-key-scanned.yaml => zmk,gpio-scanned-key-behavior-trigger.yaml} (86%) rename app/src/{behavior_key.c => gpio_key_behavior_trigger.c} (61%) create mode 100644 app/src/gpio_key_wakeup_trigger.c rename app/src/{behavior_key_scanned.c => gpio_scanned_key_behavior_trigger.c} (57%) delete mode 100644 app/src/wakeup_trigger_key.c diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index bf7cfeef..908800db 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -29,11 +29,11 @@ target_sources(app PRIVATE src/matrix_transform.c) target_sources(app PRIVATE src/sensors.c) target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/wpm.c) target_sources(app PRIVATE src/event_manager.c) -target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_KEY app PRIVATE src/behavior_key.c) -target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_KEY_SCANNED app PRIVATE src/behavior_key_scanned.c) +target_sources_ifdef(CONFIG_ZMK_GPIO_KEY_BEHAVIOR_TRIGGER app PRIVATE src/gpio_key_behavior_trigger.c) +target_sources_ifdef(CONFIG_ZMK_GPIO_SCANNED_KEY_BEHAVIOR_TRIGGER app PRIVATE src/gpio_scanned_key_behavior_trigger.c) target_sources_ifdef(CONFIG_ZMK_PM_SOFT_OFF app PRIVATE src/pm.c) target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/ext_power_generic.c) -target_sources_ifdef(CONFIG_ZMK_WAKEUP_TRIGGER_KEY app PRIVATE src/wakeup_trigger_key.c) +target_sources_ifdef(CONFIG_ZMK_GPIO_KEY_WAKEUP_TRIGGER app PRIVATE src/gpio_key_wakeup_trigger.c) target_sources(app PRIVATE src/events/activity_state_changed.c) target_sources(app PRIVATE src/events/position_state_changed.c) target_sources(app PRIVATE src/events/sensor_event.c) diff --git a/app/Kconfig b/app/Kconfig index 60a959d4..3ca56793 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -427,10 +427,10 @@ config ZMK_PM_SOFT_OFF bool "Soft-off support" select PM_DEVICE -config ZMK_WAKEUP_TRIGGER_KEY +config ZMK_GPIO_KEY_WAKEUP_TRIGGER bool "Hardware supported wakeup (GPIO)" default y - depends on DT_HAS_ZMK_WAKEUP_TRIGGER_KEY_ENABLED && ZMK_PM_SOFT_OFF + depends on DT_HAS_ZMK_GPIO_KEY_WAKEUP_TRIGGER_ENABLED && ZMK_PM_SOFT_OFF #Power Management endmenu diff --git a/app/Kconfig.behaviors b/app/Kconfig.behaviors index 18fd5c15..ecd06ffb 100644 --- a/app/Kconfig.behaviors +++ b/app/Kconfig.behaviors @@ -1,15 +1,15 @@ # Copyright (c) 2023 The ZMK Contributors # SPDX-License-Identifier: MIT -config ZMK_BEHAVIOR_KEY +config ZMK_GPIO_KEY_BEHAVIOR_TRIGGER bool default y - depends on DT_HAS_ZMK_BEHAVIOR_KEY_ENABLED + depends on DT_HAS_ZMK_GPIO_KEY_BEHAVIOR_TRIGGER_ENABLED -config ZMK_BEHAVIOR_KEY_SCANNED +config ZMK_GPIO_SCANNED_KEY_BEHAVIOR_TRIGGER bool default y - depends on DT_HAS_ZMK_BEHAVIOR_KEY_SCANNED_ENABLED + depends on DT_HAS_ZMK_GPIO_SCANNED_KEY_BEHAVIOR_TRIGGER_ENABLED config ZMK_BEHAVIOR_KEY_TOGGLE bool diff --git a/app/boards/shields/zmk_uno/Kconfig.defconfig b/app/boards/shields/zmk_uno/Kconfig.defconfig index cccca1d2..95602ca7 100644 --- a/app/boards/shields/zmk_uno/Kconfig.defconfig +++ b/app/boards/shields/zmk_uno/Kconfig.defconfig @@ -20,4 +20,7 @@ config ZMK_RGB_UNDERGLOW select WS2812_STRIP select SPI +config ZMK_PM_SOFT_OFF + default y if BOARD_NRF52840DK_NRF52840 + endif diff --git a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.conf b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.conf deleted file mode 100644 index ac92c4d8..00000000 --- a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.conf +++ /dev/null @@ -1 +0,0 @@ -CONFIG_ZMK_PM_SOFT_OFF=y \ No newline at end of file diff --git a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay index d08105c6..b068b431 100644 --- a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay +++ b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay @@ -43,7 +43,7 @@ encoder: &qdec0 { }; wakeup_source: wakeup_source { - compatible = "zmk,wakeup-trigger-key"; + compatible = "zmk,gpio-key-wakeup-trigger"; status = "okay"; trigger = <&button0>; @@ -58,7 +58,7 @@ encoder: &qdec0 { }; soft_off_behavior_key { - compatible = "zmk,behavior-key"; + compatible = "zmk,gpio-key-behavior-trigger"; status = "okay"; bindings = <&soft_off>; key = <&button0>; diff --git a/app/dts/behaviors/soft_off.dtsi b/app/dts/behaviors/soft_off.dtsi index c88e1b51..1e58c771 100644 --- a/app/dts/behaviors/soft_off.dtsi +++ b/app/dts/behaviors/soft_off.dtsi @@ -8,7 +8,6 @@ behaviors { /omit-if-no-ref/ soft_off: soft_off { compatible = "zmk,behavior-soft-off"; - label = "SOFTOFF"; #binding-cells = <0>; }; }; diff --git a/app/dts/bindings/zmk,behavior-key.yaml b/app/dts/bindings/zmk,gpio-key-behavior-trigger.yaml similarity index 86% rename from app/dts/bindings/zmk,behavior-key.yaml rename to app/dts/bindings/zmk,gpio-key-behavior-trigger.yaml index ff7a585e..2a1387f0 100644 --- a/app/dts/bindings/zmk,behavior-key.yaml +++ b/app/dts/bindings/zmk,gpio-key-behavior-trigger.yaml @@ -4,7 +4,7 @@ description: | Driver for a dedicated key for invoking a connected behavior. -compatible: "zmk,behavior-key" +compatible: "zmk,gpio-key-behavior-trigger" include: base.yaml @@ -16,7 +16,7 @@ properties: bindings: type: phandle required: true - description: The GPIO key that triggers wake via interrupt + description: The behavior to invoke when the GPIO key is pressed debounce-press-ms: type: int default: 5 diff --git a/app/dts/bindings/zmk,wakeup-trigger-key.yaml b/app/dts/bindings/zmk,gpio-key-wakeup-trigger.yaml similarity index 90% rename from app/dts/bindings/zmk,wakeup-trigger-key.yaml rename to app/dts/bindings/zmk,gpio-key-wakeup-trigger.yaml index fa7636d1..4e16ff33 100644 --- a/app/dts/bindings/zmk,wakeup-trigger-key.yaml +++ b/app/dts/bindings/zmk,gpio-key-wakeup-trigger.yaml @@ -4,7 +4,7 @@ description: | Driver for a dedicated key for waking the device from sleep -compatible: "zmk,wakeup-trigger-key" +compatible: "zmk,gpio-key-wakeup-trigger" include: base.yaml diff --git a/app/dts/bindings/zmk,behavior-key-scanned.yaml b/app/dts/bindings/zmk,gpio-scanned-key-behavior-trigger.yaml similarity index 86% rename from app/dts/bindings/zmk,behavior-key-scanned.yaml rename to app/dts/bindings/zmk,gpio-scanned-key-behavior-trigger.yaml index bdb3abaf..860155dd 100644 --- a/app/dts/bindings/zmk,behavior-key-scanned.yaml +++ b/app/dts/bindings/zmk,gpio-scanned-key-behavior-trigger.yaml @@ -4,7 +4,7 @@ description: | Driver for a dedicated key triggered by matrix scanning for invoking a connected behavior. -compatible: "zmk,behavior-key-scanned" +compatible: "zmk,gpio-scanned-key-behavior-trigger" include: base.yaml @@ -16,7 +16,7 @@ properties: bindings: type: phandle required: true - description: The GPIO key that triggers wake via interrupt + description: The behavior to invoke when the GPIO key is pressed debounce-press-ms: type: int default: 5 diff --git a/app/dts/bindings/zmk,soft-off-wakeup-sources.yaml b/app/dts/bindings/zmk,soft-off-wakeup-sources.yaml index f98039a0..6b55d5d2 100644 --- a/app/dts/bindings/zmk,soft-off-wakeup-sources.yaml +++ b/app/dts/bindings/zmk,soft-off-wakeup-sources.yaml @@ -2,7 +2,7 @@ # SPDX-License-Identifier: MIT description: | - Description of all possible wakeup-sources from a forces + Description of all possible wakeup-sources from a forced soft-off state. compatible: "zmk,soft-off-wakeup-sources" @@ -11,4 +11,4 @@ properties: wakeup-sources: type: phandles required: true - description: List of wakeup-sources that should be enabled to wake the system from forces soft-off state. + description: List of wakeup-sources that should be enabled to wake the system from forced soft-off state. diff --git a/app/module/drivers/kscan/kscan_gpio_direct.c b/app/module/drivers/kscan/kscan_gpio_direct.c index 2bc35f4c..7cfdb480 100644 --- a/app/module/drivers/kscan/kscan_gpio_direct.c +++ b/app/module/drivers/kscan/kscan_gpio_direct.c @@ -322,8 +322,6 @@ static int kscan_direct_init(const struct device *dev) { #if IS_ENABLED(CONFIG_PM_DEVICE) static int kscan_direct_pm_action(const struct device *dev, enum pm_device_action action) { - int ret = 0; - switch (action) { case PM_DEVICE_ACTION_SUSPEND: kscan_direct_disable(dev); @@ -332,11 +330,8 @@ static int kscan_direct_pm_action(const struct device *dev, enum pm_device_actio kscan_direct_enable(dev); break; default: - ret = -ENOTSUP; - break; + return -ENOTSUP; } - - return ret; } #endif // IS_ENABLED(CONFIG_PM_DEVICE) diff --git a/app/module/drivers/kscan/kscan_gpio_matrix.c b/app/module/drivers/kscan/kscan_gpio_matrix.c index 3917196e..0daf97dc 100644 --- a/app/module/drivers/kscan/kscan_gpio_matrix.c +++ b/app/module/drivers/kscan/kscan_gpio_matrix.c @@ -425,8 +425,6 @@ static int kscan_matrix_init(const struct device *dev) { #if IS_ENABLED(CONFIG_PM_DEVICE) static int kscan_matrix_pm_action(const struct device *dev, enum pm_device_action action) { - int ret = 0; - switch (action) { case PM_DEVICE_ACTION_SUSPEND: kscan_matrix_disable(dev); @@ -435,11 +433,8 @@ static int kscan_matrix_pm_action(const struct device *dev, enum pm_device_actio kscan_matrix_enable(dev); break; default: - ret = -ENOTSUP; - break; + return -ENOTSUP; } - - return ret; } #endif // IS_ENABLED(CONFIG_PM_DEVICE) diff --git a/app/src/behaviors/behavior_soft_off.c b/app/src/behaviors/behavior_soft_off.c index 0f24a644..e6096bb4 100644 --- a/app/src/behaviors/behavior_soft_off.c +++ b/app/src/behaviors/behavior_soft_off.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 The ZMK Contributors + * Copyright (c) 2023 The ZMK Contributors * * SPDX-License-Identifier: MIT */ diff --git a/app/src/behavior_key.c b/app/src/gpio_key_behavior_trigger.c similarity index 61% rename from app/src/behavior_key.c rename to app/src/gpio_key_behavior_trigger.c index 3633ce39..a72f8e48 100644 --- a/app/src/behavior_key.c +++ b/app/src/gpio_key_behavior_trigger.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: MIT */ -#define DT_DRV_COMPAT zmk_behavior_key +#define DT_DRV_COMPAT zmk_gpio_key_behavior_trigger #include #include @@ -19,13 +19,13 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); -struct behavior_key_config { +struct gkbt_config { struct zmk_debounce_config debounce_config; int32_t debounce_scan_period_ms; struct gpio_dt_spec key; }; -struct behavior_key_data { +struct gkbt_data { struct zmk_behavior_binding binding; struct zmk_debounce_state debounce_state; struct gpio_callback key_callback; @@ -34,21 +34,21 @@ struct behavior_key_data { uint32_t read_time; }; -static void bk_enable_interrupt(const struct device *dev) { - const struct behavior_key_config *config = dev->config; +static void gkbt_enable_interrupt(const struct device *dev) { + const struct gkbt_config *config = dev->config; gpio_pin_interrupt_configure_dt(&config->key, GPIO_INT_LEVEL_ACTIVE); } -static void bk_disable_interrupt(const struct device *dev) { - const struct behavior_key_config *config = dev->config; +static void gkbt_disable_interrupt(const struct device *dev) { + const struct gkbt_config *config = dev->config; gpio_pin_interrupt_configure_dt(&config->key, GPIO_INT_DISABLE); } -static void bk_read(const struct device *dev) { - const struct behavior_key_config *config = dev->config; - struct behavior_key_data *data = dev->data; +static void gkbt_read(const struct device *dev) { + const struct gkbt_config *config = dev->config; + struct gkbt_data *data = dev->data; zmk_debounce_update(&data->debounce_state, gpio_pin_get_dt(&config->key), config->debounce_scan_period_ms, &config->debounce_config); @@ -71,65 +71,72 @@ static void bk_read(const struct device *dev) { k_work_reschedule(&data->update_work, K_TIMEOUT_ABS_MS(data->read_time)); } else { - bk_enable_interrupt(dev); + gkbt_enable_interrupt(dev); } } -static void bk_update_work(struct k_work *work) { +static void gkbt_update_work(struct k_work *work) { struct k_work_delayable *dwork = CONTAINER_OF(work, struct k_work_delayable, work); - struct behavior_key_data *data = CONTAINER_OF(dwork, struct behavior_key_data, update_work); - bk_read(data->dev); + struct gkbt_data *data = CONTAINER_OF(dwork, struct gkbt_data, update_work); + gkbt_read(data->dev); } -static void bk_gpio_irq_callback(const struct device *port, struct gpio_callback *cb, - const gpio_port_pins_t pin) { - struct behavior_key_data *data = CONTAINER_OF(cb, struct behavior_key_data, key_callback); +static void gkbt_gpio_irq_callback(const struct device *port, struct gpio_callback *cb, + const gpio_port_pins_t pin) { + struct gkbt_data *data = CONTAINER_OF(cb, struct gkbt_data, key_callback); - bk_disable_interrupt(data->dev); + gkbt_disable_interrupt(data->dev); data->read_time = k_uptime_get(); k_work_reschedule(&data->update_work, K_NO_WAIT); } -static int behavior_key_init(const struct device *dev) { - const struct behavior_key_config *config = dev->config; - struct behavior_key_data *data = dev->data; - - if (!device_is_ready(config->key.port)) { - LOG_ERR("GPIO port is not ready"); - return -ENODEV; - } - - k_work_init_delayable(&data->update_work, bk_update_work); - data->dev = dev; - - gpio_pin_configure_dt(&config->key, GPIO_INPUT); - gpio_init_callback(&data->key_callback, bk_gpio_irq_callback, BIT(config->key.pin)); - gpio_add_callback(config->key.port, &data->key_callback); +static void gkbt_wait_for_key_release(const struct device *dev) { + const struct gkbt_config *config = dev->config; while (gpio_pin_get_dt(&config->key)) { k_sleep(K_MSEC(100)); } +} - bk_enable_interrupt(dev); +static int gkbt_init(const struct device *dev) { + const struct gkbt_config *config = dev->config; + struct gkbt_data *data = dev->data; + + if (!device_is_ready(config->key.port)) { + LOG_ERR("GPIO port %s is not ready", config->key.port->name); + return -ENODEV; + } + + k_work_init_delayable(&data->update_work, gkbt_update_work); + data->dev = dev; + + gpio_pin_configure_dt(&config->key, GPIO_INPUT); + gpio_init_callback(&data->key_callback, gkbt_gpio_irq_callback, BIT(config->key.pin)); + gpio_add_callback(config->key.port, &data->key_callback); + + // Be sure our wakeup key is released before startup continues to avoid wake/sleep loop. + gkbt_wait_for_key_release(dev); + + gkbt_enable_interrupt(dev); return 0; } -static int behavior_key_pm_action(const struct device *dev, enum pm_device_action action) { - const struct behavior_key_config *config = dev->config; - struct behavior_key_data *data = dev->data; +static int gkbt_pm_action(const struct device *dev, enum pm_device_action action) { + const struct gkbt_config *config = dev->config; + struct gkbt_data *data = dev->data; int ret; switch (action) { case PM_DEVICE_ACTION_SUSPEND: - bk_disable_interrupt(dev); + gkbt_disable_interrupt(dev); ret = gpio_remove_callback(config->key.port, &data->key_callback); break; case PM_DEVICE_ACTION_RESUME: ret = gpio_add_callback(config->key.port, &data->key_callback); - bk_enable_interrupt(dev); + gkbt_enable_interrupt(dev); break; default: ret = -ENOTSUP; @@ -139,8 +146,8 @@ static int behavior_key_pm_action(const struct device *dev, enum pm_device_actio return ret; } -#define BK_INST(n) \ - const struct behavior_key_config bk_config_##n = { \ +#define GKBT_INST(n) \ + const struct gkbt_config gkbt_config_##n = { \ .key = GPIO_DT_SPEC_GET(DT_INST_PHANDLE(n, key), gpios), \ .debounce_config = \ { \ @@ -149,11 +156,12 @@ static int behavior_key_pm_action(const struct device *dev, enum pm_device_actio }, \ .debounce_scan_period_ms = DT_INST_PROP(n, debounce_scan_period_ms), \ }; \ - struct behavior_key_data bk_data_##n = { \ + struct gkbt_data gkbt_data_##n = { \ .binding = ZMK_KEYMAP_EXTRACT_BINDING(0, DT_DRV_INST(n)), \ }; \ - PM_DEVICE_DT_INST_DEFINE(n, behavior_key_pm_action); \ - DEVICE_DT_INST_DEFINE(n, behavior_key_init, PM_DEVICE_DT_INST_GET(n), &bk_data_##n, \ - &bk_config_##n, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL); + PM_DEVICE_DT_INST_DEFINE(n, gkbt_pm_action); \ + DEVICE_DT_INST_DEFINE(n, gkbt_init, PM_DEVICE_DT_INST_GET(n), &gkbt_data_##n, \ + &gkbt_config_##n, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ + NULL); -DT_INST_FOREACH_STATUS_OKAY(BK_INST) +DT_INST_FOREACH_STATUS_OKAY(GKBT_INST) diff --git a/app/src/gpio_key_wakeup_trigger.c b/app/src/gpio_key_wakeup_trigger.c new file mode 100644 index 00000000..ac0c6b22 --- /dev/null +++ b/app/src/gpio_key_wakeup_trigger.c @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include +#include + +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +#define DT_DRV_COMPAT zmk_gpio_key_wakeup_trigger + +struct gpio_key_wakeup_trigger_config { + struct gpio_dt_spec trigger; + size_t extra_gpios_count; + struct gpio_dt_spec extra_gpios[]; +}; + +static int zmk_gpio_key_wakeup_trigger_init(const struct device *dev) { +#if IS_ENABLED(CONFIG_PM_DEVICE) + pm_device_init_suspended(dev); + pm_device_wakeup_enable(dev, true); +#endif + + return 0; +} + +#if IS_ENABLED(CONFIG_PM_DEVICE) + +static int gpio_key_wakeup_trigger_pm_resume(const struct device *dev) { + const struct gpio_key_wakeup_trigger_config *config = dev->config; + + int ret = gpio_pin_interrupt_configure_dt(&config->trigger, GPIO_INT_LEVEL_ACTIVE); + if (ret < 0) { + LOG_ERR("Failed to configure wakeup trigger key GPIO pin interrupt (%d)", ret); + goto exit; + } + + for (int i = 0; i < config->extra_gpios_count; i++) { + ret = gpio_pin_configure_dt(&config->extra_gpios[i], GPIO_OUTPUT_ACTIVE); + if (ret < 0) { + LOG_WRN("Failed to set extra GPIO pin active for waker (%d)", ret); + goto exit; + } + } + +exit: + return ret; +} + +static int gpio_key_wakeup_trigger_pm_suspend(const struct device *dev) { + const struct gpio_key_wakeup_trigger_config *config = dev->config; + + int ret = gpio_pin_interrupt_configure_dt(&config->trigger, GPIO_INT_DISABLE); + if (ret < 0) { + LOG_ERR("Failed to configure wakeup trigger key GPIO pin interrupt (%d)", ret); + } + + return ret; +} + +static int gpio_key_wakeup_trigger_pm_action(const struct device *dev, + enum pm_device_action action) { + switch (action) { + case PM_DEVICE_ACTION_RESUME: + return gpio_key_wakeup_trigger_pm_resume(dev); + case PM_DEVICE_ACTION_SUSPEND: + return gpio_key_wakeup_trigger_pm_suspend(dev); + default: + return -ENOTSUP; + } +} + +#endif // IS_ENABLED(CONFIG_PM_DEVICE) + +#define WAKEUP_TRIGGER_EXTRA_GPIO_SPEC(idx, n) \ + GPIO_DT_SPEC_GET_BY_IDX(DT_DRV_INST(n), extra_gpios, idx) + +#define GPIO_KEY_WAKEUP_TRIGGER_INST(n) \ + const struct gpio_key_wakeup_trigger_config wtk_cfg_##n = { \ + .trigger = GPIO_DT_SPEC_GET(DT_INST_PROP(n, trigger), gpios), \ + .extra_gpios = {LISTIFY(DT_PROP_LEN_OR(DT_DRV_INST(n), extra_gpios, 0), \ + WAKEUP_TRIGGER_EXTRA_GPIO_SPEC, (, ), n)}, \ + .extra_gpios_count = DT_PROP_LEN_OR(DT_DRV_INST(n), extra_gpios, 0), \ + }; \ + PM_DEVICE_DT_INST_DEFINE(n, gpio_key_wakeup_trigger_pm_action); \ + DEVICE_DT_INST_DEFINE(n, zmk_gpio_key_wakeup_trigger_init, PM_DEVICE_DT_INST_GET(n), NULL, \ + &wtk_cfg_##n, PRE_KERNEL_2, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL); + +DT_INST_FOREACH_STATUS_OKAY(GPIO_KEY_WAKEUP_TRIGGER_INST) diff --git a/app/src/behavior_key_scanned.c b/app/src/gpio_scanned_key_behavior_trigger.c similarity index 57% rename from app/src/behavior_key_scanned.c rename to app/src/gpio_scanned_key_behavior_trigger.c index c961b292..d27b162b 100644 --- a/app/src/behavior_key_scanned.c +++ b/app/src/gpio_scanned_key_behavior_trigger.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: MIT */ -#define DT_DRV_COMPAT zmk_behavior_key_scanned +#define DT_DRV_COMPAT zmk_gpio_scanned_key_behavior_trigger #include #include @@ -19,45 +19,41 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); -struct behavior_key_scanned_config { +struct gskbt_config { struct zmk_debounce_config debounce_config; int32_t debounce_scan_period_ms; struct gpio_dt_spec key; }; -struct behavior_key_scanned_data { +struct gskbt_data { struct zmk_behavior_binding binding; struct zmk_debounce_state debounce_state; struct gpio_callback key_callback; const struct device *dev; struct k_work_delayable update_work; + struct k_work gpio_trigger_work; uint32_t read_time; + uint32_t trigger_time; bool pin_active; bool active_scan_detected; - struct k_sem sem; }; -static void bks_enable_interrupt(const struct device *dev, bool active_scanning) { - const struct behavior_key_scanned_config *config = dev->config; +static void gskbt_enable_interrupt(const struct device *dev, bool active_scanning) { + const struct gskbt_config *config = dev->config; gpio_pin_interrupt_configure_dt(&config->key, active_scanning ? GPIO_INT_EDGE_TO_ACTIVE : GPIO_INT_LEVEL_ACTIVE); } -static void bks_disable_interrupt(const struct device *dev) { - const struct behavior_key_scanned_config *config = dev->config; +static void gskbt_disable_interrupt(const struct device *dev) { + const struct gskbt_config *config = dev->config; gpio_pin_interrupt_configure_dt(&config->key, GPIO_INT_DISABLE); } -static void bks_read(const struct device *dev) { - const struct behavior_key_scanned_config *config = dev->config; - struct behavior_key_scanned_data *data = dev->data; - - if (k_sem_take(&data->sem, K_NO_WAIT) < 0) { - // k_work_reschedule(&data->update_work, K_NO_WAIT); - return; - } +static void gskbt_read(const struct device *dev) { + const struct gskbt_config *config = dev->config; + struct gskbt_data *data = dev->data; zmk_debounce_update(&data->debounce_state, data->active_scan_detected, config->debounce_scan_period_ms, &config->debounce_config); @@ -81,89 +77,83 @@ static void bks_read(const struct device *dev) { k_work_schedule(&data->update_work, K_TIMEOUT_ABS_MS(data->read_time)); } else { - bks_enable_interrupt(dev, false); + gskbt_enable_interrupt(dev, false); } - - k_sem_give(&data->sem); } -static void bks_update_work(struct k_work *work) { +static void gskbt_update_work(struct k_work *work) { struct k_work_delayable *dwork = CONTAINER_OF(work, struct k_work_delayable, work); - struct behavior_key_scanned_data *data = - CONTAINER_OF(dwork, struct behavior_key_scanned_data, update_work); - bks_read(data->dev); + struct gskbt_data *data = CONTAINER_OF(dwork, struct gskbt_data, update_work); + gskbt_read(data->dev); } -static void bks_gpio_irq_callback(const struct device *port, struct gpio_callback *cb, - const gpio_port_pins_t pin) { - struct behavior_key_scanned_data *data = - CONTAINER_OF(cb, struct behavior_key_scanned_data, key_callback); - const struct behavior_key_scanned_config *config = data->dev->config; +static void gskbt_gpio_interrupt_work(struct k_work *work) { + struct gskbt_data *data = CONTAINER_OF(work, struct gskbt_data, gpio_trigger_work); - uint32_t time = k_uptime_get(); - - if (k_sem_take(&data->sem, K_MSEC(10)) < 0) { - LOG_ERR("FAILED TO TAKE THE SEMAPHORE"); - // Do more? - return; - } - - data->active_scan_detected = true; - data->read_time = time; + const struct gskbt_config *config = data->dev->config; if (!zmk_debounce_is_active(&data->debounce_state)) { - // When we get that very first interrupt, we need to schedule the update checks to fall in - // between each of the real scans, so we can do our checks for state *after* each scan has + // When we get that very first interrupt, we need to schedule the update checks right before + // the next real scan, so we can do our checks for state *after* each scan has // occurred. + data->read_time = data->trigger_time; k_work_reschedule(&data->update_work, - K_TIMEOUT_ABS_MS(time + (config->debounce_scan_period_ms / 2))); - - bks_enable_interrupt(data->dev, true); + K_TIMEOUT_ABS_MS(data->read_time + config->debounce_scan_period_ms - 1)); } - - k_sem_give(&data->sem); } -static int behavior_key_scanned_init(const struct device *dev) { - const struct behavior_key_scanned_config *config = dev->config; - struct behavior_key_scanned_data *data = dev->data; +static void gskbt_gpio_irq_callback(const struct device *port, struct gpio_callback *cb, + const gpio_port_pins_t pin) { + struct gskbt_data *data = CONTAINER_OF(cb, struct gskbt_data, key_callback); + + // LOG_DBG("IRQ"); + data->active_scan_detected = true; + data->trigger_time = k_uptime_get(); + gskbt_enable_interrupt(data->dev, true); + k_work_submit(&data->gpio_trigger_work); +} + +static int gskbt_init(const struct device *dev) { + const struct gskbt_config *config = dev->config; + struct gskbt_data *data = dev->data; if (!device_is_ready(config->key.port)) { LOG_ERR("GPIO port is not ready"); return -ENODEV; } - k_work_init_delayable(&data->update_work, bks_update_work); - k_sem_init(&data->sem, 1, 1); + k_work_init_delayable(&data->update_work, gskbt_update_work); + k_work_init(&data->gpio_trigger_work, gskbt_gpio_interrupt_work); + data->dev = dev; gpio_pin_configure_dt(&config->key, GPIO_INPUT); - gpio_init_callback(&data->key_callback, bks_gpio_irq_callback, BIT(config->key.pin)); + gpio_init_callback(&data->key_callback, gskbt_gpio_irq_callback, BIT(config->key.pin)); gpio_add_callback(config->key.port, &data->key_callback); while (gpio_pin_get_dt(&config->key)) { k_sleep(K_MSEC(100)); } - bks_enable_interrupt(dev, false); + gskbt_enable_interrupt(dev, false); return 0; } -static int behavior_key_scanned_pm_action(const struct device *dev, enum pm_device_action action) { - const struct behavior_key_scanned_config *config = dev->config; - struct behavior_key_scanned_data *data = dev->data; +static int gskbt_pm_action(const struct device *dev, enum pm_device_action action) { + const struct gskbt_config *config = dev->config; + struct gskbt_data *data = dev->data; int ret; switch (action) { case PM_DEVICE_ACTION_SUSPEND: - bks_disable_interrupt(dev); + gskbt_disable_interrupt(dev); ret = gpio_remove_callback(config->key.port, &data->key_callback); break; case PM_DEVICE_ACTION_RESUME: ret = gpio_add_callback(config->key.port, &data->key_callback); - bks_enable_interrupt(dev, false); + gskbt_enable_interrupt(dev, false); break; default: ret = -ENOTSUP; @@ -173,8 +163,8 @@ static int behavior_key_scanned_pm_action(const struct device *dev, enum pm_devi return ret; } -#define BK_INST(n) \ - const struct behavior_key_scanned_config bks_config_##n = { \ +#define GSKBT_INST(n) \ + const struct gskbt_config gskbt_config_##n = { \ .key = GPIO_DT_SPEC_GET(DT_INST_PHANDLE(n, key), gpios), \ .debounce_config = \ { \ @@ -183,12 +173,12 @@ static int behavior_key_scanned_pm_action(const struct device *dev, enum pm_devi }, \ .debounce_scan_period_ms = DT_INST_PROP(n, debounce_scan_period_ms), \ }; \ - struct behavior_key_scanned_data bks_data_##n = { \ + struct gskbt_data gskbt_data_##n = { \ .binding = ZMK_KEYMAP_EXTRACT_BINDING(0, DT_DRV_INST(n)), \ }; \ - PM_DEVICE_DT_INST_DEFINE(n, behavior_key_scanned_pm_action); \ - DEVICE_DT_INST_DEFINE(n, behavior_key_scanned_init, PM_DEVICE_DT_INST_GET(n), &bks_data_##n, \ - &bks_config_##n, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ + PM_DEVICE_DT_INST_DEFINE(n, gskbt_pm_action); \ + DEVICE_DT_INST_DEFINE(n, gskbt_init, PM_DEVICE_DT_INST_GET(n), &gskbt_data_##n, \ + &gskbt_config_##n, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ NULL); -DT_INST_FOREACH_STATUS_OKAY(BK_INST) +DT_INST_FOREACH_STATUS_OKAY(GSKBT_INST) diff --git a/app/src/pm.c b/app/src/pm.c index a78b6ae5..41d72eee 100644 --- a/app/src/pm.c +++ b/app/src/pm.c @@ -41,10 +41,10 @@ int zmk_pm_soft_off(void) { // from normal "inactive goes to sleep" behavior, so disable them as wakeup devices // and then suspend them so we're ready to take over setting up our system // and then putting it into an off state. + LOG_DBG("soft-on-off pressed cb: suspend devices"); for (int i = 0; i < device_count; i++) { const struct device *dev = &devs[i]; - LOG_DBG("soft-on-off pressed cb: suspend device"); if (pm_device_wakeup_is_enabled(dev)) { pm_device_wakeup_enable(dev, false); } @@ -60,6 +60,6 @@ int zmk_pm_soft_off(void) { } #endif // HAS_WAKERS - LOG_DBG("soft-on-off interrupt: go to sleep"); + LOG_DBG("soft-off: go to sleep"); return pm_state_force(0U, &(struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0}); } diff --git a/app/src/wakeup_trigger_key.c b/app/src/wakeup_trigger_key.c deleted file mode 100644 index 0cc4f250..00000000 --- a/app/src/wakeup_trigger_key.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2023 The ZMK Contributors - * - * SPDX-License-Identifier: MIT - */ - -#include -#include -#include -#include -#include - -#include - -LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); - -#define DT_DRV_COMPAT zmk_wakeup_trigger_key - -struct wakeup_trigger_key_config { - struct gpio_dt_spec trigger; - size_t extra_gpios_count; - struct gpio_dt_spec extra_gpios[]; -}; - -static int zmk_wakeup_trigger_key_init(const struct device *dev) { -#if IS_ENABLED(CONFIG_PM_DEVICE) - pm_device_init_suspended(dev); - pm_device_wakeup_enable(dev, true); -#endif - - return 0; -} - -#if IS_ENABLED(CONFIG_PM_DEVICE) - -static int wakeup_trigger_key_pm_action(const struct device *dev, enum pm_device_action action) { - const struct wakeup_trigger_key_config *config = dev->config; - int ret = 0; - - switch (action) { - case PM_DEVICE_ACTION_RESUME: - ret = gpio_pin_interrupt_configure_dt(&config->trigger, GPIO_INT_LEVEL_ACTIVE); - if (ret < 0) { - LOG_ERR("Failed to configure wakeup trigger key GPIO pin interrupt (%d)", ret); - return ret; - } - - for (int i = 0; i < config->extra_gpios_count; i++) { - ret = gpio_pin_configure_dt(&config->extra_gpios[i], GPIO_OUTPUT_ACTIVE); - if (ret < 0) { - LOG_WRN("Failed to set extra GPIO pin active for waker (%d)", ret); - } - } - break; - case PM_DEVICE_ACTION_SUSPEND: - - ret = gpio_pin_interrupt_configure_dt(&config->trigger, GPIO_INT_DISABLE); - if (ret < 0) { - LOG_ERR("Failed to configure wakeup trigger key GPIO pin interrupt (%d)", ret); - return ret; - } - break; - default: - ret = -ENOTSUP; - break; - } - - return ret; -} - -#endif // IS_ENABLED(CONFIG_PM_DEVICE) - -#define WAKEUP_TRIGGER_EXTRA_GPIO_SPEC(idx, n) \ - GPIO_DT_SPEC_GET_BY_IDX(DT_DRV_INST(n), extra_gpios, idx) - -#define WAKEUP_TRIGGER_KEY_INST(n) \ - const struct wakeup_trigger_key_config wtk_cfg_##n = { \ - .trigger = GPIO_DT_SPEC_GET(DT_INST_PROP(n, trigger), gpios), \ - .extra_gpios = {LISTIFY(DT_PROP_LEN_OR(DT_DRV_INST(n), extra_gpios, 0), \ - WAKEUP_TRIGGER_EXTRA_GPIO_SPEC, (, ), n)}, \ - .extra_gpios_count = DT_PROP_LEN_OR(DT_DRV_INST(n), extra_gpios, 0), \ - }; \ - PM_DEVICE_DT_INST_DEFINE(n, wakeup_trigger_key_pm_action); \ - DEVICE_DT_INST_DEFINE(n, zmk_wakeup_trigger_key_init, PM_DEVICE_DT_INST_GET(n), NULL, \ - &wtk_cfg_##n, PRE_KERNEL_2, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL); - -DT_INST_FOREACH_STATUS_OKAY(WAKEUP_TRIGGER_KEY_INST) diff --git a/docs/docs/config/kscan.md b/docs/docs/config/kscan.md index 3076edc0..4a3954f9 100644 --- a/docs/docs/config/kscan.md +++ b/docs/docs/config/kscan.md @@ -455,7 +455,7 @@ Note that the entire addressable space does not need to be mapped. }; kscan0: kscan { - compatible = "zmk,kscan-gpio-charlieplex";k + compatible = "zmk,kscan-gpio-charlieplex"; wakeup-source; interrupt-gpios = <&pro_micro 21 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN) >; diff --git a/docs/docs/features/soft-off.md b/docs/docs/features/soft-off.md index a3a5d7a1..6b6b5cf4 100644 --- a/docs/docs/features/soft-off.md +++ b/docs/docs/features/soft-off.md @@ -79,7 +79,7 @@ In this case, we will be creating a dedicated instance of the [Soft Off Behavior }; soft_off_behavior_key { - compatible = "zmk,behavior-key"; + compatible = "zmk,gpio-key-behavior-trigger"; bindings = <&hw_soft_off>; key = <&wakeup_key>; }; @@ -88,7 +88,7 @@ In this case, we will be creating a dedicated instance of the [Soft Off Behavior Here are the properties for the behavior key node: -- The `compatible` property for the node must be `zmk,behavior-key`. +- The `compatible` property for the node must be `zmk,gpio-key-behavior-trigger`. - The `bindings` property is a phandle to the soft off behavior defined above. - The `key` property is a phandle to the GPIO key defined earlier. @@ -97,7 +97,7 @@ If you have set up your on/off to be controlled by a matrix-integrated combo, th ``` / { soft_off_behavior_key { - compatible = "zmk,behavior-key-scanned"; + compatible = "zmk,gpio-scanned-key-behavior-trigger"; status = "okay"; bindings = <&hw_soft_off>; key = <&wakeup_key>; @@ -105,7 +105,7 @@ If you have set up your on/off to be controlled by a matrix-integrated combo, th }; ``` -Note that the only difference from the `soft_off_behavior_key` definition for GPIO keys above is the `compatible` value of `zmk,behavior-key-scanned`. +Note that the only difference from the `soft_off_behavior_key` definition for GPIO keys above is the `compatible` value of `zmk,gpio-scanned-key-behavior-trigger`. #### Wakeup Sources @@ -131,7 +131,7 @@ Next, we need to add another device which will be enabled only when the keyboard ``` / { wakeup_source: wakeup_source { - compatible = "zmk,wakeup-trigger-key"; + compatible = "zmk,gpio-key-wakeup-trigger"; trigger = <&wakeup_key>; wakeup-source; @@ -141,7 +141,7 @@ Next, we need to add another device which will be enabled only when the keyboard Here are the properties for the node: -- The `compatible` property for the node must be `zmk,wakeup-trigger-key`. +- The `compatible` property for the node must be `zmk,gpio-key-wakeup-trigger`. - The `trigger` property is a phandle to the GPIO key defined earlier. - The `wakeup-source` property signals to Zephyr this device should not be suspended during the shutdown procedure. - An optional `output-gpios` property contains a list of GPIO pins (including the appropriate flags) to set active before going into power off, if needed to ensure the GPIO pin will trigger properly to wake the keyboard. This is only needed for matrix integrated combos. For those keyboards, the list should include the matrix output needs needed so the combo hardware is properly "driven" when the keyboard is off. From 5ebe924e941ba00e81d1c66ad2333e6a73826754 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Fri, 29 Dec 2023 15:03:14 -0800 Subject: [PATCH 16/45] chore: Various soft-off review fixes * Code style to avoid goto. * Enable pm.c compilation via dedicated Kconfig flag. * Comment wakeup trigger PM behavior. --- app/CMakeLists.txt | 2 +- app/Kconfig | 4 ++++ app/module/drivers/kscan/kscan_gpio_direct.c | 6 ++---- app/module/drivers/kscan/kscan_gpio_matrix.c | 6 ++---- app/src/gpio_key_wakeup_trigger.c | 16 +++++++++++++--- app/src/pm.c | 4 ++++ 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 908800db..a56a63b3 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -31,7 +31,7 @@ target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/wpm.c) target_sources(app PRIVATE src/event_manager.c) target_sources_ifdef(CONFIG_ZMK_GPIO_KEY_BEHAVIOR_TRIGGER app PRIVATE src/gpio_key_behavior_trigger.c) target_sources_ifdef(CONFIG_ZMK_GPIO_SCANNED_KEY_BEHAVIOR_TRIGGER app PRIVATE src/gpio_scanned_key_behavior_trigger.c) -target_sources_ifdef(CONFIG_ZMK_PM_SOFT_OFF app PRIVATE src/pm.c) +target_sources_ifdef(CONFIG_ZMK_PM app PRIVATE src/pm.c) target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/ext_power_generic.c) target_sources_ifdef(CONFIG_ZMK_GPIO_KEY_WAKEUP_TRIGGER app PRIVATE src/gpio_key_wakeup_trigger.c) target_sources(app PRIVATE src/events/activity_state_changed.c) diff --git a/app/Kconfig b/app/Kconfig index 3ca56793..df84d97d 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -423,8 +423,12 @@ config ZMK_EXT_POWER bool "Enable support to control external power output" default y +config ZMK_PM + bool + config ZMK_PM_SOFT_OFF bool "Soft-off support" + select ZMK_PM select PM_DEVICE config ZMK_GPIO_KEY_WAKEUP_TRIGGER diff --git a/app/module/drivers/kscan/kscan_gpio_direct.c b/app/module/drivers/kscan/kscan_gpio_direct.c index 7cfdb480..a10190da 100644 --- a/app/module/drivers/kscan/kscan_gpio_direct.c +++ b/app/module/drivers/kscan/kscan_gpio_direct.c @@ -324,11 +324,9 @@ static int kscan_direct_init(const struct device *dev) { static int kscan_direct_pm_action(const struct device *dev, enum pm_device_action action) { switch (action) { case PM_DEVICE_ACTION_SUSPEND: - kscan_direct_disable(dev); - break; + return kscan_direct_disable(dev); case PM_DEVICE_ACTION_RESUME: - kscan_direct_enable(dev); - break; + return kscan_direct_enable(dev); default: return -ENOTSUP; } diff --git a/app/module/drivers/kscan/kscan_gpio_matrix.c b/app/module/drivers/kscan/kscan_gpio_matrix.c index 0daf97dc..8a3c39f2 100644 --- a/app/module/drivers/kscan/kscan_gpio_matrix.c +++ b/app/module/drivers/kscan/kscan_gpio_matrix.c @@ -427,11 +427,9 @@ static int kscan_matrix_init(const struct device *dev) { static int kscan_matrix_pm_action(const struct device *dev, enum pm_device_action action) { switch (action) { case PM_DEVICE_ACTION_SUSPEND: - kscan_matrix_disable(dev); - break; + return kscan_matrix_disable(dev); case PM_DEVICE_ACTION_RESUME: - kscan_matrix_enable(dev); - break; + return kscan_matrix_enable(dev); default: return -ENOTSUP; } diff --git a/app/src/gpio_key_wakeup_trigger.c b/app/src/gpio_key_wakeup_trigger.c index ac0c6b22..308c4973 100644 --- a/app/src/gpio_key_wakeup_trigger.c +++ b/app/src/gpio_key_wakeup_trigger.c @@ -39,18 +39,17 @@ static int gpio_key_wakeup_trigger_pm_resume(const struct device *dev) { int ret = gpio_pin_interrupt_configure_dt(&config->trigger, GPIO_INT_LEVEL_ACTIVE); if (ret < 0) { LOG_ERR("Failed to configure wakeup trigger key GPIO pin interrupt (%d)", ret); - goto exit; + return ret; } for (int i = 0; i < config->extra_gpios_count; i++) { ret = gpio_pin_configure_dt(&config->extra_gpios[i], GPIO_OUTPUT_ACTIVE); if (ret < 0) { LOG_WRN("Failed to set extra GPIO pin active for waker (%d)", ret); - goto exit; + return ret; } } -exit: return ret; } @@ -62,9 +61,20 @@ static int gpio_key_wakeup_trigger_pm_suspend(const struct device *dev) { LOG_ERR("Failed to configure wakeup trigger key GPIO pin interrupt (%d)", ret); } + for (int i = 0; i < config->extra_gpios_count; i++) { + ret = gpio_pin_configure_dt(&config->extra_gpios[i], GPIO_DISCONNECTED); + if (ret < 0) { + LOG_WRN("Failed to set extra GPIO pin disconnected for waker (%d)", ret); + return ret; + } + } + return ret; } +// The waker is "backwards", in as much as it is designed to be resumed/enabled immediately +// before a soft-off state is entered, so it can wake the device from that state later. +// So this waker correctly resumes and is ready to wake the device later. static int gpio_key_wakeup_trigger_pm_action(const struct device *dev, enum pm_device_action action) { switch (action) { diff --git a/app/src/pm.c b/app/src/pm.c index 41d72eee..a4599ac8 100644 --- a/app/src/pm.c +++ b/app/src/pm.c @@ -15,6 +15,8 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include +#if IS_ENABLED(CONFIG_ZMK_PM_SOFT_OFF) + #define HAS_WAKERS DT_HAS_COMPAT_STATUS_OKAY(zmk_soft_off_wakeup_sources) #if HAS_WAKERS @@ -63,3 +65,5 @@ int zmk_pm_soft_off(void) { LOG_DBG("soft-off: go to sleep"); return pm_state_force(0U, &(struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0}); } + +#endif // IS_ENABLED(CONFIG_ZMK_PM_SOFT_OFF) \ No newline at end of file From 933fdcd36400ea9d2f73284ff5936e0c6cefe879 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Fri, 29 Dec 2023 16:28:22 -0800 Subject: [PATCH 17/45] refactor(pm): Remove scanned behavior trigger. * Remove the painful scanned behavior trigger for now, future enhancement will restore this high level functionality using kscan directly. --- app/CMakeLists.txt | 1 - app/Kconfig.behaviors | 5 - ...zmk,gpio-scanned-key-behavior-trigger.yaml | 31 --- app/src/gpio_scanned_key_behavior_trigger.c | 184 ------------------ docs/docs/features/soft-off.md | 17 +- 5 files changed, 2 insertions(+), 236 deletions(-) delete mode 100644 app/dts/bindings/zmk,gpio-scanned-key-behavior-trigger.yaml delete mode 100644 app/src/gpio_scanned_key_behavior_trigger.c diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index a56a63b3..4ee9135d 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -30,7 +30,6 @@ target_sources(app PRIVATE src/sensors.c) target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/wpm.c) target_sources(app PRIVATE src/event_manager.c) target_sources_ifdef(CONFIG_ZMK_GPIO_KEY_BEHAVIOR_TRIGGER app PRIVATE src/gpio_key_behavior_trigger.c) -target_sources_ifdef(CONFIG_ZMK_GPIO_SCANNED_KEY_BEHAVIOR_TRIGGER app PRIVATE src/gpio_scanned_key_behavior_trigger.c) target_sources_ifdef(CONFIG_ZMK_PM app PRIVATE src/pm.c) target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/ext_power_generic.c) target_sources_ifdef(CONFIG_ZMK_GPIO_KEY_WAKEUP_TRIGGER app PRIVATE src/gpio_key_wakeup_trigger.c) diff --git a/app/Kconfig.behaviors b/app/Kconfig.behaviors index ecd06ffb..6abdbddd 100644 --- a/app/Kconfig.behaviors +++ b/app/Kconfig.behaviors @@ -6,11 +6,6 @@ config ZMK_GPIO_KEY_BEHAVIOR_TRIGGER default y depends on DT_HAS_ZMK_GPIO_KEY_BEHAVIOR_TRIGGER_ENABLED -config ZMK_GPIO_SCANNED_KEY_BEHAVIOR_TRIGGER - bool - default y - depends on DT_HAS_ZMK_GPIO_SCANNED_KEY_BEHAVIOR_TRIGGER_ENABLED - config ZMK_BEHAVIOR_KEY_TOGGLE bool default y diff --git a/app/dts/bindings/zmk,gpio-scanned-key-behavior-trigger.yaml b/app/dts/bindings/zmk,gpio-scanned-key-behavior-trigger.yaml deleted file mode 100644 index 860155dd..00000000 --- a/app/dts/bindings/zmk,gpio-scanned-key-behavior-trigger.yaml +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright (c) 2023 The ZMK Contributors -# SPDX-License-Identifier: MIT - -description: | - Driver for a dedicated key triggered by matrix scanning for invoking a connected behavior. - -compatible: "zmk,gpio-scanned-key-behavior-trigger" - -include: base.yaml - -properties: - key: - type: phandle - required: true - description: The GPIO key that triggers wake via interrupt - bindings: - type: phandle - required: true - description: The behavior to invoke when the GPIO key is pressed - debounce-press-ms: - type: int - default: 5 - description: Debounce time for key press in milliseconds. Use 0 for eager debouncing. - debounce-release-ms: - type: int - default: 5 - description: Debounce time for key release in milliseconds. - debounce-scan-period-ms: - type: int - default: 1 - description: Time between reads in milliseconds when any key is pressed. diff --git a/app/src/gpio_scanned_key_behavior_trigger.c b/app/src/gpio_scanned_key_behavior_trigger.c deleted file mode 100644 index d27b162b..00000000 --- a/app/src/gpio_scanned_key_behavior_trigger.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2023 The ZMK Contributors - * - * SPDX-License-Identifier: MIT - */ - -#define DT_DRV_COMPAT zmk_gpio_scanned_key_behavior_trigger - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); - -struct gskbt_config { - struct zmk_debounce_config debounce_config; - int32_t debounce_scan_period_ms; - struct gpio_dt_spec key; -}; - -struct gskbt_data { - struct zmk_behavior_binding binding; - struct zmk_debounce_state debounce_state; - struct gpio_callback key_callback; - const struct device *dev; - struct k_work_delayable update_work; - struct k_work gpio_trigger_work; - uint32_t read_time; - uint32_t trigger_time; - bool pin_active; - bool active_scan_detected; -}; - -static void gskbt_enable_interrupt(const struct device *dev, bool active_scanning) { - const struct gskbt_config *config = dev->config; - - gpio_pin_interrupt_configure_dt(&config->key, active_scanning ? GPIO_INT_EDGE_TO_ACTIVE - : GPIO_INT_LEVEL_ACTIVE); -} - -static void gskbt_disable_interrupt(const struct device *dev) { - const struct gskbt_config *config = dev->config; - - gpio_pin_interrupt_configure_dt(&config->key, GPIO_INT_DISABLE); -} - -static void gskbt_read(const struct device *dev) { - const struct gskbt_config *config = dev->config; - struct gskbt_data *data = dev->data; - - zmk_debounce_update(&data->debounce_state, data->active_scan_detected, - config->debounce_scan_period_ms, &config->debounce_config); - - if (zmk_debounce_get_changed(&data->debounce_state)) { - const bool pressed = zmk_debounce_is_pressed(&data->debounce_state); - - struct zmk_behavior_binding_event event = {.position = INT32_MAX, - .timestamp = k_uptime_get()}; - - if (pressed) { - behavior_keymap_binding_pressed(&data->binding, event); - } else { - behavior_keymap_binding_released(&data->binding, event); - } - } - - if (zmk_debounce_is_active(&data->debounce_state)) { - data->active_scan_detected = false; - data->read_time += config->debounce_scan_period_ms; - - k_work_schedule(&data->update_work, K_TIMEOUT_ABS_MS(data->read_time)); - } else { - gskbt_enable_interrupt(dev, false); - } -} - -static void gskbt_update_work(struct k_work *work) { - struct k_work_delayable *dwork = CONTAINER_OF(work, struct k_work_delayable, work); - struct gskbt_data *data = CONTAINER_OF(dwork, struct gskbt_data, update_work); - gskbt_read(data->dev); -} - -static void gskbt_gpio_interrupt_work(struct k_work *work) { - struct gskbt_data *data = CONTAINER_OF(work, struct gskbt_data, gpio_trigger_work); - - const struct gskbt_config *config = data->dev->config; - - if (!zmk_debounce_is_active(&data->debounce_state)) { - // When we get that very first interrupt, we need to schedule the update checks right before - // the next real scan, so we can do our checks for state *after* each scan has - // occurred. - data->read_time = data->trigger_time; - k_work_reschedule(&data->update_work, - K_TIMEOUT_ABS_MS(data->read_time + config->debounce_scan_period_ms - 1)); - } -} - -static void gskbt_gpio_irq_callback(const struct device *port, struct gpio_callback *cb, - const gpio_port_pins_t pin) { - struct gskbt_data *data = CONTAINER_OF(cb, struct gskbt_data, key_callback); - - // LOG_DBG("IRQ"); - data->active_scan_detected = true; - data->trigger_time = k_uptime_get(); - gskbt_enable_interrupt(data->dev, true); - k_work_submit(&data->gpio_trigger_work); -} - -static int gskbt_init(const struct device *dev) { - const struct gskbt_config *config = dev->config; - struct gskbt_data *data = dev->data; - - if (!device_is_ready(config->key.port)) { - LOG_ERR("GPIO port is not ready"); - return -ENODEV; - } - - k_work_init_delayable(&data->update_work, gskbt_update_work); - k_work_init(&data->gpio_trigger_work, gskbt_gpio_interrupt_work); - - data->dev = dev; - - gpio_pin_configure_dt(&config->key, GPIO_INPUT); - gpio_init_callback(&data->key_callback, gskbt_gpio_irq_callback, BIT(config->key.pin)); - gpio_add_callback(config->key.port, &data->key_callback); - - while (gpio_pin_get_dt(&config->key)) { - k_sleep(K_MSEC(100)); - } - - gskbt_enable_interrupt(dev, false); - - return 0; -} - -static int gskbt_pm_action(const struct device *dev, enum pm_device_action action) { - const struct gskbt_config *config = dev->config; - struct gskbt_data *data = dev->data; - - int ret; - - switch (action) { - case PM_DEVICE_ACTION_SUSPEND: - gskbt_disable_interrupt(dev); - ret = gpio_remove_callback(config->key.port, &data->key_callback); - break; - case PM_DEVICE_ACTION_RESUME: - ret = gpio_add_callback(config->key.port, &data->key_callback); - gskbt_enable_interrupt(dev, false); - break; - default: - ret = -ENOTSUP; - break; - } - - return ret; -} - -#define GSKBT_INST(n) \ - const struct gskbt_config gskbt_config_##n = { \ - .key = GPIO_DT_SPEC_GET(DT_INST_PHANDLE(n, key), gpios), \ - .debounce_config = \ - { \ - .debounce_press_ms = DT_INST_PROP(n, debounce_press_ms), \ - .debounce_release_ms = DT_INST_PROP(n, debounce_release_ms), \ - }, \ - .debounce_scan_period_ms = DT_INST_PROP(n, debounce_scan_period_ms), \ - }; \ - struct gskbt_data gskbt_data_##n = { \ - .binding = ZMK_KEYMAP_EXTRACT_BINDING(0, DT_DRV_INST(n)), \ - }; \ - PM_DEVICE_DT_INST_DEFINE(n, gskbt_pm_action); \ - DEVICE_DT_INST_DEFINE(n, gskbt_init, PM_DEVICE_DT_INST_GET(n), &gskbt_data_##n, \ - &gskbt_config_##n, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ - NULL); - -DT_INST_FOREACH_STATUS_OKAY(GSKBT_INST) diff --git a/docs/docs/features/soft-off.md b/docs/docs/features/soft-off.md index 6b6b5cf4..370a3880 100644 --- a/docs/docs/features/soft-off.md +++ b/docs/docs/features/soft-off.md @@ -37,7 +37,7 @@ The simplest way to achieve this is with a push button between a GPIO pin and gr #### Matrix-Integrated Hardware Combo -Another, more complicated option is to tie two of the switch outputs in the matrix together through an AND gate and connect that to the dedicated GPIO pin. This way you can use a key combination in your existing keyboard matrix to trigger soft on/off. To make this work best, the two switches used should both be driven by the same matrix input pin so that both will be active simultaneously on the AND gate inputs. The alternative is to use a combination of diodes and capacitors to ensure both pins are active/high at the same time even if scanning sets them high at different times. +Another, more complicated option is to tie two of the switch outputs in the matrix together through an AND gate and connect that to the dedicated GPIO pin. This way you can use a key combination in your existing keyboard matrix to trigger soft on/off. To make this work best, the two switches used should both be driven by the same matrix input pin so that both will be active simultaneously on the AND gate inputs. The alternative is to use a combination of diodes and capacitors to ensure both pins are active/high at the same time even if scanning sets them high at different times. Support for this mode will be coming soon. ### Firmware Changes @@ -92,20 +92,7 @@ Here are the properties for the behavior key node: - The `bindings` property is a phandle to the soft off behavior defined above. - The `key` property is a phandle to the GPIO key defined earlier. -If you have set up your on/off to be controlled by a matrix-integrated combo, the behavior key needs use a different driver that will handle detecting the pressed state when the pin is toggled by the other matrix kscan driver: - -``` -/ { - soft_off_behavior_key { - compatible = "zmk,gpio-scanned-key-behavior-trigger"; - status = "okay"; - bindings = <&hw_soft_off>; - key = <&wakeup_key>; - }; -}; -``` - -Note that the only difference from the `soft_off_behavior_key` definition for GPIO keys above is the `compatible` value of `zmk,gpio-scanned-key-behavior-trigger`. +If you have set up your on/off to be controlled by a matrix-integrated combo, the behavior key will need to be integrated into your existing kscan setup. Full details to come when this is supported. #### Wakeup Sources From e78b25a445b5bfc4b0c9b979d68964729c3e8fa1 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Sun, 31 Dec 2023 00:34:20 +0000 Subject: [PATCH 18/45] feat(kscan): Direct kscan driver can use gpio-keys. * Allow specifying direct kscan driver pins using gpio-key list as an alternative. --- app/module/drivers/kscan/kscan_gpio_direct.c | 11 +++++++++-- .../dts/bindings/kscan/zmk,kscan-gpio-direct.yaml | 6 +++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/module/drivers/kscan/kscan_gpio_direct.c b/app/module/drivers/kscan/kscan_gpio_direct.c index a10190da..e05eb2f3 100644 --- a/app/module/drivers/kscan/kscan_gpio_direct.c +++ b/app/module/drivers/kscan/kscan_gpio_direct.c @@ -42,9 +42,14 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #define COND_POLL_OR_INTERRUPTS(pollcode, intcode) \ COND_CODE_1(CONFIG_ZMK_KSCAN_DIRECT_POLLING, pollcode, intcode) -#define INST_INPUTS_LEN(n) DT_INST_PROP_LEN(n, input_gpios) +#define INST_INPUTS_LEN(n) \ + COND_CODE_1(DT_INST_NODE_HAS_PROP(n, input_gpios), (DT_INST_PROP_LEN(n, input_gpios)), \ + (DT_INST_PROP_LEN(n, input_keys))) + #define KSCAN_DIRECT_INPUT_CFG_INIT(idx, inst_idx) \ KSCAN_GPIO_GET_BY_IDX(DT_DRV_INST(inst_idx), input_gpios, idx) +#define KSCAN_KEY_DIRECT_INPUT_CFG_INIT(idx, inst_idx) \ + KSCAN_GPIO_GET_BY_IDX(DT_INST_PROP_BY_IDX(inst_idx, input_keys, idx), gpios, 0) struct kscan_direct_irq_callback { const struct device *dev; @@ -347,7 +352,9 @@ static const struct kscan_driver_api kscan_direct_api = { "ZMK_KSCAN_DEBOUNCE_RELEASE_MS or debounce-release-ms is too large"); \ \ static struct kscan_gpio kscan_direct_inputs_##n[] = { \ - LISTIFY(INST_INPUTS_LEN(n), KSCAN_DIRECT_INPUT_CFG_INIT, (, ), n)}; \ + COND_CODE_1(DT_INST_NODE_HAS_PROP(n, input_gpios), \ + (LISTIFY(INST_INPUTS_LEN(n), KSCAN_DIRECT_INPUT_CFG_INIT, (, ), n)), \ + (LISTIFY(INST_INPUTS_LEN(n), KSCAN_KEY_DIRECT_INPUT_CFG_INIT, (, ), n)))}; \ \ static struct zmk_debounce_state kscan_direct_state_##n[INST_INPUTS_LEN(n)]; \ \ diff --git a/app/module/dts/bindings/kscan/zmk,kscan-gpio-direct.yaml b/app/module/dts/bindings/kscan/zmk,kscan-gpio-direct.yaml index f477b591..4953d5cf 100644 --- a/app/module/dts/bindings/kscan/zmk,kscan-gpio-direct.yaml +++ b/app/module/dts/bindings/kscan/zmk,kscan-gpio-direct.yaml @@ -10,7 +10,11 @@ include: kscan.yaml properties: input-gpios: type: phandle-array - required: true + required: false + input-keys: + type: phandles + required: false + description: List of gpio-key references debounce-period: type: int required: false From a0ad1d4c9402fbfe5e3dee8996057150a3f0f209 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Sat, 30 Dec 2023 16:38:52 -0800 Subject: [PATCH 19/45] refactor: Add kscan sideband behavior driver * Instead of gpio key behavior trigger, add new kscan driver that decorates/wraps a given kscan driver and will invoke basic system behavior assigned to a given row + column, without the need for keymap mapping in the matrix transform, bypassing keymaps entirely. --- app/CMakeLists.txt | 2 +- app/Kconfig | 6 + app/Kconfig.behaviors | 5 - .../boards/nrf52840dk_nrf52840.overlay | 19 +- .../kscan/zmk,kscan-sideband-behaviors.yaml | 29 +++ .../zmk,gpio-key-behavior-trigger.yaml | 31 ---- app/src/gpio_key_behavior_trigger.c | 167 ------------------ app/src/kscan_sideband_behaviors.c | 142 +++++++++++++++ 8 files changed, 192 insertions(+), 209 deletions(-) create mode 100644 app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml delete mode 100644 app/dts/bindings/zmk,gpio-key-behavior-trigger.yaml delete mode 100644 app/src/gpio_key_behavior_trigger.c create mode 100644 app/src/kscan_sideband_behaviors.c diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 4ee9135d..2abf943f 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -25,11 +25,11 @@ target_sources(app PRIVATE src/stdlib.c) target_sources(app PRIVATE src/activity.c) target_sources(app PRIVATE src/behavior.c) target_sources(app PRIVATE src/kscan.c) +target_sources_ifdef(CONFIG_ZMK_KSCAN_SIDEBAND_BEHAVIORS app PRIVATE src/kscan_sideband_behaviors.c) target_sources(app PRIVATE src/matrix_transform.c) target_sources(app PRIVATE src/sensors.c) target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/wpm.c) target_sources(app PRIVATE src/event_manager.c) -target_sources_ifdef(CONFIG_ZMK_GPIO_KEY_BEHAVIOR_TRIGGER app PRIVATE src/gpio_key_behavior_trigger.c) target_sources_ifdef(CONFIG_ZMK_PM app PRIVATE src/pm.c) target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/ext_power_generic.c) target_sources_ifdef(CONFIG_ZMK_GPIO_KEY_WAKEUP_TRIGGER app PRIVATE src/gpio_key_wakeup_trigger.c) diff --git a/app/Kconfig b/app/Kconfig index df84d97d..15c31375 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -512,6 +512,12 @@ config ZMK_KSCAN_EVENT_QUEUE_SIZE endif # ZMK_KSCAN +config ZMK_KSCAN_SIDEBAND_BEHAVIORS + bool + default y + depends on DT_HAS_ZMK_KSCAN_SIDEBAND_BEHAVIORS_ENABLED + select KSCAN + menu "Logging" config ZMK_LOGGING_MINIMAL diff --git a/app/Kconfig.behaviors b/app/Kconfig.behaviors index 6abdbddd..c9754bf7 100644 --- a/app/Kconfig.behaviors +++ b/app/Kconfig.behaviors @@ -1,11 +1,6 @@ # Copyright (c) 2023 The ZMK Contributors # SPDX-License-Identifier: MIT -config ZMK_GPIO_KEY_BEHAVIOR_TRIGGER - bool - default y - depends on DT_HAS_ZMK_GPIO_KEY_BEHAVIOR_TRIGGER_ENABLED - config ZMK_BEHAVIOR_KEY_TOGGLE bool default y diff --git a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay index b068b431..47b67dc0 100644 --- a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay +++ b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay @@ -57,10 +57,19 @@ encoder: &qdec0 { wakeup-sources = <&wakeup_source>; }; - soft_off_behavior_key { - compatible = "zmk,gpio-key-behavior-trigger"; - status = "okay"; - bindings = <&soft_off>; - key = <&button0>; + soft_off_direct_kscan: soft_off_direct_kscan { + compatible = "zmk,kscan-gpio-direct"; + input-keys = <&button0>; }; + + soft_off_sideband_behaviors { + compatible = "zmk,kscan-sideband-behaviors"; + kscan = <&soft_off_direct_kscan>; + soft_off { + row = <0>; + column = <0>; + bindings = <&soft_off>; + }; + }; + }; \ No newline at end of file diff --git a/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml b/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml new file mode 100644 index 00000000..7289b9e1 --- /dev/null +++ b/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml @@ -0,0 +1,29 @@ +# Copyright (c) 2023, The ZMK Contributors +# SPDX-License-Identifier: MIT + +description: | + kscan sideband behavior runner. Only basic system behavior should be used, + since no keymap processing occurs when using them. + +compatible: "zmk,kscan-sideband-behaviors" + +include: [kscan.yaml] + +properties: + kscan: + type: phandle + required: true + +child-binding: + description: "A sideband behavior tied to a row/column pair" + + properties: + row: + type: int + required: true + column: + type: int + required: true + bindings: + type: phandle-array + required: true diff --git a/app/dts/bindings/zmk,gpio-key-behavior-trigger.yaml b/app/dts/bindings/zmk,gpio-key-behavior-trigger.yaml deleted file mode 100644 index 2a1387f0..00000000 --- a/app/dts/bindings/zmk,gpio-key-behavior-trigger.yaml +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright (c) 2023 The ZMK Contributors -# SPDX-License-Identifier: MIT - -description: | - Driver for a dedicated key for invoking a connected behavior. - -compatible: "zmk,gpio-key-behavior-trigger" - -include: base.yaml - -properties: - key: - type: phandle - required: true - description: The GPIO key that triggers wake via interrupt - bindings: - type: phandle - required: true - description: The behavior to invoke when the GPIO key is pressed - debounce-press-ms: - type: int - default: 5 - description: Debounce time for key press in milliseconds. Use 0 for eager debouncing. - debounce-release-ms: - type: int - default: 5 - description: Debounce time for key release in milliseconds. - debounce-scan-period-ms: - type: int - default: 1 - description: Time between reads in milliseconds when any key is pressed. diff --git a/app/src/gpio_key_behavior_trigger.c b/app/src/gpio_key_behavior_trigger.c deleted file mode 100644 index a72f8e48..00000000 --- a/app/src/gpio_key_behavior_trigger.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2023 The ZMK Contributors - * - * SPDX-License-Identifier: MIT - */ - -#define DT_DRV_COMPAT zmk_gpio_key_behavior_trigger - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); - -struct gkbt_config { - struct zmk_debounce_config debounce_config; - int32_t debounce_scan_period_ms; - struct gpio_dt_spec key; -}; - -struct gkbt_data { - struct zmk_behavior_binding binding; - struct zmk_debounce_state debounce_state; - struct gpio_callback key_callback; - const struct device *dev; - struct k_work_delayable update_work; - uint32_t read_time; -}; - -static void gkbt_enable_interrupt(const struct device *dev) { - const struct gkbt_config *config = dev->config; - - gpio_pin_interrupt_configure_dt(&config->key, GPIO_INT_LEVEL_ACTIVE); -} - -static void gkbt_disable_interrupt(const struct device *dev) { - const struct gkbt_config *config = dev->config; - - gpio_pin_interrupt_configure_dt(&config->key, GPIO_INT_DISABLE); -} - -static void gkbt_read(const struct device *dev) { - const struct gkbt_config *config = dev->config; - struct gkbt_data *data = dev->data; - - zmk_debounce_update(&data->debounce_state, gpio_pin_get_dt(&config->key), - config->debounce_scan_period_ms, &config->debounce_config); - - if (zmk_debounce_get_changed(&data->debounce_state)) { - const bool pressed = zmk_debounce_is_pressed(&data->debounce_state); - - struct zmk_behavior_binding_event event = {.position = INT32_MAX, - .timestamp = k_uptime_get()}; - - if (pressed) { - behavior_keymap_binding_pressed(&data->binding, event); - } else { - behavior_keymap_binding_released(&data->binding, event); - } - } - - if (zmk_debounce_is_active(&data->debounce_state)) { - data->read_time += config->debounce_scan_period_ms; - - k_work_reschedule(&data->update_work, K_TIMEOUT_ABS_MS(data->read_time)); - } else { - gkbt_enable_interrupt(dev); - } -} - -static void gkbt_update_work(struct k_work *work) { - struct k_work_delayable *dwork = CONTAINER_OF(work, struct k_work_delayable, work); - struct gkbt_data *data = CONTAINER_OF(dwork, struct gkbt_data, update_work); - gkbt_read(data->dev); -} - -static void gkbt_gpio_irq_callback(const struct device *port, struct gpio_callback *cb, - const gpio_port_pins_t pin) { - struct gkbt_data *data = CONTAINER_OF(cb, struct gkbt_data, key_callback); - - gkbt_disable_interrupt(data->dev); - - data->read_time = k_uptime_get(); - k_work_reschedule(&data->update_work, K_NO_WAIT); -} - -static void gkbt_wait_for_key_release(const struct device *dev) { - const struct gkbt_config *config = dev->config; - - while (gpio_pin_get_dt(&config->key)) { - k_sleep(K_MSEC(100)); - } -} - -static int gkbt_init(const struct device *dev) { - const struct gkbt_config *config = dev->config; - struct gkbt_data *data = dev->data; - - if (!device_is_ready(config->key.port)) { - LOG_ERR("GPIO port %s is not ready", config->key.port->name); - return -ENODEV; - } - - k_work_init_delayable(&data->update_work, gkbt_update_work); - data->dev = dev; - - gpio_pin_configure_dt(&config->key, GPIO_INPUT); - gpio_init_callback(&data->key_callback, gkbt_gpio_irq_callback, BIT(config->key.pin)); - gpio_add_callback(config->key.port, &data->key_callback); - - // Be sure our wakeup key is released before startup continues to avoid wake/sleep loop. - gkbt_wait_for_key_release(dev); - - gkbt_enable_interrupt(dev); - - return 0; -} - -static int gkbt_pm_action(const struct device *dev, enum pm_device_action action) { - const struct gkbt_config *config = dev->config; - struct gkbt_data *data = dev->data; - - int ret; - - switch (action) { - case PM_DEVICE_ACTION_SUSPEND: - gkbt_disable_interrupt(dev); - ret = gpio_remove_callback(config->key.port, &data->key_callback); - break; - case PM_DEVICE_ACTION_RESUME: - ret = gpio_add_callback(config->key.port, &data->key_callback); - gkbt_enable_interrupt(dev); - break; - default: - ret = -ENOTSUP; - break; - } - - return ret; -} - -#define GKBT_INST(n) \ - const struct gkbt_config gkbt_config_##n = { \ - .key = GPIO_DT_SPEC_GET(DT_INST_PHANDLE(n, key), gpios), \ - .debounce_config = \ - { \ - .debounce_press_ms = DT_INST_PROP(n, debounce_press_ms), \ - .debounce_release_ms = DT_INST_PROP(n, debounce_release_ms), \ - }, \ - .debounce_scan_period_ms = DT_INST_PROP(n, debounce_scan_period_ms), \ - }; \ - struct gkbt_data gkbt_data_##n = { \ - .binding = ZMK_KEYMAP_EXTRACT_BINDING(0, DT_DRV_INST(n)), \ - }; \ - PM_DEVICE_DT_INST_DEFINE(n, gkbt_pm_action); \ - DEVICE_DT_INST_DEFINE(n, gkbt_init, PM_DEVICE_DT_INST_GET(n), &gkbt_data_##n, \ - &gkbt_config_##n, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ - NULL); - -DT_INST_FOREACH_STATUS_OKAY(GKBT_INST) diff --git a/app/src/kscan_sideband_behaviors.c b/app/src/kscan_sideband_behaviors.c new file mode 100644 index 00000000..3a03a293 --- /dev/null +++ b/app/src/kscan_sideband_behaviors.c @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2023 The ZMK Contributors + * + * SPDX-License-Identifier: MIT + */ + +#define DT_DRV_COMPAT zmk_kscan_sideband_behaviors + +#include +#include +#include +#include +#include + +#include +#include +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +struct ksbb_entry { + uint8_t row; + uint8_t column; + struct zmk_behavior_binding binding; +}; + +struct ksbb_config { + const struct device *kscan; + struct ksbb_entry *entries; + size_t entries_len; +}; + +struct ksbb_data { + kscan_callback_t callback; + bool enabled; +}; + +#define GET_KSBB_DEV(n) DEVICE_DT_GET(DT_DRV_INST(n)), + +// The kscan callback has no context with it, so we keep a static array of all possible +// KSBBs to check when a kscan callback from the "wrapped" inner kscan fires. +static const struct device *ksbbs[DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT)] = { + DT_INST_FOREACH_STATUS_OKAY(GET_KSBB_DEV)}; + +void ksbb_inner_kscan_callback(const struct device *dev, uint32_t row, uint32_t column, + bool pressed) { + for (int i = 0; i < ARRAY_SIZE(ksbbs); i++) { + const struct device *ksbb = ksbbs[i]; + const struct ksbb_config *cfg = ksbb->config; + struct ksbb_data *data = ksbb->data; + + if (cfg->kscan != dev) { + continue; + } + + for (int e = 0; e < cfg->entries_len; e++) { + struct ksbb_entry *entry = &cfg->entries[e]; + if (entry->row == row && entry->column == column) { + struct zmk_behavior_binding_event event = {.position = INT32_MAX, + .timestamp = k_uptime_get()}; + + if (pressed) { + behavior_keymap_binding_pressed(&entry->binding, event); + } else { + behavior_keymap_binding_released(&entry->binding, event); + } + return; + } + } + + if (data->enabled && data->callback) { + data->callback(ksbb, row, column, pressed); + } + } +} + +static int ksbb_configure(const struct device *dev, kscan_callback_t callback) { + struct ksbb_data *data = dev->data; + + if (!callback) { + return -EINVAL; + } + + data->callback = callback; + return 0; +} + +static int ksbb_enable(const struct device *dev) { + struct ksbb_data *data = dev->data; + data->enabled = true; + + return 0; +} + +static int ksbb_disable(const struct device *dev) { + struct ksbb_data *data = dev->data; + data->enabled = false; + + return 0; +} + +static int ksbb_init(const struct device *dev) { + const struct ksbb_config *config = dev->config; + + if (!device_is_ready(config->kscan)) { + LOG_ERR("kscan %s is not ready", config->kscan->name); + return -ENODEV; + } + + kscan_config(config->kscan, &ksbb_inner_kscan_callback); + kscan_enable_callback(config->kscan); + + return 0; +} + +static const struct kscan_driver_api ksbb_api = { + .config = ksbb_configure, + .enable_callback = ksbb_enable, + .disable_callback = ksbb_disable, +}; + +#define JUST_ONE(_id) 1 + +#define ENTRY(e) \ + { \ + .row = DT_PROP(e, row), .column = DT_PROP(e, column), \ + .binding = ZMK_KEYMAP_EXTRACT_BINDING(0, e), \ + } + +#define KSBB_INST(n) \ + static struct ksbb_entry entries_##n[] = { \ + DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(n, ENTRY, (, ))}; \ + const struct ksbb_config ksbb_config_##n = { \ + .kscan = DEVICE_DT_GET(DT_INST_PHANDLE(n, kscan)), \ + .entries = entries_##n, \ + .entries_len = DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(n, JUST_ONE, (+)), \ + }; \ + struct ksbb_data ksbb_data_##n = {}; \ + DEVICE_DT_INST_DEFINE(n, ksbb_init, NULL, &ksbb_data_##n, &ksbb_config_##n, APPLICATION, \ + CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &ksbb_api); + +DT_INST_FOREACH_STATUS_OKAY(KSBB_INST) From c3144055e8534169bf1a6d798b1ee712f6c1d002 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Sun, 31 Dec 2023 00:57:00 +0000 Subject: [PATCH 20/45] refactor(boards): Move ZMK Uno 1P3T slider to sideband * Invoke output selection from the slider on the ZMK Uno via sideband behavior setup, to simplify keymap. --- app/boards/shields/zmk_uno/zmk_uno.dtsi | 36 +---------------- app/boards/shields/zmk_uno/zmk_uno.keymap | 21 +--------- app/boards/shields/zmk_uno/zmk_uno.overlay | 40 +++++++++++++++++++ app/boards/shields/zmk_uno/zmk_uno_split.dtsi | 10 ++--- .../shields/zmk_uno/zmk_uno_split.keymap | 18 --------- 5 files changed, 46 insertions(+), 79 deletions(-) diff --git a/app/boards/shields/zmk_uno/zmk_uno.dtsi b/app/boards/shields/zmk_uno/zmk_uno.dtsi index 196ac8b5..e8ba79d6 100644 --- a/app/boards/shields/zmk_uno/zmk_uno.dtsi +++ b/app/boards/shields/zmk_uno/zmk_uno.dtsi @@ -40,7 +40,7 @@ nice_view_spi: &arduino_spi { / { chosen { - zmk,kscan = &kscan_matrix_comp; + zmk,kscan = &kscan_matrix; zmk,backlight = &backlight; zmk,underglow = &led_strip; zmk,matrix-transform = &matrix_transform; @@ -74,7 +74,6 @@ nice_view_spi: &arduino_spi { map = < RC(0,0) RC(0,1) RC(1,0) RC(1,1) - RC(2,0) RC(2,1) RC(2,2) >; }; @@ -86,42 +85,9 @@ nice_view_spi: &arduino_spi { map = < RC(0,0) RC(0,1) RC(0,2) RC(0,3) - RC(1,0) RC(1,1) RC(1,2) >; }; - - kscan_matrix_comp: kscan_matrix_comp { - compatible = "zmk,kscan-composite"; - rows = <1>; - columns = <7>; - - matrix { - kscan = <&kscan_matrix>; - }; - - toggle { - kscan = <&kscan_sp3t_toggle>; - row-offset = <2>; - }; - - }; - - kscan_direct_comp: kscan_direct_comp { - compatible = "zmk,kscan-composite"; - status = "disabled"; - - matrix { - kscan = <&kscan_direct>; - }; - - toggle { - kscan = <&kscan_sp3t_toggle>; - row-offset = <1>; - }; - - }; - kscan_matrix: kscan_matrix { compatible = "zmk,kscan-gpio-matrix"; wakeup-source; diff --git a/app/boards/shields/zmk_uno/zmk_uno.keymap b/app/boards/shields/zmk_uno/zmk_uno.keymap index 0e0fc795..e416ff5e 100644 --- a/app/boards/shields/zmk_uno/zmk_uno.keymap +++ b/app/boards/shields/zmk_uno/zmk_uno.keymap @@ -9,42 +9,25 @@ #include #include #include -#include #include // Uncomment the following block if using the "Direct Wire" jumper to switch the matrix to a direct wire. /* :REMOVE ME -&kscan_direct_comp { status = "okay"; }; &kscan_direct { status = "okay"; }; -&kscan_matrix_comp { status = "disabled"; }; &kscan_matrix { status = "disabled"; }; / { chosen { zmk,matrix-transform = &direct_matrix_transform; - zmk,kscan = &kscan_direct_comp; + zmk,kscan = &kscan_direct; }; }; REMOVE ME: */ - / { - macros { - ZMK_MACRO(ble_zero, - wait-ms = <1>; - tap-ms = <1>; - bindings = <&out OUT_BLE &bt BT_SEL 0>; - ) - ZMK_MACRO(ble_one, - wait-ms = <1>; - tap-ms = <1>; - bindings = <&out OUT_BLE &bt BT_SEL 1>; - ) - }; - keymap { compatible = "zmk,keymap"; @@ -52,8 +35,6 @@ REMOVE ME: */ bindings = < &kp A &bl BL_TOG &rgb_ug RGB_EFF &bt BT_CLR - - &out OUT_USB &ble_zero &ble_one >; sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>; diff --git a/app/boards/shields/zmk_uno/zmk_uno.overlay b/app/boards/shields/zmk_uno/zmk_uno.overlay index 4999c82c..c86f6e5c 100644 --- a/app/boards/shields/zmk_uno/zmk_uno.overlay +++ b/app/boards/shields/zmk_uno/zmk_uno.overlay @@ -6,6 +6,10 @@ #include "zmk_uno.dtsi" +#include +#include +#include + / { chosen { zmk,matrix-transform = &matrix_transform; @@ -19,4 +23,40 @@ }; }; + macros { + ZMK_MACRO(ble_zero, + wait-ms = <1>; + tap-ms = <1>; + bindings = <&out OUT_BLE &bt BT_SEL 0>; + ) + ZMK_MACRO(ble_one, + wait-ms = <1>; + tap-ms = <1>; + bindings = <&out OUT_BLE &bt BT_SEL 1>; + ) + }; + + endpoint_sideband_behaviors { + compatible = "zmk,kscan-sideband-behaviors"; + kscan = <&kscan_sp3t_toggle>; + + usb { + row = <0>; + column = <0>; + bindings = <&out OUT_USB>; + }; + + ble_zero { + row = <0>; + column = <1>; + bindings = <&ble_zero>; + }; + + ble_one { + row = <0>; + column = <2>; + bindings = <&ble_one>; + }; + }; + }; diff --git a/app/boards/shields/zmk_uno/zmk_uno_split.dtsi b/app/boards/shields/zmk_uno/zmk_uno_split.dtsi index 516213bd..dac6fc3e 100644 --- a/app/boards/shields/zmk_uno/zmk_uno_split.dtsi +++ b/app/boards/shields/zmk_uno/zmk_uno_split.dtsi @@ -17,16 +17,15 @@ split_matrix_transform: split_matrix_transform { compatible = "zmk,matrix-transform"; - rows = <3>; - columns = <4>; + rows = <4>; + columns = <2>; map = < RC(0,0) RC(0,1) RC(1,0) RC(1,1) - RC(2,0) RC(2,1) RC(2,2) + RC(3,0) RC(3,1) RC(4,0) RC(4,1) - RC(5,0) RC(5,1) RC(5,2) >; }; @@ -38,10 +37,9 @@ map = < RC(0,0) RC(0,1) RC(0,2) RC(0,3) - RC(1,0) RC(1,1) RC(1,2) + RC(2,0) RC(2,1) RC(2,2) RC(2,3) - RC(3,0) RC(3,1) RC(3,2) >; }; diff --git a/app/boards/shields/zmk_uno/zmk_uno_split.keymap b/app/boards/shields/zmk_uno/zmk_uno_split.keymap index 05f0ffb0..1e46042a 100644 --- a/app/boards/shields/zmk_uno/zmk_uno_split.keymap +++ b/app/boards/shields/zmk_uno/zmk_uno_split.keymap @@ -16,9 +16,7 @@ /* :REMOVE ME -&kscan_direct_comp { status = "okay"; }; &kscan_direct { status = "okay"; }; -&kscan_matrix_comp { status = "disabled"; }; &kscan_matrix { status = "disabled"; }; / { @@ -30,20 +28,7 @@ REMOVE ME: */ - / { - macros { - ZMK_MACRO(ble_zero, - wait-ms = <1>; - tap-ms = <1>; - bindings = <&out OUT_BLE &bt BT_SEL 0>; - ) - ZMK_MACRO(ble_one, - wait-ms = <1>; - tap-ms = <1>; - bindings = <&out OUT_BLE &bt BT_SEL 1>; - ) - }; keymap { compatible = "zmk,keymap"; @@ -53,11 +38,8 @@ REMOVE ME: */ &kp A &bl BL_TOG &rgb_ug RGB_EFF &bt BT_CLR - &out OUT_USB &ble_zero &ble_one - &kp C &kp D &kp E &kp F - &none &none &none >; sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN &inc_dec_kp PG_UP PG_DN>; From 09111f1cf36099690bf96091b46214c421b1fb3b Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Sun, 31 Dec 2023 06:36:52 +0000 Subject: [PATCH 21/45] fix: Sleep after clearing endpoints to wait for send. * Add a small sleep to allow other threads to send data for the endpoint clearing before sleep. --- app/src/pm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/pm.c b/app/src/pm.c index a4599ac8..8525046f 100644 --- a/app/src/pm.c +++ b/app/src/pm.c @@ -35,6 +35,8 @@ int zmk_pm_soft_off(void) { #if !IS_ENABLED(CONFIG_ZMK_SPLIT) || IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) zmk_endpoints_clear_current(); + // Need to sleep to give any other threads a chance so submit endpoint data. + k_sleep(K_MSEC(100)); #endif device_count = z_device_get_all_static(&devs); From 4198fac90f4f35e7464cb3793632f81601bbf1d5 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 3 Jan 2024 11:11:24 -0800 Subject: [PATCH 22/45] fix(pm): Fix deep sleep with sideband behaviors. * Properly implement the PM hook needed for sideband behavior kscan device to have wakeup source enabled on it. --- .../kscan/zmk,kscan-sideband-behaviors.yaml | 2 +- app/src/kscan.c | 5 ++-- app/src/kscan_sideband_behaviors.c | 29 +++++++++++++++++-- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml b/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml index 7289b9e1..57b54a60 100644 --- a/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml +++ b/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml @@ -7,7 +7,7 @@ description: | compatible: "zmk,kscan-sideband-behaviors" -include: [kscan.yaml] +include: kscan.yaml properties: kscan: diff --git a/app/src/kscan.c b/app/src/kscan.c index c04ce2d8..5c7a5535 100644 --- a/app/src/kscan.c +++ b/app/src/kscan.c @@ -74,13 +74,14 @@ int zmk_kscan_init(const struct device *dev) { k_work_init(&msg_processor.work, zmk_kscan_process_msgq); - kscan_config(dev, zmk_kscan_callback); - kscan_enable_callback(dev); #if IS_ENABLED(CONFIG_PM_DEVICE) if (pm_device_wakeup_is_capable(dev)) { pm_device_wakeup_enable(dev, true); } #endif // IS_ENABLED(CONFIG_PM_DEVICE) + kscan_config(dev, zmk_kscan_callback); + kscan_enable_callback(dev); + return 0; } diff --git a/app/src/kscan_sideband_behaviors.c b/app/src/kscan_sideband_behaviors.c index 3a03a293..cff28e49 100644 --- a/app/src/kscan_sideband_behaviors.c +++ b/app/src/kscan_sideband_behaviors.c @@ -75,6 +75,7 @@ void ksbb_inner_kscan_callback(const struct device *dev, uint32_t row, uint32_t } static int ksbb_configure(const struct device *dev, kscan_callback_t callback) { + const struct ksbb_config *cfg = dev->config; struct ksbb_data *data = dev->data; if (!callback) { @@ -82,6 +83,13 @@ static int ksbb_configure(const struct device *dev, kscan_callback_t callback) { } data->callback = callback; + +#if IS_ENABLED(CONFIG_PM_DEVICE) + if (pm_device_wakeup_is_enabled(dev) && pm_device_wakeup_is_capable(cfg->kscan)) { + pm_device_wakeup_enable(cfg->kscan, true); + } +#endif // IS_ENABLED(CONFIG_PM_DEVICE) + return 0; } @@ -119,6 +127,21 @@ static const struct kscan_driver_api ksbb_api = { .disable_callback = ksbb_disable, }; +#if IS_ENABLED(CONFIG_PM_DEVICE) + +static int ksbb_pm_action(const struct device *dev, enum pm_device_action action) { + switch (action) { + case PM_DEVICE_ACTION_SUSPEND: + return ksbb_disable(dev); + case PM_DEVICE_ACTION_RESUME: + return ksbb_disable(dev); + default: + return -ENOTSUP; + } +} + +#endif // IS_ENABLED(CONFIG_PM_DEVICE) + #define JUST_ONE(_id) 1 #define ENTRY(e) \ @@ -136,7 +159,9 @@ static const struct kscan_driver_api ksbb_api = { .entries_len = DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(n, JUST_ONE, (+)), \ }; \ struct ksbb_data ksbb_data_##n = {}; \ - DEVICE_DT_INST_DEFINE(n, ksbb_init, NULL, &ksbb_data_##n, &ksbb_config_##n, APPLICATION, \ - CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &ksbb_api); + PM_DEVICE_DT_INST_DEFINE(n, ksbb_pm_action); \ + DEVICE_DT_INST_DEFINE(n, ksbb_init, PM_DEVICE_DT_INST_GET(n), &ksbb_data_##n, \ + &ksbb_config_##n, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ + &ksbb_api); DT_INST_FOREACH_STATUS_OKAY(KSBB_INST) From 5d960a758f6067ae82eccb01d8508114b2a98c6a Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 22 Jan 2024 13:39:08 -0800 Subject: [PATCH 23/45] fix: Cleanups of sideband and direct kscan from review. * Add dedicated init priority for the sideband kscan. * Refactor sideband code for clarity. * Tweaks to direct kscan for clarity. * Make sideband behavior row optional for brevity. * Allow overriding ZMK Uno sideband behaviors. --- app/Kconfig | 9 +++ app/boards/shields/zmk_uno/zmk_uno.keymap | 22 +++--- app/boards/shields/zmk_uno/zmk_uno.overlay | 9 +-- .../shields/zmk_uno/zmk_uno_split.keymap | 21 +++--- .../kscan/zmk,kscan-sideband-behaviors.yaml | 7 +- app/module/drivers/kscan/kscan_gpio_direct.c | 4 +- app/src/kscan_sideband_behaviors.c | 67 ++++++++++++------- 7 files changed, 78 insertions(+), 61 deletions(-) diff --git a/app/Kconfig b/app/Kconfig index 15c31375..a719875e 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -518,6 +518,15 @@ config ZMK_KSCAN_SIDEBAND_BEHAVIORS depends on DT_HAS_ZMK_KSCAN_SIDEBAND_BEHAVIORS_ENABLED select KSCAN +if ZMK_KSCAN_SIDEBAND_BEHAVIORS + +config ZMK_KSCAN_SIDEBAND_BEHAVIORS_INIT_PRIORITY + int "Keyboard scan sideband behaviors driver init priority" + # The default kscan init priority is 90, so be sure we are lower. + default 95 + +endif # ZMK_KSCAN_SIDEBAND_BEHAVIORS + menu "Logging" config ZMK_LOGGING_MINIMAL diff --git a/app/boards/shields/zmk_uno/zmk_uno.keymap b/app/boards/shields/zmk_uno/zmk_uno.keymap index e416ff5e..a7f6a267 100644 --- a/app/boards/shields/zmk_uno/zmk_uno.keymap +++ b/app/boards/shields/zmk_uno/zmk_uno.keymap @@ -11,21 +11,17 @@ #include #include -// Uncomment the following block if using the "Direct Wire" jumper to switch the matrix to a direct wire. +// Uncomment the following lines if using the "Direct Wire" jumper to switch the matrix to a direct wire. -/* :REMOVE ME +// &kscan_direct { status = "okay"; }; +// &kscan_matrix { status = "disabled"; }; -&kscan_direct { status = "okay"; }; -&kscan_matrix { status = "disabled"; }; - -/ { - chosen { - zmk,matrix-transform = &direct_matrix_transform; - zmk,kscan = &kscan_direct; - }; -}; - -REMOVE ME: */ +// / { +// chosen { +// zmk,matrix-transform = &direct_matrix_transform; +// zmk,kscan = &kscan_direct; +// }; +// }; / { keymap { diff --git a/app/boards/shields/zmk_uno/zmk_uno.overlay b/app/boards/shields/zmk_uno/zmk_uno.overlay index c86f6e5c..3d105abf 100644 --- a/app/boards/shields/zmk_uno/zmk_uno.overlay +++ b/app/boards/shields/zmk_uno/zmk_uno.overlay @@ -40,20 +40,17 @@ compatible = "zmk,kscan-sideband-behaviors"; kscan = <&kscan_sp3t_toggle>; - usb { - row = <0>; + first_toggle_sideband: first_toggle_sideband { column = <0>; bindings = <&out OUT_USB>; }; - ble_zero { - row = <0>; + second_toggle_sideband: second_toggle_sideband { column = <1>; bindings = <&ble_zero>; }; - ble_one { - row = <0>; + third_toggle_sideband: third_toggle_sideband { column = <2>; bindings = <&ble_one>; }; diff --git a/app/boards/shields/zmk_uno/zmk_uno_split.keymap b/app/boards/shields/zmk_uno/zmk_uno_split.keymap index 1e46042a..37672a7d 100644 --- a/app/boards/shields/zmk_uno/zmk_uno_split.keymap +++ b/app/boards/shields/zmk_uno/zmk_uno_split.keymap @@ -12,21 +12,18 @@ #include #include -// Uncomment the following block if using the "Direct Wire" jumper to switch the matrix to a direct wire. +// Uncomment the following lines if using the "Direct Wire" jumper to switch the matrix to a direct wire. -/* :REMOVE ME -&kscan_direct { status = "okay"; }; -&kscan_matrix { status = "disabled"; }; +// &kscan_direct { status = "okay"; }; +// &kscan_matrix { status = "disabled"; }; -/ { - chosen { - zmk,matrix-transform = &split_direct_matrix_transform; - zmk,kscan = &kscan_direct_comp; - }; -}; - -REMOVE ME: */ +// / { +// chosen { +// zmk,matrix-transform = &split_direct_matrix_transform; +// zmk,kscan = &kscan_direct_comp; +// }; +// }; / { diff --git a/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml b/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml index 57b54a60..f3ed180d 100644 --- a/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml +++ b/app/dts/bindings/kscan/zmk,kscan-sideband-behaviors.yaml @@ -2,8 +2,9 @@ # SPDX-License-Identifier: MIT description: | - kscan sideband behavior runner. Only basic system behavior should be used, - since no keymap processing occurs when using them. + kscan sideband behavior runner. Only basic system behaviors should be used, + since no keymap processing occurs when using them. Primarily, that means avoiding + using tap-holds, sticky keys, etc. as sideband behaviors. compatible: "zmk,kscan-sideband-behaviors" @@ -20,7 +21,7 @@ child-binding: properties: row: type: int - required: true + default: 0 column: type: int required: true diff --git a/app/module/drivers/kscan/kscan_gpio_direct.c b/app/module/drivers/kscan/kscan_gpio_direct.c index e05eb2f3..fa24e69e 100644 --- a/app/module/drivers/kscan/kscan_gpio_direct.c +++ b/app/module/drivers/kscan/kscan_gpio_direct.c @@ -46,7 +46,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); COND_CODE_1(DT_INST_NODE_HAS_PROP(n, input_gpios), (DT_INST_PROP_LEN(n, input_gpios)), \ (DT_INST_PROP_LEN(n, input_keys))) -#define KSCAN_DIRECT_INPUT_CFG_INIT(idx, inst_idx) \ +#define KSCAN_GPIO_DIRECT_INPUT_CFG_INIT(idx, inst_idx) \ KSCAN_GPIO_GET_BY_IDX(DT_DRV_INST(inst_idx), input_gpios, idx) #define KSCAN_KEY_DIRECT_INPUT_CFG_INIT(idx, inst_idx) \ KSCAN_GPIO_GET_BY_IDX(DT_INST_PROP_BY_IDX(inst_idx, input_keys, idx), gpios, 0) @@ -353,7 +353,7 @@ static const struct kscan_driver_api kscan_direct_api = { \ static struct kscan_gpio kscan_direct_inputs_##n[] = { \ COND_CODE_1(DT_INST_NODE_HAS_PROP(n, input_gpios), \ - (LISTIFY(INST_INPUTS_LEN(n), KSCAN_DIRECT_INPUT_CFG_INIT, (, ), n)), \ + (LISTIFY(INST_INPUTS_LEN(n), KSCAN_GPIO_DIRECT_INPUT_CFG_INIT, (, ), n)), \ (LISTIFY(INST_INPUTS_LEN(n), KSCAN_KEY_DIRECT_INPUT_CFG_INIT, (, ), n)))}; \ \ static struct zmk_debounce_state kscan_direct_state_##n[INST_INPUTS_LEN(n)]; \ diff --git a/app/src/kscan_sideband_behaviors.c b/app/src/kscan_sideband_behaviors.c index cff28e49..5b8a30a8 100644 --- a/app/src/kscan_sideband_behaviors.c +++ b/app/src/kscan_sideband_behaviors.c @@ -19,9 +19,9 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); struct ksbb_entry { + struct zmk_behavior_binding binding; uint8_t row; uint8_t column; - struct zmk_behavior_binding binding; }; struct ksbb_config { @@ -39,32 +39,53 @@ struct ksbb_data { // The kscan callback has no context with it, so we keep a static array of all possible // KSBBs to check when a kscan callback from the "wrapped" inner kscan fires. -static const struct device *ksbbs[DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT)] = { - DT_INST_FOREACH_STATUS_OKAY(GET_KSBB_DEV)}; +static const struct device *ksbbs[] = {DT_INST_FOREACH_STATUS_OKAY(GET_KSBB_DEV)}; -void ksbb_inner_kscan_callback(const struct device *dev, uint32_t row, uint32_t column, - bool pressed) { +int find_ksbb_for_inner(const struct device *inner_dev, const struct device **ksbb_dev) { for (int i = 0; i < ARRAY_SIZE(ksbbs); i++) { const struct device *ksbb = ksbbs[i]; const struct ksbb_config *cfg = ksbb->config; - struct ksbb_data *data = ksbb->data; - if (cfg->kscan != dev) { - continue; + if (cfg->kscan == inner_dev) { + *ksbb_dev = ksbb; + return 0; } + } - for (int e = 0; e < cfg->entries_len; e++) { - struct ksbb_entry *entry = &cfg->entries[e]; - if (entry->row == row && entry->column == column) { - struct zmk_behavior_binding_event event = {.position = INT32_MAX, - .timestamp = k_uptime_get()}; + return -ENODEV; +} - if (pressed) { - behavior_keymap_binding_pressed(&entry->binding, event); - } else { - behavior_keymap_binding_released(&entry->binding, event); - } - return; +int find_sideband_behavior(const struct device *dev, uint32_t row, uint32_t column, + struct ksbb_entry **entry) { + const struct ksbb_config *cfg = dev->config; + + for (int e = 0; e < cfg->entries_len; e++) { + struct ksbb_entry *candidate = &cfg->entries[e]; + + if (candidate->row == row && candidate->column == column) { + *entry = candidate; + return 0; + } + } + + return -ENODEV; +} + +void ksbb_inner_kscan_callback(const struct device *dev, uint32_t row, uint32_t column, + bool pressed) { + struct ksbb_entry *entry = NULL; + const struct device *ksbb = NULL; + + if (find_ksbb_for_inner(dev, &ksbb) >= 0) { + struct ksbb_data *data = ksbb->data; + if (find_sideband_behavior(ksbb, row, column, &entry) >= 0) { + struct zmk_behavior_binding_event event = {.position = INT32_MAX, + .timestamp = k_uptime_get()}; + + if (pressed) { + behavior_keymap_binding_pressed(&entry->binding, event); + } else { + behavior_keymap_binding_released(&entry->binding, event); } } @@ -78,10 +99,6 @@ static int ksbb_configure(const struct device *dev, kscan_callback_t callback) { const struct ksbb_config *cfg = dev->config; struct ksbb_data *data = dev->data; - if (!callback) { - return -EINVAL; - } - data->callback = callback; #if IS_ENABLED(CONFIG_PM_DEVICE) @@ -161,7 +178,7 @@ static int ksbb_pm_action(const struct device *dev, enum pm_device_action action struct ksbb_data ksbb_data_##n = {}; \ PM_DEVICE_DT_INST_DEFINE(n, ksbb_pm_action); \ DEVICE_DT_INST_DEFINE(n, ksbb_init, PM_DEVICE_DT_INST_GET(n), &ksbb_data_##n, \ - &ksbb_config_##n, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ - &ksbb_api); + &ksbb_config_##n, POST_KERNEL, \ + CONFIG_ZMK_KSCAN_SIDEBAND_BEHAVIORS_INIT_PRIORITY, &ksbb_api); DT_INST_FOREACH_STATUS_OKAY(KSBB_INST) From bd21f41412eaff5822a17efa86ce1dadf831cbcc Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Fri, 26 Jan 2024 01:48:46 -0800 Subject: [PATCH 24/45] refactor: Fixes for review feedback. --- app/Kconfig | 2 +- app/src/kscan_sideband_behaviors.c | 29 ++++++++++++----------------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/app/Kconfig b/app/Kconfig index a719875e..28d3c22a 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -522,7 +522,7 @@ if ZMK_KSCAN_SIDEBAND_BEHAVIORS config ZMK_KSCAN_SIDEBAND_BEHAVIORS_INIT_PRIORITY int "Keyboard scan sideband behaviors driver init priority" - # The default kscan init priority is 90, so be sure we are lower. + # The default kscan init priority is 90, so be sure we are initialized later. default 95 endif # ZMK_KSCAN_SIDEBAND_BEHAVIORS diff --git a/app/src/kscan_sideband_behaviors.c b/app/src/kscan_sideband_behaviors.c index 5b8a30a8..7a9922af 100644 --- a/app/src/kscan_sideband_behaviors.c +++ b/app/src/kscan_sideband_behaviors.c @@ -41,44 +41,41 @@ struct ksbb_data { // KSBBs to check when a kscan callback from the "wrapped" inner kscan fires. static const struct device *ksbbs[] = {DT_INST_FOREACH_STATUS_OKAY(GET_KSBB_DEV)}; -int find_ksbb_for_inner(const struct device *inner_dev, const struct device **ksbb_dev) { +const struct device *find_ksbb_for_inner(const struct device *inner_dev) { for (int i = 0; i < ARRAY_SIZE(ksbbs); i++) { const struct device *ksbb = ksbbs[i]; const struct ksbb_config *cfg = ksbb->config; if (cfg->kscan == inner_dev) { - *ksbb_dev = ksbb; - return 0; + return ksbb; } } - return -ENODEV; + return NULL; } -int find_sideband_behavior(const struct device *dev, uint32_t row, uint32_t column, - struct ksbb_entry **entry) { +struct ksbb_entry *find_sideband_behavior(const struct device *dev, uint32_t row, uint32_t column) { const struct ksbb_config *cfg = dev->config; for (int e = 0; e < cfg->entries_len; e++) { struct ksbb_entry *candidate = &cfg->entries[e]; if (candidate->row == row && candidate->column == column) { - *entry = candidate; - return 0; + return candidate; } } - return -ENODEV; + return NULL; } void ksbb_inner_kscan_callback(const struct device *dev, uint32_t row, uint32_t column, bool pressed) { - struct ksbb_entry *entry = NULL; - const struct device *ksbb = NULL; - - if (find_ksbb_for_inner(dev, &ksbb) >= 0) { + const struct device *ksbb = find_ksbb_for_inner(dev); + if (ksbb) { struct ksbb_data *data = ksbb->data; - if (find_sideband_behavior(ksbb, row, column, &entry) >= 0) { + + struct ksbb_entry *entry = find_sideband_behavior(ksbb, row, column); + if (entry) { struct zmk_behavior_binding_event event = {.position = INT32_MAX, .timestamp = k_uptime_get()}; @@ -159,8 +156,6 @@ static int ksbb_pm_action(const struct device *dev, enum pm_device_action action #endif // IS_ENABLED(CONFIG_PM_DEVICE) -#define JUST_ONE(_id) 1 - #define ENTRY(e) \ { \ .row = DT_PROP(e, row), .column = DT_PROP(e, column), \ @@ -173,7 +168,7 @@ static int ksbb_pm_action(const struct device *dev, enum pm_device_action action const struct ksbb_config ksbb_config_##n = { \ .kscan = DEVICE_DT_GET(DT_INST_PHANDLE(n, kscan)), \ .entries = entries_##n, \ - .entries_len = DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(n, JUST_ONE, (+)), \ + .entries_len = ARRAY_SIZE(entries_##n), \ }; \ struct ksbb_data ksbb_data_##n = {}; \ PM_DEVICE_DT_INST_DEFINE(n, ksbb_pm_action); \ From 8d54e287f019baa44540c8d8120eac594a630b03 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 19 Feb 2024 02:18:23 -0800 Subject: [PATCH 25/45] fix: Adjustments for Zephyr 3.5. --- app/Kconfig | 6 +++ app/include/zmk/pm.h | 3 ++ app/src/activity.c | 61 +----------------------- app/src/behaviors/behavior_soft_off.c | 2 +- app/src/pm.c | 68 ++++++++++++++++++++++++++- 5 files changed, 79 insertions(+), 61 deletions(-) diff --git a/app/Kconfig b/app/Kconfig index 28d3c22a..5068e91f 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -405,6 +405,7 @@ config ZMK_SLEEP bool "Enable deep sleep support" depends on HAS_POWEROFF select POWEROFF + select ZMK_PM_DEVICE_SUSPEND_RESUME imply USB if ZMK_SLEEP @@ -426,10 +427,15 @@ config ZMK_EXT_POWER config ZMK_PM bool +config ZMK_PM_DEVICE_SUSPEND_RESUME + bool + select ZMK_PM + config ZMK_PM_SOFT_OFF bool "Soft-off support" select ZMK_PM select PM_DEVICE + select ZMK_PM_DEVICE_SUSPEND_RESUME config ZMK_GPIO_KEY_WAKEUP_TRIGGER bool "Hardware supported wakeup (GPIO)" diff --git a/app/include/zmk/pm.h b/app/include/zmk/pm.h index dff217af..a733856d 100644 --- a/app/include/zmk/pm.h +++ b/app/include/zmk/pm.h @@ -6,4 +6,7 @@ #pragma once +int zmk_pm_suspend_devices(void); +void zmk_pm_resume_devices(void); + int zmk_pm_soft_off(void); \ No newline at end of file diff --git a/app/src/activity.c b/app/src/activity.c index 8f421f85..454e91e5 100644 --- a/app/src/activity.c +++ b/app/src/activity.c @@ -7,8 +7,6 @@ #include #include #include -#include -#include #include #include @@ -20,69 +18,14 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include #include +#include + #include #if IS_ENABLED(CONFIG_USB_DEVICE_STACK) #include #endif -// Reimplement some of the device work from Zephyr PM to work with the new `sys_poweroff` API. -// TODO: Tweak this to smarter runtime PM of subsystems on sleep. - -#ifdef CONFIG_PM_DEVICE -TYPE_SECTION_START_EXTERN(const struct device *, zmk_pm_device_slots); - -#if !defined(CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE) -/* Number of devices successfully suspended. */ -static size_t zmk_num_susp; - -static int zmk_pm_suspend_devices(void) { - const struct device *devs; - size_t devc; - - devc = z_device_get_all_static(&devs); - - zmk_num_susp = 0; - - for (const struct device *dev = devs + devc - 1; dev >= devs; dev--) { - int ret; - - /* - * Ignore uninitialized devices, busy devices, wake up sources, and - * devices with runtime PM enabled. - */ - if (!device_is_ready(dev) || pm_device_is_busy(dev) || pm_device_state_is_locked(dev) || - pm_device_wakeup_is_enabled(dev) || pm_device_runtime_is_enabled(dev)) { - continue; - } - - ret = pm_device_action_run(dev, PM_DEVICE_ACTION_SUSPEND); - /* ignore devices not supporting or already at the given state */ - if ((ret == -ENOSYS) || (ret == -ENOTSUP) || (ret == -EALREADY)) { - continue; - } else if (ret < 0) { - LOG_ERR("Device %s did not enter %s state (%d)", dev->name, - pm_device_state_str(PM_DEVICE_STATE_SUSPENDED), ret); - return ret; - } - - TYPE_SECTION_START(zmk_pm_device_slots)[zmk_num_susp] = dev; - zmk_num_susp++; - } - - return 0; -} - -static void zmk_pm_resume_devices(void) { - for (int i = (zmk_num_susp - 1); i >= 0; i--) { - pm_device_action_run(TYPE_SECTION_START(zmk_pm_device_slots)[i], PM_DEVICE_ACTION_RESUME); - } - - zmk_num_susp = 0; -} -#endif /* !CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE */ -#endif /* CONFIG_PM_DEVICE */ - bool is_usb_power_present(void) { #if IS_ENABLED(CONFIG_USB_DEVICE_STACK) return zmk_usb_is_powered(); diff --git a/app/src/behaviors/behavior_soft_off.c b/app/src/behaviors/behavior_soft_off.c index e6096bb4..878a2fc5 100644 --- a/app/src/behaviors/behavior_soft_off.c +++ b/app/src/behaviors/behavior_soft_off.c @@ -64,7 +64,7 @@ static const struct behavior_driver_api behavior_soft_off_driver_api = { }; \ static struct behavior_soft_off_data bso_data_##n = {}; \ BEHAVIOR_DT_INST_DEFINE(0, behavior_soft_off_init, NULL, &bso_data_##n, &bso_config_##n, \ - APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ + POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ &behavior_soft_off_driver_api); DT_INST_FOREACH_STATUS_OKAY(BSO_INST) diff --git a/app/src/pm.c b/app/src/pm.c index 8525046f..4f151875 100644 --- a/app/src/pm.c +++ b/app/src/pm.c @@ -8,13 +8,72 @@ #include #include #include +#include #include +#include #include LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include +// Reimplement some of the device work from Zephyr PM to work with the new `sys_poweroff` API. +// TODO: Tweak this to smarter runtime PM of subsystems on sleep. + +#ifdef CONFIG_ZMK_PM_DEVICE_SUSPEND_RESUME +TYPE_SECTION_START_EXTERN(const struct device *, zmk_pm_device_slots); + +#if !defined(CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE) +/* Number of devices successfully suspended. */ +static size_t zmk_num_susp; + +int zmk_pm_suspend_devices(void) { + const struct device *devs; + size_t devc; + + devc = z_device_get_all_static(&devs); + + zmk_num_susp = 0; + + for (const struct device *dev = devs + devc - 1; dev >= devs; dev--) { + int ret; + + /* + * Ignore uninitialized devices, busy devices, wake up sources, and + * devices with runtime PM enabled. + */ + if (!device_is_ready(dev) || pm_device_is_busy(dev) || pm_device_state_is_locked(dev) || + pm_device_wakeup_is_enabled(dev) || pm_device_runtime_is_enabled(dev)) { + continue; + } + + ret = pm_device_action_run(dev, PM_DEVICE_ACTION_SUSPEND); + /* ignore devices not supporting or already at the given state */ + if ((ret == -ENOSYS) || (ret == -ENOTSUP) || (ret == -EALREADY)) { + continue; + } else if (ret < 0) { + LOG_ERR("Device %s did not enter %s state (%d)", dev->name, + pm_device_state_str(PM_DEVICE_STATE_SUSPENDED), ret); + return ret; + } + + TYPE_SECTION_START(zmk_pm_device_slots)[zmk_num_susp] = dev; + zmk_num_susp++; + } + + return 0; +} + +void zmk_pm_resume_devices(void) { + for (int i = (zmk_num_susp - 1); i >= 0; i--) { + pm_device_action_run(TYPE_SECTION_START(zmk_pm_device_slots)[i], PM_DEVICE_ACTION_RESUME); + } + + zmk_num_susp = 0; +} +#endif /* !CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE */ +#endif /* CONFIG_ZMK_PM_DEVICE_SUSPEND_RESUME */ + #if IS_ENABLED(CONFIG_ZMK_PM_SOFT_OFF) #define HAS_WAKERS DT_HAS_COMPAT_STATUS_OKAY(zmk_soft_off_wakeup_sources) @@ -64,8 +123,15 @@ int zmk_pm_soft_off(void) { } #endif // HAS_WAKERS + int err = zmk_pm_suspend_devices(); + if (err < 0) { + zmk_pm_resume_devices(); + return err; + } + LOG_DBG("soft-off: go to sleep"); - return pm_state_force(0U, &(struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0}); + sys_poweroff(); + return 0; } #endif // IS_ENABLED(CONFIG_ZMK_PM_SOFT_OFF) \ No newline at end of file From cac999b1d6f09cb9f11fbdb832bed64b888baef5 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Tue, 20 Feb 2024 07:59:26 +0000 Subject: [PATCH 26/45] feat: Updated soft-off docs. * Document new sideband behavior kscan driver for integrated soft-off support. --- docs/docs/features/soft-off.md | 207 +++++++++++++++++++++++++-------- 1 file changed, 156 insertions(+), 51 deletions(-) diff --git a/docs/docs/features/soft-off.md b/docs/docs/features/soft-off.md index 370a3880..ff47e7f1 100644 --- a/docs/docs/features/soft-off.md +++ b/docs/docs/features/soft-off.md @@ -37,11 +37,28 @@ The simplest way to achieve this is with a push button between a GPIO pin and gr #### Matrix-Integrated Hardware Combo -Another, more complicated option is to tie two of the switch outputs in the matrix together through an AND gate and connect that to the dedicated GPIO pin. This way you can use a key combination in your existing keyboard matrix to trigger soft on/off. To make this work best, the two switches used should both be driven by the same matrix input pin so that both will be active simultaneously on the AND gate inputs. The alternative is to use a combination of diodes and capacitors to ensure both pins are active/high at the same time even if scanning sets them high at different times. Support for this mode will be coming soon. +Another, more complicated option is to tie two of the switch outputs in the matrix together through an AND gate and connect that to the dedicated GPIO pin. This way you can use a key combination in your existing keyboard matrix to trigger soft on/off. To make this work best, the two switches used should both be driven by the same matrix input pin so that both will be active simultaneously on the AND gate inputs. The alternative is to connect the switch to two MOSFETs that trigger both the regular matrix connect and the connect to the AND gate to ensure both pins are active/high at the same time even if scanning sets them high at different times. ### Firmware Changes -Several items work together to make both triggering soft off properly, and setting up the device to _wake_ from soft off work as expected. +Several items work together to make both triggering soft off properly, and setting up the device to _wake_ from soft off work as expected. In addition, some small changes are needed to keep the regular idle deep sleep functionality working. + +#### Wakeup Sources + +Zephyr has general support for the concept of a device as a "wakeup source", which ZMK has not previously used. Adding soft off requires properly updating the existing `kscan` devices with the `wakeup-source` property to ensure they will still work to wake the device from regular inactive deep sleep, e.g.: + +``` +/ { + kscan0: kscan_0 { + compatible = "zmk,kscan-gpio-matrix"; + label = "KSCAN"; + diode-direction = "col2row"; + wakeup-source; + + ... + }; +}; +``` #### GPIO Key @@ -62,55 +79,6 @@ GPIO keys are defined using child nodes under the `gpio-keys` compatible node. E - The `gpios` property should be a phandle-array with a fully defined GPIO pin and with the correct pull up/down and active high/low flags set. In the above example the soft on/off would be triggered by pulling the specified pin low, typically by pressing a switch that has the other leg connected to ground. -#### Behavior Key - -Next, we will create a new "behavior key". Behavior keys are an easy way to tie a keymap behavior to a GPIO key outside of the normal keymap processing. They do _not_ do the normal keymap processing, so they are only suitable for use with basic behaviors, not complicated macros, hold-taps, etc. - -In this case, we will be creating a dedicated instance of the [Soft Off Behavior](../behaviors/soft-off.md) that will be used only for our hardware on/off button, then binding it to our key: - -``` -/ { - behaviors { - hw_soft_off: hw_soft_off { - compatible = "zmk,behavior-soft-off"; - #binding-cells = <0>; - hold-time-ms = <5000>; - }; - }; - - soft_off_behavior_key { - compatible = "zmk,gpio-key-behavior-trigger"; - bindings = <&hw_soft_off>; - key = <&wakeup_key>; - }; -}; -``` - -Here are the properties for the behavior key node: - -- The `compatible` property for the node must be `zmk,gpio-key-behavior-trigger`. -- The `bindings` property is a phandle to the soft off behavior defined above. -- The `key` property is a phandle to the GPIO key defined earlier. - -If you have set up your on/off to be controlled by a matrix-integrated combo, the behavior key will need to be integrated into your existing kscan setup. Full details to come when this is supported. - -#### Wakeup Sources - -Zephyr has general support for the concept of a device as a "wakeup source", which ZMK has not previously used. Adding soft off requires properly updating the existing `kscan` devices with the `wakeup-source` property, e.g.: - -``` -/ { - kscan0: kscan_0 { - compatible = "zmk,kscan-gpio-matrix"; - label = "KSCAN"; - diode-direction = "col2row"; - wakeup-source; - - ... - }; -}; -``` - #### Soft Off Waker Next, we need to add another device which will be enabled only when the keyboard is going into soft off state, and will configure the previously declared GPIO key with the correct interrupt configuration to wake the device from soft off once it is pressed. @@ -148,3 +116,140 @@ Here are the properties for the node: - The `compatible` property for the node must be `zmk,soft-off-wakeup-sources`. - The `wakeup-sources` property is a [phandle array](../config/index.md#devicetree-property-types) pointing to all the devices that should be enabled during the shutdown process to be sure they can later wake the keyboard. + +#### Soft Off Behavior Instance + +To use the [soft off behavior](../behaviors/soft-off.md) outside of a keymap, add an instance of the behavior to your `.overlay`/`.dts` file: + +``` +/ { + behaviors { + hw_soft_off: hw_soft_off { + compatible = "zmk,behavior-soft-off"; + #binding-cells = <0>; + hold-time-ms = <5000>; + }; + }; +}; +``` + +#### KScan Sideband Behavior + +The kscan sideband behavior driver will be used to trigger the [soft off behavior](../behaviors/soft-off.md) "out of band" from the normal keymap processing. To do so, it will decorate/wrap an underlying kscan driver. What kscan driver will vary for simple direct pin vs. matrix-integrated hardware combo. + +##### Simple Direct Pin + +With a simple direct pin setup, the The [direct kscan](../config/kscan.md) driver can be used with a GPIO key, to make a small "side matrix": + +``` + soft_off_direct_scan: soft_off_direct_scan { + compatible = "zmk,kscan-gpio-direct"; + input-keys = <&wakeup_key>; + }; +``` + +With that in place, the kscan sideband behavior will wrap the new driver: + +``` +/ { + side_band_behavior_triggers: side_band_behavior_triggers { + compatible = "zmk,kscan-sideband-behaviors"; + + kscan = <&soft_off_direct_scan>; + wakeup-source; + + soft_off { + column = <0>; + row = <0>; + bindings = <&hw_soft_off>; + }; + }; +}; +``` + +##### Matrix-Integrated Hardware Combo + +For this case, you will supplement the existing kscan matrix, by adding the additional pin as another entry in +the `row-gpios`/`col-gpios` for whichever pins are used to read the matrix state. For example, for an existing matrix like: + +``` + kscan: kscan { + compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + label = "KSCAN"; + debounce-press-ms = <1>; + debounce-release-ms = <5>; + + diode-direction = "col2row"; + + col-gpios + = <&gpio0 12 (GPIO_ACTIVE_HIGH)> + , <&gpio1 9 (GPIO_ACTIVE_HIGH)> + ; + row-gpios + = <&gpio0 19 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&gpio0 4 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + ; + }; +``` + +you would add another row value: + +``` + kscan: kscan { + compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + label = "KSCAN"; + debounce-press-ms = <1>; + debounce-release-ms = <5>; + + diode-direction = "col2row"; + + col-gpios + = <&gpio0 12 (GPIO_ACTIVE_HIGH)> + , <&gpio1 9 (GPIO_ACTIVE_HIGH)> + ; + row-gpios + = <&gpio0 19 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&gpio0 4 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + , <&gpio0 2 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> + ; + }; +``` + +With that in place, you would decorate the kscan driver: + +``` + side_band_behavior_triggers: side_band_behavior_triggers { + compatible = "zmk,kscan-sideband-behaviors"; + wakeup-source; + kscan = <&kscan>; + soft_off { + column = <0>; + row = <3>; + bindings = <&hw_soft_off>; + }; + }; +``` + +Critically, the `column` and `row` values would correspond to the location of the added entry. + +Lastly, which is critical, you would update the `zmk,kscan` chosen value to point to the new kscan instance: + +``` + chosen { + ... + zmk,kscan = &side_band_behavior_triggers; + ... + }; +``` + +Here are the properties for the kscan sideband behaviors node: + +- The `compatible` property for the node must be `zmk,kscan-sideband-behaviors`. +- The `kscan` property is a phandle to the inner kscan instance that will have press/release events intercepted. + +The child nodes allow setting up the behaviors to invoke directly for a certain row and column: + +- The `row` and `column` properties set the values to intercept and trigger the behavior for. +- The `bindings` property references the behavior that should be triggered when the matching row and column event triggers. From bb94a7aafeb3d3d2f4165f58a654e79f8f6e6c9f Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Tue, 20 Feb 2024 00:10:15 -0800 Subject: [PATCH 27/45] fix: Fixes for building soft off without deep sleep. --- app/CMakeLists.txt | 2 +- app/Kconfig | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 2abf943f..2744f53d 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -8,7 +8,7 @@ set(ZEPHYR_EXTRA_MODULES "${ZMK_EXTRA_MODULES};${CMAKE_CURRENT_SOURCE_DIR}/modul find_package(Zephyr REQUIRED HINTS ../zephyr) project(zmk) -if(CONFIG_ZMK_SLEEP) +if(CONFIG_ZMK_PM_DEVICE_SUSPEND_RESUME) zephyr_linker_sources(SECTIONS include/linker/zmk-pm-devices.ld) endif() diff --git a/app/Kconfig b/app/Kconfig index 5068e91f..8f2fe837 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -433,9 +433,11 @@ config ZMK_PM_DEVICE_SUSPEND_RESUME config ZMK_PM_SOFT_OFF bool "Soft-off support" + depends on HAS_POWEROFF select ZMK_PM select PM_DEVICE select ZMK_PM_DEVICE_SUSPEND_RESUME + select POWEROFF config ZMK_GPIO_KEY_WAKEUP_TRIGGER bool "Hardware supported wakeup (GPIO)" From fa9ea9ea8b171a86765b5b08bed31922e9b2af76 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Fri, 15 Mar 2024 20:22:54 -0400 Subject: [PATCH 28/45] fix(docs): Fix soft off waker prop name, headers. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use the correct property for extra GPIOs to make active for the waker before going into soft off state. * Change header depth for easier navigation of the soft off feature page. Co-authored-by: Pablo Martínez <58857054+elpekenin@users.noreply.github.com> --- docs/docs/features/soft-off.md | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/docs/docs/features/soft-off.md b/docs/docs/features/soft-off.md index ff47e7f1..20a5bbe4 100644 --- a/docs/docs/features/soft-off.md +++ b/docs/docs/features/soft-off.md @@ -24,26 +24,24 @@ For existing designs, using soft off is as simple as placing the [Soft Off Behav You can then wake up the keyboard by pressing the reset button once, and repeating this for each side for split keyboards. -## Adding Dedicated Soft On/Off GPIO Pin To New Designs - -### Hardware Design +## Hardware Changes For New Designs ZMK's dedicated soft on/off pin feature requires a dedicated GPIO pin to be used to trigger powering off, and to wake the core from the soft off state when it goes active again later. -#### Simple Direct Pin +### Simple Direct Pin The simplest way to achieve this is with a push button between a GPIO pin and ground. -#### Matrix-Integrated Hardware Combo +### Matrix-Integrated Hardware Combo Another, more complicated option is to tie two of the switch outputs in the matrix together through an AND gate and connect that to the dedicated GPIO pin. This way you can use a key combination in your existing keyboard matrix to trigger soft on/off. To make this work best, the two switches used should both be driven by the same matrix input pin so that both will be active simultaneously on the AND gate inputs. The alternative is to connect the switch to two MOSFETs that trigger both the regular matrix connect and the connect to the AND gate to ensure both pins are active/high at the same time even if scanning sets them high at different times. -### Firmware Changes +## Firmware Changes For New Designs Several items work together to make both triggering soft off properly, and setting up the device to _wake_ from soft off work as expected. In addition, some small changes are needed to keep the regular idle deep sleep functionality working. -#### Wakeup Sources +### Wakeup Sources Zephyr has general support for the concept of a device as a "wakeup source", which ZMK has not previously used. Adding soft off requires properly updating the existing `kscan` devices with the `wakeup-source` property to ensure they will still work to wake the device from regular inactive deep sleep, e.g.: @@ -60,7 +58,7 @@ Zephyr has general support for the concept of a device as a "wakeup source", whi }; ``` -#### GPIO Key +### GPIO Key Zephyr's basic GPIO Key concept is used to configure the GPIO pin that will be used for both triggering soft off and waking the device later. Here is an example for a keyboard with a dedicated on/off push button that is a direct wire between the GPIO pin and ground: @@ -79,7 +77,7 @@ GPIO keys are defined using child nodes under the `gpio-keys` compatible node. E - The `gpios` property should be a phandle-array with a fully defined GPIO pin and with the correct pull up/down and active high/low flags set. In the above example the soft on/off would be triggered by pulling the specified pin low, typically by pressing a switch that has the other leg connected to ground. -#### Soft Off Waker +### Soft Off Waker Next, we need to add another device which will be enabled only when the keyboard is going into soft off state, and will configure the previously declared GPIO key with the correct interrupt configuration to wake the device from soft off once it is pressed. @@ -99,7 +97,7 @@ Here are the properties for the node: - The `compatible` property for the node must be `zmk,gpio-key-wakeup-trigger`. - The `trigger` property is a phandle to the GPIO key defined earlier. - The `wakeup-source` property signals to Zephyr this device should not be suspended during the shutdown procedure. -- An optional `output-gpios` property contains a list of GPIO pins (including the appropriate flags) to set active before going into power off, if needed to ensure the GPIO pin will trigger properly to wake the keyboard. This is only needed for matrix integrated combos. For those keyboards, the list should include the matrix output needs needed so the combo hardware is properly "driven" when the keyboard is off. +- An optional `extra-gpios` property contains a list of GPIO pins (including the appropriate flags) to set active before going into power off, if needed to ensure the GPIO pin will trigger properly to wake the keyboard. This is only needed for matrix integrated combos. For those keyboards, the list should include the matrix output needs needed so the combo hardware is properly "driven" when the keyboard is off. Once that is declared, we will list it in an additional configuration section so that the ZMK soft off process knows it needs to enable this device as part of the soft off processing: @@ -117,7 +115,7 @@ Here are the properties for the node: - The `compatible` property for the node must be `zmk,soft-off-wakeup-sources`. - The `wakeup-sources` property is a [phandle array](../config/index.md#devicetree-property-types) pointing to all the devices that should be enabled during the shutdown process to be sure they can later wake the keyboard. -#### Soft Off Behavior Instance +### Soft Off Behavior Instance To use the [soft off behavior](../behaviors/soft-off.md) outside of a keymap, add an instance of the behavior to your `.overlay`/`.dts` file: @@ -133,11 +131,11 @@ To use the [soft off behavior](../behaviors/soft-off.md) outside of a keymap, ad }; ``` -#### KScan Sideband Behavior +### KScan Sideband Behavior The kscan sideband behavior driver will be used to trigger the [soft off behavior](../behaviors/soft-off.md) "out of band" from the normal keymap processing. To do so, it will decorate/wrap an underlying kscan driver. What kscan driver will vary for simple direct pin vs. matrix-integrated hardware combo. -##### Simple Direct Pin +#### Simple Direct Pin With a simple direct pin setup, the The [direct kscan](../config/kscan.md) driver can be used with a GPIO key, to make a small "side matrix": @@ -167,7 +165,7 @@ With that in place, the kscan sideband behavior will wrap the new driver: }; ``` -##### Matrix-Integrated Hardware Combo +#### Matrix-Integrated Hardware Combo For this case, you will supplement the existing kscan matrix, by adding the additional pin as another entry in the `row-gpios`/`col-gpios` for whichever pins are used to read the matrix state. For example, for an existing matrix like: From 2df6dcd973776c0c0d1047d13178a72b5c0b6ca7 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Sat, 16 Mar 2024 14:15:52 -0700 Subject: [PATCH 29/45] feat(behaviors): More logging in soft off. --- app/src/behaviors/behavior_soft_off.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/behaviors/behavior_soft_off.c b/app/src/behaviors/behavior_soft_off.c index 878a2fc5..8b8ba4f9 100644 --- a/app/src/behaviors/behavior_soft_off.c +++ b/app/src/behaviors/behavior_soft_off.c @@ -45,8 +45,18 @@ static int on_keymap_binding_released(struct zmk_behavior_binding *binding, struct behavior_soft_off_data *data = dev->data; const struct behavior_soft_off_config *config = dev->config; - if (config->hold_time_ms == 0 || (k_uptime_get() - data->press_start) >= config->hold_time_ms) { + if (config->hold_time_ms == 0) { + LOG_DBG("No hold time set, triggering soft off"); zmk_pm_soft_off(); + } else { + uint32_t hold_time = k_uptime_get() - data->press_start; + + if (hold_time > config->hold_time_ms) { + zmk_pm_soft_off(); + } else { + LOG_INF("Not triggering soft off: held for %d and hold time is %d", hold_time, + config->hold_time_ms); + } } return ZMK_BEHAVIOR_OPAQUE; From d0e0ecb4e3d11b5303c1dc5c857ff1f75c1d0aaa Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 25 Mar 2024 01:47:11 -0700 Subject: [PATCH 30/45] refactor: Use kscan directly to wake when we can. * When adding a dedicated GPIO pin for soft off/on, use the direct kscan as the waker, instead of adding an additional node. --- .../boards/nrf52840dk_nrf52840.overlay | 22 ++--- docs/docs/features/soft-off.md | 95 +++++++++++-------- 2 files changed, 63 insertions(+), 54 deletions(-) diff --git a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay index 47b67dc0..b9c68e5a 100644 --- a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay +++ b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay @@ -42,24 +42,10 @@ encoder: &qdec0 { }; }; - wakeup_source: wakeup_source { - compatible = "zmk,gpio-key-wakeup-trigger"; - status = "okay"; - - trigger = <&button0>; - wakeup-source; - }; - - soft_off_wakers { - compatible = "zmk,soft-off-wakeup-sources"; - status = "okay"; - - wakeup-sources = <&wakeup_source>; - }; - soft_off_direct_kscan: soft_off_direct_kscan { compatible = "zmk,kscan-gpio-direct"; input-keys = <&button0>; + wakeup-source; }; soft_off_sideband_behaviors { @@ -72,4 +58,10 @@ encoder: &qdec0 { }; }; + soft_off_wakers { + compatible = "zmk,soft-off-wakeup-sources"; + status = "okay"; + + wakeup-sources = <&soft_off_direct_kscan>; + }; }; \ No newline at end of file diff --git a/docs/docs/features/soft-off.md b/docs/docs/features/soft-off.md index 20a5bbe4..b08e1643 100644 --- a/docs/docs/features/soft-off.md +++ b/docs/docs/features/soft-off.md @@ -66,7 +66,7 @@ Zephyr's basic GPIO Key concept is used to configure the GPIO pin that will be u / { keys { compatible = "gpio-keys"; - wakeup_key: wakeup_key { + soft_off_key: soft_off_key { gpios = <&gpio0 2 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; }; }; @@ -77,44 +77,6 @@ GPIO keys are defined using child nodes under the `gpio-keys` compatible node. E - The `gpios` property should be a phandle-array with a fully defined GPIO pin and with the correct pull up/down and active high/low flags set. In the above example the soft on/off would be triggered by pulling the specified pin low, typically by pressing a switch that has the other leg connected to ground. -### Soft Off Waker - -Next, we need to add another device which will be enabled only when the keyboard is going into soft off state, and will configure the previously declared GPIO key with the correct interrupt configuration to wake the device from soft off once it is pressed. - -``` -/ { - wakeup_source: wakeup_source { - compatible = "zmk,gpio-key-wakeup-trigger"; - - trigger = <&wakeup_key>; - wakeup-source; - }; -}; -``` - -Here are the properties for the node: - -- The `compatible` property for the node must be `zmk,gpio-key-wakeup-trigger`. -- The `trigger` property is a phandle to the GPIO key defined earlier. -- The `wakeup-source` property signals to Zephyr this device should not be suspended during the shutdown procedure. -- An optional `extra-gpios` property contains a list of GPIO pins (including the appropriate flags) to set active before going into power off, if needed to ensure the GPIO pin will trigger properly to wake the keyboard. This is only needed for matrix integrated combos. For those keyboards, the list should include the matrix output needs needed so the combo hardware is properly "driven" when the keyboard is off. - -Once that is declared, we will list it in an additional configuration section so that the ZMK soft off process knows it needs to enable this device as part of the soft off processing: - -``` -/ { - soft_off_wakers { - compatible = "zmk,soft-off-wakeup-sources"; - wakeup-sources = <&wakeup_source>; - }; -}; -``` - -Here are the properties for the node: - -- The `compatible` property for the node must be `zmk,soft-off-wakeup-sources`. -- The `wakeup-sources` property is a [phandle array](../config/index.md#devicetree-property-types) pointing to all the devices that should be enabled during the shutdown process to be sure they can later wake the keyboard. - ### Soft Off Behavior Instance To use the [soft off behavior](../behaviors/soft-off.md) outside of a keymap, add an instance of the behavior to your `.overlay`/`.dts` file: @@ -143,6 +105,7 @@ With a simple direct pin setup, the The [direct kscan](../config/kscan.md) drive soft_off_direct_scan: soft_off_direct_scan { compatible = "zmk,kscan-gpio-direct"; input-keys = <&wakeup_key>; + wakeup-source; }; ``` @@ -165,6 +128,22 @@ With that in place, the kscan sideband behavior will wrap the new driver: }; ``` +Finally, we will list the kscan instance in an additional configuration section so that the ZMK soft off process knows it needs to enable this device as part of the soft off processing so it can _also_ wake the keyboard from soft off when pressed: + +``` +/ { + soft_off_wakers { + compatible = "zmk,soft-off-wakeup-sources"; + wakeup-sources = <&soft_off_direct_scan>; + }; +}; +``` + +Here are the properties for the node: + +- The `compatible` property for the node must be `zmk,soft-off-wakeup-sources`. +- The `wakeup-sources` property is a [phandle array](../config/index.md#devicetree-property-types) pointing to all the devices that should be enabled during the shutdown process to be sure they can later wake the keyboard. + #### Matrix-Integrated Hardware Combo For this case, you will supplement the existing kscan matrix, by adding the additional pin as another entry in @@ -251,3 +230,41 @@ The child nodes allow setting up the behaviors to invoke directly for a certain - The `row` and `column` properties set the values to intercept and trigger the behavior for. - The `bindings` property references the behavior that should be triggered when the matching row and column event triggers. + +### Soft Off Waker + +Next, we need to add another device which will be enabled only when the keyboard is going into soft off state, and will configure the previously declared GPIO key with the correct interrupt configuration to wake the device from soft off once it is pressed. + +``` +/ { + wakeup_source: wakeup_source { + compatible = "zmk,gpio-key-wakeup-trigger"; + + trigger = <&wakeup_key>; + wakeup-source; + }; +}; +``` + +Here are the properties for the node: + +- The `compatible` property for the node must be `zmk,gpio-key-wakeup-trigger`. +- The `trigger` property is a phandle to the GPIO key defined earlier. +- The `wakeup-source` property signals to Zephyr this device should not be suspended during the shutdown procedure. +- An optional `extra-gpios` property contains a list of GPIO pins (including the appropriate flags) to set active before going into power off, if needed to ensure the GPIO pin will trigger properly to wake the keyboard. This is only needed for matrix integrated combos. For those keyboards, the list should include the matrix output needs needed so the combo hardware is properly "driven" when the keyboard is off. + +Once that is declared, we will list it in an additional configuration section so that the ZMK soft off process knows it needs to enable this device as part of the soft off processing: + +``` +/ { + soft_off_wakers { + compatible = "zmk,soft-off-wakeup-sources"; + wakeup-sources = <&wakeup_source>; + }; +}; +``` + +Here are the properties for the node: + +- The `compatible` property for the node must be `zmk,soft-off-wakeup-sources`. +- The `wakeup-sources` property is a [phandle array](../config/index.md#devicetree-property-types) pointing to all the devices that should be enabled during the shutdown process to be sure they can later wake the keyboard. From 41d81801ed11a1dca918c9c0088351856e4e1808 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 25 Mar 2024 09:37:14 +0000 Subject: [PATCH 31/45] fix(pm): Use Zephyr created device slots. * Avoid overwriting random memory by using iterable section created by Zephyr PM. --- app/CMakeLists.txt | 4 ---- app/include/linker/zmk-pm-devices.ld | 9 --------- app/src/pm.c | 6 +++--- 3 files changed, 3 insertions(+), 16 deletions(-) delete mode 100644 app/include/linker/zmk-pm-devices.ld diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 2744f53d..0b681ea9 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -8,10 +8,6 @@ set(ZEPHYR_EXTRA_MODULES "${ZMK_EXTRA_MODULES};${CMAKE_CURRENT_SOURCE_DIR}/modul find_package(Zephyr REQUIRED HINTS ../zephyr) project(zmk) -if(CONFIG_ZMK_PM_DEVICE_SUSPEND_RESUME) - zephyr_linker_sources(SECTIONS include/linker/zmk-pm-devices.ld) -endif() - zephyr_linker_sources(SECTIONS include/linker/zmk-behaviors.ld) zephyr_linker_sources(RODATA include/linker/zmk-events.ld) diff --git a/app/include/linker/zmk-pm-devices.ld b/app/include/linker/zmk-pm-devices.ld deleted file mode 100644 index 93ec5025..00000000 --- a/app/include/linker/zmk-pm-devices.ld +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (c) 2023 The ZMK Contributors - * - * SPDX-License-Identifier: MIT - */ - -#include - -ITERABLE_SECTION_RAM(zmk_pm_device_slots, 4) diff --git a/app/src/pm.c b/app/src/pm.c index 4f151875..447eb351 100644 --- a/app/src/pm.c +++ b/app/src/pm.c @@ -21,7 +21,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); // TODO: Tweak this to smarter runtime PM of subsystems on sleep. #ifdef CONFIG_ZMK_PM_DEVICE_SUSPEND_RESUME -TYPE_SECTION_START_EXTERN(const struct device *, zmk_pm_device_slots); +TYPE_SECTION_START_EXTERN(const struct device *, pm_device_slots); #if !defined(CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE) /* Number of devices successfully suspended. */ @@ -57,7 +57,7 @@ int zmk_pm_suspend_devices(void) { return ret; } - TYPE_SECTION_START(zmk_pm_device_slots)[zmk_num_susp] = dev; + TYPE_SECTION_START(pm_device_slots)[zmk_num_susp] = dev; zmk_num_susp++; } @@ -66,7 +66,7 @@ int zmk_pm_suspend_devices(void) { void zmk_pm_resume_devices(void) { for (int i = (zmk_num_susp - 1); i >= 0; i--) { - pm_device_action_run(TYPE_SECTION_START(zmk_pm_device_slots)[i], PM_DEVICE_ACTION_RESUME); + pm_device_action_run(TYPE_SECTION_START(pm_device_slots)[i], PM_DEVICE_ACTION_RESUME); } zmk_num_susp = 0; From 7e7110d85f0fe24948b319382bed723e38f5336c Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 25 Mar 2024 02:39:54 -0700 Subject: [PATCH 32/45] fix(pm): Fixes for dedicated on/off on peripherals. * Add new flag to differentiate soft off on peripherals that is invoked by split GATT svc and dedicated additional ones tied to GPIO pin. --- .../zmk_uno/boards/nrf52840dk_nrf52840.overlay | 5 ++--- app/dts/behaviors/soft_off.dtsi | 3 ++- .../behaviors/zmk,behavior-soft-off.yaml | 3 +++ app/src/behaviors/behavior_soft_off.c | 17 ++++++++++++----- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay index b9c68e5a..d798eca7 100644 --- a/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay +++ b/app/boards/shields/zmk_uno/boards/nrf52840dk_nrf52840.overlay @@ -35,10 +35,9 @@ encoder: &qdec0 { / { behaviors { - soft_off: soft_off { + hw_soft_off: hw_soft_off { compatible = "zmk,behavior-soft-off"; #binding-cells = <0>; - status = "okay"; }; }; @@ -54,7 +53,7 @@ encoder: &qdec0 { soft_off { row = <0>; column = <0>; - bindings = <&soft_off>; + bindings = <&hw_soft_off>; }; }; diff --git a/app/dts/behaviors/soft_off.dtsi b/app/dts/behaviors/soft_off.dtsi index 1e58c771..63c04b1d 100644 --- a/app/dts/behaviors/soft_off.dtsi +++ b/app/dts/behaviors/soft_off.dtsi @@ -6,9 +6,10 @@ / { behaviors { - /omit-if-no-ref/ soft_off: soft_off { + /omit-if-no-ref/ soft_off: keymap_soft_off { compatible = "zmk,behavior-soft-off"; #binding-cells = <0>; + split-peripheral-off-on-press; }; }; }; diff --git a/app/dts/bindings/behaviors/zmk,behavior-soft-off.yaml b/app/dts/bindings/behaviors/zmk,behavior-soft-off.yaml index 1467ede4..865e656f 100644 --- a/app/dts/bindings/behaviors/zmk,behavior-soft-off.yaml +++ b/app/dts/bindings/behaviors/zmk,behavior-soft-off.yaml @@ -12,3 +12,6 @@ properties: type: int required: false description: Number of milliseconds the behavior must be held before releasing will actually trigger a soft-off. + split-peripheral-off-on-press: + type: boolean + description: When built for a split peripheral, turn off on press, not release diff --git a/app/src/behaviors/behavior_soft_off.c b/app/src/behaviors/behavior_soft_off.c index 8b8ba4f9..3a4ae424 100644 --- a/app/src/behaviors/behavior_soft_off.c +++ b/app/src/behaviors/behavior_soft_off.c @@ -16,6 +16,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); struct behavior_soft_off_config { + bool split_peripheral_turn_off_on_press; uint32_t hold_time_ms; }; @@ -23,18 +24,22 @@ struct behavior_soft_off_data { uint32_t press_start; }; +#define IS_SPLIT_PERIPHERAL \ + (IS_ENABLED(CONFIG_ZMK_SPLIT) && !IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL)) + static int behavior_soft_off_init(const struct device *dev) { return 0; }; static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding, struct zmk_behavior_binding_event event) { const struct device *dev = zmk_behavior_get_binding(binding->behavior_dev); struct behavior_soft_off_data *data = dev->data; + const struct behavior_soft_off_config *config = dev->config; -#if IS_ENABLED(CONFIG_ZMK_SPLIT) && !IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) - zmk_pm_soft_off(); -#else - data->press_start = k_uptime_get(); -#endif + if (IS_SPLIT_PERIPHERAL && config->split_peripheral_turn_off_on_press) { + zmk_pm_soft_off(); + } else { + data->press_start = k_uptime_get(); + } return ZMK_BEHAVIOR_OPAQUE; } @@ -71,6 +76,8 @@ static const struct behavior_driver_api behavior_soft_off_driver_api = { #define BSO_INST(n) \ static const struct behavior_soft_off_config bso_config_##n = { \ .hold_time_ms = DT_INST_PROP_OR(n, hold_time_ms, 0), \ + .split_peripheral_turn_off_on_press = \ + DT_INST_PROP_OR(n, split_peripheral_off_on_press, false), \ }; \ static struct behavior_soft_off_data bso_data_##n = {}; \ BEHAVIOR_DT_INST_DEFINE(0, behavior_soft_off_init, NULL, &bso_data_##n, &bso_config_##n, \ From 29c0cdb3abce98708f5961e01d96eefc9efb7d42 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 25 Mar 2024 09:41:33 +0000 Subject: [PATCH 33/45] fix(shields): Fix for direct use with ZMK Uno split. --- app/boards/shields/zmk_uno/zmk_uno_split.keymap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/boards/shields/zmk_uno/zmk_uno_split.keymap b/app/boards/shields/zmk_uno/zmk_uno_split.keymap index 37672a7d..0e50a283 100644 --- a/app/boards/shields/zmk_uno/zmk_uno_split.keymap +++ b/app/boards/shields/zmk_uno/zmk_uno_split.keymap @@ -21,7 +21,7 @@ // / { // chosen { // zmk,matrix-transform = &split_direct_matrix_transform; -// zmk,kscan = &kscan_direct_comp; +// zmk,kscan = &kscan_direct; // }; // }; From e66f068fb5d53f3e6071359970021d04a338c176 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Wed, 27 Mar 2024 20:35:40 -0700 Subject: [PATCH 34/45] fix(docs): Minor soft-off docs tweaks from review. --- docs/docs/behaviors/soft-off.md | 2 ++ docs/docs/config/kscan.md | 2 +- docs/docs/features/soft-off.md | 8 ++++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/docs/behaviors/soft-off.md b/docs/docs/behaviors/soft-off.md index 05374004..14b5f36a 100644 --- a/docs/docs/behaviors/soft-off.md +++ b/docs/docs/behaviors/soft-off.md @@ -7,6 +7,8 @@ sidebar_label: Soft Off The soft off behavior is used to force the keyboard into an off state. Depending on the specific keyboard hardware, the keyboard can be turned back on again either with a dedicated on/off button that is available, or using the reset button found on the device. +Refer to the [soft off config](../config/power.md#soft-off) for details on enabling soft off in order to use this behavior. + For more information, see the [Soft Off Feature](../features/soft-off.md) page. ### Behavior Binding diff --git a/docs/docs/config/kscan.md b/docs/docs/config/kscan.md index 4a3954f9..3aa1b378 100644 --- a/docs/docs/config/kscan.md +++ b/docs/docs/config/kscan.md @@ -73,7 +73,7 @@ Definition file: [zmk/app/module/dts/bindings/kscan/zmk,kscan-gpio-direct.yaml]( | Property | Type | Description | Default | | ------------------------- | ---------- | ----------------------------------------------------------------------------------------------------------- | ------- | -| `input-gpios` | GPIO array | Input GPIOs (one per key) | | +| `input-gpios` | GPIO array | Input GPIOs (one per key). Can be either direct GPIO pin or `gpio-key` references. | | | `debounce-press-ms` | int | Debounce time for key press in milliseconds. Use 0 for eager debouncing. | 5 | | `debounce-release-ms` | int | Debounce time for key release in milliseconds. | 5 | | `debounce-scan-period-ms` | int | Time between reads in milliseconds when any key is pressed. | 1 | diff --git a/docs/docs/features/soft-off.md b/docs/docs/features/soft-off.md index b08e1643..bd631f1b 100644 --- a/docs/docs/features/soft-off.md +++ b/docs/docs/features/soft-off.md @@ -18,6 +18,10 @@ Once powered off, the keyboard will only wake up when: - You press the same button/sequence that you pressed to power off the keyboard, or - You press a reset button found on the keyboard. +## Config + +Refer to the [soft off config](../config/power.md#soft-off) for details on enabling soft off. + ## Soft Off With Existing Designs For existing designs, using soft off is as simple as placing the [Soft Off Behavior](../behaviors/soft-off.md) in your keymap and then invoking it. @@ -104,7 +108,7 @@ With a simple direct pin setup, the The [direct kscan](../config/kscan.md) drive ``` soft_off_direct_scan: soft_off_direct_scan { compatible = "zmk,kscan-gpio-direct"; - input-keys = <&wakeup_key>; + input-keys = <&on_off_key>; wakeup-source; }; ``` @@ -240,7 +244,7 @@ Next, we need to add another device which will be enabled only when the keyboard wakeup_source: wakeup_source { compatible = "zmk,gpio-key-wakeup-trigger"; - trigger = <&wakeup_key>; + trigger = <&on_off_key>; wakeup-source; }; }; From f9bb18b67631288a7ee8046e796775e34b61c0f6 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Thu, 28 Mar 2024 04:14:02 +0000 Subject: [PATCH 35/45] fix(docs): Add `&soft_off` to behaviors index. --- docs/docs/behaviors/index.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/docs/behaviors/index.mdx b/docs/docs/behaviors/index.mdx index 32f4b29a..4a05f565 100644 --- a/docs/docs/behaviors/index.mdx +++ b/docs/docs/behaviors/index.mdx @@ -70,6 +70,7 @@ Below is a summary of pre-defined behavior bindings and user-definable behaviors | Binding | Behavior | Description | | ------------ | --------------------------------------------- | --------------------------------------------------------------- | | `&ext_power` | [Power management](power.md#behavior-binding) | Allows enabling or disabling the VCC power output to save power | +| `&soft_off` | [Soft off](soft-off.md#behavior-binding) | Turns the keyboard off. | ## User-defined behaviors From 34910787ff68d7e977a2f74b4bc51ef8f99d2cb7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 23 Mar 2024 06:44:29 +0000 Subject: [PATCH 36/45] chore(deps): bump webpack-dev-middleware from 5.3.3 to 5.3.4 in /docs Bumps [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware) from 5.3.3 to 5.3.4. - [Release notes](https://github.com/webpack/webpack-dev-middleware/releases) - [Changelog](https://github.com/webpack/webpack-dev-middleware/blob/v5.3.4/CHANGELOG.md) - [Commits](https://github.com/webpack/webpack-dev-middleware/compare/v5.3.3...v5.3.4) --- updated-dependencies: - dependency-name: webpack-dev-middleware dependency-type: indirect ... Signed-off-by: dependabot[bot] --- docs/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/package-lock.json b/docs/package-lock.json index 16525e7c..b0b7e4f6 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -21538,9 +21538,9 @@ } }, "node_modules/webpack-dev-middleware": { - "version": "5.3.3", - "resolved": "https://registry.npmjs.org/webpack-dev-middleware/-/webpack-dev-middleware-5.3.3.tgz", - "integrity": "sha512-hj5CYrY0bZLB+eTO+x/j67Pkrquiy7kWepMHmUMoPsmcUaeEnQJqFzHJOyxgWlq746/wUuA64p9ta34Kyb01pA==", + "version": "5.3.4", + "resolved": "https://registry.npmjs.org/webpack-dev-middleware/-/webpack-dev-middleware-5.3.4.tgz", + "integrity": "sha512-BVdTqhhs+0IfoeAf7EoH5WE+exCmqGerHfDM0IL096Px60Tq2Mn9MAbnaGUe6HiMa41KMCYF19gyzZmBcq/o4Q==", "dependencies": { "colorette": "^2.0.10", "memfs": "^3.4.3", From 25bb126a11736545401e351a68649b7626763963 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 28 Mar 2024 17:16:57 +0000 Subject: [PATCH 37/45] chore(deps): bump express from 4.18.2 to 4.19.2 in /docs Bumps [express](https://github.com/expressjs/express) from 4.18.2 to 4.19.2. - [Release notes](https://github.com/expressjs/express/releases) - [Changelog](https://github.com/expressjs/express/blob/master/History.md) - [Commits](https://github.com/expressjs/express/compare/4.18.2...4.19.2) --- updated-dependencies: - dependency-name: express dependency-type: indirect ... Signed-off-by: dependabot[bot] --- docs/package-lock.json | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/package-lock.json b/docs/package-lock.json index b0b7e4f6..afdc8248 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -4809,12 +4809,12 @@ } }, "node_modules/body-parser": { - "version": "1.20.1", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", - "integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==", + "version": "1.20.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz", + "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==", "dependencies": { "bytes": "3.1.2", - "content-type": "~1.0.4", + "content-type": "~1.0.5", "debug": "2.6.9", "depd": "2.0.0", "destroy": "1.2.0", @@ -4822,7 +4822,7 @@ "iconv-lite": "0.4.24", "on-finished": "2.4.1", "qs": "6.11.0", - "raw-body": "2.5.1", + "raw-body": "2.5.2", "type-is": "~1.6.18", "unpipe": "1.0.0" }, @@ -5542,9 +5542,9 @@ "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==" }, "node_modules/cookie": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz", - "integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==", + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz", + "integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==", "engines": { "node": ">= 0.6" } @@ -9042,16 +9042,16 @@ } }, "node_modules/express": { - "version": "4.18.2", - "resolved": "https://registry.npmjs.org/express/-/express-4.18.2.tgz", - "integrity": "sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==", + "version": "4.19.2", + "resolved": "https://registry.npmjs.org/express/-/express-4.19.2.tgz", + "integrity": "sha512-5T6nhjsT+EOMzuck8JjBHARTHfMht0POzlA60WV2pMD3gyXw2LZnZ+ueGdNxG+0calOJcWKbpFcuzLZ91YWq9Q==", "dependencies": { "accepts": "~1.3.8", "array-flatten": "1.1.1", - "body-parser": "1.20.1", + "body-parser": "1.20.2", "content-disposition": "0.5.4", "content-type": "~1.0.4", - "cookie": "0.5.0", + "cookie": "0.6.0", "cookie-signature": "1.0.6", "debug": "2.6.9", "depd": "2.0.0", @@ -17802,9 +17802,9 @@ } }, "node_modules/raw-body": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz", - "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==", + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz", + "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==", "dependencies": { "bytes": "3.1.2", "http-errors": "2.0.0", From 18b86b7720201dde045fddb42965cd64d1082a9b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 28 Mar 2024 17:23:05 +0000 Subject: [PATCH 38/45] chore(deps): bump follow-redirects from 1.15.5 to 1.15.6 in /docs Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.5 to 1.15.6. - [Release notes](https://github.com/follow-redirects/follow-redirects/releases) - [Commits](https://github.com/follow-redirects/follow-redirects/compare/v1.15.5...v1.15.6) --- updated-dependencies: - dependency-name: follow-redirects dependency-type: indirect ... Signed-off-by: dependabot[bot] --- docs/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/package-lock.json b/docs/package-lock.json index afdc8248..379360a9 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -9387,9 +9387,9 @@ "devOptional": true }, "node_modules/follow-redirects": { - "version": "1.15.5", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.5.tgz", - "integrity": "sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==", + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "funding": [ { "type": "individual", From d672b0c70512aa9c880c76f34dd448f9cffe4ae6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 28 Mar 2024 17:32:02 +0000 Subject: [PATCH 39/45] chore(deps): bump react-toastify from 7.0.4 to 10.0.5 in /docs Bumps [react-toastify](https://github.com/fkhadra/react-toastify) from 7.0.4 to 10.0.5. - [Release notes](https://github.com/fkhadra/react-toastify/releases) - [Commits](https://github.com/fkhadra/react-toastify/compare/v7.0.4...v10.0.5) --- updated-dependencies: - dependency-name: react-toastify dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- docs/package-lock.json | 22 +++++++--------------- docs/package.json | 2 +- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/docs/package-lock.json b/docs/package-lock.json index 379360a9..3c76a963 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -20,7 +20,7 @@ "react-async": "^10.0.1", "react-copy-to-clipboard": "^5.0.3", "react-dom": "^18.0.0", - "react-toastify": "^7.0.4", + "react-toastify": "^10.0.5", "web-tree-sitter": "^0.20.8" }, "devDependencies": { @@ -18049,23 +18049,15 @@ } }, "node_modules/react-toastify": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/react-toastify/-/react-toastify-7.0.4.tgz", - "integrity": "sha512-Rol7+Cn39hZp5hQ/k6CbMNE2CKYV9E5OQdC/hBLtIQU2xz7DdAm7xil4NITQTHR6zEbE5RVFbpgSwTD7xRGLeQ==", + "version": "10.0.5", + "resolved": "https://registry.npmjs.org/react-toastify/-/react-toastify-10.0.5.tgz", + "integrity": "sha512-mNKt2jBXJg4O7pSdbNUfDdTsK9FIdikfsIE/yUCxbAEXl4HMyJaivrVFcn3Elvt5xvCQYhUZm+hqTIu1UXM3Pw==", "dependencies": { - "clsx": "^1.1.1" + "clsx": "^2.1.0" }, "peerDependencies": { - "react": ">=16", - "react-dom": ">=16" - } - }, - "node_modules/react-toastify/node_modules/clsx": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/clsx/-/clsx-1.2.1.tgz", - "integrity": "sha512-EcR6r5a8bj6pu3ycsa/E/cKVGuTgZJZdsyUYHOksG/UHIiKfjxzRxYJpyVBwYaQeOvghal9fcc4PidlgzugAQg==", - "engines": { - "node": ">=6" + "react": ">=18", + "react-dom": ">=18" } }, "node_modules/read-package-json-fast": { diff --git a/docs/package.json b/docs/package.json index 7f468cb5..a0801763 100644 --- a/docs/package.json +++ b/docs/package.json @@ -27,7 +27,7 @@ "react-async": "^10.0.1", "react-copy-to-clipboard": "^5.0.3", "react-dom": "^18.0.0", - "react-toastify": "^7.0.4", + "react-toastify": "^10.0.5", "web-tree-sitter": "^0.20.8" }, "browserslist": { From fff1cbecdcc75302b6280a469ed31687cfc79776 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Fri, 29 Mar 2024 18:15:06 +0000 Subject: [PATCH 40/45] fix: Add wakeup-source; to kscan nodes for ZMK_SLEEP. * ZMK_SLEEP also enables PM_DEVICE, so be sure to mark kscan nodes as wakeup sources so they can wake keyboards from sleep. --- app/boards/arm/adv360pro/adv360pro_left.dts | 1 + app/boards/arm/adv360pro/adv360pro_right.dts | 1 + app/boards/arm/bt60/bt60_v1.dts | 2 ++ app/boards/arm/bt60/bt60_v1_hs.dts | 2 ++ app/boards/arm/ckp/ckp.dtsi | 2 ++ app/boards/arm/corneish_zen/corneish_zen_v1_left.dts | 1 + app/boards/arm/corneish_zen/corneish_zen_v1_right.dts | 1 + app/boards/arm/corneish_zen/corneish_zen_v2_left.dts | 1 + app/boards/arm/corneish_zen/corneish_zen_v2_right.dts | 1 + app/boards/arm/glove80/glove80.dtsi | 2 ++ app/boards/arm/nice60/nice60.dts | 1 + app/boards/arm/s40nc/s40nc.dts | 1 + app/boards/shields/a_dux/a_dux.dtsi | 2 ++ app/boards/shields/bat43/bat43.overlay | 1 + app/boards/shields/bfo9000/bfo9000.dtsi | 1 + app/boards/shields/boardsource3x4/boardsource3x4.overlay | 2 ++ app/boards/shields/boardsource5x12/boardsource5x12.overlay | 2 ++ app/boards/shields/chalice/chalice.overlay | 2 ++ app/boards/shields/clog/clog.dtsi | 1 + app/boards/shields/contra/contra.overlay | 2 ++ app/boards/shields/corne/corne.dtsi | 1 + app/boards/shields/cradio/cradio.dtsi | 2 ++ app/boards/shields/crbn/crbn.overlay | 2 ++ app/boards/shields/eek/eek.overlay | 2 ++ app/boards/shields/elephant42/elephant42.dtsi | 1 + app/boards/shields/ergodash/ergodash.dtsi | 1 + app/boards/shields/eternal_keypad/eternal_keypad.dtsi | 1 + app/boards/shields/fourier/fourier.dtsi | 1 + app/boards/shields/helix/helix.dtsi | 1 + app/boards/shields/hummingbird/hummingbird.overlay | 2 ++ app/boards/shields/iris/iris.dtsi | 1 + app/boards/shields/jian/jian.dtsi | 1 + app/boards/shields/jiran/jiran.dtsi | 1 + app/boards/shields/jorne/jorne.dtsi | 1 + app/boards/shields/knob_goblin/knob_goblin.overlay | 2 ++ app/boards/shields/kyria/kyria_common.dtsi | 1 + app/boards/shields/leeloo/leeloo_common.dtsi | 1 + app/boards/shields/leeloo_micro/leeloo_micro.dtsi | 1 + app/boards/shields/lily58/lily58.dtsi | 1 + app/boards/shields/lotus58/lotus58.dtsi | 1 + app/boards/shields/m60/m60.overlay | 1 + app/boards/shields/microdox/microdox.dtsi | 1 + app/boards/shields/microdox/microdox_v2.dtsi | 1 + app/boards/shields/murphpad/murphpad.overlay | 1 + app/boards/shields/naked60/naked60.overlay | 1 + app/boards/shields/osprette/osprette.overlay | 1 + app/boards/shields/pancake/pancake.overlay | 1 + app/boards/shields/qaz/qaz.overlay | 1 + app/boards/shields/quefrency/quefrency_left.overlay | 2 ++ app/boards/shields/quefrency/quefrency_right.overlay | 2 ++ app/boards/shields/redox/redox.dtsi | 1 + app/boards/shields/reviung34/reviung34.overlay | 2 ++ app/boards/shields/reviung41/reviung41.overlay | 2 ++ app/boards/shields/reviung5/reviung5.overlay | 1 + app/boards/shields/reviung53/reviung53.overlay | 2 ++ app/boards/shields/romac/romac.overlay | 1 + app/boards/shields/romac_plus/romac_plus.overlay | 1 + app/boards/shields/sofle/sofle.dtsi | 1 + .../splitkb_aurora_corne/splitkb_aurora_corne_left.overlay | 2 ++ .../splitkb_aurora_corne/splitkb_aurora_corne_right.overlay | 2 ++ .../splitkb_aurora_helix/splitkb_aurora_helix_left.overlay | 2 ++ .../splitkb_aurora_helix/splitkb_aurora_helix_right.overlay | 2 ++ .../splitkb_aurora_lily58/splitkb_aurora_lily58_left.overlay | 2 ++ .../splitkb_aurora_lily58/splitkb_aurora_lily58_right.overlay | 2 ++ .../splitkb_aurora_sofle/splitkb_aurora_sofle_left.overlay | 2 ++ .../splitkb_aurora_sofle/splitkb_aurora_sofle_right.overlay | 2 ++ .../splitkb_aurora_sweep/splitkb_aurora_sweep_left.overlay | 2 ++ .../splitkb_aurora_sweep/splitkb_aurora_sweep_right.overlay | 1 + app/boards/shields/splitreus62/splitreus62.dtsi | 1 + app/boards/shields/tg4x/tg4x.overlay | 1 + app/boards/shields/two_percent_milk/two_percent_milk.overlay | 1 + app/boards/shields/waterfowl/waterfowl.dtsi | 1 + app/boards/shields/zodiark/zodiark.dtsi | 1 + 73 files changed, 101 insertions(+) diff --git a/app/boards/arm/adv360pro/adv360pro_left.dts b/app/boards/arm/adv360pro/adv360pro_left.dts index 6ef5f590..459a2232 100644 --- a/app/boards/arm/adv360pro/adv360pro_left.dts +++ b/app/boards/arm/adv360pro/adv360pro_left.dts @@ -10,6 +10,7 @@ /{ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/arm/adv360pro/adv360pro_right.dts b/app/boards/arm/adv360pro/adv360pro_right.dts index 97d846f8..748cc42a 100644 --- a/app/boards/arm/adv360pro/adv360pro_right.dts +++ b/app/boards/arm/adv360pro/adv360pro_right.dts @@ -10,6 +10,7 @@ /{ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/arm/bt60/bt60_v1.dts b/app/boards/arm/bt60/bt60_v1.dts index 53d4e77b..315d8cce 100644 --- a/app/boards/arm/bt60/bt60_v1.dts +++ b/app/boards/arm/bt60/bt60_v1.dts @@ -81,6 +81,8 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; col-gpios diff --git a/app/boards/arm/bt60/bt60_v1_hs.dts b/app/boards/arm/bt60/bt60_v1_hs.dts index 57b47554..27e38286 100644 --- a/app/boards/arm/bt60/bt60_v1_hs.dts +++ b/app/boards/arm/bt60/bt60_v1_hs.dts @@ -30,6 +30,8 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; col-gpios diff --git a/app/boards/arm/ckp/ckp.dtsi b/app/boards/arm/ckp/ckp.dtsi index 6bbbbdd7..4142622a 100644 --- a/app/boards/arm/ckp/ckp.dtsi +++ b/app/boards/arm/ckp/ckp.dtsi @@ -34,6 +34,8 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; col-gpios diff --git a/app/boards/arm/corneish_zen/corneish_zen_v1_left.dts b/app/boards/arm/corneish_zen/corneish_zen_v1_left.dts index 6683b1b2..2c77f01c 100644 --- a/app/boards/arm/corneish_zen/corneish_zen_v1_left.dts +++ b/app/boards/arm/corneish_zen/corneish_zen_v1_left.dts @@ -15,6 +15,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/arm/corneish_zen/corneish_zen_v1_right.dts b/app/boards/arm/corneish_zen/corneish_zen_v1_right.dts index 492c79fa..536e46ea 100644 --- a/app/boards/arm/corneish_zen/corneish_zen_v1_right.dts +++ b/app/boards/arm/corneish_zen/corneish_zen_v1_right.dts @@ -15,6 +15,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/arm/corneish_zen/corneish_zen_v2_left.dts b/app/boards/arm/corneish_zen/corneish_zen_v2_left.dts index dacb24c3..42839b61 100644 --- a/app/boards/arm/corneish_zen/corneish_zen_v2_left.dts +++ b/app/boards/arm/corneish_zen/corneish_zen_v2_left.dts @@ -15,6 +15,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/arm/corneish_zen/corneish_zen_v2_right.dts b/app/boards/arm/corneish_zen/corneish_zen_v2_right.dts index f1baea42..b47d122f 100644 --- a/app/boards/arm/corneish_zen/corneish_zen_v2_right.dts +++ b/app/boards/arm/corneish_zen/corneish_zen_v2_right.dts @@ -15,6 +15,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/arm/glove80/glove80.dtsi b/app/boards/arm/glove80/glove80.dtsi index 0078fe62..4803488b 100644 --- a/app/boards/arm/glove80/glove80.dtsi +++ b/app/boards/arm/glove80/glove80.dtsi @@ -34,6 +34,8 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; debounce-press-ms = <4>; debounce-release-ms = <20>; diff --git a/app/boards/arm/nice60/nice60.dts b/app/boards/arm/nice60/nice60.dts index 7397cffa..d1b9f992 100644 --- a/app/boards/arm/nice60/nice60.dts +++ b/app/boards/arm/nice60/nice60.dts @@ -42,6 +42,7 @@ RC(4,0) RC(4,1) RC(4,2) RC(4,5) R kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/arm/s40nc/s40nc.dts b/app/boards/arm/s40nc/s40nc.dts index a04f42e1..a2eb89ea 100644 --- a/app/boards/arm/s40nc/s40nc.dts +++ b/app/boards/arm/s40nc/s40nc.dts @@ -37,6 +37,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/a_dux/a_dux.dtsi b/app/boards/shields/a_dux/a_dux.dtsi index caeae8db..46aa8fda 100644 --- a/app/boards/shields/a_dux/a_dux.dtsi +++ b/app/boards/shields/a_dux/a_dux.dtsi @@ -27,6 +27,8 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-direct"; + wakeup-source; + input-gpios = <&pro_micro 5 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>, <&pro_micro 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>, diff --git a/app/boards/shields/bat43/bat43.overlay b/app/boards/shields/bat43/bat43.overlay index 600dccec..89c2428d 100644 --- a/app/boards/shields/bat43/bat43.overlay +++ b/app/boards/shields/bat43/bat43.overlay @@ -28,6 +28,7 @@ RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(6,0) RC(6,1) RC(6,2) kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/bfo9000/bfo9000.dtsi b/app/boards/shields/bfo9000/bfo9000.dtsi index ea9283ad..11080671 100644 --- a/app/boards/shields/bfo9000/bfo9000.dtsi +++ b/app/boards/shields/bfo9000/bfo9000.dtsi @@ -28,6 +28,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/boardsource3x4/boardsource3x4.overlay b/app/boards/shields/boardsource3x4/boardsource3x4.overlay index 389f5b7a..0d63214d 100644 --- a/app/boards/shields/boardsource3x4/boardsource3x4.overlay +++ b/app/boards/shields/boardsource3x4/boardsource3x4.overlay @@ -13,6 +13,8 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/boardsource5x12/boardsource5x12.overlay b/app/boards/shields/boardsource5x12/boardsource5x12.overlay index 9a721d0c..15ae7b68 100644 --- a/app/boards/shields/boardsource5x12/boardsource5x12.overlay +++ b/app/boards/shields/boardsource5x12/boardsource5x12.overlay @@ -13,6 +13,8 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/chalice/chalice.overlay b/app/boards/shields/chalice/chalice.overlay index 92dfe356..8631d735 100644 --- a/app/boards/shields/chalice/chalice.overlay +++ b/app/boards/shields/chalice/chalice.overlay @@ -44,6 +44,8 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/clog/clog.dtsi b/app/boards/shields/clog/clog.dtsi index feea830c..883aaa29 100644 --- a/app/boards/shields/clog/clog.dtsi +++ b/app/boards/shields/clog/clog.dtsi @@ -26,6 +26,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-direct"; + wakeup-source; input-gpios = <&pro_micro 18 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> diff --git a/app/boards/shields/contra/contra.overlay b/app/boards/shields/contra/contra.overlay index 0ac042d6..45cc3088 100644 --- a/app/boards/shields/contra/contra.overlay +++ b/app/boards/shields/contra/contra.overlay @@ -11,6 +11,8 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/corne/corne.dtsi b/app/boards/shields/corne/corne.dtsi index f6d41e33..e1edcce8 100644 --- a/app/boards/shields/corne/corne.dtsi +++ b/app/boards/shields/corne/corne.dtsi @@ -47,6 +47,7 @@ RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(2,6) RC(2,7) RC(2,8) RC(2,9) RC(2,10 kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/cradio/cradio.dtsi b/app/boards/shields/cradio/cradio.dtsi index 4f8a09d7..b510c636 100644 --- a/app/boards/shields/cradio/cradio.dtsi +++ b/app/boards/shields/cradio/cradio.dtsi @@ -27,6 +27,8 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-direct"; + wakeup-source; + input-gpios = <&pro_micro 7 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> , <&pro_micro 18 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> diff --git a/app/boards/shields/crbn/crbn.overlay b/app/boards/shields/crbn/crbn.overlay index af5910d6..c6a2b87c 100644 --- a/app/boards/shields/crbn/crbn.overlay +++ b/app/boards/shields/crbn/crbn.overlay @@ -13,6 +13,8 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/eek/eek.overlay b/app/boards/shields/eek/eek.overlay index e9e734ac..28aab7ef 100644 --- a/app/boards/shields/eek/eek.overlay +++ b/app/boards/shields/eek/eek.overlay @@ -26,6 +26,8 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/elephant42/elephant42.dtsi b/app/boards/shields/elephant42/elephant42.dtsi index 22a72708..d72aa9a8 100644 --- a/app/boards/shields/elephant42/elephant42.dtsi +++ b/app/boards/shields/elephant42/elephant42.dtsi @@ -26,6 +26,7 @@ RC(1,0) RC(1,1) RC(1,2) RC(1,3) RC(1,4) RC(1,5) RC(1,6) RC(1,7) kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/ergodash/ergodash.dtsi b/app/boards/shields/ergodash/ergodash.dtsi index 2e41ca30..b6ef7fc4 100644 --- a/app/boards/shields/ergodash/ergodash.dtsi +++ b/app/boards/shields/ergodash/ergodash.dtsi @@ -35,6 +35,7 @@ RC(4,0) RC(4,1) RC(4,2) RC(4,3) RC(4,4) RC(4,5) RC(4,6) RC(4,13) RC(4,12 kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; diff --git a/app/boards/shields/eternal_keypad/eternal_keypad.dtsi b/app/boards/shields/eternal_keypad/eternal_keypad.dtsi index 3144f986..1274e3dd 100644 --- a/app/boards/shields/eternal_keypad/eternal_keypad.dtsi +++ b/app/boards/shields/eternal_keypad/eternal_keypad.dtsi @@ -14,6 +14,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; diff --git a/app/boards/shields/fourier/fourier.dtsi b/app/boards/shields/fourier/fourier.dtsi index 3b309b8d..f486e0a4 100644 --- a/app/boards/shields/fourier/fourier.dtsi +++ b/app/boards/shields/fourier/fourier.dtsi @@ -30,6 +30,7 @@ RC(3,0) RC(3,1) RC(3,2) RC(3,3) RC(3,4) /**/ RC(3,6) RC(3,9 kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/helix/helix.dtsi b/app/boards/shields/helix/helix.dtsi index df80f4ca..8566ffc6 100644 --- a/app/boards/shields/helix/helix.dtsi +++ b/app/boards/shields/helix/helix.dtsi @@ -32,6 +32,7 @@ RC(4,0) RC(4,1) RC(4,2) RC(4,3) RC(4,4) RC(4,5) RC(4,6) RC(4,7) RC(4,8) RC(4,9 kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/hummingbird/hummingbird.overlay b/app/boards/shields/hummingbird/hummingbird.overlay index 871728a2..2474d089 100644 --- a/app/boards/shields/hummingbird/hummingbird.overlay +++ b/app/boards/shields/hummingbird/hummingbird.overlay @@ -29,6 +29,8 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "row2col"; col-gpios diff --git a/app/boards/shields/iris/iris.dtsi b/app/boards/shields/iris/iris.dtsi index c979214c..8ddbd359 100644 --- a/app/boards/shields/iris/iris.dtsi +++ b/app/boards/shields/iris/iris.dtsi @@ -32,6 +32,7 @@ RC(3,0) RC(3,1) RC(3,2) RC(3,3) RC(3,4) RC(3,5) RC(4,2) RC(4,9) RC(3,6) RC(3,7) kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/jian/jian.dtsi b/app/boards/shields/jian/jian.dtsi index c5ae1b9e..439bf93c 100644 --- a/app/boards/shields/jian/jian.dtsi +++ b/app/boards/shields/jian/jian.dtsi @@ -62,6 +62,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/jiran/jiran.dtsi b/app/boards/shields/jiran/jiran.dtsi index b6633b65..517cbe5f 100644 --- a/app/boards/shields/jiran/jiran.dtsi +++ b/app/boards/shields/jiran/jiran.dtsi @@ -67,6 +67,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/jorne/jorne.dtsi b/app/boards/shields/jorne/jorne.dtsi index a2d804b9..e7b81e5f 100644 --- a/app/boards/shields/jorne/jorne.dtsi +++ b/app/boards/shields/jorne/jorne.dtsi @@ -63,6 +63,7 @@ RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(2,6) RC(2,7) RC(2,8) RC(2,9) RC(2,10 kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/knob_goblin/knob_goblin.overlay b/app/boards/shields/knob_goblin/knob_goblin.overlay index 49306ddf..c42482db 100644 --- a/app/boards/shields/knob_goblin/knob_goblin.overlay +++ b/app/boards/shields/knob_goblin/knob_goblin.overlay @@ -14,6 +14,8 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/kyria/kyria_common.dtsi b/app/boards/shields/kyria/kyria_common.dtsi index 23058f37..f662fa1c 100644 --- a/app/boards/shields/kyria/kyria_common.dtsi +++ b/app/boards/shields/kyria/kyria_common.dtsi @@ -15,6 +15,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; }; diff --git a/app/boards/shields/leeloo/leeloo_common.dtsi b/app/boards/shields/leeloo/leeloo_common.dtsi index df4f228e..8ae5b064 100644 --- a/app/boards/shields/leeloo/leeloo_common.dtsi +++ b/app/boards/shields/leeloo/leeloo_common.dtsi @@ -32,6 +32,7 @@ RC(3,0) RC(3,1) RC(3,2) RC(3,3) RC(3,4) RC(3,5) RC(4,5) RC(4,6) RC(3,6) RC(3,7) kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; diff --git a/app/boards/shields/leeloo_micro/leeloo_micro.dtsi b/app/boards/shields/leeloo_micro/leeloo_micro.dtsi index bc314205..f2339653 100644 --- a/app/boards/shields/leeloo_micro/leeloo_micro.dtsi +++ b/app/boards/shields/leeloo_micro/leeloo_micro.dtsi @@ -31,6 +31,7 @@ RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(3,4) RC(3,5) RC(2,5) RC(2,6) RC(2,7) kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; diff --git a/app/boards/shields/lily58/lily58.dtsi b/app/boards/shields/lily58/lily58.dtsi index 1a326d62..c82b197c 100644 --- a/app/boards/shields/lily58/lily58.dtsi +++ b/app/boards/shields/lily58/lily58.dtsi @@ -33,6 +33,7 @@ RC(3,0) RC(3,1) RC(3,2) RC(3,3) RC(3,4) RC(3,5) RC(4,5) RC(4,6) RC(3,6) RC(3,7) kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/lotus58/lotus58.dtsi b/app/boards/shields/lotus58/lotus58.dtsi index afa311d9..e4595930 100644 --- a/app/boards/shields/lotus58/lotus58.dtsi +++ b/app/boards/shields/lotus58/lotus58.dtsi @@ -33,6 +33,7 @@ RC(3,0) RC(3,1) RC(3,2) RC(3,3) RC(3,4) RC(3,5) RC(4,5) RC(4,6) RC(3,6) RC(3,7 kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/m60/m60.overlay b/app/boards/shields/m60/m60.overlay index 22eed44f..c479233c 100644 --- a/app/boards/shields/m60/m60.overlay +++ b/app/boards/shields/m60/m60.overlay @@ -14,6 +14,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/microdox/microdox.dtsi b/app/boards/shields/microdox/microdox.dtsi index 4869cfea..65c670f0 100644 --- a/app/boards/shields/microdox/microdox.dtsi +++ b/app/boards/shields/microdox/microdox.dtsi @@ -9,6 +9,7 @@ / { kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios = <&pro_micro 16 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)> diff --git a/app/boards/shields/microdox/microdox_v2.dtsi b/app/boards/shields/microdox/microdox_v2.dtsi index 6eb7efa5..95aaf79d 100644 --- a/app/boards/shields/microdox/microdox_v2.dtsi +++ b/app/boards/shields/microdox/microdox_v2.dtsi @@ -9,6 +9,7 @@ / { kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; }; }; diff --git a/app/boards/shields/murphpad/murphpad.overlay b/app/boards/shields/murphpad/murphpad.overlay index a8234968..e2c9117f 100644 --- a/app/boards/shields/murphpad/murphpad.overlay +++ b/app/boards/shields/murphpad/murphpad.overlay @@ -14,6 +14,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/naked60/naked60.overlay b/app/boards/shields/naked60/naked60.overlay index 843c867f..4e36bc76 100644 --- a/app/boards/shields/naked60/naked60.overlay +++ b/app/boards/shields/naked60/naked60.overlay @@ -11,6 +11,7 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/osprette/osprette.overlay b/app/boards/shields/osprette/osprette.overlay index af2e5625..ed893f47 100644 --- a/app/boards/shields/osprette/osprette.overlay +++ b/app/boards/shields/osprette/osprette.overlay @@ -26,6 +26,7 @@ RC(0,0) RC(1,0) RC(1,1) RC(1,2) RC(1,3) RC(1,4) RC(1,5) RC(1,6) RC(1,7) RC(1,8) kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "row2col"; col-gpios diff --git a/app/boards/shields/pancake/pancake.overlay b/app/boards/shields/pancake/pancake.overlay index 0ceb2d5c..0538bf71 100644 --- a/app/boards/shields/pancake/pancake.overlay +++ b/app/boards/shields/pancake/pancake.overlay @@ -11,6 +11,7 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/qaz/qaz.overlay b/app/boards/shields/qaz/qaz.overlay index d0ec5b3a..5c76b98f 100644 --- a/app/boards/shields/qaz/qaz.overlay +++ b/app/boards/shields/qaz/qaz.overlay @@ -27,6 +27,7 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/quefrency/quefrency_left.overlay b/app/boards/shields/quefrency/quefrency_left.overlay index cf795841..a40d47c1 100644 --- a/app/boards/shields/quefrency/quefrency_left.overlay +++ b/app/boards/shields/quefrency/quefrency_left.overlay @@ -12,6 +12,8 @@ */ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; diff --git a/app/boards/shields/quefrency/quefrency_right.overlay b/app/boards/shields/quefrency/quefrency_right.overlay index 446a614a..ebb9f844 100644 --- a/app/boards/shields/quefrency/quefrency_right.overlay +++ b/app/boards/shields/quefrency/quefrency_right.overlay @@ -17,6 +17,8 @@ */ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; diff --git a/app/boards/shields/redox/redox.dtsi b/app/boards/shields/redox/redox.dtsi index 505a5c69..098be434 100644 --- a/app/boards/shields/redox/redox.dtsi +++ b/app/boards/shields/redox/redox.dtsi @@ -32,6 +32,7 @@ RC(4,0) RC(4,1) RC(4,2) RC(4,3) RC(4,4) RC(4,5) RC(4,6) RC(4,7) RC(4,8) kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/reviung34/reviung34.overlay b/app/boards/shields/reviung34/reviung34.overlay index 6ec9813d..0f58b99d 100644 --- a/app/boards/shields/reviung34/reviung34.overlay +++ b/app/boards/shields/reviung34/reviung34.overlay @@ -38,6 +38,8 @@ RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(2,6) RC(2,7) RC(2,8) RC(3,7) kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/reviung41/reviung41.overlay b/app/boards/shields/reviung41/reviung41.overlay index 079fd36b..f8503fc3 100644 --- a/app/boards/shields/reviung41/reviung41.overlay +++ b/app/boards/shields/reviung41/reviung41.overlay @@ -27,6 +27,8 @@ RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(5,0) RC(5,1) RC(5,2) RC(5,3) kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/reviung5/reviung5.overlay b/app/boards/shields/reviung5/reviung5.overlay index 0382145c..0abd3a06 100644 --- a/app/boards/shields/reviung5/reviung5.overlay +++ b/app/boards/shields/reviung5/reviung5.overlay @@ -22,6 +22,7 @@ kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/reviung53/reviung53.overlay b/app/boards/shields/reviung53/reviung53.overlay index d6037aec..fa784478 100644 --- a/app/boards/shields/reviung53/reviung53.overlay +++ b/app/boards/shields/reviung53/reviung53.overlay @@ -28,6 +28,8 @@ RC(6,0) RC(6,1) RC(6,2) RC(6,3) RC(6,4) RC(6,5) kscan0: kscan_0 { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; col-gpios diff --git a/app/boards/shields/romac/romac.overlay b/app/boards/shields/romac/romac.overlay index 3d99e51b..8c11a8ac 100644 --- a/app/boards/shields/romac/romac.overlay +++ b/app/boards/shields/romac/romac.overlay @@ -13,6 +13,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/romac_plus/romac_plus.overlay b/app/boards/shields/romac_plus/romac_plus.overlay index 229b4a2c..39e123c0 100644 --- a/app/boards/shields/romac_plus/romac_plus.overlay +++ b/app/boards/shields/romac_plus/romac_plus.overlay @@ -13,6 +13,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; diff --git a/app/boards/shields/sofle/sofle.dtsi b/app/boards/shields/sofle/sofle.dtsi index f88339d7..ef89e4a5 100644 --- a/app/boards/shields/sofle/sofle.dtsi +++ b/app/boards/shields/sofle/sofle.dtsi @@ -33,6 +33,7 @@ RC(3,0) RC(3,1) RC(3,2) RC(3,3) RC(3,4) RC(3,5) RC(4,5) RC(4,6) RC(3,6) RC(3,7) kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/splitkb_aurora_corne/splitkb_aurora_corne_left.overlay b/app/boards/shields/splitkb_aurora_corne/splitkb_aurora_corne_left.overlay index df930cd2..ec40a016 100644 --- a/app/boards/shields/splitkb_aurora_corne/splitkb_aurora_corne_left.overlay +++ b/app/boards/shields/splitkb_aurora_corne/splitkb_aurora_corne_left.overlay @@ -13,6 +13,8 @@ kscan: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/splitkb_aurora_corne/splitkb_aurora_corne_right.overlay b/app/boards/shields/splitkb_aurora_corne/splitkb_aurora_corne_right.overlay index 3823cdfb..7341f072 100644 --- a/app/boards/shields/splitkb_aurora_corne/splitkb_aurora_corne_right.overlay +++ b/app/boards/shields/splitkb_aurora_corne/splitkb_aurora_corne_right.overlay @@ -13,6 +13,8 @@ kscan: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/splitkb_aurora_helix/splitkb_aurora_helix_left.overlay b/app/boards/shields/splitkb_aurora_helix/splitkb_aurora_helix_left.overlay index 59d82553..61b663e6 100644 --- a/app/boards/shields/splitkb_aurora_helix/splitkb_aurora_helix_left.overlay +++ b/app/boards/shields/splitkb_aurora_helix/splitkb_aurora_helix_left.overlay @@ -13,6 +13,8 @@ kscan: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/splitkb_aurora_helix/splitkb_aurora_helix_right.overlay b/app/boards/shields/splitkb_aurora_helix/splitkb_aurora_helix_right.overlay index 95cea9ec..5aee19bd 100644 --- a/app/boards/shields/splitkb_aurora_helix/splitkb_aurora_helix_right.overlay +++ b/app/boards/shields/splitkb_aurora_helix/splitkb_aurora_helix_right.overlay @@ -13,6 +13,8 @@ kscan: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_left.overlay b/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_left.overlay index fc38bbcb..8d56890f 100644 --- a/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_left.overlay +++ b/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_left.overlay @@ -13,6 +13,8 @@ kscan: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "row2col"; row-gpios diff --git a/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_right.overlay b/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_right.overlay index c9a96491..6b719020 100644 --- a/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_right.overlay +++ b/app/boards/shields/splitkb_aurora_lily58/splitkb_aurora_lily58_right.overlay @@ -13,6 +13,8 @@ kscan: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "row2col"; row-gpios diff --git a/app/boards/shields/splitkb_aurora_sofle/splitkb_aurora_sofle_left.overlay b/app/boards/shields/splitkb_aurora_sofle/splitkb_aurora_sofle_left.overlay index 024c9e75..2a3f485d 100644 --- a/app/boards/shields/splitkb_aurora_sofle/splitkb_aurora_sofle_left.overlay +++ b/app/boards/shields/splitkb_aurora_sofle/splitkb_aurora_sofle_left.overlay @@ -13,6 +13,8 @@ kscan: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/splitkb_aurora_sofle/splitkb_aurora_sofle_right.overlay b/app/boards/shields/splitkb_aurora_sofle/splitkb_aurora_sofle_right.overlay index 58df0026..6eb0d113 100644 --- a/app/boards/shields/splitkb_aurora_sofle/splitkb_aurora_sofle_right.overlay +++ b/app/boards/shields/splitkb_aurora_sofle/splitkb_aurora_sofle_right.overlay @@ -13,6 +13,8 @@ kscan: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/splitkb_aurora_sweep/splitkb_aurora_sweep_left.overlay b/app/boards/shields/splitkb_aurora_sweep/splitkb_aurora_sweep_left.overlay index 4a1bec90..9c1fd975 100644 --- a/app/boards/shields/splitkb_aurora_sweep/splitkb_aurora_sweep_left.overlay +++ b/app/boards/shields/splitkb_aurora_sweep/splitkb_aurora_sweep_left.overlay @@ -13,6 +13,8 @@ kscan: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; + diode-direction = "row2col"; row-gpios diff --git a/app/boards/shields/splitkb_aurora_sweep/splitkb_aurora_sweep_right.overlay b/app/boards/shields/splitkb_aurora_sweep/splitkb_aurora_sweep_right.overlay index c3655477..b280b42d 100644 --- a/app/boards/shields/splitkb_aurora_sweep/splitkb_aurora_sweep_right.overlay +++ b/app/boards/shields/splitkb_aurora_sweep/splitkb_aurora_sweep_right.overlay @@ -13,6 +13,7 @@ kscan: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "row2col"; row-gpios diff --git a/app/boards/shields/splitreus62/splitreus62.dtsi b/app/boards/shields/splitreus62/splitreus62.dtsi index d80f8731..1a4f3af1 100644 --- a/app/boards/shields/splitreus62/splitreus62.dtsi +++ b/app/boards/shields/splitreus62/splitreus62.dtsi @@ -34,6 +34,7 @@ RC(4,0) RC(4,1) RC(4,2) RC(4,3) RC(4,4) RC(4,5) RC(4,6) RC(4,7) kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "row2col"; row-gpios diff --git a/app/boards/shields/tg4x/tg4x.overlay b/app/boards/shields/tg4x/tg4x.overlay index 07a0635d..ac05e810 100644 --- a/app/boards/shields/tg4x/tg4x.overlay +++ b/app/boards/shields/tg4x/tg4x.overlay @@ -9,6 +9,7 @@ / { kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; diff --git a/app/boards/shields/two_percent_milk/two_percent_milk.overlay b/app/boards/shields/two_percent_milk/two_percent_milk.overlay index 474150ef..7647f551 100644 --- a/app/boards/shields/two_percent_milk/two_percent_milk.overlay +++ b/app/boards/shields/two_percent_milk/two_percent_milk.overlay @@ -11,6 +11,7 @@ kscan0: kscan { compatible = "zmk,kscan-gpio-direct"; + wakeup-source; input-gpios = <&pro_micro 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)> diff --git a/app/boards/shields/waterfowl/waterfowl.dtsi b/app/boards/shields/waterfowl/waterfowl.dtsi index d46910a3..2329ca78 100644 --- a/app/boards/shields/waterfowl/waterfowl.dtsi +++ b/app/boards/shields/waterfowl/waterfowl.dtsi @@ -31,6 +31,7 @@ RC(3,0) RC(3,1) RC(3,2) RC(3,3) RC(3,4) RC(3,5) kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios diff --git a/app/boards/shields/zodiark/zodiark.dtsi b/app/boards/shields/zodiark/zodiark.dtsi index 3151f31c..aa68e20d 100644 --- a/app/boards/shields/zodiark/zodiark.dtsi +++ b/app/boards/shields/zodiark/zodiark.dtsi @@ -33,6 +33,7 @@ RC(4,0) RC(4,1) RC(4,2) RC(4,3) RC(4,4) RC(4,5) RC(4,6) RC(4,7) R kscan0: kscan { compatible = "zmk,kscan-gpio-matrix"; + wakeup-source; diode-direction = "col2row"; row-gpios From 4bef4e98f52c3ea57630a3cd1e0e2d078d67758b Mon Sep 17 00:00:00 2001 From: zhiayang <500236+zhiayang@users.noreply.github.com> Date: Sat, 30 Mar 2024 19:12:37 -0400 Subject: [PATCH 41/45] feat(boards): Support board revisions in setup scripts. * Make setup.sh/ps1 prompt for board revision for boards that have revisions --- docs/src/templates/setup.ps1.mustache | 29 ++++++++++++++++++++++ docs/src/templates/setup.sh.mustache | 35 +++++++++++++++++++++++++++ schema/hardware-metadata.schema.json | 15 +++++++++++- 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/docs/src/templates/setup.ps1.mustache b/docs/src/templates/setup.ps1.mustache index 90f9cdcf..b8ecc293 100644 --- a/docs/src/templates/setup.ps1.mustache +++ b/docs/src/templates/setup.ps1.mustache @@ -131,6 +131,19 @@ if ($keyboard_type -eq "shield") { {{/boards}} } + $boards_revisions = [ordered]@{ + {{#boards}} + {{id}} = @({{#revisions}} + "{{.}}"{{/revisions}}); + {{/boards}} + } + + $boards_default_revision=[ordered]@{ + {{#boards}} + {{id}} = "{{{default_revision}}}"; + {{/boards}} + } + Write-Host "$title" Write-Host "" Write-Host "MCU Board Selection:" @@ -145,6 +158,22 @@ if ($keyboard_type -eq "shield") { $shields = $keyboard_siblings $board = $($($boards.keys)[$choice]) $boards = ( $board ) + + if ($($($boards_revisions.values)[$choice]).count -gt 0) { + $valid_revisions = $($($boards_revisions.values)[$choice]) + $revision_choices = @() + $valid_revisions + + for ($i = 0; $i -lt $valid_revisions.count; $i += 1) { + if ($valid_revisions[$i] -eq $($($boards_default_revision.values)[$choice])) { + $revision_choices[$i] += " (default)" + } + } + + $revision_choice = Get-Choice-From-Options -Options $revision_choices -Prompt $prompt + $board = $board + "@" + $valid_revisions[$revision_choice] + $boards = ( $board ) + } + } else { $boards = ( $keyboard_siblings ) $shields = @( ) diff --git a/docs/src/templates/setup.sh.mustache b/docs/src/templates/setup.sh.mustache index c711dbc5..dd7a7a2d 100644 --- a/docs/src/templates/setup.sh.mustache +++ b/docs/src/templates/setup.sh.mustache @@ -122,6 +122,9 @@ if [ "$keyboard_shield" == "y" ]; then board_ids=({{#boards}}"{{id}}" {{/boards}}) boards_usb_only=({{#boards}}"{{#usb_only}}y{{/usb_only}}{{^usb_only}}n{{/usb_only}}" {{/boards}}) + boards_revisions=({{#boards}}"{{#revisions}}{{.}} {{/revisions}}" {{/boards}}) + boards_default_revision=({{#boards}}"{{{default_revision}}}" {{/boards}}) + echo "" echo "MCU Board Selection:" PS3="$prompt " @@ -151,6 +154,38 @@ if [ "$keyboard_shield" == "y" ]; then esac done + + if [ -n "${boards_revisions[$board_index]}" ]; then + read -a _valid_revisions <<< "${boards_revisions[$board_index]}" + + _rev_choices=("${_valid_revisions[@]}") + for (( _i=0; _i<${#_valid_revisions}; _i++ )); do + if [ "${boards_default_revision[board_index]}" = "${_valid_revisions[_i]}" ]; then + _rev_choices[_i]+=" (default)" + fi + done + + echo "" + echo "MCU Board Revision:" + select opt in "${_rev_choices[@]}" "Quit"; do + case "$REPLY" in + ''|*[!0-9]*) echo "Invalid option. Try another one."; continue;; + + $(( ${#_valid_revisions[@]}+1 )) ) echo "Goodbye!"; exit 1;; + *) + if [ $REPLY -gt $(( ${#_valid_revisions[@]}+1 )) ] || [ $REPLY -lt 0 ]; then + echo "Invalid option. Try another one." + continue + fi + + _rev_index=$(( $REPLY-1 )) + board="${board_ids[$board_index]}@${_valid_revisions[_rev_index]}" + boards=( "${board}" ) + break + ;; + esac + done + fi else board=${keyboard} boards=$keyboard_siblings diff --git a/schema/hardware-metadata.schema.json b/schema/hardware-metadata.schema.json index 4c2bdf3b..9710c792 100644 --- a/schema/hardware-metadata.schema.json +++ b/schema/hardware-metadata.schema.json @@ -16,7 +16,11 @@ "$defs": { "id": { "type": "string", - "pattern": "^[a-z0-9_]+$" + "pattern": "^[a-z0-9_]+(@([A-Z]|[0-9]+|([0-9]+(\\.[0-9]+){1,2})))?$" + }, + "revision": { + "type": "string", + "pattern": "[A-Z]|[0-9]+|([0-9]+(\\.[0-9]+){1,2})" }, "keyboard_siblings": { "type": "array", @@ -202,6 +206,15 @@ }, "exposes": { "$ref": "#/$defs/interconnects" + }, + "revisions": { + "type": "array", + "items": { + "$ref": "#/$defs/revision" + } + }, + "default_revision": { + "$ref": "#/$defs/revision" } } }, From e65a1227d8cddc2edc2e5da2276f992d8a91ed49 Mon Sep 17 00:00:00 2001 From: Cem Aksoylar Date: Fri, 29 Mar 2024 14:41:18 -0700 Subject: [PATCH 42/45] fix(docs): Correct property types for behavior bindings --- docs/docs/config/behaviors.md | 52 +++++++++++++++++------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/docs/docs/config/behaviors.md b/docs/docs/config/behaviors.md index 1a5b899a..06e87850 100644 --- a/docs/docs/config/behaviors.md +++ b/docs/docs/config/behaviors.md @@ -57,18 +57,18 @@ Definition file: [zmk/app/dts/bindings/behaviors/zmk,behavior-hold-tap.yaml](htt Applies to: `compatible = "zmk,behavior-hold-tap"` -| Property | Type | Description | Default | -| ----------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------- | ------------------ | -| `#binding-cells` | int | Must be `<2>` | | -| `bindings` | phandle array | A list of two behaviors (without parameters): one for hold and one for tap | | -| `flavor` | string | Adjusts how the behavior chooses between hold and tap | `"hold-preferred"` | -| `tapping-term-ms` | int | How long in milliseconds the key must be held to trigger a hold | | -| `quick-tap-ms` | int | Tap twice within this period (in milliseconds) to trigger a tap, even when held | -1 (disabled) | -| `require-prior-idle-ms` | int | Triggers a tap immediately if any non-modifier key was pressed within `require-prior-idle-ms` of the hold-tap. | -1 (disabled) | -| `retro-tap` | bool | Triggers the tap behavior on release if no other key was pressed during a hold | false | -| `hold-while-undecided` | bool | Triggers the hold behavior immediately on press and releases before a tap | false | -| `hold-while-undecided-linger` | bool | Continues to hold the hold behavior until after the tap is released | false | -| `hold-trigger-key-positions` | array | If set, pressing the hold-tap and then any key position _not_ in the list triggers a tap. | | +| Property | Type | Description | Default | +| ----------------------------- | -------- | -------------------------------------------------------------------------------------------------------------- | ------------------ | +| `#binding-cells` | int | Must be `<2>` | | +| `bindings` | phandles | A list of two behaviors (without parameters): one for hold and one for tap | | +| `flavor` | string | Adjusts how the behavior chooses between hold and tap | `"hold-preferred"` | +| `tapping-term-ms` | int | How long in milliseconds the key must be held to trigger a hold | | +| `quick-tap-ms` | int | Tap twice within this period (in milliseconds) to trigger a tap, even when held | -1 (disabled) | +| `require-prior-idle-ms` | int | Triggers a tap immediately if any non-modifier key was pressed within `require-prior-idle-ms` of the hold-tap. | -1 (disabled) | +| `retro-tap` | bool | Triggers the tap behavior on release if no other key was pressed during a hold | false | +| `hold-while-undecided` | bool | Triggers the hold behavior immediately on press and releases before a tap | false | +| `hold-while-undecided-linger` | bool | Continues to hold the hold behavior until after the tap is released | false | +| `hold-trigger-key-positions` | array | If set, pressing the hold-tap and then any key position _not_ in the list triggers a tap. | | This behavior forwards the first parameter it receives to the parameter of the first behavior specified in `bindings`, and second parameter to the parameter of the second behavior. @@ -203,12 +203,12 @@ Definition files: - [zmk/app/dts/bindings/behaviors/zmk,behavior-sensor-rotate.yaml](https://github.com/zmkfirmware/zmk/blob/main/app/dts/bindings/behaviors/zmk%2Cbehavior-sensor-rotate.yaml) - [zmk/app/dts/bindings/behaviors/zmk,behavior-sensor-rotate-var.yaml](https://github.com/zmkfirmware/zmk/blob/main/app/dts/bindings/behaviors/zmk%2Cbehavior-sensor-rotate-var.yaml) -| Property | Type | Description | Default | -| ----------------------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -| `compatible` | string | Sensor rotation type, **must be _one_ of**:
  • `"zmk,behavior-sensor-rotate"`
  • `"zmk,behavior-sensor-rotate-var"`
| | -| `#sensor-binding-cells` | int | Must be
  • `<0>` if `compatible = "zmk,behavior-sensor-rotate"`
  • `<2>` if `compatible = "zmk,behavior-sensor-rotate-var"`
| | -| `bindings` | phandle array | A list of two behaviors to trigger for each rotation direction, must include parameters for `"zmk,behavior-sensor-rotate"` and exclude them for `"zmk,behavior-sensor-rotate-var"` | | -| `tap-ms` | int | The tap duration (between press and release events) in milliseconds for behaviors in `bindings` | 5 | +| Property | Type | Description | Default | +| ----------------------- | ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | +| `compatible` | string | Sensor rotation type, **must be _one_ of**:
  • `"zmk,behavior-sensor-rotate"`
  • `"zmk,behavior-sensor-rotate-var"`
| | +| `#sensor-binding-cells` | int | Must be
  • `<0>` if `compatible = "zmk,behavior-sensor-rotate"`
  • `<2>` if `compatible = "zmk,behavior-sensor-rotate-var"`
| | +| `bindings` | phandles for `"zmk,behavior-sensor-rotate"`, phandle array for `"zmk,behavior-sensor-rotate-var"` | A list of two behaviors to trigger for each rotation direction, must include parameters for `"zmk,behavior-sensor-rotate"` and exclude them for `"zmk,behavior-sensor-rotate-var"` | | +| `tap-ms` | int | The tap duration (between press and release events) in milliseconds for behaviors in `bindings` | 5 | With `compatible = "zmk,behavior-sensor-rotate-var"`, this behavior forwards the first parameter it receives to the parameter of the first behavior specified in `bindings`, and second parameter to the parameter of the second behavior. @@ -224,14 +224,14 @@ Definition file: [zmk/app/dts/bindings/behaviors/zmk,behavior-sticky-key.yaml](h Applies to: `compatible = "zmk,behavior-sticky-key"` -| Property | Type | Description | Default | -| ------------------ | ------------- | ------------------------------------------------------------------------ | ------- | -| `#binding-cells` | int | Must be `<1>` | | -| `bindings` | phandle array | A behavior (without parameters) to trigger | | -| `release-after-ms` | int | Releases the key after this many milliseconds if no other key is pressed | 1000 | -| `quick-release` | bool | Release the sticky key on the next key press instead of release | false | -| `lazy` | bool | Wait until the next key press to activate the sticky key behavior | false | -| `ignore-modifiers` | bool | If enabled, pressing a modifier key does not cancel the sticky key | true | +| Property | Type | Description | Default | +| ------------------ | -------- | ------------------------------------------------------------------------ | ------- | +| `#binding-cells` | int | Must be `<1>` | | +| `bindings` | phandles | A behavior (without parameters) to trigger | | +| `release-after-ms` | int | Releases the key after this many milliseconds if no other key is pressed | 1000 | +| `quick-release` | bool | Release the sticky key on the next key press instead of release | false | +| `lazy` | bool | Wait until the next key press to activate the sticky key behavior | false | +| `ignore-modifiers` | bool | If enabled, pressing a modifier key does not cancel the sticky key | true | This behavior forwards the one parameter it receives to the parameter of the behavior specified in `bindings`. From eb5a6fcfe19b32df13488d2ec751f90cb9fa3362 Mon Sep 17 00:00:00 2001 From: Cem Aksoylar Date: Fri, 29 Mar 2024 14:44:00 -0700 Subject: [PATCH 43/45] refactor(docs): Split DT props table for sensor rotate variants --- docs/docs/config/behaviors.md | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/docs/config/behaviors.md b/docs/docs/config/behaviors.md index 06e87850..28abdf27 100644 --- a/docs/docs/config/behaviors.md +++ b/docs/docs/config/behaviors.md @@ -203,12 +203,21 @@ Definition files: - [zmk/app/dts/bindings/behaviors/zmk,behavior-sensor-rotate.yaml](https://github.com/zmkfirmware/zmk/blob/main/app/dts/bindings/behaviors/zmk%2Cbehavior-sensor-rotate.yaml) - [zmk/app/dts/bindings/behaviors/zmk,behavior-sensor-rotate-var.yaml](https://github.com/zmkfirmware/zmk/blob/main/app/dts/bindings/behaviors/zmk%2Cbehavior-sensor-rotate-var.yaml) -| Property | Type | Description | Default | -| ----------------------- | ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -| `compatible` | string | Sensor rotation type, **must be _one_ of**:
  • `"zmk,behavior-sensor-rotate"`
  • `"zmk,behavior-sensor-rotate-var"`
| | -| `#sensor-binding-cells` | int | Must be
  • `<0>` if `compatible = "zmk,behavior-sensor-rotate"`
  • `<2>` if `compatible = "zmk,behavior-sensor-rotate-var"`
| | -| `bindings` | phandles for `"zmk,behavior-sensor-rotate"`, phandle array for `"zmk,behavior-sensor-rotate-var"` | A list of two behaviors to trigger for each rotation direction, must include parameters for `"zmk,behavior-sensor-rotate"` and exclude them for `"zmk,behavior-sensor-rotate-var"` | | -| `tap-ms` | int | The tap duration (between press and release events) in milliseconds for behaviors in `bindings` | 5 | +Applies to: `compatible = "zmk,behavior-sensor-rotate"` + +| Property | Type | Description | Default | +| ----------------------- | -------- | ------------------------------------------------------------------------------------------------------ | ------- | +| `#sensor-binding-cells` | int | Must be `<0>` | | +| `bindings` | phandles | A list of two behaviors to trigger for each rotation direction, must _include_ any behavior parameters | | +| `tap-ms` | int | The tap duration (between press and release events) in milliseconds for behaviors in `bindings` | 5 | + +Applies to: `compatible = "zmk,behavior-sensor-rotate-var"` + +| Property | Type | Description | Default | +| ----------------------- | ------------- | ------------------------------------------------------------------------------------------------------ | ------- | +| `#sensor-binding-cells` | int | Must be `<2>` | | +| `bindings` | phandle array | A list of two behaviors to trigger for each rotation direction, must _exclude_ any behavior parameters | | +| `tap-ms` | int | The tap duration (between press and release events) in milliseconds for behaviors in `bindings` | 5 | With `compatible = "zmk,behavior-sensor-rotate-var"`, this behavior forwards the first parameter it receives to the parameter of the first behavior specified in `bindings`, and second parameter to the parameter of the second behavior. From e7d6519534231525e6173635061ab8e8bda5a997 Mon Sep 17 00:00:00 2001 From: Tobias Arndt Date: Sat, 30 Mar 2024 18:24:11 -0700 Subject: [PATCH 44/45] fix(docs): Fix and note GPIO flags for charlieplex config --- docs/docs/config/kscan.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/docs/config/kscan.md b/docs/docs/config/kscan.md index 3aa1b378..e6e8bb62 100644 --- a/docs/docs/config/kscan.md +++ b/docs/docs/config/kscan.md @@ -187,6 +187,8 @@ Define the transform with a [matrix transform](#matrix-transform). The row is al For example, in `RC(5,0)` power flows from the 6th pin in `gpios` to the 1st pin in `gpios`. Exclude all positions where the row and column are the same as these pairs will never be triggered, since no pin can be both input and output at the same time. +The [GPIO flags](https://docs.zephyrproject.org/3.5.0/hardware/peripherals/gpio.html#api-reference) for the elements in `gpios` should be `GPIO_ACTIVE_HIGH`, and interrupt pins set in `interrupt-gpios` should have the flags `(GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)`. + ## Composite Driver Keyboard scan driver which combines multiple other keyboard scan drivers. @@ -460,11 +462,11 @@ Note that the entire addressable space does not need to be mapped. interrupt-gpios = <&pro_micro 21 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN) >; gpios - = <&pro_micro 16 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN) > - , <&pro_micro 17 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN) > - , <&pro_micro 18 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN) > - , <&pro_micro 19 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN) > - , <&pro_micro 20 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN) > + = <&pro_micro 16 GPIO_ACTIVE_HIGH> + , <&pro_micro 17 GPIO_ACTIVE_HIGH> + , <&pro_micro 18 GPIO_ACTIVE_HIGH> + , <&pro_micro 19 GPIO_ACTIVE_HIGH> + , <&pro_micro 20 GPIO_ACTIVE_HIGH> ; // addressable space is 5x5, (minus paired values) }; From fe509c466f818471c677b069094d1e84e33ccf2e Mon Sep 17 00:00:00 2001 From: Tobias Arndt Date: Sat, 30 Mar 2024 18:24:51 -0700 Subject: [PATCH 45/45] fix(kscan): Enable charlieplex interrupts for single compatible device Fixes #2201 --- app/module/drivers/kscan/kscan_gpio_charlieplex.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/app/module/drivers/kscan/kscan_gpio_charlieplex.c b/app/module/drivers/kscan/kscan_gpio_charlieplex.c index a4867aa3..3ecbcd6a 100644 --- a/app/module/drivers/kscan/kscan_gpio_charlieplex.c +++ b/app/module/drivers/kscan/kscan_gpio_charlieplex.c @@ -47,14 +47,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #define USES_POLLING DT_INST_FOREACH_STATUS_OKAY(WITHOUT_INTR) > 0 #define USES_INTERRUPT DT_INST_FOREACH_STATUS_OKAY(WITH_INTR) > 0 -#if USES_POLLING && USES_INTERRUPT -#define USES_POLL_AND_INTR 1 -#else -#define USES_POLL_AND_INTR 0 -#endif - #define COND_ANY_POLLING(code) COND_CODE_1(USES_POLLING, code, ()) -#define COND_POLL_AND_INTR(code) COND_CODE_1(USES_POLL_AND_INTR, code, ()) #define COND_THIS_INTERRUPT(n, code) COND_CODE_1(INST_INTR_DEFINED(n), code, ()) #define KSCAN_INTR_CFG_INIT(inst_idx) GPIO_DT_SPEC_GET(DT_DRV_INST(inst_idx), interrupt_gpios) @@ -410,7 +403,7 @@ static const struct kscan_driver_api kscan_charlieplex_api = { }, \ .debounce_scan_period_ms = DT_INST_PROP(n, debounce_scan_period_ms), \ COND_ANY_POLLING((.poll_period_ms = DT_INST_PROP(n, poll_period_ms), )) \ - COND_POLL_AND_INTR((.use_interrupt = INST_INTR_DEFINED(n), )) \ + COND_THIS_INTERRUPT(n, (.use_interrupt = INST_INTR_DEFINED(n), )) \ COND_THIS_INTERRUPT(n, (.interrupt = KSCAN_INTR_CFG_INIT(n), ))}; \ \ DEVICE_DT_INST_DEFINE(n, &kscan_charlieplex_init, NULL, &kscan_charlieplex_data_##n, \