rmk_config/resolved/
hardware.rs1pub use crate::board::{BoardConfig, UniBodyConfig};
7pub use crate::chip::{ChipModel, ChipSeries};
8pub use crate::communication::{CommunicationConfig, UsbInfo};
9use crate::validate_unlock_keys;
10pub use crate::{
11 BleConfig, ChipConfig, CommunicationProtocol, DependencyConfig, DisplayConfig, DisplayDriver, EncoderConfig,
12 EncoderResolution, I2cConfig, InputDeviceConfig, Iqs5xxConfig, Iqs5xxI2cConfig, JoystickConfig, KeyInfo,
13 LightConfig, MatrixConfig, MatrixType, OutputConfig, PinConfig, Pmw33xxConfig, Pmw33xxType, Pmw3610Config,
14 PointingDeviceConfig, SerialConfig, SpiConfig, SplitBoardConfig, SplitConfig,
15};
16
17pub struct Storage {
19 pub start_addr: usize,
20 pub num_sectors: u8,
21 pub clear_storage: bool,
22 pub clear_layout: bool,
23}
24
25pub struct DfuConfig {
27 pub page_size: u32,
28 pub led: Option<PinConfig>,
29 pub unlock_keys: Vec<[u8; 2]>,
30}
31
32pub struct Hardware {
34 pub chip: ChipModel,
35 pub chip_config: ChipConfig,
36 pub communication: CommunicationConfig,
37 pub board: BoardConfig,
38 pub storage: Option<Storage>,
39 pub dfu: Option<DfuConfig>,
40 pub light: LightConfig,
41 pub display: Option<DisplayConfig>,
42 pub output: Vec<OutputConfig>,
43 pub dependency: DependencyConfig,
44}
45
46impl crate::KeyboardTomlConfig {
47 pub fn hardware(&self) -> Result<Hardware, String> {
49 let chip = self.get_chip_model()?;
50 let chip_config = self.get_chip_config();
51 let communication = self.get_communication_config()?;
52 let board = self.get_board_config()?;
53 let storage_toml = self.get_storage_config();
54 let storage = if storage_toml.enabled {
55 Some(Storage {
56 start_addr: storage_toml.start_addr.unwrap_or(0),
57 num_sectors: if self.get_dfu_config().is_some() {
58 if self.storage_user_set {
59 storage_toml.num_sectors.unwrap_or(8)
60 } else {
61 8
62 }
63 } else {
64 storage_toml.num_sectors.unwrap_or(2)
65 },
66 clear_storage: storage_toml.clear_storage.unwrap_or(false),
67 clear_layout: storage_toml.clear_layout.unwrap_or(false),
68 })
69 } else {
70 None
71 };
72 let dfu = match self.get_dfu_config() {
73 Some(d) => {
74 let unlock_keys = d.unlock_keys.clone().unwrap_or_default();
75 validate_unlock_keys("[dfu]", &unlock_keys, self.layout.as_ref())?;
76 Some(DfuConfig {
77 page_size: d.page_size.unwrap_or(4096),
78 led: d.led.clone().map(|pin| PinConfig { pin, low_active: false }),
79 unlock_keys,
80 })
81 }
82 None => None,
83 };
84 let light = self.get_light_config();
85 let display = self.get_display_config();
86 let output = self.get_output_config()?;
87 let dependency = self.get_dependency_config();
88 Ok(Hardware {
89 chip,
90 chip_config,
91 communication,
92 board,
93 storage,
94 dfu,
95 light,
96 display,
97 output,
98 dependency,
99 })
100 }
101}