Step 4.6 of Tutorial
Dependencies: DMBasicGUI DMSupport
Fork of lpc4088_displaymodule_hello_world by
main.cpp@6:e904b6833ea4, 2016-06-14 (annotated)
- Committer:
- millsrm0724
- Date:
- Tue Jun 14 20:48:05 2016 +0000
- Revision:
- 6:e904b6833ea4
- Parent:
- 0:8ef5f57e33dc
Added Step 4.6 of tutorial
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 0:8ef5f57e33dc | 1 | #include "mbed.h" |
embeddedartists | 0:8ef5f57e33dc | 2 | #include "DMBoard.h" |
embeddedartists | 0:8ef5f57e33dc | 3 | #include "lpc_swim.h" |
embeddedartists | 0:8ef5f57e33dc | 4 | #include "lpc_swim_font.h" |
embeddedartists | 0:8ef5f57e33dc | 5 | |
millsrm0724 | 6:e904b6833ea4 | 6 | DigitalOut myled1(LED1); |
millsrm0724 | 6:e904b6833ea4 | 7 | DigitalOut myled2(LED2); |
millsrm0724 | 6:e904b6833ea4 | 8 | DigitalOut myled3(LED3); |
millsrm0724 | 6:e904b6833ea4 | 9 | DigitalOut myled4(LED4); |
millsrm0724 | 6:e904b6833ea4 | 10 | |
embeddedartists | 0:8ef5f57e33dc | 11 | int main() |
embeddedartists | 0:8ef5f57e33dc | 12 | { |
embeddedartists | 0:8ef5f57e33dc | 13 | DMBoard::BoardError err; |
embeddedartists | 0:8ef5f57e33dc | 14 | DMBoard* board = &DMBoard::instance(); |
embeddedartists | 0:8ef5f57e33dc | 15 | RtosLog* log = board->logger(); |
embeddedartists | 0:8ef5f57e33dc | 16 | Display* disp = board->display(); |
embeddedartists | 0:8ef5f57e33dc | 17 | |
millsrm0724 | 6:e904b6833ea4 | 18 | //Turn all LEDs off |
millsrm0724 | 6:e904b6833ea4 | 19 | myled1 = 1; //LED1 is active low, turn it off |
millsrm0724 | 6:e904b6833ea4 | 20 | myled2 = 1; //LED2 is active low, turn it off |
millsrm0724 | 6:e904b6833ea4 | 21 | myled3 = 0; //LED3 is active high, turn it off |
millsrm0724 | 6:e904b6833ea4 | 22 | myled4 = 0; //LED4 is active high, turn it off |
millsrm0724 | 6:e904b6833ea4 | 23 | |
embeddedartists | 0:8ef5f57e33dc | 24 | do { |
embeddedartists | 0:8ef5f57e33dc | 25 | err = board->init(); |
embeddedartists | 0:8ef5f57e33dc | 26 | if (err != DMBoard::Ok) { |
embeddedartists | 0:8ef5f57e33dc | 27 | log->printf("Failed to initialize the board, got error %d\r\n", err); |
embeddedartists | 0:8ef5f57e33dc | 28 | break; |
embeddedartists | 0:8ef5f57e33dc | 29 | } |
embeddedartists | 0:8ef5f57e33dc | 30 | |
embeddedartists | 0:8ef5f57e33dc | 31 | log->printf("\n\nHello World!\n\n"); |
embeddedartists | 0:8ef5f57e33dc | 32 | |
embeddedartists | 0:8ef5f57e33dc | 33 | SWIM_WINDOW_T win; |
embeddedartists | 0:8ef5f57e33dc | 34 | void* fb = disp->allocateFramebuffer(); |
embeddedartists | 0:8ef5f57e33dc | 35 | if (fb == NULL) { |
embeddedartists | 0:8ef5f57e33dc | 36 | log->printf("Failed to allocate memory for a frame buffer\r\n"); |
embeddedartists | 0:8ef5f57e33dc | 37 | err = DMBoard::MemoryError; |
embeddedartists | 0:8ef5f57e33dc | 38 | break; |
embeddedartists | 0:8ef5f57e33dc | 39 | } |
embeddedartists | 0:8ef5f57e33dc | 40 | |
embeddedartists | 0:8ef5f57e33dc | 41 | // Prepare fullscreen |
embeddedartists | 0:8ef5f57e33dc | 42 | swim_window_open(&win, |
embeddedartists | 0:8ef5f57e33dc | 43 | disp->width(), disp->height(), // full size |
embeddedartists | 0:8ef5f57e33dc | 44 | (COLOR_T*)fb, |
embeddedartists | 0:8ef5f57e33dc | 45 | 0,0,disp->width()-1, disp->height()-1, // window position and size |
embeddedartists | 0:8ef5f57e33dc | 46 | 1, // border |
embeddedartists | 0:8ef5f57e33dc | 47 | WHITE, BLUE, BLACK); // colors: pen, backgr, forgr |
embeddedartists | 0:8ef5f57e33dc | 48 | swim_set_title(&win, "My Program", BLACK); |
embeddedartists | 0:8ef5f57e33dc | 49 | |
embeddedartists | 0:8ef5f57e33dc | 50 | // Message |
embeddedartists | 0:8ef5f57e33dc | 51 | swim_put_text_xy(&win, "Hello World!", 100, 100); |
embeddedartists | 0:8ef5f57e33dc | 52 | |
embeddedartists | 0:8ef5f57e33dc | 53 | // Start display in default mode (16-bit) |
embeddedartists | 0:8ef5f57e33dc | 54 | Display::DisplayError disperr = disp->powerUp(fb); |
embeddedartists | 0:8ef5f57e33dc | 55 | if (disperr != Display::DisplayError_Ok) { |
embeddedartists | 0:8ef5f57e33dc | 56 | log->printf("Failed to initialize the display, got error %d\r\n", disperr); |
embeddedartists | 0:8ef5f57e33dc | 57 | break; |
embeddedartists | 0:8ef5f57e33dc | 58 | } |
embeddedartists | 0:8ef5f57e33dc | 59 | } while(false); |
embeddedartists | 0:8ef5f57e33dc | 60 | |
embeddedartists | 0:8ef5f57e33dc | 61 | if (err != DMBoard::Ok) { |
embeddedartists | 0:8ef5f57e33dc | 62 | log->printf("\nTERMINATING\n"); |
embeddedartists | 0:8ef5f57e33dc | 63 | wait_ms(2000); // allow RtosLog to flush messages |
embeddedartists | 0:8ef5f57e33dc | 64 | mbed_die(); |
embeddedartists | 0:8ef5f57e33dc | 65 | } |
embeddedartists | 0:8ef5f57e33dc | 66 | |
millsrm0724 | 6:e904b6833ea4 | 67 | while(true) |
millsrm0724 | 6:e904b6833ea4 | 68 | { |
millsrm0724 | 6:e904b6833ea4 | 69 | myled3 = 0; //Turn LED3 off |
millsrm0724 | 6:e904b6833ea4 | 70 | myled1 = 0; //Turn LED1 on |
millsrm0724 | 6:e904b6833ea4 | 71 | wait(0.2); //Wait 200 ms |
millsrm0724 | 6:e904b6833ea4 | 72 | myled1 = 1; //Turn LED1 off |
millsrm0724 | 6:e904b6833ea4 | 73 | myled2 = 0; //Turn LED2 on |
millsrm0724 | 6:e904b6833ea4 | 74 | wait(0.2); //Wait 200 ms |
millsrm0724 | 6:e904b6833ea4 | 75 | myled2 = 1; //Turn LED2 off |
millsrm0724 | 6:e904b6833ea4 | 76 | myled4 = 1; //Turn LED4 on |
millsrm0724 | 6:e904b6833ea4 | 77 | wait(0.2); //Wait 200 ms |
millsrm0724 | 6:e904b6833ea4 | 78 | myled4 = 0; //Turn LED4 off |
millsrm0724 | 6:e904b6833ea4 | 79 | myled3 = 1; //Turn LED3 on |
millsrm0724 | 6:e904b6833ea4 | 80 | wait(0.2); //Wait 200 ms |
embeddedartists | 0:8ef5f57e33dc | 81 | } |
embeddedartists | 0:8ef5f57e33dc | 82 | } |