Skip to content

Commit 1bc6d4d

Browse files
authored
ST7735 driver fix for screen hanging. (#186)
* Fix for the microbit-app hanging issue * renamed displayIsFree to inProgressLock. Removed inProgress since it is no longer neccessary on account of inProgressLock, removed temporary comments that commented out code.
1 parent 8c8366f commit 1bc6d4d

2 files changed

Lines changed: 15 additions & 17 deletions

File tree

inc/drivers/ST7735.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ DEALINGS IN THE SOFTWARE.
2929
#include "SPI.h"
3030
#include "Event.h"
3131
#include "ScreenIO.h"
32+
#include "CodalFiber.h"
3233

3334
namespace codal
3435
{
@@ -52,6 +53,7 @@ class ST7735 : public CodalComponent
5253
uint8_t cmdBuf[20];
5354
ST7735WorkBuffer *work;
5455
bool inSleepMode;
56+
FiberLock inProgressLock;
5557

5658
// if true, every pixel will be plotted as 4 pixels and 16 bit color mode
5759
// will be used; this is for ILI9341 which usually has 320x240 screens
@@ -65,12 +67,12 @@ class ST7735 : public CodalComponent
6567

6668
void sendCmd(uint8_t *buf, int len);
6769
void sendCmdSeq(const uint8_t *buf);
68-
void sendDone(Event);
6970
void sendWords(unsigned numBytes);
7071
void startTransfer(unsigned size);
7172
void sendBytes(unsigned num);
7273
void startRAMWR(int cmd = 0);
7374

75+
static void sendDone(ST7735* st);
7476
static void sendColorsStep(ST7735 *st);
7577

7678
public:

source/drivers/ST7735.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
namespace codal
6666
{
6767

68-
ST7735::ST7735(ScreenIO &io, Pin &cs, Pin &dc) : io(io), cs(&cs), dc(&dc), work(NULL)
68+
ST7735::ST7735(ScreenIO &io, Pin &cs, Pin &dc)
69+
: io(io), cs(&cs), dc(&dc), work(NULL), inProgressLock(1)
6970
{
7071
double16 = false;
7172
inSleepMode = false;
@@ -145,7 +146,6 @@ struct ST7735WorkBuffer
145146
unsigned x;
146147
uint32_t *paletteTable;
147148
unsigned srcLeft;
148-
bool inProgress;
149149
uint32_t expPalette[256];
150150
};
151151

@@ -269,7 +269,7 @@ void ST7735::sendColorsStep(ST7735 *st)
269269
if (work->srcLeft == 0)
270270
{
271271
st->endCS();
272-
Event(DEVICE_ID_DISPLAY, 100);
272+
st->sendDone(st);
273273
}
274274
else
275275
{
@@ -301,19 +301,16 @@ void ST7735::startRAMWR(int cmd)
301301
beginCS();
302302
}
303303

304-
void ST7735::sendDone(Event)
304+
void ST7735::sendDone(ST7735 *st)
305305
{
306-
// this executes outside of interrupt context, so we don't get a race
307-
// with waitForSendDone
308-
work->inProgress = false;
309-
Event(DEVICE_ID_DISPLAY, 101);
306+
st->inProgressLock.notify();
310307
}
311308

312-
void ST7735::waitForSendDone()
313-
{
314-
if (work && work->inProgress)
315-
fiber_wait_for_event(DEVICE_ID_DISPLAY, 101);
316-
}
309+
310+
/**
311+
* Deprecated; no longer neccessary. sendIndexedImage handles this.
312+
*/
313+
void ST7735::waitForSendDone() {}
317314

318315
int ST7735::setSleep(bool sleepMode)
319316
{
@@ -355,15 +352,14 @@ int ST7735::sendIndexedImage(const uint8_t *src, unsigned width, unsigned height
355352
else
356353
for (int i = 0; i < 256; ++i)
357354
work->expPalette[i] = 0x1011 * (i & 0xf) | (0x110100 * (i >> 4));
358-
EventModel::defaultEventBus->listen(DEVICE_ID_DISPLAY, 100, this, &ST7735::sendDone);
359355
}
360356

361-
if (work->inProgress || inSleepMode)
357+
inProgressLock.wait();
358+
if (inSleepMode)
362359
return DEVICE_BUSY;
363360

364361
work->paletteTable = palette;
365362

366-
work->inProgress = true;
367363
work->srcPtr = src;
368364
work->width = width;
369365
work->height = height;

0 commit comments

Comments
 (0)