Skip to content

Commit deca190

Browse files
aykevldeadprogram
authored andcommitted
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).
1 parent 184dff9 commit deca190

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

ili9341/ili9341.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,18 @@ func (d *Device) Display() error {
160160
return nil
161161
}
162162

163+
// EnableTEOutput enables the TE ("tearing effect") line.
164+
// The TE line goes high when the screen is not currently being updated and can
165+
// be used to start drawing. When used correctly, it can avoid tearing entirely.
166+
func (d *Device) EnableTEOutput(on bool) {
167+
if on {
168+
cmdBuf[0] = 0
169+
d.sendCommand(TEON, cmdBuf[:1]) // M=0 (V-blanking only, no H-blanking)
170+
} else {
171+
d.sendCommand(TEOFF, nil) // TEOFF
172+
}
173+
}
174+
163175
// DrawRGBBitmap copies an RGB bitmap to the internal buffer at given coordinates
164176
func (d *Device) DrawRGBBitmap(x, y int16, data []uint16, w, h int16) error {
165177
k, i := d.Size()
@@ -287,17 +299,17 @@ func (d *Device) SetRotation(rotation drivers.Rotation) error {
287299
case Rotation90:
288300
madctl = MADCTL_MV | MADCTL_BGR
289301
case Rotation180:
290-
madctl = MADCTL_MY | MADCTL_BGR
302+
madctl = MADCTL_MY | MADCTL_BGR | MADCTL_ML
291303
case Rotation270:
292-
madctl = MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR
304+
madctl = MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR | MADCTL_ML
293305
case Rotation0Mirror:
294306
madctl = MADCTL_BGR
295307
case Rotation90Mirror:
296-
madctl = MADCTL_MY | MADCTL_MV | MADCTL_BGR
308+
madctl = MADCTL_MY | MADCTL_MV | MADCTL_BGR | MADCTL_ML
297309
case Rotation180Mirror:
298-
madctl = MADCTL_MX | MADCTL_MY | MADCTL_BGR
310+
madctl = MADCTL_MX | MADCTL_MY | MADCTL_BGR | MADCTL_ML
299311
case Rotation270Mirror:
300-
madctl = MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR
312+
madctl = MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR | MADCTL_ML
301313
}
302314
cmdBuf[0] = madctl
303315
d.sendCommand(MADCTL, cmdBuf[:1])

ili9341/registers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ const (
4141

4242
PTLAR = 0x30 ///< Partial Area
4343
VSCRDEF = 0x33 ///< Vertical Scrolling Definition
44+
TEOFF = 0x34 ///< TEOFF: Tearing Effect Line OFF
45+
TEON = 0x35 ///< TEON: Tearing Effect Line ON
4446
MADCTL = 0x36 ///< Memory Access Control
4547
VSCRSADD = 0x37 ///< Vertical Scrolling Start Address
4648
PIXFMT = 0x3A ///< COLMOD: Pixel Format Set

0 commit comments

Comments
 (0)