From cba17ef125b0cb057a7427737eee216e1cb44057 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sun, 26 Mar 2023 00:11:08 +0100 Subject: [PATCH] st7735: add DrawRGBBitmap8 method to draw raw RGB565 buffers This is needed for high performance graphics. Using this API, and using partial updates to the screen (no full screen refreshes), I've been able to get well over 60fps of updates. --- st7735/st7735.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/st7735/st7735.go b/st7735/st7735.go index cd0f19d..5251f6e 100644 --- a/st7735/st7735.go +++ b/st7735/st7735.go @@ -16,6 +16,10 @@ import ( type Model uint8 type Rotation uint8 +var ( + errOutOfBounds = errors.New("rectangle coordinates outside display area") +) + // Device wraps an SPI connection. type Device struct { bus drivers.SPI @@ -274,6 +278,18 @@ func (d *Device) FillRectangle(x, y, width, height int16, c color.RGBA) error { return nil } +// DrawRGBBitmap8 copies an RGB bitmap to the internal buffer at given coordinates +func (d *Device) DrawRGBBitmap8(x, y int16, data []uint8, w, h int16) error { + k, i := d.Size() + if x < 0 || y < 0 || w <= 0 || h <= 0 || + x >= k || (x+w) > k || y >= i || (y+h) > i { + return errOutOfBounds + } + d.setWindow(x, y, w, h) + d.Tx(data, false) + return nil +} + // FillRectangle fills a rectangle at a given coordinates with a buffer func (d *Device) FillRectangleWithBuffer(x, y, width, height int16, buffer []color.RGBA) error { k, l := d.Size()