Library for Mini-DK board

Dependencies:   SPI_TFT_ILI9320

Dependents:   LPC1768_Mini-DK_EasyWeb_DM9161 LPC1768_Mini-DK LPC1768_Mini-DK

Fork of Mini-DK by Frank Vannieuwkerke

Mini-DK board overview (Micro SD connector is at the bottom side)

One serial interface , uses CP2102 (USB to RS232 interface, support ISP download )

RJ45-10/100M Ethernet network interface (Ethernet PHY: DM9161)

2.8 inch TFT color LCD interface (SPI interface or 16Bit parallel interface)

Touch panel controller XPT2046 (ADS7843 compatible)

USB 2.0 interface, USB host and USB Device interface.

TF SD / MMC card (SPI) interface.

Two user buttons, One Reset button and ISP button , One INT0 button, two user-programmable LED lights

Serial ISP download, Standard 20-pin JTAG download simulation debugging interface.

Selection between external 5V power supply or USB 5V supply.

Board size: 95mm * 78mm

All IO available on extension connectors

/media/uploads/frankvnk/mini-dk_top.jpg

04/01/13

Erik Olieman (http://mbed.org/users/Sissors/) joined the code development for the Mini-DK board.

Thanks to his input, we were able to obtain a tremendous speed gain, remove warnings, ...

An overview of all modifications is stored in modifs.h

The old page (http://mbed.org/users/frankvnk/code/LPC1768_Mini-DK/) contains the demo code.

IMPORTANT : Due to a change in the mbed libraries (Stream()), we cannot use the printf instruction - we need to use <SPI_TFT>.printf (example - see main.cpp in http://mbed.org/users/frankvnk/code/LPC1768_Mini-DK/)

WARNING: filetoflash (SD to CPU flash)

The SPI_TFT library contains an option to copy an image from the SD card to the CPU flash memory. This allows you to use an image as background without speed loss when writing other text and graphics.

By default, this option is enabled.

It can be disabled by uncommenting the #define mentioned below in Mini_DK.h:

#define NO_FLASH_BUFFER

Since the flash memory has limited write endurance, DO NOT use this feature when you intend to read multiple images from the SD card (eg: when used as a photo frame).

14/01/13

A newer version of the Mini-DK has been released by the manufacturer: Mini-DK2. They replaced the DM9161 PHY with a LAN8720A PHY and better buttons are fitted on the board. All other hardware remains the same. Code for this PHY is available from the NXP MCU SW application team. This allows us to use the mbed 'EthernetInterface' library with little modifications. Further info - see http://mbed.org/forum/mbed/topic/3684/?page=1#comment-18473.

Notes:

The code in 'lpc_phy_lan8720.c' uses 'msDelay' - needs to be replaced with 'osDelay'.

A custom MAC address can be defined using following code:

extern "C" void mbed_mac_address(char * mac) {
 
// define your own MAC Address
  mac[0] = 0x00;  
  mac[1] = 0x01;  
  mac[2] = 0x02;  
  mac[3] = 0x03;  
  mac[4] = 0x04;  
  mac[5] = 0x05;           
  
};

Files at this revision

API Documentation at this revision

Comitter:
frankvnk
Date:
Wed Dec 12 12:42:22 2012 +0000
Parent:
0:ee7076d8260a
Child:
2:d0acbd263ec7
Commit message:
Replaced circle and fillcircle with draw_ellipse and fill_ellipse
; Modified rect and fillrect: use wirdth and height parameters instead of x1,y1

Changed in this revision

SPI_TFT/SPI_TFT.cpp Show annotated file Show diff for this revision Revisions of this file
SPI_TFT/SPI_TFT.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
--- a/SPI_TFT/SPI_TFT.cpp	Tue Dec 11 08:58:06 2012 +0000
+++ b/SPI_TFT/SPI_TFT.cpp	Wed Dec 12 12:42:22 2012 +0000
@@ -305,125 +305,6 @@
     _cs = 1;
 }
 
-
-void SPI_TFT::circle(int x0, int y0, int r, int color)
-{
-    wr_reg(0x03, 0x1030);
-    WindowMax();
-
-    int draw_x0, draw_y0;
-    int draw_x1, draw_y1;
-    int draw_x2, draw_y2;
-    int draw_x3, draw_y3;
-    int draw_x4, draw_y4;
-    int draw_x5, draw_y5;
-    int draw_x6, draw_y6;
-    int draw_x7, draw_y7;
-    int xx, yy;
-    int di;
-    if (r == 0) {       /* no radius */
-        return;
-    }
-
-    draw_x0 = draw_x1 = x0;
-    draw_y0 = draw_y1 = y0 + r;
-    if (draw_y0 < height()) {
-        pixel(draw_x0, draw_y0, color);     /* 90 degree */
-    }
-
-    draw_x2 = draw_x3 = x0;
-    draw_y2 = draw_y3 = y0 - r;
-    if (draw_y2 >= 0) {
-        pixel(draw_x2, draw_y2, color);    /* 270 degree */
-    }
-
-    draw_x4 = draw_x6 = x0 + r;
-    draw_y4 = draw_y6 = y0;
-    if (draw_x4 < width()) {
-        pixel(draw_x4, draw_y4, color);     /* 0 degree */
-    }
-
-    draw_x5 = draw_x7 = x0 - r;
-    draw_y5 = draw_y7 = y0;
-    if (draw_x5>=0) {
-        pixel(draw_x5, draw_y5, color);     /* 180 degree */
-    }
-
-    if (r == 1) {
-        return;
-    }
-
-    di = 3 - 2*r;
-    xx = 0;
-    yy = r;
-    while (xx < yy) {
-
-        if (di < 0) {
-            di += 4*xx + 6;
-        } else {
-            di += 4*(xx - yy) + 10;
-            yy--;
-            draw_y0--;
-            draw_y1--;
-            draw_y2++;
-            draw_y3++;
-            draw_x4--;
-            draw_x5++;
-            draw_x6--;
-            draw_x7++;
-        }
-        xx++;
-        draw_x0++;
-        draw_x1--;
-        draw_x2++;
-        draw_x3--;
-        draw_y4++;
-        draw_y5++;
-        draw_y6--;
-        draw_y7--;
-
-        if ( (draw_x0 <= width()) && (draw_y0>=0) ) {
-            pixel(draw_x0, draw_y0, color);
-        }
-
-        if ( (draw_x1 >= 0) && (draw_y1 >= 0) ) {
-            pixel(draw_x1, draw_y1, color);
-        }
-
-        if ( (draw_x2 <= width()) && (draw_y2 <= height()) ) {
-            pixel(draw_x2, draw_y2, color);
-        }
-
-        if ( (draw_x3 >=0 ) && (draw_y3 <= height()) ) {
-            pixel(draw_x3, draw_y3, color);
-        }
-
-        if ( (draw_x4 <= width()) && (draw_y4 >= 0) ) {
-            pixel(draw_x4, draw_y4, color);
-        }
-
-        if ( (draw_x5 >= 0) && (draw_y5 >= 0) ) {
-            pixel(draw_x5, draw_y5, color);
-        }
-        if ( (draw_x6 <=width()) && (draw_y6 <= height()) ) {
-            pixel(draw_x6, draw_y6, color);
-        }
-        if ( (draw_x7 >= 0) && (draw_y7 <= height()) ) {
-            pixel(draw_x7, draw_y7, color);
-        }
-    }
-    return;
-}
-
-void SPI_TFT::fillcircle(int x, int y, int r, int color)
-{
-    int i;
-    for (i = 0; i <= r; i++)
-        circle(x,y,i,color);
-}
-
-
-
 void SPI_TFT::hline(int x0, int x1, int y, int color)
 {
     unsigned int index=0;
@@ -533,35 +414,34 @@
 }
 
 
-void SPI_TFT::rect(int x0, int y0, int x1, int y1, int color)
+void SPI_TFT::rect(int x0, int y0, int w, int h, int color)
 {
-    if (x1 > x0) hline(x0,x1,y0,color);
-    else  hline(x1,x0,y0,color);
-
-    if (y1 > y0) vline(x0,y0,y1,color);
-    else vline(x0,y1,y0,color);
-
-    if (x1 > x0) hline(x0,x1,y1,color);
-    else  hline(x1,x0,y1,color);
-
-    if (y1 > y0) vline(x1,y0,y1,color);
-    else vline(x1,y1,y0,color);
+    hline(x0,x0+w,y0,color);
+    vline(x0,y0,y0+h,color);
+    hline(x0,x0+w,y0+h,color);
+    vline(x0+w,y0,y0+h,color);
 
     return;
 }
 
-
-
-void SPI_TFT::fillrect(int x0, int y0, int x1, int y1, int color)
+void SPI_TFT::fillrect(int x0, int y0, int w, int h, int color)
 {
     unsigned long int index=0;
-    int h = y1 - y0 + 1;
-    int w = x1 - x0 + 1;
+    if (w < 0)
+    {
+        x0 = x0 + w;
+        w = -w;
+    }
+    if (h < 0)
+    {
+        y0 = y0 + h;
+        h = -h;
+    }
     mod_orientation();
     window(x0,y0,w,h);
     wr_cmd(0x22);
-     _cs = 0;
-     wr_dat_start();
+    _cs = 0;
+    wr_dat_start();
 
     for( index = 0; index < h * w; index++ )
     {
@@ -571,6 +451,123 @@
     return;
 }
 
+void SPI_TFT::draw_ellipse(int xc, int yc, int a, int b, unsigned int color)
+{           /* e(x,y) = b^2*x^2 + a^2*y^2 - a^2*b^2 */
+    wr_reg(0x03, 0x1030);
+    WindowMax();
+    int x = 0, y = b;
+    long a2 = (long)a*a, b2 = (long)b*b;
+    long crit1 = -(a2/4 + a%2 + b2);
+    long crit2 = -(b2/4 + b%2 + a2);
+    long crit3 = -(b2/4 + b%2);
+    long t = -a2*y; /* e(x+1/2,y-1/2) - (a^2+b^2)/4 */
+    long dxt = 2*b2*x, dyt = -2*a2*y;
+    long d2xt = 2*b2, d2yt = 2*a2;
+
+    while (y>=0 && x<=a)
+    {
+        pixel(xc+x, yc+y, color);
+        if (x!=0 || y!=0)
+            pixel(xc-x, yc-y, color);
+        if (x!=0 && y!=0)
+        {
+            pixel(xc+x, yc-y, color);
+            pixel(xc-x, yc+y, color);
+        }
+        if (t + b2*x <= crit1 ||   /* e(x+1,y-1/2) <= 0 */
+            t + a2*y <= crit3)     /* e(x+1/2,y) <= 0 */
+            incx();
+        else if (t - a2*y > crit2) /* e(x+1/2,y-1) > 0 */
+            incy();
+        else
+        {
+            incx();
+            incy();
+        }
+    }
+}
+
+void SPI_TFT::fill_ellipse(int xc, int yc, int a, int b, unsigned int color)
+{           /* e(x,y) = b^2*x^2 + a^2*y^2 - a^2*b^2 */
+    int x = 0, y = b;
+    int rx = x, ry = y;
+    unsigned int width = 1;
+    unsigned int height = 1;
+    long a2 = (long)a*a, b2 = (long)b*b;
+    long crit1 = -(a2/4 + a%2 + b2);
+    long crit2 = -(b2/4 + b%2 + a2);
+    long crit3 = -(b2/4 + b%2);
+    long t = -a2*y; /* e(x+1/2,y-1/2) - (a^2+b^2)/4 */
+    long dxt = 2*b2*x, dyt = -2*a2*y;
+    long d2xt = 2*b2, d2yt = 2*a2;
+
+    if (b == 0)
+    {
+        fillrect(xc-a, yc, 2*a+1, 1, color);
+        return;
+    }
+
+    while (y>=0 && x<=a)
+    {
+        if (t + b2*x <= crit1 ||    /* e(x+1,y-1/2) <= 0 */
+            t + a2*y <= crit3)      /* e(x+1/2,y) <= 0 */
+        {
+            if (height == 1)
+                ; /* draw nothing */
+            else if (ry*2+1 > (height-1)*2)
+            {
+                fillrect(xc-rx, yc-ry, width, height-1, color);
+                fillrect(xc-rx, yc+ry+1, width, 1-height, color);
+                ry -= height-1;
+                height = 1;
+            }
+            else
+            {
+                fillrect(xc-rx, yc-ry, width, ry*2+1, color);
+                ry -= ry;
+                height = 1;
+            }
+            incx();
+            rx++;
+            width += 2;
+        }
+        else if (t - a2*y > crit2)      /* e(x+1/2,y-1) > 0 */
+        {
+            incy();
+            height++;
+        }
+        else
+        {
+            if (ry*2+1 > height*2)
+            {
+                fillrect(xc-rx, yc-ry, width, height, color);
+                fillrect(xc-rx, yc+ry+1, width, -height, color);
+            }
+            else
+            {
+                fillrect(xc-rx, yc-ry, width, ry*2+1, color);
+            }
+            incx();
+            incy();
+            rx++;
+            width += 2;
+            ry -= height;
+            height = 1;
+        }
+    }
+
+    if (ry > height)
+    {
+        fillrect(xc-rx, yc-ry, width, height, color);
+        fillrect(xc-rx, yc+ry+1, width, -height, color);
+    }
+    else
+    {
+        fillrect(xc-rx, yc-ry, width, ry*2+1, color);
+    }
+}
+
+
 void SPI_TFT::locate(int x, int y)
 {
     char_x = x;
--- a/SPI_TFT/SPI_TFT.h	Tue Dec 11 08:58:06 2012 +0000
+++ b/SPI_TFT/SPI_TFT.h	Wed Dec 12 12:42:22 2012 +0000
@@ -7,6 +7,8 @@
 #include "GraphicsDisplay.h"
 #include "mbed.h"
 
+#define incx() x++, dxt += d2xt, t += dxt
+#define incy() y--, dyt += d2yt, t += dyt
 
 #define SPI_F_LO    10000000
 #define SPI_F_HI    48000000
@@ -66,28 +68,6 @@
    */
   virtual void pixel(int x, int y,int colour);
 
-  /** draw a circle
-   *
-   * @param x0,y0 center
-   * @param r radius
-   * @param color 16 bit color                                                                 *
-   *
-   */
-  void circle(int x, int y, int r, int colour);
-
-  /** draw a filled circle
-   *
-   * @param x0,y0 center
-   * @param r radius
-   * @param color 16 bit color                                                                 *
-   *
-   * use circle with different radius,
-   * can miss some pixel
-   */
-  void fillcircle(int x, int y, int r, int colour);
-
-
-
   /** draw a 1 pixel line
    *
    * @param x0,y0 start point
@@ -100,20 +80,38 @@
   /** draw a rect
    *
    * @param x0,y0 top left corner
-   * @param x1,y1 down right corner
+   * @param w,h   width and height
    * @param color 16 bit color
    *                                                   *
    */
-  void rect(int x0, int y0, int x1, int y1, int colour);
+  void rect(int x0, int y0, int w, int h, int colour);
 
   /** draw a filled rect
    *
    * @param x0,y0 top left corner
-   * @param x1,y1 down right corner
+   * @param w,h   width and height
    * @param color 16 bit color
    *
    */
-  void fillrect(int x0, int y0, int x1, int y1, int colour);
+  void fillrect(int x0, int y0, int w, int h, int colour);
+
+  /** draw an ellipse - source : http://enchantia.com/graphapp/doc/tech/ellipses.html
+   *
+   * @param xc,yc center point
+   * @param a,b semi-major axis and semi-minor axis
+   * @param color 16 bit color
+   *
+   */
+  void draw_ellipse(int xc, int yc, int a, int b, unsigned int color);
+
+  /** draw a filled ellipse - source : http://enchantia.com/graphapp/doc/tech/ellipses.html
+   *
+   * @param xc,yc center point
+   * @param a,b semi-major axis and semi-minor axis
+   * @param color 16 bit color
+   *
+   */
+  void fill_ellipse(int xc, int yc, int a, int b, unsigned int color);
 
   /** setup cursor position
    *
--- a/main.cpp	Tue Dec 11 08:58:06 2012 +0000
+++ b/main.cpp	Wed Dec 12 12:42:22 2012 +0000
@@ -60,10 +60,10 @@
     TFT.locate(120,115);
     TFT.printf("Graphic");
     TFT.line(0,0,100,200,Green);
-    TFT.rect(100,50,150,100,Red);
-    TFT.fillrect(180,25,220,70,Blue);
-    TFT.circle(80,150,33,White);
-    TFT.fillcircle(80,50,33,White);
+    TFT.rect(100,50,50,50,Red);
+    TFT.fillrect(180,25,40,45,Blue);
+    TFT.draw_ellipse(80, 150, 33, 33, White);
+    TFT.fill_ellipse(80, 50, 33, 33, White);
 
     wait(2);
 
@@ -114,12 +114,12 @@
     uint8_t r = 255, g = 0,  b = 0, step = 5, i;
     for (i=0;i<5;i++)
     {
-        for(;g<255;g+=step) {TFT.fillrect(70,110,170,210,RGB565CONVERT(r, g, b));}      // Cycle from FF0000 to FFFF00 : red to yellow
-        for(;r>0;r-=step)   {TFT.fillrect(70,110,170,210,RGB565CONVERT(r, g, b));}      // Cycle from FFFF00 to 00FF00 : yellow to green
-        for(;b<255;b+=step) {TFT.fillrect(70,110,170,210,RGB565CONVERT(r, g, b));}      // Cycle from 00FF00 to 00FFFF : green to cyan
-        for(;g>0;g-=step)   {TFT.fillrect(70,110,170,210,RGB565CONVERT(r, g, b));}      // Cycle from 00FFFF to 0000FF : cyan to blue
-        for(;r<255;r+=step) {TFT.fillrect(70,110,170,210,RGB565CONVERT(r, g, b));}      // Cycle from 0000FF to FF00FF : blue to purple
-        for(;b>0;b-=step)   {TFT.fillrect(70,110,170,210,RGB565CONVERT(r, g, b));}      // Cycle from FF00FF to FF0000 : purple to red
+       for(;g<255;g+=step) {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));}      // Cycle from FF0000 to FFFF00 : red to yellow
+        for(;r>0;r-=step)   {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));}      // Cycle from FFFF00 to 00FF00 : yellow to green
+        for(;b<255;b+=step) {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));}      // Cycle from 00FF00 to 00FFFF : green to cyan
+        for(;g>0;g-=step)   {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));}      // Cycle from 00FFFF to 0000FF : cyan to blue
+        for(;r<255;r+=step) {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));}      // Cycle from 0000FF to FF00FF : blue to purple
+        for(;b>0;b-=step)   {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));}      // Cycle from FF00FF to FF0000 : purple to red
     }
     wait(2);
 
@@ -143,7 +143,7 @@
             {
                 TFT.getDisplayPoint(&display, &screen, &matrix ) ;
                 TFT.TP_DrawPoint(display.x,display.y, Blue);
-//                TFT.rect(display.x,display.y,display.x+1,display.y+1,Red);
+//                TFT.rect(display.x,display.y,1,1,Red);
                 TFT.locate(25,0);
                 printf("%03d",display.x);
                 TFT.locate(95,0);