From 640e8cd1febc679b976fb26225aec8d462a4c241 Mon Sep 17 00:00:00 2001 From: JF Date: Sun, 26 Jan 2020 15:35:18 +0100 Subject: GFX : wait end of transfert using a task notification. Code cleaning in SpiMaster. --- src/Components/Gfx/Gfx.cpp | 27 ++++++++++++++++++++++++--- src/Components/Gfx/Gfx.h | 5 +++++ 2 files changed, 29 insertions(+), 3 deletions(-) (limited to 'src/Components/Gfx') diff --git a/src/Components/Gfx/Gfx.cpp b/src/Components/Gfx/Gfx.cpp index 2f64596c..0dcb98a6 100644 --- a/src/Components/Gfx/Gfx.cpp +++ b/src/Components/Gfx/Gfx.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include "Gfx.h" #include "../../drivers/St7789.h" using namespace Pinetime::Components; @@ -17,10 +19,12 @@ void Gfx::ClearScreen() { state.currentIteration = 0; state.busy = true; state.action = Action::FillRectangle; + state.taskToNotify = xTaskGetCurrentTaskHandle(); lcd.BeginDrawBuffer(0, 0, width, height); lcd.NextDrawBuffer(reinterpret_cast(buffer), width * 2); - while(state.busy) {} // TODO wait on an event/queue/... instead of polling + WaitTransfertFinished(); + } void Gfx::FillRectangle(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t color) { @@ -30,10 +34,13 @@ void Gfx::FillRectangle(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t col state.currentIteration = 0; state.busy = true; state.action = Action::FillRectangle; + state.color = color; + state.taskToNotify = xTaskGetCurrentTaskHandle(); lcd.BeginDrawBuffer(x, y, w, h); lcd.NextDrawBuffer(reinterpret_cast(buffer), width * 2); - while(state.busy) {} // TODO wait on an event/queue/... instead of polling + + WaitTransfertFinished(); } void Gfx::DrawString(uint8_t x, uint8_t y, uint16_t color, const char *text, const FONT_INFO *p_font, bool wrap) { @@ -100,10 +107,11 @@ void Gfx::DrawChar(const FONT_INFO *font, uint8_t c, uint8_t *x, uint8_t y, uint state.font = const_cast(font); state.character = c; state.color = color; + state.taskToNotify = xTaskGetCurrentTaskHandle(); lcd.BeginDrawBuffer(*x, y, bytes_in_line*8, font->height); lcd.NextDrawBuffer(reinterpret_cast(&buffer), bytes_in_line*8*2); - while(state.busy) {} // TODO wait on an event/queue/... instead of polling + WaitTransfertFinished(); *x += font->charInfo[char_idx].widthBits + font->spacePixels; } @@ -131,6 +139,7 @@ bool Gfx::GetNextBuffer(uint8_t **data, size_t &size) { state.remainingIterations--; if (state.remainingIterations == 0) { state.busy = false; + NotifyEndOfTransfert(state.taskToNotify); return false; } @@ -162,4 +171,16 @@ bool Gfx::GetNextBuffer(uint8_t **data, size_t &size) { return true; } +void Gfx::NotifyEndOfTransfert(TaskHandle_t task) { + if(task != nullptr) { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + vTaskNotifyGiveFromISR(task, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + } +} + +void Gfx::WaitTransfertFinished() const { + ulTaskNotifyTake(pdTRUE, 500); +} + diff --git a/src/Components/Gfx/Gfx.h b/src/Components/Gfx/Gfx.h index 81c5f387..f31b13c0 100644 --- a/src/Components/Gfx/Gfx.h +++ b/src/Components/Gfx/Gfx.h @@ -2,6 +2,8 @@ #include #include #include +#include +#include namespace Pinetime { @@ -36,6 +38,7 @@ namespace Pinetime { volatile FONT_INFO *font; volatile uint16_t color; volatile uint8_t character; + volatile TaskHandle_t taskToNotify = nullptr; }; volatile State state; @@ -45,6 +48,8 @@ namespace Pinetime { void pixel_draw(uint8_t x, uint8_t y, uint16_t color); void SetBackgroundColor(uint16_t color); + void WaitTransfertFinished() const; + void NotifyEndOfTransfert(TaskHandle_t task); }; } } -- cgit v1.2.3