Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SPI_TFT by
Diff: SPI_TFT.cpp
- Revision:
- 17:d7e48335953e
- Parent:
- 12:9de056a58793
diff -r 9de056a58793 -r d7e48335953e SPI_TFT.cpp
--- a/SPI_TFT.cpp Tue Mar 05 15:47:00 2013 +0000
+++ b/SPI_TFT.cpp Fri Oct 18 09:11:57 2013 +0000
@@ -22,6 +22,7 @@
// 21.09.12 fix Bug in BMP_16
// 11.10.12 patch from Hans Bergles to get SPI1 working again
// 03.02.13 add a switch to switch off DMA use for LPC11U24
+// 18.10.13 Better Circle function from Michael Ammann
#include "SPI_TFT.h"
#include "mbed.h"
@@ -408,118 +409,36 @@
void SPI_TFT::circle(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 {
+ 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;
}
- 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;
+ if (e2 > x) err += ++x*2+1;
+ } while (x <= 0);
+
}
-void SPI_TFT::fillcircle(int x, int y, int r, int color)
+void SPI_TFT::fillcircle(int x0, int y0, int r, int color)
{
- int i;
- for (i = 0; i <= r; i++)
- circle(x,y,i,color);
+ 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;
+ }
+ if (e2 > x) err += ++x*2+1;
+ } while (x <= 0);
}
@@ -1084,6 +1003,7 @@
} while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI FIFO not empty
}
#else // use mbed lib
+ bitmap_ptr += ((h - 1)* (w + padd));
_spi.format(8,3); // 8 bit Mode 3
_spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0
_spi.format(16,3); // switch to 16 bit Mode 3
