Skip to content

Commit

Permalink
WIP: Support Direct Pin matrix for split keyboards.
Browse files Browse the repository at this point in the history
* Update config to handle Matrix for split firmware
  • Loading branch information
DivineGod committed Nov 14, 2024
1 parent 52d0855 commit f318062
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 16 deletions.
3 changes: 3 additions & 0 deletions rmk-config/src/toml_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,13 @@ pub struct SplitBoardConfig {
pub ble_addr: Option<[u8; 6]>,
/// Serial config, the vector length should be 1 for peripheral
pub serial: Option<Vec<SerialConfig>>,
/*
/// Input pin config
pub input_pins: Vec<String>,
/// Output pin config
pub output_pins: Vec<String>,
*/
pub matrix: MatrixConfig,
}

/// Serial port config
Expand Down
46 changes: 38 additions & 8 deletions rmk-macro/src/split/central.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::panic;

use proc_macro2::TokenStream as TokenStream2;
use quote::{format_ident, quote};
use rmk_config::toml_config::{SerialConfig, SplitConfig};
use rmk_config::toml_config::{MatrixType, SerialConfig, SplitConfig};
use syn::ItemMod;

use crate::{
Expand All @@ -16,7 +16,7 @@ use crate::{
keyboard::gen_imports,
keyboard_config::{read_keyboard_toml_config, BoardConfig, KeyboardConfig},
light::expand_light_config,
matrix::expand_matrix_input_output_pins,
matrix::{expand_matrix_direct_pins, expand_matrix_input_output_pins},
ChipModel, ChipSeries,
};

Expand Down Expand Up @@ -75,12 +75,42 @@ fn expand_split_central(
let flash_init = expand_flash_init(keyboard_config);
let light_config = expand_light_config(keyboard_config);

let matrix_config = expand_matrix_input_output_pins(
&keyboard_config.chip,
split_config.central.input_pins.clone(),
split_config.central.output_pins.clone(),
async_matrix,
);
let mut matrix_config = proc_macro2::TokenStream::new();
match &split_config.central.matrix.matrix_type {
MatrixType::normal => {
matrix_config.extend(expand_matrix_input_output_pins(
&keyboard_config.chip,
split_config.central.matrix.input_pins.clone().unwrap(),
split_config.central.matrix.output_pins.clone().unwrap(),
async_matrix,
));
}
MatrixType::direct_pin => {
matrix_config.extend(expand_matrix_direct_pins(
&keyboard_config.chip,
split_config.central.matrix.direct_pins.clone().unwrap(),
async_matrix,
split_config.central.matrix.direct_pin_low_active,
));
// `generic_arg_infer` is a nightly feature. Const arguments cannot yet be inferred with `_` in stable now.
// So we need to declaring them in advance.
/*
let rows = keyboard_config.layout.rows as usize;
let cols = keyboard_config.layout.cols as usize;
let size = keyboard_config.layout.rows as usize * keyboard_config.layout.cols as usize;
let layers = keyboard_config.layout.layers as usize;
let low_active = peripheral_config.matrix.direct_pin_low_active;
matrix_config.extend(quote! {
pub(crate) const ROW: usize = #rows;
pub(crate) const COL: usize = #cols;
pub(crate) const SIZE: usize = #size;
pub(crate) const LAYER_NUM: usize = #layers;
let low_active = #low_active;
});
*/
}
}

let split_communication_config =
expand_split_communication_config(&keyboard_config.chip, split_config);
let run_rmk = expand_split_central_entry(keyboard_config, split_config);
Expand Down
47 changes: 39 additions & 8 deletions rmk-macro/src/split/peripheral.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use std::rc::Weak;

use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
use rmk_config::toml_config::SplitBoardConfig;
use rmk_config::toml_config::{MatrixType, SplitBoardConfig};
use syn::ItemMod;

use crate::{
chip_init::expand_chip_init,
feature::{get_rmk_features, is_feature_enabled},
import::expand_imports,
keyboard_config::{read_keyboard_toml_config, BoardConfig, KeyboardConfig},
matrix::expand_matrix_input_output_pins,
matrix::{expand_matrix_direct_pins, expand_matrix_input_output_pins},
split::central::expand_serial_init,
ChipModel, ChipSeries,
};
Expand Down Expand Up @@ -91,12 +93,41 @@ fn expand_split_peripheral(

let imports = expand_imports(&item_mod);
let chip_init = expand_chip_init(keyboard_config, &item_mod);
let matrix_config = expand_matrix_input_output_pins(
&keyboard_config.chip,
peripheral_config.input_pins.clone(),
peripheral_config.output_pins.clone(),
async_matrix,
);
let mut matrix_config = proc_macro2::TokenStream::new();
match &peripheral_config.matrix.matrix_type {
MatrixType::normal => {
matrix_config.extend(expand_matrix_input_output_pins(
&keyboard_config.chip,
peripheral_config.matrix.input_pins.clone().unwrap(),
peripheral_config.matrix.output_pins.clone().unwrap(),
async_matrix,
));
}
MatrixType::direct_pin => {
matrix_config.extend(expand_matrix_direct_pins(
&keyboard_config.chip,
peripheral_config.matrix.direct_pins.clone().unwrap(),
async_matrix,
peripheral_config.matrix.direct_pin_low_active,
));
// `generic_arg_infer` is a nightly feature. Const arguments cannot yet be inferred with `_` in stable now.
// So we need to declaring them in advance.
/*
let rows = keyboard_config.layout.rows as usize;
let cols = keyboard_config.layout.cols as usize;
let size = keyboard_config.layout.rows as usize * keyboard_config.layout.cols as usize;
let layers = keyboard_config.layout.layers as usize;
let low_active = peripheral_config.matrix.direct_pin_low_active;
matrix_config.extend(quote! {
pub(crate) const ROW: usize = #rows;
pub(crate) const COL: usize = #cols;
pub(crate) const SIZE: usize = #size;
pub(crate) const LAYER_NUM: usize = #layers;
let low_active = #low_active;
});
*/
}
}

let run_rmk_peripheral =
expand_split_peripheral_entry(&keyboard_config.chip, peripheral_config, &central_config);
Expand Down

0 comments on commit f318062

Please sign in to comment.