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

Move reset to DisplayModeTrait #126

Merged
merged 3 commits into from
Jun 12, 2020
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

### Changed

-**(breaking)** [#119](https://github.com/jamwaffles/ssd1306/pull/119) Remove `DisplayMode` and `RawMode`
- **(breaking)** [#126](https://github.com/jamwaffles/ssd1306/pull/126) Moved `reset` method to `DisplayModeTrait`. If the prelude is not used, add either `use ssd1306::prelude::*` or `ssd1306::mode::displaymode::DisplayModeTrait` to your imports.
- **(breaking)** [#119](https://github.com/jamwaffles/ssd1306/pull/119) Remove `DisplayMode` and `RawMode`
- [#120](https://github.com/jamwaffles/ssd1306/pull/120) Update to v0.4 [`display-interface`](https://crates.io/crates/display-interface)
- **(breaking)** [#118](https://github.com/jamwaffles/ssd1306/pull/118) Change `release` method to return the display interface instead of the `DisplayProperties`.
- **(breaking)** [#116](https://github.com/jamwaffles/ssd1306/pull/116) Replace custom I2C and SPI interfaces by generic [`display-interface`](https://crates.io/crates/display-interface)
Expand Down
19 changes: 19 additions & 0 deletions src/mode/displaymode.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Abstraction of different operating modes for the SSD1306

use crate::properties::DisplayProperties;
use crate::Error;
use hal::{blocking::delay::DelayMs, digital::v2::OutputPin};

/// Trait with core functionality for display mode switching
pub trait DisplayModeTrait<DI>: Sized {
Expand All @@ -14,4 +16,21 @@ pub trait DisplayModeTrait<DI>: Sized {
fn release(self) -> DI {
self.into_properties().release()
}

/// Reset the display
fn reset<RST, DELAY, PinE>(
&mut self,
rst: &mut RST,
delay: &mut DELAY,
) -> Result<(), Error<(), PinE>>
where
RST: OutputPin<Error = PinE>,
DELAY: DelayMs<u8>,
{
rst.set_high().map_err(Error::Pin)?;
delay.delay_ms(1);
rst.set_low().map_err(Error::Pin)?;
delay.delay_ms(10);
rst.set_high().map_err(Error::Pin)
}
}
23 changes: 1 addition & 22 deletions src/mode/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@
//! [embedded_graphics]: https://crates.io/crates/embedded_graphics

use display_interface::{DisplayError, WriteOnlyDataCommand};
use hal::{blocking::delay::DelayMs, digital::v2::OutputPin};

use crate::{
displayrotation::DisplayRotation, mode::displaymode::DisplayModeTrait,
properties::DisplayProperties, Error,
properties::DisplayProperties,
};

// TODO: Add to prelude
Expand Down Expand Up @@ -93,26 +92,6 @@ impl<DI> DisplayModeTrait<DI> for GraphicsMode<DI> {
}
}

impl<DI> GraphicsMode<DI> {
/// Reset display
// TODO: Move to a more appropriate place
pub fn reset<RST, DELAY, PinE>(
&mut self,
rst: &mut RST,
delay: &mut DELAY,
) -> Result<(), Error<(), PinE>>
where
RST: OutputPin<Error = PinE>,
DELAY: DelayMs<u8>,
{
rst.set_high().map_err(Error::Pin)?;
delay.delay_ms(1);
rst.set_low().map_err(Error::Pin)?;
delay.delay_ms(10);
rst.set_high().map_err(Error::Pin)
}
}

impl<DI> GraphicsMode<DI>
where
DI: WriteOnlyDataCommand,
Expand Down
21 changes: 0 additions & 21 deletions src/mode/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ use crate::{
terminal::TerminalModeError::{InterfaceError, OutOfBounds, Uninitialized},
},
properties::DisplayProperties,
Error,
};
use core::{cmp::min, fmt};
use hal::{blocking::delay::DelayMs, digital::v2::OutputPin};

/// Contains the new row that the cursor has wrapped around to
struct CursorWrapEvent(u8);
Expand Down Expand Up @@ -159,25 +157,6 @@ where
}
}

impl<DI> TerminalMode<DI> {
/// Reset display
pub fn reset<RST, DELAY, PinE>(
&mut self,
rst: &mut RST,
delay: &mut DELAY,
) -> Result<(), Error<(), PinE>>
where
RST: OutputPin<Error = PinE>,
DELAY: DelayMs<u8>,
{
rst.set_high().map_err(Error::Pin)?;
delay.delay_ms(1);
rst.set_low().map_err(Error::Pin)?;
delay.delay_ms(10);
rst.set_high().map_err(Error::Pin)
}
}

impl<DI> TerminalMode<DI>
where
DI: WriteOnlyDataCommand,
Expand Down