20 #ifndef _ADAFRUIT_SPITFT_H_ 21 #define _ADAFRUIT_SPITFT_H_ 23 #if !defined(__AVR_ATtiny85__) // Not for ATtiny, at all 25 #include "Adafruit_GFX.h" 32 #define USE_FAST_PINIO 33 #elif defined(ARDUINO_STM32_FEATHER) // WICED 34 typedef class HardwareSPI SPIClass;
36 #elif defined(__arm__) 37 #if defined(ARDUINO_ARCH_SAMD) 40 #define USE_FAST_PINIO 41 #define HAS_PORT_SET_CLR 42 #elif defined(CORE_TEENSY) 44 #if defined(__IMXRT1052__) || defined(__IMXRT1062__) // Teensy 4.x 50 #define USE_FAST_PINIO 51 #define HAS_PORT_SET_CLR 69 #define DEFAULT_SPI_FREQ 8000000L 71 #define DEFAULT_SPI_FREQ 16000000L 74 #if defined(ADAFRUIT_PYPORTAL) || defined(ADAFRUIT_PYPORTAL_M4_TITANO) || \ 75 defined(ADAFRUIT_PYBADGE_M4_EXPRESS) || \ 76 defined(ADAFRUIT_PYGAMER_M4_EXPRESS) || \ 77 defined(ADAFRUIT_MONSTER_M4SK_EXPRESS) || defined(NRF52_SERIES) || \ 78 defined(ADAFRUIT_CIRCUITPLAYGROUND_M0) 90 #if defined(USE_SPI_DMA) && (defined(__SAMD51__) || defined(ARDUINO_SAMD_ZERO)) 91 #include <Adafruit_ZeroDMA.h> 130 Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t cs, int8_t dc, int8_t mosi,
131 int8_t sck, int8_t rst = -1, int8_t miso = -1);
141 #if !defined(ESP8266) // See notes in .cpp 146 int8_t dc, int8_t rst = -1);
147 #endif // end !ESP8266 155 int8_t wr, int8_t dc, int8_t cs = -1, int8_t rst = -1,
170 virtual void begin(uint32_t freq) = 0;
184 virtual void setAddrWindow(uint16_t x, uint16_t y, uint16_t w,
196 void initSPI(uint32_t freq = 0, uint8_t spiMode = SPI_MODE0);
202 void sendCommand(uint8_t commandByte, uint8_t *dataBytes,
203 uint8_t numDataBytes);
204 void sendCommand(uint8_t commandByte,
const uint8_t *dataBytes = NULL,
205 uint8_t numDataBytes = 0);
206 void sendCommand16(uint16_t commandWord,
const uint8_t *dataBytes = NULL,
207 uint8_t numDataBytes = 0);
208 uint8_t
readcommand8(uint8_t commandByte, uint8_t index = 0);
217 void writePixel(int16_t x, int16_t y, uint16_t color);
218 void writePixels(uint16_t *colors, uint32_t len,
bool block =
true,
219 bool bigEndian =
false);
220 void writeColor(uint16_t color, uint32_t len);
221 void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h,
223 void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
224 void writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
231 int16_t h, uint16_t color);
238 void swapBytes(uint16_t *src, uint32_t len, uint16_t *dest = NULL);
244 void drawPixel(int16_t x, int16_t y, uint16_t color);
245 void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
246 void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
247 void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
254 void drawRGBBitmap(int16_t x, int16_t y, uint16_t *pcolors, int16_t w,
258 uint16_t
color565(uint8_t r, uint8_t g, uint8_t b);
292 #if defined(USE_FAST_PINIO) 293 #if defined(HAS_PORT_SET_CLR) 294 #if defined(KINETISK) 297 *csPortSet = csPinMask;
298 #endif // end !KINETISK 299 #else // !HAS_PORT_SET_CLR 300 *csPort |= csPinMaskSet;
301 #endif // end !HAS_PORT_SET_CLR 302 #else // !USE_FAST_PINIO 303 digitalWrite(
_cs, HIGH);
304 #endif // end !USE_FAST_PINIO 314 #if defined(USE_FAST_PINIO) 315 #if defined(HAS_PORT_SET_CLR) 316 #if defined(KINETISK) 319 *csPortClr = csPinMask;
320 #endif // end !KINETISK 321 #else // !HAS_PORT_SET_CLR 322 *csPort &= csPinMaskClr;
323 #endif // end !HAS_PORT_SET_CLR 324 #else // !USE_FAST_PINIO 325 digitalWrite(
_cs, LOW);
326 #endif // end !USE_FAST_PINIO 333 #if defined(USE_FAST_PINIO) 334 #if defined(HAS_PORT_SET_CLR) 335 #if defined(KINETISK) 338 *dcPortSet = dcPinMask;
339 #endif // end !KINETISK 340 #else // !HAS_PORT_SET_CLR 341 *dcPort |= dcPinMaskSet;
342 #endif // end !HAS_PORT_SET_CLR 343 #else // !USE_FAST_PINIO 344 digitalWrite(
_dc, HIGH);
345 #endif // end !USE_FAST_PINIO 352 #if defined(USE_FAST_PINIO) 353 #if defined(HAS_PORT_SET_CLR) 354 #if defined(KINETISK) 357 *dcPortClr = dcPinMask;
358 #endif // end !KINETISK 359 #else // !HAS_PORT_SET_CLR 360 *dcPort &= dcPinMaskClr;
361 #endif // end !HAS_PORT_SET_CLR 362 #else // !USE_FAST_PINIO 363 digitalWrite(
_dc, LOW);
364 #endif // end !USE_FAST_PINIO 392 #if defined(USE_FAST_PINIO) 393 #if defined(HAS_PORT_SET_CLR) 398 #else // !HAS_PORT_SET_CLR 401 #endif // end HAS_PORT_SET_CLR 402 #endif // end USE_FAST_PINIO 403 #if defined(__cplusplus) && (__cplusplus >= 201100) 408 #if defined(SPI_HAS_TRANSACTION) 409 SPISettings settings;
416 #if defined(USE_FAST_PINIO) 418 #if defined(HAS_PORT_SET_CLR) 423 #if !defined(KINETISK) 426 #endif // end !KINETISK 427 #else // !HAS_PORT_SET_CLR 434 #endif // end HAS_PORT_SET_CLR 435 #if !defined(KINETISK) 437 #endif // end !KINETISK 438 #endif // end USE_FAST_PINIO 444 #if defined(USE_FAST_PINIO) 446 #if defined(__IMXRT1052__) || defined(__IMXRT1062__) // Teensy 4.x 447 volatile uint32_t *writePort;
448 volatile uint32_t *readPort;
450 volatile uint8_t *writePort;
451 volatile uint8_t *readPort;
453 #if defined(HAS_PORT_SET_CLR) 456 #if defined(__IMXRT1052__) || defined(__IMXRT1062__) // Teensy 4.x 457 volatile uint32_t *dirSet;
458 volatile uint32_t *dirClr;
460 volatile uint8_t *dirSet;
461 volatile uint8_t *dirClr;
467 #if !defined(KINETISK) 469 #endif // end !KINETISK 471 #else // !HAS_PORT_SET_CLR 474 volatile uint8_t *portDir;
481 #endif // end HAS_PORT_SET_CLR 482 #endif // end USE_FAST_PINIO 488 #if defined(__cplusplus) && (__cplusplus >= 201100) 491 #if defined(USE_SPI_DMA) && \ 492 (defined(__SAMD51__) || \ 493 defined(ARDUINO_SAMD_ZERO)) // Used by hardware SPI and tft8 494 Adafruit_ZeroDMA dma;
495 DmacDescriptor *dptr = NULL;
496 DmacDescriptor *descriptor = NULL;
497 uint16_t *pixelBuf[2];
499 uint16_t lastFillColor = 0;
500 uint32_t lastFillLen = 0;
503 #if defined(USE_FAST_PINIO) 504 #if defined(HAS_PORT_SET_CLR) 505 #if !defined(KINETISK) 508 #endif // end !KINETISK 509 #else // !HAS_PORT_SET_CLR 514 #endif // end HAS_PORT_SET_CLR 515 #endif // end USE_FAST_PINIO 529 #endif // end __AVR_ATtiny85__ 530 #endif // end _ADAFRUIT_SPITFT_H_ void sendCommand(uint8_t commandByte, uint8_t *dataBytes, uint8_t numDataBytes)
Adafruit_SPITFT Send Command handles complete sending of commands and data.
Definition: Adafruit_SPITFT.cpp:1901
void write16(uint16_t w)
Issue a single 16-bit value to the display. Chip-select, transaction and data/command selection must ...
Definition: Adafruit_SPITFT.cpp:2232
uint32_t _freq
SPI bitrate (if no SPI transactions)
Definition: Adafruit_SPITFT.h:411
void writePixels(uint16_t *colors, uint32_t len, bool block=true, bool bigEndian=false)
Issue a series of pixels from memory to the display. Not self- contained; should follow startWrite() ...
Definition: Adafruit_SPITFT.cpp:995
uint8_t invertOffCommand
Command to disable invert mode.
Definition: Adafruit_SPITFT.h:524
int8_t _rd
Read strobe pin # (or -1)
Definition: Adafruit_SPITFT.h:485
void writePixel(int16_t x, int16_t y, uint16_t color)
Draw a single pixel to the display at requested coordinates. Not self-contained; should follow a star...
Definition: Adafruit_SPITFT.cpp:945
struct Adafruit_SPITFT::@2 tft8
Parallel interface settings.
virtual void setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h)=0
Set up the specific display hardware's "address window" for subsequent pixel-pushing operations...
void SPI_WRITE16(uint16_t w)
Issue a single 16-bit value to the display. Chip-select, transaction and data/command selection must ...
Definition: Adafruit_SPITFT.cpp:2394
Definition: Adafruit_GFX.h:18
uint16_t readcommand16(uint16_t addr)
Read 16 bits of data from display register. For 16-bit parallel displays only.
Definition: Adafruit_SPITFT.cpp:2023
void SPI_BEGIN_TRANSACTION(void)
Start an SPI transaction if using the hardware SPI interface to the display. If using an earlier vers...
Definition: Adafruit_SPITFT.cpp:2065
int8_t _sck
SCK pin #.
Definition: Adafruit_SPITFT.h:441
void drawRGBBitmap(int16_t x, int16_t y, uint16_t *pcolors, int16_t w, int16_t h)
Draw a 16-bit image (565 RGB) at the specified (x,y) position. For 16-bit display devices; no color r...
Definition: Adafruit_SPITFT.cpp:1829
void TFT_RD_LOW(void)
Set the RD line LOW. Used for parallel-connected interfaces when reading data.
Definition: Adafruit_SPITFT.cpp:2549
int8_t _cs
Chip select pin # (or -1)
Definition: Adafruit_SPITFT.h:518
void writeColor(uint16_t color, uint32_t len)
Issue a series of pixels, all the same color. Not self- contained; should follow startWrite() and set...
Definition: Adafruit_SPITFT.cpp:1193
void writeCommand16(uint16_t cmd)
Write a single command word to the display. Chip-select and transaction must have been previously set...
Definition: Adafruit_SPITFT.cpp:2252
void SPI_SCK_HIGH(void)
Set the software (bitbang) SPI SCK line HIGH.
Definition: Adafruit_SPITFT.cpp:2333
int8_t _miso
MISO pin #.
Definition: Adafruit_SPITFT.h:440
uint8_t connection
TFT_HARD_SPI, TFT_SOFT_SPI, etc.
Definition: Adafruit_SPITFT.h:516
bool SPI_MISO_READ(void)
Read the state of the software (bitbang) SPI MISO line.
Definition: Adafruit_SPITFT.cpp:2372
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
Draw a horizontal line on the display. Self-contained and provides its own transaction as needed (see...
Definition: Adafruit_SPITFT.cpp:1733
void writeFillRectPreclipped(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
A lower-level version of writeFillRect(). This version requires all inputs are in-bounds, that width and height are positive, and no part extends offscreen. NO EDGE CLIPPING OR REJECTION IS PERFORMED. If higher-level graphics primitives are written to handle their own clipping earlier in the drawing process, this can avoid unnecessary function calls and repeated clipping operations in the lower-level functions.
Definition: Adafruit_SPITFT.cpp:1621
void invertDisplay(bool i)
Invert the colors of the display (if supported by hardware). Self-contained, no transaction setup req...
Definition: Adafruit_SPITFT.cpp:1874
tftBusWidth
Definition: Adafruit_SPITFT.h:103
void dmaWait(void)
Wait for the last DMA transfer in a prior non-blocking writePixels() call to complete. This does nothing if DMA is not enabled, and is not needed if blocking writePixels() was used (as is the default case).
Definition: Adafruit_SPITFT.cpp:1159
Adafruit_SPITFT(uint16_t w, uint16_t h, int8_t cs, int8_t dc, int8_t mosi, int8_t sck, int8_t rst=-1, int8_t miso=-1)
Adafruit_SPITFT constructor for software (bitbang) SPI.
Definition: Adafruit_SPITFT.cpp:117
void setSPISpeed(uint32_t freq)
Allow changing the SPI clock speed after initialization.
Definition: Adafruit_SPITFT.cpp:898
void drawRGBBitmap(int16_t x, int16_t y, const uint16_t bitmap[], int16_t w, int16_t h)
Draw a PROGMEM-resident 16-bit image (RGB 5/6/5) at the specified (x,y) position. For 16-bit display ...
Definition: Adafruit_GFX.cpp:1001
void SPI_CS_LOW(void)
Set the chip-select line LOW. Does NOT check whether CS pin is set (>=0), that should be handled in c...
Definition: Adafruit_SPITFT.h:313
struct Adafruit_SPITFT::@0 hwspi
Hardware SPI values.
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
Draw a vertical line on the display. Self-contained and provides its own transaction as needed (see w...
Definition: Adafruit_SPITFT.cpp:1774
int8_t _wr
Write strobe pin #.
Definition: Adafruit_SPITFT.h:484
void pushColor(uint16_t color)
Essentially writePixel() with a transaction around it. I don't think this is in use by any of our cod...
Definition: Adafruit_SPITFT.cpp:1807
int16_t _ystart
Internal framebuffer Y offset.
Definition: Adafruit_SPITFT.h:522
void SPI_SCK_LOW(void)
Set the software (bitbang) SPI SCK line LOW.
Definition: Adafruit_SPITFT.cpp:2352
void SPI_MOSI_HIGH(void)
Set the software (bitbang) SPI MOSI line HIGH.
Definition: Adafruit_SPITFT.cpp:2295
void sendCommand16(uint16_t commandWord, const uint8_t *dataBytes=NULL, uint8_t numDataBytes=0)
Adafruit_SPITFT sendCommand16 handles complete sending of commands and data for 16-bit parallel displ...
Definition: Adafruit_SPITFT.cpp:1968
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Draw a filled rectangle to the display. Self-contained and provides its own transaction as needed (se...
Definition: Adafruit_SPITFT.cpp:1675
uint32_t _mode
SPI data mode (transactions or no)
Definition: Adafruit_SPITFT.h:413
void writeCommand(uint8_t cmd)
Write a single command byte to the display. Chip-select and transaction must have been previously set...
Definition: Adafruit_SPITFT.cpp:2153
void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Draw a filled rectangle to the display. Not self-contained; should follow startWrite(). Typically used by higher-level graphics primitives; user code shouldn't need to call this and is likely to use the self-contained fillRect() instead. writeFillRect() performs its own edge clipping and rejection; see writeFillRectPreclipped() for a more 'raw' implementation.
Definition: Adafruit_SPITFT.cpp:1489
bool dmaBusy(void) const
Check if DMA transfer is active. Always returts false if DMA is not enabled.
Definition: Adafruit_SPITFT.cpp:1179
void SPI_DC_HIGH(void)
Set the data/command line HIGH (data mode).
Definition: Adafruit_SPITFT.h:332
void SPI_CS_HIGH(void)
Set the chip-select line HIGH. Does NOT check whether CS pin is set (>=0), that should be handled in ...
Definition: Adafruit_SPITFT.h:291
uint16_t read16(void)
Read a single 16-bit value from the display. Chip-select and transaction must have been previously se...
Definition: Adafruit_SPITFT.cpp:2266
volatile ADAGFX_PORT_t * PORTreg_t
PORT register type.
Definition: Adafruit_SPITFT.h:66
SPIClass * _spi
SPI class pointer.
Definition: Adafruit_SPITFT.h:407
struct Adafruit_SPITFT::@1 swspi
Software SPI values.
void SPI_MOSI_LOW(void)
Set the software (bitbang) SPI MOSI line LOW.
Definition: Adafruit_SPITFT.cpp:2314
Adafruit_SPITFT is an intermediary class between Adafruit_GFX and various hardware-specific subclasse...
Definition: Adafruit_SPITFT.h:120
void drawPixel(int16_t x, int16_t y, uint16_t color)
Draw a single pixel to the display at requested coordinates. Self-contained and provides its own tran...
Definition: Adafruit_SPITFT.cpp:1645
void spiWrite(uint8_t b)
Issue a single 8-bit value to the display. Chip-select, transaction and data/command selection must h...
Definition: Adafruit_SPITFT.cpp:2110
uint16_t color565(uint8_t r, uint8_t g, uint8_t b)
Given 8-bit red, green and blue values, return a 'packed' 16-bit color value in '565' RGB format (5 b...
Definition: Adafruit_SPITFT.cpp:1890
int8_t _d0
Data pin 0 #.
Definition: Adafruit_SPITFT.h:483
void SPI_DC_LOW(void)
Set the data/command line LOW (command mode).
Definition: Adafruit_SPITFT.h:351
void endWrite(void)
Call after issuing command(s) or data to display. Performs chip-deselect (if required) and ends an SP...
Definition: Adafruit_SPITFT.cpp:924
uint8_t invertOnCommand
Command to enable invert mode.
Definition: Adafruit_SPITFT.h:523
void startWrite(void)
Call before issuing command(s) or data to display. Performs chip-select (if required) and starts an S...
Definition: Adafruit_SPITFT.cpp:912
void TFT_WR_STROBE(void)
Set the WR line LOW, then HIGH. Used for parallel-connected interfaces when writing data...
Definition: Adafruit_SPITFT.cpp:2509
bool wide
If true, is 16-bit interface.
Definition: Adafruit_SPITFT.h:486
int8_t _dc
Data/command pin #.
Definition: Adafruit_SPITFT.h:519
void SPI_END_TRANSACTION(void)
End an SPI transaction if using the hardware SPI interface to the display. No action is taken if the ...
Definition: Adafruit_SPITFT.cpp:2093
int16_t _xstart
Internal framebuffer X offset.
Definition: Adafruit_SPITFT.h:521
void initSPI(uint32_t freq=0, uint8_t spiMode=SPI_MODE0)
Configure microcontroller pins for TFT interfacing. Typically called by a subclass' begin() function...
Definition: Adafruit_SPITFT.cpp:527
virtual void begin(uint32_t freq)=0
Display-specific initialization function.
void TFT_RD_HIGH(void)
Set the RD line HIGH. Used for parallel-connected interfaces when reading data.
Definition: Adafruit_SPITFT.cpp:2533
void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
Draw a horizontal line on the display. Performs edge clipping and rejection. Not self-contained; shou...
Definition: Adafruit_SPITFT.cpp:1541
void SPI_WRITE32(uint32_t l)
Issue a single 32-bit value to the display. Chip-select, transaction and data/command selection must ...
Definition: Adafruit_SPITFT.cpp:2448
uint8_t spiRead(void)
Read a single 8-bit value from the display. Chip-select and transaction must have been previously set...
Definition: Adafruit_SPITFT.cpp:2169
uint32_t ADAGFX_PORT_t
PORT values are 32-bit.
Definition: Adafruit_SPITFT.h:64
uint8_t readcommand8(uint8_t commandByte, uint8_t index=0)
Read 8 bits of data from display configuration memory (not RAM). This is highly undocumented/supporte...
Definition: Adafruit_SPITFT.cpp:2004
void swapBytes(uint16_t *src, uint32_t len, uint16_t *dest=NULL)
Swap bytes in an array of pixels; converts little-to-big or big-to-little endian. Used by writePixels...
Definition: Adafruit_SPITFT.cpp:962
int8_t _rst
Reset pin # (or -1)
Definition: Adafruit_SPITFT.h:517
int8_t _mosi
MOSI pin #.
Definition: Adafruit_SPITFT.h:439
void writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
Draw a vertical line on the display. Performs edge clipping and rejection. Not self-contained; should...
Definition: Adafruit_SPITFT.cpp:1577