@@ -9,6 +9,7 @@ use cortex_m::delay::Delay;
9
9
use defmt_rtt as _;
10
10
use embedded_hal:: digital:: v2:: { InputPin , OutputPin } ;
11
11
12
+ use rp2040_hal:: gpio:: bank0:: Gpio29 ;
12
13
//#[cfg(debug_assertions)]
13
14
//use panic_probe as _;
14
15
use rp2040_panic_usb_boot as _;
@@ -78,7 +79,7 @@ use lotus_led_hal as bsp;
78
79
79
80
use bsp:: hal:: {
80
81
clocks:: { init_clocks_and_plls, Clock } ,
81
- pac,
82
+ gpio , pac,
82
83
sio:: Sio ,
83
84
usb,
84
85
watchdog:: Watchdog ,
@@ -217,8 +218,8 @@ fn main() -> ! {
217
218
218
219
let i2c = bsp:: hal:: I2C :: i2c1 (
219
220
pac. I2C1 ,
220
- pins. gpio26 . into_mode :: < bsp :: hal :: gpio:: FunctionI2C > ( ) ,
221
- pins. gpio27 . into_mode :: < bsp :: hal :: gpio:: FunctionI2C > ( ) ,
221
+ pins. gpio26 . into_mode :: < gpio:: FunctionI2C > ( ) ,
222
+ pins. gpio27 . into_mode :: < gpio:: FunctionI2C > ( ) ,
222
223
1000 . kHz ( ) ,
223
224
& mut pac. RESETS ,
224
225
& clocks. peripheral_clock ,
@@ -293,10 +294,17 @@ fn main() -> ! {
293
294
}
294
295
Ok ( count) => {
295
296
if let Some ( command) = parse_command ( count, & buf) {
296
- handle_command ( & command, & mut state, & mut matrix) ;
297
-
298
297
if let Command :: Sleep ( go_sleeping) = command {
299
- handle_sleep ( go_sleeping, & mut state, & mut matrix, & mut delay) ;
298
+ handle_sleep (
299
+ go_sleeping,
300
+ & mut state,
301
+ & mut matrix,
302
+ & mut delay,
303
+ & mut led_enable,
304
+ ) ;
305
+ } else if let SleepState :: Awake = state. sleeping {
306
+ // While sleeping no command is handled, except waking up
307
+ handle_command ( & command, & mut state, & mut matrix) ;
300
308
}
301
309
302
310
fill_grid_pixels ( & state. grid , & mut matrix) ;
@@ -307,7 +315,13 @@ fn main() -> ! {
307
315
}
308
316
}
309
317
310
- fn handle_sleep ( go_sleeping : bool , state : & mut State , matrix : & mut Foo , delay : & mut Delay ) {
318
+ fn handle_sleep (
319
+ go_sleeping : bool ,
320
+ state : & mut State ,
321
+ matrix : & mut Foo ,
322
+ delay : & mut Delay ,
323
+ led_enable : & mut gpio:: Pin < Gpio29 , gpio:: Output < gpio:: PushPull > > ,
324
+ ) {
311
325
match ( state. sleeping . clone ( ) , go_sleeping) {
312
326
( SleepState :: Awake , false ) => ( ) ,
313
327
( SleepState :: Awake , true ) => {
@@ -329,6 +343,9 @@ fn handle_sleep(go_sleeping: bool, state: &mut State, matrix: &mut Foo, delay: &
329
343
}
330
344
}
331
345
346
+ // Turn LED controller off to save power
347
+ led_enable. set_low ( ) . unwrap ( ) ;
348
+
332
349
// TODO: Set up SLEEP# pin as interrupt and wfi
333
350
//cortex_m::asm::wfi();
334
351
}
@@ -339,6 +356,9 @@ fn handle_sleep(go_sleeping: bool, state: &mut State, matrix: &mut Foo, delay: &
339
356
state. grid = old_grid;
340
357
fill_grid_pixels ( & state. grid , matrix) ;
341
358
359
+ // Power LED controller back on
360
+ led_enable. set_high ( ) . unwrap ( ) ;
361
+
342
362
// Slowly increase brightness
343
363
delay. delay_ms ( 1000 ) ;
344
364
let mut brightness = 0 ;
0 commit comments