Skip to content

Commit 1c52961

Browse files
JohnAZoidbergkiram9
andcommitted
chromium_ec: Implement GpioSet
Allow setting individual GPIOs. You need to be careful because the definitions can change between each platform and controlling some GPIOs can cause mainboard damaged if controlled in correctly. Co-Authored-by: Kieran Levin <ktl@frame.work> Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 0fe7727 commit 1c52961

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

framework_lib/src/chromium_ec/command.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub enum EcCommands {
3737
PwmGetDuty = 0x0026,
3838
SetTabletMode = 0x0031,
3939
AutoFanCtrl = 0x0052,
40+
GpioSet = 0x0092,
4041
GpioGet = 0x0093,
4142
I2cPassthrough = 0x009e,
4243
ConsoleSnapshot = 0x0097,

framework_lib/src/chromium_ec/commands.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,18 @@ impl EcRequest<()> for EcRequestAutoFanCtrlV1 {
452452
}
453453
}
454454

455+
#[repr(C, packed)]
456+
pub struct EcRequestGpioSetV0 {
457+
pub name: [u8; 32],
458+
pub value: u8,
459+
}
460+
461+
impl EcRequest<()> for EcRequestGpioSetV0 {
462+
fn command_id() -> EcCommands {
463+
EcCommands::GpioSet
464+
}
465+
}
466+
455467
#[repr(C, packed)]
456468
pub struct EcRequestGpioGetV0 {
457469
pub name: [u8; 32],

framework_lib/src/chromium_ec/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,19 @@ impl CrosEc {
15801580
.send_command(self)
15811581
}
15821582

1583+
pub fn set_gpio(&self, name: &str, value: bool) -> EcResult<()> {
1584+
const MAX_LEN: usize = 32;
1585+
let mut request = EcRequestGpioSetV0 {
1586+
name: [0; MAX_LEN],
1587+
value: value as u8,
1588+
};
1589+
1590+
let end = MAX_LEN.min(name.len());
1591+
request.name[..end].copy_from_slice(&name.as_bytes()[..end]);
1592+
1593+
request.send_command(self)?;
1594+
Ok(())
1595+
}
15831596
pub fn get_gpio(&self, name: &str) -> EcResult<bool> {
15841597
const MAX_LEN: usize = 32;
15851598
let mut request = EcRequestGpioGetV0 { name: [0; MAX_LEN] };

0 commit comments

Comments
 (0)