This repository has been archived on 2026-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
macropad-rs/src/layout.rs

237 lines
6.4 KiB
Rust

//! Module: layout.rs
//!
//! This module contains the layout of the macro keyboard (macropad), defining the arrangement of keys and their corresponding actions.
//!
//! It provides functionality for defining the physical layout of the macropad, mapping keys to specific actions or macros, and managing the layout configuration.
//!
// TODO: Add a macro to generate all this and most of the dispatch
use core::sync::atomic::AtomicBool;
use usbd_hid::descriptor::KeyboardReport;
use crate::keyboard::KeyCode;
// #[derive(Debug)]
pub(crate) static A1: AtomicBool = AtomicBool::new(false);
pub(crate) static B1: AtomicBool = AtomicBool::new(false);
pub(crate) static C1: AtomicBool = AtomicBool::new(false);
// pub(crate) enum Modkeys {
// A1,
// B1,
// C1,
// }
pub(crate) enum KeypadKey {
A1,
A2,
A3,
A4,
B1,
B2,
B3,
B4,
C1,
C2,
C3,
C4,
}
#[macro_export]
macro_rules! KR {
($($a:expr ),* ; $m:expr) => {
KeyboardReport {
modifier: $m as u8,
reserved: 0,
leds: 0,
keycodes: [$($a as u8, )*],
}
};
}
#[allow(dead_code)]
enum KeyMods {
None,
/// The Absence of modifier
LCtrl,
/// Left Shift.
LShift,
/// Left Alt.
LAlt,
/// Left GUI (the Windows key).
LGui,
/// Right Control.
RCtrl,
/// Right Shift.
RShift,
/// Right Alt (or Alt Gr).
RAlt,
/// Right GUI (the Windows key).
RGui, // 0xE7
}
pub(crate) const fn translate(symbol: &Layout) -> KeyboardReport {
match symbol {
Layout::a => KR!(KeyCode::Q,0,0,0,0,0;0),
Layout::b => KR!(KeyCode::B,0,0,0,0,0;0),
Layout::c => KR!(KeyCode::C,0,0,0,0,0;0),
Layout::d => KR!(KeyCode::D,0,0,0,0,0;0),
Layout::e => KR!(KeyCode::E,0,0,0,0,0;0),
Layout::f => KR!(KeyCode::F,0,0,0,0,0;0),
Layout::g => KR!(KeyCode::G,0,0,0,0,0;0),
Layout::h => KR!(KeyCode::H,0,0,0,0,0;0),
Layout::i => KR!(KeyCode::I,0,0,0,0,0;0),
Layout::j => KR!(KeyCode::J,0,0,0,0,0;0),
Layout::k => KR!(KeyCode::K,0,0,0,0,0;0),
Layout::l => KR!(KeyCode::L,0,0,0,0,0;0),
Layout::m => KR!(KeyCode::SColon, 0,0,0,0,0;0),
Layout::n => KR!(KeyCode::N,0,0,0,0,0;0),
Layout::o => KR!(KeyCode::O,0,0,0,0,0;0),
Layout::p => KR!(KeyCode::P,0,0,0,0,0;0),
Layout::q => KR!(KeyCode::A,0,0,0,0,0;0),
Layout::r => KR!(KeyCode::R,0,0,0,0,0;0),
Layout::s => KR!(KeyCode::S,0,0,0,0,0;0),
Layout::t => KR!(KeyCode::T,0,0,0,0,0;0),
Layout::u => KR!(KeyCode::U,0,0,0,0,0;0),
Layout::v => KR!(KeyCode::V,0,0,0,0,0;0),
Layout::w => KR!(KeyCode::Z,0,0,0,0,0;0),
Layout::x => KR!(KeyCode::X,0,0,0,0,0;0),
Layout::y => KR!(KeyCode::Y,0,0,0,0,0;0),
Layout::z => KR!(KeyCode::W,0,0,0,0,0;0),
Layout::A => KR!(KeyCode::Q,0,0,0,0,0;KeyMods::LShift),
Layout::B => KR!(KeyCode::B,0,0,0,0,0;KeyMods::LShift),
Layout::C => KR!(KeyCode::C,0,0,0,0,0;KeyMods::LShift),
Layout::D => KR!(KeyCode::D,0,0,0,0,0;KeyMods::LShift),
Layout::E => KR!(KeyCode::E,0,0,0,0,0;KeyMods::LShift),
Layout::F => KR!(KeyCode::F,0,0,0,0,0;KeyMods::LShift),
Layout::G => KR!(KeyCode::G,0,0,0,0,0;KeyMods::LShift),
Layout::H => KR!(KeyCode::H,0,0,0,0,0;KeyMods::LShift),
Layout::I => KR!(KeyCode::I,0,0,0,0,0;KeyMods::LShift),
Layout::J => KR!(KeyCode::J,0,0,0,0,0;KeyMods::LShift),
Layout::K => KR!(KeyCode::K,0,0,0,0,0;KeyMods::LShift),
Layout::L => KR!(KeyCode::L,0,0,0,0,0;KeyMods::LShift),
Layout::M => KR!(KeyCode::SColon,0,0,0,0,0;KeyMods::LShift),
Layout::N => KR!(KeyCode::N,0,0,0,0,0;KeyMods::LShift),
Layout::O => KR!(KeyCode::O,0,0,0,0,0;KeyMods::LShift),
Layout::P => KR!(KeyCode::P,0,0,0,0,0;KeyMods::LShift),
Layout::Q => KR!(KeyCode::A,0,0,0,0,0;KeyMods::LShift),
Layout::R => KR!(KeyCode::R,0,0,0,0,0;KeyMods::LShift),
Layout::S => KR!(KeyCode::S,0,0,0,0,0;KeyMods::LShift),
Layout::T => KR!(KeyCode::T,0,0,0,0,0;KeyMods::LShift),
Layout::U => KR!(KeyCode::U,0,0,0,0,0;KeyMods::LShift),
Layout::V => KR!(KeyCode::V,0,0,0,0,0;KeyMods::LShift),
Layout::W => KR!(KeyCode::Z,0,0,0,0,0;KeyMods::LShift),
Layout::X => KR!(KeyCode::X,0,0,0,0,0;KeyMods::LShift),
Layout::Y => KR!(KeyCode::Y,0,0,0,0,0;KeyMods::LShift),
Layout::Z => KR!(KeyCode::W,0,0,0,0,0;KeyMods::LShift),
Layout::nb1 => KR!(KeyCode::Kb1,0,0,0,0,0;KeyMods::LShift),
Layout::nb2 => KR!(KeyCode::Kb2,0,0,0,0,0;KeyMods::LShift),
Layout::nb3 => KR!(KeyCode::Kb3,0,0,0,0,0;KeyMods::LShift),
Layout::nb4 => KR!(KeyCode::Kb4,0,0,0,0,0;KeyMods::LShift),
Layout::nb5 => KR!(KeyCode::Kb5,0,0,0,0,0;KeyMods::LShift),
Layout::nb6 => KR!(KeyCode::Kb6,0,0,0,0,0;KeyMods::LShift),
Layout::nb7 => KR!(KeyCode::Kb7,0,0,0,0,0;KeyMods::LShift),
Layout::nb8 => KR!(KeyCode::Kb8,0,0,0,0,0;KeyMods::LShift),
Layout::nb9 => KR!(KeyCode::Kb9,0,0,0,0,0;KeyMods::LShift),
Layout::nb0 => KR!(KeyCode::Kb0,0,0,0,0,0;KeyMods::LShift),
Layout::amp => todo!(),
Layout::eacute => todo!(),
Layout::quote => todo!(),
Layout::squote => todo!(),
Layout::lparenth => todo!(),
Layout::minus => todo!(),
Layout::eagrave => todo!(),
Layout::underscore => todo!(),
Layout::cced => todo!(),
Layout::agrave => todo!(),
Layout::rparenth => todo!(),
Layout::equals => todo!(),
Layout::lessthan => todo!(),
Layout::morethan => todo!(),
Layout::pow => todo!(),
Layout::star => todo!(),
}
}
#[allow(non_camel_case_types, dead_code)]
pub(crate) enum Layout {
a,
b,
c,
d,
e,
f,
g,
h,
i,
j,
k,
l,
m,
n,
o,
p,
q,
r,
s,
t,
u,
v,
w,
x,
y,
z,
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q,
R,
S,
T,
U,
V,
W,
X,
Y,
Z,
nb1,
nb2,
nb3,
nb4,
nb5,
nb6,
nb7,
nb8,
nb9,
nb0,
amp,
eacute,
quote,
squote,
lparenth,
minus,
eagrave,
underscore,
cced,
agrave,
rparenth,
equals,
lessthan,
morethan,
pow,
star,
}