Raise to version 2.0.0

The library has been cleaned up as it has got a bit untidy due to the large number of small incremental changes.

4bit Sprite examples renaed to be consistent with others.

alphaBlend example moved to generic folder (alphaBlend fn was moved to TFT_eSPI class).
Added sections + explanatory comments to functions prototypes.

Temporary comments added for potential gotchas for noobs when using DMA.

spi_begin/end functions renamed to reflect functionality. Old fns  retained for backwards compatibility with user setup.h files.
This commit is contained in:
Bodmer committed 2020-01-26 21:17:49 +00:00
1 parent b954372859
commit 0e0fd75277
29 files changed
+1267 -797

No files matched your search

+44 -3
View File
@@ -171,7 +171,7 @@ void* TFT_eSprite::callocSprite(int16_t w, int16_t h, uint8_t frames)
}
/***************************************************************************************
** Function name: createPalette
** Function name: createPalette (from RAM array)
** Description: Set a palette for a 4-bit per pixel sprite
*************************************************************************************x*/
@@ -197,6 +197,33 @@ void TFT_eSprite::createPalette(uint16_t colorMap[], int colors)
}
}
/***************************************************************************************
** Function name: createPalette (from FLASH array)
** Description: Set a palette for a 4-bit per pixel sprite
*************************************************************************************x*/
void TFT_eSprite::createPalette(const uint16_t colorMap[], int colors)
{
if (_colorMap != nullptr)
{
free(_colorMap);
}
if (colorMap == nullptr)
{
return; // do nothing other than clear the existing map
}
// allocate color map
_colorMap = (uint16_t *)calloc(16, sizeof(uint16_t));
if (colors > 16)
colors = 16;
for (auto i = 0; i < colors; i++)
{
_colorMap[i] = pgm_read_word(colorMap++);
}
}
/***************************************************************************************
** Function name: frameBuffer
** Description: For 1 bpp Sprites, select the frame used for graphics
@@ -487,6 +514,8 @@ bool TFT_eSprite::pushRotatedHP(int16_t angle, int32_t transp)
if (max_x > _tft->width()) max_x = _tft->width();
if (max_y > _tft->height()) max_y = _tft->height();
uint16_t sline_buffer[max_y - min_y + 1];
_tft->startWrite(); // ESP32: avoid transaction overhead for every tft pixel
// Scan destination bounding box and fetch transformed pixels from source Sprite
@@ -495,6 +524,8 @@ bool TFT_eSprite::pushRotatedHP(int16_t angle, int32_t transp)
float cxt = cosra * xt + _xpivot;
float sxt = sinra * xt + _ypivot;
bool column_drawn = false;
uint32_t pixel_count = 0;
int32_t y_start = 0;
for (int32_t y = min_y; y <= max_y; y++) {
int32_t yt = y - _tft->_ypivot;
int32_t xs = (int32_t)round(cxt - sinra * yt);
@@ -505,12 +536,19 @@ bool TFT_eSprite::pushRotatedHP(int16_t angle, int32_t transp)
// Check if ys is in bounds
if (ys >= 0 && ys < height()) {
int32_t rp = readPixel(xs, ys);
if (rp != transp) _tft->drawPixel(x, y, rp);
if (transp >= 0 ) {
if (rp != transp) _tft->drawPixel(x, y, rp);
}
else {
if (!column_drawn) y_start = y;
sline_buffer[pixel_count++] = rp>>8 | rp<<8;
}
column_drawn = true;
}
}
else if (column_drawn) y = max_y; // Skip remaining column pixels
}
if (pixel_count) _tft->pushImage(x, y_start, 1, pixel_count, sline_buffer);
}
_tft->endWrite(); // ESP32: end transaction
@@ -665,7 +703,10 @@ bool TFT_eSprite::pushRotatedHP(TFT_eSprite *spr, int16_t angle, int32_t transp)
// Check if ys is in bounds
if (ys >= 0 && ys < height())
{
int32_t rp = readPixel(xs, ys);
uint32_t rp;
// Can avoid bounds check overhead for reading 16bpp
if (_bpp == 16) {rp = _img[xs + ys * _iwidth]; rp = rp>>8 | rp<<8; }
else rp = readPixel(xs, ys);
if (rp != transp) spr->drawPixel(x, y, rp);
column_drawn = true;
}
+4 -3
View File
@@ -38,12 +38,13 @@ class TFT_eSprite : public TFT_eSPI {
int8_t getColorDepth(void);
// Set the palette for a 4 bit depth sprite. Only the first 16 colours in the map are used.
void createPalette(uint16_t *palette, int colors = 16);
void createPalette(uint16_t *palette, int colors = 16); // Palette in RAM
void createPalette(const uint16_t *palette, int colors = 16); // Palette in FLASH
// Set a single palette index to the given color
// Set a single palette index to the given color
void setPaletteColor(uint8_t index, uint16_t color);
// Get the color at the given palette index
// Get the color at the given palette index
uint16_t getPaletteColor(uint8_t index);
// Set foreground and background colours for 1 bit per pixel Sprite
+4 -4
View File
@@ -17,7 +17,7 @@
uint8_t TFT_eSPI::getTouchRaw(uint16_t *x, uint16_t *y){
uint16_t tmp;
spi_begin_touch();
begin_touch_read_write();
// Start YP sample request for x position, read 4 times and keep last sample
spi.transfer(0xd0); // Start new YP conversion
@@ -48,7 +48,7 @@ uint8_t TFT_eSPI::getTouchRaw(uint16_t *x, uint16_t *y){
*y = tmp;
spi_end_touch();
end_touch_read_write();
return true;
}
@@ -59,7 +59,7 @@ uint8_t TFT_eSPI::getTouchRaw(uint16_t *x, uint16_t *y){
***************************************************************************************/
uint16_t TFT_eSPI::getTouchRawZ(void){
spi_begin_touch();
begin_touch_read_write();
// Z sample request
int16_t tz = 0xFFF;
@@ -67,7 +67,7 @@ uint16_t TFT_eSPI::getTouchRawZ(void){
tz += spi.transfer16(0xc0) >> 3; // Read Z1 and start Z2 conversion
tz -= spi.transfer16(0x00) >> 3; // Read Z2
spi_end_touch();
end_touch_read_write();
return (uint16_t)tz;
}
+7 -3
View File
@@ -18,9 +18,13 @@
void setTouch(uint16_t *data);
private:
// Handlers for the SPI settings and clock speed change
inline void spi_begin_touch() __attribute__((always_inline));
inline void spi_end_touch() __attribute__((always_inline));
// Legacy support only - deprecated
void spi_begin_touch() {begin_touch_read_write();}
void spi_end_touch() { end_touch_read_write();}
// Handlers for the touch controller bus settings
inline void begin_touch_read_write() __attribute__((always_inline));
inline void end_touch_read_write() __attribute__((always_inline));
// Private function to validate a touch, allow settle time and reduce spurious coordinates
uint8_t validTouch(uint16_t *x, uint16_t *y, uint16_t threshold = 600);