Commit Graph

245 Commits

Author SHA1 Message Date
Tobias Adolph 342d838913
fix(ble,hid): Fix smooth scrolling over BLE (#2998)
- Use correct MIN16 value in hid report. -32768 in 2's compliment is 8000(hex)
- Initialize resolution multiplier array
- Properly implement `read_hids_mouse_feature_report`

Fixes: #2957

Co-authored-by: Tobias Adolph <43353209+adolto@users.noreply.github.comgit>
2025-07-20 09:13:18 -06:00
snoyer fe91cc6625
refactor(ble): add functions to check if profile is open/connected by address (#2993)
Helper functions for BLE profile statuses.
2025-07-19 07:51:53 -06:00
snoyer 9e905d6593
feat(ble): Add function to get profile address by index (#2992) 2025-07-09 20:25:11 -06:00
Pete Johanson 6b44d33db2
feat(split): Runtime selection of split transport (#2886)
feat(split): Runtime selection of split transport

Allow building multiple split transports, and select an active
one based on the transport availability. Wired split availability
depends on additional `detect-gpios` which must be a GPIO pin
that goes active when a wired connection is present.

feat(split): Suspend/resume wired UART devices.

To better support runtime split support, suspend/resume the UART
as necessary to save power when not using the UART.

docs(split): Document adjusting nRF52 UART interrupt priorities

For wired split on nRF52, you may need to adjust the priority for UART
interrupts lower, to ensure the interrupts used for timing sensitive
BT operations can run when needed, so document this in our pinctrl docs.

refactor(split): Restore use of aync UART on nRF52.

With fixes for Zephyr UART driver, re-enable using async API on nRF52.

fix(split): Minor wired split fixes.

Various minor fixes for wired split to avoid spurious TX in half duplex,
etc.

fix: Unconditionally define HID payloads to avoid error.

Don't conditionally define HID indicator payload, to avoid compilation
errors.

docs(split): Expand on details of split transports.

Expand the split keyboard documentation with a more fleshed out section
on the available split trasnports, and what is and isn't supported by
each, including the runtime selection functionality.

---------

Co-authored-by: Nicolas Munnich <98408764+nmunnich@users.noreply.github.com>
2025-06-16 03:45:25 -04:00
Tobias Adolph 2c0e7daced
fix(hid): Fix scroll value truncation (#2865)
Fix 8 bit truncation of 16 bit scroll values when passed into
functions `zmk_hid_mouse_scroll_set` and
`zmk_hid_mouse_scroll_update`.

Fixes: #2864

Co-authored-by: Tobias Adolph <43353209+adolto@users.noreply.github.comgit>
2025-04-20 04:28:51 -04:00
Pete Johanson 147c340c6e
Feature: Full-Duplex Wired Split (#2766)
refactor(split): Refactor split code for extension

Extract central/peripheral code to allow for plugging in alternate
transports, instead of tying all split logic to BT.

feat(split): Add full-duplex wired split support

* Depends on full-duplex hardware UART for communication.
* Supports all existing central commands/peripheral events, including
  sensors/inputs from peripherals.
* Only one wired split peripheral supported (for now)
* Relies on chosen `zmk,split-uart` referencing the UART device.

docs: Add wired split config docs.

Migrate split to its own dedicated config file, and add details
on wired split config.

Co-authored-by: Nicolas Munnich <98408764+Nick-Munnich@users.noreply.github.com>

fix: Properly override stack size on RP2040

Move the system work queue stack size override on RP2040 ouf of
a `ZMK_BLE` conditional so it is properly applied generally for that
SoC.

---------

Co-authored-by: Nicolas Munnich <98408764+Nick-Munnich@users.noreply.github.com>
2025-03-18 02:48:32 -04:00
Pete Johanson e4f1454e0b
refactor(keymap): Reduce flash usage for studio builds (#2771)
When building for ZMK Studio, we can use the constant stock keymap
for init of the in-memory keymap, to avoid duplicate flash usage
for the keymap from the devicetree.
2025-01-15 16:51:26 -05:00
Pete Johanson c367d8f636
feat(core): Make physical layout key rotation optional (#2770)
To be able to save on flash space, for layouts on space constrained
devices that don't require rotation, make key rotation props
optional behind a new Kconfig flag.
2025-01-15 16:48:18 -05:00
Willow Herring 05abd677c5
chore: Add trailing lines to fix build warnings (#2743)
When building a unibody or central warnings get thrown for the backslash newlines at EOF in combos.h and input_listeners.h. Adding a trailing newline to the affected files rectifies this
2025-01-02 08:58:49 -07:00
Pete Johanson f0a77b888a
fix(combos): Properly report combos len with emply block (#2739)
Handle the scenario where there is an empty combos block and return
a zero combos length.
2025-01-01 18:14:53 -05:00
Pete Johanson cb867f92db
Feature: input processor behavior invocation (#2714)
refactor(pointing): Allow stopping event propagation

    Allow input processors to return a special value if a given input event
    should not be further processed/propagated.

feat(pointing): Add behavior input processor

    Add the ability to intercept certain input events and trigger behaviors
    when they occur.

Co-authored-by: Jorge Villalobos <minusfive@users.noreply.github.com>
Co-authored-by: Cem Aksoylar <caksoylar@users.noreply.github.com>
2024-12-17 20:50:06 -05:00
Pete Johanson 6b40bfda53
feat(mouse): Add mouse move and scroll support (#2477)
* feat(mouse): Add mouse move and scroll support

    * Use Zephyr input subsystem for all pointers.
    * Input processors for modifying events, e.g. scaling, swapping
      codes, temporary (mouse) layers, etc.
    * Mouse move/scroll behaviors.
    * Infrastructure in place for physical pointer input devices.

* feat: Add input split support.

* docs: Add initial pointer docs.

---------

Co-authored-by: Cem Aksoylar <caksoylar@users.noreply.github.com>
Co-authored-by: Alexander Krikun <krikun98@gmail.com>
Co-authored-by: Robert U <urob@users.noreply.github.com>
Co-authored-by: Shawn Meier <ftc@users.noreply.github.com>
Co-authored-by: Chris Andreae <chris@andreae.gen.nz>
Co-authored-by: Anant Thazhemadam <47104651+thazhemadam@users.noreply.github.com>
Co-authored-by: Erik Tollerud <erik.tollerud@gmail.com>
Co-authored-by: Nicolas Munnich <98408764+Nick-Munnich@users.noreply.github.com>
2024-12-09 19:45:41 -05:00
Peter Johanson ea1a09bf99 fix: Optimize layout changes by doing runtime mapping
* To avoid tons of migration, extra flash writes, etc, we keep
  the keymaps and settings using a key position index that's tied
  to the stock layout, and at runtime mapping key positions as
  needed.
2024-10-18 15:30:13 -06:00
angweekiat 0adb80c02b
fix(usb): detect USB power mode to fallback to BLE
* Add tracking to see if we ever hit a configured status before
  suspend, so we can properly track "is connected" even when
  connected to a suspended/asleep host.
2024-10-14 19:15:45 -04:00
ReFil 17f0a4d307
feat(ble): Set device name at runtime
This allows for the device name to be set at runtime, possible uses for this include a custom display screen that lets you type it in using the keycode state event, future configuration in zmk studio, or altering it per profile as per #1169
2024-09-25 15:35:42 -04:00
Peter Johanson 33e3b02ddb feat: Split physical layout selection sync.
* Ensure the split peripherals have the same selected physical
  layout on connection and change.
2024-09-23 15:12:22 -06:00
Cem Aksoylar fb18a4d871 refactor: Condition source props on CONFIG_ZMK_SPLIT 2024-09-23 10:17:29 -06:00
Cem Aksoylar 9e36ebd525 feat(split): Make locality work nested behavior invocations
Co-authored-by: Tokazio <tokazio@hotmail.com>
2024-09-23 10:17:29 -06:00
Peter Johanson cca637d66e fix: Properly calculate highest active layer for display. 2024-09-20 22:59:44 -06:00
Peter Johanson de38676afd fix(core): Warn only with layouts + chosen transform
* Instead of erroring out, simply ignore physical layouts if we
  detect a chosen matrix transform, and warn instead.
2024-09-19 13:12:17 -06:00
Maxime Vincent 67d595f29f pre-commit: re-format using clang-format hook (v18.1.8) 2024-09-13 16:04:26 -06:00
Pete Johanson d52bb04090 Revert "feat: Split physical layout selection sync."
This reverts commit 03b5b38bc4.
2024-09-07 00:22:01 -06:00
Peter Johanson 03b5b38bc4 feat: Split physical layout selection sync.
* Ensure the split peripherals have the same selected physical
  layout on connection and change.
2024-09-06 12:20:45 -06:00
Peter Johanson fd28eab179 feat: Add the ability to keep/omit behaviors for a given build.
* Use defines to keep either all behaviors with omits, or selective behaviors with
  explicit kept behavior, before including `behavior.dtsi` in keymaps.
* Default ZMK_BEHAVIORS_KEEP_ALL when building with the studio RPC
  endpoint snippet.
2024-09-05 12:22:08 -06:00
Peter Johanson c8c19598a7 feat(keymap): Add binding get/set, layer movement
* Add keymap API for getting/setting a bindings
  in keymap layers.
* Add layer move support via intemediary ordering array.
* Add settings storage for keymap changes.
2024-09-05 12:22:08 -06:00
Peter Johanson feda96eb40 feat(studio): Initial RPC infrastructure and subsystems.
* UART and BLE/GATT transports for a protobuf encoded RPC
  request/response protocol.
* Custom framing protocol is used to frame a give message.
* Requests/responses are divided into major "subsystems" which
  handle requests and create response messages.
* Notification support, including mapping local events to RPC
  notifications by a given subsystem.
* Meta responses for "no response" and "unlock needed".
* Initial basic lock state support in a new core section, and allow specifying
  if a given RPC callback requires unlocked state or not.
* Add behavior subsystem with full metadata support and examples of
  using callback to serialize a repeated field without extra stack space needed.

Co-authored-by: Cem Aksoylar <caksoylar@users.noreply.github.com>
2024-08-15 11:45:18 -06:00
Peter Johanson 3694ff85a0 fix: Fix up layer metadata, move to layer IDs.
* Studio will use stable layer IDs to refer to layers, so that
  layer reordering doesn't affect behavior bindings, so update to match.
* Fix a few layer metadata entries that missed being refactored.
2024-07-05 13:13:42 -06:00
Peter Johanson c5cca5b34f feat: Add keyboard physical layout system.
* Add bindings to allow creating multiple physical layouts that specify
  their key's physical attributes, and the matching matrix transform
  and dependant kscan to use.
* Synthesize a basic physical layout if none specified, for backwards
  compatibility.
* Update matrix transform API to explicitly pass in the selected transform
  to the API instead of using a fixed chosen transform.
* Move kscan subscription and handling into the physical layout code, so
  that selecting a different physical layout at runtime can also use the
  correct kscan instance.
* Add `physical_layouts.dtsi` file to include so you can use the
  pre-configured `&key_physical_attrs` for adding you layout keys.
2024-07-03 16:52:05 -06:00
Peter Johanson 80173f8ea3 fix: Improve startup time with proper settings loading.
* Avoid doing duplicate calls to setings_load_subtree, which iterates
  NVS fully each time under the hood, and instead use on settings_load
  later in the lifecycle.
2024-07-03 16:24:17 -06:00
Peter Johanson 483a4930e9 feat(behaviors): Add local ID system for behaviors
* Add a new feature for tracking a given behavior by a new concept
  of a "behavior local ID" which is a stable 16-bit identifier for
  a given behavior, that is resilient to new behaviors being added
  and requires no additional work on the part of the behavior
  authors.
* Add implementations for either settings lookup table, or CRC16
  hashing of behavior device names for generating behavior local
  IDs.
2024-06-28 15:10:32 -06:00
Peter Johanson f7c34c70ba refactor(ble): Extract API to get active profile connection.
* Add `struct bt_conn *zmk_ble_active_profile_conn(void)` function for
  fetching a connection for the current profile.
2024-06-28 14:43:17 -06:00
Peter Johanson b576d52d58 feat(core): Support adding subs to other listeners.
* Used for ZMK Studio event remappers to be sure the one
  RPC event listener subscribes to their mapped events.
2024-06-28 14:36:25 -06:00
Peter Johanson 03099b04b6 feat(behaviors): Add behavior metadata information.
* For upcoming ZMK studio work, make a set of rich metadata available
  to provide a friendly name for a behavior, and allow super flexible
  descriptions of the parameters the behaviors take.
* Add ability to validate a zmk_behavior_binding against
  the behavior metadata available.
2024-06-24 11:08:00 -06:00
Horu 7d1f84e3eb
chore: fix typos in various places 2024-05-13 16:47:33 -04:00
Keeley Hoek e22bc7620c fix(hid): Correct off-by-one buffer overflow with NKRO 2024-04-09 23:20:20 -07:00
Peter Johanson 41d81801ed fix(pm): Use Zephyr created device slots.
* Avoid overwriting random memory by using
  iterable section created by Zephyr PM.
2024-03-27 20:59:26 -07:00
Peter Johanson 8d54e287f0 fix: Adjustments for Zephyr 3.5. 2024-03-27 20:59:26 -07:00
Peter Johanson 860e53b33a refactor: Promote new endpoints API
* Add ability for external callers to clear the current endpoint.
2024-03-27 20:59:26 -07:00
Peter Johanson adb3a13dc5 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 <caksoylar@users.noreply.github.com>
2024-03-27 20:59:26 -07:00
Hans Kruse c6e0551fb0
fix(hid): Fix typo in HID usage alias 2024-03-18 13:06:09 -04:00
Joel Spadin 610a806c84 feat: Add function to erase all settings
Added a zmk_settings_erase() function to clear all saved settings. This
does not go through Zephyr's settings subsystem, but instead directly
clears the data from the setting storage backend, so a reboot is needed
for it to take effect.
2024-03-18 09:48:19 -07:00
Peter Johanson 50a303b8bb fix(pm): Restore sleep suspension of devices.
* After the move to `sys_poweroff`, restore the behavior of
  suspending devices before entering sleep state.
2024-02-09 14:32:46 -08:00
Peter Johanson bf4008da02 refactor: All SYS_INIT functions are void args. 2024-02-09 14:32:46 -08:00
Peter Johanson e89cffc959 fix(events): Remove our usage of assert.
* __ASSERT is converted to a do/while loop when asserts are enabled,
  which doesn't work with our usage, so revert that addition.
2024-01-14 16:19:30 -08:00
Peter Johanson 644feeb40d fix(core): Address review comments from Joel.
* Fix up some lingering events API tweaks for heap-less event manager.
2024-01-14 11:13:57 -08:00
Peter Johanson 33209dee1d refactor(core): Move to stack allocated events.
* Move to local/stack allocated event API that doesn't require
  dynamic allocation/freeing.
* Disable heap, we no longer use alloc/free unless using LVGL.
* Tons of refactors all over to account for the new event approach.
2024-01-14 11:13:57 -08:00
Chris Andreae 604c95118e Remove error reporting from ble utility functions that never error 2024-01-05 12:16:38 -08:00
Chris Andreae 7a5155f36e lint: add (void) parameter to pass -Wstrict-prototypes
Note there was one place where a non-strict prototype was actually being used
with an argument, in `zmk_hog_init`. In this case, the actual argument type was
added instead.
2024-01-05 12:16:38 -08:00
moergo-sc 5257cde1f5 bt: add BT_CLR_ALL behaviour
Defines behaviour to clear all paired Bluetooth profiles
2024-01-05 12:16:38 -08:00
Gabor Hornyak 0e2f94b73b feat(ble): Support perhipheral battery levels.
* Add ability to fetch and report peripheral battery levels
  on split centrals.
* Add additional support for adding a new Battery Level
  service to split centrals that exposes fetched peripheral
  battery levels to connected hosts.

Co-authored-by: Peter Johanson <peter@peterjohanson.com>
2024-01-03 09:26:51 -08:00