Skip to content
Merged
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
1 change: 1 addition & 0 deletions framework_lib/src/chromium_ec/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub enum EcCommands {
RebootEc = 0x00D2,
/// Get information about PD controller power
UsbPdPowerInfo = 0x0103,
AdcRead = 0x0123,
RgbKbdSetColor = 0x013A,
RgbKbd = 0x013B,

Expand Down
16 changes: 16 additions & 0 deletions framework_lib/src/chromium_ec/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,22 @@ impl EcRequest<EcResponseUsbPdPowerInfo> for EcRequestUsbPdPowerInfo {
}
}

#[repr(C, packed)]
pub struct EcRequestAdcRead {
/// ADC Channel, specific to each mainboard schematic
pub adc_channel: u8,
}

pub struct EcResponseAdcRead {
pub adc_value: i32,
}

impl EcRequest<EcResponseAdcRead> for EcRequestAdcRead {
fn command_id() -> EcCommands {
EcCommands::AdcRead
}
}

// TODO: Actually 128, but if we go above ~80 EC returns REQUEST_TRUNCATED
// At least when I use the portio driver
pub const EC_RGBKBD_MAX_KEY_COUNT: usize = 64;
Expand Down
5 changes: 5 additions & 0 deletions framework_lib/src/chromium_ec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,11 @@ impl CrosEc {
Ok(res.val == 1)
}

pub fn adc_read(&self, adc_channel: u8) -> EcResult<i32> {
let res = EcRequestAdcRead { adc_channel }.send_command(self)?;
Ok(res.adc_value)
}

pub fn rgbkbd_set_color(&self, start_key: u8, colors: Vec<RgbS>) -> EcResult<()> {
for (chunk, colors) in colors.chunks(EC_RGBKBD_MAX_KEY_COUNT).enumerate() {
let mut request = EcRequestRgbKbdSetColor {
Expand Down