Skip to content

Commit 95772ff

Browse files
bugadanijamwaffles
andauthored
Move reset to DisplayModeTrait (#126)
* Move reset to DisplayModeTrait The functionality is common, so the implementation can be as well. * Added changelog entry and a missing space * Update CHANGELOG.md Co-authored-by: James Waples <[email protected]> Co-authored-by: James Waples <[email protected]>
1 parent 385b903 commit 95772ff

File tree

4 files changed

+22
-44
lines changed

4 files changed

+22
-44
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
### Changed
1414

15-
-**(breaking)** [#119](https://github.com/jamwaffles/ssd1306/pull/119) Remove `DisplayMode` and `RawMode`
15+
- **(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.
16+
- **(breaking)** [#119](https://github.com/jamwaffles/ssd1306/pull/119) Remove `DisplayMode` and `RawMode`
1617
- [#120](https://github.com/jamwaffles/ssd1306/pull/120) Update to v0.4 [`display-interface`](https://crates.io/crates/display-interface)
1718
- **(breaking)** [#118](https://github.com/jamwaffles/ssd1306/pull/118) Change `release` method to return the display interface instead of the `DisplayProperties`.
1819
- **(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)

src/mode/displaymode.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Abstraction of different operating modes for the SSD1306
22
33
use crate::properties::DisplayProperties;
4+
use crate::Error;
5+
use hal::{blocking::delay::DelayMs, digital::v2::OutputPin};
46

57
/// Trait with core functionality for display mode switching
68
pub trait DisplayModeTrait<DI>: Sized {
@@ -14,4 +16,21 @@ pub trait DisplayModeTrait<DI>: Sized {
1416
fn release(self) -> DI {
1517
self.into_properties().release()
1618
}
19+
20+
/// Reset the display
21+
fn reset<RST, DELAY, PinE>(
22+
&mut self,
23+
rst: &mut RST,
24+
delay: &mut DELAY,
25+
) -> Result<(), Error<(), PinE>>
26+
where
27+
RST: OutputPin<Error = PinE>,
28+
DELAY: DelayMs<u8>,
29+
{
30+
rst.set_high().map_err(Error::Pin)?;
31+
delay.delay_ms(1);
32+
rst.set_low().map_err(Error::Pin)?;
33+
delay.delay_ms(10);
34+
rst.set_high().map_err(Error::Pin)
35+
}
1736
}

src/mode/graphics.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,10 @@
5656
//! [embedded_graphics]: https://crates.io/crates/embedded_graphics
5757
5858
use display_interface::{DisplayError, WriteOnlyDataCommand};
59-
use hal::{blocking::delay::DelayMs, digital::v2::OutputPin};
6059

6160
use crate::{
6261
displayrotation::DisplayRotation, mode::displaymode::DisplayModeTrait,
63-
properties::DisplayProperties, Error,
62+
properties::DisplayProperties,
6463
};
6564

6665
// TODO: Add to prelude
@@ -93,26 +92,6 @@ impl<DI> DisplayModeTrait<DI> for GraphicsMode<DI> {
9392
}
9493
}
9594

96-
impl<DI> GraphicsMode<DI> {
97-
/// Reset display
98-
// TODO: Move to a more appropriate place
99-
pub fn reset<RST, DELAY, PinE>(
100-
&mut self,
101-
rst: &mut RST,
102-
delay: &mut DELAY,
103-
) -> Result<(), Error<(), PinE>>
104-
where
105-
RST: OutputPin<Error = PinE>,
106-
DELAY: DelayMs<u8>,
107-
{
108-
rst.set_high().map_err(Error::Pin)?;
109-
delay.delay_ms(1);
110-
rst.set_low().map_err(Error::Pin)?;
111-
delay.delay_ms(10);
112-
rst.set_high().map_err(Error::Pin)
113-
}
114-
}
115-
11695
impl<DI> GraphicsMode<DI>
11796
where
11897
DI: WriteOnlyDataCommand,

src/mode/terminal.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ use crate::{
3636
terminal::TerminalModeError::{InterfaceError, OutOfBounds, Uninitialized},
3737
},
3838
properties::DisplayProperties,
39-
Error,
4039
};
4140
use core::{cmp::min, fmt};
42-
use hal::{blocking::delay::DelayMs, digital::v2::OutputPin};
4341

4442
/// Contains the new row that the cursor has wrapped around to
4543
struct CursorWrapEvent(u8);
@@ -159,25 +157,6 @@ where
159157
}
160158
}
161159

162-
impl<DI> TerminalMode<DI> {
163-
/// Reset display
164-
pub fn reset<RST, DELAY, PinE>(
165-
&mut self,
166-
rst: &mut RST,
167-
delay: &mut DELAY,
168-
) -> Result<(), Error<(), PinE>>
169-
where
170-
RST: OutputPin<Error = PinE>,
171-
DELAY: DelayMs<u8>,
172-
{
173-
rst.set_high().map_err(Error::Pin)?;
174-
delay.delay_ms(1);
175-
rst.set_low().map_err(Error::Pin)?;
176-
delay.delay_ms(10);
177-
rst.set_high().map_err(Error::Pin)
178-
}
179-
}
180-
181160
impl<DI> TerminalMode<DI>
182161
where
183162
DI: WriteOnlyDataCommand,

0 commit comments

Comments
 (0)