![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Example for the LPC4088 QSB Base Board
main.cpp@3:33a36d79ab7d, 2014-04-09 (annotated)
- Committer:
- embeddedartists
- Date:
- Wed Apr 09 10:26:13 2014 +0000
- Revision:
- 3:33a36d79ab7d
- Parent:
- 0:83b8ee8e8d4b
Updated to latest version of EALib
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 0:83b8ee8e8d4b | 1 | /****************************************************************************** |
embeddedartists | 0:83b8ee8e8d4b | 2 | * Includes |
embeddedartists | 0:83b8ee8e8d4b | 3 | *****************************************************************************/ |
embeddedartists | 0:83b8ee8e8d4b | 4 | |
embeddedartists | 0:83b8ee8e8d4b | 5 | #include "mbed.h" |
embeddedartists | 0:83b8ee8e8d4b | 6 | |
embeddedartists | 0:83b8ee8e8d4b | 7 | #include "LcdController.h" |
embeddedartists | 0:83b8ee8e8d4b | 8 | #include "EaLcdBoard.h" |
embeddedartists | 0:83b8ee8e8d4b | 9 | #include "sdram.h" |
embeddedartists | 0:83b8ee8e8d4b | 10 | |
embeddedartists | 0:83b8ee8e8d4b | 11 | #include "PictureDemo.h" |
embeddedartists | 0:83b8ee8e8d4b | 12 | |
embeddedartists | 0:83b8ee8e8d4b | 13 | |
embeddedartists | 0:83b8ee8e8d4b | 14 | /****************************************************************************** |
embeddedartists | 0:83b8ee8e8d4b | 15 | * Typedefs and defines |
embeddedartists | 0:83b8ee8e8d4b | 16 | *****************************************************************************/ |
embeddedartists | 0:83b8ee8e8d4b | 17 | |
embeddedartists | 0:83b8ee8e8d4b | 18 | #define RESET_FLAG \ |
embeddedartists | 0:83b8ee8e8d4b | 19 | do { \ |
embeddedartists | 0:83b8ee8e8d4b | 20 | if (abortTest) { \ |
embeddedartists | 0:83b8ee8e8d4b | 21 | abortTest = false; \ |
embeddedartists | 0:83b8ee8e8d4b | 22 | wait(0.04); \ |
embeddedartists | 0:83b8ee8e8d4b | 23 | } \ |
embeddedartists | 0:83b8ee8e8d4b | 24 | } while(false) |
embeddedartists | 0:83b8ee8e8d4b | 25 | |
embeddedartists | 0:83b8ee8e8d4b | 26 | /****************************************************************************** |
embeddedartists | 0:83b8ee8e8d4b | 27 | * Local variables |
embeddedartists | 0:83b8ee8e8d4b | 28 | *****************************************************************************/ |
embeddedartists | 0:83b8ee8e8d4b | 29 | |
embeddedartists | 0:83b8ee8e8d4b | 30 | static InterruptIn buttonInterrupt(P2_10); |
embeddedartists | 0:83b8ee8e8d4b | 31 | static DigitalOut led(LED1); |
embeddedartists | 0:83b8ee8e8d4b | 32 | |
embeddedartists | 0:83b8ee8e8d4b | 33 | /****************************************************************************** |
embeddedartists | 0:83b8ee8e8d4b | 34 | * Global variables |
embeddedartists | 0:83b8ee8e8d4b | 35 | *****************************************************************************/ |
embeddedartists | 0:83b8ee8e8d4b | 36 | |
embeddedartists | 0:83b8ee8e8d4b | 37 | EaLcdBoard lcdBoard(P0_27, P0_28); |
embeddedartists | 0:83b8ee8e8d4b | 38 | bool abortTest = false; |
embeddedartists | 0:83b8ee8e8d4b | 39 | |
embeddedartists | 0:83b8ee8e8d4b | 40 | /****************************************************************************** |
embeddedartists | 0:83b8ee8e8d4b | 41 | * Interrupt functions |
embeddedartists | 0:83b8ee8e8d4b | 42 | *****************************************************************************/ |
embeddedartists | 0:83b8ee8e8d4b | 43 | |
embeddedartists | 0:83b8ee8e8d4b | 44 | void trigger() { |
embeddedartists | 0:83b8ee8e8d4b | 45 | abortTest = true; |
embeddedartists | 0:83b8ee8e8d4b | 46 | } |
embeddedartists | 0:83b8ee8e8d4b | 47 | |
embeddedartists | 0:83b8ee8e8d4b | 48 | /****************************************************************************** |
embeddedartists | 0:83b8ee8e8d4b | 49 | * Main |
embeddedartists | 0:83b8ee8e8d4b | 50 | *****************************************************************************/ |
embeddedartists | 0:83b8ee8e8d4b | 51 | |
embeddedartists | 0:83b8ee8e8d4b | 52 | int main (void) { |
embeddedartists | 0:83b8ee8e8d4b | 53 | |
embeddedartists | 0:83b8ee8e8d4b | 54 | EaLcdBoard::Result result; |
embeddedartists | 0:83b8ee8e8d4b | 55 | LcdController::Config lcdCfg; |
embeddedartists | 0:83b8ee8e8d4b | 56 | uint32_t frameBuf1; |
embeddedartists | 0:83b8ee8e8d4b | 57 | |
embeddedartists | 0:83b8ee8e8d4b | 58 | printf("EA LCD Board Picture Demo\n"); |
embeddedartists | 0:83b8ee8e8d4b | 59 | |
embeddedartists | 0:83b8ee8e8d4b | 60 | // Listen for button presses |
embeddedartists | 0:83b8ee8e8d4b | 61 | buttonInterrupt.mode(PullUp); |
embeddedartists | 0:83b8ee8e8d4b | 62 | buttonInterrupt.fall(&trigger); |
embeddedartists | 0:83b8ee8e8d4b | 63 | |
embeddedartists | 0:83b8ee8e8d4b | 64 | do { |
embeddedartists | 0:83b8ee8e8d4b | 65 | // framebuffer is put in SDRAM |
embeddedartists | 0:83b8ee8e8d4b | 66 | if (sdram_init() == 1) { |
embeddedartists | 0:83b8ee8e8d4b | 67 | printf("Failed to initialize SDRAM\n"); |
embeddedartists | 0:83b8ee8e8d4b | 68 | break; |
embeddedartists | 0:83b8ee8e8d4b | 69 | } |
embeddedartists | 0:83b8ee8e8d4b | 70 | |
embeddedartists | 0:83b8ee8e8d4b | 71 | result = lcdBoard.open(NULL, NULL); |
embeddedartists | 0:83b8ee8e8d4b | 72 | if (result != EaLcdBoard::Ok) { |
embeddedartists | 0:83b8ee8e8d4b | 73 | printf("Failed to open display: %d\n", result); |
embeddedartists | 0:83b8ee8e8d4b | 74 | break; |
embeddedartists | 0:83b8ee8e8d4b | 75 | } |
embeddedartists | 0:83b8ee8e8d4b | 76 | |
embeddedartists | 0:83b8ee8e8d4b | 77 | result = lcdBoard.getLcdConfig(&lcdCfg); |
embeddedartists | 0:83b8ee8e8d4b | 78 | if (result != EaLcdBoard::Ok) { |
embeddedartists | 0:83b8ee8e8d4b | 79 | printf("Failed to get LCD configuration: %d\n", result); |
embeddedartists | 0:83b8ee8e8d4b | 80 | break; |
embeddedartists | 0:83b8ee8e8d4b | 81 | } |
embeddedartists | 0:83b8ee8e8d4b | 82 | |
embeddedartists | 0:83b8ee8e8d4b | 83 | // Prepare 3 consequtive framebuffers (2 will be used for background buffers) |
embeddedartists | 0:83b8ee8e8d4b | 84 | frameBuf1 = (uint32_t)malloc(lcdCfg.width*lcdCfg.height*2 *3); |
embeddedartists | 0:83b8ee8e8d4b | 85 | if (frameBuf1 == NULL) { |
embeddedartists | 0:83b8ee8e8d4b | 86 | printf("Failed to allocate memory for the frame buffer\n"); |
embeddedartists | 0:83b8ee8e8d4b | 87 | break; |
embeddedartists | 0:83b8ee8e8d4b | 88 | } |
embeddedartists | 0:83b8ee8e8d4b | 89 | memset((void*)frameBuf1, 0x0, lcdCfg.width*lcdCfg.height*2 *3); |
embeddedartists | 0:83b8ee8e8d4b | 90 | |
embeddedartists | 0:83b8ee8e8d4b | 91 | result = lcdBoard.setFrameBuffer(frameBuf1); |
embeddedartists | 0:83b8ee8e8d4b | 92 | if (result != EaLcdBoard::Ok) { |
embeddedartists | 0:83b8ee8e8d4b | 93 | printf("Failed to activate frameBuffer: %d\n", result); |
embeddedartists | 0:83b8ee8e8d4b | 94 | break; |
embeddedartists | 0:83b8ee8e8d4b | 95 | } |
embeddedartists | 0:83b8ee8e8d4b | 96 | |
embeddedartists | 0:83b8ee8e8d4b | 97 | PictureDemo pictureDemo((uint8_t *)frameBuf1, lcdCfg.width, lcdCfg.height); |
embeddedartists | 0:83b8ee8e8d4b | 98 | while (1) { |
embeddedartists | 0:83b8ee8e8d4b | 99 | |
embeddedartists | 0:83b8ee8e8d4b | 100 | //Display Picture 1 for two seconds |
embeddedartists | 0:83b8ee8e8d4b | 101 | pictureDemo.run(1, 2000); |
embeddedartists | 0:83b8ee8e8d4b | 102 | RESET_FLAG; |
embeddedartists | 0:83b8ee8e8d4b | 103 | |
embeddedartists | 0:83b8ee8e8d4b | 104 | //Display Picture 2 for three seconds |
embeddedartists | 0:83b8ee8e8d4b | 105 | pictureDemo.run(2, 3000); |
embeddedartists | 0:83b8ee8e8d4b | 106 | RESET_FLAG; |
embeddedartists | 0:83b8ee8e8d4b | 107 | } |
embeddedartists | 0:83b8ee8e8d4b | 108 | } while(0); |
embeddedartists | 0:83b8ee8e8d4b | 109 | |
embeddedartists | 0:83b8ee8e8d4b | 110 | // Blink to indicate error |
embeddedartists | 0:83b8ee8e8d4b | 111 | while (1) { |
embeddedartists | 0:83b8ee8e8d4b | 112 | led = 0; |
embeddedartists | 0:83b8ee8e8d4b | 113 | wait(0.2); |
embeddedartists | 0:83b8ee8e8d4b | 114 | led = 1; |
embeddedartists | 0:83b8ee8e8d4b | 115 | wait(0.2); |
embeddedartists | 0:83b8ee8e8d4b | 116 | } |
embeddedartists | 0:83b8ee8e8d4b | 117 | } |