Example using the support package for LPC4088 DisplayModule

Dependencies:   DMBasicGUI DMSupport

Example using a lot of the features in the software package for the LPC4088 Display Module.

This project can be selected as a template when creating a new project based on the LPC4088 Display Module.

Information

This project works on the 4.3" display modules.

Some of the apps works on the 5" display modules. The ImageViewer and Slideshow app will show the images distorted as it does not take the resolution into consideration.

Information

The USB Status app is disabled. The Image viewer looks for images in the root of SD cards, USB memory sticks or the file system on the QSPI flash. The Slideshow app expects to find a slideshow script in /mci/elec14/ea_logo.txt.

This is what it looks like on the 4.3" display:

/media/uploads/embeddedartists/everything_cap_000.png /media/uploads/embeddedartists/everything_cap_001.png /media/uploads/embeddedartists/everything_cap_003.png /media/uploads/embeddedartists/everything_cap_004.png /media/uploads/embeddedartists/everything_cap_006.png /media/uploads/embeddedartists/everything_cap_008.png

Committer:
alindvall
Date:
Tue Apr 28 11:49:03 2015 +0000
Revision:
29:be8b784873f5
Parent:
26:f07df116f3c9
Child:
30:e1cded731965
Updated to latest version of the DMSupport library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 13:57e65aba9802 1 /*
embeddedartists 13:57e65aba9802 2 * Copyright 2014 Embedded Artists AB
embeddedartists 13:57e65aba9802 3 *
embeddedartists 13:57e65aba9802 4 * Licensed under the Apache License, Version 2.0 (the "License");
embeddedartists 13:57e65aba9802 5 * you may not use this file except in compliance with the License.
embeddedartists 13:57e65aba9802 6 * You may obtain a copy of the License at
embeddedartists 13:57e65aba9802 7 *
embeddedartists 13:57e65aba9802 8 * http://www.apache.org/licenses/LICENSE-2.0
embeddedartists 13:57e65aba9802 9 *
embeddedartists 13:57e65aba9802 10 * Unless required by applicable law or agreed to in writing, software
embeddedartists 13:57e65aba9802 11 * distributed under the License is distributed on an "AS IS" BASIS,
embeddedartists 13:57e65aba9802 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
embeddedartists 13:57e65aba9802 13 * See the License for the specific language governing permissions and
embeddedartists 13:57e65aba9802 14 * limitations under the License.
embeddedartists 13:57e65aba9802 15 */
embeddedartists 13:57e65aba9802 16
embeddedartists 13:57e65aba9802 17
embeddedartists 13:57e65aba9802 18 #include "mbed.h"
embeddedartists 13:57e65aba9802 19 #include "EthernetInterface.h"
embeddedartists 13:57e65aba9802 20 #include "AppStatus.h"
embeddedartists 13:57e65aba9802 21 #include "lpc_swim_font.h"
embeddedartists 13:57e65aba9802 22 #include "image_data.h"
embeddedartists 13:57e65aba9802 23
embeddedartists 13:57e65aba9802 24 /******************************************************************************
embeddedartists 13:57e65aba9802 25 * Defines and typedefs
embeddedartists 13:57e65aba9802 26 *****************************************************************************/
embeddedartists 13:57e65aba9802 27
embeddedartists 13:57e65aba9802 28 #define HEADER_X_OFF 20
embeddedartists 13:57e65aba9802 29 #define HEADER_Y_SPACING 20
embeddedartists 13:57e65aba9802 30 #define ITEM_CAPTION_X_OFF 40
embeddedartists 13:57e65aba9802 31 #define ITEM_CAPTION_Y_SPACING (swim_get_font_height(_win) + 5)
embeddedartists 13:57e65aba9802 32 #define ITEM_VALUE_X_OFF 140
embeddedartists 13:57e65aba9802 33 #define COL3_OFF 230
embeddedartists 13:57e65aba9802 34
embeddedartists 13:57e65aba9802 35 #define BTN_WIDTH 40
embeddedartists 13:57e65aba9802 36 #define BTN_HEIGHT 40
embeddedartists 13:57e65aba9802 37 #define BTN_OFF 20
embeddedartists 13:57e65aba9802 38
embeddedartists 13:57e65aba9802 39 /******************************************************************************
embeddedartists 13:57e65aba9802 40 * Global variables
embeddedartists 13:57e65aba9802 41 *****************************************************************************/
embeddedartists 13:57e65aba9802 42
embeddedartists 26:f07df116f3c9 43 #if defined(DM_BOARD_USE_ETHERNET)
embeddedartists 26:f07df116f3c9 44 extern EthernetInterface eth;
embeddedartists 26:f07df116f3c9 45 extern bool ethInitialized;
embeddedartists 26:f07df116f3c9 46 extern bool ethUsingDHCP;
embeddedartists 26:f07df116f3c9 47 #endif
embeddedartists 13:57e65aba9802 48
embeddedartists 13:57e65aba9802 49 /******************************************************************************
embeddedartists 13:57e65aba9802 50 * Private functions
embeddedartists 13:57e65aba9802 51 *****************************************************************************/
embeddedartists 13:57e65aba9802 52
embeddedartists 13:57e65aba9802 53 static void buttonClicked(uint32_t x)
embeddedartists 13:57e65aba9802 54 {
embeddedartists 13:57e65aba9802 55 bool* done = (bool*)x;
embeddedartists 13:57e65aba9802 56 *done = true;
embeddedartists 13:57e65aba9802 57 }
embeddedartists 13:57e65aba9802 58
embeddedartists 13:57e65aba9802 59 void AppStatus::draw()
embeddedartists 13:57e65aba9802 60 {
embeddedartists 13:57e65aba9802 61 // Prepare fullscreen
embeddedartists 13:57e65aba9802 62 swim_window_open(_win,
embeddedartists 13:57e65aba9802 63 _disp->width(), _disp->height(), // full size
embeddedartists 13:57e65aba9802 64 (COLOR_T*)_fb,
embeddedartists 13:57e65aba9802 65 0,0,_disp->width()-1, _disp->height()-1, // window position and size
embeddedartists 13:57e65aba9802 66 1, // border
embeddedartists 13:57e65aba9802 67 WHITE, BLUE, BLACK); // colors: pen, backgr, forgr
embeddedartists 13:57e65aba9802 68 swim_set_title(_win, "Application Status", BLACK);
embeddedartists 13:57e65aba9802 69
embeddedartists 13:57e65aba9802 70 char buff[120];
embeddedartists 13:57e65aba9802 71
embeddedartists 13:57e65aba9802 72 // Column 1
embeddedartists 13:57e65aba9802 73 swim_put_text_xy(_win, "Ethernet:", HEADER_X_OFF, HEADER_Y_SPACING);
embeddedartists 13:57e65aba9802 74 swim_put_text_xy(_win, "IP Address:", ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 1);
embeddedartists 13:57e65aba9802 75 swim_put_text_xy(_win, "NetMask:", ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 2);
embeddedartists 13:57e65aba9802 76 swim_put_text_xy(_win, "Gateway Address:", ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 3);
embeddedartists 13:57e65aba9802 77 swim_put_text_xy(_win, "MAC Address:", ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 4);
embeddedartists 13:57e65aba9802 78 swim_put_text_xy(_win, "DHCP/Static IP:", ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 5);
embeddedartists 13:57e65aba9802 79
embeddedartists 13:57e65aba9802 80 // Column 2
embeddedartists 26:f07df116f3c9 81 #if defined(DM_BOARD_USE_ETHERNET)
embeddedartists 13:57e65aba9802 82 if (ethInitialized) {
embeddedartists 13:57e65aba9802 83 swim_put_text_xy(_win, eth.getIPAddress(), ITEM_VALUE_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 1);
embeddedartists 13:57e65aba9802 84 swim_put_text_xy(_win, eth.getNetworkMask(), ITEM_VALUE_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 2);
embeddedartists 13:57e65aba9802 85 swim_put_text_xy(_win, eth.getGateway(), ITEM_VALUE_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 3);
embeddedartists 13:57e65aba9802 86 swim_put_text_xy(_win, eth.getMACAddress(), ITEM_VALUE_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 4);
embeddedartists 13:57e65aba9802 87 swim_put_text_xy(_win, ethUsingDHCP?"DHCP":"Static IP", ITEM_VALUE_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 5);
embeddedartists 13:57e65aba9802 88 } else {
embeddedartists 26:f07df116f3c9 89 #else
embeddedartists 26:f07df116f3c9 90 {
embeddedartists 26:f07df116f3c9 91 #endif
embeddedartists 13:57e65aba9802 92 swim_put_text_xy(_win, "Not Initialized", ITEM_VALUE_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 1);
embeddedartists 13:57e65aba9802 93 swim_put_text_xy(_win, "Not Initialized", ITEM_VALUE_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 2);
embeddedartists 13:57e65aba9802 94 swim_put_text_xy(_win, "Not Initialized", ITEM_VALUE_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 3);
embeddedartists 20:45ae832249d0 95 char mac[6];
embeddedartists 20:45ae832249d0 96 mbed_mac_address(mac);
embeddedartists 20:45ae832249d0 97 snprintf(buff, 19, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
embeddedartists 20:45ae832249d0 98 swim_put_text_xy(_win, buff, ITEM_VALUE_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 4);
embeddedartists 13:57e65aba9802 99 swim_put_text_xy(_win, "Not Initialized", ITEM_VALUE_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 5);
embeddedartists 13:57e65aba9802 100 }
embeddedartists 13:57e65aba9802 101
embeddedartists 13:57e65aba9802 102 // Column 3
embeddedartists 13:57e65aba9802 103 swim_put_text_xy(_win, "Display:", COL3_OFF+HEADER_X_OFF, HEADER_Y_SPACING);
embeddedartists 13:57e65aba9802 104 swim_put_text_xy(_win, "Size:", COL3_OFF+ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 1);
embeddedartists 13:57e65aba9802 105 swim_put_text_xy(_win, "Resolutions:", COL3_OFF+ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 2);
embeddedartists 13:57e65aba9802 106 swim_put_text_xy(_win, " 16bit RGB565:", COL3_OFF+ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 3);
embeddedartists 13:57e65aba9802 107 swim_put_text_xy(_win, " 18bit RGB666:", COL3_OFF+ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 4);
embeddedartists 13:57e65aba9802 108 swim_put_text_xy(_win, " 24bit RGB888:", COL3_OFF+ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 5);
embeddedartists 13:57e65aba9802 109 swim_put_text_xy(_win, "Landscape:", COL3_OFF+ITEM_CAPTION_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 6);
embeddedartists 13:57e65aba9802 110
embeddedartists 13:57e65aba9802 111 // Column 4
embeddedartists 13:57e65aba9802 112 sprintf(buff, "%d x %d pixels", _disp->width(), _disp->height());
embeddedartists 13:57e65aba9802 113 swim_put_text_xy(_win, buff, COL3_OFF+ITEM_VALUE_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 1);
embeddedartists 13:57e65aba9802 114
embeddedartists 13:57e65aba9802 115 sprintf(buff, "%s %s", _disp->isSupported(Display::Resolution_16bit_rgb565)?"Supported":"N/A", _disp->currentResolution()==Display::Resolution_16bit_rgb565?" (Active)":"");
embeddedartists 13:57e65aba9802 116 swim_put_text_xy(_win, buff, COL3_OFF+ITEM_VALUE_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 3);
embeddedartists 13:57e65aba9802 117
embeddedartists 13:57e65aba9802 118 sprintf(buff, "%s %s", _disp->isSupported(Display::Resolution_18bit_rgb666)?"Supported":"N/A", _disp->currentResolution()==Display::Resolution_18bit_rgb666?" (Active)":"");
embeddedartists 13:57e65aba9802 119 swim_put_text_xy(_win, buff, COL3_OFF+ITEM_VALUE_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 4);
embeddedartists 13:57e65aba9802 120
embeddedartists 13:57e65aba9802 121 sprintf(buff, "%s %s", _disp->isSupported(Display::Resolution_24bit_rgb888)?"Supported":"N/A", _disp->currentResolution()==Display::Resolution_24bit_rgb888?" (Active)":"");
embeddedartists 13:57e65aba9802 122 swim_put_text_xy(_win, buff, COL3_OFF+ITEM_VALUE_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 5);
embeddedartists 13:57e65aba9802 123
embeddedartists 13:57e65aba9802 124 sprintf(buff, "%s", _disp->landscape()?"YES":"NO");
embeddedartists 13:57e65aba9802 125 swim_put_text_xy(_win, buff, COL3_OFF+ITEM_VALUE_X_OFF, HEADER_Y_SPACING + ITEM_CAPTION_Y_SPACING * 6);
embeddedartists 13:57e65aba9802 126
embeddedartists 13:57e65aba9802 127 _btn = new ImageButton(_win->fb, _win->xpmax - BTN_OFF - BTN_WIDTH, _win->ypmax - BTN_OFF - BTN_HEIGHT, BTN_WIDTH, BTN_HEIGHT);
embeddedartists 13:57e65aba9802 128 _btn->loadImages(img_ok, img_size_ok);
embeddedartists 13:57e65aba9802 129 _btn->draw();
embeddedartists 13:57e65aba9802 130 }
embeddedartists 13:57e65aba9802 131
embeddedartists 13:57e65aba9802 132 /******************************************************************************
embeddedartists 13:57e65aba9802 133 * Public functions
embeddedartists 13:57e65aba9802 134 *****************************************************************************/
embeddedartists 13:57e65aba9802 135
embeddedartists 13:57e65aba9802 136 AppStatus::AppStatus() : _disp(NULL), _win(NULL), _fb(NULL), _btn(NULL)
embeddedartists 13:57e65aba9802 137 {
embeddedartists 13:57e65aba9802 138 }
embeddedartists 13:57e65aba9802 139
embeddedartists 13:57e65aba9802 140 AppStatus::~AppStatus()
embeddedartists 13:57e65aba9802 141 {
embeddedartists 13:57e65aba9802 142 teardown();
embeddedartists 13:57e65aba9802 143 }
embeddedartists 13:57e65aba9802 144
embeddedartists 13:57e65aba9802 145 bool AppStatus::setup()
embeddedartists 13:57e65aba9802 146 {
embeddedartists 13:57e65aba9802 147 _disp = DMBoard::instance().display();
embeddedartists 13:57e65aba9802 148 _win = (SWIM_WINDOW_T*)malloc(sizeof(SWIM_WINDOW_T));
embeddedartists 13:57e65aba9802 149 _fb = _disp->allocateFramebuffer();
embeddedartists 13:57e65aba9802 150
embeddedartists 13:57e65aba9802 151 return (_win != NULL && _fb != NULL);
embeddedartists 13:57e65aba9802 152 }
embeddedartists 13:57e65aba9802 153
embeddedartists 13:57e65aba9802 154 void AppStatus::runToCompletion()
embeddedartists 13:57e65aba9802 155 {
embeddedartists 13:57e65aba9802 156 // Alternative 1: use the calling thread's context to run in
embeddedartists 13:57e65aba9802 157 bool done = false;
embeddedartists 13:57e65aba9802 158 draw();
embeddedartists 13:57e65aba9802 159 _btn->setAction(buttonClicked, (uint32_t)&done);
embeddedartists 13:57e65aba9802 160 void* oldFB = _disp->swapFramebuffer(_fb);
embeddedartists 13:57e65aba9802 161
embeddedartists 16:77f4f42eb6a7 162 // Wait for touches, but the AppLauncher is already listening
embeddedartists 16:77f4f42eb6a7 163 // for new touch event and sends a signal to its thread which
embeddedartists 16:77f4f42eb6a7 164 // is the same as runs this function so it is enough to wait
embeddedartists 16:77f4f42eb6a7 165 // for that signal.
embeddedartists 13:57e65aba9802 166 TouchPanel* touch = DMBoard::instance().touchPanel();
embeddedartists 16:77f4f42eb6a7 167 touch_coordinate_t coord;
embeddedartists 13:57e65aba9802 168 while(!done) {
embeddedartists 16:77f4f42eb6a7 169 Thread::signal_wait(0x1);
embeddedartists 13:57e65aba9802 170 if (touch->read(coord) == TouchPanel::TouchError_Ok) {
embeddedartists 13:57e65aba9802 171 if (_btn->handle(coord.x, coord.y, coord.z > 0)) {
embeddedartists 13:57e65aba9802 172 _btn->draw();
embeddedartists 13:57e65aba9802 173 }
embeddedartists 13:57e65aba9802 174 }
embeddedartists 13:57e65aba9802 175 }
embeddedartists 13:57e65aba9802 176
embeddedartists 13:57e65aba9802 177 // User has clicked the button, restore the original FB
embeddedartists 13:57e65aba9802 178 _disp->swapFramebuffer(oldFB);
embeddedartists 13:57e65aba9802 179 swim_window_close(_win);
embeddedartists 13:57e65aba9802 180 }
embeddedartists 13:57e65aba9802 181
embeddedartists 13:57e65aba9802 182 bool AppStatus::teardown()
embeddedartists 13:57e65aba9802 183 {
embeddedartists 13:57e65aba9802 184 if (_win != NULL) {
embeddedartists 13:57e65aba9802 185 free(_win);
embeddedartists 13:57e65aba9802 186 _win = NULL;
embeddedartists 13:57e65aba9802 187 }
embeddedartists 13:57e65aba9802 188 if (_fb != NULL) {
embeddedartists 13:57e65aba9802 189 free(_fb);
embeddedartists 13:57e65aba9802 190 _fb = NULL;
embeddedartists 13:57e65aba9802 191 }
embeddedartists 13:57e65aba9802 192 if (_btn != NULL) {
embeddedartists 13:57e65aba9802 193 delete _btn;
embeddedartists 13:57e65aba9802 194 _btn = NULL;
embeddedartists 13:57e65aba9802 195 }
embeddedartists 13:57e65aba9802 196 return true;
embeddedartists 13:57e65aba9802 197 }
embeddedartists 13:57e65aba9802 198
embeddedartists 13:57e65aba9802 199