aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Hannam <andrewh@inmarket.com.au>2012-11-09 18:47:05 -0800
committerAndrew Hannam <andrewh@inmarket.com.au>2012-11-09 18:47:05 -0800
commit0eeb2a2b8f0c6bfb77256522c720e6915d57c217 (patch)
tree03ce8e6d759d5482185ae4a4797555ac0a922bfa /src
parentd3b4c499ab0267dbcad3d5972bb0317fdba9043e (diff)
parentaffd9792ff42fab8f376bd2c87a71b25fd52baf7 (diff)
downloaduGFX-0eeb2a2b8f0c6bfb77256522c720e6915d57c217.tar.gz
uGFX-0eeb2a2b8f0c6bfb77256522c720e6915d57c217.tar.bz2
uGFX-0eeb2a2b8f0c6bfb77256522c720e6915d57c217.zip
Merge pull request #1 from Tectu/master
Included Tectu changes
Diffstat (limited to 'src')
-rw-r--r--src/console.c44
-rw-r--r--src/gdisp-readme.txt14
-rw-r--r--src/gdisp.c117
-rw-r--r--src/gdisp_fonts.c2
-rw-r--r--src/graph.c71
-rw-r--r--src/gwin.c4
-rw-r--r--src/touchpad.c278
-rw-r--r--src/touchscreen.c374
8 files changed, 540 insertions, 364 deletions
diff --git a/src/console.c b/src/console.c
index 064b6a05..55549fd1 100644
--- a/src/console.c
+++ b/src/console.c
@@ -18,11 +18,19 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * @file src/console.c
+ * @brief CONSOLE code.
+ *
+ * @addtogroup CONSOLE
+ * @{
+ */
+
#include "ch.h"
#include "hal.h"
#include "console.h"
-#if GFX_USE_CONSOLE
+#if GFX_USE_CONSOLE || defined(__DOXYGEN__)
/*
* Interface implementation. The interface is write only
@@ -86,6 +94,18 @@ static const struct GConsoleVMT vmt = {
putt, gett, writet, readt
};
+/**
+ * @brief Initializes a console.
+ *
+ * @param[in] console The console driver struct
+ * @param[in] x0,y0 The location of the upper left corner of the resulting window
+ * @param[in] width, height The width and height of the window
+ * @param[in] font The font to be used when printing to the console
+ * @param[in] bkcolor The background color
+ * @param[in] color The foreground / font color
+ *
+ * @return RDY_OK if done
+ */
msg_t gfxConsoleInit(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 */
@@ -110,6 +130,14 @@ msg_t gfxConsoleInit(GConsole *console, coord_t x0, coord_t y0, coord_t width, c
return RDY_OK;
}
+/**
+ * @brief Write a single character to the console.
+ *
+ * @param[in] console The console driver struct
+ * @param[in] c The char to be written
+ *
+ * @return RDY_OK if done
+ */
msg_t gfxConsolePut(GConsole *console, char c) {
uint8_t width;
@@ -164,6 +192,17 @@ msg_t gfxConsolePut(GConsole *console, char c) {
return RDY_OK;
}
+/**
+ * @brief Write a string to the console.
+ *
+ * @param[in] console The console driver struct
+ * @param[in] bp The buffer / string
+ * @param[in] n The size of the buffer
+ *
+ * @return RDY_OK if done
+ *
+ * @api
+ */
msg_t gfxConsoleWrite(GConsole *console, const uint8_t *bp, size_t n) {
size_t i;
for(i = 0; i < n; i++)
@@ -172,5 +211,6 @@ msg_t gfxConsoleWrite(GConsole *console, const uint8_t *bp, size_t n) {
return RDY_OK;
}
-#endif
+#endif /* GFX_USE_CONSOLE */
+/** @} */
diff --git a/src/gdisp-readme.txt b/src/gdisp-readme.txt
deleted file mode 100644
index 28b86077..00000000
--- a/src/gdisp-readme.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-The new GDISP driver is an architecture independent rewrite of the GLCD interface.
-This new architecture independence should allow many new low level drivers to be easily added.
-
-GDISP allows low-level driver hardware accelerated drawing routines while providing a software emulation
-if the low level driver can not provide it. A basic low level driver now only requires 2 routines to be written.
-
-A glcd.h compatibility file has been included that allow applications written to use the existing GLCD driver to
-use the GDISP driver with little or no change.
-
-It is written in the ChibiOS style with ChibiOS style includes and documentation.
-
-It is encapsulated into a "halext" structure with appropriate readme's that allow for easy inclusion in any
-ChibiOS project. This structure can be seamlessly added to as new driver types are added and it supports
-low level drivers that are neither platform or board specific (although they can be).
diff --git a/src/gdisp.c b/src/gdisp.c
index 5a3aff13..35d778d3 100644
--- a/src/gdisp.c
+++ b/src/gdisp.c
@@ -19,7 +19,7 @@
*/
/**
- * @file gdisp.c
+ * @file src/gdisp.c
* @brief GDISP Driver code.
*
* @addtogroup GDISP
@@ -144,6 +144,8 @@
* @note This function is NOT currently implicitly invoked by @p halInit().
* It must be called manually.
*
+ * @return True if succeeded, False otherwise
+ *
* @init
*/
bool_t gdispInit(void) {
@@ -192,7 +194,9 @@
/**
* @brief Test if the GDISP engine is currently drawing.
* @note This function will always return FALSE if
- * GDISP_NEED_ASYNC is not defined.
+ * GDISP_NEED_ASYNC is not defined.
+ *
+ * @return TRUE if gdisp is busy, FALSE otherwise
*
* @init
*/
@@ -208,7 +212,6 @@
#if GDISP_NEED_MULTITHREAD || defined(__DOXYGEN__)
/**
* @brief Clear the display to the specified color.
- * @pre The GDISP unit must be in powerOn or powerSleep mode.
*
* @param[in] color The color to use when clearing the screen
*
@@ -230,7 +233,6 @@
#if GDISP_NEED_MULTITHREAD || defined(__DOXYGEN__)
/**
* @brief Set a pixel in the specified color.
- * @pre The GDISP unit must be in powerOn or powerSleep mode.
*
* @param[in] x,y The position to set the pixel.
* @param[in] color The color to use
@@ -255,7 +257,6 @@
#if GDISP_NEED_MULTITHREAD || defined(__DOXYGEN__)
/**
* @brief Draw a line.
- * @pre The GDISP unit must be in powerOn or powerSleep mode.
*
* @param[in] x0,y0 The start position
* @param[in] x1,y1 The end position
@@ -280,24 +281,11 @@
}
#endif
- /**
- * @brief Draw a dashed line.
- * @pre The GDISP unit must be in powerOn or powerSleep mode.
- *
- * @param[in] x0,y0 The start position
- * @param[in] x1,y1 The end position
- * @param[in] length The length of the dash
- * @param[in] color The color of the dashed line
- *
- * @api
- */
-
#if GDISP_NEED_MULTITHREAD || defined(__DOXYGEN__)
/**
* @brief Fill an area with a color.
- * @pre The GDISP unit must be in powerOn or powerSleep mode.
*
- * @param[in] x0,y0 The start position
+ * @param[in] x,y The start position
* @param[in] cx,cy The size of the box (outside dimensions)
* @param[in] color The color to use
*
@@ -323,7 +311,6 @@
#if GDISP_NEED_MULTITHREAD || defined(__DOXYGEN__)
/**
* @brief Fill an area using the supplied bitmap.
- * @pre The GDISP unit must be in powerOn or powerSleep mode.
* @details The bitmap is in the pixel format specified by the low level driver
* @note If a packed pixel format is used and the width doesn't
* match a whole number of bytes, the next line will start on a
@@ -332,9 +319,11 @@
* 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] 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.
+ * @param[in] x,y The start position
+ * @param[in] cx,cy The size of the filled area
+ * @param[in] srcx,srcy I've no idea
+ * @param[in] srccx Really, I've no fucking idea
+ * @param[in] buffer The bitmap in the driver's pixel format
*
* @api
*/
@@ -361,7 +350,6 @@
#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
@@ -387,9 +375,8 @@
#if (GDISP_NEED_CIRCLE && GDISP_NEED_MULTITHREAD) || defined(__DOXYGEN__)
/**
* @brief Draw a circle.
- * @pre The GDISP unit must be in powerOn or powerSleep mode.
*
- * @param[in] x0,y0 The center of the circle
+ * @param[in] x,y The center of the circle
* @param[in] radius The radius of the circle
* @param[in] color The color to use
*
@@ -414,9 +401,8 @@
#if (GDISP_NEED_CIRCLE && GDISP_NEED_MULTITHREAD) || defined(__DOXYGEN__)
/**
* @brief Draw a filled circle.
- * @pre The GDISP unit must be in powerOn or powerSleep mode.
*
- * @param[in] x0,y0 The center of the circle
+ * @param[in] x,y The center of the circle
* @param[in] radius The radius of the circle
* @param[in] color The color to use
*
@@ -441,9 +427,8 @@
#if (GDISP_NEED_ELLIPSE && GDISP_NEED_MULTITHREAD) || defined(__DOXYGEN__)
/**
* @brief Draw an ellipse.
- * @pre The GDISP unit must be in powerOn or powerSleep mode.
*
- * @param[in] x0,y0 The center of the ellipse
+ * @param[in] x,y The center of the ellipse
* @param[in] a,b The dimensions of the ellipse
* @param[in] color The color to use
*
@@ -469,9 +454,8 @@
#if (GDISP_NEED_ELLIPSE && GDISP_NEED_MULTITHREAD) || defined(__DOXYGEN__)
/**
* @brief Draw a filled ellipse.
- * @pre The GDISP unit must be in powerOn or powerSleep mode.
*
- * @param[in] x0,y0 The center of the ellipse
+ * @param[in] x,y The center of the ellipse
* @param[in] a,b The dimensions of the ellipse
* @param[in] color The color to use
*
@@ -497,7 +481,6 @@
#if (GDISP_NEED_ARC && GDISP_NEED_MULTITHREAD) || defined(__DOXYGEN__)
/*
* @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
@@ -528,7 +511,6 @@
#if (GDISP_NEED_ARC && GDISP_NEED_MULTITHREAD) || defined(__DOXYGEN__)
/*
* @brief Draw a filled arc.
- * @pre The GDISP must be in powerOn or powerSleep mode.
* @note Not very efficient currently - does lots of overdrawing
*
* @param[in] x0,y0 The center point
@@ -560,7 +542,6 @@
#if GDISP_NEED_ARC || defined(__DOXYGEN__)
/**
* @brief Draw a rectangular box with rounded corners
- * @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 box (outside dimensions)
@@ -588,7 +569,6 @@ void gdispDrawRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t r
#if GDISP_NEED_ARC || defined(__DOXYGEN__)
/**
* @brief Draw a filled rectangular box with rounded corners
- * @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 box (outside dimensions)
@@ -618,11 +598,11 @@ void gdispFillRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t r
#if (GDISP_NEED_TEXT && GDISP_NEED_MULTITHREAD) || defined(__DOXYGEN__)
/**
* @brief Draw a text character.
- * @pre The GDISP unit must be in powerOn or powerSleep mode.
*
- * @param[in] x,y The position for the text
- * @param[in] c The character to draw
- * @param[in] color The color to use
+ * @param[in] x,y The position for the text
+ * @param[in] c The character to draw
+ * @param[in] font The font to use
+ * @param[in] color The color to use
*
* @api
*/
@@ -646,12 +626,12 @@ void gdispFillRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t r
#if (GDISP_NEED_TEXT && GDISP_NEED_MULTITHREAD) || defined(__DOXYGEN__)
/**
* @brief Draw a text character with a filled background.
- * @pre The GDISP unit must be in powerOn or powerSleep mode.
*
- * @param[in] x,y The position for the text
- * @param[in] c The character to draw
- * @param[in] color The color to use
- * @param[in] bgcolor The background color to use
+ * @param[in] x,y The position for the text
+ * @param[in] c The character to draw
+ * @param[in] font The font to use
+ * @param[in] color The color to use
+ * @param[in] bgcolor The background color to use
*
* @api
*/
@@ -697,6 +677,7 @@ void gdispFillRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t r
#if (GDISP_NEED_SCROLL && GDISP_NEED_MULTITHREAD) || defined(__DOXYGEN__)
/**
* @brief Scroll vertically a section of the screen.
+ * @pre GDISP_NEED_SCROLL must be set to TRUE in halconf.h
* @note Optional.
* @note If lines is >= cy, it is equivelent to a area fill with bgcolor.
*
@@ -732,7 +713,8 @@ void gdispFillRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t r
* @note Depending on the hardware implementation this function may not
* support some codes. They will be ignored.
*
- * @param[in] powerMode The power mode to use
+ * @param[in] what what you want to control
+ * @param[in] value The value to be assigned
*
* @api
*/
@@ -779,7 +761,6 @@ void gdispFillRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t r
/**
* @brief Draw a rectangular box.
- * @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 box (outside dimensions)
@@ -817,11 +798,11 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
#if GDISP_NEED_TEXT || defined(__DOXYGEN__)
/**
* @brief Draw a text string.
- * @pre The GDISP unit must be in powerOn or powerSleep mode.
*
- * @param[in] x,y The position for the text
- * @param[in] str The string to draw
- * @param[in] color The color to use
+ * @param[in] x,y The position for the text
+ * @param[in] font The font to use
+ * @param[in] str The string to draw
+ * @param[in] color The color to use
*
* @api
*/
@@ -859,12 +840,12 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
#if GDISP_NEED_TEXT || defined(__DOXYGEN__)
/**
* @brief Draw a text string.
- * @pre The GDISP unit must be in powerOn or powerSleep mode.
*
- * @param[in] x,y The position for the text
- * @param[in] str The string to draw
- * @param[in] color The color to use
- * @param[in] bgcolor The background color to use
+ * @param[in] x,y The position for the text
+ * @param[in] str The string to draw
+ * @param[in] font The font to use
+ * @param[in] color The color to use
+ * @param[in] bgcolor The background color to use
*
* @api
*/
@@ -904,12 +885,13 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
#if GDISP_NEED_TEXT || defined(__DOXYGEN__)
/**
* @brief Draw a text string verticly centered within the specified box.
- * @pre The GDISP unit must be in powerOn or powerSleep mode.
*
- * @param[in] x,y The position for the text (need to define top-right or base-line - check code)
- * @param[in] str The string to draw
- * @param[in] color The color to use
- * @param[in] justify Justify the text left, center or right within the box
+ * @param[in] x,y The position for the text (need to define top-right or base-line - check code)
+ * @param[in] cx,cy The width and height of the box
+ * @param[in] str The string to draw
+ * @param[in] font The font to use
+ * @param[in] color The color to use
+ * @param[in] justify Justify the text left, center or right within the box
*
* @api
*/
@@ -1035,14 +1017,15 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) {
#if GDISP_NEED_TEXT || defined(__DOXYGEN__)
/**
* @brief Draw a text string verticly centered within the specified box. The box background is filled with the specified background color.
- * @pre The GDISP unit must be in powerOn or powerSleep mode.
* @note The entire box is filled
*
- * @param[in] x,y The position for the text (need to define top-right or base-line - check code)
- * @param[in] str The string to draw
- * @param[in] color The color to use
- * @param[in] bgcolor The background color to use
- * @param[in] justify Justify the text left, center or right within the box
+ * @param[in] x,y The position for the text (need to define top-right or base-line - check code)
+ * @param[in] cx,cy The width and height of the box
+ * @param[in] str The string to draw
+ * @param[in] font The font to use
+ * @param[in] color The color to use
+ * @param[in] bgcolor The background color to use
+ * @param[in] justify Justify the text left, center or right within the box
*
* @api
*/
diff --git a/src/gdisp_fonts.c b/src/gdisp_fonts.c
index a58c538d..bd30342c 100644
--- a/src/gdisp_fonts.c
+++ b/src/gdisp_fonts.c
@@ -17,6 +17,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+
/*
Font tables included into gdisp.c
*/
@@ -653,3 +654,4 @@
#endif /* GDISP_NEED_TEXT */
#endif /* GFX_USE_GDISP */
+
diff --git a/src/graph.c b/src/graph.c
index f3c043c7..89f6fe00 100644
--- a/src/graph.c
+++ b/src/graph.c
@@ -18,13 +18,20 @@
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
+#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;
@@ -46,6 +53,16 @@ static void _verticalDotLine(coord_t x0, coord_t y0, coord_t y1, uint16_t 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;
@@ -85,7 +102,17 @@ void graphDrawSystem(Graph *g) {
}
}
-bool_t _boundaryCheck(Graph *g, coord_t x, coord_t y) {
+/**
+ * @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)
@@ -98,6 +125,18 @@ bool_t _boundaryCheck(Graph *g, coord_t x, coord_t y) {
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;
@@ -108,6 +147,19 @@ void graphDrawDot(Graph *g, coord_t x, coord_t y, uint16_t radius, color_t color
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;
@@ -122,6 +174,20 @@ void graphDrawDots(Graph *g, int coord[][2], uint16_t entries, uint16_t radius,
}
}
+/**
+ * @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;
@@ -146,4 +212,5 @@ void graphDrawNet(Graph *g, int coord[][2], uint16_t entries, uint16_t radius, u
}
#endif /* GFX_USE_GRAPH */
+/** @} */
diff --git a/src/gwin.c b/src/gwin.c
index 1c987204..8d893887 100644
--- a/src/gwin.c
+++ b/src/gwin.c
@@ -19,7 +19,7 @@
*/
/**
- * @file gwin.c
+ * @file src/gwin.c
* @brief GWIN Driver code.
*
* @addtogroup GWIN
@@ -166,6 +166,7 @@ void gwinClear(GHandle gh) {
* @note May leave GDISP clipping to this window's dimensions
*
* @param[in] gh The window handle
+ * @param[in] x,y The coordinates of the pixel
*
* @api
*/
@@ -887,3 +888,4 @@ void gwinButtonDraw(GHandle gh) {
#endif /* _GWIN_C */
/** @} */
+
diff --git a/src/touchpad.c b/src/touchpad.c
deleted file mode 100644
index bf6936d7..00000000
--- a/src/touchpad.c
+++ /dev/null
@@ -1,278 +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 touchpad.c
- * @brief Touchpad Driver code.
- *
- * @addgroup TOUCHPAD
- * @{
- */
-#include "ch.h"
-#include "hal.h"
-#include "gdisp.h"
-#include "touchpad.h"
-
-#if GFX_USE_TOUCHPAD || defined(__DOXYGEN__)
-
-#if TOUCHPAD_STORE_CALIBRATION
-extern void tp_store_calibration_lld(struct cal_t *cal);
-extern struct cal_t *tp_restore_calibration_lld(void);
-#endif
-
-/*===========================================================================*/
-/* Driver local definitions. */
-/*===========================================================================*/
-
-/*===========================================================================*/
-/* Driver exported variables. */
-/*===========================================================================*/
-
-/*===========================================================================*/
-/* Driver local variables. */
-/*===========================================================================*/
-static struct cal_t *cal;
-
-/*===========================================================================*/
-/* Driver local functions. */
-/*===========================================================================*/
-
-/**
- * @brief returns the uncalibrated readout of the X direction from the controller
- *
- * @noapi
- */
-static uint16_t _tpReadRealX(void) {
- uint32_t results = 0;
- uint16_t i, x;
-
- /* Median filtering is already done in LLD */
- for(i = 0; i < CONVERSIONS; i++) {
- results += tp_lld_read_x();
- }
-
- /* Take the average of the readings */
- x = results / CONVERSIONS;
-
- return x;
-}
-
-/**
- * @brief return the uncalibrated readout of the Y-direction from the controller
- *
- * @noapi
- */
-static uint16_t _tpReadRealY(void) {
- uint32_t results = 0;
- uint16_t i, y;
-
- /* Median filtering is already done in LLD */
- for(i = 0; i < CONVERSIONS; i++) {
- results += tp_lld_read_y();
- }
-
- /* Take the average of the readings */
- y = results / CONVERSIONS;
-
- return y;
-}
-
-/**
- * @brief draws a cross. Used for calibration.
- *
- * @noapi
- */
-static void _tpDrawCross(uint16_t x, uint16_t y) {
- gdispDrawLine(x-15, y, x-2, y, 0xffff);
- gdispDrawLine(x+2, y, x+15, y, 0xffff);
- gdispDrawLine(x, y-15, x, y-2, 0xffff);
- gdispDrawLine(x, y+2, x, y+15, 0xffff);
-
- gdispDrawLine(x-15, y+15, x-7, y+15, RGB565CONVERT(184,158,131));
- gdispDrawLine(x-15, y+7, x-15, y+15, RGB565CONVERT(184,158,131));
-
- gdispDrawLine(x-15, y-15, x-7, y-15, RGB565CONVERT(184,158,131));
- gdispDrawLine(x-15, y-7, x-15, y-15, RGB565CONVERT(184,158,131));
-
- gdispDrawLine(x+7, y+15, x+15, y+15, RGB565CONVERT(184,158,131));
- gdispDrawLine(x+15, y+7, x+15, y+15, RGB565CONVERT(184,158,131));
-
- gdispDrawLine(x+7, y-15, x+15, y-15, RGB565CONVERT(184,158,131));
- gdispDrawLine(x+15, y-15, x+15, y-7, RGB565CONVERT(184,158,131));
-}
-
-/*===========================================================================*/
-/* Driver exported functions. */
-/*===========================================================================*/
-
-/**
- * @brief Touchpad Driver initialization.
- * @note This function is NOT currently implicitly invoked by @p halInit().
- * It must be called manually.
- *
- * @api
- */
-void tpInit(const TOUCHPADDriver *tp) {
- cal = (struct cal_t*)chHeapAlloc(NULL, sizeof(struct cal_t));
- if(cal == NULL)
- return;
-
- /* Initialise Mutex */
- //MUTEX_INIT
-
- /* Initialise driver */
- //MUTEX_ENTER
- tp_lld_init(tp);
- //MUTEX_EXIT
-
- #if TOUCHPAD_STORE_CALIBRATION
- cal = tp_restore_calibration_lld();
- if(cal == NULL) {
- cal = (struct cal_t*)chHeapAlloc(NULL, sizeof(struct cal_t));
- tpCalibrate();
- }
- #endif
-}
-
-/**
- * @brief Get the X-Coordinate, relative to screen zero point.
- *
- * @return The X position in pixels.
- *
- * @api
- */
-uint16_t tpReadX(void) {
- uint16_t x, y;
-
-#if TOUCHPAD_XY_INVERTED == TRUE
- x = cal->xm * _tpReadRealY() + cal->xn;
- y = cal->ym * _tpReadRealX() + cal->yn;
-#else
- x = cal->xm * _tpReadRealX() + cal->xn;
- y = cal->ym * _tpReadRealY() + cal->yn;
-#endif
-
- switch(gdispGetOrientation()) {
- case GDISP_ROTATE_0:
- return x;
- case GDISP_ROTATE_90:
- return y;
- case GDISP_ROTATE_180:
- return GDISP_SCREEN_WIDTH - x - 1;
- case GDISP_ROTATE_270:
- return GDISP_SCREEN_HEIGHT - y - 1;
- }
-
- return 0;
-}
-
-/**
- * @brief Get the X-Coordinate, relative to screen zero point.
- *
- * @return The Y position in pixels.
- *
- * @api
- */
-uint16_t tpReadY(void) {
- uint16_t x, y;
-
-#if TOUCHPAD_XY_INVERTED == TRUE
- x = cal->xm * _tpReadRealY() + cal->xn;
- y = cal->ym * _tpReadRealX() + cal->yn;
-#else
- x = cal->xm * _tpReadRealX() + cal->xn;
- y = cal->ym * _tpReadRealY() + cal->yn;
-#endif
-
- switch(gdispGetOrientation()) {
- case GDISP_ROTATE_0:
- return y;
- case GDISP_ROTATE_90:
- return GDISP_SCREEN_WIDTH - x - 1;
- case GDISP_ROTATE_180:
- return GDISP_SCREEN_HEIGHT - y - 1;
- case GDISP_ROTATE_270:
- return x;
- }
-
- return 0;
-}
-
-void tpCalibrate(void) {
- const uint16_t h = gdispGetHeight();
- const uint16_t w = gdispGetWidth();
- const uint16_t cross[2][2] = {{(w/8), (h/8)}, {(w-(w/8)) , (h-(h/8))}};
- uint16_t points[2][2];
- uint8_t i;
-
- gdispSetOrientation(GDISP_ROTATE_0);
- gdispClear(Red);
- gdispFillStringBox(0, 10, gdispGetWidth(), 30, "Calibration", &fontUI2Double, White, Red, justifyCenter);
-
- for(i = 0; i < 2; i++) {
- _tpDrawCross(cross[i][0], cross[i][1]);
- while(!tpIRQ());
- points[i][0] = _tpReadRealX();
- points[i][1] = _tpReadRealY();
- chThdSleepMilliseconds(100);
- while(tpIRQ());
- gdispFillArea(cross[i][0]-15, cross[i][1]-15, 42, 42, Red);
- }
-
- cal->xm = ((float)cross[1][0] - (float)cross[0][0]) / ((float)points[1][0] - (float)points[0][0]);
- cal->ym = ((float)cross[1][1] - (float)cross[0][1]) / ((float)points[1][1] - (float)points[0][1]);
-
- cal->xn = (float)cross[0][0] - cal->xm * (float)points[0][0];
- cal->yn = (float)cross[0][1] - cal->ym * (float)points[0][1];
-
- #if TOUCHPAD_STORE_CALIBRATION
- tp_store_calibration_lld(cal);
- #endif
-}
-
-/**
- * @brief returns if touchpad is pressed or not
- *
- * @return 1 if pressed, 0 otherwise
- *
- * @api
- */
-#if TOUCHPAD_HAS_IRQ || defined(__DOXYGEN__)
- uint8_t tpIRQ(void) {
- return tp_lld_irq();
- }
-#endif
-
-/**
- * @brief Get the pressure.
- *
- * @return The pressure.
- *
- * @api
- */
-#if TOUCHPAD_HAS_PRESSURE || defined(__DOXYGEN__)
- uint16_t tpReadZ(void) {
- /* ToDo */
- return (tp_lld_read_z());
- }
-#endif
-
-#endif /* GFX_USE_TOUCHPAD */
-/** @} */
-
diff --git a/src/touchscreen.c b/src/touchscreen.c
new file mode 100644
index 00000000..e226eaea
--- /dev/null
+++ b/src/touchscreen.c
@@ -0,0 +1,374 @@
+/* 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__)
+
+#if TOUCHSCREEN_STORE_CALIBRATION
+extern void ts_store_calibration_lld(struct cal_t *cal);
+extern struct cal_t *ts_restore_calibration_lld(void);
+#endif
+
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver exported variables. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* 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 < CONVERSIONS; i++) {
+ results += ts_lld_read_x();
+ }
+
+ /* Take the average of the readings */
+ x = results / CONVERSIONS;
+
+ return x;
+}
+
+static coord_t _tsReadRealY(void) {
+ int32_t results = 0;
+ int16_t i;
+ coord_t y;
+
+ for(i = 0; i < CONVERSIONS; i++) {
+ results += ts_lld_read_y();
+ }
+
+ /* Take the average of the readings */
+ y = results / CONVERSIONS;
+
+ return y;
+}
+
+static void _tsDrawCross(uint16_t x, uint16_t y) {
+ gdispDrawLine(x-15, y, x-2, y, 0xffff);
+ gdispDrawLine(x+2, y, x+15, y, 0xffff);
+ gdispDrawLine(x, y-15, x, y-2, 0xffff);
+ gdispDrawLine(x, y+2, x, y+15, 0xffff);
+
+ gdispDrawLine(x-15, y+15, x-7, y+15, RGB565CONVERT(184,158,131));
+ gdispDrawLine(x-15, y+7, x-15, y+15, RGB565CONVERT(184,158,131));
+
+ gdispDrawLine(x-15, y-15, x-7, y-15, RGB565CONVERT(184,158,131));
+ gdispDrawLine(x-15, y-7, x-15, y-15, RGB565CONVERT(184,158,131));
+
+ gdispDrawLine(x+7, y+15, x+15, y+15, RGB565CONVERT(184,158,131));
+ gdispDrawLine(x+15, y+7, x+15, y+15, RGB565CONVERT(184,158,131));
+
+ gdispDrawLine(x+7, y-15, x+15, y-15, RGB565CONVERT(184,158,131));
+ gdispDrawLine(x+15, y-15, x+15, y-7, RGB565CONVERT(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 This function is NOT currently implicitly invoked by @p halInit().
+ * It must be called manually.
+ *
+ * @param[in] ts The touchscreen driver struct
+ *
+ * @api
+ */
+void tsInit(const TouchscreenDriver *ts) {
+ cal = (struct cal_t*)chHeapAlloc(NULL, sizeof(struct cal_t));
+ if(cal == NULL)
+ return;
+
+ /* 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) {
+ cal = (struct cal_t*)chHeapAlloc(NULL, sizeof(struct cal_t));
+ tsCalibrate();
+ }
+ #endif
+}
+
+/**
+ * @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 == TRUE
+ 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 GDISP_SCREEN_WIDTH - x - 1;
+ case GDISP_ROTATE_270:
+ return GDISP_SCREEN_HEIGHT - 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 == TRUE
+ 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 GDISP_SCREEN_WIDTH - x - 1;
+ case GDISP_ROTATE_180:
+ return GDISP_SCREEN_HEIGHT - 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_IRQ || defined(__DOXYGEN__)
+ bool_t tsIRQ(void) {
+ return ts_lld_irq();
+ }
+#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.
+ *
+ * @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;
+
+ gdispSetOrientation(GDISP_ROTATE_0);
+ 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(!tsIRQ())
+ 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 (tsIRQ()) {
+ /* We have valid pointer data */
+ px += _tsReadRealX();
+ py += _tsReadRealY();
+
+ j++;
+ }
+ }
+
+ points[i][0] = px / j;
+ points[i][1] = py / j;
+
+ chThdSleepMilliseconds(100);
+
+ while(tsIRQ())
+ 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 */
+/** @} */
+