Skip to content

Commit

Permalink
fix(direct-pins): rust cannot infer the specific type of options for …
Browse files Browse the repository at this point in the history
…shadowing variables

use {PIN}_{ROW_INDEX}_{COL_INDEX} as the variable name while constructing the direct-pin matrix.
support multi "None" gpio in one row for direct-pins matrix.
might be useful for some direct-pin keyboard with unconventional matrix.
  • Loading branch information
drindr committed Dec 3, 2024
1 parent dee5388 commit c44f1cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
4 changes: 2 additions & 2 deletions examples/use_config/rp2040_direct_pin/keyboard.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ direct_pin_low_active = true
direct_pins = [
["PIN_0", "PIN_1", "PIN_2"],
["PIN_3", "PIN_4", "PIN_5"],
["PIN_6", "_", "PIN_8"],
["PIN_6", "_", "_"],
["PIN_9", "PIN_10", "_"],
]

Expand All @@ -28,7 +28,7 @@ keymap = [
[
["A", "B", "C"],
["Kc1", "Kc2", "Kc3"],
["LCtrl", "_", "LShift"],
["LCtrl", "_", "_"],
["OSL(1)", "LT(2, Kc9)", "_"]
],
[
Expand Down
23 changes: 8 additions & 15 deletions rmk-macro/src/gpio_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,15 @@ pub(crate) fn convert_direct_pins_to_initializers(
let pin_initializers = row_pins
.into_iter()
.map(|p| {
(
p.clone(),
if p != "_" {
// Convert pin to Some(pin) when it's not "_"
let pin = convert_gpio_str_to_input_pin(chip, p, async_matrix, low_active);
quote! { Some(#pin) }
} else {
// Use None for "_" pins
quote! { None }
},
)
})
.map(|(p, ts)| {
let ident_name = format_ident!("{}_{}", p.to_lowercase(), row_idx);
let ident_name = format_ident!("{}_{}_{}", p.to_lowercase(), row_idx, col_idents.len());
col_idents.push(ident_name.clone());
quote! { let #ident_name = #ts; }
if p != "_" {
// Convert pin to Some(pin) when it's not "_"
let pin = convert_gpio_str_to_input_pin(chip, p, async_matrix, low_active);
quote! { let #ident_name = Some(#pin); }
} else {
quote! { let #ident_name = None; }
}
});
// Extend initializers with current row's pin initializations
initializers.extend(pin_initializers);
Expand Down

0 comments on commit c44f1cc

Please sign in to comment.