Skip to content

Commit

Permalink
Merge pull request #78 from almindor/is_sleeping
Browse files Browse the repository at this point in the history
add Display::is_sleeping fixes #77
  • Loading branch information
almindor authored Oct 23, 2023
2 parents 05abb44 + 000ea47 commit 9fbaca7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions mipidsi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- added `GC9A01` model support
- added `Display::wake` method
- added `Display::sleep` method
- added `Display::is_sleeping` method

## [v0.7.1] - 2023-05-24

Expand Down
1 change: 1 addition & 0 deletions mipidsi/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ where
rst,
options: self.options,
madctl,
sleeping: false, // TODO: init should lock state
};

Ok(display)
Expand Down
11 changes: 11 additions & 0 deletions mipidsi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ where
options: ModelOptions,
// Current MADCTL value copy for runtime updates
madctl: dcs::SetAddressMode,
// State monitor for sleeping TODO: refactor to a Model-connected state machine
sleeping: bool,
}

impl<DI, M, RST> Display<DI, M, RST>
Expand Down Expand Up @@ -258,6 +260,13 @@ where
.write_command(dcs::SetTearingEffect(tearing_effect))
}

///
/// Returns `true` if display is currently set to sleep.
///
pub fn is_sleeping<D: DelayUs<u32>>(&self) -> bool {
self.sleeping
}

///
/// Puts the display to sleep, reducing power consumption.
/// Need to call [Self::wake] before issuing other commands
Expand All @@ -266,6 +275,7 @@ where
self.dcs.write_command(dcs::EnterSleepMode)?;
// All supported models requires a 120ms delay before issuing other commands
delay.delay_us(120_000);
self.sleeping = true;
Ok(())
}

Expand All @@ -276,6 +286,7 @@ where
self.dcs.write_command(dcs::ExitSleepMode)?;
// ST7789 and st7735s have the highest minimal delay of 120ms
delay.delay_us(120_000);
self.sleeping = false;
Ok(())
}
}

0 comments on commit 9fbaca7

Please sign in to comment.