commit
e28a4dbd0e
12 changed files with 153 additions and 150 deletions
|
@ -43,7 +43,6 @@ void mandelbrot(float x1, float y1, float x2, float y2) {
|
||||||
x = xx - yy + cx;
|
x = xx - yy + cx;
|
||||||
}
|
}
|
||||||
color = ((iter << 8) | (iter&0xFF));
|
color = ((iter << 8) | (iter&0xFF));
|
||||||
//color = RGB565CONVERT(iter*4, iter*13, iter*10);
|
|
||||||
gdispDrawPixel(i, j, color);
|
gdispDrawPixel(i, j, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,8 +53,6 @@ TouchscreenDriver TOUCHPADD1 = {
|
||||||
|
|
||||||
void drawScreen(void) {
|
void drawScreen(void) {
|
||||||
char *msg = "ChibiOS/GFX";
|
char *msg = "ChibiOS/GFX";
|
||||||
uint16_t colorsize = COLOR_SIZE;
|
|
||||||
uint16_t pensize = PEN_SIZE;
|
|
||||||
|
|
||||||
gdispSetOrientation(GDISP_ROTATE_90);
|
gdispSetOrientation(GDISP_ROTATE_90);
|
||||||
gdispClear(White);
|
gdispClear(White);
|
||||||
|
@ -86,7 +84,6 @@ int main(void) {
|
||||||
|
|
||||||
gdispInit();
|
gdispInit();
|
||||||
tsInit(&TOUCHPADD1);
|
tsInit(&TOUCHPADD1);
|
||||||
tsCalibrate();
|
|
||||||
|
|
||||||
drawScreen();
|
drawScreen();
|
||||||
|
|
||||||
|
|
|
@ -546,7 +546,7 @@ uint16_t ts_lld_read_z(void) {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
uint8_t ts_lld_irq(void) {
|
uint8_t ts_lld_pressed(void) {
|
||||||
return (uint8_t)mousedn;
|
return (uint8_t)mousedn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -213,13 +213,13 @@ uint16_t ts_lld_read_y(void) {
|
||||||
/* ---- Optional Routines ---- */
|
/* ---- Optional Routines ---- */
|
||||||
#if TOUCHSCREEN_HAS_IRQ || defined(__DOXYGEN__)
|
#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
|
* @return 1 if pressed / 0 if not pressed
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
uint8_t ts_lld_irq(void) {
|
uint8_t ts_lld_pressed(void) {
|
||||||
return (!palReadPad(tsDriver->tsIRQPort, tsDriver->tsIRQPin));
|
return (!palReadPad(tsDriver->tsIRQPort, tsDriver->tsIRQPin));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -219,7 +219,7 @@ uint16_t ts_lld_read_y(void) {
|
||||||
*
|
*
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
uint8_t ts_lld_irq(void) {
|
uint8_t ts_lld_pressed(void) {
|
||||||
return (!palReadPad(tsDriver->tsIRQPort, tsDriver->tsIRQPin));
|
return (!palReadPad(tsDriver->tsIRQPort, tsDriver->tsIRQPin));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -293,7 +293,6 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color);
|
||||||
|
|
||||||
/* Now obsolete functions */
|
/* Now obsolete functions */
|
||||||
#define gdispBlitArea(x, y, cx, cy, buffer) gdispBlitAreaEx(x, y, cx, cy, 0, 0, cx, buffer)
|
#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 */
|
/* Macro definitions for common gets and sets */
|
||||||
#define gdispSetPowerMode(powerMode) gdispControl(GDISP_CONTROL_POWER, (void *)(unsigned)(powerMode))
|
#define gdispSetPowerMode(powerMode) gdispControl(GDISP_CONTROL_POWER, (void *)(unsigned)(powerMode))
|
||||||
|
|
|
@ -31,6 +31,14 @@
|
||||||
|
|
||||||
#if GFX_USE_TOUCHSCREEN || defined(__DOXYGEN__)
|
#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.
|
* @brief specifies how many conversions are made for a readout.
|
||||||
*
|
*
|
||||||
|
@ -82,7 +90,7 @@ coord_t tsReadY(void);
|
||||||
void tsCalibrate(void);
|
void tsCalibrate(void);
|
||||||
|
|
||||||
#if TOUCHSCREEN_HAS_IRQ
|
#if TOUCHSCREEN_HAS_IRQ
|
||||||
bool_t tsIRQ(void);
|
bool_t tsPressed(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TOUCHSCREEN_HAS_PRESSURE
|
#if TOUCHSCREEN_HAS_PRESSURE
|
||||||
|
|
|
@ -49,14 +49,6 @@
|
||||||
#define TOUCHSCREEN_XY_INVERTED FALSE
|
#define TOUCHSCREEN_XY_INVERTED FALSE
|
||||||
#endif
|
#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
|
#ifndef TOUCHSCREEN_HAS_IRQ
|
||||||
#define TOUCHSCREEN_HAS_IRQ FALSE
|
#define TOUCHSCREEN_HAS_IRQ FALSE
|
||||||
#endif
|
#endif
|
||||||
|
@ -137,7 +129,7 @@ extern "C" {
|
||||||
uint16_t ts_lld_read_y(void);
|
uint16_t ts_lld_read_y(void);
|
||||||
|
|
||||||
#if TOUCHSCREEN_HAS_IRQ
|
#if TOUCHSCREEN_HAS_IRQ
|
||||||
uint8_t ts_lld_irq(void);
|
uint8_t ts_lld_pressed(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TOUCHSCREEN_HAS_PRESSURE
|
#if TOUCHSCREEN_HAS_PRESSURE
|
||||||
|
|
|
@ -8,6 +8,7 @@ current stable: 1.4
|
||||||
*** changes after 1.4 ***
|
*** changes after 1.4 ***
|
||||||
FEATURE: Added three point calibration
|
FEATURE: Added three point calibration
|
||||||
FIX: Touchpad renamed into Touchscreen
|
FIX: Touchpad renamed into Touchscreen
|
||||||
|
FIX: tsIRQ() renamed into tsPressed()
|
||||||
|
|
||||||
|
|
||||||
*** changes after 1.3 ***
|
*** changes after 1.3 ***
|
||||||
|
|
|
@ -321,8 +321,8 @@
|
||||||
*
|
*
|
||||||
* @param[in] x,y The start position
|
* @param[in] x,y The start position
|
||||||
* @param[in] cx,cy The size of the filled area
|
* @param[in] cx,cy The size of the filled area
|
||||||
* @param[in] srcx,srcy I've no idea
|
* @param[in] srcx,srcy The bitmap position to start the fill form
|
||||||
* @param[in] srccx Really, I've no fucking idea
|
* @param[in] srccx The width of a line in the bitmap
|
||||||
* @param[in] buffer The bitmap in the driver's pixel format
|
* @param[in] buffer The bitmap in the driver's pixel format
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
|
|
36
src/gwin.c
36
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.
|
* @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);
|
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.
|
* @brief Draw a circle in the window.
|
||||||
* @note Uses the current foreground color to draw the circle
|
* @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
|
#endif
|
||||||
|
|
||||||
#if GDISP_NEED_CIRCLE
|
#if GDISP_NEED_CIRCLE || defined(__DOXYGEN__)
|
||||||
/**
|
/**
|
||||||
* @brief Draw a filled circle in the window.
|
* @brief Draw a filled circle in the window.
|
||||||
* @note Uses the current foreground color to draw the filled circle
|
* @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
|
#endif
|
||||||
|
|
||||||
#if GDISP_NEED_ELLIPSE
|
#if GDISP_NEED_ELLIPSE || defined(__DOXYGEN__)
|
||||||
/**
|
/**
|
||||||
* @brief Draw an ellipse.
|
* @brief Draw an ellipse.
|
||||||
* @note Uses the current foreground color to draw the 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
|
#endif
|
||||||
|
|
||||||
#if GDISP_NEED_ELLIPSE
|
#if GDISP_NEED_ELLIPSE || defined(__DOXYGEN__)
|
||||||
/**
|
/**
|
||||||
* @brief Draw an filled ellipse.
|
* @brief Draw an filled ellipse.
|
||||||
* @note Uses the current foreground color to draw the 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
|
#endif
|
||||||
|
|
||||||
#if GDISP_NEED_ARC
|
#if GDISP_NEED_ARC || defined(__DOXYGEN__)
|
||||||
/*
|
/*
|
||||||
* @brief Draw an arc in the window.
|
* @brief Draw an arc in the window.
|
||||||
* @note Uses the current foreground color to draw the arc
|
* @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
|
#endif
|
||||||
|
|
||||||
#if GDISP_NEED_ARC
|
#if GDISP_NEED_ARC || defined(__DOXYGEN__)
|
||||||
/*
|
/*
|
||||||
* @brief Draw a filled arc in the window.
|
* @brief Draw a filled arc in the window.
|
||||||
* @note Uses the current foreground color to draw the filled arc
|
* @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
|
#endif
|
||||||
|
|
||||||
#if GDISP_NEED_PIXELREAD
|
#if GDISP_NEED_PIXELREAD || defined(__DOXYGEN__)
|
||||||
/**
|
/**
|
||||||
* @brief Get the color of a pixel in the window.
|
* @brief Get the color of a pixel in the window.
|
||||||
* @return The color of the pixel.
|
* @return The color of the pixel.
|
||||||
|
@ -398,7 +398,7 @@ color_t gwinGetPixelColor(GHandle gh, coord_t x, coord_t y) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if GDISP_NEED_TEXT
|
#if GDISP_NEED_TEXT || defined(__DOXYGEN__)
|
||||||
/**
|
/**
|
||||||
* @brief Draw a text character at the specified position in the window.
|
* @brief Draw a text character at the specified position in the window.
|
||||||
* @pre The font must have been set.
|
* @pre The font must have been set.
|
||||||
|
@ -420,7 +420,7 @@ void gwinDrawChar(GHandle gh, coord_t x, coord_t y, char c) {
|
||||||
}
|
}
|
||||||
#endif
|
#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.
|
* @brief Draw a text character with a filled background at the specified position in the window.
|
||||||
* @pre The font must have been set.
|
* @pre The font must have been set.
|
||||||
|
@ -442,7 +442,7 @@ void gwinFillChar(GHandle gh, coord_t x, coord_t y, char c) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if GDISP_NEED_TEXT
|
#if GDISP_NEED_TEXT || defined(__DOXYGEN__)
|
||||||
/**
|
/**
|
||||||
* @brief Draw a text string in the window
|
* @brief Draw a text string in the window
|
||||||
* @pre The font must have been set.
|
* @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
|
#endif
|
||||||
|
|
||||||
#if GDISP_NEED_TEXT
|
#if GDISP_NEED_TEXT || defined(__DOXYGEN__)
|
||||||
/**
|
/**
|
||||||
* @brief Draw a text string with a filled background in the window
|
* @brief Draw a text string with a filled background in the window
|
||||||
* @pre The font must have been set.
|
* @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
|
#endif
|
||||||
|
|
||||||
#if GDISP_NEED_TEXT
|
#if GDISP_NEED_TEXT || defined(__DOXYGEN__)
|
||||||
/**
|
/**
|
||||||
* @brief Draw a text string verticly centered within the specified box.
|
* @brief Draw a text string verticly centered within the specified box.
|
||||||
* @pre The font must have been set.
|
* @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] 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] 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] str The string to draw
|
||||||
* @param[in] justify Justify the text left, center or right within the box
|
* @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
|
#endif
|
||||||
|
|
||||||
#if GDISP_NEED_TEXT
|
#if GDISP_NEED_TEXT || defined(__DOXYGEN__)
|
||||||
/**
|
/**
|
||||||
* @brief Draw a text string verticly centered within the specified filled box.
|
* @brief Draw a text string verticly centered within the specified filled box.
|
||||||
* @pre The font must have been set.
|
* @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] 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] 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] str The string to draw
|
||||||
* @param[in] justify Justify the text left, center or right within the box
|
* @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
|
* 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 = {
|
static const GButtonStyle GButtonDefaultStyle = {
|
||||||
GBTN_3D,
|
GBTN_3D,
|
||||||
|
@ -720,7 +722,7 @@ static const GButtonStyle GButtonDefaultStyle = {
|
||||||
* @brief Create a button window.
|
* @brief Create a button window.
|
||||||
* @return NULL if there is no resultant drawing area, otherwise a window handle.
|
* @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] x,y The screen co-ordinates for the bottom left corner of the window
|
||||||
* @param[in] width The width of the window
|
* @param[in] width The width of the window
|
||||||
* @param[in] height The height of the window
|
* @param[in] height The height of the window
|
||||||
|
|
|
@ -85,64 +85,64 @@ static coord_t _tsReadRealY(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _tsDrawCross(uint16_t x, uint16_t y) {
|
static void _tsDrawCross(uint16_t x, uint16_t y) {
|
||||||
gdispDrawLine(x-15, y, x-2, y, White);
|
gdispDrawLine(x-15, y, x-2, y, White);
|
||||||
gdispDrawLine(x+2, y, x+15, y, White);
|
gdispDrawLine(x+2, y, x+15, y, White);
|
||||||
gdispDrawLine(x, y-15, x, y-2, White);
|
gdispDrawLine(x, y-15, x, y-2, White);
|
||||||
gdispDrawLine(x, y+2, x, y+15, 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+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+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-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-7, x-15, y-15, RGB2COLOR(184,158,131));
|
||||||
|
|
||||||
gdispDrawLine(x+7, y+15, 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+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+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+15, y-15, x+15, y-7, RGB2COLOR(184,158,131));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _tsTransform(coord_t *x, coord_t *y) {
|
static void _tsTransform(coord_t *x, coord_t *y) {
|
||||||
*x = (coord_t) (cal->ax * (*x) + cal->bx * (*y) + cal->cx);
|
*x = (coord_t) (cal->ax * (*x) + cal->bx * (*y) + cal->cx);
|
||||||
*y = (coord_t) (cal->ay * (*x) + cal->by * (*y) + cal->cy);
|
*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) {
|
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 */
|
/* Compute all the required determinants */
|
||||||
dx = ((float)(points[0][0] - points[2][0])) * ((float)(points[1][1] - points[2][1]))
|
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]));
|
- ((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]))
|
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]));
|
- ((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]))
|
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]));
|
- ((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]) -
|
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[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]);
|
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]))
|
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]));
|
- ((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]))
|
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]));
|
- ((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]) -
|
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[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]);
|
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 */
|
/* Now, calculate all the required coefficients */
|
||||||
c->ax = dx0 / dx;
|
c->ax = dx0 / dx;
|
||||||
c->bx = dx1 / dx;
|
c->bx = dx1 / dx;
|
||||||
c->cx = dx2 / dx;
|
c->cx = dx2 / dx;
|
||||||
|
|
||||||
c->ay = dy0 / dx;
|
c->ay = dy0 / dx;
|
||||||
c->by = dy1 / dx;
|
c->by = dy1 / dx;
|
||||||
c->cy = dy2 / dx;
|
c->cy = dy2 / dx;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -151,15 +151,13 @@ static void _tsDo3PointCalibration(const coord_t (*cross)[2], coord_t (*points)[
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Touchscreen Driver initialization.
|
* @brief Touchscreen Driver initialization.
|
||||||
* @note This function is NOT currently implicitly invoked by @p halInit().
|
* @note Calling this function automatically invokes a tsCalibration()
|
||||||
* It must be called manually.
|
|
||||||
*
|
*
|
||||||
* @param[in] ts The touchscreen driver struct
|
* @param[in] ts The touchscreen driver struct
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
void tsInit(const TouchscreenDriver *ts) {
|
void tsInit(const TouchscreenDriver *ts) {
|
||||||
|
|
||||||
/* Initialise Mutex */
|
/* Initialise Mutex */
|
||||||
//MUTEX_INIT
|
//MUTEX_INIT
|
||||||
|
|
||||||
|
@ -177,6 +175,7 @@ void tsInit(const TouchscreenDriver *ts) {
|
||||||
cal = (struct cal_t*)chHeapAlloc(NULL, sizeof(struct cal_t));
|
cal = (struct cal_t*)chHeapAlloc(NULL, sizeof(struct cal_t));
|
||||||
if(cal == NULL)
|
if(cal == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
tsCalibrate();
|
tsCalibrate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,17 +187,17 @@ void tsInit(const TouchscreenDriver *ts) {
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
coord_t tsReadX(void) {
|
coord_t tsReadX(void) {
|
||||||
coord_t x, y;
|
coord_t x, y;
|
||||||
|
|
||||||
#if TOUCHSCREEN_XY_INVERTED == TRUE
|
#if TOUCHSCREEN_XY_INVERTED
|
||||||
x = _tsReadRealY();
|
x = _tsReadRealY();
|
||||||
y = _tsReadRealX();
|
y = _tsReadRealX();
|
||||||
#else
|
#else
|
||||||
x = _tsReadRealX();
|
x = _tsReadRealX();
|
||||||
y = _tsReadRealY();
|
y = _tsReadRealY();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_tsTransform(&x, &y);
|
_tsTransform(&x, &y);
|
||||||
|
|
||||||
switch(gdispGetOrientation()) {
|
switch(gdispGetOrientation()) {
|
||||||
case GDISP_ROTATE_0:
|
case GDISP_ROTATE_0:
|
||||||
|
@ -206,9 +205,9 @@ coord_t tsReadX(void) {
|
||||||
case GDISP_ROTATE_90:
|
case GDISP_ROTATE_90:
|
||||||
return y;
|
return y;
|
||||||
case GDISP_ROTATE_180:
|
case GDISP_ROTATE_180:
|
||||||
return gdispGetWidth() - x - 1;
|
return GDISP_SCREEN_WIDTH - x - 1;
|
||||||
case GDISP_ROTATE_270:
|
case GDISP_ROTATE_270:
|
||||||
return gdispGetHeight() - y - 1;
|
return GDISP_SCREEN_HEIGHT - y - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -224,7 +223,7 @@ coord_t tsReadX(void) {
|
||||||
coord_t tsReadY(void) {
|
coord_t tsReadY(void) {
|
||||||
coord_t x, y;
|
coord_t x, y;
|
||||||
|
|
||||||
#if TOUCHSCREEN_XY_INVERTED == TRUE
|
#if TOUCHSCREEN_XY_INVERTED
|
||||||
x = _tsReadRealY();
|
x = _tsReadRealY();
|
||||||
y = _tsReadRealX();
|
y = _tsReadRealX();
|
||||||
#else
|
#else
|
||||||
|
@ -238,9 +237,9 @@ coord_t tsReadY(void) {
|
||||||
case GDISP_ROTATE_0:
|
case GDISP_ROTATE_0:
|
||||||
return y;
|
return y;
|
||||||
case GDISP_ROTATE_90:
|
case GDISP_ROTATE_90:
|
||||||
return gdispGetWidth() - x - 1;
|
return GDISP_SCREEN_WIDTH - x - 1;
|
||||||
case GDISP_ROTATE_180:
|
case GDISP_ROTATE_180:
|
||||||
return gdispGetHeight() - y - 1;
|
return GDISP_SCREEN_HEIGHT - y - 1;
|
||||||
case GDISP_ROTATE_270:
|
case GDISP_ROTATE_270:
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
@ -270,8 +269,8 @@ coord_t tsReadY(void) {
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
#if TOUCHSCREEN_HAS_IRQ || defined(__DOXYGEN__)
|
#if TOUCHSCREEN_HAS_IRQ || defined(__DOXYGEN__)
|
||||||
bool_t tsIRQ(void) {
|
bool_t tsPressed(void) {
|
||||||
return ts_lld_irq();
|
return ts_lld_pressed();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -285,88 +284,94 @@ coord_t tsReadY(void) {
|
||||||
* the accuracy of the calibration coefficients obtained if the symbol
|
* the accuracy of the calibration coefficients obtained if the symbol
|
||||||
* TOUCHSCREEN_VERIFY_CALIBRATION is defined in the configuration.
|
* TOUCHSCREEN_VERIFY_CALIBRATION is defined in the configuration.
|
||||||
*
|
*
|
||||||
|
* @note You don't have to call this function manually. It gets invoked by tsInit()
|
||||||
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
void tsCalibrate(void) {
|
void tsCalibrate(void) {
|
||||||
const uint16_t height = gdispGetHeight();
|
const uint16_t height = gdispGetHeight();
|
||||||
const uint16_t width = gdispGetWidth();
|
const uint16_t width = gdispGetWidth();
|
||||||
const coord_t cross[][2] = {{(width / 4), (height / 4)},
|
const coord_t cross[][2] = {{(width / 4), (height / 4)},
|
||||||
{(width - (width / 4)) , (height / 4)},
|
{(width - (width / 4)) , (height / 4)},
|
||||||
{(width - (width / 4)) , (height - (height / 4))},
|
{(width - (width / 4)) , (height - (height / 4))},
|
||||||
{(width / 2), (height / 2)}}; /* Check point */
|
{(width / 2), (height / 2)}}; /* Check point */
|
||||||
coord_t points[4][2];
|
coord_t points[4][2];
|
||||||
int32_t px, py;
|
int32_t px, py;
|
||||||
uint8_t i, j;
|
uint8_t i, j;
|
||||||
|
|
||||||
gdispSetOrientation(GDISP_ROTATE_0);
|
gdispSetOrientation(GDISP_ROTATE_0);
|
||||||
gdispClear(Blue);
|
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
|
#if TOUCHSCREEN_VERIFY_CALIBRATION
|
||||||
calibrate:
|
calibrate:
|
||||||
for(i = 0; i < 4; i++) {
|
for(i = 0; i < 4; i++) {
|
||||||
#else
|
#else
|
||||||
for(i = 0; i < 3; i++) {
|
for(i = 0; i < 3; i++) {
|
||||||
#endif
|
#endif
|
||||||
_tsDrawCross(cross[i][0], cross[i][1]);
|
_tsDrawCross(cross[i][0], cross[i][1]);
|
||||||
|
|
||||||
while(!tsIRQ())
|
while(!tsPressed())
|
||||||
chThdSleepMilliseconds(2); /* Be nice to other threads*/
|
chThdSleepMilliseconds(2); /* Be nice to other threads*/
|
||||||
|
|
||||||
|
chThdSleepMilliseconds(20); /* Allow screen to settle */
|
||||||
|
|
||||||
chThdSleepMilliseconds(20); /* Allow screen to settle */
|
/* Take a little more samples per point and their average
|
||||||
|
* for precise calibration */
|
||||||
|
px = py = 0;
|
||||||
|
j = 0;
|
||||||
|
|
||||||
/* Take a little more samples per point and their average
|
while(j < MAX_CAL_SAMPLES) {
|
||||||
* for precise calibration */
|
if(tsPressed()) { /* We have valid pointer data */
|
||||||
px = py = 0;
|
#if TOUCHSCREEN_XY_INVERTED
|
||||||
|
py += _tsReadRealX();
|
||||||
|
px += _tsReadRealY();
|
||||||
|
#else
|
||||||
|
px += _tsReadRealX();
|
||||||
|
py += _tsReadRealY();
|
||||||
|
#endif
|
||||||
|
|
||||||
j = 0;
|
j++;
|
||||||
while (j < MAX_CAL_SAMPLES) {
|
}
|
||||||
if (tsIRQ()) {
|
}
|
||||||
/* We have valid pointer data */
|
|
||||||
px += _tsReadRealX();
|
points[i][0] = px / j;
|
||||||
py += _tsReadRealY();
|
points[i][1] = py / j;
|
||||||
|
|
||||||
j++;
|
chThdSleepMilliseconds(100);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
points[i][0] = px / j;
|
while(tsPressed())
|
||||||
points[i][1] = py / j;
|
chThdSleepMilliseconds(2); /* Be nice to other threads*/
|
||||||
|
|
||||||
chThdSleepMilliseconds(100);
|
gdispFillArea(cross[i][0] - 15, cross[i][1] - 15, 42, 42, Blue);
|
||||||
|
}
|
||||||
|
|
||||||
while(tsIRQ())
|
/* Apply 3 point calibration algorithm */
|
||||||
chThdSleepMilliseconds(2); /* Be nice to other threads*/
|
_tsDo3PointCalibration(cross, points, cal);
|
||||||
|
|
||||||
gdispFillArea(cross[i][0] - 15, cross[i][1] - 15, 42, 42, Blue);
|
#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.
|
||||||
|
*/
|
||||||
|
|
||||||
/* Apply 3 point calibration algorithm */
|
/* Transform the co-ordinates */
|
||||||
_tsDo3PointCalibration(cross, points, cal);
|
_tpTransform(&points[3][0], &points[3][1]);
|
||||||
|
|
||||||
#if TOUCHSCREEN_VERIFY_CALIBRATION
|
/* Calculate the delta */
|
||||||
/* Verification of correctness of calibration (optional) :
|
px = (points[3][0] - cross[3][0]) * (points[3][0] - cross[3][0]) +
|
||||||
* See if the 4th point (Middle of the screen) coincides with the calibrated
|
(points[3][1] - cross[3][1]) * (points[3][1] - cross[3][1]);
|
||||||
* result. If point is with +/- 2 pixel margin, then successful calibration
|
|
||||||
* Else, start from the beginning.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Transform the co-ordinates */
|
if(px > 4)
|
||||||
_tpTransform(&points[3][0], &points[3][1]);
|
goto calibrate;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Calculate the delta */
|
/* If enabled, serialize the calibration values for storage */
|
||||||
px = (points[3][0] - cross[3][0]) * (points[3][0] - cross[3][0]) +
|
#if TOUCHSCREEN_STORE_CALIBRATION
|
||||||
(points[3][1] - cross[3][1]) * (points[3][1] - cross[3][1]);
|
ts_store_calibration_lld(cal);
|
||||||
|
#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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* GFX_USE_TOUCHSCREEN */
|
#endif /* GFX_USE_TOUCHSCREEN */
|
||||||
|
|
Loading…
Add table
Reference in a new issue