Skip to content

Commit

Permalink
feat(macro): add input device definition in toml
Browse files Browse the repository at this point in the history
Signed-off-by: Haobo Gu <[email protected]>
  • Loading branch information
HaoboGu committed Jan 2, 2025
1 parent 50ad5fa commit 54bf7c1
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions rmk-macro/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ pub enum MatrixType {
direct_pin,
}

#[allow(unused)]
#[derive(Clone, Debug, Default, Deserialize)]
pub struct MatrixConfig {
#[serde(default)]
Expand Down Expand Up @@ -176,6 +175,7 @@ pub struct SplitConfig {
/// Configurations for each split board
///
/// Either ble_addr or serial must be set, but not both.
#[allow(unused)]
#[derive(Clone, Debug, Default, Deserialize)]
pub struct SplitBoardConfig {
/// Row number of the split board
Expand All @@ -193,7 +193,7 @@ pub struct SplitBoardConfig {
/// Matrix config for the split
pub matrix: MatrixConfig,
/// Input device config for the split
pub input_device: InputDeviceConfig,
pub input_device: Option<InputDeviceConfig>,
}

/// Serial port config
Expand Down Expand Up @@ -238,17 +238,61 @@ fn parse_duration_millis<'de, D: de::Deserializer<'de>>(deserializer: D) -> Resu
/// Configurations for input devices
///
#[derive(Clone, Debug, Default, Deserialize)]
#[allow(unused)]
pub struct InputDeviceConfig {
pub encoder: Option<Vec<EncoderConfig>>,
pub pointing: Option<Vec<PointingDeviceConfig>>,
}

#[derive(Clone, Debug, Default, Deserialize)]
#[allow(unused)]
pub struct EncoderConfig {
// Pin a of the encoder
pub pin_a: String,
// Pin b of the encoder
pub pin_b: String,
pub pin_btn: Option<String>,
// Press button position in the keyboard matrix
// TODO: direct pin support?
pub btn_pos: Option<(u8, u8)>,
// Resolution
pub resolution: Option<u8>,
pub clockwise_pos: (u8, u8),
pub counter_clockwise_pos: (u8, u8),
pub press_pos: Option<(u8, u8)>,
}


/// Pointing device config
#[derive(Clone, Debug, Default, Deserialize)]
#[allow(unused)]
pub struct PointingDeviceConfig {
pub interface: Option<CommunicationProtocol>,
}

#[derive(Clone, Debug, Deserialize)]
#[allow(unused)]
pub enum CommunicationProtocol {
I2C(I2cConfig),
SPI(SpiConfig),
}

/// SPI config
#[derive(Clone, Debug, Default, Deserialize)]
#[allow(unused)]
pub struct SpiConfig {
pub instance: String,
pub sck: String,
pub mosi: String,
pub miso: String,
pub cs: Option<String>,
pub cpi: Option<u32>,
}

/// I2C config
#[derive(Clone, Debug, Default, Deserialize)]
#[allow(unused)]
pub struct I2cConfig {
pub instance: String,
pub sda: String,
pub scl: String,
pub address: u8,
}

0 comments on commit 54bf7c1

Please sign in to comment.