Skip to content

Commit af96787

Browse files
committed
Allow keyboard remapping
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent d515b02 commit af96787

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

framework_lib/src/chromium_ec/command.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub enum EcCommands {
6060
FlashNotified = 0x3E01,
6161
/// Change charge limit
6262
ChargeLimitControl = 0x3E03,
63+
UpdateKeyboardMatrix = 0x3E0C,
6364
/// Get/Set Fingerprint LED brightness
6465
FpLedLevelControl = 0x3E0E,
6566
/// Get information about the current chassis open/close status

framework_lib/src/chromium_ec/commands.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,31 @@ impl EcRequest<EcResponseFlashNotify> for EcRequestFlashNotify {
744744
}
745745
}
746746

747+
#[repr(C, packed)]
748+
pub struct KeyboardMatrixMap {
749+
pub row: u8,
750+
pub col: u8,
751+
pub scanset: u16,
752+
}
753+
#[repr(C, packed)]
754+
pub struct EcRequestUpdateKeyboardMatrix {
755+
pub num_items: u32,
756+
pub write: u32,
757+
pub scan_update: [KeyboardMatrixMap; 1],
758+
}
759+
#[repr(C, packed)]
760+
pub struct EcResponseUpdateKeyboardMatrix {
761+
pub num_items: u32,
762+
pub write: u32,
763+
pub scan_update: [KeyboardMatrixMap; 32],
764+
}
765+
766+
impl EcRequest<EcResponseUpdateKeyboardMatrix> for EcRequestUpdateKeyboardMatrix {
767+
fn command_id() -> EcCommands {
768+
EcCommands::UpdateKeyboardMatrix
769+
}
770+
}
771+
747772
#[repr(C, packed)]
748773
pub struct EcRequestChassisOpenCheck {}
749774

framework_lib/src/chromium_ec/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,20 @@ impl CrosEc {
353353
))
354354
}
355355

356+
pub fn remap_caps_to_ctrl(&self) -> EcResult<()> {
357+
self.remap_key(6, 15, 0x0014)
358+
}
359+
360+
pub fn remap_key(&self, row: u8, col: u8, scanset: u16) -> EcResult<()> {
361+
let _current_matrix = EcRequestUpdateKeyboardMatrix {
362+
num_items: 1,
363+
write: 1,
364+
scan_update: [KeyboardMatrixMap { row, col, scanset }],
365+
}
366+
.send_command(self)?;
367+
Ok(())
368+
}
369+
356370
/// Get current status of Framework Laptop's microphone and camera privacy switches
357371
/// [true = device enabled/connected, false = device disabled]
358372
pub fn get_privacy_info(&self) -> EcResult<(bool, bool)> {

0 commit comments

Comments
 (0)