Fix #1188
Support debugged for ILI9488 TFT with RP2040 processors. Minor improvements to ESP32 code.
This commit is contained in:
1 parent
8164629397
commit
5a6ef1d05d
8 files changed
+196
-52
No files matched your search
@@ -191,6 +191,7 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len)
|
||||
** Function name: pushBlock - for ESP32
|
||||
** Description: Write a block of pixels of the same colour
|
||||
***************************************************************************************/
|
||||
/*
|
||||
void TFT_eSPI::pushBlock(uint16_t color, uint32_t len){
|
||||
|
||||
uint32_t color32 = (color<<8 | color >>8)<<16 | (color<<8 | color >>8);
|
||||
@@ -236,7 +237,43 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len){
|
||||
}
|
||||
while ((*_spi_cmd)&SPI_USR); // Move to later in code to use transmit time usefully?
|
||||
}
|
||||
//*/
|
||||
//*
|
||||
void TFT_eSPI::pushBlock(uint16_t color, uint32_t len){
|
||||
|
||||
volatile uint32_t* spi_w = _spi_w;
|
||||
uint32_t color32 = (color<<8 | color >>8)<<16 | (color<<8 | color >>8);
|
||||
uint32_t i = 0;
|
||||
uint32_t rem = len & 0x1F;
|
||||
len = len - rem;
|
||||
|
||||
// Start with partial buffer pixels
|
||||
if (rem)
|
||||
{
|
||||
while (*_spi_cmd&SPI_USR);
|
||||
for (i=0; i < rem; i+=2) *spi_w++ = color32;
|
||||
*_spi_mosi_dlen = (rem << 4) - 1;
|
||||
*_spi_cmd = SPI_USR;
|
||||
if (!len) return; //{while (*_spi_cmd&SPI_USR); return; }
|
||||
i = i>>1; while(i++<16) *spi_w++ = color32;
|
||||
}
|
||||
|
||||
while (*_spi_cmd&SPI_USR);
|
||||
if (!rem) while (i++<16) *spi_w++ = color32;
|
||||
*_spi_mosi_dlen = 511;
|
||||
|
||||
// End with full buffer to maximise useful time for downstream code
|
||||
while(len)
|
||||
{
|
||||
while (*_spi_cmd&SPI_USR);
|
||||
*_spi_cmd = SPI_USR;
|
||||
len -= 32;
|
||||
}
|
||||
|
||||
// Do not wait here
|
||||
//while (*_spi_cmd&SPI_USR);
|
||||
}
|
||||
//*/
|
||||
/***************************************************************************************
|
||||
** Function name: pushSwapBytePixels - for ESP32
|
||||
** Description: Write a sequence of pixels with swapped bytes
|
||||
|
||||
@@ -71,6 +71,12 @@
|
||||
#define DMA_BUSY_CHECK
|
||||
#endif
|
||||
|
||||
#if defined(TFT_PARALLEL_8_BIT)
|
||||
#define SPI_BUSY_CHECK
|
||||
#else
|
||||
#define SPI_BUSY_CHECK while (*_spi_cmd&SPI_USR)
|
||||
#endif
|
||||
|
||||
// If smooth font is used then it is likely SPIFFS will be needed
|
||||
#ifdef SMOOTH_FONT
|
||||
// Call up the SPIFFS (SPI FLASH Filing System) for the anti-aliased fonts
|
||||
@@ -382,6 +388,9 @@
|
||||
spi.transfer(((C) & 0x07E0)>>3); \
|
||||
spi.transfer(((C) & 0x001F)<<3)
|
||||
|
||||
// Future option for transfer without wait
|
||||
#define tft_Write_16N(C) tft_Write_16(C)
|
||||
|
||||
// Convert swapped byte 16 bit colour to 18 bit and write in 3 bytes
|
||||
#define tft_Write_16S(C) spi.transfer((C) & 0xF8); \
|
||||
spi.transfer(((C) & 0xE000)>>11 | ((C) & 0x07)<<5); \
|
||||
@@ -415,6 +424,9 @@
|
||||
// Write 16 bits with corrected endianess for 16 bit colours
|
||||
#define tft_Write_16(C) TFT_WRITE_BITS((C)<<8 | (C)>>8, 16)
|
||||
|
||||
// Future option for transfer without wait
|
||||
#define tft_Write_16N(C) tft_Write_16(C)
|
||||
|
||||
// Write 16 bits
|
||||
#define tft_Write_16S(C) TFT_WRITE_BITS(C, 16)
|
||||
|
||||
@@ -432,7 +444,7 @@
|
||||
// Macros for all other SPI displays
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
#else
|
||||
|
||||
/* Old macros
|
||||
// ESP32 low level SPI writes for 8, 16 and 32 bit values
|
||||
// to avoid the function call overhead
|
||||
#define TFT_WRITE_BITS(D, B) \
|
||||
@@ -458,7 +470,37 @@
|
||||
|
||||
// Write same value twice
|
||||
#define tft_Write_32D(C) TFT_WRITE_BITS((uint16_t)((C)<<8 | (C)>>8)<<16 | (uint16_t)((C)<<8 | (C)>>8), 32)
|
||||
//*/
|
||||
//* Replacement slimmer macros
|
||||
#define TFT_WRITE_BITS(D, B) *_spi_mosi_dlen = B-1; \
|
||||
*_spi_w = D; \
|
||||
*_spi_cmd = SPI_USR; \
|
||||
while (*_spi_cmd & SPI_USR);
|
||||
|
||||
// Write 8 bits
|
||||
#define tft_Write_8(C) TFT_WRITE_BITS(C, 8)
|
||||
|
||||
// Write 16 bits with corrected endianess for 16 bit colours
|
||||
#define tft_Write_16(C) TFT_WRITE_BITS((C)<<8 | (C)>>8, 16)
|
||||
|
||||
// Future option for transfer without wait
|
||||
#define tft_Write_16N(C) *_spi_mosi_dlen = 16-1; \
|
||||
*_spi_w = ((C)<<8 | (C)>>8); \
|
||||
*_spi_cmd = SPI_USR;
|
||||
|
||||
// Write 16 bits
|
||||
#define tft_Write_16S(C) TFT_WRITE_BITS(C, 16)
|
||||
|
||||
// Write 32 bits
|
||||
#define tft_Write_32(C) TFT_WRITE_BITS(C, 32)
|
||||
|
||||
// Write two address coordinates
|
||||
#define tft_Write_32C(C,D) TFT_WRITE_BITS((uint16_t)((D)<<8 | (D)>>8)<<16 | (uint16_t)((C)<<8 | (C)>>8), 32)
|
||||
|
||||
// Write same value twice
|
||||
#define tft_Write_32D(C) TFT_WRITE_BITS((uint16_t)((C)<<8 | (C)>>8)<<16 | (uint16_t)((C)<<8 | (C)>>8), 32)
|
||||
|
||||
//*/
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -7,9 +7,14 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined (TFT_PARALLEL_8_BIT)
|
||||
// Select the SPI port to use
|
||||
//SPIClass& spi = SPI;
|
||||
MbedSPI spi = MbedSPI(TFT_MISO, TFT_MOSI, TFT_SCLK);
|
||||
// Select the SPI port and board package to use
|
||||
#ifdef ARDUINO_ARCH_MBED
|
||||
// Arduino RP2040 board package
|
||||
MbedSPI spi = MbedSPI(TFT_MISO, TFT_MOSI, TFT_SCLK);
|
||||
#else
|
||||
// Community RP2040 board package by Earle Philhower
|
||||
SPIClass& spi = SPI;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef RP2040_DMA
|
||||
@@ -185,12 +190,31 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len)
|
||||
***************************************************************************************/
|
||||
void TFT_eSPI::pushBlock(uint16_t color, uint32_t len)
|
||||
{
|
||||
// Split out the colours
|
||||
uint8_t r = (color & 0xF800)>>8;
|
||||
uint8_t g = (color & 0x07E0)>>3;
|
||||
uint8_t b = (color & 0x001F)<<3;
|
||||
uint16_t r = (color & 0xF800)>>8;
|
||||
uint16_t g = (color & 0x07E0)>>3;
|
||||
uint16_t b = (color & 0x001F)<<3;
|
||||
|
||||
while ( len-- ) {tft_Write_8(r); tft_Write_8(g); tft_Write_8(b);}
|
||||
// If more than 32 pixels then change to 16 bit transfers with concatenated pixels
|
||||
if (len > 32) {
|
||||
uint32_t rg = r<<8 | g;
|
||||
uint32_t br = b<<8 | r;
|
||||
uint32_t gb = g<<8 | b;
|
||||
// Must wait before changing to 16 bit
|
||||
while (spi_get_hw(spi0)->sr & SPI_SSPSR_BSY_BITS) {};
|
||||
spi_set_format(spi0, 16, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST);
|
||||
while ( len > 1 ) {
|
||||
while (!spi_is_writable(spi0)){}; spi_get_hw(spi0)->dr = rg;
|
||||
while (!spi_is_writable(spi0)){}; spi_get_hw(spi0)->dr = br;
|
||||
while (!spi_is_writable(spi0)){}; spi_get_hw(spi0)->dr = gb;
|
||||
len -= 2;
|
||||
}
|
||||
// Must wait before changing back to 8 bit
|
||||
while (spi_get_hw(spi0)->sr & SPI_SSPSR_BSY_BITS) {};
|
||||
spi_set_format(spi0, 8, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST);
|
||||
}
|
||||
|
||||
// Mop up the remaining pixels
|
||||
while ( len-- ) {tft_Write_8N(r);tft_Write_8N(g);tft_Write_8N(b);}
|
||||
}
|
||||
|
||||
/***************************************************************************************
|
||||
@@ -202,19 +226,14 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len){
|
||||
uint16_t *data = (uint16_t*)data_in;
|
||||
if (_swapBytes) {
|
||||
while ( len-- ) {
|
||||
uint16_t color = *data >> 8 | *data << 8;
|
||||
tft_Write_8((color & 0xF800)>>8);
|
||||
tft_Write_8((color & 0x07E0)>>3);
|
||||
tft_Write_8((color & 0x001F)<<3);
|
||||
data++;
|
||||
uint32_t col = *data++;
|
||||
tft_Write_16(col);
|
||||
}
|
||||
}
|
||||
else {
|
||||
while ( len-- ) {
|
||||
tft_Write_8((*data & 0xF800)>>8);
|
||||
tft_Write_8((*data & 0x07E0)>>3);
|
||||
tft_Write_8((*data & 0x001F)<<3);
|
||||
data++;
|
||||
uint32_t col = *data++;
|
||||
tft_Write_16S(col);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#ifndef _TFT_eSPI_RP2040H_
|
||||
#define _TFT_eSPI_RP2040H_
|
||||
|
||||
#include "hardware/dma.h"
|
||||
//#include "hardware/dma.h"
|
||||
|
||||
// Processor ID reported by getSetup()
|
||||
#define PROCESSOR_ID 0x2040
|
||||
@@ -17,7 +17,7 @@
|
||||
// None
|
||||
|
||||
// Processor specific code used by SPI bus transaction begin/end_tft_write functions
|
||||
#define SET_BUS_WRITE_MODE spi_set_format(spi0, 16, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST)
|
||||
#define SET_BUS_WRITE_MODE spi_set_format(spi0, 8, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST)
|
||||
#define SET_BUS_READ_MODE // spi_set_format(spi0, 8, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST)
|
||||
|
||||
// Code to check if SPI or DMA is busy, used by SPI bus transaction startWrite and/or endWrite functions
|
||||
@@ -56,6 +56,8 @@
|
||||
#define DC_C // No macro allocated so it generates no code
|
||||
#define DC_D // No macro allocated so it generates no code
|
||||
#else
|
||||
//#define DC_C sio_hw->gpio_clr = (1ul << TFT_DC)
|
||||
//#define DC_D sio_hw->gpio_set = (1ul << TFT_DC)
|
||||
#define DC_C sio_hw->gpio_clr = (1ul << TFT_DC)
|
||||
#define DC_D sio_hw->gpio_set = (1ul << TFT_DC)
|
||||
#endif
|
||||
@@ -110,30 +112,44 @@
|
||||
#if defined (SPI_18BIT_DRIVER) // SPI 18 bit colour
|
||||
|
||||
// Write 8 bits to TFT
|
||||
#define tft_Write_8(C) spi.transfer(C)
|
||||
#define tft_Write_8(C) spi_get_hw(spi0)->dr = (uint32_t)(C); \
|
||||
while (spi_get_hw(spi0)->sr & SPI_SSPSR_BSY_BITS) {}; \
|
||||
|
||||
//#define tft_Write_8(C) spi.transfer(C);
|
||||
#define tft_Write_8N(B) while (!spi_is_writable(spi0)){}; \
|
||||
spi_get_hw(spi0)->dr = (uint8_t)(B)
|
||||
|
||||
// Convert 16 bit colour to 18 bit and write in 3 bytes
|
||||
#define tft_Write_16(C) spi.transfer(((C) & 0xF800)>>8); \
|
||||
spi.transfer(((C) & 0x07E0)>>3); \
|
||||
spi.transfer(((C) & 0x001F)<<3)
|
||||
#define tft_Write_16(C) tft_Write_8N(((C) & 0xF800)>>8); \
|
||||
tft_Write_8N(((C) & 0x07E0)>>3); \
|
||||
tft_Write_8N(((C) & 0x001F)<<3)
|
||||
|
||||
// Convert 16 bit colour to 18 bit and write in 3 bytes
|
||||
#define tft_Write_16N(C) spi.transfer(((C) & 0xF800)>>8); \
|
||||
spi.transfer(((C) & 0x07E0)>>3); \
|
||||
spi.transfer(((C) & 0x001F)<<3)
|
||||
#define tft_Write_16N(C) tft_Write_8N(((C) & 0xF800)>>8); \
|
||||
tft_Write_8N(((C) & 0x07E0)>>3); \
|
||||
tft_Write_8N(((C) & 0x001F)<<3)
|
||||
|
||||
// Convert swapped byte 16 bit colour to 18 bit and write in 3 bytes
|
||||
#define tft_Write_16S(C) spi.transfer((C) & 0xF8); \
|
||||
spi.transfer(((C) & 0xE000)>>11 | ((C) & 0x07)<<5); \
|
||||
spi.transfer(((C) & 0x1F00)>>5)
|
||||
#define tft_Write_16S(C) tft_Write_8N((C) & 0xF8); \
|
||||
tft_Write_8N(((C) & 0xE000)>>11 | ((C) & 0x07)<<5); \
|
||||
tft_Write_8N(((C) & 0x1F00)>>5)
|
||||
// Write 32 bits to TFT
|
||||
#define tft_Write_32(C) spi.transfer16((C)>>16); spi.transfer16((uint16_t)(C))
|
||||
#define tft_Write_32(C) tft_Write_8N(C>>24); \
|
||||
tft_Write_8N(C>>16); \
|
||||
tft_Write_8N(C>>8); \
|
||||
tft_Write_8N(C)
|
||||
|
||||
// Write two address coordinates
|
||||
#define tft_Write_32C(C,D) spi.transfer16(C); spi.transfer16(D)
|
||||
#define tft_Write_32C(C,D) tft_Write_8N(C>>8); \
|
||||
tft_Write_8N(C); \
|
||||
tft_Write_8N(D>>8); \
|
||||
tft_Write_8N(D)
|
||||
|
||||
// Write same value twice
|
||||
#define tft_Write_32D(C) spi.transfer16(C); spi.transfer16(C)
|
||||
#define tft_Write_32D(C) tft_Write_8N(C>>8); \
|
||||
tft_Write_8N(C); \
|
||||
tft_Write_8N(C>>8); \
|
||||
tft_Write_8N(C)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Macros to write commands/pixel colour data to other displays
|
||||
@@ -178,11 +194,11 @@
|
||||
|
||||
#define tft_Write_16S(C) while (!spi_is_writable(spi0)){}; spi_get_hw(spi0)->dr = (uint32_t)(C)<<8 | (C)>>8
|
||||
|
||||
#define tft_Write_32(C) while (!spi_is_writable(spi0)){}; spi_get_hw(spi0)->dr = (uint32_t)((C)>>8);spi_get_hw(spi0)->dr = (uint32_t)(C)
|
||||
#define tft_Write_32(C) spi_get_hw(spi0)->dr = (uint32_t)((C)>>16); spi_get_hw(spi0)->dr = (uint32_t)(C)
|
||||
|
||||
#define tft_Write_32C(C,D) while (!spi_is_writable(spi0)){}; spi_get_hw(spi0)->dr = (uint32_t)(C);spi_get_hw(spi0)->dr = (uint32_t)(D)
|
||||
#define tft_Write_32C(C,D) spi_get_hw(spi0)->dr = (uint32_t)(C); spi_get_hw(spi0)->dr = (uint32_t)(D)
|
||||
|
||||
#define tft_Write_32D(C) while (!spi_is_writable(spi0)){}; spi_get_hw(spi0)->dr = (uint32_t)(C);spi_get_hw(spi0)->dr = (uint32_t)(C)
|
||||
#define tft_Write_32D(C) spi_get_hw(spi0)->dr = (uint32_t)(C); spi_get_hw(spi0)->dr = (uint32_t)(C)
|
||||
|
||||
#endif // RPI_DISPLAY_TYPE
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user