228 lines
9.0 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! Project: CMtec CMDR Keyboard
//! Date: 2025-03-09
//! Author: Christoffer Martinsson
//! Email: cm@cmtec.se
//! License: Please refer to LICENSE in root directory
// Button index map:
// ------------------------------------- -------------------------------------
// | 0 | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 10 | 11 |
// | 12 | 13 | 14 | 15 | 16 | 17 | | 18 | 19 | 20 | 21 | 22 | 23 |
// | 24 | 25 | 26 | 27 | 28 | 29 | | 30 | 31 | 32 | 33 | 34 | 35 |
// ------------------| 39 | 40 | 41 | | 42 | 43 | 44 |------------------
// 36 37 38 ------------------- ------------------- 45 46 47
//
// Swedish keymap conversion table:
// US Swedish
// --------------------------
// Grave §
// Semicolon ö
// Apostrophe ä
// LeftBrace å
// ForwardSlash -
// NonUSBackslash <
// Equal ´
// Backslash '
// RightBrace ^
// Minus +
// LeftAlt Alt
// RightAlt AltGr
use crate::NUMBER_OF_KEYS;
use usbd_human_interface_device::page::Keyboard;
/// Function (Fn) buttons index (need two buttons)
/// Button 41 are used both as Fn and RightAlt (AltGr) for better ergonomics.
/// This means that RightAlt is only available on layer 1 keys.
pub const FN_BUTTONS: [u8; 3] = [40, 43, 44];
/// Sticky button [index, layer]
pub const STICKY_BUTTON: [u8; 2] = [7, 2];
/// OS Lock button [index, layer]
pub const OS_LOCK_BUTTON: [u8; 2] = [9, 2];
pub const OS_LOCK_BUTTON_KEYS: [Keyboard; 2] = [Keyboard::LeftGUI, Keyboard::L];
/// Button map to HID key (three Function layers)
pub const MAP: [[Keyboard; NUMBER_OF_KEYS]; 3] = [
[
// Function layer 0
// HID Key // Button Index
// -----------------------------------------
Keyboard::Tab, // 0
Keyboard::Q, // 1
Keyboard::W, // 2
Keyboard::E, // 3
Keyboard::R, // 4
Keyboard::T, // 5
Keyboard::Y, // 6
Keyboard::U, // 7
Keyboard::I, // 8
Keyboard::O, // 9
Keyboard::P, // 10
Keyboard::LeftBrace, // 11 å
Keyboard::LeftControl, // 12
Keyboard::A, // 13
Keyboard::S, // 14
Keyboard::D, // 15
Keyboard::F, // 16
Keyboard::G, // 17
Keyboard::H, // 18
Keyboard::J, // 19
Keyboard::K, // 20
Keyboard::L, // 21
Keyboard::Semicolon, // 22 ö
Keyboard::Apostrophe, // 23 ä
Keyboard::LeftShift, // 24
Keyboard::Z, // 25
Keyboard::X, // 26
Keyboard::C, // 27
Keyboard::V, // 28
Keyboard::B, // 29
Keyboard::N, // 30
Keyboard::M, // 31
Keyboard::Comma, // 32
Keyboard::Dot, // 33
Keyboard::ForwardSlash, // 34 -
Keyboard::RightShift, // 35
Keyboard::NoEventIndicated, // 36 no button connected
Keyboard::NoEventIndicated, // 37 no button connected
Keyboard::NoEventIndicated, // 38 no button connected
Keyboard::LeftAlt, // 39
Keyboard::NoEventIndicated, // 40 Fn (= will never trigg this layer)
Keyboard::Space, // 41
Keyboard::ReturnEnter, // 42
Keyboard::NoEventIndicated, // 43 Fn (= will never trigg this layer)
Keyboard::NoEventIndicated, // 44 Fn (= will never trigg this layer)
Keyboard::NoEventIndicated, // 45 no button connected
Keyboard::NoEventIndicated, // 46 no button connected
Keyboard::NoEventIndicated, // 47 no button connected
],
[
// Function layer 1
// HID Key // Button Index
// -----------------------------------------
Keyboard::Escape, // 0
Keyboard::F1, // 1
Keyboard::F2, // 2
Keyboard::F3, // 3
Keyboard::F4, // 4
Keyboard::F5, // 5
Keyboard::F6, // 6
Keyboard::F7, // 7
Keyboard::F8, // 8
Keyboard::F9, // 9
Keyboard::F10, // 10
Keyboard::DeleteBackspace, // 11
Keyboard::LeftControl, // 12
Keyboard::Keyboard1, // 13
Keyboard::Keyboard2, // 14
Keyboard::Keyboard3, // 15
Keyboard::Keyboard4, // 16
Keyboard::Keyboard5, // 17
Keyboard::Keyboard6, // 18
Keyboard::Keyboard7, // 19
Keyboard::Keyboard8, // 20
Keyboard::Keyboard9, // 21
Keyboard::Keyboard0, // 22
Keyboard::ReturnEnter, // 23
Keyboard::LeftShift, // 24
Keyboard::Keyboard6, // 25
Keyboard::Keyboard7, // 26
Keyboard::Keyboard8, // 27
Keyboard::Keyboard9, // 28
Keyboard::Keyboard0, // 29
Keyboard::NonUSBackslash, // 30 <
Keyboard::Equal, // 31 ´
Keyboard::Backslash, // 32 '
Keyboard::RightBrace, // 33 ^
Keyboard::Minus, // 34 +
Keyboard::RightShift, // 35
Keyboard::NoEventIndicated, // 36 no button connected
Keyboard::NoEventIndicated, // 37 no button connected
Keyboard::NoEventIndicated, // 38 no button connected
Keyboard::LeftAlt, // 39
Keyboard::NoEventIndicated, // 40 Fn
Keyboard::DeleteBackspace, // 41
Keyboard::DeleteBackspace, // 42
Keyboard::NoEventIndicated, // 43 Fn
Keyboard::RightAlt, // 44 Fn
Keyboard::NoEventIndicated, // 45 no button connected
Keyboard::NoEventIndicated, // 46 no button connected
Keyboard::NoEventIndicated, // 47 no button connected
],
[
// Function layer 2
// HID Key // Button Index
// -----------------------------------------
Keyboard::Escape, // 0
Keyboard::F11, // 1
Keyboard::F12, // 2
Keyboard::F13, // 3
Keyboard::F14, // 4
Keyboard::PrintScreen, // 5
Keyboard::Grave, // 6 §
Keyboard::NoEventIndicated, // 7 STICKY lock
Keyboard::LeftGUI, // 8
Keyboard::NoEventIndicated, // 9 OS Lock
Keyboard::CapsLock, // 10
Keyboard::DeleteForward, // 11
Keyboard::LeftControl, // 12
Keyboard::F15, // 13
Keyboard::F16, // 14
Keyboard::F17, // 15
Keyboard::F18, // 16
Keyboard::F19, // 17
Keyboard::LeftArrow, // 18
Keyboard::DownArrow, // 19
Keyboard::UpArrow, // 20
Keyboard::RightArrow, // 21
Keyboard::DeleteForward, // 22
Keyboard::ReturnEnter, // 23
Keyboard::LeftShift, // 24
Keyboard::F20, // 25
Keyboard::F21, // 26
Keyboard::F22, // 27
Keyboard::F23, // 28
Keyboard::F24, // 29
Keyboard::Home, // 30
Keyboard::PageDown, // 31
Keyboard::PageUp, // 32
Keyboard::End, // 33
Keyboard::Insert, // 34
Keyboard::RightShift, // 35
Keyboard::NoEventIndicated, // 36 no button connected
Keyboard::NoEventIndicated, // 37 no button connected
Keyboard::NoEventIndicated, // 38 no button connected
Keyboard::LeftAlt, // 39
Keyboard::NoEventIndicated, // 40 Fn
Keyboard::LeftGUI, // 41
Keyboard::DeleteBackspace, // 42
Keyboard::NoEventIndicated, // 43 Fn
Keyboard::NoEventIndicated, // 44 Fn
Keyboard::NoEventIndicated, // 45 no button connected
Keyboard::NoEventIndicated, // 46 no button connected
Keyboard::NoEventIndicated, // 47 no button connected
],
];
#[cfg(all(test, feature = "std"))]
mod tests {
use super::*;
#[test]
fn layer_map_dimensions_match() {
// Validate each layer exposes exactly one mapping per physical key index.
for layer in MAP.iter() {
assert_eq!(layer.len(), NUMBER_OF_KEYS);
}
}
#[test]
fn fn_buttons_are_unique() {
// Ensure every Fn button index is distinct so layer counting stays reliable.
assert_ne!(FN_BUTTONS[0], FN_BUTTONS[1]);
assert_ne!(FN_BUTTONS[0], FN_BUTTONS[2]);
}
}