From e20c6d05f8b3a13a0fd222b4835c0b6b61cdb9b9 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Tue, 20 Jun 2023 17:11:29 +0200 Subject: [PATCH] =?UTF-8?q?st7789:=20fix=20scrolling=20when=20rotated=20by?= =?UTF-8?q?=20180=C2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes https://github.com/tinygo-org/drivers/issues/573. It doesn't handle 90° or 270°, I guess it needs a fix for 270° but I haven't tested that so didn't include it in the patch. --- st7789/st7789.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/st7789/st7789.go b/st7789/st7789.go index 5494203..1e6f128 100644 --- a/st7789/st7789.go +++ b/st7789/st7789.go @@ -558,7 +558,13 @@ func (d *Device) SetScrollArea(topFixedArea, bottomFixedArea int16) { // The screen doesn't use the full 320 pixel height. // Enlarge the bottom fixed area to fill the 320 pixel height, so that // bottomFixedArea starts from the visible bottom of the screen. - bottomFixedArea += 320 - d.height + topFixedArea += d.rowOffset + bottomFixedArea += (320 - d.height) - d.rowOffset + } + if d.rotation == drivers.Rotation180 { + // The screen is rotated by 180°, so we have to switch the top and + // bottom fixed area. + topFixedArea, bottomFixedArea = bottomFixedArea, topFixedArea } verticalScrollArea := 320 - topFixedArea - bottomFixedArea copy(d.buf[:6], []uint8{ @@ -572,6 +578,11 @@ func (d *Device) SetScrollArea(topFixedArea, bottomFixedArea int16) { // SetScroll sets the vertical scroll address of the display. func (d *Device) SetScroll(line int16) { + if d.rotation == drivers.Rotation180 { + // The screen is rotated by 180°, so we have to invert the scroll line + // (taking care of the RowOffset). + line = (319 - d.rowOffset) - line + } d.buf[0] = uint8(line >> 8) d.buf[1] = uint8(line) d.startWrite()