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 EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ Add `-vv` for more verbose details.

```
> sudo framework_tool --power
Battery Cutoff: Not cut off
Charger Status
AC is: not connected
Charger Voltage: 17048mV
Expand Down
2 changes: 2 additions & 0 deletions framework_lib/src/chromium_ec/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ pub enum EcCommands {
GetGpuPcie = 0x3E1E,
/// Set gpu bay serial and program structure
ProgramGpuEeprom = 0x3E1F,
/// Get battery cutoff (ship mode) status
GetCutoffStatus = 0x3E21,
/// Get PD port state from Cypress PD controller
GetPdPortState = 0x3E23,
/// Read board ID of specific ADC channel
Expand Down
18 changes: 18 additions & 0 deletions framework_lib/src/chromium_ec/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,24 @@ pub enum BoardIdType {
DGpu1 = 5,
}

#[repr(C, packed)]
pub struct EcRequestGetCutoffStatus {}

#[repr(C, packed)]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct EcResponseGetCutoffStatus {
/// Non-zero if the battery has been cut off (ship mode), zero otherwise.
/// The EC's battery_is_cut_off() returns a plain boolean here, not the
/// full battery_cutoff_states enum.
pub status: u8,
}

impl EcRequest<EcResponseGetCutoffStatus> for EcRequestGetCutoffStatus {
fn command_id() -> EcCommands {
EcCommands::GetCutoffStatus
}
}

#[repr(C, packed)]
pub struct EcRequestReadBoardId {
/// See BoardIdType
Expand Down
15 changes: 15 additions & 0 deletions framework_lib/src/power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,22 @@ pub fn is_standalone(ec: &CrosEc) -> bool {
}
}

/// Query battery cutoff (ship mode) status.
pub fn get_cutoff_status(ec: &CrosEc) -> Option<bool> {
(EcRequestGetCutoffStatus {})
.send_command(ec)
.ok()
.map(|res| res.status != 0)
}

pub fn get_and_print_power_info(ec: &CrosEc) -> i32 {
print!("Battery Cutoff: ");
match get_cutoff_status(ec) {
Some(true) => println!("Cut off"),
Some(false) => println!("Not cut off"),
None => println!("Unknown"),
}

if let Some(power_info) = power_info(ec) {
print_err_ref(&ec.get_charge_state(&power_info));
print_battery_information(&power_info);
Expand Down
Loading