Same as for st7735 in the previous commit.
In addition, this avoids allocating a big chunk of memory on _every_
draw operation (even SetPixel) and instead reuses it across draw
operations. This makes the driver a whole lot more efficient.
The rotation as configured using st7789.Config was rotated 180°: 0° was
configured as 180°, 90° was configured as 270°, etc. Presumably with the
original test display, the ribbon cable was seen as the top of the
screen while if you look at product photos it is usually at the bottom.
Example:
https://www.buydisplay.com/wide-angle-1-3-inch-240x240-color-ips-tft-display-st7789-controller
Only Adafruit seems to sell these displays upside down:
https://www.adafruit.com/product/3787
This patch fixes this mistake. It should be noted that this is backwards
incompatible: all code that uses a st7789 will have to be modified to
use the correct rotation instead of the previous incorrect rotation.
If this is too big of a change, we could just keep things as-is and
pretend that all displays are upside down.
The existing code was broken in a few ways:
- It didn't use the correct operator precedence for the VSCRDEF VSA
variable: it needed some extra parentheses to be correct.
- It used the configured height instead of the actual display height
for calculating VSA, which is incorrect. TFA+VSA+BFA must always be
exactly 320, even if a lower value is configured.
- If a lower than 320 pixel height is configured, the bottomFixedArea
parameter applied to the whole 320 pixel screen height. Because this
seems counter intuitive (and relies on properties of any given
screen), I've changed it to work from the actual visible bottom of
the screen (which may be smaller than 320 pixels).
TODO: this doesn't take RowOffset into account, while it probably
should.
I haven't fixed the st7735 implementation, because I didn't have example
code on hand that would easily work on a st7735 screen. This is left as
a TODO for the future.
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.
It is needed to control the chip select pin when the st7789 display is
wired together with some other SPI device on the same bus, for example
if it shares the bus with SPI flash.
This required some refactoring of the code to correctly set the CS pin
everywhere. Notably, this removes the public Command, Data, Tx, and Rx
methods which poke into private details of the st7789 driver and are
therefore best hidden in my opinion.
* Unify the Rotation type, so that SetRotation can be used in
interfaces.
* Add Rotation() method to these displays, so that the current
rotation can be read.
* Change SetRotation() so that it can return an error (if the given
rotation isn't supported).
The API looks like this and is based on the PCA9685 PWM chip:
Sleep(sleepEnabled bool) error
It will set the LCD panel to a low power state (not displaying any
image) but memory contents will be preserved.
Heap allocations can result in significant and unpredictable slowdowns.
For example, they can take over 10ms on the Gopher Badge, which results
in visible tearing (when tearing is otherwise avoided).
Some displays need other values than the default to look right.
Therefore, add a configuration option to set the gamma table for a
particular LCD panel.
- FrameRate option sets device framerates from 39-111Hz
- VSyncLines option adjusts device vsync pause using st7789 "porch control" feature
- Added Rx(cmd, bytes[]) to support retrieving scanline timing data over SPI
- Added Sync functions to support syncronization of animation to vertical scanline timing
- Minor adjustments to Configure to clear screen memory before display is visible
* Fix setWindow bug, add CS pin for Clue compatibility.
- corrected bit shift in setWindow that broke high addresses
- added csPin to constructor (will now work with adafruit clue)
- small adjustments and comments to init routine based on working arduino driver
* Update main.go
Updated test example with CS pin.
* Reverting unnecessary (no-effect) change in setRotation.