Commit Graph

195 Commits

Author SHA1 Message Date
Joel Spadin
36eda571b7 refactor(behaviors): Create a list to lookup behaviors
Added BEHAVIOR_DT_DEFINE() and BEHAVIOR_DT_INST_DEFINE(), which work
exactly like the DEVICE_*_DEFINE() macros, except they also register the
device as a behavior by adding a pointer to it to a memory section.

Added zmk_behavior_get_binding(), which works like device_get_binding()
except that it only searches the devices that have been registered as
behaviors. This ensures that behaviors cannot have name collisions with
other devices defined by the SoC, which will be important when we remove
the label property from behaviors so they are given their node names.

As an added benefit, this is faster since it searches a smaller list.
Some basic benchmark code I wrote indicates it takes 30-70% as long,
depending on where the behavior is in the list and whether the name
string is an exact pointer match.

From now on, behaviors should use BEHAVIOR_*_DEFINe() instead of
DEVICE_*_DEFINE(), and any code that looks up a behavior by name should
use zmk_behavior_get_binding() instead of device_get_binding().
2023-12-04 20:06:54 -06:00
Joel Spadin
d4e8dee444 refactor(keymaps): Rename layer label to "display-name"
Changed the property used to define a layer name for displays from
"label" (which affects other things in Zephyr and is deprecated) to
"display-name". (It cannot be named simply "name", because that has
special meaning in newer versions of the devicetree compiler.)

"label" is still supported as a fallback, so no changes need to be made
to existing keymaps.
2023-12-04 20:06:54 -06:00
Joel Spadin
179bdbc41a refactor(behaviors): Make label property optional
Changed all code (except for layer names) which used the label property
to use DEVICE_DT_NAME() instead, which uses the label if set or falls
back to the full node name. This matches how Zephyr determines the node
names used with device_get_binding() and allows us to start removing the
deprecated label property from things.
2023-12-04 20:06:54 -06:00
ReFil
dbe5dfb1d8
feat(split): Add is_bonded function to peripherals
There is already a function to see if the peripheral is connected, a matching one for if it's bonded is a useful addition for displays/indicators. `is_bonded` gets reset to false in the advertising function in preparation for runtime peripheral bond clearing
2023-12-04 18:31:35 -05:00
ReFil
9bacaffe62
feat(hid): Add KConfig option for higher NKRO usages
By default the maximum NKRO usage is set to maximise compatibility, but some keys dont work, this adds the ability to use those extended keys, at the cost of compatibiltity

Co-authored-by: Cem Aksoylar <caksoylar@users.noreply.github.com>
Co-authored-by: Pete Johanson <peter@peterjohanson.com>
2023-12-04 18:24:05 -05:00
Peter Johanson
817ce8764f refactor: Move to zmk_hid_indicators_t type. 2023-11-27 16:03:18 -08:00
Alessandro Bortolin
d9bb0d7d0e feat: LED indicators on peripheral side 2023-11-27 16:03:18 -08:00
Alessandro Bortolin
4e55c5f6e9 feat: handle LED indicators report 2023-11-27 16:03:18 -08:00
Chris Andreae
0a4b1a6533
feat(ble): add behavior to disconnect from BLE profile
Adds new functionality and a behavior to disconnect an active BLE connection.
The motivation for this is that for some devices like phones, the presence of an
active BLE connection results in the onscreen keyboard being selected.
2023-11-20 15:00:10 -05:00
Alexander Krikun
d7d9eed317 feat(mouse): Initial mouse keys support.
* Add HID report/descriptor for a new report with mouse buttons,
  and x/y/wheel deltas.
* New mouse key press behavior for press/release of mouse keys.
* Add constants for HID main item values (e.g. data/array/absolute)
* Define and use constants for our HID report IDs.
2023-11-15 11:16:59 -08:00
Chris Andreae
91aa3378f3
feat(usb): Add boot protocol support
* USB boot protocol support
* Use a single definition of a boot report, used for regular reports in
  non-6KRO, and for rollover in all branches.
* Handle gaps in the zmk report when producing a boot report in HKRO mode. For
  .example, if it was 8KRO, it would be possible to have the state 0 0 0 0 0 0 0
  17 (by pressing 8 keys, and letting go of the first 7). Copying the first 6
  bytes would not show up the single pressed key.
* Disable usb status change and callback on SOF events:
  SOF events were introduced by the boot protocol changes, and required internally
  by Zephyr's idle support, but are unused within ZMK itself. Ignore them in the
  usb status callback.

---------

Co-authored-by: Andrew Childs <lorne@cons.org.nz>
2023-11-13 13:04:04 -05:00
Peter Johanson
c2d220fbdf refactor(hid): Use proper defines for HID values.
* Add report ID defines and use them consistently.
* Add defines for main item value flags to avoid magic constants.
2023-11-08 16:00:19 -08:00
Joel Spadin
651ed05e9a refactor: Split endpoint to transport and instance
Changed the endpoints code to rename the existing endpoint types to
"transport" and add the concept of "endpoint instances". A transport is
the method by which data is sent, while instances allow describing
multiple endpoints that use the same transport (e.g. bluetooth profiles)

Also added new APIs to get the total number of possible endpoint
instances and assign each instance a unique index, which can be used
for tracking separate state for each endpoint in other code files.
2023-10-02 22:03:08 -07:00
ReFil
c1ebadcd2a
feat(hid): Add apple globe keycode
* feat(hid): Add apple globe keycode
* Update docs/src/data/hid.js

Co-authored-by: Cem Aksoylar <caksoylar@users.noreply.github.com>
Co-authored-by: Pete Johanson <peter@peterjohanson.com>
Co-authored-by: Nick Coutsos <nick@coutsos.com>
2023-09-29 13:14:31 -07:00
Peter Johanson
690bc1bb44 refactor: Move drivers into properly module.
* Align our driver module layout to properly match Zephyr conventions,
  allowing proper CMake setup to amend the library for each type of driver.
2023-09-16 11:52:40 -07:00
Peter Johanson
a92a4967aa fix(sensors): Only accept data once per behavior.
* Don't accept data for the same behavior on multiple layers more than
  once, to avoid duplicate/extraneous triggers.
2023-08-27 19:52:03 -07:00
Stephen Wan
9d44229800 feature(split): add support for sensors from peripheral
This commit adds a new GATT characteristics on the peripheral side
and wires it up to read sensor values. The central side subscribes
to this new characteristics and replays sensor values on its side.

Co-authored-by: Peter Johanson <peter@peterjohanson.com>
2023-08-27 19:52:03 -07:00
Xudong Zheng
9a963abfc8 refactor: use low priority workqueue for underglow and battery reporting
Blocking operations on the high priority system workqueue may result in
deadlocks, particularly when Bluetooth is in use.
2023-07-24 17:04:51 -07:00
Peter Johanson
753802cd79 fix(sensors): Clean ups based on code review. 2023-06-18 20:45:06 -06:00
Peter Johanson
3a91b32513 refactor(sensors): Use "sensor index" consistently 2023-06-18 20:45:06 -06:00
Peter Johanson
8b29f6d345 refactor(sensors): Split data handling from triggers.
* All sensor behaviors should see sensor data, then selectively
  only have some trigger their behaviors.
2023-06-18 20:45:06 -06:00
Peter Johanson
295ed83409 refactor(sensors): ec11 rotation sensor value in degrees.
* Add new `steps` property to the `aips,ec11` binding, to make
  the driver properly report degrees in the rotation delta channel.
* Handle old sensor values in sensor rotate behavior.
2023-06-18 20:45:06 -06:00
Peter Johanson
2244bd3d81 refactor(sensors): Sensor event channel data, resolution tweaks.
* Refactor sensor events to include channel data,
  necessary for prop split encoders, and avoiding duplicate calls,
  to fetch channel data twice, etc.
* More consistent behavior driver API.
* Allow setting triggers per resolution at the behavior level optionally.
2023-06-18 20:45:06 -06:00
Xudong Zheng
5d9ae8fffa feat(split): allow central to connect to multiple peripherals 2023-06-05 16:22:41 -06:00
Xudong Zheng
1adfcf92bf refactor(split): fix inconsistency in Kconfig names 2023-05-28 22:58:31 -06:00
Joel Spadin
94061bb916 refactor: Replace tabs with spaces
Standardized indentation to use spaces with a new pre-commit hook.
2023-04-24 16:07:04 -07:00
Joel Spadin
32ae776c42 refactor: Add more checks to pre-commit
Updated existing pre-commit hooks and added some new hooks:

- Remove trailing whitespace
- Ensure every non-empty file ends with a new line
- Check YAML file validity
- Prevent adding large files
- Ensure any scripts with shebangs are executable

Added a GitHub action to run pre-commit on every commit. Removed any
existing actions which duplicate pre-commit.

Ran pre-commit on the codebase.
2023-04-24 16:07:04 -07:00
Nick Conway
3db163aa2c feat(behaviors): Add reusable sensor behaviors.
* Add new sensor behaviors that either take full bindings
  add definition, or accept parameters when bound in the
  keymap.
* Remove existing hard-coded key press sensor behavior
  and instead leverage new generic sensor behaviors to
  achieve the same functionality.

Co-authored-by: nick@conway.dev
2023-04-21 21:13:31 -07:00
Joel Spadin
e7a6e4016d feat(behaviors): Add key position to key events
Extended the virtual key position system from combos so that each sensor
also gets a virtual key position. This allows sensor behaviors to use
the behavior queue API.
2023-04-16 23:53:12 -07:00
Purdea Andrei
309359b32f
fix(keymaps): fix keypresses that are not in the transform
Before this change, if a matrix position was not present in the transform,
various incorrect behaviors would happen:

1) In some cases out-of-bounds accesses:

Note that the size of the`transform[]` array does not necessarily match
the size of the matrix. So for example if key position
(ZMK_MATRIX_COLS-1, ZMK_MATRIX_ROWS-1) is not present in the transform,
but ends up being pressed, then the array will be accessed beyond its
size, and any data could be returned.

2) In other cases the 0th position in the keymap will be used because
the `transform[]` array is initialized to all zeros.
2023-04-10 03:27:19 -04:00
Peter Johanson
09ed79a867 refactor: Move away from deprecated label usages.
* Move away from DT_LABEL.
* Move to DEVICE_DT_GET for non-behavior device access.
* Move various drivers to `gpio_spec_dt` and `DT` related macros.
* Remove mcp23017 while at it, since better upstream driver is
  available.
2023-04-05 22:55:38 -07:00
Peter Johanson
3a958c667f refactor: Move to zephyr/ include paths.
* Zephyr moved to properly namespaced headers, so major "rip
  the bandaid" commit to move us to those everywhere.
2023-04-05 22:55:38 -07:00
jhorology
768fc4a5e5 fix: HID report descriptor 2022-11-10 22:15:06 -06:00
ebastler
c9eb63199a
feat(keymaps): add NUHS/NUBS alias for Non-US-Backslash/Non-US-Hash 2022-10-17 21:48:19 -04:00
Robert U
ef2e6e9156
feat(behaviors): Add mod-morph keep-mods
* Update docs for mod-morph
* Add unit tests for mod-morph
* Add keep-mods to DT binding

Co-authored-by: Martin Aumüller <aumuell@reserv.at>
Co-authored-by: Cem Aksoylar <caksoylar@users.noreply.github.com>
2022-10-14 20:40:28 -05:00
Shreyas
391f80f069
feat(hid): Add C_AC_DESKTOP_SHOW_ALL_APPLICATIONS
* support for C_AC_DESKTOP_SHOW_ALL_APPLICATIONS

Co-authored-by: Shreyas Kale <shreyaskale@Shreyass-MacBook-Pro.local>
2022-08-22 00:27:47 -04:00
Caleb Goates
0d5bb100ba feat(behavior): Add key toggle 2022-06-03 00:04:41 -04:00
Okke Formsma
c5922fae56 refactor(hid): add mask to HID_USAGE_PAGE macro 2022-06-03 00:04:41 -04:00
Okke Formsma
57fca34dc0 refactor(hid): Move hid logic into hid.c
Move the logic for picking the correct hid function into hid.c.
2022-06-03 00:04:41 -04:00
Peter Johanson
6539b3ae25 refactor(split): Clean up Kconfig organization.
* Seperated configs for split role (central/peripheral)
  and transport (BLE only for now).
* Split the configs to align on structure.
2022-05-29 19:18:09 -04:00
Peter Johanson
16ab6df18d feat(display): Add new peripheral status/display
* Add new API/status to track state of the
  peripheral connection to the central.
* Add new peripheral status widget for displaying
  the current status of the connection to
  the central.
2022-05-17 13:09:21 -04:00
Stefán Páll Sturluson
d7ba7a1bee
fix(codes): typo in C_SUBTITLES. 2022-05-17 00:29:53 -04:00
Peter Johanson
40cd8da743 fix(usb): Split HID from core USB, logging fix.
* Split core USB init from USB HID init.
* Tweak logging to avoid "log loop" causing
  spurious buffer messages on startup.
2022-04-13 13:07:59 -04:00
Peter Johanson
1dccb7fe50 fix(hid): Use a full valid range for consumer page
* Switch to a logical max for the consumer page
  that avoid signed issue, and still allows
  full range of documented consumer page
  values.
2022-04-10 22:32:09 -04:00
Peter Johanson
40d8470664 refactor: Handle HID macro/API changes in Zephyr. 2022-04-03 00:10:29 -04:00
Peter Johanson
3a6a249ad0 feat(behaviors): Add macro support.
* Fine grainted press/release/tap actions.
* TIming between actions can be controlled.
* Processed async, to avoid blocking.
2022-03-23 23:42:54 -04:00
Alessandro Bortolin
13a4515300 feat(backlight): add command to cycle brightness 2022-02-05 23:40:18 -05:00
Alessandro Bortolin
ce843825e8 refactor(backlight): code cleanup 2022-02-05 23:40:18 -05:00
ReFil
5614a8bb80 feat(backlight): initial split support 2022-02-05 23:40:18 -05:00
Alessandro Bortolin
85b2d30bd5 feat(lighting): add backlight behavior 2022-02-05 23:40:18 -05:00