diff --git a/libraries/pico_graphics/pico_graphics_pen_p4.cpp b/libraries/pico_graphics/pico_graphics_pen_p4.cpp index ccfef6f7..6bf0ef66 100644 --- a/libraries/pico_graphics/pico_graphics_pen_p4.cpp +++ b/libraries/pico_graphics/pico_graphics_pen_p4.cpp @@ -135,8 +135,9 @@ namespace pimoroni { // Treat our void* frame_buffer as uint8_t uint8_t *src = (uint8_t *)frame_buffer; - // Allocate a per-row temporary buffer - uint16_t row_buf[bounds.w]; + // Allocate two per-row temporary buffers, as the callback may transfer by DMA + // while we're preparing the next row + uint16_t row_buf[2][bounds.w]; for(auto y = 0; y < bounds.h; y++) { /*if(scanline_interrupt != nullptr) { scanline_interrupt(y); @@ -150,11 +151,11 @@ namespace pimoroni { uint8_t c = src[(bounds.w * y / 2) + (x / 2)]; uint8_t o = (~x & 0b1) * 4; // bit offset within byte uint8_t b = (c >> o) & 0xf; // bit value shifted to position - row_buf[x] = cache[b]; + row_buf[y & 1][x] = cache[b]; } // Callback to the driver with the row data - callback(row_buf, bounds.w * sizeof(RGB565)); + callback(row_buf[y & 1], bounds.w * sizeof(RGB565)); } } } -} \ No newline at end of file +} diff --git a/libraries/pico_graphics/pico_graphics_pen_p8.cpp b/libraries/pico_graphics/pico_graphics_pen_p8.cpp index 92071611..a8d7112b 100644 --- a/libraries/pico_graphics/pico_graphics_pen_p8.cpp +++ b/libraries/pico_graphics/pico_graphics_pen_p8.cpp @@ -109,15 +109,16 @@ namespace pimoroni { // Treat our void* frame_buffer as uint8_t uint8_t *src = (uint8_t *)frame_buffer; - // Allocate a per-row temporary buffer - uint16_t row_buf[bounds.w]; + // Allocate two per-row temporary buffers, as the callback may transfer by DMA + // while we're preparing the next row + uint16_t row_buf[2][bounds.w]; for(auto y = 0; y < bounds.h; y++) { for(auto x = 0; x < bounds.w; x++) { - row_buf[x] = cache[src[bounds.w * y + x]]; + row_buf[y & 1][x] = cache[src[bounds.w * y + x]]; } // Callback to the driver with the row data - callback(row_buf, bounds.w * sizeof(RGB565)); + callback(row_buf[y & 1], bounds.w * sizeof(RGB565)); } } } -} \ No newline at end of file +} diff --git a/libraries/pico_graphics/pico_graphics_pen_rgb332.cpp b/libraries/pico_graphics/pico_graphics_pen_rgb332.cpp index b11c544a..361bd256 100644 --- a/libraries/pico_graphics/pico_graphics_pen_rgb332.cpp +++ b/libraries/pico_graphics/pico_graphics_pen_rgb332.cpp @@ -84,16 +84,17 @@ namespace pimoroni { // Treat our void* frame_buffer as uint8_t uint8_t *src = (uint8_t *)frame_buffer; - // Allocate a per-row temporary buffer - uint16_t row_buf[bounds.w]; + // Allocate two per-row temporary buffers, as the callback may transfer by DMA + // while we're preparing the next row + uint16_t row_buf[2][bounds.w]; for(auto y = 0; y < bounds.h; y++) { for(auto x = 0; x < bounds.w; x++) { - row_buf[x] = rgb332_to_rgb565_lut[*src]; + row_buf[y & 1][x] = rgb332_to_rgb565_lut[*src]; src++; } // Callback to the driver with the row data - callback(row_buf, bounds.w * sizeof(RGB565)); + callback(row_buf[y & 1], bounds.w * sizeof(RGB565)); } } } @@ -118,4 +119,4 @@ namespace pimoroni { } } } -} \ No newline at end of file +}