MCPcopy Index your code
hub / github.com/FrameworkComputer/inputmodule-rs / handle_sleep

Function handle_sleep

b1display/src/main.rs:346–392  ·  view source on GitHub ↗
(
    go_sleeping: bool,
    state: &mut B1DIsplayState,
    delay: &mut Delay,
    disp: &mut ST7306<SPI, DC, CS, RST, COLS, ROWS>,
)

Source from the content-addressed store, hash-verified

344}
345
346fn handle_sleep<SPI, DC, CS, RST, const COLS: usize, const ROWS: usize>(
347 go_sleeping: bool,
348 state: &mut B1DIsplayState,
349 delay: &mut Delay,
350 disp: &mut ST7306<SPI, DC, CS, RST, COLS, ROWS>,
351) where
352 SPI: spi::Write<u8>,
353 DC: OutputPin,
354 CS: OutputPin,
355 RST: OutputPin,
356 <SPI as spi::Write<u8>>::Error: Debug,
357{
358 match (state.sleeping.clone(), go_sleeping) {
359 (SimpleSleepState::Awake, false) => (),
360 (SimpleSleepState::Awake, true) => {
361 state.sleeping = SimpleSleepState::Sleeping;
362
363 // Turn off display
364 //disp.on_off(false).unwrap();
365 disp.sleep_in(delay).unwrap();
366
367 // TODO: Power Display controller down
368
369 // TODO: Set up SLEEP# pin as interrupt and wfi
370 //cortex_m::asm::wfi();
371 }
372 (SimpleSleepState::Sleeping, true) => (),
373 (SimpleSleepState::Sleeping, false) => {
374 // Restore back grid before sleeping
375 state.sleeping = SimpleSleepState::Awake;
376
377 // Turn display back on
378 //disp.on_off(true).unwrap();
379 disp.sleep_out(delay).unwrap();
380 // Sleep-in has to go into HPM first, so we'll be in HPM after wake-up as well
381 if state.power_mode == PowerMode::Lpm {
382 disp.switch_mode(delay, PowerMode::Lpm).unwrap();
383 }
384
385 // Turn screensaver on when resuming from sleep
386 // TODO Subject to change, but currently I want to avoid burn-in by default
387 state.screensaver = Some(ScreenSaverState::default());
388
389 // TODO: Power display controller back on
390 }
391 }
392}

Callers 1

mainFunction · 0.70

Calls 1

unwrapMethod · 0.80

Tested by

no test coverage detected