Adafruit GFX Library
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Adafruit_SPITFT Class Referenceabstract

Adafruit_SPITFT is an intermediary class between Adafruit_GFX and various hardware-specific subclasses for different displays. It handles certain operations that are common to a range of displays (address window, area fills, etc.). Originally these were all color TFT displays interfaced via SPI, but it's since expanded to include color OLEDs and parallel-interfaced TFTs. THE NAME HAS BEEN KEPT TO AVOID BREAKING A LOT OF SUBCLASSES AND EXAMPLE CODE. Many of the class member functions similarly live on with names that don't necessarily accurately describe what they're doing, again to avoid breaking a lot of other code. If in doubt, read the comments. More...

#include <Adafruit_SPITFT.h>

Inheritance diagram for Adafruit_SPITFT:
Adafruit_GFX

Public Member Functions

 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. More...
 
 Adafruit_SPITFT (uint16_t w, uint16_t h, int8_t cs, int8_t dc, int8_t rst=-1)
 Adafruit_SPITFT constructor for hardware SPI using the board's default SPI peripheral. More...
 
 Adafruit_SPITFT (uint16_t w, uint16_t h, SPIClass *spiClass, int8_t cs, int8_t dc, int8_t rst=-1)
 Adafruit_SPITFT constructor for hardware SPI using a specific SPI peripheral. More...
 
 Adafruit_SPITFT (uint16_t w, uint16_t h, tftBusWidth busWidth, int8_t d0, int8_t wr, int8_t dc, int8_t cs=-1, int8_t rst=-1, int8_t rd=-1)
 Adafruit_SPITFT constructor for parallel display connection. More...
 
virtual void begin (uint32_t freq)=0
 Display-specific initialization function. More...
 
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. More...
 
void initSPI (uint32_t freq=0, uint8_t spiMode=SPI_MODE0)
 Configure microcontroller pins for TFT interfacing. Typically called by a subclass' begin() function. More...
 
void setSPISpeed (uint32_t freq)
 Allow changing the SPI clock speed after initialization. More...
 
void startWrite (void)
 Call before issuing command(s) or data to display. Performs chip-select (if required) and starts an SPI transaction (if using hardware SPI and transactions are supported). Required for all display types; not an SPI-specific function.
 
void endWrite (void)
 Call after issuing command(s) or data to display. Performs chip-deselect (if required) and ends an SPI transaction (if using hardware SPI and transactions are supported). Required for all display types; not an SPI-specific function.
 
void sendCommand (uint8_t commandByte, uint8_t *dataBytes, uint8_t numDataBytes)
 Adafruit_SPITFT Send Command handles complete sending of commands and data. More...
 
void sendCommand (uint8_t commandByte, const uint8_t *dataBytes=NULL, uint8_t numDataBytes=0)
 Adafruit_SPITFT Send Command handles complete sending of commands and data. More...
 
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 displays. Currently somewhat rigged for the NT35510, which has the odd behavior of wanting commands 16-bit, but subsequent data as 8-bit values, despite the 16-bit bus (high byte is always 0). Also seems to require issuing and incrementing address with each transfer. More...
 
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/supported and should be avoided, function is only included because some of the examples use it. More...
 
uint16_t readcommand16 (uint16_t addr)
 Read 16 bits of data from display register. For 16-bit parallel displays only. More...
 
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 startWrite() call. More...
 
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() and setAddrWindow() calls. More...
 
void writeColor (uint16_t color, uint32_t len)
 Issue a series of pixels, all the same color. Not self- contained; should follow startWrite() and setAddrWindow() calls. More...
 
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. More...
 
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; 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 drawFastHLine() instead. More...
 
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 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 drawFastVLine() instead. More...
 
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. More...
 
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).
 
bool dmaBusy (void) const
 Check if DMA transfer is active. Always returts false if DMA is not enabled. More...
 
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() below in some situations, but may also be helpful for user code occasionally. More...
 
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 transaction as needed (see writePixel(x,y,color) for a lower-level variant). Edge clipping is performed here. More...
 
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 (see writeFillRect() or writeFillRectPreclipped() for lower-level variants). Edge clipping and rejection is performed here. More...
 
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 writeFastHLine() for a lower-level variant). Edge clipping and rejection is performed here. More...
 
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 writeFastHLine() for a lower- level variant). Edge clipping and rejection is performed here. More...
 
void pushColor (uint16_t color)
 Essentially writePixel() with a transaction around it. I don't think this is in use by any of our code anymore (believe it was for some older BMP-reading examples), but is kept here in case any user code relies on it. Consider it DEPRECATED. More...
 
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 reduction performed. Adapted from https://github.com/PaulStoffregen/ILI9341_t3 by Marc MERLIN. See examples/pictureEmbed to use this. 5/6/2017: function name and arguments have changed for compatibility with current GFX library and to avoid naming problems in prior implementation. Formerly drawBitmap() with arguments in different order. Handles its own transaction and edge clipping/rejection. More...
 
void invertDisplay (bool i)
 Invert the colors of the display (if supported by hardware). Self-contained, no transaction setup required. More...
 
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 bits red, 6 bits green, 5 bits blue). This is just a mathematical operation, no hardware is touched. More...
 
void spiWrite (uint8_t b)
 Issue a single 8-bit value to the display. Chip-select, transaction and data/command selection must have been previously set – this ONLY issues the byte. This is another of those functions in the library with a now-not-accurate name that's being maintained for compatibility with outside code. This function is used even if display connection is parallel. More...
 
void writeCommand (uint8_t cmd)
 Write a single command byte to the display. Chip-select and transaction must have been previously set – this ONLY sets the device to COMMAND mode, issues the byte and then restores DATA mode. There is no corresponding explicit writeData() function – just use spiWrite(). More...
 
uint8_t spiRead (void)
 Read a single 8-bit value from the display. Chip-select and transaction must have been previously set – this ONLY reads the byte. This is another of those functions in the library with a now-not-accurate name that's being maintained for compatibility with outside code. This function is used even if display connection is parallel. More...
 
void write16 (uint16_t w)
 Issue a single 16-bit value to the display. Chip-select, transaction and data/command selection must have been previously set – this ONLY issues the word. Thus operates ONLY on 'wide' (16-bit) parallel displays! More...
 
void writeCommand16 (uint16_t cmd)
 Write a single command word to the display. Chip-select and transaction must have been previously set – this ONLY sets the device to COMMAND mode, issues the byte and then restores DATA mode. This operates ONLY on 'wide' (16-bit) parallel displays! More...
 
uint16_t read16 (void)
 Read a single 16-bit value from the display. Chip-select and transaction must have been previously set – this ONLY reads the byte. This operates ONLY on 'wide' (16-bit) parallel displays! More...
 
void SPI_WRITE16 (uint16_t w)
 Issue a single 16-bit value to the display. Chip-select, transaction and data/command selection must have been previously set – this ONLY issues the word. Despite the name, this function is used even if display connection is parallel; name was maintaned for backward compatibility. Naming is also not consistent with the 8-bit version, spiWrite(). Sorry about that. Again, staying compatible with outside code. More...
 
void SPI_WRITE32 (uint32_t l)
 Issue a single 32-bit value to the display. Chip-select, transaction and data/command selection must have been previously set – this ONLY issues the longword. Despite the name, this function is used even if display connection is parallel; name was maintaned for backward compatibility. Naming is also not consistent with the 8-bit version, spiWrite(). Sorry about that. Again, staying compatible with outside code. More...
 
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 calling function. Despite function name, this is used even if the display connection is parallel.
 
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 calling function. Despite function name, this is used even if the display connection is parallel.
 
void SPI_DC_HIGH (void)
 Set the data/command line HIGH (data mode).
 
void SPI_DC_LOW (void)
 Set the data/command line LOW (command mode).
 
- Public Member Functions inherited from Adafruit_GFX
 Adafruit_GFX (int16_t w, int16_t h)
 Instatiate a GFX context for graphics! Can only be done by a superclass. More...
 
virtual void writeLine (int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
 Write a line. Bresenham's algorithm - thx wikpedia. More...
 
virtual void setRotation (uint8_t r)
 Set rotation setting for display. More...
 
virtual void fillScreen (uint16_t color)
 Fill the screen completely with one color. Update in subclasses if desired! More...
 
virtual void drawLine (int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
 Draw a line. More...
 
virtual void drawRect (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
 Draw a rectangle with no fill color. More...
 
void drawCircle (int16_t x0, int16_t y0, int16_t r, uint16_t color)
 Draw a circle outline. More...
 
void drawCircleHelper (int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color)
 Quarter-circle drawer, used to do circles and roundrects. More...
 
void fillCircle (int16_t x0, int16_t y0, int16_t r, uint16_t color)
 Draw a circle with filled color. More...
 
void fillCircleHelper (int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color)
 Quarter-circle drawer with fill, used for circles and roundrects. More...
 
void drawTriangle (int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
 Draw a triangle with no fill color. More...
 
void fillTriangle (int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
 Draw a triangle with color-fill. More...
 
void drawRoundRect (int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color)
 Draw a rounded rectangle with no fill color. More...
 
void fillRoundRect (int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color)
 Draw a rounded rectangle with fill color. More...
 
void drawBitmap (int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h, uint16_t color)
 Draw a PROGMEM-resident 1-bit image at the specified (x,y) position, using the specified foreground color (unset bits are transparent). More...
 
void drawBitmap (int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h, uint16_t color, uint16_t bg)
 Draw a PROGMEM-resident 1-bit image at the specified (x,y) position, using the specified foreground (for set bits) and background (unset bits) colors. More...
 
void drawBitmap (int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h, uint16_t color)
 Draw a RAM-resident 1-bit image at the specified (x,y) position, using the specified foreground color (unset bits are transparent). More...
 
void drawBitmap (int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg)
 Draw a RAM-resident 1-bit image at the specified (x,y) position, using the specified foreground (for set bits) and background (unset bits) colors. More...
 
void drawXBitmap (int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h, uint16_t color)
 Draw PROGMEM-resident XBitMap Files (*.xbm), exported from GIMP. Usage: Export from GIMP to *.xbm, rename *.xbm to *.c and open in editor. C Array can be directly used with this function. There is no RAM-resident version of this function; if generating bitmaps in RAM, use the format defined by drawBitmap() and call that instead. More...
 
void drawGrayscaleBitmap (int16_t x, int16_t y, const uint8_t bitmap[], int16_t w, int16_t h)
 Draw a PROGMEM-resident 8-bit image (grayscale) at the specified (x,y) pos. Specifically for 8-bit display devices such as IS31FL3731; no color reduction/expansion is performed. More...
 
void drawGrayscaleBitmap (int16_t x, int16_t y, uint8_t *bitmap, int16_t w, int16_t h)
 Draw a RAM-resident 8-bit image (grayscale) at the specified (x,y) pos. Specifically for 8-bit display devices such as IS31FL3731; no color reduction/expansion is performed. More...
 
void drawGrayscaleBitmap (int16_t x, int16_t y, const uint8_t bitmap[], const uint8_t mask[], int16_t w, int16_t h)
 Draw a PROGMEM-resident 8-bit image (grayscale) with a 1-bit mask (set bits = opaque, unset bits = clear) at the specified (x,y) position. BOTH buffers (grayscale and mask) must be PROGMEM-resident. Specifically for 8-bit display devices such as IS31FL3731; no color reduction/expansion is performed. More...
 
void drawGrayscaleBitmap (int16_t x, int16_t y, uint8_t *bitmap, uint8_t *mask, int16_t w, int16_t h)
 Draw a RAM-resident 8-bit image (grayscale) with a 1-bit mask (set bits = opaque, unset bits = clear) at the specified (x,y) position. BOTH buffers (grayscale and mask) must be RAM-residentt, no mix-and-match Specifically for 8-bit display devices such as IS31FL3731; no color reduction/expansion is performed. More...
 
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 devices; no color reduction performed. More...
 
void drawRGBBitmap (int16_t x, int16_t y, uint16_t *bitmap, int16_t w, int16_t h)
 Draw a RAM-resident 16-bit image (RGB 5/6/5) at the specified (x,y) position. For 16-bit display devices; no color reduction performed. More...
 
void drawRGBBitmap (int16_t x, int16_t y, const uint16_t bitmap[], const uint8_t mask[], int16_t w, int16_t h)
 Draw a PROGMEM-resident 16-bit image (RGB 5/6/5) with a 1-bit mask (set bits = opaque, unset bits = clear) at the specified (x,y) position. BOTH buffers (color and mask) must be PROGMEM-resident. For 16-bit display devices; no color reduction performed. More...
 
void drawRGBBitmap (int16_t x, int16_t y, uint16_t *bitmap, uint8_t *mask, int16_t w, int16_t h)
 Draw a RAM-resident 16-bit image (RGB 5/6/5) with a 1-bit mask (set bits = opaque, unset bits = clear) at the specified (x,y) position. BOTH buffers (color and mask) must be RAM-resident. For 16-bit display devices; no color reduction performed. More...
 
void drawChar (int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size)
 Draw a single character. More...
 
void drawChar (int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size_x, uint8_t size_y)
 Draw a single character. More...
 
void getTextBounds (const char *string, int16_t x, int16_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h)
 Helper to determine size of a string with current font/size. Pass string and a cursor position, returns UL corner and W,H. More...
 
void getTextBounds (const __FlashStringHelper *s, int16_t x, int16_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h)
 Helper to determine size of a PROGMEM string with current font/size. Pass string and a cursor position, returns UL corner and W,H. More...
 
void getTextBounds (const String &str, int16_t x, int16_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h)
 Helper to determine size of a string with current font/size. Pass string and a cursor position, returns UL corner and W,H. More...
 
void setTextSize (uint8_t s)
 Set text 'magnification' size. Each increase in s makes 1 pixel that much bigger. More...
 
void setTextSize (uint8_t sx, uint8_t sy)
 Set text 'magnification' size. Each increase in s makes 1 pixel that much bigger. More...
 
void setFont (const GFXfont *f=NULL)
 Set the font to display when print()ing, either custom or default. More...
 
void setCursor (int16_t x, int16_t y)
 Set text cursor location. More...
 
void setTextColor (uint16_t c)
 Set text font color with transparant background. More...
 
void setTextColor (uint16_t c, uint16_t bg)
 Set text font color with custom background color. More...
 
void setTextWrap (bool w)
 Set whether text that is too long for the screen width should automatically wrap around to the next line (else clip right). More...
 
void cp437 (bool x=true)
 Enable (or disable) Code Page 437-compatible charset. There was an error in glcdfont.c for the longest time – one character (#176, the 'light shade' block) was missing – this threw off the index of every character that followed it. But a TON of code has been written with the erroneous character indices. By default, the library uses the original 'wrong' behavior and old sketches will still work. Pass 'true' to this function to use correct CP437 character values in your code. More...
 
virtual void write (uint8_t)
 Print one byte/character of data, used to support print() More...
 
int16_t width (void) const
 Get width of the display, accounting for current rotation. More...
 
int16_t height (void) const
 Get height of the display, accounting for current rotation. More...
 
uint8_t getRotation (void) const
 Get rotation setting for display. More...
 
int16_t getCursorX (void) const
 Get text cursor X location. More...
 
int16_t getCursorY (void) const
 Get text cursor Y location. More...
 

Protected Member Functions

void SPI_MOSI_HIGH (void)
 Set the software (bitbang) SPI MOSI line HIGH.
 
void SPI_MOSI_LOW (void)
 Set the software (bitbang) SPI MOSI line LOW.
 
void SPI_SCK_HIGH (void)
 Set the software (bitbang) SPI SCK line HIGH.
 
void SPI_SCK_LOW (void)
 Set the software (bitbang) SPI SCK line LOW.
 
bool SPI_MISO_READ (void)
 Read the state of the software (bitbang) SPI MISO line. More...
 
void SPI_BEGIN_TRANSACTION (void)
 Start an SPI transaction if using the hardware SPI interface to the display. If using an earlier version of the Arduino platform (before the addition of SPI transactions), this instead attempts to set up the SPI clock and mode. No action is taken if the connection is not hardware SPI-based. This does NOT include a chip-select operation – see startWrite() for a function that encapsulated both actions.
 
void SPI_END_TRANSACTION (void)
 End an SPI transaction if using the hardware SPI interface to the display. No action is taken if the connection is not hardware SPI-based or if using an earlier version of the Arduino platform (before the addition of SPI transactions). This does NOT include a chip-deselect operation – see endWrite() for a function that encapsulated both actions.
 
void TFT_WR_STROBE (void)
 Set the WR line LOW, then HIGH. Used for parallel-connected interfaces when writing data.
 
void TFT_RD_HIGH (void)
 Set the RD line HIGH. Used for parallel-connected interfaces when reading data.
 
void TFT_RD_LOW (void)
 Set the RD line LOW. Used for parallel-connected interfaces when reading data.
 
- Protected Member Functions inherited from Adafruit_GFX
void charBounds (unsigned char c, int16_t *x, int16_t *y, int16_t *minx, int16_t *miny, int16_t *maxx, int16_t *maxy)
 Helper to determine size of a character with current font/size. Broke this out as it's used by both the PROGMEM- and RAM-resident getTextBounds() functions. More...
 

Protected Attributes

struct {
   SPIClass *   _spi
 SPI class pointer.
 
   uint32_t   _freq
 SPI bitrate (if no SPI transactions)
 
   uint32_t   _mode
 SPI data mode (transactions or no)
 
hwspi
 Hardware SPI values.
 
struct {
   int8_t   _mosi
 MOSI pin #.
 
   int8_t   _miso
 MISO pin #.
 
   int8_t   _sck
 SCK pin #.
 
swspi
 Software SPI values.
 
struct {
   int8_t   _d0
 Data pin 0 #.
 
   int8_t   _wr
 Write strobe pin #.
 
   int8_t   _rd
 Read strobe pin # (or -1)
 
   bool   wide = 0
 If true, is 16-bit interface.
 
tft8
 Parallel interface settings.
 
uint8_t connection
 TFT_HARD_SPI, TFT_SOFT_SPI, etc.
 
int8_t _rst
 Reset pin # (or -1)
 
int8_t _cs
 Chip select pin # (or -1)
 
int8_t _dc
 Data/command pin #.
 
int16_t _xstart = 0
 Internal framebuffer X offset.
 
int16_t _ystart = 0
 Internal framebuffer Y offset.
 
uint8_t invertOnCommand = 0
 Command to enable invert mode.
 
uint8_t invertOffCommand = 0
 Command to disable invert mode.
 
- Protected Attributes inherited from Adafruit_GFX
int16_t WIDTH
 This is the 'raw' display width - never changes.
 
int16_t HEIGHT
 This is the 'raw' display height - never changes.
 
int16_t _width
 Display width as modified by current rotation.
 
int16_t _height
 Display height as modified by current rotation.
 
int16_t cursor_x
 x location to start print()ing text
 
int16_t cursor_y
 y location to start print()ing text
 
uint16_t textcolor
 16-bit background color for print()
 
uint16_t textbgcolor
 16-bit text color for print()
 
uint8_t textsize_x
 Desired magnification in X-axis of text to print()
 
uint8_t textsize_y
 Desired magnification in Y-axis of text to print()
 
uint8_t rotation
 Display rotation (0 thru 3)
 
bool wrap
 If set, 'wrap' text at right edge of display.
 
bool _cp437
 If set, use correct CP437 charset (default is off)
 
GFXfontgfxFont
 Pointer to special font.
 

Detailed Description

Adafruit_SPITFT is an intermediary class between Adafruit_GFX and various hardware-specific subclasses for different displays. It handles certain operations that are common to a range of displays (address window, area fills, etc.). Originally these were all color TFT displays interfaced via SPI, but it's since expanded to include color OLEDs and parallel-interfaced TFTs. THE NAME HAS BEEN KEPT TO AVOID BREAKING A LOT OF SUBCLASSES AND EXAMPLE CODE. Many of the class member functions similarly live on with names that don't necessarily accurately describe what they're doing, again to avoid breaking a lot of other code. If in doubt, read the comments.

Constructor & Destructor Documentation

◆ Adafruit_SPITFT() [1/4]

Adafruit_SPITFT::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.

Parameters
wDisplay width in pixels at default rotation setting (0).
hDisplay height in pixels at default rotation setting (0).
csArduino pin # for chip-select (-1 if unused, tie CS low).
dcArduino pin # for data/command select (required).
mosiArduino pin # for bitbang SPI MOSI signal (required).
sckArduino pin # for bitbang SPI SCK signal (required).
rstArduino pin # for display reset (optional, display reset can be tied to MCU reset, default of -1 means unused).
misoArduino pin # for bitbang SPI MISO signal (optional, -1 default, many displays don't support SPI read).
Note
Output pins are not initialized; application typically will need to call subclass' begin() function, which in turn calls this library's initSPI() function to initialize pins.

◆ Adafruit_SPITFT() [2/4]

Adafruit_SPITFT::Adafruit_SPITFT ( uint16_t  w,
uint16_t  h,
int8_t  cs,
int8_t  dc,
int8_t  rst = -1 
)

Adafruit_SPITFT constructor for hardware SPI using the board's default SPI peripheral.

Parameters
wDisplay width in pixels at default rotation setting (0).
hDisplay height in pixels at default rotation setting (0).
csArduino pin # for chip-select (-1 if unused, tie CS low).
dcArduino pin # for data/command select (required).
rstArduino pin # for display reset (optional, display reset can be tied to MCU reset, default of -1 means unused).
Note
Output pins are not initialized; application typically will need to call subclass' begin() function, which in turn calls this library's initSPI() function to initialize pins.

◆ Adafruit_SPITFT() [3/4]

Adafruit_SPITFT::Adafruit_SPITFT ( uint16_t  w,
uint16_t  h,
SPIClass *  spiClass,
int8_t  cs,
int8_t  dc,
int8_t  rst = -1 
)

Adafruit_SPITFT constructor for hardware SPI using a specific SPI peripheral.

Parameters
wDisplay width in pixels at default rotation (0).
hDisplay height in pixels at default rotation (0).
spiClassPointer to SPIClass type (e.g. &SPI or &SPI1).
csArduino pin # for chip-select (-1 if unused, tie CS low).
dcArduino pin # for data/command select (required).
rstArduino pin # for display reset (optional, display reset can be tied to MCU reset, default of -1 means unused).
Note
Output pins are not initialized in constructor; application typically will need to call subclass' begin() function, which in turn calls this library's initSPI() function to initialize pins. EXCEPT...if you have built your own SERCOM SPI peripheral (calling the SPIClass constructor) rather than one of the built-in SPI devices (e.g. &SPI, &SPI1 and so forth), you will need to call the begin() function for your object as well as pinPeripheral() for the MOSI, MISO and SCK pins to configure GPIO manually. Do this BEFORE calling the display-specific begin or init function. Unfortunate but unavoidable.

◆ Adafruit_SPITFT() [4/4]

Adafruit_SPITFT::Adafruit_SPITFT ( uint16_t  w,
uint16_t  h,
tftBusWidth  busWidth,
int8_t  d0,
int8_t  wr,
int8_t  dc,
int8_t  cs = -1,
int8_t  rst = -1,
int8_t  rd = -1 
)

Adafruit_SPITFT constructor for parallel display connection.

Parameters
wDisplay width in pixels at default rotation (0).
hDisplay height in pixels at default rotation (0).
busWidthIf tft16 (enumeration in header file), is a 16-bit parallel connection, else 8-bit. 16-bit isn't fully implemented or tested yet so applications should pass "tft8bitbus" for now...needed to stick a required enum argument in there to disambiguate this constructor from the soft-SPI case. Argument is ignored on 8-bit architectures (no 'wide' support there since PORTs are 8 bits anyway).
d0Arduino pin # for data bit 0 (1+ are extrapolated). The 8 (or 16) data bits MUST be contiguous and byte- aligned (or word-aligned for wide interface) within the same PORT register (might not correspond to Arduino pin sequence).
wrArduino pin # for write strobe (required).
dcArduino pin # for data/command select (required).
csArduino pin # for chip-select (optional, -1 if unused, tie CS low).
rstArduino pin # for display reset (optional, display reset can be tied to MCU reset, default of -1 means unused).
rdArduino pin # for read strobe (optional, -1 if unused).
Note
Output pins are not initialized; application typically will need to call subclass' begin() function, which in turn calls this library's initSPI() function to initialize pins. Yes, the name is a misnomer...this library originally handled only SPI displays, parallel being a recent addition (but not wanting to break existing code).

Member Function Documentation

◆ begin()

virtual void Adafruit_SPITFT::begin ( uint32_t  freq)
pure virtual

Display-specific initialization function.

Parameters
freqSPI frequency, in hz (or 0 for default or unused).

◆ setAddrWindow()

virtual void Adafruit_SPITFT::setAddrWindow ( uint16_t  x,
uint16_t  y,
uint16_t  w,
uint16_t  h 
)
pure virtual

Set up the specific display hardware's "address window" for subsequent pixel-pushing operations.

Parameters
xLeftmost pixel of area to be drawn (MUST be within display bounds at current rotation setting).
yTopmost pixel of area to be drawn (MUST be within display bounds at current rotation setting).
wWidth of area to be drawn, in pixels (MUST be >0 and, added to x, within display bounds at current rotation).
hHeight of area to be drawn, in pixels (MUST be >0 and, added to x, within display bounds at current rotation).

◆ initSPI()

void Adafruit_SPITFT::initSPI ( uint32_t  freq = 0,
uint8_t  spiMode = SPI_MODE0 
)

Configure microcontroller pins for TFT interfacing. Typically called by a subclass' begin() function.

Parameters
freqSPI frequency when using hardware SPI. If default (0) is passed, will fall back on a device-specific value. Value is ignored when using software SPI or parallel connection.
spiModeSPI mode when using hardware SPI. MUST be one of the values SPI_MODE0, SPI_MODE1, SPI_MODE2 or SPI_MODE3 defined in SPI.h. Do NOT attempt to pass '0' for SPI_MODE0 and so forth...the values are NOT the same! Use ONLY the defines! (Pity it's not an enum.)
Note
Another anachronistically-named function; this is called even when the display connection is parallel (not SPI). Also, this could probably be made private...quite a few class functions were generously put in the public section.

◆ setSPISpeed()

void Adafruit_SPITFT::setSPISpeed ( uint32_t  freq)

Allow changing the SPI clock speed after initialization.

Parameters
freqDesired frequency of SPI clock, may not be the end frequency you get based on what the chip can do!

◆ sendCommand() [1/2]

void Adafruit_SPITFT::sendCommand ( uint8_t  commandByte,
uint8_t *  dataBytes,
uint8_t  numDataBytes 
)

Adafruit_SPITFT Send Command handles complete sending of commands and data.

Parameters
commandByteThe Command Byte
dataBytesA pointer to the Data bytes to send
numDataBytesThe number of bytes we should send

◆ sendCommand() [2/2]

void Adafruit_SPITFT::sendCommand ( uint8_t  commandByte,
const uint8_t *  dataBytes = NULL,
uint8_t  numDataBytes = 0 
)

Adafruit_SPITFT Send Command handles complete sending of commands and data.

Parameters
commandByteThe Command Byte
dataBytesA pointer to the Data bytes to send
numDataBytesThe number of bytes we should send

◆ sendCommand16()

void Adafruit_SPITFT::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 displays. Currently somewhat rigged for the NT35510, which has the odd behavior of wanting commands 16-bit, but subsequent data as 8-bit values, despite the 16-bit bus (high byte is always 0). Also seems to require issuing and incrementing address with each transfer.

Parameters
commandWordThe command word (16 bits)
dataBytesA pointer to the data bytes to send
numDataBytesThe number of bytes we should send

◆ readcommand8()

uint8_t Adafruit_SPITFT::readcommand8 ( uint8_t  commandByte,
uint8_t  index = 0 
)

Read 8 bits of data from display configuration memory (not RAM). This is highly undocumented/supported and should be avoided, function is only included because some of the examples use it.

Parameters
commandByteThe command register to read data from.
indexThe byte index into the command to read from.
Returns
Unsigned 8-bit data read from display register.

◆ readcommand16()

uint16_t Adafruit_SPITFT::readcommand16 ( uint16_t  addr)

Read 16 bits of data from display register. For 16-bit parallel displays only.

Parameters
addrCommand/register to access.
Returns
Unsigned 16-bit data.

◆ writePixel()

void Adafruit_SPITFT::writePixel ( int16_t  x,
int16_t  y,
uint16_t  color 
)
virtual

Draw a single pixel to the display at requested coordinates. Not self-contained; should follow a startWrite() call.

Parameters
xHorizontal position (0 = left).
yVertical position (0 = top).
color16-bit pixel color in '565' RGB format.

Reimplemented from Adafruit_GFX.

◆ writePixels()

void Adafruit_SPITFT::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() and setAddrWindow() calls.

Parameters
colorsPointer to array of 16-bit pixel values in '565' RGB format.
lenNumber of elements in 'colors' array.
blockIf true (default case if unspecified), function blocks until DMA transfer is complete. This is simply IGNORED if DMA is not enabled. If false, the function returns immediately after the last DMA transfer is started, and one should use the dmaWait() function before doing ANY other display-related activities (or even any SPI-related activities, if using an SPI display that shares the bus with other devices).
bigEndianIf true, bitmap in memory is in big-endian order (most significant byte first). By default this is false, as most microcontrollers seem to be little-endian and 16-bit pixel values must be byte-swapped before issuing to the display (which tend toward big-endian when using SPI or 8-bit parallel). If an application can optimize around this – for example, a bitmap in a uint16_t array having the byte values already ordered big-endian, this can save time here, ESPECIALLY if using this function's non-blocking DMA mode.

◆ writeColor()

void Adafruit_SPITFT::writeColor ( uint16_t  color,
uint32_t  len 
)

Issue a series of pixels, all the same color. Not self- contained; should follow startWrite() and setAddrWindow() calls.

Parameters
color16-bit pixel color in '565' RGB format.
lenNumber of pixels to draw.

◆ writeFillRect()

void Adafruit_SPITFT::writeFillRect ( int16_t  x,
int16_t  y,
int16_t  w,
int16_t  h,
uint16_t  color 
)
virtual

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.

Parameters
xHorizontal position of first corner.
yVertical position of first corner.
wRectangle width in pixels (positive = right of first corner, negative = left of first corner).
hRectangle height in pixels (positive = below first corner, negative = above first corner).
color16-bit fill color in '565' RGB format.
Note
Written in this deep-nested way because C by definition will optimize for the 'if' case, not the 'else' – avoids branches and rejects clipped rectangles at the least-work possibility.

Reimplemented from Adafruit_GFX.

◆ writeFastHLine()

void Adafruit_SPITFT::writeFastHLine ( int16_t  x,
int16_t  y,
int16_t  w,
uint16_t  color 
)
inlinevirtual

Draw a horizontal line on the display. Performs edge clipping and rejection. 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 drawFastHLine() instead.

Parameters
xHorizontal position of first point.
yVertical position of first point.
wLine width in pixels (positive = right of first point, negative = point of first corner).
color16-bit line color in '565' RGB format.

Reimplemented from Adafruit_GFX.

◆ writeFastVLine()

void Adafruit_SPITFT::writeFastVLine ( int16_t  x,
int16_t  y,
int16_t  h,
uint16_t  color 
)
inlinevirtual

Draw a vertical line on the display. Performs edge clipping and rejection. 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 drawFastVLine() instead.

Parameters
xHorizontal position of first point.
yVertical position of first point.
hLine height in pixels (positive = below first point, negative = above first point).
color16-bit line color in '565' RGB format.

Reimplemented from Adafruit_GFX.

◆ writeFillRectPreclipped()

void Adafruit_SPITFT::writeFillRectPreclipped ( int16_t  x,
int16_t  y,
int16_t  w,
int16_t  h,
uint16_t  color 
)
inline

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.

Parameters
xHorizontal position of first corner. MUST BE WITHIN SCREEN BOUNDS.
yVertical position of first corner. MUST BE WITHIN SCREEN BOUNDS.
wRectangle width in pixels. MUST BE POSITIVE AND NOT EXTEND OFF SCREEN.
hRectangle height in pixels. MUST BE POSITIVE AND NOT EXTEND OFF SCREEN.
color16-bit fill color in '565' RGB format.
Note
This is a new function, no graphics primitives besides rects and horizontal/vertical lines are written to best use this yet.

◆ dmaBusy()

bool Adafruit_SPITFT::dmaBusy ( void  ) const

Check if DMA transfer is active. Always returts false if DMA is not enabled.

Returns
true if DMA is enabled and transmitting data, false otherwise.

◆ swapBytes()

void Adafruit_SPITFT::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() below in some situations, but may also be helpful for user code occasionally.

Parameters
srcSource address of 16-bit pixels buffer.
lenNumber of pixels to byte-swap.
destOptional destination address if different than src – otherwise, if NULL (default) or same address is passed, pixel buffer is overwritten in-place.

◆ drawPixel()

void Adafruit_SPITFT::drawPixel ( int16_t  x,
int16_t  y,
uint16_t  color 
)
virtual

Draw a single pixel to the display at requested coordinates. Self-contained and provides its own transaction as needed (see writePixel(x,y,color) for a lower-level variant). Edge clipping is performed here.

Parameters
xHorizontal position (0 = left).
yVertical position (0 = top).
color16-bit pixel color in '565' RGB format.

Implements Adafruit_GFX.

◆ fillRect()

void Adafruit_SPITFT::fillRect ( int16_t  x,
int16_t  y,
int16_t  w,
int16_t  h,
uint16_t  color 
)
virtual

Draw a filled rectangle to the display. Self-contained and provides its own transaction as needed (see writeFillRect() or writeFillRectPreclipped() for lower-level variants). Edge clipping and rejection is performed here.

Parameters
xHorizontal position of first corner.
yVertical position of first corner.
wRectangle width in pixels (positive = right of first corner, negative = left of first corner).
hRectangle height in pixels (positive = below first corner, negative = above first corner).
color16-bit fill color in '565' RGB format.
Note
This repeats the writeFillRect() function almost in its entirety, with the addition of a transaction start/end. It's done this way (rather than starting the transaction and calling writeFillRect() to handle clipping and so forth) so that the transaction isn't performed at all if the rectangle is rejected. It's really not that much code.

Reimplemented from Adafruit_GFX.

◆ drawFastHLine()

void Adafruit_SPITFT::drawFastHLine ( int16_t  x,
int16_t  y,
int16_t  w,
uint16_t  color 
)
virtual

Draw a horizontal line on the display. Self-contained and provides its own transaction as needed (see writeFastHLine() for a lower-level variant). Edge clipping and rejection is performed here.

Parameters
xHorizontal position of first point.
yVertical position of first point.
wLine width in pixels (positive = right of first point, negative = point of first corner).
color16-bit line color in '565' RGB format.
Note
This repeats the writeFastHLine() function almost in its entirety, with the addition of a transaction start/end. It's done this way (rather than starting the transaction and calling writeFastHLine() to handle clipping and so forth) so that the transaction isn't performed at all if the line is rejected.

Reimplemented from Adafruit_GFX.

◆ drawFastVLine()

void Adafruit_SPITFT::drawFastVLine ( int16_t  x,
int16_t  y,
int16_t  h,
uint16_t  color 
)
virtual

Draw a vertical line on the display. Self-contained and provides its own transaction as needed (see writeFastHLine() for a lower- level variant). Edge clipping and rejection is performed here.

Parameters
xHorizontal position of first point.
yVertical position of first point.
hLine height in pixels (positive = below first point, negative = above first point).
color16-bit line color in '565' RGB format.
Note
This repeats the writeFastVLine() function almost in its entirety, with the addition of a transaction start/end. It's done this way (rather than starting the transaction and calling writeFastVLine() to handle clipping and so forth) so that the transaction isn't performed at all if the line is rejected.

Reimplemented from Adafruit_GFX.

◆ pushColor()

void Adafruit_SPITFT::pushColor ( uint16_t  color)

Essentially writePixel() with a transaction around it. I don't think this is in use by any of our code anymore (believe it was for some older BMP-reading examples), but is kept here in case any user code relies on it. Consider it DEPRECATED.

Parameters
color16-bit pixel color in '565' RGB format.

◆ drawRGBBitmap()

void Adafruit_SPITFT::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 reduction performed. Adapted from https://github.com/PaulStoffregen/ILI9341_t3 by Marc MERLIN. See examples/pictureEmbed to use this. 5/6/2017: function name and arguments have changed for compatibility with current GFX library and to avoid naming problems in prior implementation. Formerly drawBitmap() with arguments in different order. Handles its own transaction and edge clipping/rejection.

Parameters
xTop left corner horizontal coordinate.
yTop left corner vertical coordinate.
pcolorsPointer to 16-bit array of pixel values.
wWidth of bitmap in pixels.
hHeight of bitmap in pixels.

◆ invertDisplay()

void Adafruit_SPITFT::invertDisplay ( bool  i)
virtual

Invert the colors of the display (if supported by hardware). Self-contained, no transaction setup required.

Parameters
itrue = inverted display, false = normal display.

Reimplemented from Adafruit_GFX.

◆ color565()

uint16_t Adafruit_SPITFT::color565 ( uint8_t  red,
uint8_t  green,
uint8_t  blue 
)

Given 8-bit red, green and blue values, return a 'packed' 16-bit color value in '565' RGB format (5 bits red, 6 bits green, 5 bits blue). This is just a mathematical operation, no hardware is touched.

Parameters
red8-bit red brightnesss (0 = off, 255 = max).
green8-bit green brightnesss (0 = off, 255 = max).
blue8-bit blue brightnesss (0 = off, 255 = max).
Returns
'Packed' 16-bit color value (565 format).

◆ spiWrite()

void Adafruit_SPITFT::spiWrite ( uint8_t  b)

Issue a single 8-bit value to the display. Chip-select, transaction and data/command selection must have been previously set – this ONLY issues the byte. This is another of those functions in the library with a now-not-accurate name that's being maintained for compatibility with outside code. This function is used even if display connection is parallel.

Parameters
b8-bit value to write.

◆ writeCommand()

void Adafruit_SPITFT::writeCommand ( uint8_t  cmd)

Write a single command byte to the display. Chip-select and transaction must have been previously set – this ONLY sets the device to COMMAND mode, issues the byte and then restores DATA mode. There is no corresponding explicit writeData() function – just use spiWrite().

Parameters
cmd8-bit command to write.

◆ spiRead()

uint8_t Adafruit_SPITFT::spiRead ( void  )

Read a single 8-bit value from the display. Chip-select and transaction must have been previously set – this ONLY reads the byte. This is another of those functions in the library with a now-not-accurate name that's being maintained for compatibility with outside code. This function is used even if display connection is parallel.

Returns
Unsigned 8-bit value read (always zero if USE_FAST_PINIO is not supported by the MCU architecture).

◆ write16()

void Adafruit_SPITFT::write16 ( uint16_t  w)

Issue a single 16-bit value to the display. Chip-select, transaction and data/command selection must have been previously set – this ONLY issues the word. Thus operates ONLY on 'wide' (16-bit) parallel displays!

Parameters
w16-bit value to write.

◆ writeCommand16()

void Adafruit_SPITFT::writeCommand16 ( uint16_t  cmd)

Write a single command word to the display. Chip-select and transaction must have been previously set – this ONLY sets the device to COMMAND mode, issues the byte and then restores DATA mode. This operates ONLY on 'wide' (16-bit) parallel displays!

Parameters
cmd16-bit command to write.

◆ read16()

uint16_t Adafruit_SPITFT::read16 ( void  )

Read a single 16-bit value from the display. Chip-select and transaction must have been previously set – this ONLY reads the byte. This operates ONLY on 'wide' (16-bit) parallel displays!

Returns
Unsigned 16-bit value read (always zero if USE_FAST_PINIO is not supported by the MCU architecture).

◆ SPI_WRITE16()

void Adafruit_SPITFT::SPI_WRITE16 ( uint16_t  w)

Issue a single 16-bit value to the display. Chip-select, transaction and data/command selection must have been previously set – this ONLY issues the word. Despite the name, this function is used even if display connection is parallel; name was maintaned for backward compatibility. Naming is also not consistent with the 8-bit version, spiWrite(). Sorry about that. Again, staying compatible with outside code.

Parameters
w16-bit value to write.

◆ SPI_WRITE32()

void Adafruit_SPITFT::SPI_WRITE32 ( uint32_t  l)

Issue a single 32-bit value to the display. Chip-select, transaction and data/command selection must have been previously set – this ONLY issues the longword. Despite the name, this function is used even if display connection is parallel; name was maintaned for backward compatibility. Naming is also not consistent with the 8-bit version, spiWrite(). Sorry about that. Again, staying compatible with outside code.

Parameters
l32-bit value to write.

◆ SPI_MISO_READ()

bool Adafruit_SPITFT::SPI_MISO_READ ( void  )
inlineprotected

Read the state of the software (bitbang) SPI MISO line.

Returns
true if HIGH, false if LOW.

Member Data Documentation

◆ _freq

uint32_t Adafruit_SPITFT::_freq = 0

SPI bitrate (if no SPI transactions)

Dummy var to keep subclasses happy.


The documentation for this class was generated from the following files: