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