aboutsummaryrefslogtreecommitdiffstats
path: root/glcd
diff options
context:
space:
mode:
authortrsaunders <trsaunders@gmail.com>2012-07-24 17:22:50 +0100
committertrsaunders <trsaunders@gmail.com>2012-07-24 17:22:50 +0100
commite4094ad4681e2d73c1a22c60a7dd16835f9b7287 (patch)
tree8db74abf04b378191b7d036011b09ed32bb58ebc /glcd
parent4ba0eb23a7d41a0f2afee3fd64b9ed56684bf865 (diff)
parent8d7a588c5185558fdc85da867a37ecf09026bb3c (diff)
downloaduGFX-e4094ad4681e2d73c1a22c60a7dd16835f9b7287.tar.gz
uGFX-e4094ad4681e2d73c1a22c60a7dd16835f9b7287.tar.bz2
uGFX-e4094ad4681e2d73c1a22c60a7dd16835f9b7287.zip
get pixel return value implemented in struct
Diffstat (limited to 'glcd')
-rw-r--r--glcd/fastMath.c29
-rw-r--r--glcd/fastMath.h5
-rw-r--r--glcd/glcd.c108
-rw-r--r--glcd/glcd.h3
-rw-r--r--glcd/glcdWorker.h (renamed from glcd/worker.h)4
5 files changed, 75 insertions, 74 deletions
diff --git a/glcd/fastMath.c b/glcd/fastMath.c
index 26ae0d3f..1957b304 100644
--- a/glcd/fastMath.c
+++ b/glcd/fastMath.c
@@ -116,44 +116,39 @@ float sintable[91] = {
};
-float getSin(unsigned int degree)
-{
+float getSin(unsigned int degree) {
degree = degree % 360;
- if(degree <= 90)
- {
+
+ if(degree <= 90) {
return sintable[degree];
}
- else if(degree <= 180)
- {
+ else if(degree <= 180) {
return sintable[180-degree];
}
- else if(degree <= 270)
- {
+ else if(degree <= 270) {
return sintable[degree-180]*(-1.0);
}
- else
- {
+ else {
return sintable[360-degree]*(-1.0);
}
}
-double getCos(unsigned int degree)
-{
+double getCos(unsigned int degree) {
degree = degree % 360;
+
return getSin(degree+90);
}
/* signum function */
-char sgn(char x){
+char sgn(char x) {
return (x > 0) ? 1 : (x < 0) ? -1 : 0;
}
-unsigned char max(unsigned char a, unsigned char b)
-{
+unsigned char max(unsigned char a, unsigned char b) {
return (a<b) ? b : a;
}
-unsigned char min (unsigned char a, unsigned char b)
-{
+unsigned char min (unsigned char a, unsigned char b) {
return (a<b) ? a : b;
}
+
diff --git a/glcd/fastMath.h b/glcd/fastMath.h
index 674f2394..db4c7329 100644
--- a/glcd/fastMath.h
+++ b/glcd/fastMath.h
@@ -19,12 +19,13 @@
* Copyright: 2011 Roland Domke
*/
-#ifndef FASTMATH_H_
-#define FASTMATH_H_
+#ifndef FASTMATH_H
+#define FASTMATH_H
char sgn(char x);
double getCos(unsigned int degree);
double getSin(unsigned int degree);
unsigned char max(unsigned char a, unsigned char b);
unsigned char min(unsigned char a, unsigned char b);
+
#endif /* FASTMATH_H_ */
diff --git a/glcd/glcd.c b/glcd/glcd.c
index 70936288..6f61cb5c 100644
--- a/glcd/glcd.c
+++ b/glcd/glcd.c
@@ -1,6 +1,4 @@
#include "glcd.h"
-#include <stdlib.h>
-#include <math.h>
#define EMSG(a) const struct a *emsg = (const struct a*)msg
@@ -68,8 +66,9 @@ static msg_t ThreadGLCDWorker(void *arg) {
}
case GLCD_GET_PIXEL_COLOR: {
- /* ToDo */
-
+ EMSG(glcd_msg_get_pixel_color);
+ ((struct glcd_msg_get_pixel_color *)emsg)->color =
+ lld_lcdGetPixelColor(emsg->x, emsg->y);
result = GLCD_DONE;
break;
}
@@ -110,6 +109,7 @@ static msg_t ThreadGLCDWorker(void *arg) {
/* Done, release msg again. */
chMsgRelease(p, (msg_t)result);
+
}
return 0;
@@ -206,16 +206,14 @@ glcd_result_t lcdClear(uint16_t color) {
uint16_t lcdGetPixelColor(uint16_t x, uint16_t y) {
struct glcd_msg_get_pixel_color msg;
- uint16_t result;
msg.action = GLCD_GET_PIXEL_COLOR;
msg.x = x;
msg.y = y;
- msg.color = &result;
chMsgSend(workerThread, (msg_t)&msg);
- return result;
+ return msg.color;
}
glcd_result_t lcdDrawPixel(uint16_t x, uint16_t y, uint16_t color) {
@@ -269,49 +267,57 @@ glcd_result_t lcdVerticalScroll(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t
}
void lcdDrawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) {
- int16_t dy, dx;
- int16_t addx = 1, addy = 1;
- int16_t P, diff;
-
- int16_t i = 0;
- dx = abs((int16_t)(x1 - x0));
- dy = abs((int16_t)(y1 - y0));
-
- if(x0 > x1)
- addx = -1;
- if(y0 > y1)
- addy = -1;
-
- if(dx >= dy) {
- dy *= 2;
- P = dy - dx;
- diff = P - dx;
-
- for(; i<=dx; ++i) {
- lcdDrawPixel(x0, y0, color);
- if(P < 0) {
- P += dy;
- x0 += addx;
- } else {
- P += diff;
- x0 += addx;
- y0 += addy;
- }
- }
+ // speed improvement if vertical or horizontal
+ if(x0 == x1) {
+ lcdFillArea(x0, y0, x0+1, y1, color);
+ } else if (y0 == y1) {
+ lcdFillArea(x0, y0, x1, y0+1, color);
+
} else {
- dx *= 2;
- P = dx - dy;
- diff = P - dy;
-
- for(; i<=dy; ++i) {
- lcdDrawPixel(x0, y0, color);
- if(P < 0) {
- P += dx;
- y0 += addy;
- } else {
- P += diff;
- x0 += addx;
- y0 += addy;
+ int16_t dy, dx;
+ int16_t addx = 1, addy = 1;
+ int16_t P, diff;
+
+ int16_t i = 0;
+ dx = abs((int16_t)(x1 - x0));
+ dy = abs((int16_t)(y1 - y0));
+
+ if(x0 > x1)
+ addx = -1;
+ if(y0 > y1)
+ addy = -1;
+
+ if(dx >= dy) {
+ dy *= 2;
+ P = dy - dx;
+ diff = P - dx;
+
+ for(; i<=dx; ++i) {
+ lcdDrawPixel(x0, y0, color);
+ if(P < 0) {
+ P += dy;
+ x0 += addx;
+ } else {
+ P += diff;
+ x0 += addx;
+ y0 += addy;
+ }
+ }
+ } else {
+ dx *= 2;
+ P = dx - dy;
+ diff = P - dy;
+
+ for(; i<=dy; ++i) {
+ lcdDrawPixel(x0, y0, color);
+ if(P < 0) {
+ P += dx;
+ y0 += addy;
+ } else {
+ P += diff;
+ x0 += addx;
+ y0 += addy;
+ }
}
}
}
@@ -456,9 +462,7 @@ void lcdDrawRect(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t fil
y0 = TempY;
}
if(filled) {
- for(i=x0; i<x1; i++)
- for(j=y0; j<y1; j++)
- lcdDrawPixel(i , j , color);
+ lcdFillArea(x0, y0, x1, y1, color);
} else {
lcdDrawLine(x0, y0, x1, y0, color);
lcdDrawLine(x0, y1, x1, y1, color);
diff --git a/glcd/glcd.h b/glcd/glcd.h
index f0d4e65a..4ae26233 100644
--- a/glcd/glcd.h
+++ b/glcd/glcd.h
@@ -4,7 +4,8 @@
#include "ch.h"
#include "hal.h"
#include "fonts.h"
-#include "worker.h"
+#include "fastMath.h"
+#include "glcdWorker.h"
#if !defined(LCD_USE_FSMC) && !defined(LCD_USE_GPIO) && !defined(LCD_USE_SPI)
#include "glcdconf.h"
diff --git a/glcd/worker.h b/glcd/glcdWorker.h
index e3f257c9..40e315b5 100644
--- a/glcd/worker.h
+++ b/glcd/glcdWorker.h
@@ -1,5 +1,5 @@
-#ifndef WORKER_H
-#define WORKER_H
+#ifndef GLCD_WORKER_H
+#define GLCD_WORKER_H
#define GLCD_WORKER_SIZE 512