acidportal- 😈 Worlds smallest Evil Portal on a LilyGo T-QT |
git clone git://git.acid.vegas/acidportal.git |
Log | Files | Refs | Archive | README | LICENSE |
TFT_eSPI_ESP8266.h (8665B)
1 ////////////////////////////////////////////////////// 2 // TFT_eSPI driver functions for ESP8266 processors // 3 ////////////////////////////////////////////////////// 4 5 #ifndef _TFT_eSPI_ESP8266H_ 6 #define _TFT_eSPI_ESP8266H_ 7 8 // Processor ID reported by getSetup() 9 #define PROCESSOR_ID 0x8266 10 11 // Include processor specific header 12 // None 13 14 // Processor specific code used by SPI bus transaction startWrite and endWrite functions 15 #define SET_BUS_WRITE_MODE SPI1U=SPI1U_WRITE 16 #define SET_BUS_READ_MODE SPI1U=SPI1U_READ 17 18 // Code to check if DMA is busy, used by SPI bus transaction transaction and endWrite functions 19 #define DMA_BUSY_CHECK // DMA not available, leave blank 20 21 // Initialise processor specific SPI functions, used by init() 22 #if (!defined (SUPPORT_TRANSACTIONS) && defined (ARDUINO_ARCH_ESP8266)) 23 #define INIT_TFT_DATA_BUS \ 24 spi.setBitOrder(MSBFIRST); \ 25 spi.setDataMode(TFT_SPI_MODE); \ 26 spi.setFrequency(SPI_FREQUENCY); 27 #else 28 #define INIT_TFT_DATA_BUS 29 #endif 30 31 // If smooth fonts are enabled the filing system may need to be loaded 32 #ifdef SMOOTH_FONT 33 // Call up the SPIFFS FLASH filing system for the anti-aliased fonts 34 #define FS_NO_GLOBALS 35 #include <FS.h> 36 #define FONT_FS_AVAILABLE 37 #endif 38 39 // Do not allow parallel mode for ESP8266 40 #ifdef ESP32_PARALLEL 41 #undef ESP32_PARALLEL 42 #endif 43 #ifdef TFT_PARALLEL_8_BIT 44 #undef TFT_PARALLEL_8_BIT 45 #endif 46 47 //////////////////////////////////////////////////////////////////////////////////////// 48 // Define the DC (TFT Data/Command or Register Select (RS))pin drive code 49 //////////////////////////////////////////////////////////////////////////////////////// 50 #ifndef TFT_DC 51 #define DC_C // No macro allocated so it generates no code 52 #define DC_D // No macro allocated so it generates no code 53 #else 54 #if (TFT_DC == 16) 55 #define DC_C digitalWrite(TFT_DC, LOW) 56 #define DC_D digitalWrite(TFT_DC, HIGH) 57 #else 58 #define DC_C GPOC=dcpinmask 59 #define DC_D GPOS=dcpinmask 60 #endif 61 #endif 62 63 //////////////////////////////////////////////////////////////////////////////////////// 64 // Define the CS (TFT chip select) pin drive code 65 //////////////////////////////////////////////////////////////////////////////////////// 66 #ifndef TFT_CS 67 #define CS_L // No macro allocated so it generates no code 68 #define CS_H // No macro allocated so it generates no code 69 #else 70 #if (TFT_CS == 16) 71 #define CS_L digitalWrite(TFT_CS, LOW) 72 #define CS_H digitalWrite(TFT_CS, HIGH) 73 #else 74 #define CS_L GPOC=cspinmask 75 #define CS_H GPOS=cspinmask 76 #endif 77 #endif 78 79 //////////////////////////////////////////////////////////////////////////////////////// 80 // Define the WR (TFT Write) pin drive code 81 //////////////////////////////////////////////////////////////////////////////////////// 82 #ifdef TFT_WR 83 #define WR_L GPOC=wrpinmask 84 #define WR_H GPOS=wrpinmask 85 #endif 86 87 //////////////////////////////////////////////////////////////////////////////////////// 88 // Define the touch screen chip select pin drive code 89 //////////////////////////////////////////////////////////////////////////////////////// 90 #ifndef TOUCH_CS 91 #define T_CS_L // No macro allocated so it generates no code 92 #define T_CS_H // No macro allocated so it generates no code 93 #else 94 #define T_CS_L digitalWrite(TOUCH_CS, LOW) 95 #define T_CS_H digitalWrite(TOUCH_CS, HIGH) 96 #endif 97 98 //////////////////////////////////////////////////////////////////////////////////////// 99 // Make sure TFT_MISO is defined if not used to avoid an error message 100 //////////////////////////////////////////////////////////////////////////////////////// 101 #ifndef TFT_MISO 102 #define TFT_MISO -1 103 #endif 104 105 //////////////////////////////////////////////////////////////////////////////////////// 106 // ESP8266 specific SPI macros 107 //////////////////////////////////////////////////////////////////////////////////////// 108 #if defined (TFT_SPI_OVERLAP) 109 #undef TFT_CS 110 #define SPI1U_WRITE (SPIUMOSI | SPIUSSE | SPIUCSSETUP | SPIUCSHOLD) 111 #define SPI1U_READ (SPIUMOSI | SPIUSSE | SPIUCSSETUP | SPIUCSHOLD | SPIUDUPLEX) 112 #else 113 #define SPI1U_WRITE (SPIUMOSI | SPIUSSE) 114 #define SPI1U_READ (SPIUMOSI | SPIUSSE | SPIUDUPLEX) 115 #endif 116 117 //////////////////////////////////////////////////////////////////////////////////////// 118 // Macros to write commands/pixel colour data to a SPI ILI948x TFT 119 //////////////////////////////////////////////////////////////////////////////////////// 120 #if defined (SPI_18BIT_DRIVER) // SPI 18 bit colour 121 122 // Write 8 bits to TFT 123 #define tft_Write_8(C) spi.transfer(C) 124 125 // Convert 16 bit colour to 18 bit and write in 3 bytes 126 #define tft_Write_16(C) spi.transfer(((C) & 0xF800)>>8); \ 127 spi.transfer(((C) & 0x07E0)>>3); \ 128 spi.transfer(((C) & 0x001F)<<3) 129 130 // Convert swapped byte 16 bit colour to 18 bit and write in 3 bytes 131 #define tft_Write_16S(C) spi.transfer((C) & 0xF8); \ 132 spi.transfer(((C) & 0xE000)>>11 | ((C) & 0x07)<<5); \ 133 spi.transfer(((C) & 0x1F00)>>5) 134 135 // Write 32 bits to TFT 136 #define tft_Write_32(C) spi.write32(C) 137 138 // Write two address coordinates 139 #define tft_Write_32C(C,D) spi.write32((C)<<16 | (D)) 140 141 // Write same value twice 142 #define tft_Write_32D(C) spi.write32((C)<<16 | (C)) 143 144 //////////////////////////////////////////////////////////////////////////////////////// 145 // Macros to write commands/pixel colour data to an Raspberry Pi TFT 146 //////////////////////////////////////////////////////////////////////////////////////// 147 #elif defined (RPI_DISPLAY_TYPE) 148 // Command is 16 bits 149 #define CMD_BITS 16 150 151 // ESP8266 low level SPI writes for 8, 16 and 32 bit values 152 // to avoid the function call overhead 153 #define TFT_WRITE_BITS(D, B) \ 154 SPI1U1 = ((B-1) << SPILMOSI); \ 155 SPI1W0 = D; \ 156 SPI1CMD |= SPIBUSY; \ 157 while(SPI1CMD & SPIBUSY) {} 158 159 #define tft_Write_8(C) TFT_WRITE_BITS((uint16_t)(C)<<8, CMD_BITS) 160 161 #define tft_Write_16(C) TFT_WRITE_BITS((C)>>8 | (C)<<8, 16) 162 163 #define tft_Write_16S(C) TFT_WRITE_BITS(C, 16) 164 165 #define tft_Write_32(C) TFT_WRITE_BITS(C, 32) 166 167 #define tft_Write_32C(C,D) SPI1U1 = ((64-1) << SPILMOSI); \ 168 SPI1W0 = ((C)<<24) | (C); \ 169 SPI1W1 = ((D)<<24) | (D); \ 170 SPI1CMD |= SPIBUSY; \ 171 while(SPI1CMD & SPIBUSY) {;} 172 173 #define tft_Write_32D(C) tft_Write_32C(C,C) 174 175 //////////////////////////////////////////////////////////////////////////////////////// 176 // Macros for all other SPI displays 177 //////////////////////////////////////////////////////////////////////////////////////// 178 #else 179 // Command is 8 bits 180 #define CMD_BITS 8 181 182 #define tft_Write_8(C) \ 183 SPI1U1 = ((CMD_BITS-1) << SPILMOSI) | ((CMD_BITS-1) << SPILMISO); \ 184 SPI1W0 = (C)<<(CMD_BITS - 8); \ 185 SPI1CMD |= SPIBUSY; \ 186 while(SPI1CMD & SPIBUSY) {;} 187 188 #define tft_Write_16(C) \ 189 SPI1U1 = (15 << SPILMOSI) | (15 << SPILMISO); \ 190 SPI1W0 = ((C)<<8 | (C)>>8); \ 191 SPI1CMD |= SPIBUSY; \ 192 while(SPI1CMD & SPIBUSY) {;} 193 194 #define tft_Write_16N(C) \ 195 SPI1U1 = (15 << SPILMOSI) | (15 << SPILMISO); \ 196 SPI1W0 = ((C)<<8 | (C)>>8); \ 197 SPI1CMD |= SPIBUSY 198 199 #define tft_Write_16S(C) \ 200 SPI1U1 = (15 << SPILMOSI) | (15 << SPILMISO); \ 201 SPI1W0 = C; \ 202 SPI1CMD |= SPIBUSY; \ 203 while(SPI1CMD & SPIBUSY) {;} 204 205 #define tft_Write_32(C) \ 206 SPI1U1 = (31 << SPILMOSI) | (31 << SPILMISO); \ 207 SPI1W0 = C; \ 208 SPI1CMD |= SPIBUSY; \ 209 while(SPI1CMD & SPIBUSY) {;} 210 211 #define tft_Write_32C(C,D) \ 212 SPI1U1 = (31 << SPILMOSI) | (31 << SPILMISO); \ 213 SPI1W0 = ((D)>>8 | (D)<<8)<<16 | ((C)>>8 | (C)<<8); \ 214 SPI1CMD |= SPIBUSY; \ 215 while(SPI1CMD & SPIBUSY) {;} 216 217 #define tft_Write_32D(C) \ 218 SPI1U1 = (31 << SPILMOSI) | (31 << SPILMISO); \ 219 SPI1W0 = ((C)>>8 | (C)<<8)<<16 | ((C)>>8 | (C)<<8); \ 220 SPI1CMD |= SPIBUSY; \ 221 while(SPI1CMD & SPIBUSY) {;} 222 223 #endif 224 225 #ifndef tft_Write_16N 226 #define tft_Write_16N tft_Write_16 227 #endif 228 229 //////////////////////////////////////////////////////////////////////////////////////// 230 // Macros to read from display using SPI or software SPI 231 //////////////////////////////////////////////////////////////////////////////////////// 232 #if defined (TFT_SDA_READ) 233 // Use a bit banged function call for ESP8266 and bi-directional SDA pin 234 #define TFT_eSPI_ENABLE_8_BIT_READ // Enable tft_Read_8(void); 235 #define SCLK_L GPOC=sclkpinmask 236 #define SCLK_H GPOS=sclkpinmask 237 #else 238 // Use a SPI read transfer 239 #define tft_Read_8() spi.transfer(0) 240 #endif 241 242 // Concatenate a byte sequence A,B,C,D to CDAB, P is a uint8_t pointer 243 #define DAT8TO32(P) ( (uint32_t)P[0]<<8 | P[1] | P[2]<<24 | P[3]<<16 ) 244 245 #endif // Header end