A basic graphics package for the LPC4088 Display Module.

Dependents:   lpc4088_displaymodule_demo_sphere sampleGUI sampleEmptyGUI lpc4088_displaymodule_fs_aid ... more

Fork of DMBasicGUI by EmbeddedArtists AB

Committer:
embeddedartists
Date:
Wed Oct 23 06:59:53 2019 +0000
Revision:
21:0038059e3a8f
Parent:
17:6e2abf107800
Child:
22:f0d00f29bfeb
Updates related to mbed OS 5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 5:f4de114c31c3 1 /*
embeddedartists 5:f4de114c31c3 2 * Copyright 2014 Embedded Artists AB
embeddedartists 5:f4de114c31c3 3 *
embeddedartists 5:f4de114c31c3 4 * Licensed under the Apache License, Version 2.0 (the "License");
embeddedartists 5:f4de114c31c3 5 * you may not use this file except in compliance with the License.
embeddedartists 5:f4de114c31c3 6 * You may obtain a copy of the License at
embeddedartists 5:f4de114c31c3 7 *
embeddedartists 5:f4de114c31c3 8 * http://www.apache.org/licenses/LICENSE-2.0
embeddedartists 5:f4de114c31c3 9 *
embeddedartists 5:f4de114c31c3 10 * Unless required by applicable law or agreed to in writing, software
embeddedartists 5:f4de114c31c3 11 * distributed under the License is distributed on an "AS IS" BASIS,
embeddedartists 5:f4de114c31c3 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
embeddedartists 5:f4de114c31c3 13 * See the License for the specific language governing permissions and
embeddedartists 5:f4de114c31c3 14 * limitations under the License.
embeddedartists 5:f4de114c31c3 15 */
embeddedartists 5:f4de114c31c3 16
embeddedartists 5:f4de114c31c3 17
embeddedartists 5:f4de114c31c3 18 #include "mbed.h"
embeddedartists 5:f4de114c31c3 19 #include "AppSlideShow.h"
embeddedartists 17:6e2abf107800 20
embeddedartists 5:f4de114c31c3 21
embeddedartists 5:f4de114c31c3 22 /******************************************************************************
embeddedartists 5:f4de114c31c3 23 * Defines and typedefs
embeddedartists 5:f4de114c31c3 24 *****************************************************************************/
embeddedartists 5:f4de114c31c3 25
embeddedartists 5:f4de114c31c3 26 #define TICKER_RESOLUTION_IN_MS 10
embeddedartists 5:f4de114c31c3 27
embeddedartists 11:265884fa7fdd 28 #define BTN_OFF 20
embeddedartists 11:265884fa7fdd 29
embeddedartists 5:f4de114c31c3 30 /******************************************************************************
embeddedartists 5:f4de114c31c3 31 * Global variables
embeddedartists 5:f4de114c31c3 32 *****************************************************************************/
embeddedartists 5:f4de114c31c3 33
embeddedartists 5:f4de114c31c3 34 volatile uint32_t msTicks = 0;
embeddedartists 5:f4de114c31c3 35
embeddedartists 5:f4de114c31c3 36 /******************************************************************************
embeddedartists 5:f4de114c31c3 37 * Private functions
embeddedartists 5:f4de114c31c3 38 *****************************************************************************/
embeddedartists 5:f4de114c31c3 39
embeddedartists 5:f4de114c31c3 40 static void tRender(void const *args)
embeddedartists 5:f4de114c31c3 41 {
embeddedartists 5:f4de114c31c3 42 Renderer* s = (Renderer*)args;
embeddedartists 5:f4de114c31c3 43 s->render();
embeddedartists 5:f4de114c31c3 44 }
embeddedartists 5:f4de114c31c3 45
embeddedartists 5:f4de114c31c3 46 static void ticker(void const *n) {
embeddedartists 5:f4de114c31c3 47 msTicks += TICKER_RESOLUTION_IN_MS;
embeddedartists 5:f4de114c31c3 48 }
embeddedartists 5:f4de114c31c3 49
embeddedartists 11:265884fa7fdd 50 static void buttonClicked(uint32_t x)
embeddedartists 11:265884fa7fdd 51 {
embeddedartists 11:265884fa7fdd 52 bool* done = (bool*)x;
embeddedartists 11:265884fa7fdd 53 *done = true;
embeddedartists 11:265884fa7fdd 54 }
embeddedartists 11:265884fa7fdd 55
embeddedartists 5:f4de114c31c3 56 /******************************************************************************
embeddedartists 5:f4de114c31c3 57 * Public functions
embeddedartists 5:f4de114c31c3 58 *****************************************************************************/
embeddedartists 5:f4de114c31c3 59
embeddedartists 11:265884fa7fdd 60 AppSlideShow::AppSlideShow(const char* scriptFile, const char* pathPrefix, int xoff, int yoff) :
embeddedartists 11:265884fa7fdd 61 _fb(NULL), _disp(NULL), _show(NULL), _rend(NULL),
embeddedartists 11:265884fa7fdd 62 _fileMutex(), _btnDone(NULL), _btnRepeat(NULL), _script(NULL), _path(NULL)
embeddedartists 5:f4de114c31c3 63 {
embeddedartists 11:265884fa7fdd 64 _script = (char*)malloc(strlen(scriptFile)+1);
embeddedartists 11:265884fa7fdd 65 if (_script != NULL) {
embeddedartists 11:265884fa7fdd 66 strcpy(_script, scriptFile);
embeddedartists 11:265884fa7fdd 67 }
embeddedartists 11:265884fa7fdd 68 if (pathPrefix != NULL) {
embeddedartists 11:265884fa7fdd 69 _path = (char*)malloc(strlen(pathPrefix)+1);
embeddedartists 11:265884fa7fdd 70 if (_path != NULL) {
embeddedartists 11:265884fa7fdd 71 strcpy(_path, pathPrefix);
embeddedartists 11:265884fa7fdd 72 }
embeddedartists 11:265884fa7fdd 73 }
embeddedartists 11:265884fa7fdd 74 _xoff = xoff;
embeddedartists 11:265884fa7fdd 75 _yoff = yoff;
embeddedartists 5:f4de114c31c3 76 }
embeddedartists 5:f4de114c31c3 77
embeddedartists 5:f4de114c31c3 78 AppSlideShow::~AppSlideShow()
embeddedartists 5:f4de114c31c3 79 {
embeddedartists 5:f4de114c31c3 80 teardown();
embeddedartists 5:f4de114c31c3 81 }
embeddedartists 5:f4de114c31c3 82
embeddedartists 5:f4de114c31c3 83 bool AppSlideShow::setup()
embeddedartists 5:f4de114c31c3 84 {
embeddedartists 5:f4de114c31c3 85 SlideShow::SlideShowError err;
embeddedartists 5:f4de114c31c3 86
embeddedartists 5:f4de114c31c3 87 _disp = DMBoard::instance().display();
embeddedartists 5:f4de114c31c3 88
embeddedartists 5:f4de114c31c3 89 _fb = _disp->allocateFramebuffer();
embeddedartists 5:f4de114c31c3 90 if (_fb == NULL) {
embeddedartists 5:f4de114c31c3 91 err = SlideShow::OutOfMemory;
embeddedartists 5:f4de114c31c3 92 } else {
embeddedartists 5:f4de114c31c3 93 memset(_fb, 0xff, _disp->fbSize());
embeddedartists 5:f4de114c31c3 94 _rend = new Renderer();
embeddedartists 13:bff2288c2c61 95 _show = new SlideShow(_rend, _path, _xoff, _yoff, 1, &_fileMutex);
embeddedartists 11:265884fa7fdd 96 err = _show->prepare(_script);
embeddedartists 5:f4de114c31c3 97 }
embeddedartists 5:f4de114c31c3 98
embeddedartists 17:6e2abf107800 99 _btnRepeat = new ImageButton((COLOR_T*)_fb, _disp->width() - 2*BTN_OFF - _resOk->width() - _resRepeat->width(), _disp->height() - BTN_OFF - _resRepeat->height(), _resRepeat->width(), _resRepeat->height());
embeddedartists 17:6e2abf107800 100 _btnRepeat->loadImages(_resRepeat);
embeddedartists 17:6e2abf107800 101 _btnDone = new ImageButton((COLOR_T*)_fb, _disp->width() - BTN_OFF - _resOk->width(), _disp->height() - BTN_OFF - _resOk->height(), _resOk->width(), _resOk->height());
embeddedartists 17:6e2abf107800 102 _btnDone->loadImages(_resOk);
embeddedartists 11:265884fa7fdd 103
embeddedartists 5:f4de114c31c3 104 return (err == SlideShow::Ok);
embeddedartists 5:f4de114c31c3 105 }
embeddedartists 5:f4de114c31c3 106
embeddedartists 5:f4de114c31c3 107 void AppSlideShow::runToCompletion()
embeddedartists 5:f4de114c31c3 108 {
embeddedartists 5:f4de114c31c3 109 // Save existing frame buffer
embeddedartists 5:f4de114c31c3 110 void* oldFB = _disp->swapFramebuffer(_fb);
embeddedartists 5:f4de114c31c3 111
embeddedartists 11:265884fa7fdd 112 bool done = false;
embeddedartists 11:265884fa7fdd 113 bool repeat = false;
embeddedartists 11:265884fa7fdd 114 _btnDone->setAction(buttonClicked, (uint32_t)&done);
embeddedartists 11:265884fa7fdd 115 _btnRepeat->setAction(buttonClicked, (uint32_t)&repeat);
embeddedartists 11:265884fa7fdd 116
embeddedartists 11:265884fa7fdd 117
embeddedartists 5:f4de114c31c3 118 // Alternative 1: use the calling thread's context to run in
embeddedartists 21:0038059e3a8f 119 //Thread tr(tRender, _rend, osPriorityHigh);
embeddedartists 21:0038059e3a8f 120 Thread tr;
embeddedartists 21:0038059e3a8f 121 tr.start(callback(tRender, _rend));
embeddedartists 5:f4de114c31c3 122
embeddedartists 5:f4de114c31c3 123 // Generate the millisecond ticks for the slideshow
embeddedartists 21:0038059e3a8f 124 //RtosTimer rtosTimer(ticker, osTimerPeriodic);
embeddedartists 21:0038059e3a8f 125 //rtosTimer.start(TICKER_RESOLUTION_IN_MS);
embeddedartists 21:0038059e3a8f 126 EventQueue rtosTimer(4*EVENTS_EVENT_SIZE);
embeddedartists 21:0038059e3a8f 127 rtosTimer.call_every(TICKER_RESOLUTION_IN_MS, ticker, &done);
embeddedartists 21:0038059e3a8f 128 rtosTimer.dispatch(0);
embeddedartists 5:f4de114c31c3 129
embeddedartists 11:265884fa7fdd 130 // Wait for touches
embeddedartists 11:265884fa7fdd 131 TouchPanel* touch = DMBoard::instance().touchPanel();
embeddedartists 11:265884fa7fdd 132 touch_coordinate_t coord;
embeddedartists 11:265884fa7fdd 133
embeddedartists 11:265884fa7fdd 134 do {
embeddedartists 5:f4de114c31c3 135 // Wait for slideshow to complete
embeddedartists 5:f4de114c31c3 136 _show->run();
embeddedartists 11:265884fa7fdd 137
embeddedartists 11:265884fa7fdd 138 // Temporary ugly way to get current framebuffer
embeddedartists 11:265884fa7fdd 139 _btnDone->draw((COLOR_T*)LPC_LCD->UPBASE);
embeddedartists 11:265884fa7fdd 140 _btnRepeat->draw((COLOR_T*)LPC_LCD->UPBASE);
embeddedartists 11:265884fa7fdd 141
embeddedartists 11:265884fa7fdd 142 done = repeat = false;
embeddedartists 11:265884fa7fdd 143 while (!done && !repeat) {
embeddedartists 21:0038059e3a8f 144 ThisThread::flags_wait_any(0x1);
embeddedartists 11:265884fa7fdd 145 if (touch->read(coord) == TouchPanel::TouchError_Ok) {
embeddedartists 11:265884fa7fdd 146 if (_btnDone->handle(coord.x, coord.y, coord.z > 0)) {
embeddedartists 11:265884fa7fdd 147 _btnDone->draw();
embeddedartists 11:265884fa7fdd 148 }
embeddedartists 11:265884fa7fdd 149 if (_btnRepeat->handle(coord.x, coord.y, coord.z > 0)) {
embeddedartists 11:265884fa7fdd 150 _btnRepeat->draw();
embeddedartists 11:265884fa7fdd 151 }
embeddedartists 11:265884fa7fdd 152 }
embeddedartists 11:265884fa7fdd 153 }
embeddedartists 11:265884fa7fdd 154
embeddedartists 11:265884fa7fdd 155 } while(!done);
embeddedartists 5:f4de114c31c3 156
embeddedartists 5:f4de114c31c3 157 tr.terminate();
embeddedartists 5:f4de114c31c3 158
embeddedartists 5:f4de114c31c3 159 // Restore the original FB
embeddedartists 5:f4de114c31c3 160 _disp->swapFramebuffer(oldFB);
embeddedartists 5:f4de114c31c3 161 }
embeddedartists 5:f4de114c31c3 162
embeddedartists 5:f4de114c31c3 163 bool AppSlideShow::teardown()
embeddedartists 5:f4de114c31c3 164 {
embeddedartists 5:f4de114c31c3 165 if (_show != NULL) {
embeddedartists 5:f4de114c31c3 166 free(_show);
embeddedartists 5:f4de114c31c3 167 _show = NULL;
embeddedartists 5:f4de114c31c3 168 }
embeddedartists 5:f4de114c31c3 169 if (_rend != NULL) {
embeddedartists 5:f4de114c31c3 170 free(_rend);
embeddedartists 5:f4de114c31c3 171 _rend = NULL;
embeddedartists 5:f4de114c31c3 172 }
embeddedartists 5:f4de114c31c3 173 if (_fb != NULL) {
embeddedartists 5:f4de114c31c3 174 free(_fb);
embeddedartists 5:f4de114c31c3 175 _fb = NULL;
embeddedartists 5:f4de114c31c3 176 }
embeddedartists 11:265884fa7fdd 177 if (_script != NULL) {
embeddedartists 11:265884fa7fdd 178 free(_script);
embeddedartists 11:265884fa7fdd 179 _script = NULL;
embeddedartists 11:265884fa7fdd 180 }
embeddedartists 11:265884fa7fdd 181 if (_path != NULL) {
embeddedartists 11:265884fa7fdd 182 free(_path);
embeddedartists 11:265884fa7fdd 183 _path = NULL;
embeddedartists 11:265884fa7fdd 184 }
embeddedartists 5:f4de114c31c3 185 return true;
embeddedartists 5:f4de114c31c3 186 }
embeddedartists 5:f4de114c31c3 187
embeddedartists 5:f4de114c31c3 188
embeddedartists 17:6e2abf107800 189 void AppSlideShow::addResource(Resources id, Resource* res)
embeddedartists 17:6e2abf107800 190 {
embeddedartists 17:6e2abf107800 191 if (id == Resource_Ok_button) {
embeddedartists 17:6e2abf107800 192 _resOk = res;
embeddedartists 17:6e2abf107800 193 } else {
embeddedartists 17:6e2abf107800 194 _resRepeat = res;
embeddedartists 17:6e2abf107800 195 }
embeddedartists 17:6e2abf107800 196 }
embeddedartists 17:6e2abf107800 197