Skip to content

Commit 42c5803

Browse files
committed
power: Add function to get accel data
Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent d46e741 commit 42c5803

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

framework_lib/src/power.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ impl fmt::Display for AccelData {
185185
}
186186
}
187187

188-
189188
fn read_string(ec: &CrosEc, address: u16) -> String {
190189
let bytes = ec.read_memory(address, EC_MEMMAP_TEXT_MAX).unwrap();
191190
String::from_utf8_lossy(bytes.as_slice()).replace(['\0'], "")
@@ -220,6 +219,25 @@ pub fn get_als_reading(ec: &CrosEc) -> Option<u32> {
220219
Some(u32::from_le_bytes([als[0], als[1], als[2], als[3]]))
221220
}
222221

222+
pub fn get_accel_data(ec: &CrosEc) -> (AccelData, AccelData, u16) {
223+
// bit 4 = busy
224+
// bit 7 = present
225+
// #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
226+
let _acc_status = ec.read_memory(EC_MEMMAP_ACC_STATUS, 0x01).unwrap()[0];
227+
// While busy, keep reading
228+
229+
let lid_angle = ec.read_memory(EC_MEMMAP_ACC_DATA, 0x02).unwrap();
230+
let lid_angle = u16::from_le_bytes([lid_angle[0], lid_angle[1]]);
231+
let accel_1 = ec.read_memory(EC_MEMMAP_ACC_DATA + 2, 0x06).unwrap();
232+
let accel_2 = ec.read_memory(EC_MEMMAP_ACC_DATA + 8, 0x06).unwrap();
233+
234+
// TODO: Make sure we got a new sample
235+
// println!(" Status Bit: {} 0x{:X}", acc_status, acc_status);
236+
// println!(" Present: {}", (acc_status & 0x80) > 0);
237+
// println!(" Busy: {}", (acc_status & 0x8) > 0);
238+
(AccelData::from(accel_1), AccelData::from(accel_2), lid_angle)
239+
}
240+
223241
pub fn print_sensors(ec: &CrosEc) {
224242
let als_int = get_als_reading(ec).unwrap();
225243
println!("ALS: {:>4} Lux", als_int);

0 commit comments

Comments
 (0)