keyberon_smart_keyboard/
input.rs1use core::convert::Infallible;
2
3use keyberon::debounce::Debouncer;
4use keyberon::layout::Event;
5
6pub mod smart_keymap;
8
9pub type PressedKeys<const COLS: usize, const ROWS: usize> = [[bool; COLS]; ROWS];
11
12pub trait MatrixScanner<const COLS: usize, const ROWS: usize, E = Infallible> {
15 fn is_boot_key_pressed(&mut self) -> bool;
17 fn get(&mut self) -> Result<[[bool; COLS]; ROWS], E>;
18}
19
20pub struct Keyboard<const COLS: usize, const ROWS: usize, M: MatrixScanner<COLS, ROWS>> {
25 pub matrix: M,
26 pub debouncer: Debouncer<PressedKeys<COLS, ROWS>>,
27}
28
29impl<const COLS: usize, const ROWS: usize, M: MatrixScanner<COLS, ROWS>> Keyboard<COLS, ROWS, M> {
30 pub fn new(matrix: M, debouncer: Debouncer<PressedKeys<COLS, ROWS>>) -> Self {
32 Self { matrix, debouncer }
33 }
34
35 pub fn events(&mut self) -> heapless::Vec<Event, 8> {
37 let key_presses = self.matrix.get().unwrap();
38 self.debouncer.events(key_presses).collect()
39 }
40}