rust-embedded-community / ssd1306

SSD1306 OLED driver
Apache License 2.0
315 stars 70 forks source link

Using terminal mode with 90/270 degree rotation leads to incorrect output and panic #196

Closed plm closed 1 year ago

plm commented 1 year ago

Description of the problem/feature request/other

When TerminalMode and Rotation90 or Rotation270 is used, writing a new line of text results in the first character being written to the first line of the display, with the remainder of the text for the same line displayed on a later, but expected, line. After writing the eighth line, attempts to write the ninth line trigger a panic, possibly because the first character of the ninth line would (incorrectly) need to be written off screen.

Test case (if applicable)

A sample reproducer using rp2040-hal is provided in plm/ssd1306-rotation-panic, with the relevant lines below.

let i2c = ... // omitted for brevity
let mut display = I2CDisplayInterface::new(i2c),
    DisplaySize128x64,
    DisplayRotation::Rotate270,
)
.into_terminal_mode();

if display.init().is_ok() && display.clear().is_ok() {
   let _ = writeln!(display, "INIT OK");
   loop {
       for count in 0..u8::MAX {
           let _ = writeln!(display, "{}TEST", count); // panics on count == 7
       }
   }
}

Expected display output, which should repeat indefinitely:

INIT OK
0TEST
1TEST
2TEST
3TEST
4TEST
5TEST
6TEST
7TEST

Actual display output, which panics when writing the eighth test line:

I0123456
 TEST
 TEST
 TEST
 TEST
 TEST
 TEST
 TEST
jamwaffles commented 1 year ago

Hey, thanks for the detailed bug report! It made it easy to reproduce your issue. I've opened PR #197 to fix this bug.