Skip to content

Commit ee39a10

Browse files
committed
battery passthrough
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent bb87855 commit ee39a10

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

framework_lib/src/battery.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// https://www.ti.com/lit/ug/sluua43a/sluua43a.pdf?ts=1763375446472
2+
// driver/battery/smart.c
3+
// include/battery_smart.h
4+
use alloc::vec::Vec;
5+
use num_traits::FromPrimitive;
6+
7+
use crate::chromium_ec::command::EcRequestRaw;
8+
use crate::chromium_ec::commands::{EcRequestGetGpuPcie, GpuVendor};
9+
use crate::chromium_ec::i2c_passthrough::*;
10+
use crate::chromium_ec::{CrosEc, EcResult};
11+
use crate::os_specific;
12+
13+
14+
15+
pub fn dump_data(ec: &CrosEc) -> EcResult<Option<Vec<u8>>> {
16+
// I2C Port on the EC
17+
let i2c_port = 3;
18+
// 8-bit I2C address of the battery
19+
// EC passthrough needs 7-bit, so shift one over before sending to EC
20+
let i2c_addr = 0x0b << 1;
21+
22+
// Check mode
23+
let i2c_response = i2c_read(ec, i2c_port, i2c_addr >> 1, 0x03, 0x01)?;
24+
println!("Mode: {:?}", i2c_response.data);
25+
let i2c_response = i2c_read(ec, i2c_port, i2c_addr >> 1, 0x1c, 0x02)?;
26+
println!("Serial: {:X?}", i2c_response.data);
27+
let i2c_response = i2c_read(ec, i2c_port, i2c_addr >> 1, 0x08, 0x02)?;
28+
println!("Temp: {:X?}", i2c_response.data);
29+
let i2c_response = i2c_read(ec, i2c_port, i2c_addr >> 1, 0x17, 0x02)?;
30+
println!("Cycle Ct: {:?}", i2c_response.data);
31+
let i2c_response = i2c_read(ec, i2c_port, i2c_addr >> 1, 0x21, 0x08)?;
32+
// 0A 46 52 41
33+
println!("Dev Name: {:X?}", i2c_response.data);
34+
35+
// i2c_write(ec, i2c_port, (i2c_addr + 2) >> 1, 0x70, &[0x00])?;
36+
// os_specific::sleep(50_000);
37+
38+
Ok(Some(i2c_response.data))
39+
}

framework_lib/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub mod usbhub;
3434
#[macro_use]
3535
extern crate uefi_services;
3636

37+
pub mod battery;
3738
pub mod capsule;
3839
pub mod capsule_content;
3940
pub mod ccgx;

framework_lib/src/power.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ pub fn is_standalone(ec: &CrosEc) -> bool {
536536
}
537537

538538
pub fn get_and_print_power_info(ec: &CrosEc) -> i32 {
539+
crate::battery::dump_data(ec);
539540
if let Some(power_info) = power_info(ec) {
540541
print_err_ref(&ec.get_charge_state(&power_info));
541542
print_battery_information(&power_info);

0 commit comments

Comments
 (0)