diff --git a/ili9341/ili9341.go b/ili9341/ili9341.go index 421b3d2..5ddb463 100644 --- a/ili9341/ili9341.go +++ b/ili9341/ili9341.go @@ -7,6 +7,7 @@ import ( "time" "tinygo.org/x/drivers" + "tinygo.org/x/drivers/pixel" ) type Config struct { @@ -31,6 +32,9 @@ type Device struct { rd machine.Pin } +// Image buffer type used in the ili9341. +type Image = pixel.Image[pixel.RGB565BE] + var cmdBuf [6]byte var initCmd = []byte{ @@ -173,6 +177,8 @@ func (d *Device) EnableTEOutput(on bool) { } // DrawRGBBitmap copies an RGB bitmap to the internal buffer at given coordinates +// +// Deprecated: use DrawBitmap instead. func (d *Device) DrawRGBBitmap(x, y int16, data []uint16, w, h int16) error { k, i := d.Size() if x < 0 || y < 0 || w <= 0 || h <= 0 || @@ -187,6 +193,8 @@ func (d *Device) DrawRGBBitmap(x, y int16, data []uint16, w, h int16) error { } // DrawRGBBitmap8 copies an RGB bitmap to the internal buffer at given coordinates +// +// Deprecated: use DrawBitmap instead. 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 || @@ -200,6 +208,13 @@ func (d *Device) DrawRGBBitmap8(x, y int16, data []uint8, w, h int16) error { return nil } +// DrawBitmap copies the bitmap to the internal buffer on the screen at the +// given coordinates. It returns once the image data has been sent completely. +func (d *Device) DrawBitmap(x, y int16, bitmap Image) error { + width, height := bitmap.Size() + return d.DrawRGBBitmap8(x, y, bitmap.RawBuffer(), int16(width), int16(height)) +} + // FillRectangle fills a rectangle at given coordinates with a color func (d *Device) FillRectangle(x, y, width, height int16, c color.RGBA) error { k, i := d.Size() diff --git a/st7735/st7735.go b/st7735/st7735.go index 02bc93d..6f15781 100644 --- a/st7735/st7735.go +++ b/st7735/st7735.go @@ -305,6 +305,8 @@ func (d *DeviceOf[T]) FillRectangle(x, y, width, height int16, c color.RGBA) err } // DrawRGBBitmap8 copies an RGB bitmap to the internal buffer at given coordinates +// +// Deprecated: use DrawBitmap instead. func (d *DeviceOf[T]) DrawRGBBitmap8(x, y int16, data []uint8, w, h int16) error { k, i := d.Size() if x < 0 || y < 0 || w <= 0 || h <= 0 || @@ -316,6 +318,13 @@ func (d *DeviceOf[T]) DrawRGBBitmap8(x, y int16, data []uint8, w, h int16) error return nil } +// DrawBitmap copies the bitmap to the internal buffer on the screen at the +// given coordinates. It returns once the image data has been sent completely. +func (d *DeviceOf[T]) DrawBitmap(x, y int16, bitmap pixel.Image[T]) error { + width, height := bitmap.Size() + return d.DrawRGBBitmap8(x, y, bitmap.RawBuffer(), int16(width), int16(height)) +} + // FillRectangle fills a rectangle at a given coordinates with a buffer func (d *DeviceOf[T]) FillRectangleWithBuffer(x, y, width, height int16, buffer []color.RGBA) error { k, l := d.Size() diff --git a/st7789/st7789.go b/st7789/st7789.go index 245be11..5db2402 100644 --- a/st7789/st7789.go +++ b/st7789/st7789.go @@ -382,6 +382,8 @@ func (d *DeviceOf[T]) fillRectangle(x, y, width, height int16, c color.RGBA) err } // DrawRGBBitmap8 copies an RGB bitmap to the internal buffer at given coordinates +// +// Deprecated: use DrawBitmap instead. func (d *DeviceOf[T]) DrawRGBBitmap8(x, y int16, data []uint8, w, h int16) error { k, i := d.Size() if x < 0 || y < 0 || w <= 0 || h <= 0 || @@ -395,6 +397,13 @@ func (d *DeviceOf[T]) DrawRGBBitmap8(x, y int16, data []uint8, w, h int16) error return nil } +// DrawBitmap copies the bitmap to the internal buffer on the screen at the +// given coordinates. It returns once the image data has been sent completely. +func (d *DeviceOf[T]) DrawBitmap(x, y int16, bitmap pixel.Image[T]) error { + width, height := bitmap.Size() + return d.DrawRGBBitmap8(x, y, bitmap.RawBuffer(), int16(width), int16(height)) +} + // FillRectangleWithBuffer fills buffer with a rectangle at a given coordinates. func (d *DeviceOf[T]) FillRectangleWithBuffer(x, y, width, height int16, buffer []color.RGBA) error { i, j := d.Size()