Skip to content

Commit d37f202

Browse files
authored
Arc test (Bodmer#2316)
* Add smooth arc drawing function Update ESP8266 architecture reference Add pushMaskedImage() to render 16bpp images with a 1bpp mask (used for transparent PNG images plus with sprites) New functions added using drawArc: drawSmoothArc drawSmoothCircle drawSmoothRoundRect New sqrt_fraction() added to improve smooth graphics performance on processors without a FPU (e.g. RP2040) Faster alphaBlend() function added which retains 6bpp for green Rename swap_coord() to transpose() * Update TFT_eSPI.cpp * Add arc examples
1 parent ea82a7c commit d37f202

22 files changed

+140146
-119
lines changed

Extensions/Sprite.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -1257,8 +1257,8 @@ void TFT_eSprite::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const u
12571257
// Intentionally not constrained to viewport area, does not manage 1bpp rotations
12581258
void TFT_eSprite::setWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1)
12591259
{
1260-
if (x0 > x1) swap_coord(x0, x1);
1261-
if (y0 > y1) swap_coord(y0, y1);
1260+
if (x0 > x1) transpose(x0, x1);
1261+
if (y0 > y1) transpose(y0, y1);
12621262

12631263
int32_t w = width();
12641264
int32_t h = height();
@@ -1700,13 +1700,13 @@ void TFT_eSprite::drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint3
17001700

17011701
bool steep = abs(y1 - y0) > abs(x1 - x0);
17021702
if (steep) {
1703-
swap_coord(x0, y0);
1704-
swap_coord(x1, y1);
1703+
transpose(x0, y0);
1704+
transpose(x1, y1);
17051705
}
17061706

17071707
if (x0 > x1) {
1708-
swap_coord(x0, x1);
1709-
swap_coord(y0, y1);
1708+
transpose(x0, x1);
1709+
transpose(y0, y1);
17101710
}
17111711

17121712
int32_t dx = x1 - x0, dy = abs(y1 - y0);;

Processors/TFT_eSPI_ESP8266.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define DMA_BUSY_CHECK // DMA not available, leave blank
2020

2121
// Initialise processor specific SPI functions, used by init()
22-
#if (!defined (SUPPORT_TRANSACTIONS) && defined (ESP8266))
22+
#if (!defined (SUPPORT_TRANSACTIONS) && defined (ARDUINO_ARCH_ESP8266))
2323
#define INIT_TFT_DATA_BUS \
2424
spi.setBitOrder(MSBFIRST); \
2525
spi.setDataMode(TFT_SPI_MODE); \

Processors/TFT_eSPI_RP2040.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len){
577577

578578

579579
////////////////////////////////////////////////////////////////////////////////////////
580-
#ifdef RP2040_DMA // DMA functions for 16 bit SPI and 8 bit parallel displays
580+
#ifdef RP2040_DMA // DMA functions for 16 bit SPI and 8/16 bit parallel displays
581581
////////////////////////////////////////////////////////////////////////////////////////
582582
/*
583583
These are created in header file:

Processors/TFT_eSPI_RP2040.h

+37-5
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,20 @@
6565
#define DMA_BUSY_CHECK
6666
#endif
6767

68+
// Handle high performance MHS RPi display type
69+
#if defined (MHS_DISPLAY_TYPE) && !defined (RPI_DISPLAY_TYPE)
70+
#define RPI_DISPLAY_TYPE
71+
#endif
72+
6873
#if !defined (RP2040_PIO_INTERFACE) // SPI
69-
// Initialise processor specific SPI functions, used by init()
70-
#define INIT_TFT_DATA_BUS // Not used
74+
75+
#if defined (MHS_DISPLAY_TYPE) // High speed RPi TFT type always needs 16 bit transfers
76+
// This swaps to 16 bit mode, used for commands so wait avoids clash with DC timing
77+
#define INIT_TFT_DATA_BUS hw_write_masked(&spi_get_hw(SPI_X)->cr0, (16 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS)
78+
#else
79+
// Initialise processor specific SPI functions, used by init()
80+
#define INIT_TFT_DATA_BUS // Not used
81+
#endif
7182

7283
// Wait for tx to end, flush rx FIFO, clear rx overrun
7384
#define SPI_BUSY_CHECK while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {}; \
@@ -141,7 +152,7 @@
141152
#if !defined (RP2040_PIO_INTERFACE)// SPI
142153
//#define DC_C sio_hw->gpio_clr = (1ul << TFT_DC)
143154
//#define DC_D sio_hw->gpio_set = (1ul << TFT_DC)
144-
#if defined (RPI_DISPLAY_TYPE)
155+
#if defined (RPI_DISPLAY_TYPE) && !defined (MHS_DISPLAY_TYPE)
145156
#define DC_C digitalWrite(TFT_DC, LOW);
146157
#define DC_D digitalWrite(TFT_DC, HIGH);
147158
#else
@@ -167,7 +178,7 @@
167178
#define CS_H // No macro allocated so it generates no code
168179
#else
169180
#if !defined (RP2040_PIO_INTERFACE) // SPI
170-
#if defined (RPI_DISPLAY_TYPE)
181+
#if defined (RPI_DISPLAY_TYPE) && !defined (MHS_DISPLAY_TYPE)
171182
#define CS_L digitalWrite(TFT_CS, LOW);
172183
#define CS_H digitalWrite(TFT_CS, HIGH);
173184
#else
@@ -287,7 +298,28 @@
287298
// Macros to write commands/pixel colour data to other displays
288299
////////////////////////////////////////////////////////////////////////////////////////
289300
#else
290-
#if defined (RPI_DISPLAY_TYPE) // RPi TFT type always needs 16 bit transfers
301+
#if defined (MHS_DISPLAY_TYPE) // High speed RPi TFT type always needs 16 bit transfers
302+
// This swaps to 16 bit mode, used for commands so wait avoids clash with DC timing
303+
#define tft_Write_8(C) while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {}; \
304+
hw_write_masked(&spi_get_hw(SPI_X)->cr0, (16 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS); \
305+
spi_get_hw(SPI_X)->dr = (uint32_t)((C) | ((C)<<8)); \
306+
while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {}; \
307+
308+
// Note: the following macros do not wait for the end of transmission
309+
310+
#define tft_Write_16(C) while (!spi_is_writable(SPI_X)){}; spi_get_hw(SPI_X)->dr = (uint32_t)(C)
311+
312+
#define tft_Write_16N(C) while (!spi_is_writable(SPI_X)){}; spi_get_hw(SPI_X)->dr = (uint32_t)(C)
313+
314+
#define tft_Write_16S(C) while (!spi_is_writable(SPI_X)){}; spi_get_hw(SPI_X)->dr = (uint32_t)(C)<<8 | (C)>>8
315+
316+
#define tft_Write_32(C) spi_get_hw(SPI_X)->dr = (uint32_t)((C)>>16); spi_get_hw(SPI_X)->dr = (uint32_t)(C)
317+
318+
#define tft_Write_32C(C,D) spi_get_hw(SPI_X)->dr = (uint32_t)(C); spi_get_hw(SPI_X)->dr = (uint32_t)(D)
319+
320+
#define tft_Write_32D(C) spi_get_hw(SPI_X)->dr = (uint32_t)(C); spi_get_hw(SPI_X)->dr = (uint32_t)(C)
321+
322+
#elif defined (RPI_DISPLAY_TYPE) // RPi TFT type always needs 16 bit transfers
291323
#define tft_Write_8(C) spi.transfer(C); spi.transfer(C)
292324
#define tft_Write_16(C) spi.transfer((uint8_t)((C)>>8));spi.transfer((uint8_t)((C)>>0))
293325
#define tft_Write_16N(C) spi.transfer((uint8_t)((C)>>8));spi.transfer((uint8_t)((C)>>0))

0 commit comments

Comments
 (0)