Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ili9341: Cache address window to prevent sending unnecessary commands #171

Merged
merged 2 commits into from
Aug 3, 2020

Conversation

ardnew
Copy link
Contributor

@ardnew ardnew commented Jul 13, 2020

This is a port of an optimization recently added to the Adafruit_ILI9341 and ILI9341_t3 Arduino drivers.

It works by caching the last row/column sent to the setWindow function, and only resending the respective commands when one of the drawing axes changes. It exhibits a surprisingly effective speedup for basically all drawing operations.

Retrying PR against dev branch instead of master

@sago35
Copy link
Member

sago35 commented Jul 13, 2020

It will be faster in normal use.
With pyportal_boing, the cache-hit rate is low, so it was not faster.
But it's not slow, so it's good.
I'd like to test it some more.

  • pyportal_boing (WioTerminal (atsamd51p19 + SPI))
    • before : 40 - 42 fps
    • after : 40 - 42 fps

test code:

// setWindow prepares the screen to be modified at a given rectangle
func (d *Device) setWindow(x, y, w, h int16) {
	//x += d.columnOffset
	//y += d.rowOffset
	wr := false
	x1 := x + w - 1
	if x != d.x0 || x1 != d.x1 {
		wr = true
		d.sendCommand(CASET, []uint8{
			uint8(x >> 8), uint8(x), uint8(x1 >> 8), uint8(x1),
		})
		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)
		CacheFail++ // !!!
	} else {
		CacheHit++ // !!!
	}
}

result:

41  fps
hit 25 / fail 21207

@ardnew
Copy link
Contributor Author

ardnew commented Jul 14, 2020

Accidentally lost the hyperlinks when I copied the message from the bad PR I closed. So just for reference, the origin of the change is here:

PaulStoffregen/ILI9341_t3#59

adafruit/Adafruit_ILI9341#64

@sago35
Copy link
Member

sago35 commented Jul 22, 2020

LGTM

@sago35
Copy link
Member

sago35 commented Jul 22, 2020

@deadprogram
Please review.

@deadprogram
Copy link
Member

Thanks for the contribution @ardnew and for looking it over @sago35

Now squash/merging.

@deadprogram deadprogram merged commit 8163dec into tinygo-org:dev Aug 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants