Skip to content

Commit fc5a6f7

Browse files
authored
Add support for 64x48px SSD1306 modules (#111)
* Add support for 64x48px display * Fix terminal offset for smaller displays Update CHANGELOG.md with suggestion by James Waples <[email protected]>
1 parent ec608a7 commit fc5a6f7

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66

77
## [Unreleased] - ReleaseDate
88

9+
### Fixed
10+
11+
- [#111](https://github.com/jamwaffles/ssd1306/pull/111) Fix TerminalMode offset for smaller displays.
12+
13+
### Added
14+
15+
- [#111](https://github.com/jamwaffles/ssd1306/pull/111) Add support for modules with a 64x48px display size.
16+
917
### Changed
1018

1119
- [#107](https://github.com/jamwaffles/ssd1306/pull/107) Migrate from Travis to CircleCI

src/displaysize.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ pub enum DisplaySize {
1212
Display96x16,
1313
/// 70 by 42 pixels
1414
Display72x40,
15+
/// 64 by 48 pixels
16+
Display64x48,
1517
}
1618

1719
impl DisplaySize {
@@ -23,6 +25,7 @@ impl DisplaySize {
2325
DisplaySize::Display128x32 => (128, 32),
2426
DisplaySize::Display96x16 => (96, 16),
2527
DisplaySize::Display72x40 => (72, 40),
28+
DisplaySize::Display64x48 => (64, 48),
2629
}
2730
}
2831
}

src/mode/terminal.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,23 @@ where
183183
DisplaySize::Display128x32 => 64,
184184
DisplaySize::Display96x16 => 24,
185185
DisplaySize::Display72x40 => 45,
186+
DisplaySize::Display64x48 => 48,
186187
};
187188

188189
// Let the chip handle line wrapping so we can fill the screen with blanks faster
189190
self.properties
190191
.change_mode(AddrMode::Horizontal)
191192
.terminal_err()?;
192193
let (display_width, display_height) = self.properties.get_dimensions();
194+
let (display_x_offset, display_y_offset) = self.properties.display_offset;
193195
self.properties
194-
.set_draw_area((0, 0), (display_width, display_height))
196+
.set_draw_area(
197+
(display_x_offset, display_y_offset),
198+
(
199+
display_width + display_x_offset,
200+
display_height + display_y_offset,
201+
),
202+
)
195203
.terminal_err()?;
196204

197205
// Clear the display
@@ -303,8 +311,11 @@ where
303311

304312
/// Reset the draw area and move pointer to the top left corner
305313
fn reset_pos(&mut self) -> Result<(), TerminalModeError<DI>> {
306-
self.properties.set_column(0).terminal_err()?;
307-
self.properties.set_row(0).terminal_err()?;
314+
let (display_x_offset, display_y_offset) = self.properties.display_offset;
315+
self.properties
316+
.set_column(display_x_offset)
317+
.terminal_err()?;
318+
self.properties.set_row(display_y_offset).terminal_err()?;
308319
// Initialise the counter when we know it's valid
309320
let (display_width, display_height) = self.properties.get_dimensions();
310321
self.cursor = Some(Cursor::new(display_width, display_height));

src/properties.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ where
3131
DisplaySize::Display128x32 => (0, 0),
3232
DisplaySize::Display96x16 => (0, 0),
3333
DisplaySize::Display72x40 => (28, 0),
34+
DisplaySize::Display64x48 => (32, 0),
3435
};
3536

3637
DisplayProperties {
@@ -71,6 +72,7 @@ where
7172
DisplaySize::Display128x64 => Command::ComPinConfig(true, false).send(&mut self.iface),
7273
DisplaySize::Display96x16 => Command::ComPinConfig(false, false).send(&mut self.iface),
7374
DisplaySize::Display72x40 => Command::ComPinConfig(true, false).send(&mut self.iface),
75+
DisplaySize::Display64x48 => Command::ComPinConfig(true, false).send(&mut self.iface),
7476
}?;
7577

7678
Command::Contrast(0x8F).send(&mut self.iface)?;

0 commit comments

Comments
 (0)