Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions hardware/emfcamp/sam/libraries/GLCD/gText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ void gText::ScrollUp(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2,
return;
}

if (this->Acquire() != pdTRUE)
return;

for (col = x1; col <= x2; col++) {
dy = y1;
glcd_Device::GotoXY(col, dy & ~7);
Expand Down Expand Up @@ -366,6 +369,7 @@ void gText::ScrollUp(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2,
this->WriteData(dbyte);
}
}
this->Release();
}

#ifndef GLCD_NO_SCROLLDOWN
Expand All @@ -390,6 +394,9 @@ void gText::ScrollDown(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2,
return;
}

if (this->Acquire() != pdTRUE)
return;

/*
* Process region from left to right
*/
Expand Down Expand Up @@ -467,6 +474,7 @@ void gText::ScrollDown(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2,
this->WriteData(dbyte);
}
}
this->Release();
}
#endif // GLCD_NO_SCROLLDOWN

Expand Down Expand Up @@ -753,6 +761,9 @@ int gText::PutChar(uint8_t c) {

#ifdef GLCD_OLD_FONTDRAW
/*================== OLD FONT DRAWING ============================*/
if (this->Acquire() != pdTRUE)
return 0;

glcd_Device::GotoXY(this->x, this->y);

/*
Expand Down Expand Up @@ -805,6 +816,8 @@ int gText::PutChar(uint8_t c) {
}
this->x = this->x + width + 1;

this->Release();

/*================== END of OLD FONT DRAWING ============================*/
#else

Expand Down Expand Up @@ -839,6 +852,9 @@ int gText::PutChar(uint8_t c) {
uint8_t dbyte;
uint8_t fdata;

if (this->Acquire() != pdTRUE)
return 0;

for (p = 0; p < pixels;) {
dy = this->y + p;

Expand Down Expand Up @@ -1036,6 +1052,7 @@ int gText::PutChar(uint8_t c) {

this->x = this->x + width + 1;

this->Release();
/*================== END of NEW FONT DRAWING ============================*/

#endif // NEW_FONTDRAW
Expand Down
9 changes: 9 additions & 0 deletions hardware/emfcamp/sam/libraries/GLCD/glcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ void glcd::InvertRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height) {
/*
* First do the fractional pages at the top of the region
*/
if (this->Acquire() != pdTRUE)
return;

this->GotoXY(x, y);
for (i = 0; i <= width; i++) {
data = this->ReadData();
Expand Down Expand Up @@ -398,6 +401,7 @@ void glcd::InvertRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height) {
this->WriteData(data);
}
}
this->Release();
}
/**
* Set LCD Display mode
Expand Down Expand Up @@ -438,6 +442,10 @@ void glcd::DrawBitmap(Image_t bitmap, uint8_t x, uint8_t y, uint8_t color) {

width = ReadPgmData(bitmap++);
height = ReadPgmData(bitmap++);

if (this->Acquire() != pdTRUE)
return;

#define BITMAP_FIX
#ifdef BITMAP_FIX // temporary ifdef just to show what changes if a new
// bit rendering routine is written.
Expand Down Expand Up @@ -485,6 +493,7 @@ void glcd::DrawBitmap(Image_t bitmap, uint8_t x, uint8_t y, uint8_t color) {
this->WriteData(~displayData);
}
}
this->Release();
}

#ifdef NOTYET
Expand Down
8 changes: 8 additions & 0 deletions hardware/emfcamp/sam/libraries/GLCD/glcd_Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ void glcd_Device::SetDot(uint8_t x, uint8_t y, uint8_t color) {
if ((x >= this->CurrentWidth()) || (y >= this->CurrentHeight()))
return;

if (this->Acquire() != pdTRUE)
return;

this->GotoXY(x, y - y % 8); // read data from display memory

data = this->ReadData();
Expand All @@ -69,6 +72,7 @@ void glcd_Device::SetDot(uint8_t x, uint8_t y, uint8_t color) {
data &= ~(0x01 << (y % 8)); // clear dot
}
this->WriteData(data); // write data back to display
this->Release();
}

/**
Expand Down Expand Up @@ -111,6 +115,9 @@ void glcd_Device::SetPixels(uint8_t x, uint8_t y, uint8_t x2, uint8_t y2,
}
mask <<= pageOffset;

if (this->Acquire() != pdTRUE)
return;

this->GotoXY(x, y);
for (i = 0; i < width; i++) {
data = this->ReadData();
Expand Down Expand Up @@ -150,6 +157,7 @@ void glcd_Device::SetPixels(uint8_t x, uint8_t y, uint8_t x2, uint8_t y2,
this->WriteData(data);
}
}
this->Release();
}

/*
Expand Down
9 changes: 7 additions & 2 deletions hardware/emfcamp/sam/libraries/GLCD/glcd_Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ class glcd_Device : public Print {
public:
glcd_Device();
void WaitForUpdate(void);
uint8_t ReadData(void);
void WriteData(uint8_t);
void Init();
void Display();
uint8_t CurrentWidth();
Expand All @@ -133,7 +131,14 @@ class glcd_Device : public Print {
void SetDot(uint8_t x, uint8_t y, uint8_t color);
void SetPixels(uint8_t x, uint8_t y, uint8_t x1, uint8_t y1, uint8_t color);

uint8_t Acquire(void);
void Release(void);

// These must only be called after a successful Acquire()
// Screen will only be updated after Release()
void GotoXY(uint8_t x, uint8_t y);
uint8_t ReadData(void);
void WriteData(uint8_t);
};

#endif
62 changes: 25 additions & 37 deletions hardware/emfcamp/sam/libraries/GLCD/st7565.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ void glcd_Device::_updateDisplay() {
}
}

// Must Acquire() mutex before this is called
void glcd_Device::GotoXY(uint8_t x, uint8_t y) {
if ((x > this->CurrentWidth() - 1) ||
(y > this->CurrentHeight() - 1)) // exit if coordinates are not legal
Expand All @@ -328,34 +329,17 @@ void glcd_Device::GotoXY(uint8_t x, uint8_t y) {
_y = y;
}

// Never call this directly, as it has no mutex
uint8_t glcd_Device::_do_ReadData() {
// Must Acquire() mutex before you call this
uint8_t glcd_Device::ReadData() {
if (_x >= this->CurrentWidth()) {
return (0);
}
// Read from the frame buffer
return this->_framebuffer[_y /8 * this->CurrentWidth() + _x];
}

uint8_t glcd_Device::ReadData() {
uint8_t data;
if (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) {
if (frameBufferMutex == 0) {
frameBufferMutex = xSemaphoreCreateMutex();
}
if (xSemaphoreTake(frameBufferMutex, (TickType_t)100) == pdTRUE) {
data = _do_ReadData();
xSemaphoreGive(frameBufferMutex);
return data;
} else {
}
} else {
return _do_ReadData();
}
}

// Never call this directly, as it has no mutex
void glcd_Device::_do_WriteData(uint8_t data) {
// Must Acquire() mutex before you call this
void glcd_Device::WriteData(uint8_t data) {
uint8_t displayData, yOffset, chip;
uint8_t current_width = this->CurrentWidth();
if (_x >= current_width) {
Expand Down Expand Up @@ -405,22 +389,6 @@ void glcd_Device::_do_WriteData(uint8_t data) {
}
}

void glcd_Device::WriteData(uint8_t data) {
if (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) {
if (frameBufferMutex == 0) {
frameBufferMutex = xSemaphoreCreateMutex();
}
if (xSemaphoreTake(frameBufferMutex, (TickType_t)100) == pdTRUE) {
_do_WriteData(data);
xSemaphoreGive(frameBufferMutex);
} else {
}
} else {
_do_WriteData(data);
}
_updateDisplay();
}

void glcd_Device::WaitForUpdate() {
uint8_t discard;
if (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) {
Expand Down Expand Up @@ -471,3 +439,23 @@ void glcd_Device::SetRotation(rotation_t rotation)
{
_rotation = rotation;
}

uint8_t glcd_Device::Acquire(void)
{
if (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) {
if (frameBufferMutex == 0) {
frameBufferMutex = xSemaphoreCreateMutex();
}
return xSemaphoreTake(frameBufferMutex, (TickType_t)100);
} else {
return pdTRUE;
}
}

void glcd_Device::Release(void)
{
if (frameBufferMutex != 0) {
xSemaphoreGive(frameBufferMutex);
}
_updateDisplay();
}