mirror of
https://github.com/adafruit/Adafruit-GFX-Library.git
synced 2024-10-03 18:18:46 -04:00
better use nrf spi with dma for drawing pixels with nrf52840 (#248)
* better use nrf spi with dma * only use spim dma API with 52840
This commit is contained in:
parent
4e1e209b75
commit
c4e7aea568
@ -984,6 +984,25 @@ void Adafruit_SPITFT::writePixels(uint16_t *colors, uint32_t len,
|
||||
hwspi._spi->writePixels(colors, len * 2);
|
||||
return;
|
||||
}
|
||||
#elif defined(ARDUINO_NRF52_ADAFRUIT) && defined(NRF52840_XXAA)// Adafruit nRF52 use SPIM3 DMA at 32Mhz
|
||||
// TFT and SPI DMA endian is different we need to swap bytes
|
||||
if (!bigEndian) {
|
||||
for(uint32_t i=0; i<len; i++) {
|
||||
colors[i] = __builtin_bswap16(colors[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// use the separate tx, rx buf variant to prevent overwrite the buffer
|
||||
hwspi._spi->transfer(colors, NULL, 2*len);
|
||||
|
||||
// swap back color buffer
|
||||
if (!bigEndian) {
|
||||
for(uint32_t i=0; i<len; i++) {
|
||||
colors[i] = __builtin_bswap16(colors[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
#elif defined(USE_SPI_DMA)
|
||||
if((connection == TFT_HARD_SPI) || (connection == TFT_PARALLEL)) {
|
||||
int maxSpan = maxFillLen / 2; // One scanline max
|
||||
@ -1131,6 +1150,30 @@ void Adafruit_SPITFT::writeColor(uint16_t color, uint32_t len) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
#elif defined(ARDUINO_NRF52_ADAFRUIT) && defined(NRF52840_XXAA) // Adafruit nRF52840 use SPIM3 DMA at 32Mhz
|
||||
// at most 2 scan lines
|
||||
uint32_t const pixbufcount = min(len, ((uint32_t) 2*width()));
|
||||
uint16_t* pixbuf = (uint16_t*) rtos_malloc(2*pixbufcount);
|
||||
|
||||
// use SPI3 DMA if we could allocate buffer, else fall back to writing each pixel loop below
|
||||
if (pixbuf)
|
||||
{
|
||||
uint16_t const swap_color = __builtin_bswap16(color);
|
||||
|
||||
// fill buffer with color
|
||||
for(uint32_t i=0; i<pixbufcount; i++) {
|
||||
pixbuf[i] = swap_color;
|
||||
}
|
||||
|
||||
while(len) {
|
||||
uint32_t const count = min(len, pixbufcount);
|
||||
writePixels(pixbuf, count, true, true);
|
||||
len -= count;
|
||||
}
|
||||
|
||||
rtos_free(pixbuf);
|
||||
return;
|
||||
}
|
||||
#else // !ESP32
|
||||
#if defined(USE_SPI_DMA)
|
||||
if(((connection == TFT_HARD_SPI) || (connection == TFT_PARALLEL)) &&
|
||||
|
Loading…
Reference in New Issue
Block a user