Skip to content

Commit

Permalink
Merge pull request #45 from hdhoang/reset-action
Browse files Browse the repository at this point in the history
Reset action
  • Loading branch information
ah- authored Mar 15, 2018
2 parents d8bd84d + 477ad53 commit 2bd5a84
Showing 4 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/action.rs
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ use keycodes::KeyCode;
#[derive(Copy, Clone, PartialEq)]
pub enum Action {
Nop,
Reset,
Transparent,

Key(KeyCode), // = 0x10
15 changes: 15 additions & 0 deletions src/keyboard.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@ use keymatrix::KeyState;
use layout::LAYERS;
use layout::LAYER_BT;
use led::Led;
use stm32l151::SCB;
use stm32l151::SYST;

pub struct Keyboard {
layers: Layers,
@@ -46,6 +48,8 @@ impl Keyboard {
state: &KeyState,
bluetooth: &mut Bluetooth<BUFFER>,
led: &mut Led<BUFFER>,
scb: &mut SCB,
syst: &SYST,
) where
BUFFER: Unsize<[u8]>,
{
@@ -60,6 +64,17 @@ impl Keyboard {
// cut down on processing time.
if *pressed || changed {
let action = self.get_action(key);
if let Action::Reset = action {
unsafe {
// write unlock: 0x05fa << 16
// SYSRESETREQ: 0b100
scb.aircr.write((0x05fa << 16) | 0b100);
let current_tick = syst.cvr.read();
let wait_until_tick = current_tick - 300;
while syst.cvr.read() > wait_until_tick {}
// Should be unreachable
}
}
hid.process(&action, *pressed, changed);
led.process(&action, *pressed, changed);
bluetooth.process(&action, *pressed, changed);
2 changes: 1 addition & 1 deletion src/layout.rs
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ pub const FN: Layout = layout![
__ __ Up __ LedToggle LED_NAS LED_NB LED_NT Up Scrolllock Pause Home End PScreen
__ Left Down Right __ __ __ Left Down Right PgUp PgDown No __
__ __ __ __ __ BT_ON __ __ __ Insert Delete No No __
__ __ __ No No __ No No No No __ __ __ __
__ __ __ No No Reset No No No No __ __ __ __
];

pub const FN2: Layout = layout![
13 changes: 10 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@ app! {
static BLUETOOTH: Bluetooth<[u8; 0x80]>;
static LED_BUFFERS: [[u8; 0x80]; 2] = [[0; 0x80]; 2];
static LED: Led<[u8; 0x80]>;
static SCB: stm32l151::SCB;
static SYST: stm32l151::SYST;
static EXTI: stm32l151::EXTI;
},
@@ -63,7 +64,7 @@ app! {
tasks: {
SYS_TICK: {
path: tick,
resources: [BLUETOOTH, LED, KEY_MATRIX, SYST, KEYBOARD],
resources: [BLUETOOTH, LED, KEY_MATRIX, SCB, SYST, KEYBOARD],
},
DMA1_CHANNEL2: {
path: led::tx,
@@ -173,6 +174,7 @@ fn init(mut p: init::Peripherals, r: init::Resources) -> init::LateResources {
BLUETOOTH: bluetooth,
KEY_MATRIX: key_matrix,
LED: led,
SCB: p.core.SCB,
SYST: p.core.SYST,
EXTI: d.EXTI,
}
@@ -186,8 +188,13 @@ fn idle() -> ! {

fn tick(_t: &mut Threshold, mut r: SYS_TICK::Resources) {
r.KEY_MATRIX.sample(&r.SYST);
r.KEYBOARD
.process(&r.KEY_MATRIX.state, &mut r.BLUETOOTH, &mut r.LED);
r.KEYBOARD.process(
&r.KEY_MATRIX.state,
&mut r.BLUETOOTH,
&mut r.LED,
&mut r.SCB,
&r.SYST,
);
}

fn exti0(_t: &mut Threshold, r: EXTI0::Resources) {

0 comments on commit 2bd5a84

Please sign in to comment.