Skip to main content

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,
58//!  [input::Keyboard] manages scanning/debouncing events
59//!  from the keyboard matrix.
60//! Chording is handled by smart keymap.
61//!
62//! For computing the key codes, this uses [input::smart_keymap::KeyboardBackend]:
63//!
64//! ```
65//! use keyberon::layout::Event;
66//!
67//! use keyberon_smart_keyboard::input::Keyboard;
68//! use keyberon_smart_keyboard::input::MatrixScanner;
69//! use keyberon_smart_keyboard::input::PressedKeys;
70//! use keyberon_smart_keyboard::input::smart_keymap::KeyboardBackend;
71//! use keyberon_smart_keyboard::input::smart_keymap::keymap_index_of;
72//!
73//! // Gather events from keyboard matrix
74//! fn keyboard_events<M: MatrixScanner<COLS, ROWS>, const COLS: usize, const ROWS: usize>(
75//!     keyboard: &mut Keyboard<COLS, ROWS, M>,
76//! ) -> heapless::Vec<Event, 8>
77//! {
78//!     keyboard.events()
79//! }
80//!
81//! // Compute key codes from those events
82//! fn key_codes_from_events<const COLS: usize, const ROWS: usize>(
83//!     keymap_indices: &[[Option<u16>; COLS]; ROWS],
84//!     events: heapless::Vec<Event, 8>,
85//!     backend: &mut KeyboardBackend,
86//! ) -> heapless::Vec<u8, 24> {
87//!     for event in events {
88//!         if let Some(event) = keymap_index_of(keymap_indices, event) {
89//!             backend.event(event);
90//!         }
91//!     }
92//!     backend.tick();
93//!     backend.keymap_output().pressed_key_codes()
94//! }
95//! ```
96
97#![no_main]
98#![no_std]
99#![warn(clippy::unwrap_used)]
100
101/// Useful traits and structs related to input.
102pub mod input;
103
104/// A matrix scanning impl. with delay.
105pub mod matrix;
106
107/// UART-based split pressed key communication.
108pub mod split;