Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bootloader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![no_main]
use cortex_m::asm;
use cortex_m_rt::entry;
#[cfg(not(test))]
use panic_halt as _;
use stm32h7::stm32h723;

Expand All @@ -23,5 +24,7 @@ fn main() -> ! {
}

// Stay in bootloader (update mode)
loop {}
loop {
cortex_m::asm::wfi();
}
}
11 changes: 9 additions & 2 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ extern crate std;
pub type KeyState = u64;

pub mod debounce;
pub use debounce::{Debouncer, MaskDebounce, NoDebounce, TimeDebounce};
#[cfg(any(feature = "no-debounce", feature = "time-debounce", feature = "mask-debounce"))]
#[cfg(any(
feature = "no-debounce",
feature = "time-debounce",
feature = "mask-debounce"
))]
pub use debounce::ActiveDebouncer;
pub use debounce::{Debouncer, MaskDebounce, NoDebounce, TimeDebounce};

pub mod traits;
pub use traits::MatrixHardware;

/// Abstraction over the hardware keyboard interface. This trait is
/// implemented by the STM32 firmware as well as the Linux simulator.
Expand Down
1 change: 1 addition & 0 deletions core/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const NUM_KEYS: usize = NUM_ROWS * NUM_COLS;
const DEBOUNCE_BITS: u8 = 5;
const MASK: u16 = (1 << DEBOUNCE_BITS) - 1;

#[derive(Default)]
pub struct KeyboardLogic {
history: [u16; NUM_KEYS],
stable: KeyState,
Expand Down
3 changes: 3 additions & 0 deletions core/src/traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub trait MatrixHardware {
fn read_row(&self, row: usize) -> u16;
}
11 changes: 11 additions & 0 deletions core/tests/mock_matrix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use keyboard_core::MatrixHardware;

pub struct MockMatrix {
pub rows: Vec<u16>,
}

impl MatrixHardware for MockMatrix {
fn read_row(&self, row: usize) -> u16 {
self.rows[row]
}
}
12 changes: 12 additions & 0 deletions core/tests/test_matrix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use keyboard_core::MatrixHardware;
mod mock_matrix;
use mock_matrix::MockMatrix;

#[test]
fn read_row_returns_correct_value() {
let mock = MockMatrix {
rows: vec![0b1100u16, 0b0011u16],
};
assert_eq!(mock.read_row(0), 0b1100u16);
assert_eq!(mock.read_row(1), 0b0011u16);
}
8 changes: 5 additions & 3 deletions firmware/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use cortex_m::peripheral::{Peripherals, SYST};
use cortex_m_rt::entry;
use keyboard_core::{self as core, KeyEventHandler, KeyboardHW, Timer};
#[cfg(not(test))]
use panic_halt as _;
use stm32h7::stm32h723;

Expand All @@ -20,7 +21,6 @@ impl Stm32Keyboard {

struct SysTimer {
syst: SYST,
start: u64,
}

struct EventSink;
Expand Down Expand Up @@ -67,9 +67,11 @@ fn main() -> ! {
syst.set_reload(SYSCLK_HZ / 1000);
syst.clear_current();
syst.enable_counter();
let timer = SysTimer { syst, start: 0 };
let timer = SysTimer { syst };
let mut events = EventSink;

core::run(&mut hw, &timer, &mut events);
loop {}
loop {
cortex_m::asm::nop();
}
}
2 changes: 1 addition & 1 deletion simulator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod input_scenario;

use sim_hal::{SimKeyboard, SimTimer};
use input_scenario::example_scenario;
use keyboard_core::{KeyboardHW, Timer};
use keyboard_core::KeyboardHW;

fn scan_and_process(hw: &mut impl KeyboardHW, time: u64) {
let keys = hw.read_keys();
Expand Down
4 changes: 1 addition & 3 deletions simulator/src/sim_hal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ use keyboard_core::{KeyboardHW, Timer};
pub struct SimKeyboard {
pub keys: u64,
pub active_row: Option<usize>,
pub num_rows: usize,
pub num_cols: usize,
}

impl SimKeyboard {
pub fn new(rows: usize, cols: usize) -> Self {
pub fn new(_rows: usize, cols: usize) -> Self {
SimKeyboard {
keys: 0,
active_row: None,
num_rows: rows,
num_cols: cols,
}
}
Expand Down
Loading