mirror of
https://github.com/adafruit/Adafruit-GFX-Library.git
synced 2024-10-03 18:18:46 -04:00
Still working on SPI DMA, still not good on M4
This commit is contained in:
parent
54035091a3
commit
12ced10eec
@ -455,6 +455,7 @@ void Adafruit_SPITFT::pushColor(uint16_t color) {
|
||||
/**************************************************************************/
|
||||
void Adafruit_SPITFT::writePixels(uint16_t *colors, uint32_t len) {
|
||||
#ifdef USE_SPI_DMA
|
||||
if(_sclk < 0) { // using hardware SPI?
|
||||
int maxSpan = maxFillLen / 2; // One scanline max
|
||||
uint8_t pixelBufIdx = 0; // Active pixel buffer number
|
||||
while(len) {
|
||||
@ -489,6 +490,8 @@ void Adafruit_SPITFT::writePixels(uint16_t *colors, uint32_t len) {
|
||||
lastFillColor = 0x0000; // pixelBuf has been sullied
|
||||
lastFillLen = 0;
|
||||
while(dma_busy); // Wait for last line to complete
|
||||
return;
|
||||
}
|
||||
#else
|
||||
SPI_WRITE_PIXELS((uint8_t*)colors , len * 2);
|
||||
#endif
|
||||
@ -503,10 +506,14 @@ void Adafruit_SPITFT::writePixels(uint16_t *colors, uint32_t len) {
|
||||
/**************************************************************************/
|
||||
void Adafruit_SPITFT::writeColor(uint16_t color, uint32_t len) {
|
||||
|
||||
uint8_t hi = color >> 8, lo = color;
|
||||
|
||||
if(_sclk < 0) { // Using hardware SPI
|
||||
|
||||
#ifdef USE_SPI_DMA
|
||||
|
||||
int i, d, numDescriptors;
|
||||
if((color >> 8) == (color & 0xFF)) { // If high & low bytes are same...
|
||||
if(hi == lo) { // If high & low bytes are same...
|
||||
onePixelBuf = color;
|
||||
// Can do this with a relatively short descriptor list,
|
||||
// each transferring a max of 32,767 (not 32,768) pixels.
|
||||
@ -541,7 +548,7 @@ void Adafruit_SPITFT::writeColor(uint16_t color, uint32_t len) {
|
||||
len : maxFillLen) + 1) / 2;
|
||||
for(i=fillStart; i<fillEnd; i++) pixelPtr[i] = twoPixels;
|
||||
lastFillLen = fillEnd * 2;
|
||||
} // else do nothing, don't set pixels, don't change lastFillLen
|
||||
} // else do nothing, don't set pixels or change lastFillLen
|
||||
} else {
|
||||
int fillEnd = (((len < maxFillLen) ?
|
||||
len : maxFillLen) + 1) / 2;
|
||||
@ -565,53 +572,52 @@ void Adafruit_SPITFT::writeColor(uint16_t color, uint32_t len) {
|
||||
memcpy(dptr, &descriptor[0], sizeof(DmacDescriptor));
|
||||
|
||||
dma_busy = true;
|
||||
dma.startJob(); // Trigger SPI DMA transfer
|
||||
dma.startJob();
|
||||
while(dma_busy); // Wait for completion
|
||||
|
||||
// Unfortunately the wait is necessary. An earlier version returned
|
||||
// immediately and checked dma_busy on startWrite() instead, but it
|
||||
// turns out to be MUCH slower on many graphics operations (as when
|
||||
// drawing lines, pixel-by-pixel), perhaps because it's a volatile
|
||||
// type and doesn't cache.
|
||||
// type and doesn't cache. Working on this.
|
||||
|
||||
#else // Non-DMA
|
||||
|
||||
#ifdef SPI_HAS_WRITE_PIXELS
|
||||
if(_sclk >= 0){
|
||||
for (uint32_t t=0; t<len; t++){
|
||||
writePixel(color);
|
||||
}
|
||||
return;
|
||||
}
|
||||
static uint16_t temp[SPI_MAX_PIXELS_AT_ONCE];
|
||||
size_t blen = (len > SPI_MAX_PIXELS_AT_ONCE)?SPI_MAX_PIXELS_AT_ONCE:len;
|
||||
uint16_t tlen = 0;
|
||||
#define TMPBUF_LONGWORDS (SPI_MAX_PIXELS_AT_ONCE + 1) / 2
|
||||
#define TMPBUF_PIXELS (TMPBUF_LONGWORDS * 2)
|
||||
static uint32_t temp[TMPBUF_LONGWORDS];
|
||||
uint32_t c32 = color * 0x00010001;
|
||||
uint16_t bufLen = (len < TMPBUF_PIXELS) ? len : TMPBUF_PIXELS,
|
||||
xferLen, fillLen;
|
||||
|
||||
for (uint32_t t=0; t<blen; t++){
|
||||
temp[t] = color;
|
||||
// Fill temp buffer 32 bits at a time
|
||||
fillLen = (bufLen + 1) / 2; // Round up to next 32-bit boundary
|
||||
for(uint32_t t=0; t<fillLen; t++) {
|
||||
temp[t] = c2;
|
||||
}
|
||||
|
||||
while(len){
|
||||
tlen = (len>blen)?blen:len;
|
||||
writePixels(temp, tlen);
|
||||
len -= tlen;
|
||||
// Issue pixels in blocks from temp buffer
|
||||
while(len) { // While pixels remain
|
||||
xferLen = (bufLen < len) ? bufLen : len; // How many this pass?
|
||||
writePixels(temp, xferLen);
|
||||
len -= xferLen;
|
||||
}
|
||||
#else
|
||||
uint8_t hi = color >> 8, lo = color;
|
||||
if(_sclk < 0){ //AVR Optimization
|
||||
for (uint32_t t=len; t; t--){
|
||||
while(len--) {
|
||||
HSPI_WRITE(hi);
|
||||
HSPI_WRITE(lo);
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (uint32_t t=len; t; t--){
|
||||
spiWrite(hi);
|
||||
spiWrite(lo);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // end non-DMA
|
||||
|
||||
} else { // Bitbang SPI
|
||||
while(len--) {
|
||||
spiWrite(hi);
|
||||
spiWrite(lo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
|
Loading…
x
Reference in New Issue
Block a user