From ea57bd91c369560a1bc9bb8443acbecf717a3c0f Mon Sep 17 00:00:00 2001 From: Marc Poulhiès Date: Fri, 22 Jul 2022 21:01:16 +0200 Subject: rust: extract layout in separate module First step towards reusing for pouetpouet-r2: split! --- firmware/rust/src/layout.rs | 79 +++++++++++++++++++++++++++++++++++++++++++ firmware/rust/src/main.rs | 81 +++------------------------------------------ 2 files changed, 83 insertions(+), 77 deletions(-) create mode 100644 firmware/rust/src/layout.rs (limited to 'firmware') diff --git a/firmware/rust/src/layout.rs b/firmware/rust/src/layout.rs new file mode 100644 index 0000000..fa1fa25 --- /dev/null +++ b/firmware/rust/src/layout.rs @@ -0,0 +1,79 @@ +use keyberon::action::{k, l, m, Action::*, HoldTapConfig}; +use keyberon::key_code::KeyCode::*; + +type Action = keyberon::action::Action; + +#[derive(Debug, Clone, Copy, Eq, PartialEq)] +pub enum CustomActions { + LightUp, + LightDown, + + ModeCycle, + ColorCycle, + FreqUp, + FreqDown, +} + +pub static LU : CustomActions = CustomActions::LightUp; +pub static LD : CustomActions = CustomActions::LightDown; +pub static MC : CustomActions = CustomActions::ModeCycle; +pub static CC : CustomActions = CustomActions::ColorCycle; +pub static FU : CustomActions = CustomActions::FreqUp; +pub static FD : CustomActions = CustomActions::FreqDown; + +#[cfg(not(feature = "testmode"))] +#[rustfmt::skip] + +const D_ALT: Action = HoldTap { + timeout: 200, + tap_hold_interval: 0, + config: HoldTapConfig::Default, + hold: &k(LAlt), + tap: &k(D), +}; + +const K_ALT: Action = HoldTap { + timeout: 1000, + tap_hold_interval: 0, + config: HoldTapConfig::Default, + hold: &k(RAlt), + tap: &k(K), +}; + +const F_L1: Action = HoldTap { + timeout: 200, + tap_hold_interval: 0, + config: HoldTapConfig::Default, + hold: &l(1), + tap: &k(F), +}; + +pub static LAYERS: keyberon::layout::Layers<12, 5, 2, CustomActions> = keyberon::layout::layout! { + { + [Kb1 Kb2 Kb3 Kb4 Kb5 Grave Kb6 Kb7 Kb8 Kb9 Kb0 Minus] + [Q W E R T Tab Y U I O P LBracket] + [A S D F G BSpace H J K L SColon Quote] + [Z X C V B Enter N M Comma Dot Slash Bslash ] + [LCtrl (1) LGui LShift LAlt Space RAlt RBracket Equal Delete RShift RCtrl] + } + { + [F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12] + [SysReq NumLock t t t Escape Insert PgUp PgDown VolUp VolDown Mute ] + [t t t t t t Home Up End t t t ] + [NonUsBslash {Action::Custom(CC)} {Action::Custom(FU)} {Action::Custom(FD)} t t Left Down Right t t PgUp ] + [{Action::Custom(LU)} t {Action::Custom(LD)} {Action::Custom(MC)} t t t t t t t PgDown] + } +}; + +#[cfg(feature = "testmode")] +#[rustfmt::skip] +pub static LAYERS: keyberon::layout::Layers = keyberon::layout::layout! { + { + [A, A, A, A, A, A, A, A, A, A, A, A], + [A, A, A, A, A, A, A, A, A, A, A, A], + [A, A, A, A, A, A, A, A, A, A, A, A], + [A, A, A, A, A, A, A, A, A, A, A, A], + [A, A, A, A, A, A, A, A, A, A, A, A], + } +}; + diff --git a/firmware/rust/src/main.rs b/firmware/rust/src/main.rs index 20d232a..dab7512 100644 --- a/firmware/rust/src/main.rs +++ b/firmware/rust/src/main.rs @@ -8,8 +8,6 @@ use core::convert::Infallible; use keyberon::action::{k, l, Action::*, HoldTapConfig}; use keyberon::key_code::KeyCode::*; use keyberon::layout::{Event, Layout}; -type Action = keyberon::action::Action; - use keyberon::matrix::Matrix; use rtic::app; @@ -28,6 +26,9 @@ use hal::delay::Delay; use hal::gpio::{gpioa, Alternate, Input, Output, Pin, PullUp, PushPull, AF0}; use hal::prelude::*; +mod layout; +use layout::CustomActions; + use embedded_hal::spi::FullDuplex; use hal::usb; @@ -63,80 +64,6 @@ impl ResultExt for Result { } } -#[derive(Debug, Clone, Copy, Eq, PartialEq)] -pub enum CustomActions { - LightUp, - LightDown, - - ModeCycle, - ColorCycle, - FreqUp, - FreqDown, -} - -pub static LU : CustomActions = CustomActions::LightUp; -pub static LD : CustomActions = CustomActions::LightDown; -pub static MC : CustomActions = CustomActions::ModeCycle; -pub static CC : CustomActions = CustomActions::ColorCycle; -pub static FU : CustomActions = CustomActions::FreqUp; -pub static FD : CustomActions = CustomActions::FreqDown; - -#[cfg(not(feature = "testmode"))] -#[rustfmt::skip] - -const D_ALT: Action = HoldTap { - timeout: 200, - tap_hold_interval: 0, - config: HoldTapConfig::Default, - hold: &k(LAlt), - tap: &k(D), -}; - -const K_ALT: Action = HoldTap { - timeout: 1000, - tap_hold_interval: 0, - config: HoldTapConfig::Default, - hold: &k(RAlt), - tap: &k(K), -}; - -const F_L1: Action = HoldTap { - timeout: 200, - tap_hold_interval: 0, - config: HoldTapConfig::Default, - hold: &l(1), - tap: &k(F), -}; - -pub static LAYERS: keyberon::layout::Layers<12, 5, 2, CustomActions> = keyberon::layout::layout! { - { - [Kb1 Kb2 Kb3 Kb4 Kb5 Grave Kb6 Kb7 Kb8 Kb9 Kb0 Minus] - [Q W E R T Tab Y U I O P LBracket] - [A S D F G BSpace H J K L SColon Quote] - [Z X C V B Enter N M Comma Dot Slash Bslash ] - [LCtrl (1) LGui LShift LAlt Space RAlt RBracket Equal Delete RShift RCtrl] - } - { - [F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12] - [SysReq NumLock t t t Escape Insert PgUp PgDown VolUp VolDown Mute ] - [t t t t t t Home Up End t t t ] - [NonUsBslash {Action::Custom(CC)} {Action::Custom(FU)} {Action::Custom(FD)} t t Left Down Right t t PgUp ] - [{Action::Custom(LU)} t {Action::Custom(LD)} {Action::Custom(MC)} t t t t t t t PgDown] - } -}; - -#[cfg(feature = "testmode")] -#[rustfmt::skip] -pub static LAYERS: keyberon::layout::Layers = keyberon::layout::layout! { - { - [A, A, A, A, A, A, A, A, A, A, A, A], - [A, A, A, A, A, A, A, A, A, A, A, A], - [A, A, A, A, A, A, A, A, A, A, A, A], - [A, A, A, A, A, A, A, A, A, A, A, A], - [A, A, A, A, A, A, A, A, A, A, A, A], - } -}; - pub struct Leds { ws: ws2812::Ws2812, leds: [RGB8; 10], @@ -501,7 +428,7 @@ mod app { Shared { usb_dev, usb_class, - layout: Layout::new(&LAYERS), + layout: Layout::new(&crate::layout::LAYERS), backlight: Backlight { mode: BacklightMode::Off, brightness: 8, -- cgit v1.2.3