summaryrefslogtreecommitdiff
path: root/src/Components/Gfx
diff options
context:
space:
mode:
authorJF <jf@codingfield.com>2020-01-26 15:35:18 +0100
committerJF <jf@codingfield.com>2020-01-26 15:35:18 +0100
commit640e8cd1febc679b976fb26225aec8d462a4c241 (patch)
treee008509713b90cf7c71b442b903a415d11227c1f /src/Components/Gfx
parent5fa4f5abe0b752bb2d990378e02d6424a1d1b661 (diff)
GFX : wait end of transfert using a task notification.
Code cleaning in SpiMaster.
Diffstat (limited to 'src/Components/Gfx')
-rw-r--r--src/Components/Gfx/Gfx.cpp27
-rw-r--r--src/Components/Gfx/Gfx.h5
2 files changed, 29 insertions, 3 deletions
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 <libraries/svc/nrf_svci.h>
+#include <FreeRTOS.h>
+#include <task.h>
#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<const uint8_t *>(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<const uint8_t *>(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_INFO *>(font);
state.character = c;
state.color = color;
+ state.taskToNotify = xTaskGetCurrentTaskHandle();
lcd.BeginDrawBuffer(*x, y, bytes_in_line*8, font->height);
lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(&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 <cstdint>
#include <nrf_font.h>
#include <drivers/BufferProvider.h>
+#include <FreeRTOS.h>
+#include <task.h>
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);
};
}
}