Example for the LPC4088 QSB Base Board

Dependencies:   EALib mbed

Committer:
embeddedartists
Date:
Wed Apr 09 09:48:28 2014 +0000
Revision:
1:b00a5c2416a7
Parent:
0:7ce952ea2c4c
Updated to latest version of EALib

Who changed what in which revision?

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