From a3bf8baeeea5db87d8a96aedbf84f15899db5fc5 Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Tue, 14 Sep 2021 13:39:42 +0100 Subject: [PATCH 1/3] Call spi_write_blocking directly for RP2040 This is around a 6-13x speed up in graphicstest (at 62.5Mhz) --- Adafruit_SPITFT.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Adafruit_SPITFT.cpp b/Adafruit_SPITFT.cpp index ba67e0c4..fd855a81 100644 --- a/Adafruit_SPITFT.cpp +++ b/Adafruit_SPITFT.cpp @@ -1326,7 +1326,13 @@ void Adafruit_SPITFT::writeColor(uint16_t color, uint32_t len) { hwspi._spi->write(lo); } } while (len); -#else // !ESP8266 +#elif defined(ARDUINO_ARCH_RP2040) + spi_inst_t *pi_spi = hwspi._spi == &SPI ? spi0 : spi1; + color = __builtin_bswap16(color); + + while (len--) + spi_write_blocking(pi_spi, (uint8_t *)&color, 2); +#else // !ESP8266 && !ARDUINO_ARCH_RP2040 while (len--) { #if defined(__AVR__) AVR_WRITESPI(hi); @@ -2079,6 +2085,9 @@ void Adafruit_SPITFT::spiWrite(uint8_t b) { AVR_WRITESPI(b); #elif defined(ESP8266) || defined(ESP32) hwspi._spi->write(b); +#elif defined(ARDUINO_ARCH_RP2040) + spi_inst_t *pi_spi = hwspi._spi == &SPI ? spi0 : spi1; + spi_write_blocking(pi_spi, &b, 1); #else hwspi._spi->transfer(b); #endif @@ -2385,6 +2394,10 @@ void Adafruit_SPITFT::SPI_WRITE16(uint16_t w) { AVR_WRITESPI(w); #elif defined(ESP8266) || defined(ESP32) hwspi._spi->write16(w); +#elif defined(ARDUINO_ARCH_RP2040) + spi_inst_t *pi_spi = hwspi._spi == &SPI ? spi0 : spi1; + w = __builtin_bswap16(w); + spi_write_blocking(pi_spi, (uint8_t *)&w, 2); #else // MSB, LSB because TFTs are generally big-endian hwspi._spi->transfer(w >> 8); @@ -2437,6 +2450,10 @@ void Adafruit_SPITFT::SPI_WRITE32(uint32_t l) { AVR_WRITESPI(l); #elif defined(ESP8266) || defined(ESP32) hwspi._spi->write32(l); +#elif defined(ARDUINO_ARCH_RP2040) + spi_inst_t *pi_spi = hwspi._spi == &SPI ? spi0 : spi1; + l = __builtin_bswap32(l); + spi_write_blocking(pi_spi, (uint8_t *)&l, 4); #else hwspi._spi->transfer(l >> 24); hwspi._spi->transfer(l >> 16); From b654431d6f3f1530bbb85832c85b946d68314481 Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Wed, 15 Sep 2021 12:09:08 +0100 Subject: [PATCH 2/3] Even more direct writes for writePixels on RP2040 Switch SPI to 16-bit for little-endian, write bytes as-is for big-endian --- Adafruit_SPITFT.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Adafruit_SPITFT.cpp b/Adafruit_SPITFT.cpp index fd855a81..6c5ca922 100644 --- a/Adafruit_SPITFT.cpp +++ b/Adafruit_SPITFT.cpp @@ -1021,6 +1021,19 @@ void Adafruit_SPITFT::writePixels(uint16_t *colors, uint32_t len, bool block, swapBytes(colors, len); // big-to-little endian to restore pixel buffer } + return; +#elif defined(ARDUINO_ARCH_RP2040) + spi_inst_t *pi_spi = hwspi._spi == &SPI ? spi0 : spi1; + + if (!bigEndian) { + // switch to 16-bit writes + hw_write_masked(&spi_get_hw(pi_spi)->cr0, 15 << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS); + spi_write16_blocking(pi_spi, colors, len); + // switch back to 8-bit + hw_write_masked(&spi_get_hw(pi_spi)->cr0, 7 << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS); + } else { + spi_write_blocking(pi_spi, (uint8_t *)colors, len * 2); + } return; #elif defined(USE_SPI_DMA) && \ (defined(__SAMD51__) || defined(ARDUINO_SAMD_ZERO)) From cda80a23d231cb498d964912e55dc3e226613a27 Mon Sep 17 00:00:00 2001 From: Paint Your Dragon Date: Fri, 17 Sep 2021 10:49:34 -0700 Subject: [PATCH 3/3] Update Adafruit_SPITFT.cpp Appease clang-format --- Adafruit_SPITFT.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Adafruit_SPITFT.cpp b/Adafruit_SPITFT.cpp index 6c5ca922..b78d5ce5 100644 --- a/Adafruit_SPITFT.cpp +++ b/Adafruit_SPITFT.cpp @@ -1027,10 +1027,12 @@ void Adafruit_SPITFT::writePixels(uint16_t *colors, uint32_t len, bool block, if (!bigEndian) { // switch to 16-bit writes - hw_write_masked(&spi_get_hw(pi_spi)->cr0, 15 << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS); + hw_write_masked(&spi_get_hw(pi_spi)->cr0, 15 << SPI_SSPCR0_DSS_LSB, + SPI_SSPCR0_DSS_BITS); spi_write16_blocking(pi_spi, colors, len); // switch back to 8-bit - hw_write_masked(&spi_get_hw(pi_spi)->cr0, 7 << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS); + hw_write_masked(&spi_get_hw(pi_spi)->cr0, 7 << SPI_SSPCR0_DSS_LSB, + SPI_SSPCR0_DSS_BITS); } else { spi_write_blocking(pi_spi, (uint8_t *)colors, len * 2); }