Merge pull request #14 from inmarket/master

Win32 touch support
ugfx_release_2.6
Tectu 2012-11-10 03:19:45 -08:00
commit cc5ae04b7b
8 changed files with 198 additions and 33 deletions

View File

@ -29,6 +29,7 @@
#include "ch.h"
#include "hal.h"
#include "gdisp.h"
#include "touchscreen.h"
#if GFX_USE_GDISP /*|| defined(__DOXYGEN__)*/
@ -56,6 +57,8 @@ static HDC dcBuffer = NULL;
static HBITMAP dcBitmap = NULL;
static HBITMAP dcOldBitmap;
static volatile bool_t isReady = FALSE;
static coord_t mousex, mousey;
static bool_t mousedn;
static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
@ -65,9 +68,20 @@ static LRESULT myWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
switch (Msg) {
case WM_CREATE:
break;
case WM_MOUSEMOVE:
case WM_LBUTTONDOWN:
mousedn = TRUE;
mousex = (coord_t)LOWORD(lParam);
mousey = (coord_t)HIWORD(lParam);
break;
case WM_LBUTTONUP:
mousedn = FALSE;
mousex = (coord_t)LOWORD(lParam);
mousey = (coord_t)HIWORD(lParam);
break;
case WM_MOUSEMOVE:
mousex = (coord_t)LOWORD(lParam);
mousey = (coord_t)HIWORD(lParam);
break;
case WM_LBUTTONDBLCLK:
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
@ -129,13 +143,18 @@ static DWORD WINAPI WindowThread(LPVOID lpParameter) {
wc.lpszClassName = APP_NAME;
RegisterClass(&wc);
rect.top = 0; rect.bottom = GDISP.Height;
rect.left = 0; rect.right = GDISP.Width;
AdjustWindowRect(&rect, WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU, 0);
winRootWindow = CreateWindow(APP_NAME, "", WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU, 0, 0,
GDISP.Width, GDISP.Height, 0, 0, hInstance, NULL);
rect.right-rect.left, rect.bottom-rect.top, 0, 0, hInstance, NULL);
assert(winRootWindow != NULL);
HDC dc = GetDC(winRootWindow);
GetClientRect(winRootWindow, &rect);
GDISP.Width = rect.right-rect.left;
GDISP.Height = rect.bottom - rect.top;
dcBitmap = CreateCompatibleBitmap(dc, GDISP.Width, GDISP.Height);
dcBuffer = CreateCompatibleDC(dc);
dcOldBitmap = SelectObject(dcBuffer, dcBitmap);
@ -430,6 +449,9 @@ void GDISP_LLD(drawpixel)(coord_t x, coord_t y, color_t color) {
* @notapi
*/
void GDISP_LLD(verticalscroll)(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) {
RECT rect, frect;
HBRUSH hbr;
#if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
if (x < GDISP.clipx0) { cx -= GDISP.clipx0 - x; x = GDISP.clipx0; }
if (y < GDISP.clipy0) { cy -= GDISP.clipy0 - y; y = GDISP.clipy0; }
@ -437,10 +459,99 @@ void GDISP_LLD(drawpixel)(coord_t x, coord_t y, color_t color) {
if (x+cx > GDISP.clipx1) cx = GDISP.clipx1 - x;
if (y+cy > GDISP.clipy1) cy = GDISP.clipy1 - y;
#endif
/* NOT IMPLEMENTED YET */
rect.bottom = y+cy;
rect.top = y;
rect.left = x;
rect.right = x+cx;
if (cy > lines && cy > -lines)
ScrollDC(dcBuffer, 0, -lines, &rect, 0, 0, 0);
bgcolor = COLOR2BGR(bgcolor);
hbr = CreateSolidBrush(bgcolor);
if (hbr) {
if (lines > 0) {
if (lines > cy) lines = cy;
frect.bottom = y+cy;
frect.top = y+cy-lines;
} else {
if (-lines > cy) lines = -cy;
frect.top = y;
frect.bottom = y-lines;
}
frect.left = x;
frect.right = x+cx;
FillRect(dcBuffer, &frect, hbr);
}
InvalidateRect(winRootWindow, &rect, FALSE);
UpdateWindow(winRootWindow);
}
#endif
#if GFX_USE_TOUCHSCREEN /*|| defined(__DOXYGEN__)*/
void ts_store_calibration_lld(struct cal_t *cal) {
(void) cal;
// Just ignore the calibration data - we implicitly know the calibration
}
struct cal_t *ts_restore_calibration_lld(void) {
static struct cal_t cal = { 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 };
// Our x,y is always already calibrated.
return &cal;
}
/**
* @brief Low level touchscreen driver initialization.
*
* @param[in] ts The touchscreen driver
*
* @notapi
*/
void ts_lld_init(const TouchscreenDriver *ts) {
(void) ts;
// Just ignore everything
}
/**
* @brief Reads out the X direction.
*
* @notapi
*/
uint16_t ts_lld_read_x(void) {
return mousex;
}
/**
* @brief Reads out the Y direction.
*
* @notapi
*/
uint16_t ts_lld_read_y(void) {
return mousey;
}
/**
* @brief Reads out the Z direction.
*
* @notapi
*/
uint16_t ts_lld_read_z(void) {
return 0;
}
/*
* @brief for checking if touchpad is pressed or not.
*
* @return 1 if pressed / 0 if not pressed
*
* @notapi
*/
uint8_t ts_lld_irq(void) {
return (uint8_t)mousedn;
}
#endif /* GFX_USE_TOUCHSCREEN */
#endif /* GFX_USE_GDISP */
/** @} */

View File

@ -41,7 +41,7 @@
#define GDISP_HARDWARE_LINES TRUE
#define GDISP_HARDWARE_FILLS TRUE
#define GDISP_HARDWARE_BITFILLS TRUE
#define GDISP_HARDWARE_SCROLL FALSE
#define GDISP_HARDWARE_SCROLL TRUE
#define GDISP_HARDWARE_PIXELREAD TRUE
#define GDISP_PIXELFORMAT GDISP_PIXELFORMAT_RGB888

View File

@ -1,9 +1,13 @@
To use this driver:
This driver is special in that it implements both the gdisp low level driver
and a touchscreen driver.
1. Add in your halconf.h:
a) #define GFX_USE_GDISP TRUE
b) Any optional high level driver defines (see gdisp.h) eg: GDISP_NEED_MULTITHREAD
c) All of the following (with appropriate values):
a) #define GFX_USE_GDISP TRUE
b) #define GFX_USE_TOUCHSCREEN TRUE
c) Any optional high level driver defines (see gdisp.h) eg: GDISP_NEED_MULTITHREAD
d) All of the following (with appropriate values):
#define GDISP_SCREEN_WIDTH 640
#define GDISP_SCREEN_HEIGHT 480

View File

@ -0,0 +1,51 @@
/*
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 drivers/touchscreen/ADS7843/touchscreen_lld_config.h
* @brief Touchscreen Driver subsystem low level driver.
*
* @addtogroup TOUCHSCREEN
* @{
*/
#ifndef TOUCHSCREEN_LLD_CONFIG_H
#define TOUCHSCREEN_LLD_CONFIG_H
#if GFX_USE_TOUCHSCREEN /*|| defined(__DOXYGEN__)*/
/*===========================================================================*/
/* Driver hardware support. */
/*===========================================================================*/
#define TOUCHSCREEN_HAS_IRQ TRUE
#define TOUCHSCREEN_HAS_PRESSURE FALSE
#define TOUCHSCREEN_XY_INVERTED FALSE
#define TOUCHSCREEN_STORE_CALIBRATION TRUE
/* Nasty stuff to fix SPI dependancy in driver structure (which doesn't exist in Win32) */
typedef struct SPIDriver_t {} SPIDriver;
typedef struct SPIConfig_t {} SPIConfig;
#endif /* GFX_USE_TOUCHSCREEN */
#endif /* TOUCHSCREEN_LLD_CONFIG_H */
/** @} */

View File

@ -293,6 +293,7 @@ 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))

View File

@ -468,8 +468,6 @@
#define RED_OF(c) (((c) & 0xF800)>>8)
#define GREEN_OF(c) (((c)&0x007E)>>3)
#define BLUE_OF(c) (((c)&0x001F)<<3)
#define RGB565CONVERT(red, green, blue) (uint16_t)( (( red >> 3 ) << 11 ) | (( green >> 2 ) << 5 ) | ( blue >> 3 ))
#elif GDISP_PIXELFORMAT == GDISP_PIXELFORMAT_RGB888
typedef uint32_t color_t;

View File

@ -66,7 +66,7 @@
/* Low Level Driver details and error checks. */
/*===========================================================================*/
#if !defined(GFX_USE_GDISP)
#if !defined(GFX_USE_GDISP) || !GFX_USE_GDISP
#error "GWIN: GFX_USE_GDISP must also be defined"
#endif
#include "gdisp.h"

View File

@ -85,22 +85,22 @@ static coord_t _tsReadRealY(void) {
}
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, 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, 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, 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, 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, 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, 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, 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, RGB565CONVERT(184,158,131));
gdispDrawLine(x+15, y-15, x+15, y-7, RGB565CONVERT(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) {
@ -159,9 +159,6 @@ static void _tsDo3PointCalibration(const coord_t (*cross)[2], coord_t (*points)[
* @api
*/
void tsInit(const TouchscreenDriver *ts) {
cal = (struct cal_t*)chHeapAlloc(NULL, sizeof(struct cal_t));
if(cal == NULL)
return;
/* Initialise Mutex */
//MUTEX_INIT
@ -173,11 +170,14 @@ void tsInit(const TouchscreenDriver *ts) {
#if TOUCHSCREEN_STORE_CALIBRATION
cal = ts_restore_calibration_lld();
if(cal == NULL) {
cal = (struct cal_t*)chHeapAlloc(NULL, sizeof(struct cal_t));
tsCalibrate();
}
if(cal != NULL)
return; // All done
#endif
cal = (struct cal_t*)chHeapAlloc(NULL, sizeof(struct cal_t));
if(cal == NULL)
return;
tsCalibrate();
}
/**
@ -206,9 +206,9 @@ coord_t tsReadX(void) {
case GDISP_ROTATE_90:
return y;
case GDISP_ROTATE_180:
return GDISP_SCREEN_WIDTH - x - 1;
return gdispGetWidth() - x - 1;
case GDISP_ROTATE_270:
return GDISP_SCREEN_HEIGHT - y - 1;
return gdispGetHeight() - y - 1;
}
return 0;
@ -238,9 +238,9 @@ coord_t tsReadY(void) {
case GDISP_ROTATE_0:
return y;
case GDISP_ROTATE_90:
return GDISP_SCREEN_WIDTH - x - 1;
return gdispGetWidth() - x - 1;
case GDISP_ROTATE_180:
return GDISP_SCREEN_HEIGHT - y - 1;
return gdispGetHeight() - y - 1;
case GDISP_ROTATE_270:
return x;
}