Adapted from Peter Dresche's original for Waveshare 2.8inch TFT Touch Shield Board and Mbed 6. RGB order reversed by changing reg 16 commands, spi write code adjusted as there is no reset pin but there is data command pin. Wait commands changed for new thread_sleep style, Stream class explicitly included. Library to control a QVGA TFT connected to SPI. You can use printf to print text The lib can handle different fonts, draw lines, circles, rect and bmp

Files at this revision

API Documentation at this revision

Comitter:
dreschpe
Date:
Tue Oct 22 20:17:29 2013 +0000
Parent:
16:2efcbb2814fa
Child:
19:40a5d0425259
Commit message:
The last change was made on the wrong code. Fix back the kinetis support .

Changed in this revision

SPI_TFT.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/SPI_TFT.cpp	Mon Mar 25 10:11:00 2013 +0000
+++ b/SPI_TFT.cpp	Tue Oct 22 20:17:29 2013 +0000
@@ -24,6 +24,7 @@
 // 03.02.13 add a switch to switch off DMA use for LPC11U24
 // 04.03.13 add support for new Kinetis board
 // 25.03.13 fix Bug in bitmap for Kinetis board
+// 18.10.13 Better Circle function from Michael Ammann
 
 #include "SPI_TFT.h"
 #include "mbed.h"
@@ -450,120 +451,37 @@
     _cs = 1;
 }
 
-// draw circle
 void SPI_TFT::circle(int x0, int y0, int r, int color)
+{  
+    int x = -r, y = 0, err = 2-2*r, e2;
+    do {
+        pixel(x0-x, y0+y,color);
+        pixel(x0+x, y0+y,color);
+        pixel(x0+x, y0-y,color);
+        pixel(x0-x, y0-y,color);
+        e2 = err;
+        if (e2 <= y) {
+            err += ++y*2+1;
+            if (-x == y && e2 <= x) e2 = 0;
+        }
+        if (e2 > x) err += ++x*2+1;
+    } while (x <= 0);
+        
+}
+ 
+void SPI_TFT::fillcircle(int x0, int y0, int r, int color)
 {
-
-    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;
-    //WindowMax();
-    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++;
+    int x = -r, y = 0, err = 2-2*r, e2;
+    do {
+        vline(x0-x, y0-y, y0+y, color);
+        vline(x0+x, y0-y, y0+y, color);
+        e2 = err;
+        if (e2 <= y) {
+            err += ++y*2+1;
+            if (-x == y && e2 <= x) e2 = 0;
         }
-        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);
+        if (e2 > x) err += ++x*2+1;
+    } while (x <= 0);
 }