Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added sleep/wake methods to display #75

Merged
merged 6 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mipidsi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added

- added `GC9A01` model support
- added `Display::wake` method
- added `Display::sleep` 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 @@ -117,6 +117,7 @@ where
///
/// Consumes the builder to create a new [Display] with an optional reset [OutputPin].
/// Blocks using the provided [DelayUs] `delay_source` to perform the display initialization.
/// The display will be awake ready to use, no need to call [Display::wake] after init.
///
/// ### WARNING
/// The reset pin needs to be in *high* state in order for the display to operate.
Expand Down
22 changes: 22 additions & 0 deletions mipidsi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ use dcs::Dcs;
use display_interface::WriteOnlyDataCommand;

pub mod error;
use embedded_hal::blocking::delay::DelayUs;
use embedded_hal::digital::v2::OutputPin;
pub use error::Error;

Expand Down Expand Up @@ -253,4 +254,25 @@ where
self.dcs
.write_command(dcs::SetTearingEffect(tearing_effect))
}

///
/// Puts the display to sleep, reducing power consumption.
/// Need to call [Self::wake] before issuing other commands
///
pub fn sleep<D: DelayUs<u32>>(&mut self, delay: &mut D) -> Result<(), Error> {
self.dcs.write_command(dcs::EnterSleepMode)?;
// All supported models requires a 120ms delay before issuing other commands
delay.delay_us(120_000);
Ok(())
}

///
/// Wakes the display after it's been set to sleep via [Self::sleep]
///
pub fn wake<D: DelayUs<u32>>(&mut self, delay: &mut D) -> Result<(), Error> {
self.dcs.write_command(dcs::ExitSleepMode)?;
// ST7789 and st7735s have the highest minimal delay of 120ms
delay.delay_us(120_000);
Ok(())
}
}
Loading