Skip to content

Commit

Permalink
Update lib
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Oct 17, 2023
1 parent e9b0a27 commit 97fd7e5
Show file tree
Hide file tree
Showing 33 changed files with 2,788 additions and 135 deletions.
12 changes: 6 additions & 6 deletions lib/TFT_eSPI/Extensions/Sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ void* TFT_eSprite::createSprite(int16_t w, int16_t h, uint8_t frames)
_img8_2 = _img8 + (w * h + 1);
}

if ( (_bpp == 4) && (_colorMap == nullptr)) createPalette(default_4bit_palette);

// This is to make it clear what pointer size is expected to be used
// but casting in the user sketch is needed due to the use of void*
if ( (_bpp == 1) && (frames > 1) )
Expand All @@ -101,6 +99,8 @@ void* TFT_eSprite::createSprite(int16_t w, int16_t h, uint8_t frames)
if (_img8)
{
_created = true;
if ( (_bpp == 4) && (_colorMap == nullptr)) createPalette(default_4bit_palette);

rotation = 0;
setViewport(0, 0, _dwidth, _dheight);
setPivot(_iwidth/2, _iheight/2);
Expand Down Expand Up @@ -1985,10 +1985,6 @@ void TFT_eSprite::drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uin
{
if ( _vpOoB || !_created ) return;

if ((x >= _vpW - _xDatum) || // Clip right
(y >= _vpH - _yDatum)) // Clip bottom
return;

if (c < 32) return;
#ifdef LOAD_GLCD
//>>>>>>>>>>>>>>>>>>
Expand All @@ -1997,6 +1993,10 @@ void TFT_eSprite::drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uin
#endif
//>>>>>>>>>>>>>>>>>>

if ((x >= _vpW - _xDatum) || // Clip right
(y >= _vpH - _yDatum)) // Clip bottom
return;

if (((x + 6 * size - 1) < (_vpX - _xDatum)) || // Clip left
((y + 8 * size - 1) < (_vpY - _yDatum))) // Clip top
return;
Expand Down
9 changes: 9 additions & 0 deletions lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,13 @@ void TFT_eSPI::pushPixelsDMA(uint16_t* image, uint32_t len)
// small transfers are performed using a blocking call until DMA capacity is reached.
// User sketch can prevent blocking by managing pixel count and splitting into blocks
// of 32768 pixels maximum. (equivalent to an area of ~320 x 100 pixels)
bool temp = _swapBytes;
_swapBytes = false;
while(len>0x4000) { // Transfer 16 bit pixels in blocks if len*2 over 65536 bytes
pushPixels(image, 0x400);
len -= 0x400; image+= 0x400; // Arbitrarily send 1K pixel blocks (2Kbytes)
}
_swapBytes = temp;

esp_err_t ret;
static spi_transaction_t trans;
Expand Down Expand Up @@ -685,10 +688,13 @@ void TFT_eSPI::pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t
// small transfers are performed using a blocking call until DMA capacity is reached.
// User sketch can prevent blocking by managing pixel count and splitting into blocks
// of 32768 pixels maximum. (equivalent to an area of ~320 x 100 pixels)
bool temp = _swapBytes;
_swapBytes = false;
while(len>0x4000) { // Transfer 16 bit pixels in blocks if len*2 over 65536 bytes
pushPixels(buffer, 0x400);
len -= 0x400; buffer+= 0x400; // Arbitrarily send 1K pixel blocks (2Kbytes)
}
_swapBytes = temp;

esp_err_t ret;
static spi_transaction_t trans;
Expand Down Expand Up @@ -770,10 +776,13 @@ void TFT_eSPI::pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t
// small transfers are performed using a blocking call until DMA capacity is reached.
// User sketch can prevent blocking by managing pixel count and splitting into blocks
// of 32768 pixels maximum. (equivalent to an area of ~320 x 100 pixels)
bool temp = _swapBytes;
_swapBytes = false;
while(len>0x4000) { // Transfer 16 bit pixels in blocks if len*2 over 65536 bytes
pushPixels(buffer, 0x400);
len -= 0x400; buffer+= 0x400; // Arbitrarily send 1K pixel blocks (2Kbytes)
}
_swapBytes = temp;

esp_err_t ret;
static spi_transaction_t trans;
Expand Down
56 changes: 18 additions & 38 deletions lib/TFT_eSPI/Processors/TFT_eSPI_RP2040.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@
SPIClassRP2040 spi = SPIClassRP2040(SPI_X, TFT_MISO, -1, TFT_SCLK, TFT_MOSI);
#endif

#else // PIO interface used (8 bit parallel or SPI)
#else // PIO interface used (8-bit parallel or SPI)

#ifdef RP2040_PIO_SPI
#if defined (SPI_18BIT_DRIVER)
// SPI PIO code for 18 bit colour transmit
#include "pio_SPI_18bit.pio.h"
#else
// SPI PIO code for 16 bit colour transmit
// SPI PIO code for 16-bit colour transmit
#include "pio_SPI.pio.h"
#endif
#elif defined (TFT_PARALLEL_8_BIT)
#if defined (SSD1963_DRIVER)
// PIO code for 8 bit parallel interface (18 bit colour)
// PIO code for 8-bit parallel interface (18 bit colour)
#include "pio_8bit_parallel_18bpp.pio.h"
#else
// PIO code for 8 bit parallel interface (16 bit colour)
// PIO code for 8-bit parallel interface (16-bit colour)
#include "pio_8bit_parallel.pio.h"
#endif
#else // must be TFT_PARALLEL_16_BIT
// PIO code for 16 bit parallel interface (16 bit colour)
// PIO code for 16-bit parallel interface (16-bit colour)
#include "pio_16bit_parallel.pio.h"
#endif

Expand Down Expand Up @@ -128,24 +128,12 @@ void TFT_eSPI::end_SDA_Read(void)
#ifdef RP2040_PIO_SPI
void pioinit(uint32_t clock_freq) {

// Find a free SM on one of the PIO's
tft_pio = pio0;

/*
pio_sm = pio_claim_unused_sm(tft_pio, false); // false means don't panic
// Try pio1 if SM not found
if (pio_sm < 0) {
tft_pio = pio1;
pio_sm = pio_claim_unused_sm(tft_pio, true); // panic this time if no SM is free
}
*/

// Find enough free space on one of the PIO's
tft_pio = pio0;
if (!pio_can_add_program(tft_pio, &tft_io_program)) {
tft_pio = pio1;
if (!pio_can_add_program(tft_pio, &tft_io_program)) {
Serial.println("No room for PIO program!");
// Serial.println("No room for PIO program!");
return;
}
}
Expand Down Expand Up @@ -197,29 +185,21 @@ void pioinit(uint32_t clock_freq) {
pio_instr_set_dc = pio_encode_set((pio_src_dest)0, 1);
pio_instr_clr_dc = pio_encode_set((pio_src_dest)0, 0);
}
#else // 8 or 16 bit parallel
#else // 8 or 16-bit parallel
void pioinit(uint16_t clock_div, uint16_t fract_div) {

// Find a free SM on one of the PIO's
tft_pio = pio0;
pio_sm = pio_claim_unused_sm(tft_pio, false); // false means don't panic
// Try pio1 if SM not found
if (pio_sm < 0) {
tft_pio = pio1;
pio_sm = pio_claim_unused_sm(tft_pio, true); // panic this time if no SM is free
}
/*
// Find enough free space on one of the PIO's
tft_pio = pio0;
if (!pio_can_add_program(tft_pio, &tft_io_program) {
if (!pio_can_add_program(tft_pio, &tft_io_program)) {
tft_pio = pio1;
if (!pio_can_add_program(tft_pio, &tft_io_program) {
Serial.println("No room for PIO program!");
while(1) delay(100);
if (!pio_can_add_program(tft_pio, &tft_io_program)) {
// Serial.println("No room for PIO program!");
return;
}
}
*/

pio_sm = pio_claim_unused_sm(tft_pio, false);

#if defined (TFT_PARALLEL_8_BIT)
uint8_t bits = 8;
#else // must be TFT_PARALLEL_16_BIT
Expand Down Expand Up @@ -491,12 +471,12 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len)
uint16_t g = (color & 0x07E0)>>3;
uint16_t b = (color & 0x001F)<<3;

// If more than 32 pixels then change to 16 bit transfers with concatenated pixels
// 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
// Must wait before changing to 16-bit
while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {};
hw_write_masked(&spi_get_hw(SPI_X)->cr0, (16 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS);
while ( len > 1 ) {
Expand All @@ -505,7 +485,7 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len)
while (!spi_is_writable(SPI_X)){}; spi_get_hw(SPI_X)->dr = gb;
len -= 2;
}
// Must wait before changing back to 8 bit
// Must wait before changing back to 8-bit
while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {};
hw_write_masked(&spi_get_hw(SPI_X)->cr0, (8 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS);
}
Expand Down Expand Up @@ -536,7 +516,7 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len){
}

////////////////////////////////////////////////////////////////////////////////////////
#else // Standard SPI 16 bit colour TFT
#else // Standard SPI 16-bit colour TFT
////////////////////////////////////////////////////////////////////////////////////////

/***************************************************************************************
Expand Down Expand Up @@ -582,7 +562,7 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len){


////////////////////////////////////////////////////////////////////////////////////////
#ifdef RP2040_DMA // DMA functions for 16 bit SPI and 8/16 bit parallel displays
#ifdef RP2040_DMA // DMA functions for 16-bit SPI and 8/16-bit parallel displays
////////////////////////////////////////////////////////////////////////////////////////
/*
These are created in header file:
Expand Down
Loading

0 comments on commit 97fd7e5

Please sign in to comment.