Skip to content

Commit 832e385

Browse files
committed
feat: add default from chip for UsbInfo
Signed-off-by: Haobo Gu <[email protected]>
1 parent ae79d1e commit 832e385

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

rmk-macro/gen_usb_map.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
use std::collections::HashMap;
6666
use once_cell::sync::Lazy;
6767
68+
use crate::{ChipModel, ChipSeries};
69+
6870
static USB_INFO: Lazy<HashMap<String, UsbInfo>> = Lazy::new(|| {
6971
let mut m = HashMap::new();
7072
m.insert("nrf52840".to_string(), UsbInfo::new("", "", "USBD", "USBD"));
@@ -92,6 +94,20 @@
9294
interrupt_name: i.to_string(),
9395
}
9496
}
97+
98+
pub(crate) fn new_default(chip: &ChipModel) -> Self {
99+
match chip.series {
100+
ChipSeries::Stm32 => UsbInfo::new("PA11", "PA12", "USB_OTG_FS", "USB_FS"),
101+
ChipSeries::Nrf52 => UsbInfo::new("", "", "USBD", "USBD"),
102+
ChipSeries::Rp2040 => UsbInfo::new("", "", "USB", "USBCTRL_IRQ"),
103+
_ => UsbInfo::new(
104+
"default_dm",
105+
"default_dp",
106+
"default_usb_peripheral",
107+
"default_usb_interrupt",
108+
),
109+
}
110+
}
95111
}
96112
97113

rmk-macro/src/keyboard.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ pub(crate) fn parse_keyboard_mod(attr: proc_macro::TokenStream, item_mod: ItemMo
7878
.into();
7979
}
8080

81+
if !chip.has_usb()
82+
&& (comm_type == CommunicationType::Usb || comm_type == CommunicationType::Both)
83+
{
84+
return quote! {
85+
compile_error!("The chip specified in `keyboard.toml` doesn't have a general USB peripheral, please check again. Or you can set `usb_enable = false` in `[keyboard]` section of `keyboard.toml`");
86+
}
87+
.into();
88+
}
89+
8190
let usb_info = if comm_type == CommunicationType::Usb || comm_type == CommunicationType::Both {
8291
if let Some(usb_info) = get_usb_info(&chip.chip.to_lowercase()) {
8392
usb_info
@@ -91,14 +100,6 @@ pub(crate) fn parse_keyboard_mod(attr: proc_macro::TokenStream, item_mod: ItemMo
91100
UsbInfo::default()
92101
};
93102

94-
if !chip.has_usb()
95-
&& (comm_type == CommunicationType::Usb || comm_type == CommunicationType::Both)
96-
{
97-
return quote! {
98-
compile_error!("The chip specified in `keyboard.toml` doesn't have a general USB peripheral, please check again!");
99-
}
100-
.into();
101-
}
102103

103104
// Create keyboard info and vial struct
104105
let keyboard_info_static_var = expand_keyboard_info(

rmk-macro/src/usb_interrupt_map.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use std::collections::HashMap;
66
use once_cell::sync::Lazy;
77

8+
use crate::{ChipModel, ChipSeries};
9+
810
static USB_INFO: Lazy<HashMap<String, UsbInfo>> = Lazy::new(|| {
911
let mut m = HashMap::new();
1012
m.insert("nrf52840".to_string(), UsbInfo::new("", "", "USBD", "USBD"));
@@ -1038,6 +1040,20 @@ impl UsbInfo {
10381040
interrupt_name: i.to_string(),
10391041
}
10401042
}
1043+
1044+
pub(crate) fn new_default(chip: &ChipModel) -> Self {
1045+
match chip.series {
1046+
ChipSeries::Stm32 => UsbInfo::new("PA11", "PA12", "USB_OTG_FS", "USB_FS"),
1047+
ChipSeries::Nrf52 => UsbInfo::new("", "", "USBD", "USBD"),
1048+
ChipSeries::Rp2040 => UsbInfo::new("", "", "USB", "USBCTRL_IRQ"),
1049+
_ => UsbInfo::new(
1050+
"default_dm",
1051+
"default_dp",
1052+
"default_usb_peripheral",
1053+
"default_usb_interrupt",
1054+
),
1055+
}
1056+
}
10411057
}
10421058

10431059

0 commit comments

Comments
 (0)