mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-07-26 10:38:41 +00:00
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:
committed by
Ron Evans
parent
184dff93b1
commit
deca190ba2
+17
-5
@@ -160,6 +160,18 @@ func (d *Device) Display() error {
|
|||||||
return nil
|
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
|
// 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 {
|
func (d *Device) DrawRGBBitmap(x, y int16, data []uint16, w, h int16) error {
|
||||||
k, i := d.Size()
|
k, i := d.Size()
|
||||||
@@ -287,17 +299,17 @@ func (d *Device) SetRotation(rotation drivers.Rotation) error {
|
|||||||
case Rotation90:
|
case Rotation90:
|
||||||
madctl = MADCTL_MV | MADCTL_BGR
|
madctl = MADCTL_MV | MADCTL_BGR
|
||||||
case Rotation180:
|
case Rotation180:
|
||||||
madctl = MADCTL_MY | MADCTL_BGR
|
madctl = MADCTL_MY | MADCTL_BGR | MADCTL_ML
|
||||||
case Rotation270:
|
case Rotation270:
|
||||||
madctl = MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR
|
madctl = MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR | MADCTL_ML
|
||||||
case Rotation0Mirror:
|
case Rotation0Mirror:
|
||||||
madctl = MADCTL_BGR
|
madctl = MADCTL_BGR
|
||||||
case Rotation90Mirror:
|
case Rotation90Mirror:
|
||||||
madctl = MADCTL_MY | MADCTL_MV | MADCTL_BGR
|
madctl = MADCTL_MY | MADCTL_MV | MADCTL_BGR | MADCTL_ML
|
||||||
case Rotation180Mirror:
|
case Rotation180Mirror:
|
||||||
madctl = MADCTL_MX | MADCTL_MY | MADCTL_BGR
|
madctl = MADCTL_MX | MADCTL_MY | MADCTL_BGR | MADCTL_ML
|
||||||
case Rotation270Mirror:
|
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
|
cmdBuf[0] = madctl
|
||||||
d.sendCommand(MADCTL, cmdBuf[:1])
|
d.sendCommand(MADCTL, cmdBuf[:1])
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ const (
|
|||||||
|
|
||||||
PTLAR = 0x30 ///< Partial Area
|
PTLAR = 0x30 ///< Partial Area
|
||||||
VSCRDEF = 0x33 ///< Vertical Scrolling Definition
|
VSCRDEF = 0x33 ///< Vertical Scrolling Definition
|
||||||
|
TEOFF = 0x34 ///< TEOFF: Tearing Effect Line OFF
|
||||||
|
TEON = 0x35 ///< TEON: Tearing Effect Line ON
|
||||||
MADCTL = 0x36 ///< Memory Access Control
|
MADCTL = 0x36 ///< Memory Access Control
|
||||||
VSCRSADD = 0x37 ///< Vertical Scrolling Start Address
|
VSCRSADD = 0x37 ///< Vertical Scrolling Start Address
|
||||||
PIXFMT = 0x3A ///< COLMOD: Pixel Format Set
|
PIXFMT = 0x3A ///< COLMOD: Pixel Format Set
|
||||||
|
|||||||
Reference in New Issue
Block a user