Skip to content

Add keymap commands - #2

Open
crmne wants to merge 2 commits into
fldc:masterfrom
crmne:keymap
Open

crmne wants to merge 2 commits into
fldc:masterfrom
crmne:keymap

Conversation

@crmne

@crmne crmne commented Oct 14, 2026 •

Copy link
Copy Markdown

Adds nuphyctl keymap, for reading and remapping the keymap on boards that run NuPhy's own firmware (the data NuPhy IO edits), so a keymap can live in a dotfiles TOML file and be applied from the command line.

What's in it

  • keymap info: firmware version, current mode and keymap geometry.
  • keymap dump: the whole keymap, one layer or one mode, with named keycodes and positions. --defaults reads the factory keymap, --changed shows only keys that differ from it, --raw-out saves a full binary backup.
  • keymap set --layer L <pos> <code>: set one key.
  • keymap apply <file.toml>: declarative remap. Prints the diff, writes only keys that change, and is idempotent. keymap export produces such a file from the keyboard's current changes.
  • keymap restore-backup <file.bin> and keymap reset --mode windows|mac|all --yes.
  • keymap keycodes / keymap positions list the names. Every command takes --json.

Every write first saves a backup of the whole keymap under $XDG_STATE_HOME/nuphyctl/, then reads the keymap back and fails unless it matches exactly.

Protocol

It uses the existing framing and session key. The new commands are 0xA0 GetBase, 0xA1 GetFirmwareInfo, 0xB1 GetDefaultKeys, 0xB2 GetUseKeys, 0xB3 SetUseKeys and 0xB4 RestoreUseLayers. Each layer is 196 bytes: 6x16 matrix keys plus 2 knob entries, 2 bytes each, big-endian, QMK-style keycodes, with NuPhy's own functions at 0x7Exx. Layers 0-3 are Mac mode and 4-7 Windows mode. The details are in docs/reverse-engineering.md.

Testing

  • cargo fmt --check, cargo clippy --all-targets --all-features -- -D warnings and cargo test --all-features (27 new unit tests) pass.
  • On an Air75 V3 (firmware 1.0.17.6), I remapped the Windows-mode top row and checked the new keys' output with evdev and in daily use. The remap survives a replug. Re-running the same file reports no changes, and backup/restore round-trips byte-identically.
  • keymap reset (0xB4) is implemented from the NuPhy IO web app's code but hasn't been run on hardware yet.

Named positions follow the Air75 V3 layout. Other boards with this firmware should work with row,col or #index positions, but I've only tried the Air75 V3.

crmne added 2 commits October 14, 2026 15:33
Read, back up, diff and write the per-layer keymap of NuPhy's own-firmware
boards (GetUseKeys/SetUseKeys/RestoreUseLayers), with named keycodes and
Air75 V3 key positions. keymap apply takes a declarative TOML file, writes
only the keys that change, and verifies every write by reading it back.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant