20#ifndef _ADAFRUIT_SPITFT_H_
21#define _ADAFRUIT_SPITFT_H_
23#if !defined(__AVR_ATtiny85__)
25#include "Adafruit_GFX.h"
33#elif defined(ARDUINO_STM32_FEATHER)
34typedef class HardwareSPI SPIClass;
37#if defined(ARDUINO_ARCH_SAMD)
41#define HAS_PORT_SET_CLR
42#elif defined(CORE_TEENSY)
44#if defined(__IMXRT1052__) || defined(__IMXRT1062__)
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);
146 int8_t dc, int8_t rst = -1);
155 int8_t wr, int8_t dc, int8_t cs = -1, int8_t rst = -1,
170 virtual void begin(uint32_t freq) = 0;
196 void initSPI(uint32_t freq = 0, uint8_t spiMode = SPI_MODE0);
197 void initSPI(uint32_t freq, uint8_t spiMode,
bool reset);
203 void sendCommand(uint8_t commandByte, uint8_t *dataBytes,
204 uint8_t numDataBytes);
205 void sendCommand(uint8_t commandByte,
const uint8_t *dataBytes = NULL,
206 uint8_t numDataBytes = 0);
207 void sendCommand16(uint16_t commandWord,
const uint8_t *dataBytes = NULL,
208 uint8_t numDataBytes = 0);
209 uint8_t
readcommand8(uint8_t commandByte, uint8_t index = 0);
218 void writePixel(int16_t x, int16_t y, uint16_t color);
219 void writePixels(uint16_t *colors, uint32_t len,
bool block =
true,
220 bool bigEndian =
false);
221 void writeColor(uint16_t color, uint32_t len);
222 void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h,
224 void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
225 void writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
232 int16_t h, uint16_t color);
239 void swapBytes(uint16_t *src, uint32_t len, uint16_t *dest = NULL);
245 void drawPixel(int16_t x, int16_t y, uint16_t color);
246 void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
247 void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
248 void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
255 void drawRGBBitmap(int16_t x, int16_t y, uint16_t *pcolors, int16_t w,
259 uint16_t
color565(uint8_t r, uint8_t g, uint8_t b);
293#if defined(USE_FAST_PINIO)
294#if defined(HAS_PORT_SET_CLR)
298 *csPortSet = csPinMask;
301 *csPort |= csPinMaskSet;
304 digitalWrite(
_cs, HIGH);
315#if defined(USE_FAST_PINIO)
316#if defined(HAS_PORT_SET_CLR)
320 *csPortClr = csPinMask;
323 *csPort &= csPinMaskClr;
326 digitalWrite(
_cs, LOW);
334#if defined(USE_FAST_PINIO)
335#if defined(HAS_PORT_SET_CLR)
339 *dcPortSet = dcPinMask;
342 *dcPort |= dcPinMaskSet;
345 digitalWrite(
_dc, HIGH);
353#if defined(USE_FAST_PINIO)
354#if defined(HAS_PORT_SET_CLR)
358 *dcPortClr = dcPinMask;
361 *dcPort &= dcPinMaskClr;
364 digitalWrite(
_dc, LOW);
393#if defined(USE_FAST_PINIO)
394#if defined(HAS_PORT_SET_CLR)
404#if defined(__cplusplus) && (__cplusplus >= 201100)
409#if defined(SPI_HAS_TRANSACTION)
410 SPISettings settings;
417#if defined(USE_FAST_PINIO)
419#if defined(HAS_PORT_SET_CLR)
424#if !defined(KINETISK)
436#if !defined(KINETISK)
445#if defined(USE_FAST_PINIO)
447#if defined(__IMXRT1052__) || defined(__IMXRT1062__)
448 volatile uint32_t *writePort;
449 volatile uint32_t *readPort;
451 volatile uint8_t *writePort;
452 volatile uint8_t *readPort;
454#if defined(HAS_PORT_SET_CLR)
457#if defined(__IMXRT1052__) || defined(__IMXRT1062__)
458 volatile uint32_t *dirSet;
459 volatile uint32_t *dirClr;
461 volatile uint8_t *dirSet;
462 volatile uint8_t *dirClr;
468#if !defined(KINETISK)
475 volatile uint8_t *portDir;
489#if defined(__cplusplus) && (__cplusplus >= 201100)
492#if defined(USE_SPI_DMA) && \
493 (defined(__SAMD51__) || \
494 defined(ARDUINO_SAMD_ZERO))
495 Adafruit_ZeroDMA dma;
496 DmacDescriptor *dptr = NULL;
497 DmacDescriptor *descriptor = NULL;
498 uint16_t *pixelBuf[2];
500 uint16_t lastFillColor = 0;
501 uint32_t lastFillLen = 0;
504#if defined(USE_FAST_PINIO)
505#if defined(HAS_PORT_SET_CLR)
506#if !defined(KINETISK)
uint32_t ADAGFX_PORT_t
PORT values are 32-bit.
Definition Adafruit_SPITFT.h:64
tftBusWidth
Definition Adafruit_SPITFT.h:103
volatile ADAGFX_PORT_t * PORTreg_t
PORT register type.
Definition Adafruit_SPITFT.h:66
Adafruit_GFX(int16_t w, int16_t h)
Instatiate a GFX context for graphics! Can only be done by a superclass.
Definition Adafruit_GFX.cpp:110
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_MOSI_LOW(void)
Set the software (bitbang) SPI MOSI line LOW.
Definition Adafruit_SPITFT.cpp:2336
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:2175
int8_t _mosi
MOSI pin #.
Definition Adafruit_SPITFT.h:440
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:1563
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:984
void SPI_SCK_HIGH(void)
Set the software (bitbang) SPI SCK line HIGH.
Definition Adafruit_SPITFT.cpp:2355
void SPI_SCK_LOW(void)
Set the software (bitbang) SPI SCK line LOW.
Definition Adafruit_SPITFT.cpp:2374
void TFT_RD_LOW(void)
Set the RD line LOW. Used for parallel-connected interfaces when reading data.
Definition Adafruit_SPITFT.cpp:2571
int8_t _dc
Data/command pin #.
Definition Adafruit_SPITFT.h:520
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.
int8_t _miso
MISO pin #.
Definition Adafruit_SPITFT.h:441
int16_t _ystart
Internal framebuffer Y offset.
Definition Adafruit_SPITFT.h:523
SPIClass * _spi
SPI class pointer.
Definition Adafruit_SPITFT.h:408
void invertDisplay(bool i)
Invert the colors of the display (if supported by hardware). Self-contained, no transaction setup req...
Definition Adafruit_SPITFT.cpp:1896
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:1215
int8_t _rd
Read strobe pin # (or -1)
Definition Adafruit_SPITFT.h:486
int16_t _xstart
Internal framebuffer X offset.
Definition Adafruit_SPITFT.h:522
void setSPISpeed(uint32_t freq)
Allow changing the SPI clock speed after initialization.
Definition Adafruit_SPITFT.cpp:920
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:2115
int8_t _rst
Reset pin # (or -1)
Definition Adafruit_SPITFT.h:518
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:1829
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:1697
int8_t _d0
Data pin 0 #.
Definition Adafruit_SPITFT.h:484
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:1667
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:2026
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:1912
uint32_t _freq
SPI bitrate (if no SPI transactions)
Definition Adafruit_SPITFT.h:412
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:946
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:2191
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,...
Definition Adafruit_SPITFT.cpp:1643
uint8_t invertOffCommand
Command to disable invert mode.
Definition Adafruit_SPITFT.h:525
bool dmaBusy(void) const
Check if DMA transfer is active. Always returts false if DMA is not enabled.
Definition Adafruit_SPITFT.cpp:1201
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:2132
uint32_t _mode
SPI data mode (transactions or no)
Definition Adafruit_SPITFT.h:414
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:967
struct Adafruit_SPITFT::@126254213074154253365147231257112361037374165255 swspi
Software SPI values.
virtual void begin(uint32_t freq)=0
Display-specific initialization function.
int8_t _wr
Write strobe pin #.
Definition Adafruit_SPITFT.h:485
void SPI_MOSI_HIGH(void)
Set the software (bitbang) SPI MOSI line HIGH.
Definition Adafruit_SPITFT.cpp:2317
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()....
Definition Adafruit_SPITFT.cpp:1511
void SPI_DC_HIGH(void)
Set the data/command line HIGH (data mode).
Definition Adafruit_SPITFT.h:333
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
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:2470
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:1599
bool SPI_MISO_READ(void)
Read the state of the software (bitbang) SPI MISO line.
Definition Adafruit_SPITFT.cpp:2394
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:1851
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:2274
struct Adafruit_SPITFT::@073127256017165356070345220066037201301221016135 tft8
Parallel interface settings.
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 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:292
bool wide
If true, is 16-bit interface.
Definition Adafruit_SPITFT.h:487
void TFT_WR_STROBE(void)
Set the WR line LOW, then HIGH. Used for parallel-connected interfaces when writing data.
Definition Adafruit_SPITFT.cpp:2531
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:1796
int8_t _cs
Chip select pin # (or -1)
Definition Adafruit_SPITFT.h:519
uint16_t readcommand16(uint16_t addr)
Read 16 bits of data from display register. For 16-bit parallel displays only.
Definition Adafruit_SPITFT.cpp:2045
void SPI_DC_LOW(void)
Set the data/command line LOW (command mode).
Definition Adafruit_SPITFT.h:352
struct Adafruit_SPITFT::@100176155054133214312316313102203017045214067117 hwspi
Hardware SPI values.
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:934
uint8_t invertOnCommand
Command to enable invert mode.
Definition Adafruit_SPITFT.h:524
void TFT_RD_HIGH(void)
Set the RD line HIGH. Used for parallel-connected interfaces when reading data.
Definition Adafruit_SPITFT.cpp:2555
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:2087
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:2254
uint8_t connection
TFT_HARD_SPI, TFT_SOFT_SPI, etc.
Definition Adafruit_SPITFT.h:517
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:2288
void dmaWait(void)
Wait for the last DMA transfer in a prior non-blocking writePixels() call to complete....
Definition Adafruit_SPITFT.cpp:1181
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:1755
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:1990
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:1017
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:2416
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:314
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:1923
int8_t _sck
SCK pin #.
Definition Adafruit_SPITFT.h:442