Skip to content

Commit 385b903

Browse files
bugadaniDániel Bugajamwaffles
authored
Allow reclaiming display pins (#118)
* Changes based on discussion * Add CHANGELOG entry * Run cargo fmt * Fix broken example * Change method name to better reflect its purpose * Remove rebase fail * Commit suggestions Co-authored-by: James Waples <[email protected]> Co-authored-by: Dániel Buga <[email protected]> Co-authored-by: James Waples <[email protected]>
1 parent 83c6cf6 commit 385b903

File tree

6 files changed

+25
-13
lines changed

6 files changed

+25
-13
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@
66

77
## [Unreleased] - ReleaseDate
88

9+
### Added
10+
11+
- [#118](https://github.com/jamwaffles/ssd1306/pull/118) `DisplayModeTrait::into_properties()` new method that consumes the driver and returns the `DisplayProperties`
12+
913
### Changed
1014

1115
-**(breaking)** [#119](https://github.com/jamwaffles/ssd1306/pull/119) Remove `DisplayMode` and `RawMode`
1216
- [#120](https://github.com/jamwaffles/ssd1306/pull/120) Update to v0.4 [`display-interface`](https://crates.io/crates/display-interface)
17+
- **(breaking)** [#118](https://github.com/jamwaffles/ssd1306/pull/118) Change `release` method to return the display interface instead of the `DisplayProperties`.
1318
- **(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)
1419
- **(breaking)** [#113](https://github.com/jamwaffles/ssd1306/pull/113) Removed public `send_bounded_data` from DisplayInterface and implementations
1520

examples/noise_i2c.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Send random raw data to the display, emulating an old untuned TV. This example `release()`s the
1+
//! Send random raw data to the display, emulating an old untuned TV. This example retrieves the
22
//! underlying display properties struct and allows calling of the low-level `draw()` method,
33
//! sending a 1024 byte buffer straight to the display.
44
//!
@@ -65,7 +65,7 @@ fn main() -> ! {
6565
let mut disp: GraphicsMode<_> = Builder::new().connect(interface).into();
6666
disp.init().unwrap();
6767

68-
let mut props = disp.release();
68+
let mut props = disp.into_properties();
6969

7070
let mut buf = [0x00u8; 1024];
7171

src/mode/displaymode.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
use crate::properties::DisplayProperties;
44

55
/// Trait with core functionality for display mode switching
6-
pub trait DisplayModeTrait<DI> {
6+
pub trait DisplayModeTrait<DI>: Sized {
77
/// Allocate all required data and initialise display for mode
88
fn new(properties: DisplayProperties<DI>) -> Self;
99

10-
/// Release resources for reuse with different mode
11-
fn release(self) -> DisplayProperties<DI>;
10+
/// Deconstruct object and retrieve DisplayProperties
11+
fn into_properties(self) -> DisplayProperties<DI>;
12+
13+
/// Release display interface
14+
fn release(self) -> DI {
15+
self.into_properties().release()
16+
}
1217
}

src/mode/graphics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ impl<DI> DisplayModeTrait<DI> for GraphicsMode<DI> {
8787
}
8888
}
8989

90-
/// Release all resources used by GraphicsMode
91-
fn release(self) -> DisplayProperties<DI> {
90+
/// Release display interface used by `GraphicsMode`
91+
fn into_properties(self) -> DisplayProperties<DI> {
9292
self.properties
9393
}
9494
}

src/mode/terminal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ where
153153
}
154154
}
155155

156-
/// Release all resources used by TerminalMode
157-
fn release(self) -> DisplayProperties<DI> {
156+
/// Release display interface used by `TerminalMode`
157+
fn into_properties(self) -> DisplayProperties<DI> {
158158
self.properties
159159
}
160160
}

src/properties.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ pub struct DisplayProperties<DI> {
1717
addr_mode: AddrMode,
1818
}
1919

20-
impl<DI> DisplayProperties<DI>
21-
where
22-
DI: WriteOnlyDataCommand,
23-
{
20+
impl<DI> DisplayProperties<DI> {
2421
/// Create new DisplayProperties instance
2522
pub fn new(
2623
iface: DI,
@@ -48,7 +45,12 @@ where
4845
pub fn release(self) -> DI {
4946
self.iface
5047
}
48+
}
5149

50+
impl<DI> DisplayProperties<DI>
51+
where
52+
DI: WriteOnlyDataCommand,
53+
{
5254
/// Initialise the display in column mode (i.e. a byte walks down a column of 8 pixels) with
5355
/// column 0 on the left and column _(display_width - 1)_ on the right.
5456
pub fn init_column_mode(&mut self) -> Result<(), DisplayError> {

0 commit comments

Comments
 (0)