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