From 2b5f43029c5e45a137e83782d2bfa4956f5143ca Mon Sep 17 00:00:00 2001 From: deadprogram Date: Sun, 31 Jan 2021 11:09:42 +0100 Subject: [PATCH] st7789: add scrolling functions to match st7735 Signed-off-by: deadprogram --- st7789/registers.go | 2 ++ st7789/st7789.go | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/st7789/registers.go b/st7789/registers.go index cdea194..8d40547 100644 --- a/st7789/registers.go +++ b/st7789/registers.go @@ -50,6 +50,8 @@ const ( GMCTRP1 = 0xE0 GMCTRN1 = 0xE1 GSCAN = 0x45 + VSCRDEF = 0x33 + VSCRSADD = 0x37 NO_ROTATION Rotation = 0 ROTATION_90 Rotation = 1 // 90 degrees clock-wise rotation diff --git a/st7789/st7789.go b/st7789/st7789.go index 9158c5c..cfb7236 100644 --- a/st7789/st7789.go +++ b/st7789/st7789.go @@ -435,6 +435,27 @@ func (d *Device) IsBGR(bgr bool) { d.isBGR = bgr } +// SetScrollWindow sets an area to scroll with fixed top and bottom parts of the display +func (d *Device) SetScrollArea(topFixedArea, bottomFixedArea int16) { + d.Command(VSCRDEF) + d.Tx([]uint8{ + uint8(topFixedArea >> 8), uint8(topFixedArea), + uint8(d.height - topFixedArea - bottomFixedArea>>8), uint8(d.height - topFixedArea - bottomFixedArea), + uint8(bottomFixedArea >> 8), uint8(bottomFixedArea)}, + false) +} + +// SetScroll sets the vertical scroll address of the display. +func (d *Device) SetScroll(line int16) { + d.Command(VSCRSADD) + d.Tx([]uint8{uint8(line >> 8), uint8(line)}, false) +} + +// SpotScroll returns the display to its normal state +func (d *Device) StopScroll() { + d.Command(NORON) +} + // RGBATo565 converts a color.RGBA to uint16 used in the display func RGBATo565(c color.RGBA) uint16 { r, g, b, _ := c.RGBA()