Skip to content

Commit 63961f1

Browse files
committed
ledmatrix: Ignore sleep pin when it's not connected
Early revisions of the hardware didn't have it wired up, if that is the case we have to ignore its state. Signed-off-by: Daniel Schaefer <[email protected]>
1 parent 13e5117 commit 63961f1

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

ledmatrix/src/main.rs

Lines changed: 24 additions & 11 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,16 +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-
// Go to sleep if the host is sleeping
221-
let host_sleeping = sleep.is_low().unwrap();
222-
handle_sleep(
223-
host_sleeping,
224-
&mut state,
225-
&mut matrix,
226-
&mut delay,
227-
&mut led_enable,
228-
);
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+
}
229242

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

0 commit comments

Comments
 (0)