Skip to content

Commit 3da4642

Browse files
Merge pull request #108 from FrameworkComputer/adc
chromium_ec: Add adc_read
2 parents df87e97 + 03c750a commit 3da4642

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

framework_lib/src/chromium_ec/command.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub enum EcCommands {
4646
RebootEc = 0x00D2,
4747
/// Get information about PD controller power
4848
UsbPdPowerInfo = 0x0103,
49+
AdcRead = 0x0123,
4950
RgbKbdSetColor = 0x013A,
5051
RgbKbd = 0x013B,
5152

framework_lib/src/chromium_ec/commands.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,22 @@ impl EcRequest<EcResponseUsbPdPowerInfo> for EcRequestUsbPdPowerInfo {
518518
}
519519
}
520520

521+
#[repr(C, packed)]
522+
pub struct EcRequestAdcRead {
523+
/// ADC Channel, specific to each mainboard schematic
524+
pub adc_channel: u8,
525+
}
526+
527+
pub struct EcResponseAdcRead {
528+
pub adc_value: i32,
529+
}
530+
531+
impl EcRequest<EcResponseAdcRead> for EcRequestAdcRead {
532+
fn command_id() -> EcCommands {
533+
EcCommands::AdcRead
534+
}
535+
}
536+
521537
// TODO: Actually 128, but if we go above ~80 EC returns REQUEST_TRUNCATED
522538
// At least when I use the portio driver
523539
pub const EC_RGBKBD_MAX_KEY_COUNT: usize = 64;

framework_lib/src/chromium_ec/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,11 @@ impl CrosEc {
953953
Ok(res.val == 1)
954954
}
955955

956+
pub fn adc_read(&self, adc_channel: u8) -> EcResult<i32> {
957+
let res = EcRequestAdcRead { adc_channel }.send_command(self)?;
958+
Ok(res.adc_value)
959+
}
960+
956961
pub fn rgbkbd_set_color(&self, start_key: u8, colors: Vec<RgbS>) -> EcResult<()> {
957962
for (chunk, colors) in colors.chunks(EC_RGBKBD_MAX_KEY_COUNT).enumerate() {
958963
let mut request = EcRequestRgbKbdSetColor {

0 commit comments

Comments
 (0)