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()