From 77e1371b86c6181da153d68b326c624486c1245c Mon Sep 17 00:00:00 2001 From: Andrew Hannam Date: Sat, 10 Nov 2012 17:45:53 +1000 Subject: [PATCH] Added touch to gdisp Win32 driver GDISP Win32 driver: Fixed a window sizing bug Added hardware scroll support Added touchscreen integrated driver into this driver --- drivers/gdisp/Win32/gdisp_lld.c | 117 ++++++++++++++++++- drivers/gdisp/Win32/gdisp_lld_config.h | 2 +- drivers/gdisp/Win32/readme.txt | 10 +- drivers/gdisp/Win32/touchscreen_lld_config.h | 51 ++++++++ 4 files changed, 173 insertions(+), 7 deletions(-) create mode 100644 drivers/gdisp/Win32/touchscreen_lld_config.h diff --git a/drivers/gdisp/Win32/gdisp_lld.c b/drivers/gdisp/Win32/gdisp_lld.c index 523e695d..4cf69b0e 100644 --- a/drivers/gdisp/Win32/gdisp_lld.c +++ b/drivers/gdisp/Win32/gdisp_lld.c @@ -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 */ /** @} */ diff --git a/drivers/gdisp/Win32/gdisp_lld_config.h b/drivers/gdisp/Win32/gdisp_lld_config.h index e0afa6c3..3fa485b1 100644 --- a/drivers/gdisp/Win32/gdisp_lld_config.h +++ b/drivers/gdisp/Win32/gdisp_lld_config.h @@ -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 diff --git a/drivers/gdisp/Win32/readme.txt b/drivers/gdisp/Win32/readme.txt index 3c3e1705..a475118b 100644 --- a/drivers/gdisp/Win32/readme.txt +++ b/drivers/gdisp/Win32/readme.txt @@ -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 diff --git a/drivers/gdisp/Win32/touchscreen_lld_config.h b/drivers/gdisp/Win32/touchscreen_lld_config.h new file mode 100644 index 00000000..de200ef9 --- /dev/null +++ b/drivers/gdisp/Win32/touchscreen_lld_config.h @@ -0,0 +1,51 @@ +/* + ChibiOS/GFX - Copyright (C) 2012 + Joel Bodenmann aka Tectu + + 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 . +*/ + +/** + * @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 */ +/** @} */ +