keyberon_smart_keyboard/lib.rs
1//! # Keyberon Smart Keyboard
2//!
3//! This crate provides functionality for using [smart_keymap]
4//! as part of Rust keyboard firmware.
5//!
6//! See the `examples/` under `rp2040-rtic-smart-keyboard`
7//! for an example of Rust firmware using this crate.
8//!
9//! ## Migrating from Keyberon
10//!
11//! Roughly, where Keyberon code is typically:
12//!
13//! ```
14//! use embedded_hal::digital::{InputPin, OutputPin};
15//! use keyberon::chording::Chording;
16//! use keyberon::debounce::Debouncer;
17//! use keyberon::layout::CustomEvent;
18//! use keyberon::layout::Event;
19//! use keyberon::layout::Layout;
20//! use keyberon::matrix::Matrix;
21//!
22//! // Gather events from keyboard matrix
23//! fn keyboard_events<C, R, E, const COLS: usize, const ROWS: usize, const CHORD_COUNT: usize>(
24//! matrix: &mut Matrix<C, R, COLS, ROWS>,
25//! debouncer: &mut Debouncer<[[bool; COLS]; ROWS]>,
26//! chording: &mut Chording<CHORD_COUNT>,
27//! ) -> heapless::Vec<Event, 8>
28//! where
29//! C: InputPin<Error = E>,
30//! R: OutputPin<Error = E>,
31//! E: core::fmt::Debug,
32//! {
33//! let key_presses: [[bool; COLS]; ROWS] = matrix.get().unwrap();
34//! let debounced_events: heapless::Vec<Event, 8> = debouncer.events(key_presses).collect();
35//! chording.tick(debounced_events)
36//! }
37//!
38//! // Compute key codes from those events
39//! fn key_codes_from_events<
40//! T: 'static,
41//! K: Copy + 'static,
42//! const COLS: usize,
43//! const ROWS: usize,
44//! const LAYER_COUNT: usize,
45//! >(
46//! events: heapless::Vec<Event, 8>,
47//! layout: &mut Layout<COLS, ROWS, LAYER_COUNT, T, K>,
48//! ) -> heapless::Vec<K, 8> {
49//! for event in events {
50//! layout.event(event);
51//! }
52//! let _custom_event: CustomEvent<T> = layout.tick();
53//! layout.keycodes().collect()
54//! }
55//! ```
56//!
57//! With this crate, [input::Keyboard] manages scanning/debouncing events
58//! from the keyboard matrix. Chording is handled by smart keymap.
59//!
60//! For computing the key codes, this uses [input::smart_keymap::KeyboardBackend]:
61//!
62//! ```
63//! use keyberon::layout::Event;
64//!
65//! use keyberon_smart_keyboard::input::Keyboard;
66//! use keyberon_smart_keyboard::input::MatrixScanner;
67//! use keyberon_smart_keyboard::input::PressedKeys;
68//! use keyberon_smart_keyboard::input::smart_keymap::KeyboardBackend;
69//! use keyberon_smart_keyboard::input::smart_keymap::keymap_index_of;
70//!
71//! // Gather events from keyboard matrix
72//! fn keyboard_events<M: MatrixScanner<COLS, ROWS>, const COLS: usize, const ROWS: usize>(
73//! keyboard: &mut Keyboard<COLS, ROWS, M>,
74//! ) -> heapless::Vec<Event, 8>
75//! {
76//! keyboard.events()
77//! }
78//!
79//! // Compute key codes from those events
80//! fn key_codes_from_events<const COLS: usize, const ROWS: usize>(
81//! keymap_indices: &[[Option<u16>; COLS]; ROWS],
82//! events: heapless::Vec<Event, 8>,
83//! backend: &mut KeyboardBackend,
84//! ) -> heapless::Vec<u8, 24> {
85//! for event in events {
86//! if let Some(event) = keymap_index_of(keymap_indices, event) {
87//! backend.event(event);
88//! }
89//! }
90//! backend.tick();
91//! backend.keymap_output().pressed_key_codes()
92//! }
93//! ```
94
95#![no_main]
96#![no_std]
97
98/// Useful traits and structs related to input.
99pub mod input;
100
101/// A matrix scanning impl. with delay.
102pub mod matrix;
103
104/// UART-based split pressed key communication.
105pub mod split;