@@ -865,8 +865,16 @@ void Adafruit_SPITFT::writePixel(int16_t x, int16_t y, uint16_t color) {
865865 @param colors Pointer to array of 16-bit pixel values in '565' RGB
866866 format.
867867 @param len Number of elements in 'colors' array.
868+ @param block If true (default case if unspecified), function blocks
869+ until DMA transfer is complete. This is simply IGNORED
870+ if DMA is not enabled. If false, the function returns
871+ immediately after the last DMA transfer is started,
872+ and one should use the dmaWait() function before
873+ doing ANY other display-related activities (or even any
874+ SPI-related activities, if using an SPI display that
875+ shares the bus with other devices).
868876*/
869- void Adafruit_SPITFT::writePixels (uint16_t *colors, uint32_t len) {
877+ void Adafruit_SPITFT::writePixels (uint16_t *colors, uint32_t len, bool block ) {
870878
871879 if (!len) return ; // Avoid 0-byte transfers
872880
@@ -917,15 +925,17 @@ void Adafruit_SPITFT::writePixels(uint16_t *colors, uint32_t len) {
917925 }
918926 lastFillColor = 0x0000 ; // pixelBuf has been sullied
919927 lastFillLen = 0 ;
920- while (dma_busy); // Wait for last line to complete
928+ if (block) {
929+ while (dma_busy); // Wait for last line to complete
921930 #if defined(__SAMD51__)
922- if (connection == TFT_HARD_SPI) {
923- // See SAMD51 note in writeColor()
924- hwspi._spi ->setDataMode (SPI_MODE0);
925- } else {
926- pinPeripheral (tft8._wr , PIO_OUTPUT); // Switch WR back to GPIO
927- }
931+ if (connection == TFT_HARD_SPI) {
932+ // See SAMD51 note in writeColor()
933+ hwspi._spi ->setDataMode (SPI_MODE0);
934+ } else {
935+ pinPeripheral (tft8._wr , PIO_OUTPUT); // Switch WR back to GPIO
936+ }
928937 #endif // end __SAMD51__
938+ }
929939 return ;
930940 }
931941#endif // end USE_SPI_DMA
@@ -937,6 +947,26 @@ void Adafruit_SPITFT::writePixels(uint16_t *colors, uint32_t len) {
937947 }
938948}
939949
950+ /* !
951+ @brief Wait for the last DMA transfer in a prior non-blocking
952+ writePixels() call to complete. This does nothing if DMA
953+ is not enabled, and is not needed if blocking writePixels()
954+ was used (as is the default case).
955+ */
956+ void Adafruit_SPITFT::dmaWait (void ) {
957+ #if defined(USE_SPI_DMA)
958+ while (dma_busy);
959+ #if defined(__SAMD51__)
960+ if (connection == TFT_HARD_SPI) {
961+ // See SAMD51 note in writeColor()
962+ hwspi._spi ->setDataMode (SPI_MODE0);
963+ } else {
964+ pinPeripheral (tft8._wr , PIO_OUTPUT); // Switch WR back to GPIO
965+ }
966+ #endif // end __SAMD51__
967+ #endif
968+ }
969+
940970/* !
941971 @brief Issue a series of pixels, all the same color. Not self-
942972 contained; should follow startWrite() and setAddrWindow() calls.
0 commit comments