Example using the support package for LPC4088 DisplayModule

Dependencies:   DMBasicGUI DMSupport

Example using a lot of the features in the software package for the LPC4088 Display Module.

This project can be selected as a template when creating a new project based on the LPC4088 Display Module.

Information

This project works on the 4.3" display modules.

Some of the apps works on the 5" display modules. The ImageViewer and Slideshow app will show the images distorted as it does not take the resolution into consideration.

Information

The USB Status app is disabled. The Image viewer looks for images in the root of SD cards, USB memory sticks or the file system on the QSPI flash. The Slideshow app expects to find a slideshow script in /mci/elec14/ea_logo.txt.

This is what it looks like on the 4.3" display:

/media/uploads/embeddedartists/everything_cap_000.png /media/uploads/embeddedartists/everything_cap_001.png /media/uploads/embeddedartists/everything_cap_003.png /media/uploads/embeddedartists/everything_cap_004.png /media/uploads/embeddedartists/everything_cap_006.png /media/uploads/embeddedartists/everything_cap_008.png

Files at this revision

API Documentation at this revision

Comitter:
embeddedartists
Date:
Tue Dec 02 15:23:10 2014 +0000
Child:
1:15ea03d72dd7
Commit message:
First version

Changed in this revision

DMSupport.lib Show annotated file Show diff for this revision Revisions of this file
Graphics.cpp Show annotated file Show diff for this revision Revisions of this file
Graphics.h Show annotated file Show diff for this revision Revisions of this file
HttpServer.lib Show annotated file Show diff for this revision Revisions of this file
dm_board_config.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rpc.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DMSupport.lib	Tue Dec 02 15:23:10 2014 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/embeddedartists/code/DMSupport/#887c6b45e7fa
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Graphics.cpp	Tue Dec 02 15:23:10 2014 +0000
@@ -0,0 +1,243 @@
+
+#include "mbed.h"
+#include "Graphics.h"
+
+
+Graphics::Graphics(uint16_t *pFrmBuf, uint16_t dispWidth, uint16_t dispHeight)
+{
+	this->windowX = dispWidth;
+	this->windowY = dispHeight;
+	this->pFrmBuf = pFrmBuf;
+}
+
+void Graphics::setFrameBuffer( uint16_t *pFrmBuf )
+{
+	this->pFrmBuf = pFrmBuf;
+}
+
+int32_t Graphics::abs(int32_t v1) const
+{
+   if (v1 > 0)
+     return v1;
+
+  return -v1;
+}
+
+/***********************************************************************
+ *
+ * Function: swim_put_line_raw
+ *
+ * Purpose: Draw a line on the physical display
+ *
+ * Processing:
+ *     See function.
+ *
+ * Parameters:
+ *     win : Window identifier
+ *     x1  : Physical X position of X line start
+ *     y1  : Physical Y position of Y line start
+ *     x2  : Physical X position of X line end
+ *     y2  : Physical Y position of Y line end
+ *
+ * Outputs: None
+ *
+ * Returns: Nothing
+ *
+ * Notes: None
+ *
+ **********************************************************************/
+void Graphics::put_line(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int16_t color)
+{
+    int32_t e2, sx, sy, dx, dy, err;
+    
+    /* calculate delta_x and delta_y */
+    dx = abs(x2 - x1);
+    dy = abs(y2 - y1);
+
+    /* set the direction for the step for both x and y, and
+       initialize the error */
+    if (x1 < x2)
+        sx = 1;
+    else
+        sx = -1;
+
+    if (y1 < y2)
+        sy = 1;
+    else
+        sy = -1;
+
+    err = dx - dy;
+   
+    while (1)
+    {
+        if ((x1 >= 0) && (x1 < this->windowX) && 
+            (y1 >= 0) && (y1 < this->windowY))
+            this->pFrmBuf[x1 + (this->windowX*y1)] = color;
+
+        if ((x1 == x2) && (y1 == y2))
+            return;
+
+        e2 = 2 * err;
+        if (e2 > -dy)
+        {
+            err -= dy;
+            x1 += sx;
+        }
+        if (e2 < dx)
+        {
+            err += dx;
+            y1 += sy;
+        }
+    }
+}
+
+/***********************************************************************
+ *
+ * Function: plot4points
+ *
+ * Purpose:
+ *
+ * Processing:
+ *     See function.
+ *
+ * Parameters:
+ *     win    : Window identifier
+ *     cx     :
+ *     cy     :
+ *     x      :
+ *     y      :
+ *     Filled :
+ *
+ * Outputs: None
+ *
+ * Returns: Nothing
+ *
+ * Notes: None
+ *
+ **********************************************************************/
+void Graphics::plot4points( int32_t cx, int32_t cy, int32_t x, int32_t y, int16_t color, int32_t Filled )
+   {
+   int16_t x0, x1, y0, y1;
+
+   y0 = cy + y;
+   y1 = cy - y;
+   if( Filled )
+      {
+      for( x0=cx - x; x0<=cx + x; x0++ )
+         {
+         if ((x0>=0) && (x0<this->windowX) && (y0>=0) && (y0<this->windowY))
+            this->pFrmBuf[x0 + (this->windowX*y0)] = color;
+         if ((x0>=0) && (x0<this->windowX) && (y1>=0) && (y1<this->windowY))
+            this->pFrmBuf[x0 + (this->windowX*y1)] = color;
+         }
+      }
+   else
+      {
+      x0 = cx + x;
+      x1 = cx - x;
+      if ((x0>=0) && (x0<this->windowX) && (y0>=0) && (y0<this->windowY))
+         this->pFrmBuf[x0 + (this->windowX*y0)] = color;
+      if ((x != 0) && 
+          (x1>=0) && (x1<this->windowX) && (y0>=0) && (y0<this->windowY))
+         this->pFrmBuf[x1 + (this->windowX*y0)] = color;
+      if ((y != 0) &&
+          (x0>=0) && (x0<this->windowX) && (y1>=0) && (y1<this->windowY))
+         this->pFrmBuf[x0 + (this->windowX*y1)] = color;
+      if ((x != 0 && y != 0) &&
+          (x1>=0) && (x1<this->windowX) && (y1>=0) && (y1<this->windowY))
+         this->pFrmBuf[x1 + (this->windowX*y1)] = color;
+      }
+   }
+
+/***********************************************************************
+ *
+ * Function: plot8points
+ *
+ * Purpose:
+ *
+ * Processing:
+ *     See function.
+ *
+ * Parameters:
+ *     win    : Window identifier
+ *     cx     :
+ *     cy     :
+ *     x      :
+ *     y      :
+ *     Filled :
+ *
+ * Outputs: None
+ *
+ * Returns: Nothing
+ *
+ * Notes: None
+ *
+ **********************************************************************/
+void Graphics::plot8points( int32_t cx, int32_t cy, int32_t x, int32_t y, int16_t color, int32_t Filled )
+   {
+   plot4points( cx, cy, x, y, color, Filled );
+   if (x != y)
+      plot4points( cx, cy, y, x, color, Filled );
+   }
+
+/***********************************************************************
+ *
+ * Function: swim_put_circle
+ *
+ * Purpose:
+ *
+ * Processing:
+ *     See function.
+ *
+ * Parameters:
+ *     win    : Window identifier
+ *     cx     :
+ *     cy     :
+ *     radius :
+ *     Filled :
+ *
+ * Outputs: None
+ *
+ * Returns: Nothing
+ *
+ * Notes: None
+ *
+ **********************************************************************/
+void Graphics::put_circle( int32_t cx, int32_t cy, int16_t color, int32_t radius, int32_t Filled )
+   {
+   int32_t Error = -radius;
+   int16_t x = radius;
+   int16_t y = 0;
+
+   while( x >= y )
+      {
+      plot8points( cx, cy, x, y, color, Filled );
+
+      Error += y;
+      ++y;
+      Error += y;
+
+      if( Error >= 0 )
+         {
+         --x;
+         Error -= x;
+         Error -= x;
+         }
+      }
+   }
+
+void Graphics::put_dot( int32_t cx, int32_t cy, int16_t color )
+{
+  int size = 1;
+  for (int y1 = cy - size; y1 <= (cy + size); y1++) {
+    for (int x1 = cx - size; x1 <= (cx + size); x1++) {
+      if ((x1 >= 0) && (x1 < this->windowX) && (y1 >= 0) && (y1 < this->windowY)) {
+          this->pFrmBuf[x1 + (this->windowX*y1)] = color;
+      }
+    }
+  }
+}
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Graphics.h	Tue Dec 02 15:23:10 2014 +0000
@@ -0,0 +1,69 @@
+
+#ifndef GRAPHICS_H
+#define GRAPHICS_H
+
+/**
+ * LcdController example
+ *
+ * @code
+ * #include "mbed.h"
+ * #include "LcdController.h"
+ *
+ * LcdController::Config innolux(
+ *        45,
+ *        17,
+ *        2,
+ *        800,
+ *        22,
+ *        22,
+ *        2,
+ *        480,
+ *        false,
+ *        false,
+ *        true,
+ *        true,
+ *        true,
+ *        LcdController::Bpp_16_565,
+ *        36000000,
+ *        LcdController::Tft,
+ *        false);
+ *
+ * int main(void) {
+ *    LcdController lcd;
+ *
+ *    lcd.open(&innolux);
+ *    lcd.setFrameBuffer(frameBuffer);
+ *    lcd.setPower(true);
+ *
+ *    // draw on the frame buffer
+ *    ...
+ * }
+ * @endcode
+ */
+class Graphics {
+public:
+
+	Graphics(uint16_t *pFrmBuf, uint16_t dispWidth, uint16_t dispHeight);
+
+	void setFrameBuffer( uint16_t *pFrmBuf );
+	void put_line(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int16_t color);
+    void put_circle( int32_t cx, int32_t cy, int16_t color, int32_t radius, int32_t Filled );
+    void put_dot( int32_t cx, int32_t cy, int16_t color );
+
+protected:
+	uint16_t windowX;
+	uint16_t windowY;
+	uint16_t *pFrmBuf;
+	
+    int32_t abs(int32_t v1) const;
+    
+    virtual void plot4points( int32_t cx, int32_t cy, int32_t x, int32_t y, int16_t color, int32_t Filled );
+    void plot8points( int32_t cx, int32_t cy, int32_t x, int32_t y, int16_t color, int32_t Filled );
+    
+};
+
+#endif
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HttpServer.lib	Tue Dec 02 15:23:10 2014 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/yueee_yt/code/HttpServer/#7b3320c34654
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dm_board_config.h	Tue Dec 02 15:23:10 2014 +0000
@@ -0,0 +1,38 @@
+/*
+ *  Copyright 2014 Embedded Artists AB
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#ifndef DM_BOARD_CONFIG_H
+#define DM_BOARD_CONFIG_H
+
+// Template to use for the project-specific settings. Copy this file to your project,
+// rename it to dm_board_config.h and uncomment the wanted features below:
+
+// #define DM_BOARD_USE_USB_DEVICE
+// #define DM_BOARD_USE_USB_HOST
+#define DM_BOARD_USE_MCI_FS
+#define DM_BOARD_USE_QSPI_FS
+// #define DM_BOARD_USE_QSPI
+#define DM_BOARD_USE_DISPLAY
+#define DM_BOARD_USE_TOUCH
+// #define DM_BOARD_USE_ETHERNET
+// #define DM_BOARD_USE_XBEE
+#define DM_BOARD_USE_FAST_UART
+// #define DM_BOARD_USE_INT_EEPROM_WRITE
+// #define DM_BOARD_DISABLE_STANDARD_PRINTF
+
+#define DM_BOARD_USE_4_3_DISPLAY_TMP /* temporary while debugging */
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Dec 02 15:23:10 2014 +0000
@@ -0,0 +1,330 @@
+/******************************************************************************
+ * Includes
+ *****************************************************************************/
+ 
+#include "mbed.h"
+#include "mbed_interface.h"
+#include "rtos.h"
+#include "EthernetInterface.h"
+#include "HTTPServer.h"
+#include "mbed_rpc.h"
+#include "USBHostMSD.h"
+
+#include "DMBoard.h"
+#include "Graphics.h"
+
+/******************************************************************************
+ * Typedefs and defines
+ *****************************************************************************/
+
+/* Number of colors in 565 mode */
+#define NUM_COLORS    65536
+/* Number of red colors in 565 mode */
+#define RED_COLORS    0x20
+/* Number of green colors in 565 mode */
+#define GREEN_COLORS  0x40
+/* Number of blue colors in 565 mode */
+#define BLUE_COLORS   0x20
+/* Black color, 565 mode */
+#define BLACK         0x0000
+
+/******************************************************************************
+ * Local variables
+ *****************************************************************************/
+
+EthernetInterface eth;
+
+/******************************************************************************
+ * Global variables
+ *****************************************************************************/
+
+/******************************************************************************
+ * Local functions
+ *****************************************************************************/
+
+static void verticalLine16(uint16_t* framebuffer, int w, int x, int y0, int y1, uint16_t color)
+{
+    if (x < w) {
+        int h = y1 - y0 + 1;
+        uint16_t* fb = framebuffer;
+        fb += x;
+        fb += y0 * w;
+        for (int i = 0; i < h; i++) {
+            *fb = color;
+            fb += w;
+        }
+    }
+}
+
+/**
+ * Draw color bars to the display
+ */
+static void drawBars565(uint16_t* framebuffer, int w, int h)
+{
+  uint16_t clr;
+  uint16_t xgs, ygs, curx, cury, curym, xidx;
+  int idx;
+
+  /* Compute vertical size for bars */
+  ygs = h / 3;
+
+  /* Draw Red bars */
+  cury = 0;
+  curx = 0;
+  curym = ygs - 1;
+  xgs = w / RED_COLORS;
+  clr = BLACK;
+  for (xidx = 0; xidx < RED_COLORS; xidx++)
+  {
+      //swim_set_pen_color(win1, clr);
+      for (idx = 0; idx <= xgs; idx++)
+      {
+          //swim_put_line(win1, curx, cury, curx, curym);
+        //g.put_line(curx, cury, curx, curym, clr);
+          verticalLine16(framebuffer, w, curx, cury, curym, clr);
+        curx++;
+      }
+      clr = clr + 0x0800;
+  }
+
+  /* Draw green bars */
+  cury = cury + ygs;
+  curx = 0;
+  curym = cury + (ygs - 1);
+  xgs = w / GREEN_COLORS;
+  clr = BLACK;
+  for (xidx = 0; xidx < GREEN_COLORS; xidx++)
+  {
+      //swim_set_pen_color(win1, clr);
+      for (idx = 0; idx <= xgs; idx++)
+      {
+          //swim_put_line(win1, curx, cury, curx, curym);
+        //g.put_line(curx, cury, curx, curym, clr);
+          verticalLine16(framebuffer, w, curx, cury, curym, clr);
+          curx++;
+      }
+      clr = clr + 0x0020;
+  }
+
+  /* Draw blue bars */
+  cury = cury + ygs;
+  curx = 0;
+  curym = h - 1;//cury + (ygs - 1);
+  xgs = w / BLUE_COLORS;
+  clr = BLACK;
+  for (xidx = 0; xidx < BLUE_COLORS; xidx++)
+  {
+      //swim_set_pen_color(win1, clr);
+      for (idx = 0; idx <= xgs; idx++)
+      {
+          //swim_put_line(win1, curx, cury, curx, curym);
+        //g.put_line(curx, cury, curx, curym, clr);
+          verticalLine16(framebuffer, w, curx, cury, curym, clr);
+          curx++;
+      }
+      clr = clr + 0x0001;
+  }
+}
+
+
+
+void aliveTask(void const* args)
+{
+  DMBoard* board = &DMBoard::instance();
+    
+  while(true)
+  {
+    board->setLED(DMBoard::Led4, false);
+    board->setLED(DMBoard::Led1, true);
+    Thread::wait(300);
+    board->setLED(DMBoard::Led1, false);
+    board->setLED(DMBoard::Led2, true);
+    Thread::wait(300);
+    board->setLED(DMBoard::Led2, false);
+    board->setLED(DMBoard::Led3, true);
+    Thread::wait(300);
+    board->setLED(DMBoard::Led3, false);
+    board->setLED(DMBoard::Led4, true);
+    Thread::wait(300);
+  }
+}
+
+/*
+ * Reads the /message.txt file from the file system and prints the content
+ */
+void readMessageFile(const char* prefix)
+{
+  RtosLog* log = DMBoard::instance().logger();
+  log->printf("%sTesting to read from USB\n", prefix);
+    
+  FILE * fp = fopen("/usb/test1.txt", "r");
+  
+  if (fp != NULL) {
+    uint8_t* buff = (uint8_t*)malloc(1024+1);
+    if (buff == NULL) {
+      log->printf("%sFailed to allocate memory for test\n", prefix);
+    } else {
+      int num = fread(buff, 1, 1024, fp);
+      if (num <= 0) {
+        log->printf("%sUnable to read file, got %d as result\n", prefix, num);
+      } else if (num < 1024) {
+        log->printf("%sHave read all %d bytes in the file\n", prefix, num);
+        buff[num] = '\0';
+        log->printf((const char*)buff);
+      } else {
+        log->printf("%sHave read %d bytes with more to read\n", prefix, num);
+      }
+      free(buff);
+    }
+    fclose(fp);
+  } else {
+    log->printf("%sFILE == NULL\r\n", prefix);
+  }
+}
+
+
+#if defined(DM_BOARD_USE_DISPLAY)
+#define DISPLAY_TASK_PREFIX  "[LCD] "
+void displayTask(void const* args)
+{
+  // Start display in default mode (16-bit)
+  RtosLog* log = DMBoard::instance().logger();
+  Display* disp = DMBoard::instance().display();
+  Display::DisplayError disperr;
+  uint16_t* fb = (uint16_t*)disp->allocateFramebuffer();
+  if (fb == NULL) {
+    log->printf(DISPLAY_TASK_PREFIX"Failed to allocate memory for framebuffer\r\n");
+    mbed_die();
+  }
+  drawBars565(fb, disp->width(), disp->height());
+  disperr = disp->powerUp(fb);
+  if (disperr != Display::Ok) {
+    log->printf(DISPLAY_TASK_PREFIX"Failed to initialize the display, got error %d\r\n", disperr);
+    mbed_die();
+  }
+  
+  int h = disp->height();
+  int w = disp->width();
+  uint16_t COLORS[] = { 0xFFF0, 0xF800, 0x07E0, 0x001F, 0x07FF, 0xF81F };
+  int i = 0;
+  while(true) {
+    uint16_t color = COLORS[i++ % (sizeof(COLORS)/sizeof(COLORS[0]))];
+    for (int y = 0; y < h; y++) {
+      for (int x = 0; x < w; x++) {
+        fb[y*w+x] = color;
+      }
+      Thread::wait(30);
+    }
+    
+    // test to read the message file
+    //readMessageFile(DISPLAY_TASK_PREFIX);
+  }
+}
+#endif //DM_BOARD_USE_DISPLAY
+
+#define MSD_TASK_PREFIX  "[MSD] "
+
+void msdTask(void const* args)
+{
+  USBHostMSD msd("usb");
+  USBHost* host = USBHost::getHostInst();
+  RtosLog* log = DMBoard::instance().logger();
+    
+  log->printf(MSD_TASK_PREFIX"msdTask started\n");
+  
+    while(1) {
+        
+        log->printf(MSD_TASK_PREFIX"Attempting to connect...\n");
+      
+        // try to connect a MSD device
+        while(!msd.connect()) {
+//            log->printf(MSD_TASK_PREFIX"Failed to connect, waiting 5s and trying again!\n");
+//            Thread::wait(5000);
+            log->printf(MSD_TASK_PREFIX"Failed to connect, press button to try again!\n");
+            while(!DMBoard::instance().buttonPressed()) {
+                Thread::wait(20);
+            }
+            Thread::wait(40);
+            while(DMBoard::instance().buttonPressed()) {
+                Thread::wait(20);
+            }
+            log->printf(MSD_TASK_PREFIX"Attempting to connect...\n");
+        }
+        
+        log->printf(MSD_TASK_PREFIX"Connected!\n");
+
+        // read a file
+        readMessageFile(MSD_TASK_PREFIX);
+        
+        // if/when the device is disconnected, we try to connect it again
+        while(1) {
+            
+            Thread::wait(500);
+        
+            // if device disconnected, try to connect again
+            if (!msd.connected())
+                break;
+        }
+        log->printf(MSD_TASK_PREFIX"Disconnected\n");
+    }
+}
+
+#define NET_TASK_PREFIX  "[NET] "
+
+void netTask(void const* args)
+{
+  RtosLog* log = DMBoard::instance().logger();
+  log->printf(NET_TASK_PREFIX"EthernetInterface Setting up...\r\n");
+  if(eth.init()!=0) {                             //for DHCP Server
+     //if(eth.init(IPAddress,NetMasks,Gateway)!=0) { //for Static IP Address
+     log->printf(NET_TASK_PREFIX"EthernetInterface Initialize Error \r\n");
+     mbed_die();
+  }
+  if(eth.connect()!=0) {
+     log->printf(NET_TASK_PREFIX"EthernetInterface Connect Error \r\n");
+     mbed_die();
+  }
+  
+  log->printf(NET_TASK_PREFIX"IP Address is %s\r\n", eth.getIPAddress());
+  log->printf(NET_TASK_PREFIX"NetMask is %s\r\n", eth.getNetworkMask());
+  log->printf(NET_TASK_PREFIX"Gateway Address is %s\r\n", eth.getGateway());
+  log->printf(NET_TASK_PREFIX"Ethernet Setup OK\r\n");
+
+  HTTPServerAddHandler<SimpleHandler>("/hello"); //Default handler
+  FSHandler::mount("/usb", "/");
+  HTTPServerAddHandler<FSHandler>("/");
+  //HTTPServerAddHandler<RPCHandler>("/rpc");
+  //lcd.locate(0,0);
+  //lcd.printf("%s",eth.getIPAddress());
+  HTTPServerStart(80);
+}
+
+/******************************************************************************
+ * Main function
+ *****************************************************************************/
+int main()
+{
+  DMBoard::BoardError err;
+  DMBoard* board = &DMBoard::instance();
+  RtosLog* log = board->logger();
+  err = board->init();
+  if (err != DMBoard::Ok) {
+    log->printf("Failed to initialize the board, got error %d\r\n", err);
+    mbed_die();
+  }
+  
+  log->printf("\n\n---\nMulti-threaded demo\nBuilt: " __DATE__ " at " __TIME__ "\n\n");
+  
+  log->printf("Press button to start...\r\n");
+  while(!board->buttonPressed());
+  while(board->buttonPressed());
+  
+  Thread tAlive(aliveTask);
+#if defined(DM_BOARD_USE_DISPLAY)
+  Thread tDisplay(displayTask, NULL, osPriorityNormal, 8192);
+#endif  
+  Thread tMemstick(msdTask, NULL, osPriorityNormal, 8192);
+  Thread tNetwork(netTask, NULL, osPriorityNormal, 8192);
+  
+  while(1) { wait(5); }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rpc.lib	Tue Dec 02 15:23:10 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rpc/#2a26fd6a2b36