Skip to content

Commit

Permalink
Fix Bodmer#1547 for RP2040 processor with ST7789 TFT
Browse files Browse the repository at this point in the history
Add Arduino Nano Connect setup example 62
  • Loading branch information
Bodmer committed Jan 26, 2022
1 parent 4201659 commit e61fb8c
Show file tree
Hide file tree
Showing 12 changed files with 251 additions and 43 deletions.
4 changes: 2 additions & 2 deletions Extensions/Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ void TFT_eSPI_Button::drawButton(bool inverted, String long_name) {
_gfx->drawRoundRect(_x1, _y1, _w, _h, r, outline);

if (_gfx->textfont == 255) {
_gfx->setCursor(_x1 + (_w / 2) - (strlen(_label) * 3 * _textsize),
_y1 + (_h / 2) - (4 * _textsize));
_gfx->setCursor(_x1 + (_w / 8),
_y1 + (_h / 4));
_gfx->setTextColor(text);
_gfx->setTextSize(_textsize);
_gfx->print(_label);
Expand Down
12 changes: 6 additions & 6 deletions Processors/TFT_eSPI_ESP32.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len)
***************************************************************************************/
/*
void TFT_eSPI::pushBlock(uint16_t color, uint32_t len){
uint32_t color32 = (color<<8 | color >>8)<<16 | (color<<8 | color >>8);
bool empty = true;
volatile uint32_t* spi_w = (volatile uint32_t*)_spi_w;
Expand Down Expand Up @@ -262,7 +262,7 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len){
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 color32 = (color<<8 | color >>8)<<16 | (color<<8 | color >>8);
uint32_t i = 0;
uint32_t rem = len & 0x1F;
len = len - rem;
Expand All @@ -287,7 +287,7 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len){
{
while (*_spi_cmd&SPI_USR);
*_spi_cmd = SPI_USR;
len -= 32;
len -= 32;
}

// Do not wait here
Expand Down Expand Up @@ -315,7 +315,7 @@ void TFT_eSPI::pushSwapBytePixels(const void* data_in, uint32_t len){
data+=4;
}
while (READ_PERI_REG(SPI_CMD_REG(SPI_PORT))&SPI_USR);
WRITE_PERI_REG(SPI_W0_REG(SPI_PORT), color[0]);
WRITE_PERI_REG(SPI_W0_REG(SPI_PORT), color[0]);
WRITE_PERI_REG(SPI_W1_REG(SPI_PORT), color[1]);
WRITE_PERI_REG(SPI_W2_REG(SPI_PORT), color[2]);
WRITE_PERI_REG(SPI_W3_REG(SPI_PORT), color[3]);
Expand Down Expand Up @@ -346,7 +346,7 @@ void TFT_eSPI::pushSwapBytePixels(const void* data_in, uint32_t len){
}
while (READ_PERI_REG(SPI_CMD_REG(SPI_PORT))&SPI_USR);
WRITE_PERI_REG(SPI_MOSI_DLEN_REG(SPI_PORT), 255);
WRITE_PERI_REG(SPI_W0_REG(SPI_PORT), color[0]);
WRITE_PERI_REG(SPI_W0_REG(SPI_PORT), color[0]);
WRITE_PERI_REG(SPI_W1_REG(SPI_PORT), color[1]);
WRITE_PERI_REG(SPI_W2_REG(SPI_PORT), color[2]);
WRITE_PERI_REG(SPI_W3_REG(SPI_PORT), color[3]);
Expand Down Expand Up @@ -832,5 +832,5 @@ void TFT_eSPI::deInitDMA(void)
}

////////////////////////////////////////////////////////////////////////////////////////
#endif // End of DMA FUNCTIONS
#endif // End of DMA FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////////
30 changes: 15 additions & 15 deletions Processors/TFT_eSPI_RP2040.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ void pioinit(uint32_t clock_freq) {

// Create the pull stall bit mask
pull_stall_mask = 1u << (PIO_FDEBUG_TXSTALL_LSB + pio_sm);

// Create the assembler instruction for the jump to byte send routine
pio_instr_jmp8 = pio_encode_jmp(program_offset + tft_io_offset_start_8);
pio_instr_fill = pio_encode_jmp(program_offset + tft_io_offset_block_fill);
pio_instr_addr = pio_encode_jmp(program_offset + tft_io_offset_set_addr_window);

pio_instr_set_dc = pio_encode_set((pio_src_dest)0, 1);
pio_instr_clr_dc = pio_encode_set((pio_src_dest)0, 0);
}
Expand Down Expand Up @@ -212,7 +212,7 @@ void pioinit(uint16_t clock_div, uint16_t fract_div) {

// Create the pull stall bit mask
pull_stall_mask = 1u << (PIO_FDEBUG_TXSTALL_LSB + pio_sm);

// Create the instructions for the jumps to send routines
pio_instr_jmp8 = pio_encode_jmp(program_offset + tft_io_offset_start_8);
pio_instr_fill = pio_encode_jmp(program_offset + tft_io_offset_block_fill);
Expand All @@ -235,7 +235,7 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len)
if (len) {
WAIT_FOR_STALL;
pio->sm[pio_sm].instr = pio_instr_fill;

TX_FIFO = color;
TX_FIFO = --len; // Decrement first as PIO sends n+1
}
Expand Down Expand Up @@ -368,13 +368,13 @@ uint8_t TFT_eSPI::readByte(void)
b |= digitalRead(TFT_D7) << 7;
digitalWrite(TFT_RD, HIGH);
busDir(0, OUTPUT);
busDir(0, OUTPUT);
*/
return b;
}

////////////////////////////////////////////////////////////////////////////////////////
#elif defined (RPI_WRITE_STROBE) // For RPi TFT with write strobe
#elif defined (RPI_WRITE_STROBE) // For RPi TFT with write strobe
////////////////////////////////////////////////////////////////////////////////////////

/***************************************************************************************
Expand All @@ -400,7 +400,7 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len)
}

////////////////////////////////////////////////////////////////////////////////////////
#elif defined (SPI_18BIT_DRIVER) // SPI 18 bit colour
#elif defined (SPI_18BIT_DRIVER) // SPI 18 bit colour
////////////////////////////////////////////////////////////////////////////////////////

/***************************************************************************************
Expand All @@ -420,7 +420,7 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len)
uint32_t gb = g<<8 | b;
// Must wait before changing to 16 bit
while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {};
spi_set_format(SPI_X, 16, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST);
hw_write_masked(&spi_get_hw(SPI_X)->cr0, (16 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS);
while ( len > 1 ) {
while (!spi_is_writable(SPI_X)){}; spi_get_hw(SPI_X)->dr = rg;
while (!spi_is_writable(SPI_X)){}; spi_get_hw(SPI_X)->dr = br;
Expand All @@ -429,7 +429,7 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len)
}
// Must wait before changing back to 8 bit
while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {};
spi_set_format(SPI_X, 8, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST);
hw_write_masked(&spi_get_hw(SPI_X)->cr0, (8 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS);
}

// Mop up the remaining pixels
Expand Down Expand Up @@ -458,7 +458,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 @@ -524,7 +524,7 @@ bool TFT_eSPI::dmaBusy(void) {
#if !defined (RP2040_PIO_INTERFACE)
// For SPI must also wait for FIFO to flush and reset format
while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {};
spi_set_format(SPI_X, 16, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST);
hw_write_masked(&spi_get_hw(SPI_X)->cr0, (16 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS);
#endif

return false;
Expand All @@ -541,7 +541,7 @@ void TFT_eSPI::dmaWait(void)
#if !defined (RP2040_PIO_INTERFACE)
// For SPI must also wait for FIFO to flush and reset format
while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {};
spi_set_format(SPI_X, 16, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST);
hw_write_masked(&spi_get_hw(SPI_X)->cr0, (16 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS);
#endif
}

Expand Down Expand Up @@ -624,12 +624,12 @@ void TFT_eSPI::pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t
bool TFT_eSPI::initDMA(bool ctrl_cs)
{
if (DMA_Enabled) return false;

ctrl_cs = ctrl_cs; // stop unused parameter warning

dma_tx_channel = dma_claim_unused_channel(true);
dma_tx_config = dma_channel_get_default_config(dma_tx_channel);

channel_config_set_transfer_data_size(&dma_tx_config, DMA_SIZE_16);
#if !defined (RP2040_PIO_INTERFACE)
channel_config_set_dreq(&dma_tx_config, spi_get_index(SPI_X) ? DREQ_SPI1_TX : DREQ_SPI0_TX);
Expand All @@ -653,5 +653,5 @@ void TFT_eSPI::deInitDMA(void)
}

////////////////////////////////////////////////////////////////////////////////////////
#endif // End of DMA FUNCTIONS
#endif // End of DMA FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////////
15 changes: 10 additions & 5 deletions Processors/TFT_eSPI_RP2040.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
#ifndef _TFT_eSPI_RP2040H_
#define _TFT_eSPI_RP2040H_

#ifndef ARDUINO_ARCH_MBED
#define FONT_FS_AVAILABLE
#define SPIFFS LittleFS
#endif

// Required for both the official and community board packages
#include "hardware/dma.h"
#include "hardware/pio.h"
Expand Down Expand Up @@ -37,7 +42,7 @@
#endif

// Processor specific code used by SPI bus transaction begin/end_tft_write functions
#define SET_BUS_WRITE_MODE spi_set_format(SPI_X, 8, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST)
#define SET_BUS_WRITE_MODE spi_set_format(SPI_X, 8, (spi_cpol_t)(TFT_SPI_MODE >> 1), (spi_cpha_t)(TFT_SPI_MODE & 0x1), SPI_MSB_FIRST)
#define SET_BUS_READ_MODE // spi_set_format(SPI_X, 8, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST)
#else
// Processor specific code used by SPI bus transaction begin/end_tft_write functions
Expand Down Expand Up @@ -98,7 +103,7 @@
#ifdef SMOOTH_FONT
// Call up the filing system for the anti-aliased fonts
//#define FS_NO_GLOBALS
//#include <FS.h>
#include <FS.h>
#endif

////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -183,7 +188,7 @@
#endif
#else
#ifdef TOUCH_CS
#error Touch screen not supported in parallel mode, use a separate library.
#error Touch screen not supported in parallel or SPI PIO mode, use a separate library.
#endif
#endif

Expand Down Expand Up @@ -271,10 +276,10 @@

// This swaps to 8 bit mode, then back to 16 bit mode
#define tft_Write_8(C) while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {}; \
spi_set_format(SPI_X, 8, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST); \
hw_write_masked(&spi_get_hw(SPI_X)->cr0, (8 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS); \
spi_get_hw(SPI_X)->dr = (uint32_t)(C); \
while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {}; \
spi_set_format(SPI_X, 16, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST)
hw_write_masked(&spi_get_hw(SPI_X)->cr0, (16 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS)

// Note: the following macros do not wait for the end of transmission

Expand Down
1 change: 1 addition & 0 deletions TFT_Drivers/ST7789_Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
#define ST7789_TEOFF 0x34 // Tearing effect line off
#define ST7789_TEON 0x35 // Tearing effect line on
#define ST7789_MADCTL 0x36 // Memory data access control
#define ST7789_VSCRSADD 0x37 // Vertical screoll address
#define ST7789_IDMOFF 0x38 // Idle mode off
#define ST7789_IDMON 0x39 // Idle mode on
#define ST7789_RAMWRC 0x3C // Memory write continue (ST7789V)
Expand Down
13 changes: 6 additions & 7 deletions TFT_eSPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3097,9 +3097,9 @@ void TFT_eSPI::setWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1)
DC_C;
#if !defined (SPI_18BIT_DRIVER)
#if defined (RPI_DISPLAY_TYPE) // RPi TFT type always needs 16 bit transfers
spi_set_format(SPI_X, 16, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST);
hw_write_masked(&spi_get_hw(SPI_X)->cr0, (16 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS);
#else
spi_set_format(SPI_X, 8, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST);
hw_write_masked(&spi_get_hw(SPI_X)->cr0, (8 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS);
#endif
#endif
spi_get_hw(SPI_X)->dr = (uint32_t)TFT_CASET;
Expand Down Expand Up @@ -3128,7 +3128,7 @@ void TFT_eSPI::setWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1)

while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {};
#if !defined (SPI_18BIT_DRIVER)
spi_set_format(SPI_X, 16, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST);
hw_write_masked(&spi_get_hw(SPI_X)->cr0, (16 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS);
#endif
DC_D;
#else
Expand Down Expand Up @@ -3184,7 +3184,7 @@ void TFT_eSPI::readAddrWindow(int32_t xs, int32_t ys, int32_t w, int32_t h)
#if (defined(ARDUINO_ARCH_RP2040) || defined (ARDUINO_ARCH_MBED)) && !defined(RP2040_PIO_INTERFACE)
while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {};
DC_C;
spi_set_format(SPI_X, 8, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST);
hw_write_masked(&spi_get_hw(SPI_X)->cr0, (8 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS);
spi_get_hw(SPI_X)->dr = (uint32_t)TFT_CASET;

while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {};
Expand All @@ -3210,7 +3210,6 @@ void TFT_eSPI::readAddrWindow(int32_t xs, int32_t ys, int32_t w, int32_t h)
spi_get_hw(SPI_X)->dr = (uint32_t)TFT_RAMRD;

while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {};
//spi_set_format(SPI_X, 8, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST);
DC_D;

// Flush the rx buffer and reset overflow flag
Expand Down Expand Up @@ -3305,9 +3304,9 @@ void TFT_eSPI::drawPixel(int32_t x, int32_t y, uint32_t color)
while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {};

#if defined (RPI_DISPLAY_TYPE) // RPi TFT type always needs 16 bit transfers
spi_set_format(SPI_X, 16, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST);
hw_write_masked(&spi_get_hw(SPI_X)->cr0, (16 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS);
#else
spi_set_format(SPI_X, 8, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST);
hw_write_masked(&spi_get_hw(SPI_X)->cr0, (8 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS);
#endif

if (addr_col != x) {
Expand Down
2 changes: 1 addition & 1 deletion TFT_eSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#ifndef _TFT_eSPIH_
#define _TFT_eSPIH_

#define TFT_ESPI_VERSION "2.4.25"
#define TFT_ESPI_VERSION "2.4.27"

// Bit level feature flags
// Bit 0 set: viewport capability
Expand Down
13 changes: 9 additions & 4 deletions User_Setup_Select.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

// Only ONE line below should be uncommented. Add extra lines and files as needed.

#include <User_Setup.h> // Default setup is root library folder
//#include <User_Setup.h> // Default setup is root library folder

//#include <User_Setups/Setup1_ILI9341.h> // Setup file configured for my ILI9341
//#include <User_Setups/Setup2_ST7735.h> // Setup file configured for my ST7735
Expand All @@ -46,7 +46,7 @@
//#include <User_Setups/Setup20_ILI9488.h> // Setup file for ESP8266 and ILI9488 SPI bus TFT
//#include <User_Setups/Setup21_ILI9488.h> // Setup file for ESP32 and ILI9488 SPI bus TFT

//#include <User_Setups/Setup22_TTGO_T4.h> // Setup file for ESP32 and TTGO T4 version 1.2
#include <User_Setups/Setup22_TTGO_T4.h> // Setup file for ESP32 and TTGO T4 version 1.2
//#include <User_Setups/Setup22_TTGO_T4_v1.3.h> // Setup file for ESP32 and TTGO T4 version 1.3
//#include <User_Setups/Setup23_TTGO_TM.h> // Setup file for ESP32 and TTGO TM ST7789 SPI bus TFT
//#include <User_Setups/Setup24_ST7789.h> // Setup file configured for ST7789 240 x 240
Expand Down Expand Up @@ -79,8 +79,9 @@
//#include <User_Setups/Setup51_LilyPi_ILI9481.h> // Setup file for LilyGo LilyPi with ILI9481 display
//#include <User_Setups/Setup52_LilyPi_ST7796.h> // Setup file for LilyGo LilyPi with ST7796 display

//#include <User_Setups/Setup60_RP2040_ILI9341.h> // Setup file for Raspberry Pi Pico with SPI ILI9341
//#include <User_Setups/Setup60_RP2040_ILI9341.h> // Setup file for RP2040 with SPI ILI9341
//#include <User_Setups/Setup61_RP2040_ILI9341_PIO_SPI.h> // Setup file for RP2040 with PIO SPI ILI9341
//#include <User_Setups/Setup62_RP2040_Nano_Connect_ILI9341.h> // Setup file for RP2040 with SPI ILI9341

//#include <User_Setups/Setup70_ESP32_S2_ILI9341.h> // Setup file for ESP32 S2 with SPI ILI9341

Expand All @@ -106,6 +107,11 @@
//#include <User_Setups/SetupX_Template.h>


//#include <User_Setups/Dustin_ILI9488.h> // Setup file for Dustin Watts PCB with ILI9488
//#include <User_Setups/Dustin_ST7796.h> // Setup file for Dustin Watts PCB with ST7796



#endif // USER_SETUP_LOADED


Expand Down Expand Up @@ -218,7 +224,6 @@
#define TFT_DRIVER 0x0000
#else
#define TFT_DRIVER 0x0000
# error "####### NO TFT DRIVER DEFINED #######"
#endif

// These are the pins for ESP8266 boards
Expand Down
2 changes: 1 addition & 1 deletion User_Setups/Setup22_TTGO_T4_v1.3.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define TFT_SCLK 18

#define TFT_CS 27
#define TFT_DC 32 // pin 26 for TTGO T4 v1.3 <<<<<<<<<<< Note
#define TFT_DC 32 // pin 26 for TTGO T4 v1.1
#define TFT_RST 5

#define LOAD_GLCD
Expand Down
Loading

0 comments on commit e61fb8c

Please sign in to comment.