aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--demos/mandelbrot/main.c1
-rw-r--r--demos/notepad/main.c3
-rw-r--r--drivers/gdisp/Win32/gdisp_lld.c2
-rw-r--r--drivers/touchscreen/ADS7843/touchscreen_lld.c4
-rw-r--r--drivers/touchscreen/XPT2046/touchscreen_lld.c2
-rw-r--r--include/gdisp.h1
-rw-r--r--include/touchscreen.h10
-rw-r--r--include/touchscreen_lld.h10
-rw-r--r--releases.txt1
-rw-r--r--src/gdisp.c4
-rw-r--r--src/gwin.c36
-rw-r--r--src/touchscreen.c243
12 files changed, 160 insertions, 157 deletions
diff --git a/demos/mandelbrot/main.c b/demos/mandelbrot/main.c
index 0c8dc47d..92f4aaa2 100644
--- a/demos/mandelbrot/main.c
+++ b/demos/mandelbrot/main.c
@@ -43,7 +43,6 @@ void mandelbrot(float x1, float y1, float x2, float y2) {
x = xx - yy + cx;
}
color = ((iter << 8) | (iter&0xFF));
- //color = RGB565CONVERT(iter*4, iter*13, iter*10);
gdispDrawPixel(i, j, color);
}
}
diff --git a/demos/notepad/main.c b/demos/notepad/main.c
index 5d9e5ffc..7fec864f 100644
--- a/demos/notepad/main.c
+++ b/demos/notepad/main.c
@@ -53,8 +53,6 @@ TouchscreenDriver TOUCHPADD1 = {
void drawScreen(void) {
char *msg = "ChibiOS/GFX";
- uint16_t colorsize = COLOR_SIZE;
- uint16_t pensize = PEN_SIZE;
gdispSetOrientation(GDISP_ROTATE_90);
gdispClear(White);
@@ -86,7 +84,6 @@ int main(void) {
gdispInit();
tsInit(&TOUCHPADD1);
- tsCalibrate();
drawScreen();
diff --git a/drivers/gdisp/Win32/gdisp_lld.c b/drivers/gdisp/Win32/gdisp_lld.c
index 4cf69b0e..69e90e89 100644
--- a/drivers/gdisp/Win32/gdisp_lld.c
+++ b/drivers/gdisp/Win32/gdisp_lld.c
@@ -546,7 +546,7 @@ uint16_t ts_lld_read_z(void) {
*
* @notapi
*/
-uint8_t ts_lld_irq(void) {
+uint8_t ts_lld_pressed(void) {
return (uint8_t)mousedn;
}
diff --git a/drivers/touchscreen/ADS7843/touchscreen_lld.c b/drivers/touchscreen/ADS7843/touchscreen_lld.c
index 98e25383..15b1d907 100644
--- a/drivers/touchscreen/ADS7843/touchscreen_lld.c
+++ b/drivers/touchscreen/ADS7843/touchscreen_lld.c
@@ -213,13 +213,13 @@ uint16_t ts_lld_read_y(void) {
/* ---- Optional Routines ---- */
#if TOUCHSCREEN_HAS_IRQ || defined(__DOXYGEN__)
/*
- * @brief for checking if touchpad is pressed or not.
+ * @brief for checking if touchscreen is pressed or not.
*
* @return 1 if pressed / 0 if not pressed
*
* @notapi
*/
- uint8_t ts_lld_irq(void) {
+ uint8_t ts_lld_pressed(void) {
return (!palReadPad(tsDriver->tsIRQPort, tsDriver->tsIRQPin));
}
#endif
diff --git a/drivers/touchscreen/XPT2046/touchscreen_lld.c b/drivers/touchscreen/XPT2046/touchscreen_lld.c
index 90bf0032..ef410b0d 100644
--- a/drivers/touchscreen/XPT2046/touchscreen_lld.c
+++ b/drivers/touchscreen/XPT2046/touchscreen_lld.c
@@ -219,7 +219,7 @@ uint16_t ts_lld_read_y(void) {
*
* @notapi
*/
- uint8_t ts_lld_irq(void) {
+ uint8_t ts_lld_pressed(void) {
return (!palReadPad(tsDriver->tsIRQPort, tsDriver->tsIRQPin));
}
#endif
diff --git a/include/gdisp.h b/include/gdisp.h
index db865284..9be97a12 100644
--- a/include/gdisp.h
+++ b/include/gdisp.h
@@ -293,7 +293,6 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color);
/* Now obsolete functions */
#define gdispBlitArea(x, y, cx, cy, buffer) gdispBlitAreaEx(x, y, cx, cy, 0, 0, cx, buffer)
-#define RGB565CONVERT(r,g,b) RGB2COLOR(r,g,b)
/* Macro definitions for common gets and sets */
#define gdispSetPowerMode(powerMode) gdispControl(GDISP_CONTROL_POWER, (void *)(unsigned)(powerMode))
diff --git a/include/touchscreen.h b/include/touchscreen.h
index 4d48e38d..a6673cbd 100644
--- a/include/touchscreen.h
+++ b/include/touchscreen.h
@@ -31,6 +31,14 @@
#if GFX_USE_TOUCHSCREEN || defined(__DOXYGEN__)
+#ifndef TOUCHSCREEN_STORE_CALIBRATION
+ #define TOUCHSCREEN_STORE_CALIBRATION FALSE
+#endif
+
+#ifndef TOUCHSCREEN_VERIFY_CALIBRATION
+ #define TOUCHSCREEN_VERIFY_CALIBRATION FALSE
+#endif
+
/**
* @brief specifies how many conversions are made for a readout.
*
@@ -82,7 +90,7 @@ coord_t tsReadY(void);
void tsCalibrate(void);
#if TOUCHSCREEN_HAS_IRQ
- bool_t tsIRQ(void);
+ bool_t tsPressed(void);
#endif
#if TOUCHSCREEN_HAS_PRESSURE
diff --git a/include/touchscreen_lld.h b/include/touchscreen_lld.h
index 53c66b53..3053b0e5 100644
--- a/include/touchscreen_lld.h
+++ b/include/touchscreen_lld.h
@@ -49,14 +49,6 @@
#define TOUCHSCREEN_XY_INVERTED FALSE
#endif
-#ifndef TOUCHSCREEN_STORE_CALIBRATION
- #define TOUCHSCREEN_STORE_CALIBRATION FALSE
-#endif
-
-#ifndef TOUCHSCREEN_VERIFY_CALIBRATION
- #define TOUCHSCREEN_VERIFY_CALIBRATION FALSE
-#endif
-
#ifndef TOUCHSCREEN_HAS_IRQ
#define TOUCHSCREEN_HAS_IRQ FALSE
#endif
@@ -137,7 +129,7 @@ extern "C" {
uint16_t ts_lld_read_y(void);
#if TOUCHSCREEN_HAS_IRQ
- uint8_t ts_lld_irq(void);
+ uint8_t ts_lld_pressed(void);
#endif
#if TOUCHSCREEN_HAS_PRESSURE
diff --git a/releases.txt b/releases.txt
index be897571..7002405d 100644
--- a/releases.txt
+++ b/releases.txt
@@ -8,6 +8,7 @@ current stable: 1.4
*** changes after 1.4 ***
FEATURE: Added three point calibration
FIX: Touchpad renamed into Touchscreen
+FIX: tsIRQ() renamed into tsPressed()
*** changes after 1.3 ***
diff --git a/src/gdisp.c b/src/gdisp.c
index 35d778d3..81c06599 100644
--- a/src/gdisp.c
+++ b/src/gdisp.c
@@ -321,8 +321,8 @@
*
* @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] srcx,srcy The bitmap position to start the fill form
+ * @param[in] srccx The width of a line in the bitmap
* @param[in] buffer The bitmap in the driver's pixel format
*
* @api
diff --git a/src/gwin.c b/src/gwin.c
index 8d893887..dfc4b1e0 100644
--- a/src/gwin.c
+++ b/src/gwin.c
@@ -125,7 +125,7 @@ void gwinDestroyWindow(GHandle gh) {
}
}
-#if GDISP_NEED_TEXT
+#if GDISP_NEED_TEXT || defined(__DOXYGEN__)
/**
* @brief Set the current font for this window.
*
@@ -255,7 +255,7 @@ void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coor
gdispBlitAreaEx(gh->x+x, gh->y+y, cx, cy, srcx, srcy, srccx, buffer);
}
-#if GDISP_NEED_CIRCLE
+#if GDISP_NEED_CIRCLE || defined(__DOXYGEN__)
/**
* @brief Draw a circle in the window.
* @note Uses the current foreground color to draw the circle
@@ -275,7 +275,7 @@ void gwinDrawCircle(GHandle gh, coord_t x, coord_t y, coord_t radius) {
}
#endif
-#if GDISP_NEED_CIRCLE
+#if GDISP_NEED_CIRCLE || defined(__DOXYGEN__)
/**
* @brief Draw a filled circle in the window.
* @note Uses the current foreground color to draw the filled circle
@@ -295,7 +295,7 @@ void gwinFillCircle(GHandle gh, coord_t x, coord_t y, coord_t radius) {
}
#endif
-#if GDISP_NEED_ELLIPSE
+#if GDISP_NEED_ELLIPSE || defined(__DOXYGEN__)
/**
* @brief Draw an ellipse.
* @note Uses the current foreground color to draw the ellipse
@@ -315,7 +315,7 @@ void gwinDrawEllipse(GHandle gh, coord_t x, coord_t y, coord_t a, coord_t b) {
}
#endif
-#if GDISP_NEED_ELLIPSE
+#if GDISP_NEED_ELLIPSE || defined(__DOXYGEN__)
/**
* @brief Draw an filled ellipse.
* @note Uses the current foreground color to draw the filled ellipse
@@ -335,7 +335,7 @@ void gwinFillEllipse(GHandle gh, coord_t x, coord_t y, coord_t a, coord_t b) {
}
#endif
-#if GDISP_NEED_ARC
+#if GDISP_NEED_ARC || defined(__DOXYGEN__)
/*
* @brief Draw an arc in the window.
* @note Uses the current foreground color to draw the arc
@@ -357,7 +357,7 @@ void gwinDrawArc(GHandle gh, coord_t x, coord_t y, coord_t radius, coord_t start
}
#endif
-#if GDISP_NEED_ARC
+#if GDISP_NEED_ARC || defined(__DOXYGEN__)
/*
* @brief Draw a filled arc in the window.
* @note Uses the current foreground color to draw the filled arc
@@ -379,7 +379,7 @@ void gwinFillArc(GHandle gh, coord_t x, coord_t y, coord_t radius, coord_t start
}
#endif
-#if GDISP_NEED_PIXELREAD
+#if GDISP_NEED_PIXELREAD || defined(__DOXYGEN__)
/**
* @brief Get the color of a pixel in the window.
* @return The color of the pixel.
@@ -398,7 +398,7 @@ color_t gwinGetPixelColor(GHandle gh, coord_t x, coord_t y) {
}
#endif
-#if GDISP_NEED_TEXT
+#if GDISP_NEED_TEXT || defined(__DOXYGEN__)
/**
* @brief Draw a text character at the specified position in the window.
* @pre The font must have been set.
@@ -420,7 +420,7 @@ void gwinDrawChar(GHandle gh, coord_t x, coord_t y, char c) {
}
#endif
-#if GDISP_NEED_TEXT
+#if GDISP_NEED_TEXT || defined(__DOXYGEN__)
/**
* @brief Draw a text character with a filled background at the specified position in the window.
* @pre The font must have been set.
@@ -442,7 +442,7 @@ void gwinFillChar(GHandle gh, coord_t x, coord_t y, char c) {
}
#endif
-#if GDISP_NEED_TEXT
+#if GDISP_NEED_TEXT || defined(__DOXYGEN__)
/**
* @brief Draw a text string in the window
* @pre The font must have been set.
@@ -464,7 +464,7 @@ void gwinDrawString(GHandle gh, coord_t x, coord_t y, const char *str) {
}
#endif
-#if GDISP_NEED_TEXT
+#if GDISP_NEED_TEXT || defined(__DOXYGEN__)
/**
* @brief Draw a text string with a filled background in the window
* @pre The font must have been set.
@@ -486,7 +486,7 @@ void gwinFillString(GHandle gh, coord_t x, coord_t y, const char *str) {
}
#endif
-#if GDISP_NEED_TEXT
+#if GDISP_NEED_TEXT || defined(__DOXYGEN__)
/**
* @brief Draw a text string verticly centered within the specified box.
* @pre The font must have been set.
@@ -496,6 +496,7 @@ void gwinFillString(GHandle gh, coord_t x, coord_t y, const char *str) {
*
* @param[in] gh The window handle
* @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] justify Justify the text left, center or right within the box
*
@@ -510,7 +511,7 @@ void gwinDrawStringBox(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy,
}
#endif
-#if GDISP_NEED_TEXT
+#if GDISP_NEED_TEXT || defined(__DOXYGEN__)
/**
* @brief Draw a text string verticly centered within the specified filled box.
* @pre The font must have been set.
@@ -520,6 +521,7 @@ void gwinDrawStringBox(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy,
*
* @param[in] gh The window handle
* @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] justify Justify the text left, center or right within the box
*
@@ -536,7 +538,7 @@ void gwinFillStringBox(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy,
/*------------------------------------------------------------------------------------------------------------------------*/
-#if GWIN_NEED_CONSOLE
+#if GWIN_NEED_CONSOLE || defined(__DOXYGEN__)
/*
* Stream interface implementation. The interface is write only
@@ -704,7 +706,7 @@ void gwinPutCharArray(GHandle gh, const char *str, size_t n) {
/*------------------------------------------------------------------------------------------------------------------------*/
-#if GWIN_NEED_BUTTON
+#if GWIN_NEED_BUTTON || defined(__DOXYGEN__)
static const GButtonStyle GButtonDefaultStyle = {
GBTN_3D,
@@ -720,7 +722,7 @@ static const GButtonStyle GButtonDefaultStyle = {
* @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
+ * @param[in] gb The GConsoleWindow 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/touchscreen.c b/src/touchscreen.c
index b6a1a0c3..4e90f3e4 100644
--- a/src/touchscreen.c
+++ b/src/touchscreen.c
@@ -85,64 +85,64 @@ static coord_t _tsReadRealY(void) {
}
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, 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-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+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));
+ 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);
+ *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;
+ 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]));
+ /* 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]));
+ 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]));
+ 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]);
+ 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]));
+ 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]));
+ 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]);
+ 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;
+ /* 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;
+ c->ay = dy0 / dx;
+ c->by = dy1 / dx;
+ c->cy = dy2 / dx;
}
/*===========================================================================*/
@@ -151,15 +151,13 @@ static void _tsDo3PointCalibration(const coord_t (*cross)[2], coord_t (*points)[
/**
* @brief Touchscreen Driver initialization.
- * @note This function is NOT currently implicitly invoked by @p halInit().
- * It must be called manually.
+ * @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
@@ -177,6 +175,7 @@ void tsInit(const TouchscreenDriver *ts) {
cal = (struct cal_t*)chHeapAlloc(NULL, sizeof(struct cal_t));
if(cal == NULL)
return;
+
tsCalibrate();
}
@@ -188,17 +187,17 @@ void tsInit(const TouchscreenDriver *ts) {
* @api
*/
coord_t tsReadX(void) {
- coord_t x, y;
+ coord_t x, y;
-#if TOUCHSCREEN_XY_INVERTED == TRUE
- x = _tsReadRealY();
- y = _tsReadRealX();
+#if TOUCHSCREEN_XY_INVERTED
+ x = _tsReadRealY();
+ y = _tsReadRealX();
#else
- x = _tsReadRealX();
- y = _tsReadRealY();
+ x = _tsReadRealX();
+ y = _tsReadRealY();
#endif
- _tsTransform(&x, &y);
+ _tsTransform(&x, &y);
switch(gdispGetOrientation()) {
case GDISP_ROTATE_0:
@@ -206,9 +205,9 @@ coord_t tsReadX(void) {
case GDISP_ROTATE_90:
return y;
case GDISP_ROTATE_180:
- return gdispGetWidth() - x - 1;
+ return GDISP_SCREEN_WIDTH - x - 1;
case GDISP_ROTATE_270:
- return gdispGetHeight() - y - 1;
+ return GDISP_SCREEN_HEIGHT - y - 1;
}
return 0;
@@ -224,7 +223,7 @@ coord_t tsReadX(void) {
coord_t tsReadY(void) {
coord_t x, y;
-#if TOUCHSCREEN_XY_INVERTED == TRUE
+#if TOUCHSCREEN_XY_INVERTED
x = _tsReadRealY();
y = _tsReadRealX();
#else
@@ -238,9 +237,9 @@ coord_t tsReadY(void) {
case GDISP_ROTATE_0:
return y;
case GDISP_ROTATE_90:
- return gdispGetWidth() - x - 1;
+ return GDISP_SCREEN_WIDTH - x - 1;
case GDISP_ROTATE_180:
- return gdispGetHeight() - y - 1;
+ return GDISP_SCREEN_HEIGHT - y - 1;
case GDISP_ROTATE_270:
return x;
}
@@ -270,8 +269,8 @@ coord_t tsReadY(void) {
* @api
*/
#if TOUCHSCREEN_HAS_IRQ || defined(__DOXYGEN__)
- bool_t tsIRQ(void) {
- return ts_lld_irq();
+ bool_t tsPressed(void) {
+ return ts_lld_pressed();
}
#endif
@@ -285,88 +284,94 @@ coord_t tsReadY(void) {
* 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)},
+ 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;
+ coord_t points[4][2];
+ int32_t px, py;
+ uint8_t i, j;
- gdispSetOrientation(GDISP_ROTATE_0);
- gdispClear(Blue);
+ gdispSetOrientation(GDISP_ROTATE_0);
+ gdispClear(Blue);
- gdispFillStringBox(0, 5, gdispGetWidth(), 30, "Calibration", &fontUI2Double, White, Blue, justifyCenter);
+ gdispFillStringBox(0, 5, gdispGetWidth(), 30, "Calibration", &fontUI2Double, White, Blue, justifyCenter);
#if TOUCHSCREEN_VERIFY_CALIBRATION
calibrate:
- for(i = 0; i < 4; i++) {
+ for(i = 0; i < 4; i++) {
#else
- for(i = 0; i < 3; i++) {
+ 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);
- }
+ _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);
+ /* 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.
- */
+ #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]);
+ /* 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]);
+ /* 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(px > 4)
+ goto calibrate;
+ #endif
- /* If enabled, serialize the calibration values for storage */
- #if TOUCHSCREEN_STORE_CALIBRATION
- ts_store_calibration_lld(cal);
- #endif
+ /* If enabled, serialize the calibration values for storage */
+ #if TOUCHSCREEN_STORE_CALIBRATION
+ ts_store_calibration_lld(cal);
+ #endif
}
#endif /* GFX_USE_TOUCHSCREEN */