Adafruit TFTDMA Arduino Library
Public Member Functions | List of all members
TFT_segmented Class Reference

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). More...

#include <Adafruit_TFTDMA.h>

Inheritance diagram for TFT_segmented:
Adafruit_TFTDMA

Public Member Functions

 TFT_segmented (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 hardware yet. More...
 
bool begin (void)
 Initializes all pins and peripherals used by the library. More...
 
void update (int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t *buf, uint16_t maxSegmentSize, int16_t(*userCallback)(uint16_t *dest, uint16_t len, void *udPtr), void *userData)
 Refreshes specified region of the display, using a given buffer as working space. The region will be divided vertically into a number of segments, the fewest needed to fit into the buffer, and a callback is then invoked to draw each segment as needed (segment contents are not preserved; every invocation must fully render that segment) and a DMA transfer is initiated while then processing the next segment. Function returns when last segment transfer is started – application can proceed with other code at that point but MUST not modify the segment buffer as it's transferred. Segment buffer size, specified in bytes, must be a minimum of two full scanlines (1,280 bytes), but larger is generally better, as RAM allows (e.g. 16 scanlines x 2). One half of the segment buffer is drawn (via callback) while the other half is being transferred, swapping each time until the entire region is complete. More...
 
void waitForUpdate (void)
 Wait for the last DMA transfer initiated by update() to complete. Segment buffer can then be modified by another region update.
 
void rawPixel (int16_t x, int16_t y, uint16_t color)
 Lowest-level pixel-setting operation. Sets color of pixel at a given coordinate in the current segment buffer. Does NOT provide clipping, and pixel color must already be endian-adjusted if needed to match format needed by ILI9341 (MSB first). More...
 
void drawPixel (int16_t x, int16_t y, uint16_t color)
 Set pixel in segment buffer, with clipping, compensating for the offset of the buffer relative to the screen. More...
 
void fillRect (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
 Fill rectangle in segment buffer, with clipping, compensating the offset of the buffer relative to the screen. More...
 
void fillScreen (uint16_t color=0)
 Fill entire segment buffer with solid color. More...
 
- Public Member Functions inherited from Adafruit_TFTDMA
 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 hardware yet. More...
 
bool begin (void)
 Initializes all pins and peripherals used by the library. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Adafruit_TFTDMA
void writeReg8 (uint8_t reg, uint8_t value)
 Writes an 8-bit value to an ILI9341 configuration register. More...
 
void writeReg16 (uint8_t reg, uint16_t value)
 Writes a 16-bit value to an ILI9341 configuration register. More...
 
void writeReg32 (uint8_t reg, uint32_t value)
 Writes a 32-bit value to an ILI9341 configuration register. More...
 
void setAddrWindow (int16_t x1, int16_t y1, int16_t x2, int16_t y2)
 Sets the ILI9341 'address window' for subsequent graphics operations. This also issues a MEMORYWRITE command and leaves the device selected and in DATA mode for incoming pixel data. Inputs are NOT sorted or clipped; subclasses provide higher-level functions that ensure the validity of these parameters. More...
 
- Protected Attributes inherited from Adafruit_TFTDMA
volatile uint8_t * writePort
 Pointer to 8-bit PORT OUT.
 
volatile uint8_t * readPort
 Pointer to 8-bit PORT IN.
 
volatile uint8_t * dirSet
 8-bit PORT direction set
 
volatile uint8_t * dirClr
 8-bit Port direction clear
 
volatile uint32_t * csPortSet
 Pointer to CS pin PORT SET register.
 
volatile uint32_t * csPortClr
 Pointer to CS pin PORT CLEAR register.
 
volatile uint32_t * cdPortSet
 Pointer to CD pin PORT SET register.
 
volatile uint32_t * cdPortClr
 Pointer to CD pin PORT CLEAR register.
 
volatile uint32_t * rdPortSet
 Pointer to RD pin PORT SET register.
 
volatile uint32_t * rdPortClr
 Pointer to RD pin PORT CLEAR register.
 
volatile uint32_t * wrPortActive
 Pointer to WR pin PORT active register.
 
volatile uint32_t * wrPortIdle
 Pointer to WR pin PORT idle register.
 
uint32_t csPinMask
 Bitmask for CS pin PORT.
 
uint32_t cdPinMask
 Bitmask for CD pin PORT.
 
uint32_t rdPinMask
 Bitmask for RD pin PORT.
 
uint32_t wrPinMask
 Bitmask for WR pin PORT.
 
int8_t csPin
 Index of CS pin (or -1)
 
int8_t cdPin
 Index of CD pin.
 
int8_t rdPin
 Index of RD pin.
 
int8_t wrPin
 Index of WR pin.
 
int8_t resetPin
 Index of RESET pin (or -1)
 
int8_t d0Pin
 Index of data bit 0 pin.
 
int8_t tcNum
 Timer/Counter number.
 
_EPioType wrPeripheral
 WR strobe peripheral type.
 
Adafruit_ZeroDMA dma
 DMA instance.
 

Detailed Description

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).

Constructor & Destructor Documentation

◆ TFT_segmented()

TFT_segmented::TFT_segmented ( 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 hardware yet.

Parameters
tcIndex of timer/counter peripheral for PWM (used for generating write-strobe pulses), e.g. pass 2 to use the TC2 peripheral. Certain timer/counters may be in use by other libraries or reserved for the Arduino millis()/micros() timers.
resetIndex of pin connected to the ILI9341's reset line, or -1 if unconnected. Using the reset line is optional but strongly recommended.
csIndex of pin connected to ILI9341 chip select line. Required; must be >= 0.
cdIndex of pin connected to ILI9341 command/data line. Required; must be >= 0.
rdIndex of pin connected to ILI9341 read-strobe line, or -1 if unconnected. This library currently doesn't read any registers or pixel data from the device; it is coded specifically for this driver and write-only, so -1 is totally acceptable and even preferred here. Maybe this parameter will be removed in the future.
wrIndex of pin connected to ILI9341 write-strobe line. Required; must be >= 0. Additionally, this pin must be a valid TCx/WO[0] output for the timer/counter specified by the first parameter, OR a CCL/OUT[x] pin for the same timer counter (see last parameter).
d0Index of pin connected to ILI9341 data bit 0 line. Required; must be >= 0. Additionally, the corresponding PORT bit index for this pin MUST be the least-significant bit of an 8-bit byte (e.g. 0, 8, 16 or 24) if using the 8-bit parallel interface, or the least-significant bit of a 16-bit halfword (e.g. 0 or 16) if using the 16-bit parallel interface. Use of the next 7 or 15 bits of the PORT is implied, the pins corresponding to those bits might not be contiguous or sequential; refer to the schematic or device-specific variant.cpp file for insights.
periphPeripheral type connected to the write-strobe pin for PWM out. This can be PIO_TIMER or PIO_TIMER_ALT corresponding to TCx/WO[0] for that pin, or PIO_CCL for CCL/OUT[x] on a pin. PIO_TIMER and PIO_TIMER_ALT require the use of an external logic inverter (the ILI9341 uses active-low control signals). PIO_CCL does not need an inverter, but the choice of pins is very limited, perhaps just one or two.

Member Function Documentation

◆ begin()

bool TFT_segmented::begin ( void  )

Initializes all pins and peripherals used by the library.

Returns
true if an error occurred, false otherwise. An error returned here is usually symptomatic of a constructor problem, such as an invalid pin or timer number.

◆ update()

void TFT_segmented::update ( int16_t  x1,
int16_t  y1,
int16_t  x2,
int16_t  y2,
uint16_t *  buf,
uint16_t  maxSegmentSize,
int16_t(*)(uint16_t *dest, uint16_t len, void *udPtr)  userCallback,
void *  userData 
)

Refreshes specified region of the display, using a given buffer as working space. The region will be divided vertically into a number of segments, the fewest needed to fit into the buffer, and a callback is then invoked to draw each segment as needed (segment contents are not preserved; every invocation must fully render that segment) and a DMA transfer is initiated while then processing the next segment. Function returns when last segment transfer is started – application can proceed with other code at that point but MUST not modify the segment buffer as it's transferred. Segment buffer size, specified in bytes, must be a minimum of two full scanlines (1,280 bytes), but larger is generally better, as RAM allows (e.g. 16 scanlines x 2). One half of the segment buffer is drawn (via callback) while the other half is being transferred, swapping each time until the entire region is complete.

Parameters
x1Left edge of region to update.
y1Top edge of region to update.
x2Right edge of region to update.
y2Bottom edge of region to update.
bufSegment buffer, minimum 1,280 bytes, 16 X this or more is recommended, up to a maximum of 65,535 bytes.
maxSegmentSizeSize of ONE HALF of the segment buffer, e.g. the amount of data that will be rendered or transferred in each segment – there are two segments being worked with here.
userCallbackFunction for rendering one segment of the region being updated. Callback is passed a pointer to a segment buffer, the height of the region being updated (in scanlines), and a pointer to optional user data provided by the application. Callback should return the number of actual scanlines rendered (between 1 and the number of lines passed in, which allows for subsequent calls to be aligned to specific boundaries if needed).
userDataPointer to user-defined data structure which can be used to pass data to the callback or between invocations of the callback. Very little is passed to the callback – this is by design – so this structure, or just global variables in one's code, can be used to contain information such as the region width or horizontal/vertical offsets of the segment within the overall screen. Segments are always processed in-order from top to bottom, so simple incremental counters may be adequate for many situations.

◆ rawPixel()

void TFT_segmented::rawPixel ( int16_t  x,
int16_t  y,
uint16_t  color 
)
inline

Lowest-level pixel-setting operation. Sets color of pixel at a given coordinate in the current segment buffer. Does NOT provide clipping, and pixel color must already be endian-adjusted if needed to match format needed by ILI9341 (MSB first).

Parameters
xHorizontal position of pixel (0 to buffer width-1)
yVertical position of pixel (0 to buffer height-1).
color16-bit (5/6/5 R/G/B) color value, ILI9341 byte order.

◆ drawPixel()

void TFT_segmented::drawPixel ( int16_t  x,
int16_t  y,
uint16_t  color 
)

Set pixel in segment buffer, with clipping, compensating for the offset of the buffer relative to the screen.

Parameters
xHorizontal position of pixel.
yVertical position of pixel.
color16-bit (5/6/5 R/G/B) color value, native byte order.

◆ fillRect()

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

Fill rectangle in segment buffer, with clipping, compensating the offset of the buffer relative to the screen.

Parameters
xLeft edge of rectangle (right edge if negative width).
yTop edge of rectangle (bottom edge if negative height).
wWidth in pixels.
hHeight in pixels.
color16-bit (5/6/5 R/G/B) color value, native byte order.

◆ fillScreen()

void TFT_segmented::fillScreen ( uint16_t  color = 0)

Fill entire segment buffer with solid color.

Parameters
color16-bit (5/6/5 R/G/B) color value, native byte order.

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