Single Photo displayed on LPC4088
Dependencies: DMBasicGUI DMSupport
main.cpp@0:9140ec6aa604, 2017-07-28 (annotated)
- Committer:
- jmitc91516
- Date:
- Fri Jul 28 14:19:12 2017 +0000
- Revision:
- 0:9140ec6aa604
Simple application that displays a single photograph on the LPC4088 display.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmitc91516 | 0:9140ec6aa604 | 1 | #include "mbed.h" |
jmitc91516 | 0:9140ec6aa604 | 2 | #include "DMBoard.h" |
jmitc91516 | 0:9140ec6aa604 | 3 | #include "lpc_swim.h" |
jmitc91516 | 0:9140ec6aa604 | 4 | #include "lpc_swim_font.h" |
jmitc91516 | 0:9140ec6aa604 | 5 | |
jmitc91516 | 0:9140ec6aa604 | 6 | #include "GuiLib.h" |
jmitc91516 | 0:9140ec6aa604 | 7 | #include "GuiDisplay.h" |
jmitc91516 | 0:9140ec6aa604 | 8 | |
jmitc91516 | 0:9140ec6aa604 | 9 | /* |
jmitc91516 | 0:9140ec6aa604 | 10 | Bodge so GuiDisplay.c ('easyGUIFixed' file) can call Thread::wait |
jmitc91516 | 0:9140ec6aa604 | 11 | (giving it an accurate millisecond timer) |
jmitc91516 | 0:9140ec6aa604 | 12 | */ |
jmitc91516 | 0:9140ec6aa604 | 13 | extern "C" { |
jmitc91516 | 0:9140ec6aa604 | 14 | void EasyGUIWaitMs(GuiConst_INT32U msec) |
jmitc91516 | 0:9140ec6aa604 | 15 | { |
jmitc91516 | 0:9140ec6aa604 | 16 | Thread::wait(msec); |
jmitc91516 | 0:9140ec6aa604 | 17 | } |
jmitc91516 | 0:9140ec6aa604 | 18 | } |
jmitc91516 | 0:9140ec6aa604 | 19 | |
jmitc91516 | 0:9140ec6aa604 | 20 | // Defined in GuiDisplay.c - set the display frame address at runtime |
jmitc91516 | 0:9140ec6aa604 | 21 | extern "C" { |
jmitc91516 | 0:9140ec6aa604 | 22 | void GuiDisplay_SetFrameAddress(void *newFrameAddress); |
jmitc91516 | 0:9140ec6aa604 | 23 | } |
jmitc91516 | 0:9140ec6aa604 | 24 | |
jmitc91516 | 0:9140ec6aa604 | 25 | /* |
jmitc91516 | 0:9140ec6aa604 | 26 | Displays the specified easyGUI 'structure' (or page, to use a more easily understood term). |
jmitc91516 | 0:9140ec6aa604 | 27 | |
jmitc91516 | 0:9140ec6aa604 | 28 | Args are: the index of the structure to be displayed, |
jmitc91516 | 0:9140ec6aa604 | 29 | |
jmitc91516 | 0:9140ec6aa604 | 30 | No return code. |
jmitc91516 | 0:9140ec6aa604 | 31 | */ |
jmitc91516 | 0:9140ec6aa604 | 32 | void DisplayEasyGuiStructure(int structureIndex) |
jmitc91516 | 0:9140ec6aa604 | 33 | { |
jmitc91516 | 0:9140ec6aa604 | 34 | GuiLib_Clear(); // Don't need this if we have drawn the background bitmap - it covers the entire screen |
jmitc91516 | 0:9140ec6aa604 | 35 | |
jmitc91516 | 0:9140ec6aa604 | 36 | GuiLib_ShowScreen(structureIndex, GuiLib_NO_CURSOR, GuiLib_RESET_AUTO_REDRAW); |
jmitc91516 | 0:9140ec6aa604 | 37 | |
jmitc91516 | 0:9140ec6aa604 | 38 | GuiLib_Refresh(); |
jmitc91516 | 0:9140ec6aa604 | 39 | |
jmitc91516 | 0:9140ec6aa604 | 40 | } // End of "DisplayEasyGUIStructure" |
jmitc91516 | 0:9140ec6aa604 | 41 | |
jmitc91516 | 0:9140ec6aa604 | 42 | /* |
jmitc91516 | 0:9140ec6aa604 | 43 | Sets up the easyGUI user interface in an acceptable initial state. |
jmitc91516 | 0:9140ec6aa604 | 44 | |
jmitc91516 | 0:9140ec6aa604 | 45 | No return code. |
jmitc91516 | 0:9140ec6aa604 | 46 | */ |
jmitc91516 | 0:9140ec6aa604 | 47 | void InitEasyGUIDisplay(int initialEasyGUIPage) |
jmitc91516 | 0:9140ec6aa604 | 48 | { |
jmitc91516 | 0:9140ec6aa604 | 49 | // easyGUI stuff - note function calls require 'extern "C"' in relevant header |
jmitc91516 | 0:9140ec6aa604 | 50 | |
jmitc91516 | 0:9140ec6aa604 | 51 | GuiDisplay_Lock(); |
jmitc91516 | 0:9140ec6aa604 | 52 | |
jmitc91516 | 0:9140ec6aa604 | 53 | GuiLib_Init(); |
jmitc91516 | 0:9140ec6aa604 | 54 | |
jmitc91516 | 0:9140ec6aa604 | 55 | DisplayEasyGuiStructure(initialEasyGUIPage); |
jmitc91516 | 0:9140ec6aa604 | 56 | |
jmitc91516 | 0:9140ec6aa604 | 57 | // GuiLib_ShowBitmap(GuiStruct_Bitmap_DSC_1836Reduced, 40, 0, -1); |
jmitc91516 | 0:9140ec6aa604 | 58 | |
jmitc91516 | 0:9140ec6aa604 | 59 | GuiDisplay_Unlock(); |
jmitc91516 | 0:9140ec6aa604 | 60 | } |
jmitc91516 | 0:9140ec6aa604 | 61 | |
jmitc91516 | 0:9140ec6aa604 | 62 | |
jmitc91516 | 0:9140ec6aa604 | 63 | void InitialiseLPC4088(DMBoard* board, void **frameBufferAddress1, void **frameBufferAddress2) |
jmitc91516 | 0:9140ec6aa604 | 64 | { |
jmitc91516 | 0:9140ec6aa604 | 65 | RtosLog* log = board->logger(); |
jmitc91516 | 0:9140ec6aa604 | 66 | Display* disp = board->display(); |
jmitc91516 | 0:9140ec6aa604 | 67 | |
jmitc91516 | 0:9140ec6aa604 | 68 | DMBoard::BoardError err; |
jmitc91516 | 0:9140ec6aa604 | 69 | |
jmitc91516 | 0:9140ec6aa604 | 70 | do { |
jmitc91516 | 0:9140ec6aa604 | 71 | err = board->init(); |
jmitc91516 | 0:9140ec6aa604 | 72 | if (err != DMBoard::Ok) { |
jmitc91516 | 0:9140ec6aa604 | 73 | log->printf("Failed to initialize the board, got error %d\r\n", err); |
jmitc91516 | 0:9140ec6aa604 | 74 | break; |
jmitc91516 | 0:9140ec6aa604 | 75 | } |
jmitc91516 | 0:9140ec6aa604 | 76 | |
jmitc91516 | 0:9140ec6aa604 | 77 | |
jmitc91516 | 0:9140ec6aa604 | 78 | #define COLOR_FLICKERING_FIX_1 |
jmitc91516 | 0:9140ec6aa604 | 79 | #ifdef COLOR_FLICKERING_FIX_1 |
jmitc91516 | 0:9140ec6aa604 | 80 | // Possible fix for display flickering on LPC4088 |
jmitc91516 | 0:9140ec6aa604 | 81 | uint32_t* reg = ((uint32_t*)0x400fc188); |
jmitc91516 | 0:9140ec6aa604 | 82 | *reg |= (3<<10); |
jmitc91516 | 0:9140ec6aa604 | 83 | #undef COLOR_FLICKERING_FIX_1 |
jmitc91516 | 0:9140ec6aa604 | 84 | #endif |
jmitc91516 | 0:9140ec6aa604 | 85 | log->printf("\n\nHello World!\n\n"); |
jmitc91516 | 0:9140ec6aa604 | 86 | |
jmitc91516 | 0:9140ec6aa604 | 87 | void* fb = disp->allocateFramebuffer(); |
jmitc91516 | 0:9140ec6aa604 | 88 | if (fb == NULL) { |
jmitc91516 | 0:9140ec6aa604 | 89 | log->printf("Failed to allocate memory for a frame buffer\r\n"); |
jmitc91516 | 0:9140ec6aa604 | 90 | err = DMBoard::MemoryError; |
jmitc91516 | 0:9140ec6aa604 | 91 | break; |
jmitc91516 | 0:9140ec6aa604 | 92 | } |
jmitc91516 | 0:9140ec6aa604 | 93 | |
jmitc91516 | 0:9140ec6aa604 | 94 | *frameBufferAddress1 = fb; |
jmitc91516 | 0:9140ec6aa604 | 95 | |
jmitc91516 | 0:9140ec6aa604 | 96 | // Allocate a second frame buffer - what will its address be? |
jmitc91516 | 0:9140ec6aa604 | 97 | void* fb2 = disp->allocateFramebuffer(); |
jmitc91516 | 0:9140ec6aa604 | 98 | *frameBufferAddress2 = fb2; |
jmitc91516 | 0:9140ec6aa604 | 99 | |
jmitc91516 | 0:9140ec6aa604 | 100 | Display::DisplayError disperr; |
jmitc91516 | 0:9140ec6aa604 | 101 | // disperr = disp->powerUp(fb, Display::Resolution_24bit_rgb888); |
jmitc91516 | 0:9140ec6aa604 | 102 | // Start display in default mode (16-bit) (24-bit uses too much memory) |
jmitc91516 | 0:9140ec6aa604 | 103 | #define COLOR_FLICKERING_FIX_2 |
jmitc91516 | 0:9140ec6aa604 | 104 | #ifdef COLOR_FLICKERING_FIX_2 |
jmitc91516 | 0:9140ec6aa604 | 105 | // Second possible fix for colour flickering problem, |
jmitc91516 | 0:9140ec6aa604 | 106 | // suggested by Embedded Artists - specify low frame rate |
jmitc91516 | 0:9140ec6aa604 | 107 | disp->powerDown(); |
jmitc91516 | 0:9140ec6aa604 | 108 | disperr = disp->powerUp(fb, Display::Resolution_16bit_rgb565, FrameRate_Low); |
jmitc91516 | 0:9140ec6aa604 | 109 | #undef COLOR_FLICKERING_FIX_2 |
jmitc91516 | 0:9140ec6aa604 | 110 | #else |
jmitc91516 | 0:9140ec6aa604 | 111 | disperr = disp->powerUp(fb); |
jmitc91516 | 0:9140ec6aa604 | 112 | #endif |
jmitc91516 | 0:9140ec6aa604 | 113 | if (disperr != Display::DisplayError_Ok) { |
jmitc91516 | 0:9140ec6aa604 | 114 | log->printf("Failed to initialize the display, got error %d\r\n", disperr); |
jmitc91516 | 0:9140ec6aa604 | 115 | break; |
jmitc91516 | 0:9140ec6aa604 | 116 | } |
jmitc91516 | 0:9140ec6aa604 | 117 | |
jmitc91516 | 0:9140ec6aa604 | 118 | } while(false); |
jmitc91516 | 0:9140ec6aa604 | 119 | |
jmitc91516 | 0:9140ec6aa604 | 120 | if (err != DMBoard::Ok) { |
jmitc91516 | 0:9140ec6aa604 | 121 | log->printf("\nTERMINATING\n"); |
jmitc91516 | 0:9140ec6aa604 | 122 | wait_ms(2000); // allow RtosLog to flush messages |
jmitc91516 | 0:9140ec6aa604 | 123 | mbed_die(); |
jmitc91516 | 0:9140ec6aa604 | 124 | } |
jmitc91516 | 0:9140ec6aa604 | 125 | } |
jmitc91516 | 0:9140ec6aa604 | 126 | |
jmitc91516 | 0:9140ec6aa604 | 127 | int main() |
jmitc91516 | 0:9140ec6aa604 | 128 | { |
jmitc91516 | 0:9140ec6aa604 | 129 | DMBoard* board = &DMBoard::instance(); |
jmitc91516 | 0:9140ec6aa604 | 130 | RtosLog* log = board->logger(); |
jmitc91516 | 0:9140ec6aa604 | 131 | Display* disp = board->display(); |
jmitc91516 | 0:9140ec6aa604 | 132 | |
jmitc91516 | 0:9140ec6aa604 | 133 | void *frameBuffer1; |
jmitc91516 | 0:9140ec6aa604 | 134 | void *frameBuffer2; |
jmitc91516 | 0:9140ec6aa604 | 135 | InitialiseLPC4088(board, &frameBuffer1, &frameBuffer2); |
jmitc91516 | 0:9140ec6aa604 | 136 | GuiDisplay_SetFrameAddress(frameBuffer1); |
jmitc91516 | 0:9140ec6aa604 | 137 | |
jmitc91516 | 0:9140ec6aa604 | 138 | InitEasyGUIDisplay(GuiStruct_Demo_0); |
jmitc91516 | 0:9140ec6aa604 | 139 | |
jmitc91516 | 0:9140ec6aa604 | 140 | while(true) { |
jmitc91516 | 0:9140ec6aa604 | 141 | } |
jmitc91516 | 0:9140ec6aa604 | 142 | } |