Skip to main content

Crate smart_keymap

Crate smart_keymap 

Source
Expand description

Smart Keymap library.

A “smart keyboard” is a keyboard where the keys can perform multiple actions, depending on the context. Features such as layering, tap-hold, and tap-dance are examples of smart keyboard functionality.

The smart keymap library provides an interface for the “smart keymap” part of smart keyboard firmware. i.e. the part that takes key presses and releases as input, and outputs HID keyboard reports (or other smart keyboard outputs).

This crate can be used directly with Rust, or built as a C library.

The engine implementation lives in smart_keymap_core; this package re-exports it and adds the per-build init keymap shell (dummy or codegen via SMART_KEYMAP_CUSTOM_KEYMAP).

§Usage as a C library

§Custom Keymap

When used as a C library, the library should be built by setting the environment variable SMART_KEYMAP_CUSTOM_KEYMAP to the path of a custom keymap file.

SMART_KEYMAP_CUSTOM_KEYMAP can be set either to a .ncl file, or to a .rs file (generated using the scripts under ncl/).

§Keyboard Firmware Implementation

When used as a C library, the firmware should call to keymap_init, keymap_register_input_keypress, keymap_register_input_keyrelease, and keymap_tick functions. The keymap_tick function should be called every ms, and should copy the HID keyboard report to the given buffer.

§Implementation Overview

The heart of the library is the key module, and its key::System trait.

Per-keymap aggregation is produced by Nickel codegen as init::key_system (custom keymap / keymap!). Without a custom keymap, init provides a trivial keyboard-only shell so new_keymap still type-checks.

The full-profile, Vec-backed composite shell used by Cucumber and other std harnesses lives in the separate smart-keymap-full-system-std package so default smart-keymap builds (including cargo doc) do not require Nickel for the universal shell (custom keymap codegen still needs Nickel when pointing at a .ncl file).

Re-exports§

pub use init::Keymap;
pub use init::CONTEXT;
pub use init::KEY_REFS;
pub use init::SYSTEM;

Modules§

init
Types and initial data used for constructing a keymap::Keymap.
input
Structs for input to the keymap.
key
Smart key interface and implementations.
keymap
Keymap implementation.
slice
A helper value type for Copy-able slices.
split
Split keyboard support.

Functions§

new_keymap
Constructs a new keymap.