GFX : wait end of transfert using a task notification.
Code cleaning in SpiMaster.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user