diff --git a/tool/Cargo.toml b/tool/Cargo.toml index 18e5315..e23f69a 100644 --- a/tool/Cargo.toml +++ b/tool/Cargo.toml @@ -14,5 +14,6 @@ name = "ectool" redox_hwio = "0.1.1" [features] -default = [] +default = ["std"] stable = ["redox_hwio/stable"] +std = [] diff --git a/tool/src/lib.rs b/tool/src/lib.rs index 6ebe681..974a728 100644 --- a/tool/src/lib.rs +++ b/tool/src/lib.rs @@ -1,4 +1,4 @@ -#![no_std] +#![cfg_attr(not(feature = "std"), no_std)] pub use self::ec::Ec; mod ec; @@ -22,4 +22,6 @@ pub use self::super_io::SuperIo; mod super_io; pub use self::timeout::Timeout; +#[cfg(feature = "std")] +pub use self::timeout::StdTimeout; mod timeout; diff --git a/tool/src/main.rs b/tool/src/main.rs index eea6100..115af52 100644 --- a/tool/src/main.rs +++ b/tool/src/main.rs @@ -2,10 +2,10 @@ use ectool::{ Ec, Error, Firmware, + StdTimeout, Spi, SpiRom, SpiTarget, - Timeout, }; use std::{ env, @@ -13,34 +13,10 @@ use std::{ io, process, str::{self, FromStr}, - time::{Duration, Instant}, + time::Duration, thread, }; -pub struct StdTimeout { - instant: Instant, - duration: Duration, -} - -impl StdTimeout { - pub fn new(duration: Duration) -> Self { - StdTimeout { - instant: Instant::now(), - duration - } - } -} - -impl Timeout for StdTimeout { - fn reset(&mut self) { - self.instant = Instant::now(); - } - - fn running(&self) -> bool { - self.instant.elapsed() < self.duration - } -} - unsafe fn iopl() { extern { fn iopl(level: isize) -> isize; diff --git a/tool/src/timeout.rs b/tool/src/timeout.rs index 8da4b39..c62fbac 100644 --- a/tool/src/timeout.rs +++ b/tool/src/timeout.rs @@ -1,3 +1,6 @@ +#[cfg(feature = "std")] +use std::time::{Duration, Instant}; + #[macro_export] macro_rules! timeout { ($t:expr, $f:expr) => {{ @@ -25,3 +28,30 @@ pub trait Timeout { fn reset(&mut self); fn running(&self) -> bool; } + +#[cfg(feature = "std")] +pub struct StdTimeout { + instant: Instant, + duration: Duration, +} + +#[cfg(feature = "std")] +impl StdTimeout { + pub fn new(duration: Duration) -> Self { + StdTimeout { + instant: Instant::now(), + duration + } + } +} + +#[cfg(feature = "std")] +impl Timeout for StdTimeout { + fn reset(&mut self) { + self.instant = Instant::now(); + } + + fn running(&self) -> bool { + self.instant.elapsed() < self.duration + } +}