How nazo6/rktk works
Main Architectural Components
• Core Firmware (rktk crate): This is the heart of the system where configuration, task scheduling, hooks, interfaces, and the main loop reside. It wires up all functionality and provides the abstraction layer over the hardware.
• Hardware Driver Modules:
– rktk-drivers-common: Contains shared drivers for key scan, mouse, display, USB, etc.
– rktk-drivers-nrf and rktk-drivers-rp: Provide platform-specific implementations (for nRF52840 and RP2040, respectively), handling things like split communication, native display support, and so on.
• Key Manager (rktk-keymanager): Implements the key mapping features including tap-hold, tap dance, oneshot keys, and combo keys. It is independent of the core firmware so that the key mapping logic is isolated.
• Communication and Logging Modules:
– rktk-rrp: Handles host communication and remote procedure calls.
– rktk-log: Manages logging and debugging outputs.
• External Tools and Clients:
– The tools directory includes both a CLI tool (for configuration, testing, releasing) and a graphical client (rktk-client) that likely provides a UI for remapping and interacting with the firmware.
Relationships and Data Flows
• The core rktk component uses these inputs to drive the main loop (see the tasks in lib/rktk/src/task) and to trigger processing across the firmware.
• The key manager converts raw input events into higher-level actions (e.g., keycodes, modifier actions, layer controls) and feeds these into the system.
• Communication components (rktk-rrp) and logging (rktk-log) handle sending data to external hosts or for diagnostics.
• External tools (rktk-client and CLI tools) interact with the firmware via interfaces like USB or Bluetooth, allowing live reconfiguration or debugging.
Architectural Patterns
• Layered/Modular Architecture: Each major facet of the system (hardware abstraction, firmware core, key mapping, communication) is implemented as its own crate/module, ensuring separation of concerns.
• Abstraction and Extensibility: The division between core functionality and drivers makes it straightforward to extend the support to additional hardware platforms.
• Task-based Concurrency: The project uses dedicated task modules (for display, logging, key scanning, etc.) that likely communicate via channels, which is important for real-time responsiveness on keyboard firmware.
Technologies, Frameworks, and Libraries
• Rust: The entire project is built in Rust with heavy usage of Cargo workspaces and crates for modularization.
• Embedded Rust Toolchains: Considering the embedded targets (nRF52840 and RP2040), expect use of platform-specific HALs and features optimized for embedded development.
• USB, Bluetooth, and low-level hardware interfaces are supported through these drivers, using appropriate libraries and language idioms for embedded systems.
• Each primary component (rktk core, individual driver crates, key manager, communication/logging, external tools).
– Data/event flow from hardware (input) through drivers to core logic.
– Processing flow from core logic to key mapping and out to communication interfaces.
• Annotations or notes capturing the purpose of each module (e.g., “platform-specific driver for RP2040”, “key mapping and combo resolution”).