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:
embeddedartists
Date:
Fri Dec 19 08:24:09 2014 +0000
Revision:
4:37a60b9bdb99
Parent:
3:4301d34173cf
Child:
6:8007691f78dc
Updated with BIOS support

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:dfad71908d59 1 /******************************************************************************
embeddedartists 0:dfad71908d59 2 * Includes
embeddedartists 0:dfad71908d59 3 *****************************************************************************/
embeddedartists 0:dfad71908d59 4
embeddedartists 0:dfad71908d59 5 #include "mbed.h"
embeddedartists 0:dfad71908d59 6 #include "mbed_interface.h"
embeddedartists 0:dfad71908d59 7 #include "rtos.h"
embeddedartists 0:dfad71908d59 8 #include "EthernetInterface.h"
embeddedartists 0:dfad71908d59 9 #include "HTTPServer.h"
embeddedartists 0:dfad71908d59 10 #include "mbed_rpc.h"
embeddedartists 0:dfad71908d59 11 #include "USBHostMSD.h"
embeddedartists 1:15ea03d72dd7 12 #include "USBHostMouse.h"
embeddedartists 1:15ea03d72dd7 13 #include "USBHostKeyboard.h"
embeddedartists 0:dfad71908d59 14
embeddedartists 0:dfad71908d59 15 #include "DMBoard.h"
embeddedartists 0:dfad71908d59 16
embeddedartists 2:070e9c054796 17 #include "AppLauncher.h"
embeddedartists 2:070e9c054796 18 #include "meas.h"
embeddedartists 2:070e9c054796 19
embeddedartists 2:070e9c054796 20
embeddedartists 0:dfad71908d59 21 /******************************************************************************
embeddedartists 0:dfad71908d59 22 * Typedefs and defines
embeddedartists 0:dfad71908d59 23 *****************************************************************************/
embeddedartists 0:dfad71908d59 24
embeddedartists 0:dfad71908d59 25 /* Number of colors in 565 mode */
embeddedartists 0:dfad71908d59 26 #define NUM_COLORS 65536
embeddedartists 0:dfad71908d59 27 /* Number of red colors in 565 mode */
embeddedartists 0:dfad71908d59 28 #define RED_COLORS 0x20
embeddedartists 0:dfad71908d59 29 /* Number of green colors in 565 mode */
embeddedartists 0:dfad71908d59 30 #define GREEN_COLORS 0x40
embeddedartists 0:dfad71908d59 31 /* Number of blue colors in 565 mode */
embeddedartists 0:dfad71908d59 32 #define BLUE_COLORS 0x20
embeddedartists 0:dfad71908d59 33 /* Black color, 565 mode */
embeddedartists 0:dfad71908d59 34 #define BLACK 0x0000
embeddedartists 0:dfad71908d59 35
embeddedartists 0:dfad71908d59 36 /******************************************************************************
embeddedartists 0:dfad71908d59 37 * Local variables
embeddedartists 0:dfad71908d59 38 *****************************************************************************/
embeddedartists 0:dfad71908d59 39
embeddedartists 1:15ea03d72dd7 40 Mutex usbInitGuard;
embeddedartists 0:dfad71908d59 41
embeddedartists 0:dfad71908d59 42 /******************************************************************************
embeddedartists 0:dfad71908d59 43 * Global variables
embeddedartists 0:dfad71908d59 44 *****************************************************************************/
embeddedartists 0:dfad71908d59 45
embeddedartists 2:070e9c054796 46 EthernetInterface eth;
embeddedartists 2:070e9c054796 47 bool ethInitialized = false;
embeddedartists 2:070e9c054796 48 bool ethUsingDHCP = true;
embeddedartists 4:37a60b9bdb99 49 bool haveUSBMSD = false;
embeddedartists 2:070e9c054796 50
embeddedartists 0:dfad71908d59 51 /******************************************************************************
embeddedartists 0:dfad71908d59 52 * Local functions
embeddedartists 0:dfad71908d59 53 *****************************************************************************/
embeddedartists 0:dfad71908d59 54
embeddedartists 0:dfad71908d59 55 static void verticalLine16(uint16_t* framebuffer, int w, int x, int y0, int y1, uint16_t color)
embeddedartists 0:dfad71908d59 56 {
embeddedartists 0:dfad71908d59 57 if (x < w) {
embeddedartists 0:dfad71908d59 58 int h = y1 - y0 + 1;
embeddedartists 0:dfad71908d59 59 uint16_t* fb = framebuffer;
embeddedartists 0:dfad71908d59 60 fb += x;
embeddedartists 0:dfad71908d59 61 fb += y0 * w;
embeddedartists 0:dfad71908d59 62 for (int i = 0; i < h; i++) {
embeddedartists 0:dfad71908d59 63 *fb = color;
embeddedartists 0:dfad71908d59 64 fb += w;
embeddedartists 0:dfad71908d59 65 }
embeddedartists 0:dfad71908d59 66 }
embeddedartists 0:dfad71908d59 67 }
embeddedartists 0:dfad71908d59 68
embeddedartists 0:dfad71908d59 69 /**
embeddedartists 0:dfad71908d59 70 * Draw color bars to the display
embeddedartists 0:dfad71908d59 71 */
embeddedartists 0:dfad71908d59 72 static void drawBars565(uint16_t* framebuffer, int w, int h)
embeddedartists 0:dfad71908d59 73 {
embeddedartists 0:dfad71908d59 74 uint16_t clr;
embeddedartists 0:dfad71908d59 75 uint16_t xgs, ygs, curx, cury, curym, xidx;
embeddedartists 0:dfad71908d59 76 int idx;
embeddedartists 0:dfad71908d59 77
embeddedartists 0:dfad71908d59 78 /* Compute vertical size for bars */
embeddedartists 0:dfad71908d59 79 ygs = h / 3;
embeddedartists 0:dfad71908d59 80
embeddedartists 0:dfad71908d59 81 /* Draw Red bars */
embeddedartists 0:dfad71908d59 82 cury = 0;
embeddedartists 0:dfad71908d59 83 curx = 0;
embeddedartists 0:dfad71908d59 84 curym = ygs - 1;
embeddedartists 0:dfad71908d59 85 xgs = w / RED_COLORS;
embeddedartists 0:dfad71908d59 86 clr = BLACK;
embeddedartists 0:dfad71908d59 87 for (xidx = 0; xidx < RED_COLORS; xidx++)
embeddedartists 0:dfad71908d59 88 {
embeddedartists 0:dfad71908d59 89 //swim_set_pen_color(win1, clr);
embeddedartists 0:dfad71908d59 90 for (idx = 0; idx <= xgs; idx++)
embeddedartists 0:dfad71908d59 91 {
embeddedartists 0:dfad71908d59 92 //swim_put_line(win1, curx, cury, curx, curym);
embeddedartists 0:dfad71908d59 93 //g.put_line(curx, cury, curx, curym, clr);
embeddedartists 0:dfad71908d59 94 verticalLine16(framebuffer, w, curx, cury, curym, clr);
embeddedartists 0:dfad71908d59 95 curx++;
embeddedartists 0:dfad71908d59 96 }
embeddedartists 0:dfad71908d59 97 clr = clr + 0x0800;
embeddedartists 0:dfad71908d59 98 }
embeddedartists 0:dfad71908d59 99
embeddedartists 0:dfad71908d59 100 /* Draw green bars */
embeddedartists 0:dfad71908d59 101 cury = cury + ygs;
embeddedartists 0:dfad71908d59 102 curx = 0;
embeddedartists 0:dfad71908d59 103 curym = cury + (ygs - 1);
embeddedartists 0:dfad71908d59 104 xgs = w / GREEN_COLORS;
embeddedartists 0:dfad71908d59 105 clr = BLACK;
embeddedartists 0:dfad71908d59 106 for (xidx = 0; xidx < GREEN_COLORS; xidx++)
embeddedartists 0:dfad71908d59 107 {
embeddedartists 0:dfad71908d59 108 //swim_set_pen_color(win1, clr);
embeddedartists 0:dfad71908d59 109 for (idx = 0; idx <= xgs; idx++)
embeddedartists 0:dfad71908d59 110 {
embeddedartists 0:dfad71908d59 111 //swim_put_line(win1, curx, cury, curx, curym);
embeddedartists 0:dfad71908d59 112 //g.put_line(curx, cury, curx, curym, clr);
embeddedartists 0:dfad71908d59 113 verticalLine16(framebuffer, w, curx, cury, curym, clr);
embeddedartists 0:dfad71908d59 114 curx++;
embeddedartists 0:dfad71908d59 115 }
embeddedartists 0:dfad71908d59 116 clr = clr + 0x0020;
embeddedartists 0:dfad71908d59 117 }
embeddedartists 0:dfad71908d59 118
embeddedartists 0:dfad71908d59 119 /* Draw blue bars */
embeddedartists 0:dfad71908d59 120 cury = cury + ygs;
embeddedartists 0:dfad71908d59 121 curx = 0;
embeddedartists 0:dfad71908d59 122 curym = h - 1;//cury + (ygs - 1);
embeddedartists 0:dfad71908d59 123 xgs = w / BLUE_COLORS;
embeddedartists 0:dfad71908d59 124 clr = BLACK;
embeddedartists 0:dfad71908d59 125 for (xidx = 0; xidx < BLUE_COLORS; xidx++)
embeddedartists 0:dfad71908d59 126 {
embeddedartists 0:dfad71908d59 127 //swim_set_pen_color(win1, clr);
embeddedartists 0:dfad71908d59 128 for (idx = 0; idx <= xgs; idx++)
embeddedartists 0:dfad71908d59 129 {
embeddedartists 0:dfad71908d59 130 //swim_put_line(win1, curx, cury, curx, curym);
embeddedartists 0:dfad71908d59 131 //g.put_line(curx, cury, curx, curym, clr);
embeddedartists 0:dfad71908d59 132 verticalLine16(framebuffer, w, curx, cury, curym, clr);
embeddedartists 0:dfad71908d59 133 curx++;
embeddedartists 0:dfad71908d59 134 }
embeddedartists 0:dfad71908d59 135 clr = clr + 0x0001;
embeddedartists 0:dfad71908d59 136 }
embeddedartists 0:dfad71908d59 137 }
embeddedartists 0:dfad71908d59 138
embeddedartists 0:dfad71908d59 139
embeddedartists 0:dfad71908d59 140
embeddedartists 0:dfad71908d59 141 void aliveTask(void const* args)
embeddedartists 0:dfad71908d59 142 {
embeddedartists 0:dfad71908d59 143 DMBoard* board = &DMBoard::instance();
embeddedartists 0:dfad71908d59 144
embeddedartists 0:dfad71908d59 145 while(true)
embeddedartists 0:dfad71908d59 146 {
embeddedartists 0:dfad71908d59 147 board->setLED(DMBoard::Led4, false);
embeddedartists 0:dfad71908d59 148 board->setLED(DMBoard::Led1, true);
embeddedartists 0:dfad71908d59 149 Thread::wait(300);
embeddedartists 0:dfad71908d59 150 board->setLED(DMBoard::Led1, false);
embeddedartists 0:dfad71908d59 151 board->setLED(DMBoard::Led2, true);
embeddedartists 0:dfad71908d59 152 Thread::wait(300);
embeddedartists 0:dfad71908d59 153 board->setLED(DMBoard::Led2, false);
embeddedartists 0:dfad71908d59 154 board->setLED(DMBoard::Led3, true);
embeddedartists 0:dfad71908d59 155 Thread::wait(300);
embeddedartists 0:dfad71908d59 156 board->setLED(DMBoard::Led3, false);
embeddedartists 0:dfad71908d59 157 board->setLED(DMBoard::Led4, true);
embeddedartists 0:dfad71908d59 158 Thread::wait(300);
embeddedartists 0:dfad71908d59 159 }
embeddedartists 0:dfad71908d59 160 }
embeddedartists 0:dfad71908d59 161
embeddedartists 0:dfad71908d59 162 /*
embeddedartists 0:dfad71908d59 163 * Reads the /message.txt file from the file system and prints the content
embeddedartists 0:dfad71908d59 164 */
embeddedartists 0:dfad71908d59 165 void readMessageFile(const char* prefix)
embeddedartists 0:dfad71908d59 166 {
embeddedartists 0:dfad71908d59 167 RtosLog* log = DMBoard::instance().logger();
embeddedartists 0:dfad71908d59 168 log->printf("%sTesting to read from USB\n", prefix);
embeddedartists 0:dfad71908d59 169
embeddedartists 1:15ea03d72dd7 170 FILE * fp = fopen("/usb/message.txt", "r");
embeddedartists 0:dfad71908d59 171
embeddedartists 0:dfad71908d59 172 if (fp != NULL) {
embeddedartists 0:dfad71908d59 173 uint8_t* buff = (uint8_t*)malloc(1024+1);
embeddedartists 0:dfad71908d59 174 if (buff == NULL) {
embeddedartists 0:dfad71908d59 175 log->printf("%sFailed to allocate memory for test\n", prefix);
embeddedartists 0:dfad71908d59 176 } else {
embeddedartists 0:dfad71908d59 177 int num = fread(buff, 1, 1024, fp);
embeddedartists 0:dfad71908d59 178 if (num <= 0) {
embeddedartists 0:dfad71908d59 179 log->printf("%sUnable to read file, got %d as result\n", prefix, num);
embeddedartists 0:dfad71908d59 180 } else if (num < 1024) {
embeddedartists 3:4301d34173cf 181 log->printf("%sHave read all %d bytes in the file:\n---\n", prefix, num);
embeddedartists 0:dfad71908d59 182 buff[num] = '\0';
embeddedartists 0:dfad71908d59 183 log->printf((const char*)buff);
embeddedartists 3:4301d34173cf 184 log->printf("\n---\n");
embeddedartists 0:dfad71908d59 185 } else {
embeddedartists 0:dfad71908d59 186 log->printf("%sHave read %d bytes with more to read\n", prefix, num);
embeddedartists 0:dfad71908d59 187 }
embeddedartists 0:dfad71908d59 188 free(buff);
embeddedartists 0:dfad71908d59 189 }
embeddedartists 0:dfad71908d59 190 fclose(fp);
embeddedartists 0:dfad71908d59 191 } else {
embeddedartists 0:dfad71908d59 192 log->printf("%sFILE == NULL\r\n", prefix);
embeddedartists 0:dfad71908d59 193 }
embeddedartists 0:dfad71908d59 194 }
embeddedartists 0:dfad71908d59 195
embeddedartists 0:dfad71908d59 196
embeddedartists 0:dfad71908d59 197 #if defined(DM_BOARD_USE_DISPLAY)
embeddedartists 0:dfad71908d59 198 #define DISPLAY_TASK_PREFIX "[LCD] "
embeddedartists 0:dfad71908d59 199 void displayTask(void const* args)
embeddedartists 0:dfad71908d59 200 {
embeddedartists 0:dfad71908d59 201 // Start display in default mode (16-bit)
embeddedartists 0:dfad71908d59 202 RtosLog* log = DMBoard::instance().logger();
embeddedartists 0:dfad71908d59 203 Display* disp = DMBoard::instance().display();
embeddedartists 0:dfad71908d59 204 Display::DisplayError disperr;
embeddedartists 0:dfad71908d59 205 uint16_t* fb = (uint16_t*)disp->allocateFramebuffer();
embeddedartists 0:dfad71908d59 206 if (fb == NULL) {
embeddedartists 0:dfad71908d59 207 log->printf(DISPLAY_TASK_PREFIX"Failed to allocate memory for framebuffer\r\n");
embeddedartists 0:dfad71908d59 208 mbed_die();
embeddedartists 0:dfad71908d59 209 }
embeddedartists 0:dfad71908d59 210 drawBars565(fb, disp->width(), disp->height());
embeddedartists 0:dfad71908d59 211 disperr = disp->powerUp(fb);
embeddedartists 4:37a60b9bdb99 212 if (disperr != Display::DisplayError_Ok) {
embeddedartists 0:dfad71908d59 213 log->printf(DISPLAY_TASK_PREFIX"Failed to initialize the display, got error %d\r\n", disperr);
embeddedartists 0:dfad71908d59 214 mbed_die();
embeddedartists 0:dfad71908d59 215 }
embeddedartists 0:dfad71908d59 216
embeddedartists 0:dfad71908d59 217 int h = disp->height();
embeddedartists 0:dfad71908d59 218 int w = disp->width();
embeddedartists 0:dfad71908d59 219 uint16_t COLORS[] = { 0xFFF0, 0xF800, 0x07E0, 0x001F, 0x07FF, 0xF81F };
embeddedartists 0:dfad71908d59 220 int i = 0;
embeddedartists 0:dfad71908d59 221 while(true) {
embeddedartists 0:dfad71908d59 222 uint16_t color = COLORS[i++ % (sizeof(COLORS)/sizeof(COLORS[0]))];
embeddedartists 0:dfad71908d59 223 for (int y = 0; y < h; y++) {
embeddedartists 0:dfad71908d59 224 for (int x = 0; x < w; x++) {
embeddedartists 0:dfad71908d59 225 fb[y*w+x] = color;
embeddedartists 0:dfad71908d59 226 }
embeddedartists 0:dfad71908d59 227 Thread::wait(30);
embeddedartists 0:dfad71908d59 228 }
embeddedartists 0:dfad71908d59 229
embeddedartists 0:dfad71908d59 230 // test to read the message file
embeddedartists 0:dfad71908d59 231 //readMessageFile(DISPLAY_TASK_PREFIX);
embeddedartists 0:dfad71908d59 232 }
embeddedartists 0:dfad71908d59 233 }
embeddedartists 2:070e9c054796 234
embeddedartists 2:070e9c054796 235 #define SWIM_TASK_PREFIX "[SWIM] "
embeddedartists 2:070e9c054796 236 void swimTask(void const* args)
embeddedartists 2:070e9c054796 237 {
embeddedartists 2:070e9c054796 238 RtosLog* log = DMBoard::instance().logger();
embeddedartists 2:070e9c054796 239
embeddedartists 2:070e9c054796 240 log->printf(SWIM_TASK_PREFIX"swimTask started\n");
embeddedartists 4:37a60b9bdb99 241
embeddedartists 2:070e9c054796 242 AppLauncher launcher;
embeddedartists 2:070e9c054796 243 if (launcher.setup()) {
embeddedartists 4:37a60b9bdb99 244
embeddedartists 4:37a60b9bdb99 245 // With icons as buttons we need the USB memory stick to with the image files
embeddedartists 4:37a60b9bdb99 246 if (!haveUSBMSD) {
embeddedartists 4:37a60b9bdb99 247 log->printf("Waiting for USB MSD to be connected!\n");
embeddedartists 4:37a60b9bdb99 248 do {
embeddedartists 4:37a60b9bdb99 249 Thread::wait(1000);
embeddedartists 4:37a60b9bdb99 250 } while(!haveUSBMSD);
embeddedartists 4:37a60b9bdb99 251 }
embeddedartists 4:37a60b9bdb99 252
embeddedartists 2:070e9c054796 253 log->printf(SWIM_TASK_PREFIX"Starting menu system\n");
embeddedartists 2:070e9c054796 254 launcher.runToCompletion();
embeddedartists 2:070e9c054796 255 launcher.teardown();
embeddedartists 2:070e9c054796 256 } else {
embeddedartists 4:37a60b9bdb99 257 log->printf(SWIM_TASK_PREFIX"Failed to prepare menu system\n");
embeddedartists 2:070e9c054796 258 }
embeddedartists 2:070e9c054796 259
embeddedartists 2:070e9c054796 260 // Should never end up here
embeddedartists 2:070e9c054796 261 mbed_die();
embeddedartists 2:070e9c054796 262 }
embeddedartists 2:070e9c054796 263
embeddedartists 0:dfad71908d59 264 #endif //DM_BOARD_USE_DISPLAY
embeddedartists 0:dfad71908d59 265
embeddedartists 0:dfad71908d59 266 #define MSD_TASK_PREFIX "[MSD] "
embeddedartists 0:dfad71908d59 267
embeddedartists 0:dfad71908d59 268 void msdTask(void const* args)
embeddedartists 1:15ea03d72dd7 269 {
embeddedartists 1:15ea03d72dd7 270 usbInitGuard.lock();
embeddedartists 1:15ea03d72dd7 271 USBHostMSD* msd = new USBHostMSD("usb");
embeddedartists 1:15ea03d72dd7 272 usbInitGuard.unlock();
embeddedartists 0:dfad71908d59 273 USBHost* host = USBHost::getHostInst();
embeddedartists 0:dfad71908d59 274 RtosLog* log = DMBoard::instance().logger();
embeddedartists 0:dfad71908d59 275
embeddedartists 0:dfad71908d59 276 log->printf(MSD_TASK_PREFIX"msdTask started\n");
embeddedartists 0:dfad71908d59 277
embeddedartists 0:dfad71908d59 278 while(1) {
embeddedartists 0:dfad71908d59 279
embeddedartists 0:dfad71908d59 280 log->printf(MSD_TASK_PREFIX"Attempting to connect...\n");
embeddedartists 0:dfad71908d59 281
embeddedartists 0:dfad71908d59 282 // try to connect a MSD device
embeddedartists 1:15ea03d72dd7 283 bool connected = false;
embeddedartists 1:15ea03d72dd7 284 do {
embeddedartists 1:15ea03d72dd7 285 usbInitGuard.lock();
embeddedartists 1:15ea03d72dd7 286 connected = msd->connect();
embeddedartists 1:15ea03d72dd7 287 usbInitGuard.unlock();
embeddedartists 1:15ea03d72dd7 288 if (!connected) {
embeddedartists 1:15ea03d72dd7 289 //log->printf(MSD_TASK_PREFIX"Failed to connect, waiting and trying again!\n");
embeddedartists 1:15ea03d72dd7 290 Thread::wait(500);
embeddedartists 3:4301d34173cf 291 //DMBoard::instance().buzzer(440, 100);
embeddedartists 0:dfad71908d59 292 }
embeddedartists 1:15ea03d72dd7 293 } while(!connected);
embeddedartists 0:dfad71908d59 294
embeddedartists 0:dfad71908d59 295 log->printf(MSD_TASK_PREFIX"Connected!\n");
embeddedartists 4:37a60b9bdb99 296 haveUSBMSD = true;
embeddedartists 0:dfad71908d59 297
embeddedartists 0:dfad71908d59 298 // read a file
embeddedartists 4:37a60b9bdb99 299 //readMessageFile(MSD_TASK_PREFIX);
embeddedartists 0:dfad71908d59 300
embeddedartists 0:dfad71908d59 301 // if/when the device is disconnected, we try to connect it again
embeddedartists 0:dfad71908d59 302 while(1) {
embeddedartists 0:dfad71908d59 303
embeddedartists 0:dfad71908d59 304 Thread::wait(500);
embeddedartists 0:dfad71908d59 305
embeddedartists 0:dfad71908d59 306 // if device disconnected, try to connect again
embeddedartists 4:37a60b9bdb99 307 if (!msd->connected()) {
embeddedartists 0:dfad71908d59 308 break;
embeddedartists 4:37a60b9bdb99 309 }
embeddedartists 0:dfad71908d59 310 }
embeddedartists 4:37a60b9bdb99 311 haveUSBMSD = false;
embeddedartists 0:dfad71908d59 312 log->printf(MSD_TASK_PREFIX"Disconnected\n");
embeddedartists 0:dfad71908d59 313 }
embeddedartists 0:dfad71908d59 314 }
embeddedartists 0:dfad71908d59 315
embeddedartists 0:dfad71908d59 316 #define NET_TASK_PREFIX "[NET] "
embeddedartists 0:dfad71908d59 317
embeddedartists 0:dfad71908d59 318 void netTask(void const* args)
embeddedartists 0:dfad71908d59 319 {
embeddedartists 0:dfad71908d59 320 RtosLog* log = DMBoard::instance().logger();
embeddedartists 0:dfad71908d59 321 log->printf(NET_TASK_PREFIX"EthernetInterface Setting up...\r\n");
embeddedartists 0:dfad71908d59 322 if(eth.init()!=0) { //for DHCP Server
embeddedartists 0:dfad71908d59 323 //if(eth.init(IPAddress,NetMasks,Gateway)!=0) { //for Static IP Address
embeddedartists 0:dfad71908d59 324 log->printf(NET_TASK_PREFIX"EthernetInterface Initialize Error \r\n");
embeddedartists 0:dfad71908d59 325 mbed_die();
embeddedartists 0:dfad71908d59 326 }
embeddedartists 2:070e9c054796 327 while (eth.connect() != 0) {
embeddedartists 2:070e9c054796 328 Thread::wait(1000);
embeddedartists 0:dfad71908d59 329 }
embeddedartists 0:dfad71908d59 330
embeddedartists 2:070e9c054796 331 ethInitialized = true;
embeddedartists 2:070e9c054796 332 ethUsingDHCP = true;
embeddedartists 2:070e9c054796 333
embeddedartists 0:dfad71908d59 334 log->printf(NET_TASK_PREFIX"IP Address is %s\r\n", eth.getIPAddress());
embeddedartists 0:dfad71908d59 335 log->printf(NET_TASK_PREFIX"NetMask is %s\r\n", eth.getNetworkMask());
embeddedartists 0:dfad71908d59 336 log->printf(NET_TASK_PREFIX"Gateway Address is %s\r\n", eth.getGateway());
embeddedartists 0:dfad71908d59 337 log->printf(NET_TASK_PREFIX"Ethernet Setup OK\r\n");
embeddedartists 0:dfad71908d59 338
embeddedartists 0:dfad71908d59 339 HTTPServerAddHandler<SimpleHandler>("/hello"); //Default handler
embeddedartists 0:dfad71908d59 340 FSHandler::mount("/usb", "/");
embeddedartists 0:dfad71908d59 341 HTTPServerAddHandler<FSHandler>("/");
embeddedartists 0:dfad71908d59 342 //HTTPServerAddHandler<RPCHandler>("/rpc");
embeddedartists 0:dfad71908d59 343 //lcd.locate(0,0);
embeddedartists 0:dfad71908d59 344 //lcd.printf("%s",eth.getIPAddress());
embeddedartists 0:dfad71908d59 345 HTTPServerStart(80);
embeddedartists 0:dfad71908d59 346 }
embeddedartists 0:dfad71908d59 347
embeddedartists 1:15ea03d72dd7 348 static uint8_t mouse_button, mouse_x, mouse_y, mouse_z;
embeddedartists 1:15ea03d72dd7 349 void mouseEvent(uint8_t buttons, int8_t x, int8_t y, int8_t z)
embeddedartists 1:15ea03d72dd7 350 {
embeddedartists 1:15ea03d72dd7 351 mouse_button = buttons;
embeddedartists 1:15ea03d72dd7 352 mouse_x = x;
embeddedartists 1:15ea03d72dd7 353 mouse_y = y;
embeddedartists 1:15ea03d72dd7 354 mouse_z = z;
embeddedartists 1:15ea03d72dd7 355 }
embeddedartists 1:15ea03d72dd7 356
embeddedartists 1:15ea03d72dd7 357 #define MOUSE_TASK_PREFIX "[MOUSE] "
embeddedartists 1:15ea03d72dd7 358
embeddedartists 1:15ea03d72dd7 359 void mouseTask(void const* args)
embeddedartists 1:15ea03d72dd7 360 {
embeddedartists 1:15ea03d72dd7 361 usbInitGuard.lock();
embeddedartists 1:15ea03d72dd7 362 USBHostMouse* mouse = new USBHostMouse();
embeddedartists 1:15ea03d72dd7 363 usbInitGuard.unlock();
embeddedartists 1:15ea03d72dd7 364 RtosLog* log = DMBoard::instance().logger();
embeddedartists 1:15ea03d72dd7 365
embeddedartists 1:15ea03d72dd7 366 log->printf(MOUSE_TASK_PREFIX"mouseTask started\n");
embeddedartists 1:15ea03d72dd7 367
embeddedartists 1:15ea03d72dd7 368 while(1) {
embeddedartists 1:15ea03d72dd7 369
embeddedartists 1:15ea03d72dd7 370 log->printf(MOUSE_TASK_PREFIX"Attempting to connect...\n");
embeddedartists 1:15ea03d72dd7 371
embeddedartists 1:15ea03d72dd7 372 // try to connect a mouse
embeddedartists 1:15ea03d72dd7 373 bool connected = false;
embeddedartists 1:15ea03d72dd7 374 do {
embeddedartists 1:15ea03d72dd7 375 usbInitGuard.lock();
embeddedartists 1:15ea03d72dd7 376 connected = mouse->connect();
embeddedartists 1:15ea03d72dd7 377 usbInitGuard.unlock();
embeddedartists 1:15ea03d72dd7 378 if (!connected) {
embeddedartists 1:15ea03d72dd7 379 //log->printf(MOUSE_TASK_PREFIX"Failed to connect, waiting and trying again!\n");
embeddedartists 1:15ea03d72dd7 380 Thread::wait(500);
embeddedartists 1:15ea03d72dd7 381 }
embeddedartists 1:15ea03d72dd7 382 } while(!connected);
embeddedartists 1:15ea03d72dd7 383
embeddedartists 1:15ea03d72dd7 384 log->printf(MOUSE_TASK_PREFIX"Connected!\n");
embeddedartists 1:15ea03d72dd7 385 mouse->attachEvent(mouseEvent);
embeddedartists 1:15ea03d72dd7 386
embeddedartists 1:15ea03d72dd7 387 while(mouse->connected()) {
embeddedartists 1:15ea03d72dd7 388 log->printf(MOUSE_TASK_PREFIX"Buttons: 0x%02x, X %3d, Y %3d, Z %3d\n", mouse_button, mouse_x, mouse_y, mouse_z);
embeddedartists 1:15ea03d72dd7 389 Thread::wait(500);
embeddedartists 1:15ea03d72dd7 390 }
embeddedartists 1:15ea03d72dd7 391
embeddedartists 1:15ea03d72dd7 392 log->printf(MOUSE_TASK_PREFIX"Disconnected\n");
embeddedartists 1:15ea03d72dd7 393 }
embeddedartists 1:15ea03d72dd7 394 }
embeddedartists 1:15ea03d72dd7 395
embeddedartists 1:15ea03d72dd7 396 #define CIRCBUFF_SIZE 256
embeddedartists 1:15ea03d72dd7 397 static uint8_t circbuff[CIRCBUFF_SIZE];
embeddedartists 1:15ea03d72dd7 398 static uint32_t circbuff_read = 0;
embeddedartists 1:15ea03d72dd7 399 static uint32_t circbuff_write = 0;
embeddedartists 1:15ea03d72dd7 400 void keyEvent(uint8_t key)
embeddedartists 1:15ea03d72dd7 401 {
embeddedartists 1:15ea03d72dd7 402 circbuff[circbuff_write%CIRCBUFF_SIZE] = key;
embeddedartists 1:15ea03d72dd7 403 circbuff_write++;
embeddedartists 1:15ea03d72dd7 404 }
embeddedartists 1:15ea03d72dd7 405
embeddedartists 1:15ea03d72dd7 406 #define KEY_TASK_PREFIX "[KEY] "
embeddedartists 1:15ea03d72dd7 407
embeddedartists 1:15ea03d72dd7 408 void keyTask(void const* args)
embeddedartists 1:15ea03d72dd7 409 {
embeddedartists 1:15ea03d72dd7 410 usbInitGuard.lock();
embeddedartists 1:15ea03d72dd7 411 USBHostKeyboard* keyboard = new USBHostKeyboard();
embeddedartists 1:15ea03d72dd7 412 usbInitGuard.unlock();
embeddedartists 1:15ea03d72dd7 413
embeddedartists 1:15ea03d72dd7 414 RtosLog* log = DMBoard::instance().logger();
embeddedartists 1:15ea03d72dd7 415 uint8_t buff[10+1] = {0};
embeddedartists 1:15ea03d72dd7 416 int pos;
embeddedartists 1:15ea03d72dd7 417
embeddedartists 1:15ea03d72dd7 418 log->printf(KEY_TASK_PREFIX"keyTask started\n");
embeddedartists 1:15ea03d72dd7 419
embeddedartists 1:15ea03d72dd7 420 while(1) {
embeddedartists 1:15ea03d72dd7 421
embeddedartists 1:15ea03d72dd7 422 log->printf(KEY_TASK_PREFIX"Attempting to connect...\n");
embeddedartists 1:15ea03d72dd7 423
embeddedartists 1:15ea03d72dd7 424 // try to connect a keyboard
embeddedartists 1:15ea03d72dd7 425 bool connected = false;
embeddedartists 1:15ea03d72dd7 426 do {
embeddedartists 1:15ea03d72dd7 427 usbInitGuard.lock();
embeddedartists 1:15ea03d72dd7 428 connected = keyboard->connect();
embeddedartists 1:15ea03d72dd7 429 usbInitGuard.unlock();
embeddedartists 1:15ea03d72dd7 430 if (!connected) {
embeddedartists 1:15ea03d72dd7 431 //log->printf(KEY_TASK_PREFIX"Failed to connect, waiting and trying again!\n");
embeddedartists 1:15ea03d72dd7 432 Thread::wait(1000);
embeddedartists 1:15ea03d72dd7 433 }
embeddedartists 1:15ea03d72dd7 434 } while(!connected);
embeddedartists 1:15ea03d72dd7 435
embeddedartists 1:15ea03d72dd7 436 log->printf(KEY_TASK_PREFIX"Connected!\n");
embeddedartists 1:15ea03d72dd7 437 keyboard->attach(keyEvent);
embeddedartists 1:15ea03d72dd7 438
embeddedartists 1:15ea03d72dd7 439 while(keyboard->connected()) {
embeddedartists 1:15ea03d72dd7 440 for (pos = 0; pos < 10; pos++) {
embeddedartists 1:15ea03d72dd7 441 if (circbuff_read < circbuff_write) {
embeddedartists 1:15ea03d72dd7 442 buff[pos++] = circbuff[circbuff_read%CIRCBUFF_SIZE];
embeddedartists 1:15ea03d72dd7 443 circbuff_read++;
embeddedartists 1:15ea03d72dd7 444 } else {
embeddedartists 1:15ea03d72dd7 445 break;
embeddedartists 1:15ea03d72dd7 446 }
embeddedartists 1:15ea03d72dd7 447 }
embeddedartists 1:15ea03d72dd7 448 if (pos > 0) {
embeddedartists 1:15ea03d72dd7 449 log->printf(KEY_TASK_PREFIX"%s\n", buff);
embeddedartists 1:15ea03d72dd7 450 }
embeddedartists 1:15ea03d72dd7 451 Thread::wait(20);
embeddedartists 1:15ea03d72dd7 452 }
embeddedartists 1:15ea03d72dd7 453
embeddedartists 1:15ea03d72dd7 454 log->printf(KEY_TASK_PREFIX"Disconnected\n");
embeddedartists 1:15ea03d72dd7 455 }
embeddedartists 1:15ea03d72dd7 456 }
embeddedartists 1:15ea03d72dd7 457
embeddedartists 0:dfad71908d59 458 /******************************************************************************
embeddedartists 0:dfad71908d59 459 * Main function
embeddedartists 0:dfad71908d59 460 *****************************************************************************/
embeddedartists 0:dfad71908d59 461 int main()
embeddedartists 0:dfad71908d59 462 {
embeddedartists 0:dfad71908d59 463 DMBoard::BoardError err;
embeddedartists 0:dfad71908d59 464 DMBoard* board = &DMBoard::instance();
embeddedartists 0:dfad71908d59 465 RtosLog* log = board->logger();
embeddedartists 0:dfad71908d59 466 err = board->init();
embeddedartists 0:dfad71908d59 467 if (err != DMBoard::Ok) {
embeddedartists 0:dfad71908d59 468 log->printf("Failed to initialize the board, got error %d\r\n", err);
embeddedartists 0:dfad71908d59 469 mbed_die();
embeddedartists 0:dfad71908d59 470 }
embeddedartists 0:dfad71908d59 471
embeddedartists 0:dfad71908d59 472 log->printf("\n\n---\nMulti-threaded demo\nBuilt: " __DATE__ " at " __TIME__ "\n\n");
embeddedartists 0:dfad71908d59 473
embeddedartists 1:15ea03d72dd7 474 //log->printf("Press button to start...\r\n");
embeddedartists 1:15ea03d72dd7 475 //while(!board->buttonPressed());
embeddedartists 1:15ea03d72dd7 476 //while(board->buttonPressed());
embeddedartists 0:dfad71908d59 477
embeddedartists 0:dfad71908d59 478 Thread tAlive(aliveTask);
embeddedartists 0:dfad71908d59 479 #if defined(DM_BOARD_USE_DISPLAY)
embeddedartists 2:070e9c054796 480 //Thread tDisplay(displayTask, NULL, osPriorityNormal, 8192);
embeddedartists 2:070e9c054796 481 Thread tSwim(swimTask, NULL, osPriorityNormal, 8192);
embeddedartists 0:dfad71908d59 482 #endif
embeddedartists 0:dfad71908d59 483 Thread tMemstick(msdTask, NULL, osPriorityNormal, 8192);
embeddedartists 0:dfad71908d59 484 Thread tNetwork(netTask, NULL, osPriorityNormal, 8192);
embeddedartists 1:15ea03d72dd7 485 Thread tMouse(mouseTask);
embeddedartists 1:15ea03d72dd7 486 Thread tKeyboard(keyTask);
embeddedartists 0:dfad71908d59 487
embeddedartists 0:dfad71908d59 488 while(1) { wait(5); }
embeddedartists 0:dfad71908d59 489 }