From 593c292e49f8f93583d3047c4563f0018e5b66f9 Mon Sep 17 00:00:00 2001 From: joe820730 Date: Fri, 19 Apr 2019 00:25:49 +0800 Subject: [PATCH] Add 1-D bitmap array support and fix drawing issue. (#48) * Add 1-D bitmap array support. * Fix drawing issue due to wrong _setWindow() args. --- src/TFT_22_ILI9225.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- src/TFT_22_ILI9225.h | 2 ++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/TFT_22_ILI9225.cpp b/src/TFT_22_ILI9225.cpp index 95e2de3..2da6bb1 100644 --- a/src/TFT_22_ILI9225.cpp +++ b/src/TFT_22_ILI9225.cpp @@ -1166,7 +1166,7 @@ const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg, bool t //High speed color bitmap void TFT_22_ILI9225::drawBitmap(uint16_t x1, uint16_t y1, const uint16_t** bitmap, int16_t w, int16_t h) { - _setWindow(x1, y1, x1+w, y1+h); + _setWindow(x1, y1, x1+w-1, y1+h-1,L2R_TopDown); startWrite(); SPI_DC_HIGH(); SPI_CS_LOW(); @@ -1184,7 +1184,7 @@ const uint16_t** bitmap, int16_t w, int16_t h) { //High speed color bitmap void TFT_22_ILI9225::drawBitmap(uint16_t x1, uint16_t y1, uint16_t** bitmap, int16_t w, int16_t h) { - _setWindow(x1, y1, x1+w, y1+h); + _setWindow(x1, y1, x1+w-1, y1+h-1,L2R_TopDown); startWrite(); SPI_DC_HIGH(); SPI_CS_LOW(); @@ -1199,6 +1199,42 @@ uint16_t** bitmap, int16_t w, int16_t h) { endWrite(); } +//1-D array High speed color bitmap +void TFT_22_ILI9225::drawBitmap(uint16_t x1, uint16_t y1, +const uint16_t* bitmap, int16_t w, int16_t h) { + _setWindow(x1, y1, x1+w-1, y1+h-1,L2R_TopDown); + startWrite(); + SPI_DC_HIGH(); + SPI_CS_LOW(); + for (uint16_t j = 0; j < h; j++) { + for (uint16_t i = 0; i < w; i++) { + uint16_t col = bitmap[j*h+i]; + _spiWrite(col>>8); + _spiWrite(col); + } + } + SPI_CS_HIGH(); + endWrite(); +} + +//1-D array High speed color bitmap +void TFT_22_ILI9225::drawBitmap(uint16_t x1, uint16_t y1, +uint16_t* bitmap, int16_t w, int16_t h) { + _setWindow(x1, y1, x1+w-1, y1+h-1,L2R_TopDown); + startWrite(); + SPI_DC_HIGH(); + SPI_CS_LOW(); + for (uint16_t j = 0; j < h; j++) { + for (uint16_t i = 0; i < w; i++) { + uint16_t col = bitmap[j*h+i]; + _spiWrite(col>>8); + _spiWrite(col); + } + } + SPI_CS_HIGH(); + endWrite(); +} + void TFT_22_ILI9225::startWrite(void){ if (writeFunctionLevel++ == 0) { SPI_BEGIN_TRANSACTION(); diff --git a/src/TFT_22_ILI9225.h b/src/TFT_22_ILI9225.h index 46889dd..6d59041 100644 --- a/src/TFT_22_ILI9225.h +++ b/src/TFT_22_ILI9225.h @@ -349,6 +349,8 @@ class TFT_22_ILI9225 { /// @param h height void drawBitmap(uint16_t x, uint16_t y, const uint16_t** bitmap, int16_t w, int16_t h); void drawBitmap(uint16_t x, uint16_t y, uint16_t** bitmap, int16_t w, int16_t h); + void drawBitmap(uint16_t x, uint16_t y, const uint16_t* bitmap, int16_t w, int16_t h); + void drawBitmap(uint16_t x, uint16_t y, uint16_t* bitmap, int16_t w, int16_t h); /// Set current GFX font /// @param f GFX font name defined in include file