Skip to content

Commit cc2bf45

Browse files
committed
Add K04 Micro firmware
1 parent 82976cf commit cc2bf45

19 files changed

Lines changed: 6717 additions & 14 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
keyboard: [k03, k04, imperial44, op36, velvet, velvet_ui]
16+
keyboard: [k03, k04, k04_micro, imperial44, op36, velvet, velvet_ui]
1717

1818
steps:
1919
- name: Checkout

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ RMK BLE split firmware for Ergohaven keyboards and trackballs (nRF52840).
1010
|-------------|----------------|----------|-----------|
1111
| K:03 | 5×6 + 5 thumb | 3+3 ||
1212
| K:04 | 5×6 + 5 thumb | 1+1 ||
13+
| K:04 Micro | 3×5 + 3 thumb | 1+1 ||
1314
| Imperial44 | 4×6 + 3 thumb | 1+1 ||
1415
| OP36 | 3×5 + 3 thumb |||
1516
| Velvet | 4×6 + 5 thumb |||

common/rmk-0.8.2-k04/src/keyboard.rs

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ const K04_USER_BT_OUTPUT: u8 = 37;
8181
const K04_USER_USB_OUTPUT: u8 = 38;
8282
const K04_USER_BATTERY_LEVEL: u8 = 39;
8383
const K04_USER_BT_CLEAR_PEER: u8 = 40;
84+
const K04_USER_MT_LALT_LPAREN: u8 = 41;
85+
const K04_USER_MT_LCTRL_RPAREN: u8 = 42;
86+
const K04_USER_MT_RCTRL_LBRACE: u8 = 43;
87+
const K04_USER_MT_RALT_RBRACE: u8 = 44;
88+
const K04_USER_MT_RGUI_EXCLAIM: u8 = 45;
89+
const K04_USER_MT_RGUI_BT_CLEAR: u8 = 46;
8490
const K04_RIGHT_SPLIT_PERIPHERAL_ID: usize = 0;
8591
const K04_MODE_TAPPING_TERM_MS: u32 = 200;
8692
const K04_LANG_EN: u8 = 0;
@@ -458,8 +464,10 @@ impl<'a, const ROW: usize, const COL: usize, const NUM_LAYER: usize, const NUM_E
458464
}
459465

460466
async fn process_key_action(&mut self, key_action: &KeyAction, event: KeyboardEvent, is_combo: bool) {
467+
let key_action = Self::k04_expand_custom_tap_hold(*key_action);
468+
461469
// First, make the decision for current key and held keys
462-
let (decision_for_current_key, decisions) = self.make_decisions_for_keys(key_action, event);
470+
let (decision_for_current_key, decisions) = self.make_decisions_for_keys(&key_action, event);
463471

464472
// Fire held keys if needed
465473
let (keyboard_state_updated, updated_decision_for_cur_key) =
@@ -471,23 +479,23 @@ impl<'a, const ROW: usize, const COL: usize, const NUM_LAYER: usize, const NUM_E
471479
debug!("Clean buffer, then process current key normally");
472480
let key_action = if keyboard_state_updated && !is_combo {
473481
// The key_action needs to be updated due to the morse key might be triggered
474-
&self.keymap.borrow_mut().get_action_with_layer_cache(event)
482+
Self::k04_expand_custom_tap_hold(self.keymap.borrow_mut().get_action_with_layer_cache(event))
475483
} else {
476484
key_action
477485
};
478-
self.process_key_action_inner(key_action, event).await
486+
self.process_key_action_inner(&key_action, event).await
479487
}
480488
KeyBehaviorDecision::Buffer => {
481489
debug!("Current key is buffered");
482490
let press_time = Instant::now();
483491
let timeout_time = if key_action.is_morse() {
484-
press_time + Self::morse_timeout(&self.keymap.borrow(), key_action, true)
492+
press_time + Self::morse_timeout(&self.keymap.borrow(), &key_action, true)
485493
} else {
486494
press_time
487495
};
488496
self.held_buffer.push(HeldKey::new(
489497
event,
490-
*key_action,
498+
key_action,
491499
KeyState::Pressed(MorsePattern::default()),
492500
press_time,
493501
timeout_time,
@@ -498,21 +506,21 @@ impl<'a, const ROW: usize, const COL: usize, const NUM_LAYER: usize, const NUM_E
498506
// Process current key normally
499507
let key_action = if keyboard_state_updated && !is_combo {
500508
// The key_action needs to be updated due to the morse key might be triggered
501-
&self.keymap.borrow_mut().get_action_with_layer_cache(event)
509+
Self::k04_expand_custom_tap_hold(self.keymap.borrow_mut().get_action_with_layer_cache(event))
502510
} else {
503511
key_action
504512
};
505-
self.process_key_action_inner(key_action, event).await
513+
self.process_key_action_inner(&key_action, event).await
506514
}
507515
KeyBehaviorDecision::FlowTap => {
508-
let action = Self::action_from_pattern(self.keymap.borrow().behavior, key_action, TAP); //tap action
516+
let action = Self::action_from_pattern(self.keymap.borrow().behavior, &key_action, TAP); //tap action
509517
self.process_key_action_normal(action, event).await;
510518
// Push back after triggered press
511519
let now = Instant::now();
512-
let time_out = now + Self::morse_timeout(&self.keymap.borrow(), key_action, true);
520+
let time_out = now + Self::morse_timeout(&self.keymap.borrow(), &key_action, true);
513521
self.held_buffer.push(HeldKey::new(
514522
event,
515-
*key_action,
523+
key_action,
516524
KeyState::ProcessedButReleaseNotReportedYet(action),
517525
now,
518526
time_out,
@@ -521,6 +529,40 @@ impl<'a, const ROW: usize, const COL: usize, const NUM_LAYER: usize, const NUM_E
521529
}
522530
}
523531

532+
fn k04_expand_custom_tap_hold(key_action: KeyAction) -> KeyAction {
533+
let KeyAction::Single(Action::Key(key)) = key_action else {
534+
return key_action;
535+
};
536+
if !key.is_user() {
537+
return key_action;
538+
}
539+
540+
let id = (key as u16 - KeyCode::User0 as u16) as u8;
541+
let Some((tap_key, hold_mod)) = (match id {
542+
K04_USER_MT_LALT_LPAREN => Some((KeyCode::Kc9, ModifierCombination::LALT)),
543+
K04_USER_MT_LCTRL_RPAREN => Some((KeyCode::Kc0, ModifierCombination::LCTRL)),
544+
K04_USER_MT_RCTRL_LBRACE => Some((KeyCode::LeftBracket, ModifierCombination::RCTRL)),
545+
K04_USER_MT_RALT_RBRACE => Some((KeyCode::RightBracket, ModifierCombination::RALT)),
546+
K04_USER_MT_RGUI_EXCLAIM => Some((KeyCode::Kc1, ModifierCombination::RGUI)),
547+
K04_USER_MT_RGUI_BT_CLEAR => {
548+
return KeyAction::TapHold(
549+
Action::Key(KeyCode::User26),
550+
Action::Modifier(ModifierCombination::RGUI),
551+
Default::default(),
552+
);
553+
}
554+
_ => None,
555+
}) else {
556+
return key_action;
557+
};
558+
559+
KeyAction::TapHold(
560+
Action::KeyWithModifier(tap_key, ModifierCombination::LSHIFT),
561+
Action::Modifier(hold_mod),
562+
Default::default(),
563+
)
564+
}
565+
524566
/// Fire held keys according to their decisions.
525567
///
526568
/// This function fires held keys according to their decisions, and returns
@@ -578,7 +620,9 @@ impl<'a, const ROW: usize, const COL: usize, const NUM_LAYER: usize, const NUM_E
578620
}
579621
HeldKeyDecision::PermissiveHold | HeldKeyDecision::HoldOnOtherKeyPress => {
580622
if let Some(mut held_key) = self.held_buffer.remove_if(|k| k.event.pos == pos) {
581-
let action = self.keymap.borrow_mut().get_action_with_layer_cache(held_key.event);
623+
let action = Self::k04_expand_custom_tap_hold(
624+
self.keymap.borrow_mut().get_action_with_layer_cache(held_key.event),
625+
);
582626

583627
if action.is_morse() {
584628
// Permissive hold of held key is triggered
@@ -620,7 +664,9 @@ impl<'a, const ROW: usize, const COL: usize, const NUM_LAYER: usize, const NUM_E
620664
// Releasing the current key, will always be tapping, because timeout isn't here
621665
if let Some(mut held_key) = self.held_buffer.remove_if(|k| k.event.pos == pos) {
622666
let key_action = if keyboard_state_updated {
623-
self.keymap.borrow_mut().get_action_with_layer_cache(held_key.event)
667+
Self::k04_expand_custom_tap_hold(
668+
self.keymap.borrow_mut().get_action_with_layer_cache(held_key.event),
669+
)
624670
} else {
625671
held_key.action
626672
};
@@ -677,7 +723,9 @@ impl<'a, const ROW: usize, const COL: usize, const NUM_LAYER: usize, const NUM_E
677723
if trigger_normal && let Some(held_key) = self.held_buffer.remove_if(|k| k.event.pos == pos) {
678724
debug!("Cleaning buffered normal key");
679725
let action = if keyboard_state_updated {
680-
self.keymap.borrow_mut().get_action_with_layer_cache(held_key.event)
726+
Self::k04_expand_custom_tap_hold(
727+
self.keymap.borrow_mut().get_action_with_layer_cache(held_key.event),
728+
)
681729
} else {
682730
held_key.action
683731
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2+
runner = "probe-rs run --chip nRF52840_xxAA"
3+
linker = "flip-link"
4+
5+
[build]
6+
target = "thumbv7em-none-eabihf"
7+
8+
[env]
9+
DEFMT_LOG = "info"
10+
KEYBOARD_TOML_PATH = { value = "keyboard.toml", relative = true }
11+
VIAL_JSON_PATH = { value = "vial.json", relative = true }

0 commit comments

Comments
 (0)