ili9341: add EnableTEOutput to be able to sync drawing with VSYNC

Many displays don't have the TE pin exposed. But those that do have the
pin (for example, the PyPortal) can use it to synchronize writing a new
image to the display. When implemented correctly, tearing can be avoided
entirely.

This commit also changes the LCD refresh direction to either
top-to-bottom or left-to-right depending on the rotation. Previously it
might refresh from right-to-left or bottom-to-top. This has little
impact on code that doesn't use the TE line, but code that does now only
needs to worry about two cases (top-to-bottom and left-to-right) instead
of four.
(Unfortunately, it appears that the hardware doesn't support changing
the major LCD refresh order so code that wants to do tear-free rendering
still needs to care about these two cases).
This commit is contained in:
Ayke van Laethem
2023-04-12 20:26:18 +02:00
committed by Ron Evans
parent 184dff93b1
commit deca190ba2
2 changed files with 19 additions and 5 deletions
+17 -5
View File
@@ -160,6 +160,18 @@ func (d *Device) Display() error {
return nil
}
// EnableTEOutput enables the TE ("tearing effect") line.
// The TE line goes high when the screen is not currently being updated and can
// be used to start drawing. When used correctly, it can avoid tearing entirely.
func (d *Device) EnableTEOutput(on bool) {
if on {
cmdBuf[0] = 0
d.sendCommand(TEON, cmdBuf[:1]) // M=0 (V-blanking only, no H-blanking)
} else {
d.sendCommand(TEOFF, nil) // TEOFF
}
}
// DrawRGBBitmap copies an RGB bitmap to the internal buffer at given coordinates
func (d *Device) DrawRGBBitmap(x, y int16, data []uint16, w, h int16) error {
k, i := d.Size()
@@ -287,17 +299,17 @@ func (d *Device) SetRotation(rotation drivers.Rotation) error {
case Rotation90:
madctl = MADCTL_MV | MADCTL_BGR
case Rotation180:
madctl = MADCTL_MY | MADCTL_BGR
madctl = MADCTL_MY | MADCTL_BGR | MADCTL_ML
case Rotation270:
madctl = MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR
madctl = MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR | MADCTL_ML
case Rotation0Mirror:
madctl = MADCTL_BGR
case Rotation90Mirror:
madctl = MADCTL_MY | MADCTL_MV | MADCTL_BGR
madctl = MADCTL_MY | MADCTL_MV | MADCTL_BGR | MADCTL_ML
case Rotation180Mirror:
madctl = MADCTL_MX | MADCTL_MY | MADCTL_BGR
madctl = MADCTL_MX | MADCTL_MY | MADCTL_BGR | MADCTL_ML
case Rotation270Mirror:
madctl = MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR
madctl = MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR | MADCTL_ML
}
cmdBuf[0] = madctl
d.sendCommand(MADCTL, cmdBuf[:1])
+2
View File
@@ -41,6 +41,8 @@ const (
PTLAR = 0x30 ///< Partial Area
VSCRDEF = 0x33 ///< Vertical Scrolling Definition
TEOFF = 0x34 ///< TEOFF: Tearing Effect Line OFF
TEON = 0x35 ///< TEON: Tearing Effect Line ON
MADCTL = 0x36 ///< Memory Access Control
VSCRSADD = 0x37 ///< Vertical Scrolling Start Address
PIXFMT = 0x3A ///< COLMOD: Pixel Format Set