Improve fan curve
- Implement fan cooldown and heatup periods - Add fan get/set commands - Fix compilation with logging level lower than debug
This commit is contained in:
BIN
tool/src/.ec.rs.swp
Normal file
BIN
tool/src/.ec.rs.swp
Normal file
Binary file not shown.
@ -19,12 +19,14 @@ pub enum Cmd {
|
||||
Print = 4,
|
||||
Spi = 5,
|
||||
Reset = 6,
|
||||
FanGet = 7,
|
||||
FanSet = 8,
|
||||
}
|
||||
|
||||
pub const CMD_SPI_FLAG_READ: u8 = (1 << 0);
|
||||
pub const CMD_SPI_FLAG_DISABLE: u8 = (1 << 1);
|
||||
pub const CMD_SPI_FLAG_SCRATCH: u8 = (1 << 2);
|
||||
pub const CMD_SPI_FLAG_BACKUP: u8 = (1 << 3);
|
||||
pub const CMD_SPI_FLAG_READ: u8 = 1 << 0;
|
||||
pub const CMD_SPI_FLAG_DISABLE: u8 = 1 << 1;
|
||||
pub const CMD_SPI_FLAG_SCRATCH: u8 = 1 << 2;
|
||||
pub const CMD_SPI_FLAG_BACKUP: u8 = 1 << 3;
|
||||
|
||||
pub struct Ec<T: Timeout> {
|
||||
cmd: u16,
|
||||
@ -181,6 +183,18 @@ impl<T: Timeout> Ec<T> {
|
||||
pub unsafe fn reset(&mut self) -> Result<(), Error> {
|
||||
self.command(Cmd::Reset)
|
||||
}
|
||||
|
||||
pub unsafe fn fan_get(&mut self, index: u8) -> Result<u8, Error> {
|
||||
self.write(2, index);
|
||||
self.command(Cmd::FanGet)?;
|
||||
Ok(self.read(3))
|
||||
}
|
||||
|
||||
pub unsafe fn fan_set(&mut self, index: u8, duty: u8) -> Result<(), Error> {
|
||||
self.write(2, index);
|
||||
self.write(3, duty);
|
||||
self.command(Cmd::FanSet)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EcSpi<'a, T: Timeout> {
|
||||
|
@ -274,9 +274,33 @@ unsafe fn print(message: &[u8]) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
unsafe fn fan_get(index: u8) -> Result<(), Error> {
|
||||
iopl();
|
||||
|
||||
let mut ec = Ec::new(
|
||||
StdTimeout::new(Duration::new(1, 0)),
|
||||
)?;
|
||||
|
||||
let duty = ec.fan_get(index)?;
|
||||
eprintln!("{}", duty);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
unsafe fn fan_set(index: u8, duty: u8) -> Result<(), Error> {
|
||||
iopl();
|
||||
|
||||
let mut ec = Ec::new(
|
||||
StdTimeout::new(Duration::new(1, 0)),
|
||||
)?;
|
||||
|
||||
ec.fan_set(index, duty)
|
||||
}
|
||||
|
||||
fn usage() {
|
||||
eprintln!(" console");
|
||||
eprintln!(" flash [file]");
|
||||
eprintln!(" fan [index] <duty>");
|
||||
eprintln!(" info");
|
||||
eprintln!(" print [message]");
|
||||
}
|
||||
@ -293,6 +317,40 @@ fn main() {
|
||||
process::exit(1);
|
||||
},
|
||||
},
|
||||
"fan" => match args.next() {
|
||||
Some(index_str) => match index_str.parse::<u8>() {
|
||||
Ok(index) => match args.next() {
|
||||
Some(duty_str) => match duty_str.parse::<u8>() {
|
||||
Ok(duty) => match unsafe { fan_set(index, duty) } {
|
||||
Ok(()) => (),
|
||||
Err(err) => {
|
||||
eprintln!("failed to set fan {} to {}: {:X?}", index, duty, err);
|
||||
process::exit(1);
|
||||
},
|
||||
},
|
||||
Err(err) => {
|
||||
eprintln!("failed to parse '{}': {:X?}", duty_str, err);
|
||||
process::exit(1);
|
||||
},
|
||||
},
|
||||
None => match unsafe { fan_get(index) } {
|
||||
Ok(()) => (),
|
||||
Err(err) => {
|
||||
eprintln!("failed to get fan {}: {:X?}", index, err);
|
||||
process::exit(1);
|
||||
},
|
||||
},
|
||||
},
|
||||
Err(err) => {
|
||||
eprintln!("failed to parse '{}': {:X?}", index_str, err);
|
||||
process::exit(1);
|
||||
},
|
||||
},
|
||||
None => {
|
||||
eprintln!("no index provided");
|
||||
process::exit(1);
|
||||
},
|
||||
},
|
||||
"flash" => match args.next() {
|
||||
Some(path) => match unsafe { flash(&path) } {
|
||||
Ok(()) => (),
|
||||
|
Reference in New Issue
Block a user