From 652de85f4d3bdc6e7d8286419a9d83a74192a9d9 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Fri, 12 May 2023 12:53:07 +0100 Subject: [PATCH] Tufty 2040: RGB565 DMA display update. Use DMA to transfer a native RGB565 display buffer to PIO rather than pushing into the TX FIFO in a loop. Co-authored by @zx64 - https://github.com/pimoroni/pimoroni-pico/issues/776 --- drivers/st7789/st7789.cpp | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/drivers/st7789/st7789.cpp b/drivers/st7789/st7789.cpp index a1cbc937..01c66ec9 100644 --- a/drivers/st7789/st7789.cpp +++ b/drivers/st7789/st7789.cpp @@ -240,29 +240,13 @@ namespace pimoroni { } void ST7789::write_blocking_parallel(const uint8_t *src, size_t len) { - const uint8_t *p = src; - while(len--) { - // Does not byte align correctly - //pio_sm_put_blocking(parallel_pio, parallel_sm, *p); - while (pio_sm_is_tx_fifo_full(parallel_pio, parallel_sm)) - ; - *(volatile uint8_t*)¶llel_pio->txf[parallel_sm] = *p; - p++; - } + write_blocking_dma(src, len); + dma_channel_wait_for_finish_blocking(st_dma); - uint32_t sm_stall_mask = 1u << (parallel_sm + PIO_FDEBUG_TXSTALL_LSB); - parallel_pio->fdebug = sm_stall_mask; - while (!(parallel_pio->fdebug & sm_stall_mask)) - ; - /*uint32_t mask = 0xff << d0; - while(len--) { - gpio_put(wr_sck, false); - uint8_t v = *src++; - gpio_put_masked(mask, v << d0); - //asm("nop;"); - gpio_put(wr_sck, true); - asm("nop;"); - }*/ + // This may cause a race between PIO and the + // subsequent chipselect deassert for the last pixel + while(!pio_sm_is_tx_fifo_empty(parallel_pio, parallel_sm)) + ; } void ST7789::command(uint8_t command, size_t len, const char *data) {