Skip to content

Commit

Permalink
implement central split direct pin run function
Browse files Browse the repository at this point in the history
  • Loading branch information
DivineGod committed Nov 14, 2024
1 parent a69882a commit 7e55532
Show file tree
Hide file tree
Showing 6 changed files with 381 additions and 40 deletions.
6 changes: 0 additions & 6 deletions rmk-config/src/toml_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,6 @@ 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,
}

Expand Down
117 changes: 86 additions & 31 deletions rmk-macro/src/split/central.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,18 @@ fn expand_split_central(
));
// `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;
let low_active = split_config.central.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;
});
*/
}
}

Expand Down Expand Up @@ -189,20 +187,39 @@ fn expand_split_central_entry(
} else {
format_ident!("{}", "usb")
};
let central_task = quote! {
::rmk::split::central::run_rmk_split_central::<
::embassy_stm32::gpio::Input<'_>,
::embassy_stm32::gpio::Output<'_>,
::embassy_stm32::#usb_mod_path::Driver<'_, ::embassy_stm32::peripherals::#usb_name>,
::embassy_stm32::flash::Flash<'_, ::embassy_stm32::flash::Blocking>,
ROW,
COL,
#central_row,
#central_col,
#central_row_offset,
#central_col_offset,
NUM_LAYER,
>(input_pins, output_pins, driver, flash, &mut get_default_keymap(), keyboard_config, spawner)
let low_active = split_config.central.matrix.direct_pin_low_active;
let central_task = match split_config.central.matrix.matrix_type {
MatrixType::normal => quote! {
::rmk::split::central::run_rmk_split_central::<
::embassy_stm32::gpio::Input<'_>,
::embassy_stm32::gpio::Output<'_>,
::embassy_stm32::#usb_mod_path::Driver<'_, ::embassy_stm32::peripherals::#usb_name>,
::embassy_stm32::flash::Flash<'_, ::embassy_stm32::flash::Blocking>,
ROW,
COL,
#central_row,
#central_col,
#central_row_offset,
#central_col_offset,
NUM_LAYER,
>(input_pins, output_pins, driver, flash, &mut get_default_keymap(), keyboard_config, , spawner)
},
MatrixType::direct_pin => quote! {
::rmk::split::central::run_rmk_split_central_direct_pin::<
::embassy_stm32::gpio::Input<'_>,
::embassy_stm32::gpio::Output<'_>,
::embassy_stm32::#usb_mod_path::Driver<'_, ::embassy_stm32::peripherals::#usb_name>,
::embassy_stm32::flash::Flash<'_, ::embassy_stm32::flash::Blocking>,
ROW,
COL,
#central_row,
#central_col,
#central_row_offset,
#central_col_offset,
NUM_LAYER,
SIZE,
>(direct_pins, driver, flash, &mut get_default_keymap(), keyboard_config, #low_active, spawner)
},
};
let mut tasks = vec![central_task];
let central_serials = split_config
Expand Down Expand Up @@ -236,19 +253,37 @@ fn expand_split_central_entry(
.central
.ble_addr
.expect("No ble_addr defined for central");
let central_task = quote! {
::rmk::split::central::run_rmk_split_central::<
::embassy_nrf::gpio::Input<'_>,
::embassy_nrf::gpio::Output<'_>,
::embassy_nrf::usb::Driver<'_, ::embassy_nrf::peripherals::USBD, &::embassy_nrf::usb::vbus_detect::SoftwareVbusDetect>,
ROW,
COL,
#central_row,
#central_col,
#central_row_offset,
#central_col_offset,
NUM_LAYER,
>(input_pins, output_pins, driver, &mut get_default_keymap(), keyboard_config, [#(#central_addr), *], spawner)
let low_active = split_config.central.matrix.direct_pin_low_active;
let central_task = match split_config.central.matrix.matrix_type {
MatrixType::normal => quote! {
::rmk::split::central::run_rmk_split_central::<
::embassy_nrf::gpio::Input<'_>,
::embassy_nrf::gpio::Output<'_>,
::embassy_nrf::usb::Driver<'_, ::embassy_nrf::peripherals::USBD, &::embassy_nrf::usb::vbus_detect::SoftwareVbusDetect>,
ROW,
COL,
#central_row,
#central_col,
#central_row_offset,
#central_col_offset,
NUM_LAYER,
>(input_pins, output_pins, driver, &mut get_default_keymap(), keyboard_config, [#(#central_addr), *], spawner)
},
MatrixType::direct_pin => quote! {
::rmk::split::central::run_rmk_split_central_direct_pin::<
::embassy_nrf::gpio::Input<'_>,
::embassy_nrf::gpio::Output<'_>,
::embassy_nrf::usb::Driver<'_, ::embassy_nrf::peripherals::USBD, &::embassy_nrf::usb::vbus_detect::SoftwareVbusDetect>,
ROW,
COL,
#central_row,
#central_col,
#central_row_offset,
#central_col_offset,
NUM_LAYER,
SIZE,
>(direct_pins, driver, &mut get_default_keymap(), keyboard_config, #low_active, [#(#central_addr), *], spawner)
},
};
let mut tasks = vec![central_task];
split_config.peripheral.iter().enumerate().for_each(|(idx, p)| {
Expand All @@ -267,7 +302,10 @@ fn expand_split_central_entry(
join_all_tasks(tasks)
}
ChipSeries::Rp2040 => {
let central_task = quote! {
let low_active = split_config.central.matrix.direct_pin_low_active;

let central_task = match split_config.central.matrix.matrix_type {
MatrixType::normal => quote! {
::rmk::split::central::run_rmk_split_central::<
::embassy_rp::gpio::Input<'_>,
::embassy_rp::gpio::Output<'_>,
Expand All @@ -281,6 +319,23 @@ fn expand_split_central_entry(
#central_col_offset,
NUM_LAYER,
>(input_pins, output_pins, driver, flash, &mut get_default_keymap(), keyboard_config, spawner)
},
MatrixType::direct_pin => quote! {
::rmk::split::central::run_rmk_split_central_direct_pin::<
::embassy_rp::gpio::Input<'_>,
::embassy_rp::gpio::Output<'_>,
::embassy_rp::usb::Driver<'_, ::embassy_rp::peripherals::USB>,
::embassy_rp::flash::Flash<::embassy_rp::peripherals::FLASH, ::embassy_rp::flash::Async, FLASH_SIZE>,
ROW,
COL,
#central_row,
#central_col,
#central_row_offset,
#central_col_offset,
NUM_LAYER,
SIZE,
>(direct_pins, driver, flash, &mut get_default_keymap(), keyboard_config, #low_active, spawner)
},
};
let mut tasks = vec![central_task];
let central_serials = split_config
Expand Down
6 changes: 5 additions & 1 deletion rmk-macro/src/split/peripheral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,25 @@ fn expand_split_peripheral_entry(
.expect("Missing central ble address");
let row = peripheral_config.rows;
let col = peripheral_config.cols;
let size = row + col;
let peripheral_addr = peripheral_config.ble_addr.expect(
"Peripheral should have a ble address, please check the `ble_addr` field in `keyboard.toml`",
);
let low_active = peripheral_config.matrix.direct_pin_low_active;
match peripheral_config.matrix.matrix_type {
MatrixType::direct_pin => {
quote! {
::rmk::split::peripheral::run_rmk_split_peripheral_direct_pin::<
::embassy_nrf::gpio::Input<'_>,
::embassy_nrf::gpio::Output<'_>,
#row,
#col
#col,
#size
> (
direct_pins,
[#(#central_addr), *],
[#(#peripheral_addr), *],
#low_active,
spawner,
).await
}
Expand Down
2 changes: 1 addition & 1 deletion rmk/src/direct_pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl<
) -> Self {
DirectPinMatrix {
direct_pins,
debouncer: debouncer,
debouncer,
key_states: [[KeyState::new(); COL]; ROW],
scan_start: None,
low_active,
Expand Down
Loading

0 comments on commit 7e55532

Please sign in to comment.