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