aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gdisp/fonts.c (renamed from src/gdisp_fonts.c)11
-rw-r--r--src/gdisp/gdisp.c (renamed from src/gdisp.c)5
-rw-r--r--src/gdisp/gdisp.mk2
-rw-r--r--src/gevent/gevent.c (renamed from src/gevent.c)10
-rw-r--r--src/gevent/gevent.mk1
-rw-r--r--src/ginput/dial.c6
-rw-r--r--src/ginput/keyboard.c6
-rw-r--r--src/ginput/mouse.c9
-rw-r--r--src/ginput/toggle.c9
-rw-r--r--src/graph.c216
-rw-r--r--src/gtimer/gtimer.c (renamed from src/gtimer.c)12
-rw-r--r--src/gtimer/gtimer.mk1
-rw-r--r--src/gwin/button.c14
-rw-r--r--src/gwin/console.c6
-rw-r--r--src/gwin/graph.c425
-rw-r--r--src/gwin/gwin.c (renamed from src/gwin.c)8
-rw-r--r--src/gwin/gwin.mk7
-rw-r--r--src/gwin/gwin_internal.h53
-rw-r--r--src/touchscreen.c369
19 files changed, 478 insertions, 692 deletions
diff --git a/src/gdisp_fonts.c b/src/gdisp/fonts.c
index 6a6cd910..fda963dd 100644
--- a/src/gdisp_fonts.c
+++ b/src/gdisp/fonts.c
@@ -23,11 +23,9 @@
*/
#include "ch.h"
#include "hal.h"
-#include "gdisp.h"
+#include "gfx.h"
-#if GFX_USE_GDISP || defined(__DOXYGEN__)
-
-#if GDISP_NEED_TEXT
+#if (GFX_USE_GDISP && GDISP_NEED_TEXT) || defined(__DOXYGEN__)
#include "gdisp/fonts.h"
@@ -651,7 +649,4 @@
};
#endif
-#endif /* GDISP_NEED_TEXT */
-
-#endif /* GFX_USE_GDISP */
-
+#endif /* GFX_USE_GDISP && GDISP_NEED_TEXT */
diff --git a/src/gdisp.c b/src/gdisp/gdisp.c
index 51a43b49..1f37e107 100644
--- a/src/gdisp.c
+++ b/src/gdisp/gdisp.c
@@ -27,7 +27,7 @@
*/
#include "ch.h"
#include "hal.h"
-#include "gdisp.h"
+#include "gfx.h"
#if GFX_USE_GDISP || defined(__DOXYGEN__)
@@ -731,7 +731,7 @@ void gdispFillRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t r
}
#endif
-#if (GDISP_NEED_QUERY && (GDISP_NEED_MULTITHREAD || GDISP_NEED_ASYNC)) || defined(__DOXYGEN__)
+#if (GDISP_NEED_MULTITHREAD || GDISP_NEED_ASYNC) || defined(__DOXYGEN__)
/**
* @brief Query a property of the display.
* @pre The GDISP unit must have been initialised using @p gdispInit().
@@ -1266,4 +1266,3 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
#endif /* GFX_USE_GDISP */
/** @} */
-
diff --git a/src/gdisp/gdisp.mk b/src/gdisp/gdisp.mk
new file mode 100644
index 00000000..426e9e2c
--- /dev/null
+++ b/src/gdisp/gdisp.mk
@@ -0,0 +1,2 @@
+GFXSRC += $(GFXLIB)/src/gdisp/gdisp.c \
+ $(GFXLIB)/src/gdisp/fonts.c
diff --git a/src/gevent.c b/src/gevent/gevent.c
index 0a18eca2..be3ad7df 100644
--- a/src/gevent.c
+++ b/src/gevent/gevent.c
@@ -27,7 +27,7 @@
*/
#include "ch.h"
#include "hal.h"
-#include "gevent.h"
+#include "gfx.h"
#if GFX_USE_GEVENT || defined(__DOXYGEN__)
@@ -41,14 +41,14 @@
static MUTEX_DECL(geventMutex);
/* Our table of listener/source pairs */
-static GSourceListener Assignments[MAX_SOURCE_LISTENERS];
+static GSourceListener Assignments[GEVENT_MAX_SOURCE_LISTENERS];
/* Loop through the assignment table deleting this listener/source pair. */
/* Null is treated as a wildcard. */
static void deleteAssignments(GListener *pl, GSourceHandle gsh) {
GSourceListener *psl;
- for(psl = Assignments; psl < Assignments+MAX_SOURCE_LISTENERS; psl++) {
+ for(psl = Assignments; psl < Assignments+GEVENT_MAX_SOURCE_LISTENERS; psl++) {
if ((!pl || psl->pListener == pl) && (!gsh || psl->pSource == gsh)) {
if (chSemGetCounterI(&psl->pListener->waitqueue) < 0) {
chBSemWait(&psl->pListener->eventlock); // Obtain the buffer lock
@@ -101,7 +101,7 @@ bool_t geventAttachSource(GListener *pl, GSourceHandle gsh, unsigned flags) {
// Check if this pair is already in the table (scan for a free slot at the same time)
pslfree = 0;
- for(psl = Assignments; psl < Assignments+MAX_SOURCE_LISTENERS; psl++) {
+ for(psl = Assignments; psl < Assignments+GEVENT_MAX_SOURCE_LISTENERS; psl++) {
if (pl == psl->pListener && gsh == psl->pSource) {
// Just update the flags
@@ -228,7 +228,7 @@ GSourceListener *geventGetSourceListener(GSourceHandle gsh, GSourceListener *las
chBSemSignal(&lastlr->pListener->eventlock);
// Loop through the table looking for attachments to this source
- for(psl = lastlr ? (lastlr+1) : Assignments; psl < Assignments+MAX_SOURCE_LISTENERS; psl++) {
+ for(psl = lastlr ? (lastlr+1) : Assignments; psl < Assignments+GEVENT_MAX_SOURCE_LISTENERS; psl++) {
if (gsh == psl->pSource) {
chBSemWait(&psl->pListener->eventlock); // Obtain a lock on the listener event buffer
chMtxUnlock();
diff --git a/src/gevent/gevent.mk b/src/gevent/gevent.mk
new file mode 100644
index 00000000..59226318
--- /dev/null
+++ b/src/gevent/gevent.mk
@@ -0,0 +1 @@
+GFXSRC += $(GFXLIB)/src/gevent/gevent.c
diff --git a/src/ginput/dial.c b/src/ginput/dial.c
index cb6799a9..233daa08 100644
--- a/src/ginput/dial.c
+++ b/src/ginput/dial.c
@@ -27,9 +27,9 @@
*/
#include "ch.h"
#include "hal.h"
-#include "ginput.h"
+#include "gfx.h"
-#if GINPUT_NEED_DIAL || defined(__DOXYGEN__)
+#if (GFX_USE_GINPUT && GINPUT_NEED_DIAL) || defined(__DOXYGEN__)
#error "GINPUT: GINPUT_NEED_DIAL - Not Implemented Yet"
-#endif /* GINPUT_NEED_DIAL */
+#endif /* GFX_USE_GINPUT && GINPUT_NEED_DIAL */
/** @} */
diff --git a/src/ginput/keyboard.c b/src/ginput/keyboard.c
index 1c38a408..bd443e77 100644
--- a/src/ginput/keyboard.c
+++ b/src/ginput/keyboard.c
@@ -27,9 +27,9 @@
*/
#include "ch.h"
#include "hal.h"
-#include "ginput.h"
+#include "gfx.h"
-#if GINPUT_NEED_KEYBOARD || defined(__DOXYGEN__)
+#if (GFX_USE_GINPUT && GINPUT_NEED_KEYBOARD) || defined(__DOXYGEN__)
#error "GINPUT: GINPUT_NEED_KEYBOARD - Not Implemented Yet"
-#endif /* GINPUT_NEED_KEYBOARD */
+#endif /* GFX_USE_GINPUT && GINPUT_NEED_KEYBOARD */
/** @} */
diff --git a/src/ginput/mouse.c b/src/ginput/mouse.c
index ac23e9f1..67ee5667 100644
--- a/src/ginput/mouse.c
+++ b/src/ginput/mouse.c
@@ -27,12 +27,11 @@
*/
#include "ch.h"
#include "hal.h"
-#include "gtimer.h"
-#include "ginput.h"
+#include "gfx.h"
-#if GINPUT_NEED_MOUSE || defined(__DOXYGEN__)
+#if (GFX_USE_GINPUT && GINPUT_NEED_MOUSE) || defined(__DOXYGEN__)
-#include "lld/ginput/mouse.h"
+#include "ginput/lld/mouse.h"
#if GINPUT_MOUSE_NEED_CALIBRATION
#if !defined(GFX_USE_GDISP) || !GFX_USE_GDISP
@@ -582,5 +581,5 @@ void ginputMouseWakeupI(void) {
gtimerJabI(&MouseTimer);
}
-#endif /* GINPUT_NEED_MOUSE */
+#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */
/** @} */
diff --git a/src/ginput/toggle.c b/src/ginput/toggle.c
index 890ac1dc..3b2e98bf 100644
--- a/src/ginput/toggle.c
+++ b/src/ginput/toggle.c
@@ -27,12 +27,11 @@
*/
#include "ch.h"
#include "hal.h"
-#include "gtimer.h"
-#include "ginput.h"
+#include "gfx.h"
-#if GINPUT_NEED_TOGGLE || defined(__DOXYGEN__)
+#if (GFX_USE_GINPUT && GINPUT_NEED_TOGGLE) || defined(__DOXYGEN__)
-#include "lld/ginput/toggle.h"
+#include "ginput/lld/toggle.h"
#define GINPUT_TOGGLE_ISON 0x01
#define GINPUT_TOGGLE_INVERT 0x02
@@ -163,5 +162,5 @@ void ginputToggleWakeupI(void) {
gtimerJabI(&ToggleTimer);
}
-#endif /* GINPUT_NEED_TOGGLE */
+#endif /* GFX_USE_GINPUT && GINPUT_NEED_TOGGLE */
/** @} */
diff --git a/src/graph.c b/src/graph.c
deleted file mode 100644
index 89f6fe00..00000000
--- a/src/graph.c
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- ChibiOS/GFX - Copyright (C) 2012
- Joel Bodenmann aka Tectu <joel@unormal.org>
-
- This file is part of ChibiOS/GFX.
-
- ChibiOS/GFX 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/GFX 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/>.
-*/
-
-/**
- * @file src/graph.c
- * @brief GRAPH module code.
- *
- * @addtogroup GRAPH
- * @{
- */
-#include <stdlib.h>
-#include "ch.h"
-#include "hal.h"
-#include "gdisp.h"
-#include "graph.h"
-
-#if GFX_USE_GRAPH || defined(__DOXYGEN__)
-
-static void _horizontalDotLine(coord_t x0, coord_t y0, coord_t x1, uint16_t space, color_t color) {
- uint16_t offset = x0;
- uint16_t count = ((x1 - x0) / space);
-
- do {
- gdispDrawPixel(offset, y0, color);
- offset += space;
- } while(count--);
-}
-
-static void _verticalDotLine(coord_t x0, coord_t y0, coord_t y1, uint16_t space, color_t color) {
- uint16_t offset = y0;
- uint16_t count = ((y1 - y0) / space);
-
- do {
- gdispDrawPixel(x0, offset, color);
- offset += space;
- } while(count--);
-}
-
-/**
- * @brief Draws a graph system
- * @details Draws a graph system with two axis, X and Y.
- * Different optinal parameters like grid size, grid color,
- * arrow color (if any) etc. are defined in the struct.
- *
- * @param[in] g A pointer to a Graph struct
- *
- * @init
- */
-void graphDrawSystem(Graph *g) {
- uint16_t i;
-
- g->x0 = g->origin_x - abs(g->xmin);
- g->x1 = g->origin_x + abs(g->xmax);
- g->y0 = g->origin_y + abs(g->ymin);
- g->y1 = g->origin_y - abs(g->ymax);
-
- /* X - Axis */
- if(g->full_grid) {
- for(i = 1; i <= ((g->origin_y - g->y1) / g->grid_size); i++) {
- _horizontalDotLine(g->x0, g->origin_y - g->grid_size * i, g->x1, g->dot_space, g->grid_color);
- }
- for(i = 1; i <= ((g->y0 - g->origin_y) / g->grid_size); i++) {
- _horizontalDotLine(g->x0, g->origin_y + g->grid_size * i, g->x1, g->dot_space, g->grid_color);
- }
- }
- gdispDrawLine(g->x0, g->origin_y, g->x1, g->origin_y, g->axis_color);
- if(g->arrows) {
- gdispDrawLine(g->x1, g->origin_y, g->x1-5, g->origin_y+5, g->axis_color);
- gdispDrawLine(g->x1, g->origin_y, g->x1-5, g->origin_y-5, g->axis_color);
- }
-
- /* Y - Axis */
- if(g->full_grid) {
- for(i = 1; i <= ((g->origin_x - g->x0) / g->grid_size); i++) {
- _verticalDotLine(g->origin_x - g->grid_size * i, g->y1, g->y0, g->dot_space, g->grid_color);
- }
- for(i = 1; i <= ((g->x1 - g->origin_x) / g->grid_size); i++) {
- _verticalDotLine(g->origin_x + g->grid_size * i, g->y1, g->y0, g->dot_space, g->grid_color);
- }
- }
- gdispDrawLine(g->origin_x, g->y0, g->origin_x, g->y1, g->axis_color);
- if(g->arrows) {
- gdispDrawLine(g->origin_x, g->y1, g->origin_x-5, g->y1+5, g->axis_color);
- gdispDrawLine(g->origin_x, g->y1, g->origin_x+5, g->y1+5, g->axis_color);
- }
-}
-
-/**
- * @brief Checks if x and y are inside the graph area
- *
- * @param[in] g The pointer to the graph
- * @param[in] x,y The coordinates to be checked
- *
- * @return 1 if outside the graph area, 0 otherwise
- *
- * @notapi
- */
-static bool_t _boundaryCheck(Graph *g, coord_t x, coord_t y) {
- if(g->origin_x + x > g->x1)
- return 1;
- if(g->origin_x + x < g->x0)
- return 1;
- if(g->origin_y - y < g->y1)
- return 1;
- if(g->origin_y - y > g->y0)
- return 1;
-
- return 0;
-}
-
-/**
- * @brief Draws a single dot into the graph
- * @note The dot won't be drawn if it's outsite the max and min
- * values of the graph.
- *
- * @param[in] g The pointer to the graph
- * @param[in] x,y The coordinates where the data point will be drawn
- * @param[in] radius The radius of the dot. One pixel if 0.
- * @param[in] color The color of the dot.
- *
- * @api
- */
-void graphDrawDot(Graph *g, coord_t x, coord_t y, uint16_t radius, color_t color) {
- if(_boundaryCheck(g, x, y))
- return;
-
- if(radius == 0)
- gdispDrawPixel(g->origin_x + x, g->origin_y - y, color);
- else
- gdispFillCircle(g->origin_x + x, g->origin_y - y, radius, color);
-}
-
-/**
- * @brief Draws multiple dots into the graph
- * @note A dot won't be drawn if it's outsite the max and min
- * values of the graph.
- *
- * @param[in] g The pointer to the graph
- * @param[in] coord A two dimensional int array containing the dots coordinates.
- * @param[in] entries How many dots will be drawn (array index from 0 to entries);
- * @param[in] radius The radius of the dots. One pixel if 0.
- * @param[in] color The color of the dots.
- *
- * @api
- */
-void graphDrawDots(Graph *g, int coord[][2], uint16_t entries, uint16_t radius, uint16_t color) {
- uint16_t i;
-
- for(i = 0; i < entries; i++) {
- if(_boundaryCheck(g, coord[i][0], coord[i][1]))
- continue;
-
- if(radius == 0)
- gdispDrawPixel(coord[i][0] + g->origin_x, g->origin_y - coord[i][1], color);
- else
- gdispFillCircle(coord[i][0] + g->origin_x, g->origin_y - coord[i][1], radius, color);
- }
-}
-
-/**
- * @brief Draws multiple dots into the graph and connects them by a line
- * @note A dot won't be drawn if it's outsite the max and min
- * values of the graph.
- *
- * @param[in] g The pointer to the graph
- * @param[in] coord A two dimensional int array containing the dots coordinates.
- * @param[in] entries How many dots will be drawn (array index from 0 to entries);
- * @param[in] radius The radius of the dots. One pixel if 0.
- * @param[in] lineColor The color of the line.
- * @param[in] dotColor The color of the dots.
- *
- * @api
- */
-void graphDrawNet(Graph *g, int coord[][2], uint16_t entries, uint16_t radius, uint16_t lineColor, uint16_t dotColor) {
- uint16_t i;
-
- /* draw lines */
- for(i = 0; i < entries-1; i++) {
- if(_boundaryCheck(g, coord[i][0], coord[i][1]))
- continue;
-
- gdispDrawLine(coord[i][0] + g->origin_x, g->origin_y - coord[i][1], coord[i+1][0] + g->origin_x, g->origin_y - coord[i+1][1], lineColor);
- }
-
- /* draw dots */
- for(i = 0; i < entries; i++) {
- if(_boundaryCheck(g, coord[i][0], coord[i][1]))
- continue;
-
- if(radius == 0)
- gdispDrawPixel(coord[i][0] + g->origin_x, g->origin_y - coord[i][1], dotColor);
- else
- gdispFillCircle(coord[i][0] + g->origin_x, g->origin_y - coord[i][1], radius, dotColor);
- }
-}
-
-#endif /* GFX_USE_GRAPH */
-/** @} */
-
diff --git a/src/gtimer.c b/src/gtimer/gtimer.c
index 164822f3..76c527f4 100644
--- a/src/gtimer.c
+++ b/src/gtimer/gtimer.c
@@ -19,18 +19,22 @@
*/
/**
- * @file src/gtimer.c
- * @brief GTIMER Driver code.
+ * @file src/gtimer/gtimer.c
+ * @brief GTIMER sub-system code.
*
* @addtogroup GTIMER
* @{
*/
#include "ch.h"
#include "hal.h"
-#include "gtimer.h"
+#include "gfx.h"
#if GFX_USE_GTIMER || defined(__DOXYGEN__)
+#if !CH_USE_MUTEXES || !CH_USE_SEMAPHORES
+ #error "GTIMER: CH_USE_MUTEXES and CH_USE_SEMAPHORES must be defined in chconf.h"
+#endif
+
#define GTIMER_FLG_PERIODIC 0x0001
#define GTIMER_FLG_INFINITE 0x0002
#define GTIMER_FLG_JABBED 0x0004
@@ -44,7 +48,7 @@ static MUTEX_DECL(mutex);
static Thread *pThread = 0;
static GTimer *pTimerHead = 0;
static BSEMAPHORE_DECL(waitsem, TRUE);
-static WORKING_AREA(waTimerThread, GTIMER_THREAD_STACK_SIZE);
+static WORKING_AREA(waTimerThread, GTIMER_THREAD_WORKAREA_SIZE);
/*===========================================================================*/
/* Driver local functions. */
diff --git a/src/gtimer/gtimer.mk b/src/gtimer/gtimer.mk
new file mode 100644
index 00000000..e6c2b588
--- /dev/null
+++ b/src/gtimer/gtimer.mk
@@ -0,0 +1 @@
+GFXSRC += $(GFXLIB)/src/gtimer/gtimer.c
diff --git a/src/gwin/button.c b/src/gwin/button.c
index 4e1e45f5..0c2c1ab3 100644
--- a/src/gwin/button.c
+++ b/src/gwin/button.c
@@ -20,24 +20,20 @@
/**
* @file src/gwin/button.c
- * @brief GWIN Driver code.
+ * @brief GWIN sub-system button code.
*
* @addtogroup GWIN_BUTTON
* @{
*/
#include "ch.h"
#include "hal.h"
-#include "gwin.h"
-#include "ginput.h"
+#include "gfx.h"
#if (GFX_USE_GWIN && GWIN_NEED_BUTTON) || defined(__DOXYGEN__)
-#if !GFX_USE_GINPUT
- #error "GWIN Buttons require GFX_USE_GINPUT"
-#endif
-
#include <string.h>
-#include "gwin_internal.h"
+
+#include "gwin/internal.h"
static const GButtonStyle GButtonDefaultStyle = {
GBTN_3D,
@@ -137,7 +133,7 @@ static void gwinButtonCallback(void *param, GEvent *pe) {
* @brief Create a button window.
* @return NULL if there is no resultant drawing area, otherwise a window handle.
*
- * @param[in] gb The GConsoleWindow structure to initialise. If this is NULL the structure is dynamically allocated.
+ * @param[in] gb The GButtonObject structure to initialise. If this is NULL the structure is dynamically allocated.
* @param[in] x,y The screen co-ordinates for the bottom left corner of the window
* @param[in] width The width of the window
* @param[in] height The height of the window
diff --git a/src/gwin/console.c b/src/gwin/console.c
index 63960c23..7854b658 100644
--- a/src/gwin/console.c
+++ b/src/gwin/console.c
@@ -20,20 +20,20 @@
/**
* @file src/gwin/console.c
- * @brief GWIN Driver code.
+ * @brief GWIN sub-system console code.
*
* @addtogroup GWIN_CONSOLE
* @{
*/
#include "ch.h"
#include "hal.h"
-#include "gwin.h"
+#include "gfx.h"
#if (GFX_USE_GWIN && GWIN_NEED_CONSOLE) || defined(__DOXYGEN__)
#include <string.h>
-#include "gwin_internal.h"
+#include "gwin/internal.h"
#define GWIN_CONSOLE_USE_CLEAR_LINES TRUE
#define GWIN_CONSOLE_USE_FILLED_CHARS FALSE
diff --git a/src/gwin/graph.c b/src/gwin/graph.c
new file mode 100644
index 00000000..e950f623
--- /dev/null
+++ b/src/gwin/graph.c
@@ -0,0 +1,425 @@
+/*
+ ChibiOS/GFX - Copyright (C) 2012
+ Joel Bodenmann aka Tectu <joel@unormal.org>
+
+ This file is part of ChibiOS/GFX.
+
+ ChibiOS/GFX 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/GFX 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/>.
+*/
+
+/**
+ * @file src/gwin/button.c
+ * @brief GWIN sub-system button code.
+ *
+ * @addtogroup GWIN_BUTTON
+ * @{
+ */
+#include "ch.h"
+#include "hal.h"
+#include "gfx.h"
+
+#if (GFX_USE_GWIN && GWIN_NEED_GRAPH) || defined(__DOXYGEN__)
+
+#include "gwin/internal.h"
+
+#define GGRAPH_FLG_CONNECTPOINTS (GWIN_FIRST_CONTROL_FLAG<<0)
+#define GGRAPH_ARROW_SIZE 5
+
+static const GGraphStyle GGraphDefaultStyle = {
+ { GGRAPH_POINT_DOT, 0, White }, // point
+ { GGRAPH_LINE_DOT, 2, Gray }, // line
+ { GGRAPH_LINE_SOLID, 0, White }, // x axis
+ { GGRAPH_LINE_SOLID, 0, White }, // y axis
+ { GGRAPH_LINE_NONE, 0, White, 0 }, // x grid
+ { GGRAPH_LINE_NONE, 0, White, 0 }, // y grid
+ GWIN_GRAPH_STYLE_XAXIS_ARROWS|GWIN_GRAPH_STYLE_YAXIS_ARROWS // flags
+};
+
+static void pointto(GGraphObject *gg, coord_t x, coord_t y, const GGraphPointStyle *style) {
+ if (style->type == GGRAPH_POINT_NONE)
+ return;
+
+ // Convert to device space. Note the y-axis is inverted.
+ x += gg->gwin.x + gg->xorigin;
+ y = gg->gwin.y + gg->gwin.height - 1 - gg->yorigin - y;
+
+ if (style->size <= 1) {
+ gdispDrawPixel(x, y, style->color);
+ return;
+ }
+
+ switch(style->type) {
+ case GGRAPH_POINT_SQUARE:
+ gdispDrawBox(x-style->size, y-style->size, 2*style->size, 2*style->size, style->color);
+ break;
+#if GDISP_NEED_CIRCLE
+ case GGRAPH_POINT_CIRCLE:
+ gdispDrawCircle(x, y, style->size, style->color);
+ break;
+#endif
+ case GGRAPH_POINT_DOT:
+ default:
+ gdispDrawPixel(x, y, style->color);
+ break;
+ }
+}
+
+static void lineto(GGraphObject *gg, coord_t x0, coord_t y0, coord_t x1, coord_t y1, const GGraphLineStyle *style) {
+ coord_t dy, dx;
+ coord_t addx, addy;
+ coord_t P, diff, i;
+ coord_t run_on, run_off, run;
+
+ if (style->type == GGRAPH_LINE_NONE)
+ return;
+
+ // Convert to device space. Note the y-axis is inverted.
+ x0 += gg->gwin.x + gg->xorigin;
+ y0 = gg->gwin.y + gg->gwin.height - 1 - gg->yorigin - y0;
+ x1 += gg->gwin.x + gg->xorigin;
+ y1 += gg->gwin.y + gg->gwin.height - 1 - gg->yorigin - y1;
+
+ if (style->size <= 0) {
+ // Use the driver to draw a solid line
+ gdispDrawLine(x0, y0, x1, y1, style->color);
+ return;
+ }
+
+ switch (style->type) {
+ case GGRAPH_LINE_DOT:
+ run_on = 1;
+ run_off = -style->size;
+ break;
+
+ case GGRAPH_LINE_DASH:
+ run_on = style->size;
+ run_off = -style->size;
+ break;
+
+ case GGRAPH_LINE_SOLID:
+ default:
+ // Use the driver to draw a solid line
+ gdispDrawLine(x0, y0, x1, y1, style->color);
+ return;
+ }
+
+ // Use Bresenham's algorithm modified to draw a stylized line
+ run = 0;
+ if (x1 >= x0) {
+ dx = x1 - x0;
+ addx = 1;
+ } else {
+ dx = x0 - x1;
+ addx = -1;
+ }
+ if (y1 >= y0) {
+ dy = y1 - y0;
+ addy = 1;
+ } else {
+ dy = y0 - y1;
+ addy = -1;
+ }
+
+ if (dx >= dy) {
+ dy *= 2;
+ P = dy - dx;
+ diff = P - dx;
+
+ for(i=0; i<=dx; ++i) {
+ if (run++ >= 0) {
+ if (run >= run_on)
+ run = run_off;
+ gdispDrawPixel(x0, y0, style->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=0; i<=dy; ++i) {
+ if (run++ >= 0) {
+ if (run >= run_on)
+ run = run_off;
+ gdispDrawPixel(x0, y0, style->color);
+ }
+ if (P < 0) {
+ P += dx;
+ y0 += addy;
+ } else {
+ P += diff;
+ x0 += addx;
+ y0 += addy;
+ }
+ }
+ }
+}
+
+/**
+ * @brief Create a graph window.
+ * @return NULL if there is no resultant drawing area, otherwise a window handle.
+ *
+ * @param[in] gg The GGraphObject structure to initialise. If this is NULL the structure is dynamically allocated.
+ * @param[in] x,y The screen co-ordinates for the bottom left corner of the window
+ * @param[in] width The width of the window
+ * @param[in] height The height of the window
+ * @note The console is not automatically cleared on creation. You must do that by calling gwinClear() (possibly after changing your background color)
+ * @note The coordinate system within the window for graphing operations (but not for any other drawing
+ * operation) is relative to the bottom left corner and then shifted right and up by the specified
+ * graphing x and y origin. Note that this system is inverted in the y direction relative to the display.
+ * This gives the best graphing arrangement ie. increasing y values are closer to the top of the display.
+ *
+ * @api
+ */
+GHandle gwinCreateGraph(GGraphObject *gg, coord_t x, coord_t y, coord_t width, coord_t height) {
+ if (!(gg = (GGraphObject *)_gwinInit((GWindowObject *)gg, x, y, width, height, sizeof(GGraphObject))))
+ return 0;
+ gg->gwin.type = GW_GRAPH;
+ gg->xorigin = gg->yorigin = 0;
+ gg->lastx = gg->lasty = 0;
+ gwinGraphSetStyle(&gg->gwin, &GGraphDefaultStyle);
+ return (GHandle)gg;
+}
+
+/**
+ * @brief Set the style of the graphing operations.
+ *
+ * @param[in] gh The window handle (must be a graph window)
+ * @param[in] pstyle The graph style to set.
+ * @note The graph is not automatically redrawn. The new style will apply to any new drawing operations.
+ *
+ * @api
+ */
+void gwinGraphSetStyle(GHandle gh, const GGraphStyle *pstyle) {
+ #define gg ((GGraphObject *)gh)
+
+ if (gh->type != GW_GRAPH)
+ return;
+
+ gg->style.point.type = pstyle->point.type;
+ gg->style.point.size = pstyle->point.size;
+ gg->style.point.color = pstyle->point.color;
+ gg->style.line.type = pstyle->line.type;
+ gg->style.line.size = pstyle->line.size;
+ gg->style.line.color = pstyle->line.color;
+ gg->style.xaxis.type = pstyle->xaxis.type;
+ gg->style.xaxis.size = pstyle->xaxis.size;
+ gg->style.xaxis.color = pstyle->xaxis.color;
+ gg->style.yaxis.type = pstyle->yaxis.type;
+ gg->style.yaxis.size = pstyle->yaxis.size;
+ gg->style.yaxis.color = pstyle->yaxis.color;
+ gg->style.xgrid.type = pstyle->xgrid.type;
+ gg->style.xgrid.size = pstyle->xgrid.size;
+ gg->style.xgrid.color = pstyle->xgrid.color;
+ gg->style.xgrid.spacing = pstyle->xgrid.spacing;
+ gg->style.ygrid.type = pstyle->ygrid.type;
+ gg->style.ygrid.size = pstyle->ygrid.size;
+ gg->style.ygrid.color = pstyle->ygrid.color;
+ gg->style.ygrid.spacing = pstyle->ygrid.spacing;
+
+ #undef gg
+}
+
+/**
+ * @brief Set the origin for graphing operations.
+ *
+ * @param[in] gh The window handle (must be a graph window)
+ * @param[in] x, y The new origin for the graph (in graph coordinates relative to the bottom left corner).
+ * @note The graph is not automatically redrawn. The new origin will apply to any new drawing operations.
+ *
+ * @api
+ */
+void gwinGraphSetOrigin(GHandle gh, coord_t x, coord_t y) {
+ #define gg ((GGraphObject *)gh)
+
+ if (gh->type != GW_GRAPH)
+ return;
+
+ gg->xorigin = x;
+ gg->yorigin = y;
+
+ #undef gg
+}
+
+/**
+ * @brief Draw the axis and the background grid.
+ *
+ * @param[in] gh The window handle (must be a graph window)
+ * @note The graph is not automatically cleared. You must do that first by calling gwinClear().
+ *
+ * @api
+ */
+void gwinGraphDrawAxis(GHandle gh) {
+ #define gg ((GGraphObject *)gh)
+ coord_t i, xmin, ymin, xmax, ymax;
+
+ if (gh->type != GW_GRAPH)
+ return;
+
+ xmin = -gg->xorigin;
+ xmax = gh->width-gg->xorigin-1;
+ ymin = -gg->yorigin;
+ ymax = gh->height-gg->yorigin-1;
+
+ // x grid - this code assumes that the GGraphGridStyle is a superset of GGraphListStyle
+ if (gg->style.xgrid.type != GGRAPH_LINE_NONE && gg->style.xgrid.spacing >= 2) {
+ for(i = gg->style.xgrid.spacing; i <= xmax; i += gg->style.xgrid.spacing)
+ lineto(gg, i, ymin, i, ymax, (GGraphLineStyle *)&gg->style.xgrid);
+ for(i = -gg->style.xgrid.spacing; i >= xmin; i -= gg->style.xgrid.spacing)
+ lineto(gg, i, ymin, i, ymax, (GGraphLineStyle *)&gg->style.xgrid);
+ }
+
+ // y grid - this code assumes that the GGraphGridStyle is a superset of GGraphListStyle
+ if (gg->style.ygrid.type != GGRAPH_LINE_NONE && gg->style.ygrid.spacing >= 2) {
+ for(i = gg->style.ygrid.spacing; i <= ymax; i += gg->style.ygrid.spacing)
+ lineto(gg, xmin, i, xmax, i, (GGraphLineStyle *)&gg->style.ygrid);
+ for(i = -gg->style.ygrid.spacing; i >= ymin; i -= gg->style.ygrid.spacing)
+ lineto(gg, xmin, i, xmax, i, (GGraphLineStyle *)&gg->style.ygrid);
+ }
+
+ // x axis
+ lineto(gg, xmin, 0, xmax, 0, &gg->style.xaxis);
+ if ((gg->style.flags & GWIN_GRAPH_STYLE_XAXIS_ARROWS)) {
+ if (xmin > 0 || xmin < -(GGRAPH_ARROW_SIZE+1)) {
+ lineto(gg, xmin, 0, xmin+GGRAPH_ARROW_SIZE, GGRAPH_ARROW_SIZE, &gg->style.xaxis);
+ lineto(gg, xmin, 0, xmin+GGRAPH_ARROW_SIZE, -GGRAPH_ARROW_SIZE, &gg->style.xaxis);
+ }
+ if (xmax < 0 || xmax > (GGRAPH_ARROW_SIZE+1)) {
+ lineto(gg, xmax, 0, xmax-GGRAPH_ARROW_SIZE, GGRAPH_ARROW_SIZE, &gg->style.xaxis);
+ lineto(gg, xmax, 0, xmax-GGRAPH_ARROW_SIZE, -GGRAPH_ARROW_SIZE, &gg->style.xaxis);
+ }
+ }
+
+ // y axis
+ lineto(gg, 0, ymin, 0, ymax, &gg->style.yaxis);
+ if ((gg->style.flags & GWIN_GRAPH_STYLE_YAXIS_ARROWS)) {
+ if (ymin > 0 || ymin < -(GGRAPH_ARROW_SIZE+1)) {
+ lineto(gg, 0, ymin, GGRAPH_ARROW_SIZE, ymin+GGRAPH_ARROW_SIZE, &gg->style.yaxis);
+ lineto(gg, 0, ymin, -GGRAPH_ARROW_SIZE, ymin+GGRAPH_ARROW_SIZE, &gg->style.yaxis);
+ }
+ if (ymax < 0 || ymax > (GGRAPH_ARROW_SIZE+1)) {
+ lineto(gg, 0, ymax, GGRAPH_ARROW_SIZE, ymax-GGRAPH_ARROW_SIZE, &gg->style.yaxis);
+ lineto(gg, 0, ymax, -GGRAPH_ARROW_SIZE, ymax-GGRAPH_ARROW_SIZE, &gg->style.yaxis);
+ }
+ }
+
+ #undef gg
+}
+
+/**
+ * @brief Start a new set of graphing data.
+ * @details This prevents a line being drawn from the last data point to the next point to be drawn.
+ *
+ * @param[in] gh The window handle (must be a graph window)
+ *
+ * @api
+ */
+void gwinGraphStartSet(GHandle gh) {
+ if (gh->type != GW_GRAPH)
+ return;
+
+ gh->flags &= ~GGRAPH_FLG_CONNECTPOINTS;
+}
+
+/**
+ * @brief Draw a graph point.
+ * @details A graph point and a line connecting to the previous point will be drawn.
+ *
+ * @param[in] gh The window handle (must be a graph window)
+ * @param[in] x, y The new point for the graph.
+ *
+ * @api
+ */
+void gwinGraphDrawPoint(GHandle gh, coord_t x, coord_t y) {
+ #define gg ((GGraphObject *)gh)
+
+ if (gh->type != GW_GRAPH)
+ return;
+
+ if ((gh->flags & GGRAPH_FLG_CONNECTPOINTS)) {
+ // Draw the line
+ lineto(gg, gg->lastx, gg->lasty, x, y, &gg->style.line);
+
+ // Redraw the previous point because the line may have overwritten it
+ pointto(gg, gg->lastx, gg->lasty, &gg->style.point);
+
+ } else
+ gh->flags |= GGRAPH_FLG_CONNECTPOINTS;
+
+ // Save this point for next time.
+ gg->lastx = x;
+ gg->lasty = y;
+
+ // Draw this point.
+ pointto(gg, x, y, &gg->style.point);
+
+ #undef gg
+}
+
+/**
+ * @brief Draw multiple graph points.
+ * @details A graph point and a line connecting to each previous point will be drawn.
+ *
+ * @param[in] gh The window handle (must be a graph window)
+ * @param[in] points The array of points for the graph.
+ * @param[in] count The number of points in the array.
+ * @note This is slightly more efficient than calling gwinGraphDrawPoint() repeatedly.
+ *
+ * @api
+ */
+void gwinGraphDrawPoints(GHandle gh, const GGraphPoint *points, unsigned count) {
+ #define gg ((GGraphObject *)gh)
+ unsigned i;
+ const GGraphPoint *p;
+
+ if (gh->type != GW_GRAPH)
+ return;
+
+ // Draw the connecting lines
+ for(p = points, i = 0; i < count; p++, i++) {
+ if ((gh->flags & GGRAPH_FLG_CONNECTPOINTS)) {
+ // Draw the line
+ lineto(gg, gg->lastx, gg->lasty, p->x, p->y, &gg->style.line);
+
+ // Redraw the previous point because the line may have overwritten it
+ if (i == 0)
+ pointto(gg, gg->lastx, gg->lasty, &gg->style.point);
+
+ } else
+ gh->flags |= GGRAPH_FLG_CONNECTPOINTS;
+
+ // Save this point for next time.
+ gg->lastx = p->x;
+ gg->lasty = p->y;
+ }
+
+
+ // Draw the points.
+ for(p = points, i = 0; i < count; p++, i++)
+ pointto(gg, p->x, p->y, &gg->style.point);
+
+ #undef gg
+}
+
+#endif /* GFX_USE_GWIN && GWIN_NEED_GRAPH */
+/** @} */
+
diff --git a/src/gwin.c b/src/gwin/gwin.c
index e7bbda01..999ea304 100644
--- a/src/gwin.c
+++ b/src/gwin/gwin.c
@@ -19,19 +19,19 @@
*/
/**
- * @file src/gwin.c
- * @brief GWIN Driver code.
+ * @file src/gwin/gwin.c
+ * @brief GWIN sub-system code.
*
* @addtogroup GWIN
* @{
*/
#include "ch.h"
#include "hal.h"
-#include "gwin.h"
+#include "gfx.h"
#if GFX_USE_GWIN || defined(__DOXYGEN__)
-#include "gwin/gwin_internal.h"
+#include "gwin/internal.h"
// Internal routine for use by GWIN components only
// Initialise a window creating it dynamicly if required.
diff --git a/src/gwin/gwin.mk b/src/gwin/gwin.mk
index cf952580..947d11f3 100644
--- a/src/gwin/gwin.mk
+++ b/src/gwin/gwin.mk
@@ -1,2 +1,5 @@
-GFXSRC += $(GFXLIB)/src/gwin/console.c \
- $(GFXLIB)/src/gwin/button.c
+GFXSRC += $(GFXLIB)/src/gwin/gwin.c \
+ $(GFXLIB)/src/gwin/console.c \
+ $(GFXLIB)/src/gwin/button.c \
+ $(GFXLIB)/src/gwin/graph.c
+ \ No newline at end of file
diff --git a/src/gwin/gwin_internal.h b/src/gwin/gwin_internal.h
deleted file mode 100644
index 13401a6f..00000000
--- a/src/gwin/gwin_internal.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- ChibiOS/GFX - Copyright (C) 2012
- Joel Bodenmann aka Tectu <joel@unormal.org>
-
- This file is part of ChibiOS/GFX.
-
- ChibiOS/GFX 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/GFX 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/>.
-*/
-/**
- * @file gwin_internal.h
- * @brief GWIN Graphic window subsystem header file.
- *
- * @addtogroup GWIN
- * @{
- */
-#ifndef _GWIN_INTERNAL_H
-#define _GWIN_INTERNAL_H
-
-#if GFX_USE_GWIN || defined(__DOXYGEN__)
-
-/*===========================================================================*/
-/* Sub-system constants. */
-/*===========================================================================*/
-
-#define GWIN_FLG_DYNAMIC 0x0001
-#define GWIN_FIRST_CONTROL_FLAG 0x0002
-#define GBTN_FLG_ALLOCTXT (GWIN_FIRST_CONTROL_FLAG<<0)
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-GHandle _gwinInit(GWindowObject *gw, coord_t x, coord_t y, coord_t width, coord_t height, size_t size);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* GFX_USE_GWIN */
-
-#endif /* _GWIN_INTERNAL_H */
-/** @} */
diff --git a/src/touchscreen.c b/src/touchscreen.c
deleted file mode 100644
index 0fa5402e..00000000
--- a/src/touchscreen.c
+++ /dev/null
@@ -1,369 +0,0 @@
-/* ChibiOS/GFX - Copyright (C) 2012
- Joel Bodenmann aka Tectu <joel@unormal.org>
-
- This file is part of ChibiOS/GFX.
-
- ChibiOS/GFX 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/GFX 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/>.
-*/
-
-/**
- * @file src/touchscreen.c
- * @brief Touchscreen Driver code.
- *
- * @addtogroup TOUCHSCREEN
- * @{
- */
-
-#include "ch.h"
-#include "hal.h"
-#include "gdisp.h"
-#include "touchscreen.h"
-
-#if GFX_USE_TOUCHSCREEN || defined(__DOXYGEN__)
-
-/*===========================================================================*/
-/* Driver local variables. */
-/*===========================================================================*/
-static struct cal_t *cal;
-
-/*===========================================================================*/
-/* Driver local functions. */
-/*===========================================================================*/
-
-static coord_t _tsReadRealX(void) {
- int32_t results = 0;
- int16_t i;
- coord_t x;
-
- for(i = 0; i < TOUCHSCREEN_CONVERSIONS; i++) {
- results += ts_lld_read_x();
- }
-
- /* Take the average of the readings */
- x = results / TOUCHSCREEN_CONVERSIONS;
-
- return x;
-}
-
-static coord_t _tsReadRealY(void) {
- int32_t results = 0;
- int16_t i;
- coord_t y;
-
- for(i = 0; i < TOUCHSCREEN_CONVERSIONS; i++) {
- results += ts_lld_read_y();
- }
-
- /* Take the average of the readings */
- y = results / TOUCHSCREEN_CONVERSIONS;
-
- return y;
-}
-
-static void _tsDrawCross(uint16_t x, uint16_t y) {
- gdispDrawLine(x-15, y, x-2, y, White);
- gdispDrawLine(x+2, y, x+15, y, White);
- gdispDrawLine(x, y-15, x, y-2, White);
- gdispDrawLine(x, y+2, x, y+15, White);
-
- gdispDrawLine(x-15, y+15, x-7, y+15, RGB2COLOR(184,158,131));
- gdispDrawLine(x-15, y+7, x-15, y+15, RGB2COLOR(184,158,131));
-
- gdispDrawLine(x-15, y-15, x-7, y-15, RGB2COLOR(184,158,131));
- gdispDrawLine(x-15, y-7, x-15, y-15, RGB2COLOR(184,158,131));
-
- gdispDrawLine(x+7, y+15, x+15, y+15, RGB2COLOR(184,158,131));
- gdispDrawLine(x+15, y+7, x+15, y+15, RGB2COLOR(184,158,131));
-
- gdispDrawLine(x+7, y-15, x+15, y-15, RGB2COLOR(184,158,131));
- gdispDrawLine(x+15, y-15, x+15, y-7, RGB2COLOR(184,158,131));
-}
-
-static void _tsTransform(coord_t *x, coord_t *y) {
- *x = (coord_t) (cal->ax * (*x) + cal->bx * (*y) + cal->cx);
- *y = (coord_t) (cal->ay * (*x) + cal->by * (*y) + cal->cy);
-}
-
-static void _tsDo3PointCalibration(const coord_t (*cross)[2], coord_t (*points)[2], cal_t *c) {
- float dx, dx0, dx1, dx2, dy0, dy1, dy2;
-
- /* Compute all the required determinants */
- dx = ((float)(points[0][0] - points[2][0])) * ((float)(points[1][1] - points[2][1]))
- - ((float)(points[1][0] - points[2][0])) * ((float)(points[0][1] - points[2][1]));
-
- dx0 = ((float)(cross[0][0] - cross[2][0])) * ((float)(points[1][1] - points[2][1]))
- - ((float)(cross[1][0] - cross[2][0])) * ((float)(points[0][1] - points[2][1]));
-
- dx1 = ((float)(points[0][0] - points[2][0])) * ((float)(cross[1][0] - cross[2][0]))
- - ((float)(points[1][0] - points[2][0])) * ((float)(cross[0][0] - cross[2][0]));
-
- dx2 = cross[0][0] * ((float)points[1][0] * (float)points[2][1] - (float)points[2][0] * (float)points[1][1]) -
- cross[1][0] * ((float)points[0][0] * (float)points[2][1] - (float)points[2][0] * (float)points[0][1]) +
- cross[2][0] * ((float)points[0][0] * (float)points[1][1] - (float)points[1][0] * (float)points[0][1]);
-
- dy0 = ((float)(cross[0][1] - cross[2][1])) * ((float)(points[1][1] - points[2][1]))
- - ((float)(cross[1][1] - cross[2][1])) * ((float)(points[0][1] - points[2][1]));
-
- dy1 = ((float)(points[0][0] - points[2][0])) * ((float)(cross[1][1] - cross[2][1]))
- - ((float)(points[1][0] - points[2][0])) * ((float)(cross[0][1] - cross[2][1]));
-
- dy2 = cross[0][1] * ((float)points[1][0] * (float)points[2][1] - (float)points[2][0] * (float)points[1][1]) -
- cross[1][1] * ((float)points[0][0] * (float)points[2][1] - (float)points[2][0] * (float)points[0][1]) +
- cross[2][1] * ((float)points[0][0] * (float)points[1][1] - (float)points[1][0] * (float)points[0][1]);
-
- /* Now, calculate all the required coefficients */
- c->ax = dx0 / dx;
- c->bx = dx1 / dx;
- c->cx = dx2 / dx;
-
- c->ay = dy0 / dx;
- c->by = dy1 / dx;
- c->cy = dy2 / dx;
-}
-
-/*===========================================================================*/
-/* Driver exported functions. */
-/*===========================================================================*/
-
-/**
- * @brief Touchscreen Driver initialization.
- * @note Calling this function automatically invokes a tsCalibration()
- *
- * @param[in] ts The touchscreen driver struct
- *
- * @api
- */
-void tsInit(const TouchscreenDriver *ts) {
- /* Initialise Mutex */
- //MUTEX_INIT
-
- /* Initialise driver */
- //MUTEX_ENTER
- ts_lld_init(ts);
- //MUTEX_EXIT
-
- #if TOUCHSCREEN_STORE_CALIBRATION
- cal = ts_restore_calibration_lld();
- if(cal != NULL)
- return; // All done
- #endif
-
- cal = (struct cal_t*)chHeapAlloc(NULL, sizeof(struct cal_t));
- if(cal == NULL)
- return;
-
- tsCalibrate();
-}
-
-/**
- * @brief Get the X-Coordinate, relative to screen zero point.
- *
- * @return The X position in pixels.
- *
- * @api
- */
-coord_t tsReadX(void) {
- coord_t x, y;
-
-#if TOUCHSCREEN_XY_INVERTED
- x = _tsReadRealY();
- y = _tsReadRealX();
-#else
- x = _tsReadRealX();
- y = _tsReadRealY();
-#endif
-
- _tsTransform(&x, &y);
-
- switch(gdispGetOrientation()) {
- case GDISP_ROTATE_0:
- return x;
- case GDISP_ROTATE_90:
- return y;
- case GDISP_ROTATE_180:
- return gdispGetWidth() - x - 1;
- case GDISP_ROTATE_270:
- return gdispGetWidth() - y - 1;
- }
-
- return 0;
-}
-
-/**
- * @brief Get the X-Coordinate, relative to screen zero point.
- *
- * @return The Y position in pixels.
- *
- * @api
- */
-coord_t tsReadY(void) {
- coord_t x, y;
-
-#if TOUCHSCREEN_XY_INVERTED
- x = _tsReadRealY();
- y = _tsReadRealX();
-#else
- x = _tsReadRealX();
- y = _tsReadRealY();
-#endif
-
- _tsTransform(&x, &y);
-
- switch(gdispGetOrientation()) {
- case GDISP_ROTATE_0:
- return y;
- case GDISP_ROTATE_90:
- return gdispGetHeight() - x - 1;
- case GDISP_ROTATE_180:
- return gdispGetHeight() - y - 1;
- case GDISP_ROTATE_270:
- return x;
- }
-
- return 0;
-}
-
-/**
- * @brief Get the pressure.
- *
- * @return The pressure.
- *
- * @api
- */
-#if TOUCHSCREEN_HAS_PRESSURE || defined(__DOXYGEN__)
- uint16_t tsReadZ(void) {
- /* ToDo */
- return (ts_lld_read_z());
- }
-#endif
-
-/**
- * @brief Returns if touchscreen is pressed or not
- *
- * @return TRUE if pressed, FALSE otherwise
- *
- * @api
- */
-#if TOUCHSCREEN_HAS_PRESSED || defined(__DOXYGEN__)
- bool_t tsPressed(void) {
- return ts_lld_pressed();
- }
-#endif
-
-/* Define maximum no. of times to sample the calibration point */
-#define MAX_CAL_SAMPLES 10
-
-/**
- * @brief Function to calibrate touchscreen
- * @details This function interactively performs calibration of the touchscreen
- * using 3-point calibration algorithm. Optionally, it also verifies
- * the accuracy of the calibration coefficients obtained if the symbol
- * TOUCHSCREEN_VERIFY_CALIBRATION is defined in the configuration.
- *
- * @note You don't have to call this function manually. It gets invoked by tsInit()
- *
- * @api
- */
-void tsCalibrate(void) {
- const uint16_t height = gdispGetHeight();
- const uint16_t width = gdispGetWidth();
- const coord_t cross[][2] = {{(width / 4), (height / 4)},
- {(width - (width / 4)) , (height / 4)},
- {(width - (width / 4)) , (height - (height / 4))},
- {(width / 2), (height / 2)}}; /* Check point */
- coord_t points[4][2];
- int32_t px, py;
- uint8_t i, j;
-
- #if GDISP_NEED_CONTROL
- gdispSetOrientation(GDISP_ROTATE_0);
- #endif
-
- gdispClear(Blue);
-
- gdispFillStringBox(0, 5, gdispGetWidth(), 30, "Calibration", &fontUI2Double, White, Blue, justifyCenter);
-
-#if TOUCHSCREEN_VERIFY_CALIBRATION
-calibrate:
- for(i = 0; i < 4; i++) {
-#else
- for(i = 0; i < 3; i++) {
-#endif
- _tsDrawCross(cross[i][0], cross[i][1]);
-
- while(!tsPressed())
- chThdSleepMilliseconds(2); /* Be nice to other threads*/
-
- chThdSleepMilliseconds(20); /* Allow screen to settle */
-
- /* Take a little more samples per point and their average
- * for precise calibration */
- px = py = 0;
- j = 0;
-
- while(j < MAX_CAL_SAMPLES) {
- if(tsPressed()) { /* We have valid pointer data */
- #if TOUCHSCREEN_XY_INVERTED
- py += _tsReadRealX();
- px += _tsReadRealY();
- #else
- px += _tsReadRealX();
- py += _tsReadRealY();
- #endif
-
- j++;
- }
- }
-
- points[i][0] = px / j;
- points[i][1] = py / j;
-
- chThdSleepMilliseconds(100);
-
- while(tsPressed())
- chThdSleepMilliseconds(2); /* Be nice to other threads*/
-
- gdispFillArea(cross[i][0] - 15, cross[i][1] - 15, 42, 42, Blue);
- }
-
- /* Apply 3 point calibration algorithm */
- _tsDo3PointCalibration(cross, points, cal);
-
- #if TOUCHSCREEN_VERIFY_CALIBRATION
- /* Verification of correctness of calibration (optional) :
- * See if the 4th point (Middle of the screen) coincides with the calibrated
- * result. If point is with +/- 2 pixel margin, then successful calibration
- * Else, start from the beginning.
- */
-
- /* Transform the co-ordinates */
- _tpTransform(&points[3][0], &points[3][1]);
-
- /* Calculate the delta */
- px = (points[3][0] - cross[3][0]) * (points[3][0] - cross[3][0]) +
- (points[3][1] - cross[3][1]) * (points[3][1] - cross[3][1]);
-
- if(px > 4)
- goto calibrate;
- #endif
-
- /* If enabled, serialize the calibration values for storage */
- #if TOUCHSCREEN_STORE_CALIBRATION
- ts_store_calibration_lld(cal);
- #endif
-}
-
-#endif /* GFX_USE_TOUCHSCREEN */
-/** @} */
-