@@ -215,6 +215,18 @@ fn main() -> ! {
215
215
& clocks. peripheral_clock ,
216
216
) ;
217
217
218
+ // Detect whether the dip1 pin is connected
219
+ // We switched from bootsel button to DIP-switch with general purpose DIP1 pin in DVT2
220
+ let mut dip1_present = false ;
221
+ let dip1 = pins. dip1 . into_pull_up_input ( ) ;
222
+ if dip1. is_low ( ) . unwrap ( ) {
223
+ dip1_present = true ;
224
+ }
225
+ let dip1 = dip1. into_pull_down_input ( ) ;
226
+ if dip1. is_high ( ) . unwrap ( ) {
227
+ dip1_present = true ;
228
+ }
229
+
218
230
let mut state = LedmatrixState {
219
231
grid : percentage ( 0 ) ,
220
232
col_buffer : Grid :: default ( ) ,
@@ -226,6 +238,14 @@ fn main() -> ! {
226
238
pwm_freq : PwmFreqArg :: P29k ,
227
239
debug_mode : false ,
228
240
} ;
241
+ if dip1_present {
242
+ state. debug_mode = dip1. is_high ( ) . unwrap ( ) ;
243
+ }
244
+ if !show_startup_animation ( & state) {
245
+ // If no startup animation, render another pattern
246
+ // Lighting up every second column is a good pattern to test for noise.
247
+ state. grid = every_nth_col ( 2 ) ;
248
+ } ;
229
249
230
250
let mut matrix = LedMatrix :: configure ( i2c) ;
231
251
matrix
@@ -246,9 +266,6 @@ fn main() -> ! {
246
266
let mut sleep_timer = timer. get_counter ( ) . ticks ( ) ;
247
267
248
268
let mut startup_percentage = Some ( 0 ) ;
249
- if !STARTUP_ANIMATION || state. debug_mode {
250
- state. grid = percentage ( 100 ) ;
251
- }
252
269
253
270
// Detect whether the sleep pin is connected
254
271
// Early revisions of the hardware didn't have it wired up, if that is the
@@ -263,18 +280,6 @@ fn main() -> ! {
263
280
sleep_present = true ;
264
281
}
265
282
266
- // Detect whether the dip1 pin is connected
267
- // We switched from bootsel button to DIP-switch with general purpose DIP1 pin in DVT2
268
- let mut dip1_present = false ;
269
- let dip1 = pins. dip1 . into_pull_up_input ( ) ;
270
- if dip1. is_low ( ) . unwrap ( ) {
271
- dip1_present = true ;
272
- }
273
- let dip1 = dip1. into_pull_down_input ( ) ;
274
- if sleep. is_high ( ) . unwrap ( ) {
275
- dip1_present = true ;
276
- }
277
-
278
283
let mut usb_initialized = false ;
279
284
let mut usb_suspended = false ;
280
285
let mut last_usb_suspended = usb_suspended;
@@ -342,7 +347,7 @@ fn main() -> ! {
342
347
if matches ! ( state. sleeping, SleepState :: Awake ) && render_again {
343
348
// On startup slowly turn the screen on - it's a pretty effect :)
344
349
match startup_percentage {
345
- Some ( p) if p <= 100 && ( STARTUP_ANIMATION || state. debug_mode ) => {
350
+ Some ( p) if p <= 100 && show_startup_animation ( & state) => {
346
351
state. grid = percentage ( p) ;
347
352
startup_percentage = Some ( p + 5 ) ;
348
353
}
@@ -520,14 +525,23 @@ fn get_random_byte(rosc: &RingOscillator<Enabled>) -> u8 {
520
525
byte
521
526
}
522
527
523
- fn dyn_sleep_mode ( state : & mut LedmatrixState ) -> SleepMode {
528
+ fn dyn_sleep_mode ( state : & LedmatrixState ) -> SleepMode {
524
529
if state. debug_mode {
525
530
SleepMode :: Debug
526
531
} else {
527
532
SLEEP_MODE
528
533
}
529
534
}
530
535
536
+ fn debug_mode ( state : & LedmatrixState ) -> bool {
537
+ dyn_sleep_mode ( state) == SleepMode :: Debug
538
+ }
539
+
540
+ fn show_startup_animation ( state : & LedmatrixState ) -> bool {
541
+ // Show startup animation
542
+ STARTUP_ANIMATION && !debug_mode ( state)
543
+ }
544
+
531
545
// Will do nothing if already in the right state
532
546
fn handle_sleep (
533
547
sleep_reason : Option < SleepReason > ,
@@ -554,7 +568,7 @@ fn handle_sleep(
554
568
}
555
569
556
570
// Turn LED controller off to save power
557
- if dyn_sleep_mode ( state) == SleepMode :: Debug {
571
+ if debug_mode ( state) {
558
572
state. grid = display_sleep_reason ( sleep_reason) ;
559
573
fill_grid_pixels ( state, matrix) ;
560
574
} else {
@@ -572,7 +586,7 @@ fn handle_sleep(
572
586
fill_grid_pixels ( state, matrix) ;
573
587
574
588
// Power LED controller back on
575
- if dyn_sleep_mode ( state) != SleepMode :: Debug {
589
+ if debug_mode ( state) {
576
590
led_enable. set_high ( ) . unwrap ( ) ;
577
591
}
578
592
0 commit comments