Adafruit TFTDMA Arduino Library
Adafruit_TFTDMA.h
Go to the documentation of this file.
1 
17 #ifndef _ADAFRUIT_TFTDMA_H_
18 #define _ADAFRUIT_TFTDMA_H_
19 
20 #define TFT_INTERFACE_8 0
21 #define TFT_INTERFACE_16 1
22 #define TFT_INTERFACE_SPI 2
23 
24 // Display interface must be defined at compile-time, it's baked-in deep.
25 #define TFT_INTERFACE TFT_INTERFACE_8
26 #define TFTWIDTH 320
27 #define TFTHEIGHT 240
28 
29 #include <Adafruit_ZeroDMA.h>
30 
31 //--------------------------------------------------------------------------
41 public:
88  Adafruit_TFTDMA(int8_t tc, int8_t reset, int8_t cs, int8_t cd, int8_t rd,
89  int8_t wr, int8_t d0, _EPioType periph);
96  bool begin(void);
97 
98 protected:
99 #if TFT_INTERFACE == TFT_INTERFACE_8
100  volatile uint8_t *writePort;
101  volatile uint8_t *readPort;
102  volatile uint8_t *dirSet;
103  volatile uint8_t *dirClr;
104 #elif TFT_INTERFACE == TFT_INTERFACE_16
105  volatile uint16_t *writePort;
106  volatile uint16_t *readPort;
107  volatile uint16_t *dirSet;
108  volatile uint16_t *dirClr;
109 #endif
110  volatile uint32_t *csPortSet;
111  volatile uint32_t *csPortClr;
112  volatile uint32_t *cdPortSet;
113  volatile uint32_t *cdPortClr;
114  volatile uint32_t *rdPortSet;
115  volatile uint32_t *rdPortClr;
116  volatile uint32_t *wrPortActive;
117  volatile uint32_t *wrPortIdle;
118  uint32_t csPinMask;
119  uint32_t cdPinMask;
120  uint32_t rdPinMask;
121  uint32_t wrPinMask;
122  int8_t csPin;
123  int8_t cdPin;
124  int8_t rdPin;
125  int8_t wrPin;
126  int8_t resetPin;
127  int8_t d0Pin;
128  int8_t tcNum;
129  _EPioType wrPeripheral;
130  Adafruit_ZeroDMA dma;
131 
136  void writeReg8(uint8_t reg, uint8_t value);
142  void writeReg16(uint8_t reg, uint16_t value);
148  void writeReg32(uint8_t reg, uint32_t value);
161  void setAddrWindow(int16_t x1, int16_t y1, int16_t x2, int16_t y2);
162 #if 0 // Not used:
163 
168  uint32_t readID(void);
169 #endif
170 };
171 
172 //--------------------------------------------------------------------------
179 public:
226  TFT_framebuffer(int8_t tc, int8_t reset, int8_t cs, int8_t cd, int8_t rd,
227  int8_t wr, int8_t d0, _EPioType periph);
234  bool begin(void);
242  void update(void);
247  void waitForUpdate(void);
257  void sully(int16_t x, int16_t y);
263  uint16_t *getBuffer(void);
280  bool getDirtyRect(int16_t *x1, int16_t *y1, int16_t *x2, int16_t *y2);
291  inline void rawPixel(int16_t x, int16_t y, uint16_t color);
299  void drawPixel(int16_t x, int16_t y, uint16_t color);
309  void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
314  void fillScreen(uint16_t color = 0);
315 
316 private:
317  DmacDescriptor *dptr; // Initial allocated DMA descriptor
318  DmacDescriptor descriptor[TFTHEIGHT] __attribute__((aligned(16)));
319  uint16_t framebuf[TFTWIDTH * TFTHEIGHT];
320  int16_t minx, miny, maxx, maxy; // Dirty rect
321 };
322 
323 //--------------------------------------------------------------------------
337 public:
384  TFT_segmented(int8_t tc, int8_t reset, int8_t cs, int8_t cd, int8_t rd,
385  int8_t wr, int8_t d0, _EPioType periph);
392  bool begin(void);
444  void update(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t *buf,
445  uint16_t maxSegmentSize,
446  int16_t (*userCallback)(uint16_t *dest, uint16_t len,
447  void *udPtr),
448  void *userData);
454  void waitForUpdate(void);
465  inline void rawPixel(int16_t x, int16_t y, uint16_t color);
473  void drawPixel(int16_t x, int16_t y, uint16_t color);
483  void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
488  void fillScreen(uint16_t color = 0);
489 
490 private:
491  DmacDescriptor *descriptor;
492  uint16_t *framebuf;
493  int16_t xoffset, yoffset, width, height;
494 };
495 
496 //--------------------------------------------------------------------------
507 public:
554  TFT_scanline(int8_t tc, int8_t reset, int8_t cs, int8_t cd, int8_t rd,
555  int8_t wr, int8_t d0, _EPioType periph);
562  bool begin(void);
589  void update(int16_t x1, int16_t y1, int16_t x2, int16_t y2,
590  void (*userCallback)(uint16_t *dest, void *udPtr),
591  void *userData);
612  void addSpan(uint16_t *addr, int16_t w, bool inc = 1);
613 
614 private:
615  uint8_t lineIdx;
616  uint16_t spanIdx;
617  DmacDescriptor *dptr; // Initial allocated DMA descriptor
618  struct scanline {
619  DmacDescriptor descriptor[TFTWIDTH] __attribute__((aligned(16)));
620  uint16_t linebuf[TFTWIDTH];
621  } scanline[2];
622 };
623 
624 #endif // _ADAFRUIT_TFTDMA_H_
Adafruit_TFTDMA(int8_t tc, int8_t reset, int8_t cs, int8_t cd, int8_t rd, int8_t wr, int8_t d0, _EPioType periph)
Constructor. Takes note of the hardware configuration to use, but does not itself initialize any hard...
Definition: Adafruit_TFTDMA.cpp:168
Adafruit_ZeroDMA dma
DMA instance.
Definition: Adafruit_TFTDMA.h:130
volatile uint32_t * rdPortSet
Pointer to RD pin PORT SET register.
Definition: Adafruit_TFTDMA.h:114
void writeReg16(uint8_t reg, uint16_t value)
Writes a 16-bit value to an ILI9341 configuration register.
Definition: Adafruit_TFTDMA.cpp:473
volatile uint32_t * csPortClr
Pointer to CS pin PORT CLEAR register.
Definition: Adafruit_TFTDMA.h:111
A base class that interfaces with the SAMD51 hardware, including PORTs, timer/counters, DMA and other operipherals. Unlikely to be instantiated on its own, a few subclasses are provided that represent the display and graphics memory in different ways. Applications must be designed around ONE of these subclasses and stick with it; can&#39;t toggle among them.
Definition: Adafruit_TFTDMA.h:40
void setAddrWindow(int16_t x1, int16_t y1, int16_t x2, int16_t y2)
Sets the ILI9341 &#39;address window&#39; for subsequent graphics operations. This also issues a MEMORYWRITE ...
Definition: Adafruit_TFTDMA.cpp:492
volatile uint8_t * dirSet
8-bit PORT direction set
Definition: Adafruit_TFTDMA.h:102
int8_t cdPin
Index of CD pin.
Definition: Adafruit_TFTDMA.h:123
volatile uint32_t * cdPortSet
Pointer to CD pin PORT SET register.
Definition: Adafruit_TFTDMA.h:112
int8_t csPin
Index of CS pin (or -1)
Definition: Adafruit_TFTDMA.h:122
void writeReg32(uint8_t reg, uint32_t value)
Writes a 32-bit value to an ILI9341 configuration register.
Definition: Adafruit_TFTDMA.cpp:481
int8_t rdPin
Index of RD pin.
Definition: Adafruit_TFTDMA.h:124
int8_t tcNum
Timer/Counter number.
Definition: Adafruit_TFTDMA.h:128
volatile uint8_t * readPort
Pointer to 8-bit PORT IN.
Definition: Adafruit_TFTDMA.h:101
uint32_t cdPinMask
Bitmask for CD pin PORT.
Definition: Adafruit_TFTDMA.h:119
int8_t d0Pin
Index of data bit 0 pin.
Definition: Adafruit_TFTDMA.h:127
uint32_t wrPinMask
Bitmask for WR pin PORT.
Definition: Adafruit_TFTDMA.h:121
volatile uint8_t * writePort
Pointer to 8-bit PORT OUT.
Definition: Adafruit_TFTDMA.h:100
int8_t resetPin
Index of RESET pin (or -1)
Definition: Adafruit_TFTDMA.h:126
uint32_t rdPinMask
Bitmask for RD pin PORT.
Definition: Adafruit_TFTDMA.h:120
volatile uint32_t * csPortSet
Pointer to CS pin PORT SET register.
Definition: Adafruit_TFTDMA.h:110
volatile uint8_t * dirClr
8-bit Port direction clear
Definition: Adafruit_TFTDMA.h:103
Subclass of Adafruit_TFTDMA providing a whole-screen contiguous framebuffer. This is probably the eas...
Definition: Adafruit_TFTDMA.h:178
_EPioType wrPeripheral
WR strobe peripheral type.
Definition: Adafruit_TFTDMA.h:129
int8_t wrPin
Index of WR pin.
Definition: Adafruit_TFTDMA.h:125
#define TFTWIDTH
Display width in pixels.
Definition: Adafruit_TFTDMA.h:26
Subclass of Adafruit_TFTDMA in which display (or section thereof) is generated one scanline at a time...
Definition: Adafruit_TFTDMA.h:506
volatile uint32_t * wrPortIdle
Pointer to WR pin PORT idle register.
Definition: Adafruit_TFTDMA.h:117
Subclass of Adafruit_TFTDMA that does not provide a contiguous framebuffer. Instead, application provides a buffer for graphics operations, which are divided into segments and redrawn as needed. Uses less RAM that TFT_framebuffer – only as much as one wants to allocate to it (minimum of TFTWIDTH*2 16-bit pixels, or 1,280 bytes, up to a maximum of 65,535 bytes). Invokes a user callback to draw graphics into this buffer before issuing to the screen. There is no permanent framebuffer; graphics are disposed after each update, and dirty rectangle handling is the application;s responsibility (or update the full screen or sections as needed).
Definition: Adafruit_TFTDMA.h:336
uint32_t csPinMask
Bitmask for CS pin PORT.
Definition: Adafruit_TFTDMA.h:118
#define TFTHEIGHT
Display height in pixels.
Definition: Adafruit_TFTDMA.h:27
void writeReg8(uint8_t reg, uint8_t value)
Writes an 8-bit value to an ILI9341 configuration register.
Definition: Adafruit_TFTDMA.cpp:466
volatile uint32_t * wrPortActive
Pointer to WR pin PORT active register.
Definition: Adafruit_TFTDMA.h:116
volatile uint32_t * cdPortClr
Pointer to CD pin PORT CLEAR register.
Definition: Adafruit_TFTDMA.h:113
volatile uint32_t * rdPortClr
Pointer to RD pin PORT CLEAR register.
Definition: Adafruit_TFTDMA.h:115
bool begin(void)
Initializes all pins and peripherals used by the library.
Definition: Adafruit_TFTDMA.cpp:243