diff --git a/ecsim b/ecsim index 19e16b1..3fd9b10 160000 --- a/ecsim +++ b/ecsim @@ -1 +1 @@ -Subproject commit 19e16b1ce3e175b14665073a47ef8a446cb988d6 +Subproject commit 3fd9b10bc7da755e9aa7507f37bfdb4fa6a532bb diff --git a/ecspy b/ecspy index 4be3d51..b3bde0a 160000 --- a/ecspy +++ b/ecspy @@ -1 +1 @@ -Subproject commit 4be3d5169f627539875252b124a83038c63e911d +Subproject commit b3bde0a1be6a8e3e473f56f9bc94028a34ee8289 diff --git a/src/common/include/common/command.h b/src/common/include/common/command.h index 3043cc0..1e74bef 100644 --- a/src/common/include/common/command.h +++ b/src/common/include/common/command.h @@ -34,6 +34,10 @@ enum Command { CMD_LED_GET_COLOR = 13, // Set LED color by index CMD_LED_SET_COLOR = 14, + // Get LED matrix mode and speed + CMD_LED_GET_MODE = 15, + // Set LED matrix mode and speed + CMD_LED_SET_MODE = 16, //TODO }; diff --git a/tool/src/ec.rs b/tool/src/ec.rs index ab82d0b..9e0738d 100644 --- a/tool/src/ec.rs +++ b/tool/src/ec.rs @@ -31,6 +31,8 @@ enum Cmd { LedSetValue = 12, LedGetColor = 13, LedSetColor = 14, + LedGetMode = 15, + LedSetMode = 16, } const CMD_SPI_FLAG_READ: u8 = 1 << 0; @@ -247,6 +249,26 @@ impl Ec { self.command(Cmd::LedSetColor, &mut data) } + pub unsafe fn led_get_mode(&mut self) -> Result<(u8, u8), Error> { + let mut data = [ + 0, + 0, + ]; + self.command(Cmd::LedGetMode, &mut data)?; + Ok(( + data[0], + data[1] + )) + } + + pub unsafe fn led_set_mode(&mut self, mode: u8, speed: u8) -> Result<(), Error> { + let mut data = [ + mode, + speed, + ]; + self.command(Cmd::LedSetMode, &mut data) + } + pub fn into_dyn(self) -> Ec> where A: 'static { Ec { diff --git a/tool/src/main.rs b/tool/src/main.rs index 4e7b9c2..5ee206a 100644 --- a/tool/src/main.rs +++ b/tool/src/main.rs @@ -329,6 +329,15 @@ fn main() { .validator(validate_from_str::) ) ) + .subcommand(SubCommand::with_name("led_mode") + .arg(Arg::with_name("mode") + .validator(validate_from_str::) + .requires("speed") + ) + .arg(Arg::with_name("speed") + .validator(validate_from_str::) + ) + ) .subcommand(SubCommand::with_name("print") .arg(Arg::with_name("message") .required(true) @@ -503,6 +512,30 @@ fn main() { } } }, + ("led_mode", Some(sub_m)) => { + let mode = sub_m.value_of("mode").map(|x| x.parse::().unwrap()); + let speed = sub_m.value_of("speed").map(|x| x.parse::().unwrap()); + if let (Some(mode), Some(speed)) = (mode, speed) { + match unsafe { ec.led_set_mode(mode, speed) } { + Ok(()) => (), + Err(err) => { + eprintln!("failed to set mode {} at speed {}: {:X?}", mode, speed, err); + process::exit(1); + }, + } + } else { + match unsafe { ec.led_get_mode() } { + Ok((mode, speed)) => { + println!("mode: {}", mode); + println!("speed: {}", speed); + }, + Err(err) => { + eprintln!("failed to get mode: {:X?}", err); + process::exit(1); + }, + } + } + }, ("print", Some(sub_m)) => for arg in sub_m.values_of("message").unwrap() { let mut arg = arg.to_owned(); arg.push('\n');