Skip to content

Commit 8bdaf2a

Browse files
Merge pull request #48 from FrameworkComputer/led-sleep
2 parents b4b4c83 + c9b96b7 commit 8bdaf2a

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

ledmatrix/src/main.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ fn main() -> ! {
178178
// INTB. Currently ignoring
179179
pins.intb.into_floating_input();
180180

181-
let sleep = pins.sleep.into_pull_down_input();
182-
183181
let i2c = bsp::hal::I2C::i2c1(
184182
pac.I2C1,
185183
pins.gpio26.into_mode::<gpio::FunctionI2C>(),
@@ -216,17 +214,31 @@ fn main() -> ! {
216214

217215
let mut startup_percentage = Some(0);
218216

217+
// Detect whether the sleep pin is connected
218+
// Early revisions of the hardware didn't have it wired up, if that is the
219+
// case we have to ignore its state.
220+
let mut sleep_present = false;
221+
let sleep = pins.sleep.into_pull_up_input();
222+
if sleep.is_low().unwrap() {
223+
sleep_present = true;
224+
}
225+
let sleep = sleep.into_pull_down_input();
226+
if sleep.is_high().unwrap() {
227+
sleep_present = true;
228+
}
229+
219230
loop {
220-
// TODO: Current hardware revision does not have the sleep pin wired up :(
221-
// Go to sleep if the host is sleeping
222-
let _host_sleeping = sleep.is_low().unwrap();
223-
//handle_sleep(
224-
// host_sleeping,
225-
// &mut state,
226-
// &mut matrix,
227-
// &mut delay,
228-
// &mut led_enable,
229-
//);
231+
if sleep_present {
232+
// Go to sleep if the host is sleeping
233+
let host_sleeping = sleep.is_low().unwrap();
234+
handle_sleep(
235+
host_sleeping,
236+
&mut state,
237+
&mut matrix,
238+
&mut delay,
239+
&mut led_enable,
240+
);
241+
}
230242

231243
// Handle period display updates. Don't do it too often
232244
if timer.get_counter().ticks() > prev_timer + state.animation_period {

0 commit comments

Comments
 (0)