Template for creating new programs for the LPC4088 Display Module
Dependencies: DMBasicGUI DMSupport
Fork of lpc4088_displaymodule_hello_world by
A minimal example showing how to initialize the display module and draw a message on the display.
This project can be selected as a template when creating a new project based on the LPC4088 Display Module.
Information
This project works on both the 4.3" and 5" display modules.
This is what it looks like:
main.cpp@7:791d32dd9dd9, 2019-10-23 (annotated)
- Committer:
- embeddedartists
- Date:
- Wed Oct 23 07:00:18 2019 +0000
- Revision:
- 7:791d32dd9dd9
- Parent:
- 0:8ef5f57e33dc
Updates related to mbed OS 5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 0:8ef5f57e33dc | 1 | #include "mbed.h" |
embeddedartists | 7:791d32dd9dd9 | 2 | #include "platform/mbed_thread.h" |
embeddedartists | 0:8ef5f57e33dc | 3 | #include "DMBoard.h" |
embeddedartists | 0:8ef5f57e33dc | 4 | #include "lpc_swim.h" |
embeddedartists | 0:8ef5f57e33dc | 5 | #include "lpc_swim_font.h" |
embeddedartists | 0:8ef5f57e33dc | 6 | |
embeddedartists | 0:8ef5f57e33dc | 7 | int main() |
embeddedartists | 0:8ef5f57e33dc | 8 | { |
embeddedartists | 7:791d32dd9dd9 | 9 | |
embeddedartists | 0:8ef5f57e33dc | 10 | DMBoard::BoardError err; |
embeddedartists | 0:8ef5f57e33dc | 11 | DMBoard* board = &DMBoard::instance(); |
embeddedartists | 0:8ef5f57e33dc | 12 | RtosLog* log = board->logger(); |
embeddedartists | 0:8ef5f57e33dc | 13 | Display* disp = board->display(); |
embeddedartists | 7:791d32dd9dd9 | 14 | |
embeddedartists | 0:8ef5f57e33dc | 15 | do { |
embeddedartists | 0:8ef5f57e33dc | 16 | err = board->init(); |
embeddedartists | 0:8ef5f57e33dc | 17 | if (err != DMBoard::Ok) { |
embeddedartists | 0:8ef5f57e33dc | 18 | log->printf("Failed to initialize the board, got error %d\r\n", err); |
embeddedartists | 0:8ef5f57e33dc | 19 | break; |
embeddedartists | 0:8ef5f57e33dc | 20 | } |
embeddedartists | 0:8ef5f57e33dc | 21 | |
embeddedartists | 0:8ef5f57e33dc | 22 | log->printf("\n\nHello World!\n\n"); |
embeddedartists | 0:8ef5f57e33dc | 23 | |
embeddedartists | 0:8ef5f57e33dc | 24 | SWIM_WINDOW_T win; |
embeddedartists | 0:8ef5f57e33dc | 25 | void* fb = disp->allocateFramebuffer(); |
embeddedartists | 0:8ef5f57e33dc | 26 | if (fb == NULL) { |
embeddedartists | 0:8ef5f57e33dc | 27 | log->printf("Failed to allocate memory for a frame buffer\r\n"); |
embeddedartists | 0:8ef5f57e33dc | 28 | err = DMBoard::MemoryError; |
embeddedartists | 0:8ef5f57e33dc | 29 | break; |
embeddedartists | 0:8ef5f57e33dc | 30 | } |
embeddedartists | 7:791d32dd9dd9 | 31 | |
embeddedartists | 0:8ef5f57e33dc | 32 | // Prepare fullscreen |
embeddedartists | 0:8ef5f57e33dc | 33 | swim_window_open(&win, |
embeddedartists | 0:8ef5f57e33dc | 34 | disp->width(), disp->height(), // full size |
embeddedartists | 0:8ef5f57e33dc | 35 | (COLOR_T*)fb, |
embeddedartists | 0:8ef5f57e33dc | 36 | 0,0,disp->width()-1, disp->height()-1, // window position and size |
embeddedartists | 0:8ef5f57e33dc | 37 | 1, // border |
embeddedartists | 0:8ef5f57e33dc | 38 | WHITE, BLUE, BLACK); // colors: pen, backgr, forgr |
embeddedartists | 0:8ef5f57e33dc | 39 | swim_set_title(&win, "My Program", BLACK); |
embeddedartists | 0:8ef5f57e33dc | 40 | |
embeddedartists | 0:8ef5f57e33dc | 41 | // Message |
embeddedartists | 7:791d32dd9dd9 | 42 | swim_put_text_xy(&win, "Hello World!", 100, 100); |
embeddedartists | 7:791d32dd9dd9 | 43 | |
embeddedartists | 0:8ef5f57e33dc | 44 | // Start display in default mode (16-bit) |
embeddedartists | 7:791d32dd9dd9 | 45 | Display::DisplayError disperr = disp->powerUp(fb); |
embeddedartists | 0:8ef5f57e33dc | 46 | if (disperr != Display::DisplayError_Ok) { |
embeddedartists | 0:8ef5f57e33dc | 47 | log->printf("Failed to initialize the display, got error %d\r\n", disperr); |
embeddedartists | 0:8ef5f57e33dc | 48 | break; |
embeddedartists | 0:8ef5f57e33dc | 49 | } |
embeddedartists | 7:791d32dd9dd9 | 50 | |
embeddedartists | 0:8ef5f57e33dc | 51 | } while(false); |
embeddedartists | 0:8ef5f57e33dc | 52 | |
embeddedartists | 0:8ef5f57e33dc | 53 | if (err != DMBoard::Ok) { |
embeddedartists | 0:8ef5f57e33dc | 54 | log->printf("\nTERMINATING\n"); |
embeddedartists | 7:791d32dd9dd9 | 55 | thread_sleep_for(2000); // allow RtosLog to flush messages |
embeddedartists | 0:8ef5f57e33dc | 56 | mbed_die(); |
embeddedartists | 0:8ef5f57e33dc | 57 | } |
embeddedartists | 0:8ef5f57e33dc | 58 | |
embeddedartists | 0:8ef5f57e33dc | 59 | while(true) { |
embeddedartists | 0:8ef5f57e33dc | 60 | } |
embeddedartists | 0:8ef5f57e33dc | 61 | } |