Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions framework_lib/src/chromium_ec/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,30 @@ impl EcRequest<EcResponseDeckState> for EcRequestDeckState {
}
}

/// Same request as [`EcRequestDeckState`], but asks for the V1 response,
/// which includes the raw ADC voltage of each input deck mux position.
#[repr(C, packed)]
pub struct EcRequestDeckStateV1 {
pub mode: DeckStateMode,
}

#[repr(C, packed)]
pub struct EcResponseDeckStateV1 {
pub board_id: [u8; INPUT_DECK_SLOTS],
pub deck_state: u8,
/// Raw ADC reading in mV per mux position. 0xFFFF if the read failed
pub mv: [u16; INPUT_DECK_SLOTS],
}

impl EcRequest<EcResponseDeckStateV1> for EcRequestDeckStateV1 {
fn command_id() -> EcCommands {
EcCommands::CheckDeckState
}
fn command_version() -> u8 {
1
}
}

// TODO
#[repr(C, packed)]
pub struct EcRequestUefiAppMode {
Expand Down
12 changes: 12 additions & 0 deletions framework_lib/src/chromium_ec/input_deck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ pub const INPUT_DECK_SLOTS: usize = 8;
/// The number of slots on the top row of the input deck
pub const TOP_ROW_SLOTS: usize = 5;

/// Human readable names of the input deck mux positions, indexed by mux position
pub const INPUT_DECK_MUX_NAMES: [&str; INPUT_DECK_SLOTS] = [
"Top Row 0",
"Top Row 1",
"Top Row 2",
"Top Row 3",
"Top Row 4",
"Touchpad",
"Reserved",
"Hubboard",
];

#[repr(u8)]
enum InputDeckMux {
/// C1 all the way left
Expand Down
38 changes: 38 additions & 0 deletions framework_lib/src/chromium_ec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,9 +771,47 @@ impl CrosEc {
println!(" Pos 2: {:?}", status.top_row.pos2);
println!(" Pos 3: {:?}", status.top_row.pos3);
println!(" Pos 4: {:?}", status.top_row.pos4);

if let Some((ids, mvs)) = self.get_input_deck_raw()? {
println!("Raw Board IDs:");
for (i, name) in input_deck::INPUT_DECK_MUX_NAMES.iter().enumerate() {
if mvs[i] == 0xFFFF {
println!(" {:<10} ID {:>3} ADC read failed", name, ids[i]);
} else {
println!(" {:<10} ID {:>3} {:>4} mV", name, ids[i], mvs[i]);
}
}
}
Ok(())
}

/// Get the raw board ID and ADC voltage (in mV) of each input deck mux position
///
/// Returns `None` if the EC firmware doesn't support reporting the voltages
pub fn get_input_deck_raw(
&self,
) -> EcResult<
Option<(
[u8; input_deck::INPUT_DECK_SLOTS],
[u16; input_deck::INPUT_DECK_SLOTS],
)>,
> {
if !self
.cmd_version_supported(EcCommands::CheckDeckState as u32, 1)
.unwrap_or(false)
{
return Ok(None);
}
let res = EcRequestDeckStateV1 {
mode: DeckStateMode::ReadOnly,
}
.send_command(self)?;
// Copy out of the packed struct
let ids = res.board_id;
let mvs = res.mv;
Ok(Some((ids, mvs)))
}

pub fn set_input_deck_mode(&self, mode: DeckStateMode) -> EcResult<InputDeckStatus> {
let status = EcRequestDeckState { mode }.send_command(self)?;

Expand Down
Loading