diff --git a/Cargo.toml b/Cargo.toml index 5e5b1fe7..d9e4e02e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ authors = ["Ryan Summers "] edition = "2018" readme = "README.md" name = "booster" -version = "0.3.0-rc.1" +version = "0.3.0-rc.3" build = "build.rs" resolver = "2" diff --git a/src/hardware/chassis_fans.rs b/src/hardware/chassis_fans.rs index 3b716d54..504231e5 100644 --- a/src/hardware/chassis_fans.rs +++ b/src/hardware/chassis_fans.rs @@ -4,7 +4,8 @@ //! Copyright (C) 2020 QUARTIQ GmbH - All Rights Reserved //! Unauthorized usage, editing, or copying is strictly prohibited. //! Proprietary and confidential. -use super::{I2cError, I2cProxy}; +use super::{I2cError, I2cProxy, MainboardLeds}; +use embedded_hal::digital::v2::OutputPin; use max6639::Max6639; /// The default fan speed on power-up. @@ -14,6 +15,7 @@ pub const DEFAULT_FAN_SPEED: f32 = 0.2; pub struct ChassisFans { fans: [Max6639; 3], duty_cycle: f32, + leds: MainboardLeds, } impl ChassisFans { @@ -25,10 +27,11 @@ impl ChassisFans { /// /// # Returns /// A new fan controller. - pub fn new(fans: [Max6639; 3]) -> Self { + pub fn new(fans: [Max6639; 3], leds: MainboardLeds) -> Self { ChassisFans { fans, duty_cycle: DEFAULT_FAN_SPEED, + leds, } } @@ -58,14 +61,24 @@ impl ChassisFans { // Bound the duty cycle to a normalized range. let duty_cycle = duty_cycle.clamp(0.0, 1.0); + let leds = &mut self.leds; + // Keep retrying until the configuration succeeds or the maximum number of retry // attempts is exhausted. - let retry_set = |fan: &mut Max6639, subfan, duty_cycle| { + let mut retry_set = |fan: &mut Max6639, subfan, duty_cycle| { for _ in 0..2 { match fan.set_duty_cycle(subfan, duty_cycle) { - Err(max6639::Error::Interface(I2cError::NACK)) => {} + Err(max6639::Error::Interface(I2cError::NACK)) => { + leds.0.set_high().unwrap(); + leds.1.set_high().unwrap(); + leds.2.set_high().unwrap(); + } Err(e) => Err(e).unwrap(), - Ok(_) => break, + Ok(_) => { + leds.0.set_low().unwrap(); + leds.1.set_low().unwrap(); + leds.2.set_low().unwrap(); + } } } }; diff --git a/src/hardware/mod.rs b/src/hardware/mod.rs index ae3437bb..488572dd 100644 --- a/src/hardware/mod.rs +++ b/src/hardware/mod.rs @@ -50,6 +50,11 @@ pub type Spi = hal::spi::Spi< ), >; +pub type Led1 = hal::gpio::gpioc::PC8>; +pub type Led2 = hal::gpio::gpioc::PC9>; +pub type Led3 = hal::gpio::gpioc::PC10>; +pub type MainboardLeds = (Led1, Led2, Led3); + #[cfg(feature = "phy_enc424j600")] pub type NetworkStack = smoltcp_nal::NetworkStack< 'static, diff --git a/src/hardware/setup.rs b/src/hardware/setup.rs index 848f6bdd..414c2220 100644 --- a/src/hardware/setup.rs +++ b/src/hardware/setup.rs @@ -332,6 +332,18 @@ pub fn setup( }; let mut fans = { + let main_board_leds = { + let mut led1 = gpioc.pc8.into_push_pull_output(); + let mut led2 = gpioc.pc9.into_push_pull_output(); + let mut led3 = gpioc.pc10.into_push_pull_output(); + + led1.set_low().unwrap(); + led2.set_low().unwrap(); + led3.set_low().unwrap(); + + (led1, led2, led3) + }; + let fan1 = max6639::Max6639::new(i2c_bus_manager.acquire_i2c(), max6639::AddressPin::Pulldown) .unwrap(); @@ -341,7 +353,7 @@ pub fn setup( max6639::Max6639::new(i2c_bus_manager.acquire_i2c(), max6639::AddressPin::Pullup) .unwrap(); - ChassisFans::new([fan1, fan2, fan3]) + ChassisFans::new([fan1, fan2, fan3], main_board_leds) }; assert!(fans.self_test(&mut delay));