st7789: allow changing the color format using COLMOD

This is only really useful for applications that use DrawRGBBitmap8. The
RGB444 format has fewer colors, but can be up to 25% faster than the
default RGB565.

I have tested this change on the Gopher Badge and the PineTime. Both can
be substantially faster once the code is modified to output RGB444
instead of RGB565.
This commit is contained in:
Ayke van Laethem
2023-05-09 12:10:52 +02:00
committed by Ron Evans
parent f627fd162d
commit 42e4d29157
2 changed files with 27 additions and 1 deletions
+4
View File
@@ -55,6 +55,10 @@ const (
VSCRDEF = 0x33
VSCRSADD = 0x37
ColorRGB444 ColorFormat = 0b011
ColorRGB565 ColorFormat = 0b101
ColorRGB666 ColorFormat = 0b111
NO_ROTATION = drivers.Rotation0
ROTATION_90 = drivers.Rotation90 // 90 degrees clock-wise rotation
ROTATION_180 = drivers.Rotation180
+23 -1
View File
@@ -21,6 +21,9 @@ import (
// Deprecated: use drivers.Rotation instead.
type Rotation = drivers.Rotation
// The color format used on the display, like RGB565, RGB666, and RGB444.
type ColorFormat uint8
// FrameRate controls the frame rate used by the display.
type FrameRate uint8
@@ -134,7 +137,7 @@ func (d *Device) Configure(cfg Config) {
d.sendCommand(SLPOUT, nil) // Exit sleep mode
// Memory initialization
d.sendCommand(COLMOD, []byte{0x55}) // Set color mode to 16-bit color
d.setColorFormat(ColorRGB565) // Set color mode to 16-bit color
time.Sleep(10 * time.Millisecond)
d.setRotation(d.rotation) // Memory orientation
@@ -434,6 +437,25 @@ func (d *Device) fillScreen(c color.RGBA) {
}
}
// Control the color format that is used when writing to the screen.
// The default is RGB565, setting it to any other value will break functions
// like SetPixel, FillRectangle, etc. Instead, you can write color data in the
// specified color format using DrawRGBBitmap8.
func (d *Device) SetColorFormat(format ColorFormat) {
d.startWrite()
d.setColorFormat(format)
d.endWrite()
}
func (d *Device) setColorFormat(format ColorFormat) {
// Lower 4 bits set the color format used in SPI.
// Upper 4 bits set the color format used in the direct RGB interface.
// The RGB interface is not currently supported, so it is left at a
// reasonable default. Also, the RGB interface doesn't support RGB444.
colmod := byte(format) | 0x50
d.sendCommand(COLMOD, []byte{colmod})
}
// Rotation returns the current rotation of the device.
func (d *Device) Rotation() drivers.Rotation {
return d.rotation