aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/console.c399
-rw-r--r--src/gdisp.c223
2 files changed, 312 insertions, 310 deletions
diff --git a/src/console.c b/src/console.c
index 7805ff2e..560f827e 100644
--- a/src/console.c
+++ b/src/console.c
@@ -1,180 +1,219 @@
-/*
- ChibiOS/RT - Copyright (C) 2012
- Joel Bodenmann aka Tectu <joel@unormal.org>
-
- This file is part of ChibiOS-LCD-Driver.
-
- ChibiOS-LCD-Driver is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- ChibiOS-LCD-Driver is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "ch.h"
-#include "hal.h"
-
-#include "gdisp.h"
-#include "console.h"
-
-/*
- * Interface implementation. The interface is write only
- */
-static size_t writes(void *ip, const uint8_t *bp, size_t n) {
- return lcdConsoleWrite((GLCDConsole *)ip, bp, n);
-}
-
-static size_t reads(void *ip, uint8_t *bp, size_t n) {
- (void)ip;
- (void)bp;
- (void)n;
-
- return 0;
-}
-
-static msg_t put(void *ip, uint8_t b) {
- return lcdConsolePut((GLCDConsole *)ip, (char)b);
-}
-
-static msg_t get(void *ip) {
- (void)ip;
-
- return RDY_OK;
-}
-
-static msg_t putt(void *ip, uint8_t b, systime_t timeout) {
- (void)timeout;
-
- /* TODO: handle timeout */
-
- return lcdConsolePut((GLCDConsole *)ip, (char)b);
-}
-
-static msg_t gett(void *ip, systime_t timeout) {
- (void)ip;
- (void)timeout;
-
- return RDY_OK;
-}
-
-static size_t writet(void *ip, const uint8_t *bp, size_t n, systime_t time) {
- (void)time;
-
- return lcdConsoleWrite((GLCDConsole *)ip, bp, n);
-}
-
-static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) {
- (void)ip;
- (void)bp;
- (void)n;
- (void)time;
-
- return 0;
-}
-
-static uint16_t getflags(void *ip) {
- _chn_get_and_clear_flags_impl(ip);
-}
-
-static const struct GLCDConsoleVMT vmt = {
- writes, reads, put, get,
- putt, gett, writet, readt,
- getflags
-};
-
-
-msg_t lcdConsoleInit(GLCDConsole *console, coord_t x0, coord_t y0, coord_t width, coord_t height, font_t font, pixel_t bkcolor, pixel_t color) {
- const uint8_t* ptr;
- uint16_t chi;
- uint16_t x,y;
-
- console->vmt = &vmt;
- /* read font, get height */
- console->fy = gdispGetFontMetric(font, fontHeight);
-
- /* calculate the size of the console as an integer multiple of characters height*/
- console->sx = width;
- console->sy = (((int16_t)(height/console->fy))-1)*console->fy;
-
- console->cx = 0;
- console->cy = 0;
- console->x0 = x0;
- console->y0 = y0;
-
- console->bkcolor = bkcolor;
- console->color = color;
-
- console->font = font;
-
- gdispFillArea(x0, y0, x0 + width, y0 + height, console->bkcolor);
- return RDY_OK;
-}
-
-msg_t lcdConsolePut(GLCDConsole *console, char c) {
- uint8_t width;
-
- if(c == '\n') {
- /* clear the text at the end of the line */
- if(console->cx < console->sx)
- gdispFillArea(console->x0 + console->cx, console->y0 + console->cy,
- console->sx - console->cx, console->fy,
- console->bkcolor);
- console->cx = 0;
- console->cy += console->fy;
- } else if(c == '\r') {
- /* TODO: work backwards through the buffer to the start of the current line */
- //console->cx = 0;
- } else {
- width = gdispGetCharWidth(c, console->font) + gdispGetFontMetric(console->font, fontCharPadding);
- if((console->cx + width) >= console->sx) {
- /* clear the text at the end of the line */
- if (console->cy <= console->sy)
- gdispFillArea(console->x0 + console->cx, console->y0 + console->cy,
- console->sx - (console->cx + width), console->fy,
- console->bkcolor);
- console->cx = 0;
- console->cy += console->fy;
- }
-
- if((console->cy > console->sy)) {
-#if GDISP_NEED_SCROLL
- /* scroll the console */
- gdispVerticalScroll(console->x0, console->y0, console->sx,
- console->sy + console->fy, console->fy, console->bkcolor);
- /* reset the cursor to the start of the line */
- console->cx = 0;
- console->cy = console->sy;
-#else
- /* clear the console */
- gdispFillArea(console->x0, console->y0,
- console->sx, console->sy + console->fy,
- console->bkcolor);
- /* reset the cursor to the top of the console */
- console->cx = 0;
- console->cy = 0;
-#endif
- }
-
- gdispDrawChar(console->x0 + console->cx, console->y0 + console->cy, c,
- console->font, console->color);
-
- /* update cursor */
- console->cx += width;
- }
- return RDY_OK;
-}
-
-msg_t lcdConsoleWrite(GLCDConsole *console, char *bp, size_t n) {
- size_t i;
- for(i = 0; i < n; i++)
- lcdConsolePut(console, bp[i]);
-
- return RDY_OK;
-}
+/*
+ ChibiOS/RT - Copyright (C) 2012
+ Joel Bodenmann aka Tectu <joel@unormal.org>
+
+ This file is part of ChibiOS-LCD-Driver.
+
+ ChibiOS-LCD-Driver is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS-LCD-Driver is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#if GDISP_NEED_CONSOLE
+
+#include "ch.h"
+#include "hal.h"
+
+#include "console.h"
+
+/**
+ * @extends BaseAsynchronousChannelVMT
+ *
+ * @brief @p GConsole virtual methods table.
+ */
+struct GConsoleVMT {
+ _base_asynchronous_channel_methods
+};
+
+/**
+ * @extends BaseAsynchronousChannel
+ *
+ * @brief GConsole class.
+ * @details This class extends @p BaseAsynchronousChannel by adding physical
+ * I/O queues.
+ */
+struct GConsole {
+ /** @brief Virtual Methods Table.*/
+ const struct GConsoleVMT *vmt;
+ _base_asynchronous_channel_data
+ /* WARNING: Do not add any data to this struct above this comment, only below */
+ /* font */
+ font_t font;
+ /* lcd area to use */
+ coord_t x0,y0;
+ /* current cursor position, in pixels */
+ coord_t cx,cy;
+ /* console size in pixels */
+ coord_t sx,sy;
+ /* foreground and background colour */
+ color_t bkcolor, color;
+ /* font size in pixels */
+ uint8_t fy;
+ /* font inter-character padding in pixels */
+ uint8_t fp;
+};
+
+/*
+ * Interface implementation. The interface is write only
+ */
+static size_t writes(void *ip, const uint8_t *bp, size_t n) {
+ return lcdConsoleWrite((GConsole *)ip, bp, n);
+}
+
+static size_t reads(void *ip, uint8_t *bp, size_t n) {
+ (void)ip;
+ (void)bp;
+ (void)n;
+
+ return 0;
+}
+
+static msg_t put(void *ip) {
+ (void)ip;
+
+ return RDY_OK;
+}
+
+static msg_t get(void *ip) {
+ (void)ip;
+
+ return RDY_OK;
+}
+
+static msg_t putt(void *ip, uint8_t b, systime_t timeout) {
+ (void)timeout;
+
+ /* TODO: handle timeout */
+
+ return lcdConsolePut((GConsole *)ip, (char)b);
+}
+
+static msg_t gett(void *ip, systime_t timeout) {
+ (void)ip;
+ (void)timeout;
+
+ return RDY_OK;
+}
+
+static size_t writet(void *ip, const uint8_t *bp, size_t n, systime_t time) {
+ (void)time;
+
+ return lcdConsoleWrite((GConsole *)ip, bp, n);
+}
+
+static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) {
+ (void)ip;
+ (void)bp;
+ (void)n;
+ (void)time;
+
+ return 0;
+}
+
+static ioflags_t getflags(void *ip) {
+ _ch_get_and_clear_flags_impl(ip);
+}
+
+static const struct GConsoleVMT vmt = {
+ writes, reads, put, get,
+ putt, gett, writet, readt,
+ getflags
+};
+
+
+msg_t lcdConsoleInit(GConsole *console, coord_t x0, coord_t y0, coord_t width, coord_t height, font_t font, pixel_t bkcolor, pixel_t color) {
+ console->vmt = &vmt;
+ /* read font, get height & padding */
+ console->fy = gdispGetFontMetric(font, fontHeight);
+ console->fp = gdispGetFontMetric(font, fontCharPadding);
+
+ /* calculate the size of the console as an integer multiple of characters height*/
+ console->sx = width;
+ console->sy = (((int16_t)(height/console->fy))-1)*console->fy;
+
+ console->cx = 0;
+ console->cy = 0;
+ console->x0 = x0;
+ console->y0 = y0;
+
+ console->bkcolor = bkcolor;
+ console->color = color;
+
+ console->font = font;
+
+ gdispFillArea(x0, y0, x0 + width, y0 + height, console->bkcolor);
+ return RDY_OK;
+}
+
+msg_t lcdConsolePut(GLCDConsole *console, char c) {
+ uint8_t width;
+
+ if(c == '\n') {
+ /* clear the text at the end of the line */
+ if(console->cx < console->sx)
+ gdispFillArea(console->x0 + console->cx, console->y0 + console->cy,
+ console->sx - console->cx, console->fy,
+ console->bkcolor);
+ console->cx = 0;
+ console->cy += console->fy;
+ } else if(c == '\r') {
+ /* TODO: work backwards through the buffer to the start of the current line */
+ //console->cx = 0;
+ } else {
+ width = gdispGetCharWidth(c, console->font) + console->fp;
+ if((console->cx + width) >= console->sx) {
+ /* clear the text at the end of the line */
+ if (console->cy <= console->sy)
+ gdispFillArea(console->x0 + console->cx, console->y0 + console->cy,
+ console->sx - (console->cx + width), console->fy,
+ console->bkcolor);
+ console->cx = 0;
+ console->cy += console->fy;
+ }
+
+ if((console->cy > console->sy)) {
+#if GDISP_NEED_SCROLL
+ /* scroll the console */
+ gdispVerticalScroll(console->x0, console->y0, console->sx,
+ console->sy + console->fy, console->fy, console->bkcolor);
+ /* reset the cursor to the start of the line */
+ console->cx = 0;
+ console->cy = console->sy;
+#else
+ /* clear the console */
+ gdispFillArea(console->x0, console->y0,
+ console->sx, console->sy + console->fy,
+ console->bkcolor);
+ /* reset the cursor to the top of the console */
+ console->cx = 0;
+ console->cy = 0;
+#endif
+ }
+
+ gdispDrawChar(console->x0 + console->cx, console->y0 + console->cy, c,
+ console->font, console->color);
+
+ /* update cursor */
+ console->cx += width;
+ }
+ return RDY_OK;
+}
+
+msg_t lcdConsoleWrite(GLCDConsole *console, const uint8_t *bp, size_t n) {
+ size_t i;
+ for(i = 0; i < n; i++)
+ lcdConsolePut(console, bp[i]);
+
+ return RDY_OK;
+}
+
+#endif /* GDISP_NEED_CONSOLE */
diff --git a/src/gdisp.c b/src/gdisp.c
index c3b83214..41ae8778 100644
--- a/src/gdisp.c
+++ b/src/gdisp.c
@@ -28,7 +28,6 @@
#include "ch.h"
#include "hal.h"
#include "gdisp.h"
-#include <math.h>
#ifndef _GDISP_C
#define _GDISP_C
@@ -329,29 +328,58 @@
* or at least retained until this call has finished the blit. You can
* tell when all graphics drawing is finished by @p gdispIsBusy() going FALSE.
*
- * @param[in] x0,y0 The start position
+ * @param[in] x,y The start position
* @param[in] cx,cy The size of the filled area
* @param[in] buffer The bitmap in the driver's pixel format.
*
* @api
*/
- void gdispBlitArea(coord_t x, coord_t y, coord_t cx, coord_t cy, const pixel_t *buffer) {
+ void gdispBlitAreaEx(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer) {
chMtxLock(&gdispMutex);
- GDISP_LLD(blitarea)(x, y, cx, cy, buffer);
+ GDISP_LLD(blitareaex)(x, y, cx, cy, srcx, srcy, srccx, buffer);
chMtxUnlock();
}
#elif GDISP_NEED_ASYNC
- void gdispBlitArea(coord_t x, coord_t y, coord_t cx, coord_t cy, const pixel_t *buffer) {
+ void gdispBlitAreaEx(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer) {
gdisp_lld_msg_t *p = gdispAllocMsg(GDISP_LLD_MSG_BLITAREA);
p->blitarea.x = x;
p->blitarea.y = y;
p->blitarea.cx = cx;
p->blitarea.cy = cy;
+ p->blitarea.srcx = srcx;
+ p->blitarea.srcy = srcy;
+ p->blitarea.srccx = srccx;
p->blitarea.buffer = buffer;
chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
}
#endif
+#if (GDISP_NEED_CLIP && GDISP_NEED_MULTITHREAD) || defined(__DOXYGEN__)
+ /**
+ * @brief Clip all drawing to the defined area.
+ * @pre The GDISP unit must be in powerOn or powerSleep mode.
+ *
+ * @param[in] x,y The start position
+ * @param[in] cx,cy The size of the clip area
+ *
+ * @api
+ */
+ void gdispSetClip(coord_t x, coord_t y, coord_t cx, coord_t cy) {
+ chMtxLock(&gdispMutex);
+ GDISP_LLD(setclip)(x, y, cx, cy);
+ chMtxUnlock();
+ }
+#elif GDISP_NEED_CLIP && GDISP_NEED_ASYNC
+ void gdispSetClip(coord_t x, coord_t y, coord_t cx, coord_t cy) {
+ gdisp_lld_msg_t *p = gdispAllocMsg(GDISP_LLD_MSG_SETCLIP);
+ p->setclip.x = x;
+ p->setclip.y = y;
+ p->setclip.cx = cx;
+ p->setclip.cy = cy;
+ chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
+ }
+#endif
+
#if (GDISP_NEED_CIRCLE && GDISP_NEED_MULTITHREAD) || defined(__DOXYGEN__)
/**
* @brief Draw a circle.
@@ -462,6 +490,66 @@
}
#endif
+#if (GDISP_NEED_ARC && GDISP_NEED_MULTITHREAD) || defined(__DOXYGEN__)
+ /**
+ * @brief Draw an arc.
+ * @pre The GDISP unit must be in powerOn or powerSleep mode.
+ *
+ * @param[in] x,y The center of the arc circle
+ * @param[in] radius The radius of the arc circle
+ * @param[in] startangle, endangle The start and end angle in degrees (0 to 359)
+ * @param[in] color The color to use
+ *
+ * @api
+ */
+ void gdispDrawArc(coord_t x, coord_t y, coord_t radius, coord_t startangle, coord_t endangle, color_t color) {
+ chMtxLock(&gdispMutex);
+ GDISP_LLD(drawarc)(x, y, radius, startangle, endangle, color);
+ chMtxUnlock();
+ }
+#elif GDISP_NEED_ARC && GDISP_NEED_ASYNC
+ void gdispDrawArc(coord_t x, coord_t y, coord_t radius, coord_t startangle, coord_t endangle, color_t color) {
+ gdisp_lld_msg_t *p = gdispAllocMsg(GDISP_LLD_MSG_DRAWARC);
+ p->drawarc.x = x;
+ p->drawarc.y = y;
+ p->drawarc.radius = radius;
+ p->drawarc.startangle = startangle;
+ p->drawarc.endangle = endangle;
+ p->drawarc.color = color;
+ chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
+ }
+#endif
+
+#if (GDISP_NEED_ARC && GDISP_NEED_MULTITHREAD) || defined(__DOXYGEN__)
+ /**
+ * @brief Draw a filled arc.
+ * @pre The GDISP unit must be in powerOn or powerSleep mode.
+ *
+ * @param[in] x,y The center of the arc circle
+ * @param[in] radius The radius of the arc circle
+ * @param[in] startangle, endangle The start and end angle in degrees (0 to 359)
+ * @param[in] color The color to use
+ *
+ * @api
+ */
+ void gdispFillArc(coord_t x, coord_t y, coord_t radius, coord_t startangle, coord_t endangle, color_t color) {
+ chMtxLock(&gdispMutex);
+ GDISP_LLD(fillarc)(x, y, radius, startangle, endangle, color);
+ chMtxUnlock();
+ }
+#elif GDISP_NEED_ARC && GDISP_NEED_ASYNC
+ void gdispFillArc(coord_t x, coord_t y, coord_t radius, coord_t startangle, coord_t endangle, color_t color) {
+ gdisp_lld_msg_t *p = gdispAllocMsg(GDISP_LLD_MSG_FILLARC);
+ p->fillarc.x = x;
+ p->fillarc.y = y;
+ p->fillarc.radius = radius;
+ p->fillarc.startangle = startangle;
+ p->fillarc.endangle = endangle;
+ p->fillarc.color = color;
+ chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE);
+ }
+#endif
+
#if (GDISP_NEED_TEXT && GDISP_NEED_MULTITHREAD) || defined(__DOXYGEN__)
/**
* @brief Draw a text character.
@@ -659,131 +747,6 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
}
}
-/*
- * @brief Internal helper function for gdispDrawArc()
- *
- * @note DO NOT USE DIRECTLY!
- *
- * @param[in] x, y The middle point of the arc
- * @param[in] start The start angle of the arc
- * @param[in] end The end angle of the arc
- * @param[in] radius The radius of the arc
- * @param[in] color The color in which the arc will be drawn
- *
- * @notapi
- */
-void _draw_arc(coord_t x, coord_t y, uint16_t start, uint16_t end, uint16_t radius, color_t color) {
- if (start >= 0 && start <= 180) {
- float x_maxI = x + radius*cos(start*M_PI/180);
- float x_minI;
-
- if (end > 180)
- x_minI = x - radius;
- else
- x_minI = x + radius*cos(end*M_PI/180);
-
- int a = 0;
- int b = radius;
- int P = 1 - radius;
-
- do {
- if(x-a <= x_maxI && x-a >= x_minI)
- gdispDrawPixel(x-a, y+b, color);
- if(x+a <= x_maxI && x+a >= x_minI)
- gdispDrawPixel(x+a, y+b, color);
- if(x-b <= x_maxI && x-b >= x_minI)
- gdispDrawPixel(x-b, y+a, color);
- if(x+b <= x_maxI && x+b >= x_minI)
- gdispDrawPixel(x+b, y+a, color);
-
- if (P < 0) {
- P = P + 3 + 2*a;
- a = a + 1;
- } else {
- P = P + 5 + 2*(a - b);
- a = a + 1;
- b = b - 1;
- }
- } while(a <= b);
- }
-
- if (end > 180 && end <= 360) {
- float x_maxII = x+radius*cos(end*M_PI/180);
- float x_minII;
-
- if(start <= 180)
- x_minII = x - radius;
- else
- x_minII = x+radius*cos(start*M_PI/180);
-
- int a = 0;
- int b = radius;
- int P = 1 - radius;
-
- do {
- if(x-a <= x_maxII && x-a >= x_minII)
- gdispDrawPixel(x-a, y-b, color);
- if(x+a <= x_maxII && x+a >= x_minII)
- gdispDrawPixel(x+a, y-b, color);
- if(x-b <= x_maxII && x-b >= x_minII)
- gdispDrawPixel(x-b, y-a, color);
- if(x+b <= x_maxII && x+b >= x_minII)
- gdispDrawPixel(x+b, y-a, color);
-
- if (P < 0) {
- P = P + 3 + 2*a;
- a = a + 1;
- } else {
- P = P + 5 + 2*(a - b);
- a = a + 1;
- b = b - 1;
- }
- } while (a <= b);
- }
-}
-
-/*
- * @brief Draw an arc.
- * @pre The GDISP must be in powerOn or powerSleep mode.
- *
- * @param[in] x0,y0 The center point
- * @param[in] radius The radius of the arc
- * @param[in] start The start angle (0 to 360)
- * @param[in] end The end angle (0 to 360)
- * @param[in] color The color of the arc
- *
- * @api
- */
-void gdispDrawArc(coord_t x, coord_t y, coord_t radius, uint16_t start, uint16_t end, color_t color) {
- if(end < start) {
- _draw_arc(x, y, start, 360, radius, color);
- _draw_arc(x, y, 0, end, radius, color);
- } else {
- _draw_arc(x, y, start, end, radius, color);
- }
-}
-
-/*
- * @brief Draw a filled arc.
- * @pre The GDISP must be in powerOn or powerSleep mode.
- *
- * @param[in] x0,y0 The center point of the filled arc
- * @param[in] radius The radius of the filled arc
- * @param[in] start The start angle (0 to 360)
- * @param[in] end The end angle (0 to 360)
- * @param[in] color The color of the filled arc
- *
- * @api
- */
-void gdispFillArc(coord_t x, coord_t y, coord_t radius, uint16_t start, uint16_t end, color_t color) {
- /* ToDo */
- (void)x;
- (void)y;
- (void)radius;
- (void)start;
- (void)end;
- (void)color;
-}
#if GDISP_NEED_TEXT || defined(__DOXYGEN__)
/**