From cbdbcc283d1713dc4db9da4096b0987738c5a656 Mon Sep 17 00:00:00 2001 From: Romain Goyet Date: Tue, 23 May 2017 17:34:37 +0200 Subject: [PATCH] [ion/device] Clean up DMA usage for the display Change-Id: Ic9989cf3de95cb15191d15473f839e89121c99cd --- ion/src/device/display.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ion/src/device/display.cpp b/ion/src/device/display.cpp index 02b11ab06..245705655 100644 --- a/ion/src/device/display.cpp +++ b/ion/src/device/display.cpp @@ -11,25 +11,36 @@ extern "C" { * configured, we only need to write in the address space of the MCU to actually * send some data to the LCD controller. */ +#define USE_DMA_FOR_PUSH_PIXELS 0 +#define USE_DMA_FOR_PUSH_COLOR 0 + +#define USE_DMA (USE_DMA_FOR_PUSH_PIXELS|USE_DMA_FOR_PUSH_COLOR) + // Public Ion::Display methods namespace Ion { namespace Display { void pushRect(KDRect r, const KDColor * pixels) { +#if USE_DMA Device::waitForPendingDMAUploadCompletion(); +#endif Device::setDrawingArea(r, Device::Orientation::Landscape); Device::pushPixels(pixels, r.width()*r.height()); } void pushRectUniform(KDRect r, KDColor c) { +#if USE_DMA Device::waitForPendingDMAUploadCompletion(); +#endif Device::setDrawingArea(r, Device::Orientation::Portrait); Device::pushColor(c, r.width()*r.height()); } void pullRect(KDRect r, KDColor * pixels) { +#if USE_DMA Device::waitForPendingDMAUploadCompletion(); +#endif Device::setDrawingArea(r, Device::Orientation::Landscape); Device::pullPixels(pixels, r.width()*r.height()); } @@ -57,7 +68,9 @@ namespace Device { #define SEND_COMMAND(c, ...) {*CommandAddress = Command::c; uint8_t data[] = {__VA_ARGS__}; for (unsigned int i=0;isetPINC(incrementSrc); DMAEngine.SCR(DMAStream)->setEN(true); } +#endif void initGPIO() { // All the FSMC GPIO pins use the alternate function number 12 @@ -272,7 +287,6 @@ void pushPixels(const KDColor * pixels, size_t numberOfPixels) { * guarantee that the content at "pixels" will remain valid once we exit this * function call. In practice, we might be able to use DMA here because most * of the time we push pixels from static locations. */ -#define USE_DMA_FOR_PUSH_PIXELS 0 #if USE_DMA_FOR_PUSH_PIXELS startDMAUpload(pixels, true, numberOfPixels); #else @@ -295,16 +309,19 @@ void pushPixels(const KDColor * pixels, size_t numberOfPixels) { void pushColor(KDColor color, size_t numberOfPixels) { *CommandAddress = Command::MemoryWrite; +#if USE_DMA_FOR_PUSH_COLOR /* The "color" variable lives on the stack. We cannot take its address because * it will stop being valid as soon as we return. An easy workaround is to * duplicate the content in a static variable, whose value is guaranteed to be * kept until the next pushColor call. */ static KDColor staticColor; staticColor = color; - //startDMAUpload(&staticColor, false, (numberOfPixels > 64000 ? 64000 : numberOfPixels)); + startDMAUpload(&staticColor, false, (numberOfPixels > 64000 ? 64000 : numberOfPixels)); +#else while (numberOfPixels--) { *DataAddress = color; } +#endif } void pullPixels(KDColor * pixels, size_t numberOfPixels) {