Fixed parallel epd write bug

This commit is contained in:
Dominik Kotarski
2019-03-26 12:53:11 +01:00
parent e758428c53
commit 5799593dfb
4 changed files with 15356 additions and 15120 deletions
+5
View File
@@ -13,6 +13,8 @@
#include "aconnoHelpers.h"
#include "GDEP015OC1.h"
#include "aconnoBeeper.h"
#include "semphr.h"
extern TaskHandle_t LDRTask;
extern TaskHandle_t potTask;
@@ -48,6 +50,8 @@ uint8_t tempFlag;
bool gBleTaskSuspend = false;
extern SemaphoreHandle_t epdWriteMutex;
State::State()
{
_writeMethod = EPD_WRITE_METHOD::PARTIAL;
@@ -60,6 +64,7 @@ State::State(EPD_WRITE_METHOD writeMethod)
uint8_t State::writeToEpd()
{
NRF_LOG_DEBUG("PISEM_NA_EKRAN");
if(_writeMethod == EPD_WRITE_METHOD::PARTIAL)
{
epd.write();
+15320 -15106
View File
File diff suppressed because it is too large Load Diff
+3 -1
View File
@@ -134,6 +134,7 @@ SemaphoreHandle_t getInterruptSourceSemaphore;
QueueHandle_t interruptSourceQueue;
QueueHandle_t interruptSourceQueueSecondary;
TimerHandle_t intFlagTimer;
SemaphoreHandle_t epdWriteMutex;
/**
* @brief Object defining current state of the Master Example
@@ -201,6 +202,7 @@ int main(void)
{
NRF_LOG_ERROR("ERROR, not enough space available to create semaphore!");
}
epdWriteMutex = xSemaphoreCreateMutex();
// Create all tasks that will be used
// getInterruptSource task needs higher priority to ensure prompt interrupt
@@ -245,7 +247,7 @@ int main(void)
// Initialize state machine
pMenuState = new Intro1State(State::EPD_WRITE_METHOD::FULL);
pMenuState->displayOnEpd();
// Activate deep sleep mode.
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
+28 -13
View File
@@ -32,6 +32,7 @@ extern Potentiometer pot;
extern MCP9700 ambientTemperature;
extern Servo servo;
extern SemaphoreHandle_t getInterruptSourceSemaphore;
extern SemaphoreHandle_t epdWriteMutex;
extern State *pMenuState;
extern QueueHandle_t interruptSourceQueue;
IOEXP_INT_SOURCE intSourceSend = IOEXP_INT_SOURCE::NOTHING;
@@ -133,7 +134,6 @@ void getInterruptSourceFunction(void *arg)
getInterruptSourceFlag=false;
intSourceSend = (IOEXP_INT_SOURCE)intSrcPin;
xQueueSendToBack(interruptSourceQueue,
(void *) &intSourceSend,
((TickType_t)TICKS_TO_BLOCK_DEFAULT) != pdPASS);
@@ -170,7 +170,8 @@ void menuStateMachineTaskFunction(void *arg)
&(intSourceRecv),
portMAX_DELAY))
{
//prevent changing the state while the
xSemaphoreTake(epdWriteMutex, portMAX_DELAY);
/* Todo: delete could make problems if the same state is returned */
State *newMenuState = pMenuState->handleEvent(intSourceRecv);
if(typeid(*pMenuState) != typeid(*newMenuState))
@@ -184,6 +185,8 @@ void menuStateMachineTaskFunction(void *arg)
delete pMenuState;
pMenuState = newMenuState;
}
xSemaphoreGive(epdWriteMutex);
}
/* todo: consider pre-creating all state objects instead of
@@ -210,7 +213,7 @@ void ldrFunction(void *arg)
adc.updateData();//to clear the ADC buffer
while(1)
{
{
light.updateData(&data);
if(data.light < voltage - 0.05f || data.light > voltage + 0.05f || ldrFlag == 1 )
{
@@ -227,9 +230,12 @@ void ldrFunction(void *arg)
else if(voltage<0.90f) { x_coord = 141; y_coord = 95; }
else { x_coord = 100; y_coord = 85; }
xSemaphoreTake(epdWriteMutex, portMAX_DELAY);
epd.drawImage(ldr1);
epd.drawLine(100,135,x_coord,y_coord,0);
epd.write();
xSemaphoreGive(epdWriteMutex);
}
vTaskDelay(EXAMPLE_DELAY_MS);
}
@@ -249,6 +255,7 @@ void potentiometerFunction(void *arg)
while(1)
{
xSemaphoreTake(epdWriteMutex, portMAX_DELAY);
pot.updateData(&data);
if(data.voltage > voltage + 0.02f)
{
@@ -261,6 +268,7 @@ void potentiometerFunction(void *arg)
epd.write();
}
voltage = data.voltage;
xSemaphoreGive(epdWriteMutex);
vTaskDelay(POT_DELAY_MS);
}
}
@@ -284,6 +292,7 @@ void temperatureFunction(void *arg)
if(data.temperature > temperature + 0.5f ||
data.temperature < temperature - 0.5f || tempFlag == 1)
{
xSemaphoreTake(epdWriteMutex, portMAX_DELAY);
tempFlag = 0;
// Erase previous data from the buffer
epd.writeString(buffer,110,100,1);
@@ -299,7 +308,8 @@ void temperatureFunction(void *arg)
sprintf(buffer, "%c%d.%d", tmpSign, tmpInt1, tmpInt2); //Create a string
epd.writeString(buffer, 110, 100, 0); // Write new data to the buffer
epd.write();
epd.write();
xSemaphoreGive(epdWriteMutex);
}
vTaskDelay(EXAMPLE_DELAY_MS);
}
@@ -326,6 +336,7 @@ void gyroFunction(void *arg)
(gyroVal.y > 50.0f) || (gyroVal.y < (-50.0f)) ||
(gyroVal.z > 50.0f) || (gyroVal.z < (-50.0f)))
{
xSemaphoreTake(epdWriteMutex, portMAX_DELAY);
switch(rand()%6+1)
{
#define C(x) epd.fillCircle(100,100,10,x)
@@ -374,8 +385,10 @@ void gyroFunction(void *arg)
#undef CR
#undef CL
#undef C
}
}
}
xSemaphoreGive(epdWriteMutex);
}
vTaskDelay(EXAMPLE_DELAY_MS);
}
}
@@ -455,6 +468,7 @@ void imageUpdate(uint8_t const *data, size_t dataLen)
{
static uint16_t epdPointer = 0;
xSemaphoreTake(epdWriteMutex, portMAX_DELAY);
for(uint16_t x = 0; x < dataLen; x++)
{
epd.fill(data[x], epdPointer);
@@ -467,6 +481,8 @@ void imageUpdate(uint8_t const *data, size_t dataLen)
epd.writeFull();
NRF_LOG_INFO("Image updated.");
}
xSemaphoreGive(epdWriteMutex);
}
void infraredFunction(void *arg)
@@ -592,20 +608,18 @@ void joystickTaskFunction(void *arg)
{
if (joyFlag)
{
xSemaphoreTake(epdWriteMutex, portMAX_DELAY);
joyFlag = 0;
epd.drawImage(joystick1);
epd.fillCircle(xCoordCenter,
yCoordCenter,
ballRadius,
color);
// do not allow task suspending while epd writing
vTaskSuspendAll();
epd.write();
xTaskResumeAll();
xSemaphoreGive(epdWriteMutex);
}
ballPositionPrev = ballPosition;
epd.drawImage(joystick1);
switch(intSourceRecvSecondary)
{
case IOEXP_INT_SOURCE::JOY_UP:
@@ -706,7 +720,8 @@ void joystickTaskFunction(void *arg)
}
if(ballPositionPrev != ballPosition)
{
vTaskSuspend(menuStateMachineTask);
xSemaphoreTake(epdWriteMutex, portMAX_DELAY);
epd.drawImage(joystick1);
switch(ballPosition)
{
case BALL_POSITION::UP:
@@ -759,7 +774,7 @@ void joystickTaskFunction(void *arg)
break;
}
}
vTaskResume(menuStateMachineTask);
xSemaphoreGive(epdWriteMutex);
}
}
}