Commit b6db90ad authored by Bodmer's avatar Bodmer

Add new anit-aliased graphics functions

Examples to follow.
parent 97ca3fdb
...@@ -1292,7 +1292,7 @@ void TFT_eSprite::setWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1) ...@@ -1292,7 +1292,7 @@ void TFT_eSprite::setWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1)
** Function name: pushColor ** Function name: pushColor
** Description: Send a new pixel to the set window ** Description: Send a new pixel to the set window
***************************************************************************************/ ***************************************************************************************/
void TFT_eSprite::pushColor(uint32_t color) void TFT_eSprite::pushColor(uint16_t color)
{ {
if (!_created ) return; if (!_created ) return;
...@@ -1334,7 +1334,7 @@ void TFT_eSprite::pushColor(uint32_t color) ...@@ -1334,7 +1334,7 @@ void TFT_eSprite::pushColor(uint32_t color)
** Function name: pushColor ** Function name: pushColor
** Description: Send a "len" new pixels to the set window ** Description: Send a "len" new pixels to the set window
***************************************************************************************/ ***************************************************************************************/
void TFT_eSprite::pushColor(uint32_t color, uint16_t len) void TFT_eSprite::pushColor(uint16_t color, uint32_t len)
{ {
if (!_created ) return; if (!_created ) return;
......
...@@ -63,9 +63,9 @@ class TFT_eSprite : public TFT_eSPI { ...@@ -63,9 +63,9 @@ class TFT_eSprite : public TFT_eSPI {
// Colours are converted to the set Sprite colour bit depth // Colours are converted to the set Sprite colour bit depth
setWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1), setWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1),
// Push a color (aka singe pixel) to the screen // Push a color (aka singe pixel) to the screen
pushColor(uint32_t color), pushColor(uint16_t color),
// Push len colors (pixels) to the screen // Push len colors (pixels) to the screen
pushColor(uint32_t color, uint16_t len), pushColor(uint16_t color, uint32_t len),
// Push a pixel preformatted as a 8 or 16 bit colour (avoids conversion overhead) // Push a pixel preformatted as a 8 or 16 bit colour (avoids conversion overhead)
writeColor(uint16_t color), writeColor(uint16_t color),
...@@ -149,6 +149,10 @@ class TFT_eSprite : public TFT_eSPI { ...@@ -149,6 +149,10 @@ class TFT_eSprite : public TFT_eSPI {
// Reserve memory for the Sprite and return a pointer // Reserve memory for the Sprite and return a pointer
void* callocSprite(int16_t width, int16_t height, uint8_t frames = 1); void* callocSprite(int16_t width, int16_t height, uint8_t frames = 1);
// Override the non-inlined TFT_eSPI functions
void begin_nin_write(void) { ; }
void end_nin_write(void) { ; }
protected: protected:
uint8_t _bpp; // bits per pixel (1, 8 or 16) uint8_t _bpp; // bits per pixel (1, 8 or 16)
......
...@@ -426,6 +426,10 @@ SPI3_HOST = 2 ...@@ -426,6 +426,10 @@ SPI3_HOST = 2
#define RD_L #define RD_L
#define RD_H #define RD_H
#endif #endif
#else
#define TFT_RD -1
#define RD_L
#define RD_H
#endif #endif
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
......
...@@ -160,8 +160,20 @@ ...@@ -160,8 +160,20 @@
// Make sure TFT_RD is defined if not used to avoid an error message // Make sure TFT_RD is defined if not used to avoid an error message
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// At the moment read is not supported for parallel mode, tie TFT signal high // At the moment read is not supported for parallel mode, tie TFT signal high
#ifndef TFT_RD #ifdef TFT_RD
#if (TFT_RD >= 0)
#define RD_L sio_hw->gpio_clr = (1ul << TFT_RD)
//#define RD_L digitalWrite(TFT_WR, LOW)
#define RD_H sio_hw->gpio_set = (1ul << TFT_RD)
//#define RD_H digitalWrite(TFT_WR, HIGH)
#else
#define RD_L
#define RD_H
#endif
#else
#define TFT_RD -1 #define TFT_RD -1
#define RD_L
#define RD_H
#endif #endif
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
......
This diff is collapsed.
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#ifndef _TFT_eSPIH_ #ifndef _TFT_eSPIH_
#define _TFT_eSPIH_ #define _TFT_eSPIH_
#define TFT_ESPI_VERSION "2.4.32" #define TFT_ESPI_VERSION "2.4.33"
// Bit level feature flags // Bit level feature flags
// Bit 0 set: viewport capability // Bit 0 set: viewport capability
...@@ -407,6 +407,18 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac ...@@ -407,6 +407,18 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
height(void), height(void),
width(void); width(void);
// Read the colour of a pixel at x,y and return value in 565 format
virtual uint16_t readPixel(int32_t x, int32_t y);
virtual void setWindow(int32_t xs, int32_t ys, int32_t xe, int32_t ye); // Note: start + end coordinates
// Push (aka write pixel) colours to the set window
virtual void pushColor(uint16_t color);
// These are non-inlined to enable override
virtual void begin_nin_write();
virtual void end_nin_write();
void setRotation(uint8_t r); // Set the display image orientation to 0, 1, 2 or 3 void setRotation(uint8_t r); // Set the display image orientation to 0, 1, 2 or 3
uint8_t getRotation(void); // Read the current rotation uint8_t getRotation(void); // Read the current rotation
...@@ -414,8 +426,7 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac ...@@ -414,8 +426,7 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
// The TFT_eSprite class inherits the following functions (not all are useful to Sprite class // The TFT_eSprite class inherits the following functions (not all are useful to Sprite class
void setAddrWindow(int32_t xs, int32_t ys, int32_t w, int32_t h), // Note: start coordinates + width and height void setAddrWindow(int32_t xs, int32_t ys, int32_t w, int32_t h); // Note: start coordinates + width and height
setWindow(int32_t xs, int32_t ys, int32_t xe, int32_t ye); // Note: start + end coordinates
// Viewport commands, see "Viewport_Demo" sketch // Viewport commands, see "Viewport_Demo" sketch
void setViewport(int32_t x, int32_t y, int32_t w, int32_t h, bool vpDatum = true); void setViewport(int32_t x, int32_t y, int32_t w, int32_t h, bool vpDatum = true);
...@@ -428,9 +439,13 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac ...@@ -428,9 +439,13 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
void frameViewport(uint16_t color, int32_t w); void frameViewport(uint16_t color, int32_t w);
void resetViewport(void); void resetViewport(void);
// Clip input window to viewport bounds, return false if whole area is out of bounds
bool clipAddrWindow(int32_t* x, int32_t* y, int32_t* w, int32_t* h);
// Clip input window area to viewport bounds, return false if whole area is out of bounds
bool clipWindow(int32_t* xs, int32_t* ys, int32_t* xe, int32_t* ye);
// Push (aka write pixel) colours to the TFT (use setAddrWindow() first) // Push (aka write pixel) colours to the TFT (use setAddrWindow() first)
void pushColor(uint16_t color), void pushColor(uint16_t color, uint32_t len), // Deprecated, use pushBlock()
pushColor(uint16_t color, uint32_t len), // Deprecated, use pushBlock()
pushColors(uint16_t *data, uint32_t len, bool swap = true), // With byte swap option pushColors(uint16_t *data, uint32_t len, bool swap = true), // With byte swap option
pushColors(uint8_t *data, uint32_t len); // Deprecated, use pushPixels() pushColors(uint8_t *data, uint32_t len); // Deprecated, use pushPixels()
...@@ -440,9 +455,6 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac ...@@ -440,9 +455,6 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
// Write a set of pixels stored in memory, use setSwapBytes(true/false) function to correct endianess // Write a set of pixels stored in memory, use setSwapBytes(true/false) function to correct endianess
void pushPixels(const void * data_in, uint32_t len); void pushPixels(const void * data_in, uint32_t len);
// Read the colour of a pixel at x,y and return value in 565 format
uint16_t readPixel(int32_t x, int32_t y);
// Support for half duplex (bi-directional SDA) SPI bus where MOSI must be switched to input // Support for half duplex (bi-directional SDA) SPI bus where MOSI must be switched to input
#ifdef TFT_SDA_READ #ifdef TFT_SDA_READ
#if defined (TFT_eSPI_ENABLE_8_BIT_READ) #if defined (TFT_eSPI_ENABLE_8_BIT_READ)
...@@ -461,6 +473,28 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac ...@@ -461,6 +473,28 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
void fillRectVGradient(int16_t x, int16_t y, int16_t w, int16_t h, uint32_t color1, uint32_t color2); void fillRectVGradient(int16_t x, int16_t y, int16_t w, int16_t h, uint32_t color1, uint32_t color2);
void fillRectHGradient(int16_t x, int16_t y, int16_t w, int16_t h, uint32_t color1, uint32_t color2); void fillRectHGradient(int16_t x, int16_t y, int16_t w, int16_t h, uint32_t color1, uint32_t color2);
// Draw a pixel blended with the pixel colour on the TFT or sprite, return blended colour
// If bg_color is not included the background pixel colour will be read from TFT or sprite
uint16_t drawPixel(int32_t x, int32_t y, uint32_t color, uint8_t alpha, uint32_t bg_color = 0x00FFFFFF);
// Draw a small anti-aliased filled circle at ax,ay with radius r (uses drawWideLine)
// If bg_color is not included the background pixel colour will be read from TFT or sprite
void drawSpot(float ax, float ay, float r, uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF);
// Draw an anti-aliased filled circle at x, y with radius r
// If bg_color is not included the background pixel colour will be read from TFT or sprite
void fillSmoothCircle(int32_t x, int32_t y, int32_t r, uint32_t color, uint32_t bg_color = 0x00FFFFFF);
void fillSmoothRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color, uint32_t bg_color = 0x00FFFFFF);
// Draw an anti-aliased wide line from ax,ay to bx,by width wd with radiused ends (radius is wd/2)
// If bg_color is not included the background pixel colour will be read from TFT or sprite
void drawWideLine(float ax, float ay, float bx, float by, float wd, uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF);
// Draw an anti-aliased wide line from ax,ay to bx,by with different width at each end aw, bw and with radiused ends
// If bg_color is not included the background pixel colour will be read from TFT or sprite
void drawWedgeLine(float ax, float ay, float bx, float by, float aw, float bw, uint32_t fg_color, uint32_t bg_color = 0x00FFFFFF);
void drawCircle(int32_t x, int32_t y, int32_t r, uint32_t color), void drawCircle(int32_t x, int32_t y, int32_t r, uint32_t color),
drawCircleHelper(int32_t x, int32_t y, int32_t r, uint8_t cornername, uint32_t color), drawCircleHelper(int32_t x, int32_t y, int32_t r, uint8_t cornername, uint32_t color),
fillCircle(int32_t x, int32_t y, int32_t r, uint32_t color), fillCircle(int32_t x, int32_t y, int32_t r, uint32_t color),
...@@ -577,6 +611,7 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac ...@@ -577,6 +611,7 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
// Support function to UTF8 decode and draw characters piped through print stream // Support function to UTF8 decode and draw characters piped through print stream
size_t write(uint8_t); size_t write(uint8_t);
size_t write(const uint8_t *buf, size_t len);
// Used by Smooth font class to fetch a pixel colour for the anti-aliasing // Used by Smooth font class to fetch a pixel colour for the anti-aliasing
void setCallback(getColorCallback getCol); void setCallback(getColorCallback getCol);
...@@ -744,6 +779,9 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac ...@@ -744,6 +779,9 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac
// Single GPIO input/output direction control // Single GPIO input/output direction control
void gpioMode(uint8_t gpio, uint8_t mode); void gpioMode(uint8_t gpio, uint8_t mode);
// Helper function: calculate distance of a point from a finite length line between two points
float wedgeLineDistance(float pax, float pay, float bax, float bay, float dr);
// Display variant settings // Display variant settings
uint8_t tabcolor, // ST7735 screen protector "tab" colour (now invalid) uint8_t tabcolor, // ST7735 screen protector "tab" colour (now invalid)
colstart = 0, rowstart = 0; // Screen display area to CGRAM area coordinate offsets colstart = 0, rowstart = 0; // Screen display area to CGRAM area coordinate offsets
......
...@@ -27,6 +27,15 @@ getViewportHeight KEYWORD2 ...@@ -27,6 +27,15 @@ getViewportHeight KEYWORD2
getViewportDatum KEYWORD2 getViewportDatum KEYWORD2
frameViewport KEYWORD2 frameViewport KEYWORD2
# Smooth (anti-aliased) graphics functions
fillRectHGradient KEYWORD2
fillRectVGradient KEYWORD2
fillSmoothCircle KEYWORD2
fillSmoothRoundRect KEYWORD2
drawSpot KEYWORD2
drawWideLine KEYWORD2
drawWedgeLine KEYWORD2
pushColor KEYWORD2 pushColor KEYWORD2
pushColors KEYWORD2 pushColors KEYWORD2
pushBlock KEYWORD2 pushBlock KEYWORD2
......
{ {
"name": "TFT_eSPI", "name": "TFT_eSPI",
"version": "2.4.32", "version": "2.4.33",
"keywords": "Arduino, tft, ePaper, display, Pico, RP2040, STM32, ESP8266, NodeMCU, ESP32, M5Stack, ILI9341, ST7735, ILI9163, S6D02A1, ILI9481, ILI9486, ILI9488, ST7789, RM68140, SSD1351, SSD1963, ILI9225, HX8357D", "keywords": "Arduino, tft, ePaper, display, Pico, RP2040, STM32, ESP8266, NodeMCU, ESP32, M5Stack, ILI9341, ST7735, ILI9163, S6D02A1, ILI9481, ILI9486, ILI9488, ST7789, RM68140, SSD1351, SSD1963, ILI9225, HX8357D",
"description": "A TFT and ePaper SPI graphics library with optimisation for Raspberry Pi Pico, ESP8266, ESP32 and STM32", "description": "A TFT and ePaper SPI graphics library with optimisation for Raspberry Pi Pico, ESP8266, ESP32 and STM32",
"repository": "repository":
......
name=TFT_eSPI name=TFT_eSPI
version=2.4.32 version=2.4.33
author=Bodmer author=Bodmer
maintainer=Bodmer maintainer=Bodmer
sentence=TFT graphics library for Arduino processors with performance optimisation for RP2040, STM32, ESP8266 and ESP32 sentence=TFT graphics library for Arduino processors with performance optimisation for RP2040, STM32, ESP8266 and ESP32
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment