Skip to content

Commit

Permalink
Fix windows driver
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Schaefer <[email protected]>
  • Loading branch information
JohnAZoidberg committed Oct 22, 2023
1 parent a929fbc commit d44b57d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion framework_lib/src/ccgx/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ impl PdController {
pub fn get_silicon_id(&self) -> EcResult<u16> {
let data = self.ccgx_read(ControlRegisters::SiliconId, 2)?;
assert!(data.len() >= 2);
debug_assert_eq!(data.len(), 2);
// TODO: The Windows driver seems to return 20 more bytes than expected
//debug_assert_eq!(data.len(), 2);
Ok(u16::from_le_bytes([data[0], data[1]]))
}

Expand Down
5 changes: 3 additions & 2 deletions framework_lib/src/chromium_ec/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ pub trait EcRequestRaw<R> {
Self: Sized,
{
let response = self.send_command_vec_extra(ec, extra_data)?;
if response.len() != std::mem::size_of::<R>() {
// TODO: The Windows driver seems to return 20 more bytes than expected
if response.len() < std::mem::size_of::<R>() {
return Err(EcError::DeviceError(format!(
"Returned data is not the expected ({}) size: {}",
"Returned data size ({}) is less than expected ({})",
response.len(),
std::mem::size_of::<R>()
)));
Expand Down
5 changes: 4 additions & 1 deletion framework_lib/src/chromium_ec/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ pub fn send_command(command: u16, command_version: u8, data: &[u8]) -> EcResult<
Some(status) => return Err(EcError::Response(status)),
}

let out_buffer = &cmd.buffer[..(returned as usize)];
// TODO: Figure out why that's sometimes bigger
let end = std::cmp::min(returned, 256);

let out_buffer = &cmd.buffer[..(end as usize)];
Ok(out_buffer.to_vec())
}

Expand Down

0 comments on commit d44b57d

Please sign in to comment.