mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-17 13:23:26 +00:00
ili9341: cache address window to prevent sending unnecessary commands (#171)
This commit is contained in:
+27
-7
@@ -19,6 +19,9 @@ type Device struct {
|
|||||||
rotation Rotation
|
rotation Rotation
|
||||||
driver driver
|
driver driver
|
||||||
|
|
||||||
|
x0, x1 int16 // cached address window; prevents useless/expensive
|
||||||
|
y0, y1 int16 // syscalls to PASET, CASET, and RAMWR
|
||||||
|
|
||||||
dc machine.Pin
|
dc machine.Pin
|
||||||
cs machine.Pin
|
cs machine.Pin
|
||||||
rst machine.Pin
|
rst machine.Pin
|
||||||
@@ -37,6 +40,10 @@ func (d *Device) Configure(config Config) {
|
|||||||
d.height = config.Height
|
d.height = config.Height
|
||||||
d.rotation = config.Rotation
|
d.rotation = config.Rotation
|
||||||
|
|
||||||
|
// try to pick an initial cache miss for one of the points
|
||||||
|
d.x0, d.x1 = -(d.width + 1), d.x0
|
||||||
|
d.y0, d.y1 = -(d.height + 1), d.y0
|
||||||
|
|
||||||
output := machine.PinConfig{machine.PinOutput}
|
output := machine.PinConfig{machine.PinOutput}
|
||||||
|
|
||||||
// configure chip select if there is one
|
// configure chip select if there is one
|
||||||
@@ -253,13 +260,26 @@ func (d *Device) StopScroll() {
|
|||||||
func (d *Device) setWindow(x, y, w, h int16) {
|
func (d *Device) setWindow(x, y, w, h int16) {
|
||||||
//x += d.columnOffset
|
//x += d.columnOffset
|
||||||
//y += d.rowOffset
|
//y += d.rowOffset
|
||||||
d.sendCommand(CASET, []uint8{
|
wr := false
|
||||||
uint8(x >> 8), uint8(x), uint8((x + w - 1) >> 8), uint8(x + w - 1),
|
x1 := x + w - 1
|
||||||
})
|
if x != d.x0 || x1 != d.x1 {
|
||||||
d.sendCommand(PASET, []uint8{
|
wr = true
|
||||||
uint8(y >> 8), uint8(y), uint8((y + h - 1) >> 8), uint8(y + h - 1),
|
d.sendCommand(CASET, []uint8{
|
||||||
})
|
uint8(x >> 8), uint8(x), uint8(x1 >> 8), uint8(x1),
|
||||||
d.sendCommand(RAMWR, nil)
|
})
|
||||||
|
d.x0, d.x1 = x, x1
|
||||||
|
}
|
||||||
|
y1 := y + h - 1
|
||||||
|
if y != d.y0 || y1 != d.y1 {
|
||||||
|
wr = true
|
||||||
|
d.sendCommand(PASET, []uint8{
|
||||||
|
uint8(y >> 8), uint8(y), uint8(y1 >> 8), uint8(y1),
|
||||||
|
})
|
||||||
|
d.y0, d.y1 = y, y1
|
||||||
|
}
|
||||||
|
if wr {
|
||||||
|
d.sendCommand(RAMWR, nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:inline
|
//go:inline
|
||||||
|
|||||||
Reference in New Issue
Block a user