From b7baee596b7fe1689db3ed4d02decd96cf2fe28f Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 13 Oct 2014 16:37:48 +1000 Subject: Convert FT5x06 mouse driver to newmouse (untested) --- drivers/ginput/touch/FT5x06/ginput_lld_mouse.c | 88 --------------- .../touch/FT5x06/ginput_lld_mouse_board_template.h | 27 ----- .../ginput/touch/FT5x06/ginput_lld_mouse_config.h | 21 ---- drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06.c | 120 +++++++++++++++++++++ .../FT5x06/gmouse_lld_FT5x06_board_template.h | 46 ++++++++ 5 files changed, 166 insertions(+), 136 deletions(-) delete mode 100644 drivers/ginput/touch/FT5x06/ginput_lld_mouse.c delete mode 100644 drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_template.h delete mode 100644 drivers/ginput/touch/FT5x06/ginput_lld_mouse_config.h create mode 100644 drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06.c create mode 100644 drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06_board_template.h (limited to 'drivers') diff --git a/drivers/ginput/touch/FT5x06/ginput_lld_mouse.c b/drivers/ginput/touch/FT5x06/ginput_lld_mouse.c deleted file mode 100644 index 7a50c5f6..00000000 --- a/drivers/ginput/touch/FT5x06/ginput_lld_mouse.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#include "gfx.h" - -#if (GFX_USE_GINPUT && GINPUT_NEED_MOUSE) /*|| defined(__DOXYGEN__)*/ - -#include "src/ginput/driver_mouse.h" - -#include "drivers/ginput/touch/FT5x06/ft5x06.h" - -// include board abstraction -#include "ginput_lld_mouse_board.h" - -static coord_t x, y, z; -static uint8_t touched; - -void ginput_lld_mouse_init(void) { - init_board(); - - // Init default values. (From NHD-3.5-320240MF-ATXL-CTP-1 datasheet) - // Valid touching detect threshold - write_reg(FT5x06_ID_G_THGROUP, 1, 0x16); - - // valid touching peak detect threshold - write_reg(FT5x06_ID_G_THPEAK, 1, 0x3C); - - // Touch focus threshold - write_reg(FT5x06_ID_G_THCAL, 1, 0xE9); - - // threshold when there is surface water - write_reg(FT5x06_ID_G_THWATER, 1, 0x01); - - // threshold of temperature compensation - write_reg(FT5x06_ID_G_THTEMP, 1, 0x01); - - // Touch difference threshold - write_reg(FT5x06_ID_G_THDIFF, 1, 0xA0); - - // Delay to enter 'Monitor' status (s) - write_reg(FT5x06_ID_G_TIME_ENTER_MONITOR, 1, 0x0A); - - // Period of 'Active' status (ms) - write_reg(FT5x06_ID_G_PERIODACTIVE, 1, 0x06); - - // Timer to enter ÔidleÕ when in 'Monitor' (ms) - write_reg(FT5x06_ID_G_PERIODMONITOR, 1, 0x28); -} - -void ginput_lld_mouse_get_reading(MouseReading *pt) { - // Poll to get the touched status - uint8_t last_touched; - - last_touched = touched; - touched = (uint8_t)read_reg(FT5x06_TOUCH_POINTS, 1) & 0x07; - - // If not touched, return the previous results - if (touched == 0) { - pt->x = x; - pt->y = y; - pt->z = 0; - pt->buttons = 0; - return; - } - - /* Get the X, Y, Z values */ - x = (coord_t)(read_reg(FT5x06_TOUCH1_XH, 2) & 0x0fff); - y = (coord_t)read_reg(FT5x06_TOUCH1_YH, 2); - z = 100; - - // Rescale X,Y,Z - X & Y don't need scaling when you are using calibration! -#if !GINPUT_MOUSE_NEED_CALIBRATION - x = gdispGetWidth() - x / (4096/gdispGetWidth()); - y = y / (4096/gdispGetHeight()); -#endif - - // Return the results. ADC gives values from 0 to 2^12 (4096) - pt->x = x; - pt->y = y; - pt->z = z; - pt->buttons = GINPUT_TOUCH_PRESSED; -} - -#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */ diff --git a/drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_template.h b/drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_template.h deleted file mode 100644 index b7744a49..00000000 --- a/drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_template.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _GINPUT_LLD_MOUSE_BOARD_H -#define _GINPUT_LLD_MOUSE_BOARD_H - -static void init_board(void) { - -} - -static inline bool_t getpin_irq(void) { - -} - -static void write_reg(uint8_t reg, uint8_t n, uint16_t val) { - -} - -static uint16_t read_reg(uint8_t reg, uint8_t n) { - -} - -#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ diff --git a/drivers/ginput/touch/FT5x06/ginput_lld_mouse_config.h b/drivers/ginput/touch/FT5x06/ginput_lld_mouse_config.h deleted file mode 100644 index 24335a0a..00000000 --- a/drivers/ginput/touch/FT5x06/ginput_lld_mouse_config.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -#ifndef _LLD_GINPUT_MOUSE_CONFIG_H -#define _LLD_GINPUT_MOUSE_CONFIG_H - -#define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH -#define GINPUT_MOUSE_NEED_CALIBRATION TRUE -#define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE -#define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 15 -#define GINPUT_MOUSE_READ_CYCLES 1 -#define GINPUT_MOUSE_POLL_PERIOD 25 -#define GINPUT_MOUSE_MAX_CLICK_JITTER 10 -#define GINPUT_MOUSE_MAX_MOVE_JITTER 5 -#define GINPUT_MOUSE_CLICK_TIME 450 - -#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */ diff --git a/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06.c b/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06.c new file mode 100644 index 00000000..ed2e68fa --- /dev/null +++ b/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06.c @@ -0,0 +1,120 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#include "gfx.h" + +#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE + +#define GMOUSE_DRIVER_VMT GMOUSEVMT_FT5x06 +#include "src/ginput/driver_mouse.h" + +// Get the hardware interface +#include "gmouse_lld_FT5x06_board.h" + +// Hardware definitions +#include "drivers/ginput/touch/FT5x06/ft5x06.h" + +static bool_t MouseInit(GMouse* m, unsigned driverinstance) { + if (!init_board(m, driverinstance)) + return FALSE; + + aquire_bus(m); + + // Init default values. (From NHD-3.5-320240MF-ATXL-CTP-1 datasheet) + // Valid touching detect threshold + write_reg(m, FT5x06_ID_G_THGROUP, 0x16); + + // valid touching peak detect threshold + write_reg(m, FT5x06_ID_G_THPEAK, 0x3C); + + // Touch focus threshold + write_reg(m, FT5x06_ID_G_THCAL, 0xE9); + + // threshold when there is surface water + write_reg(m, FT5x06_ID_G_THWATER, 0x01); + + // threshold of temperature compensation + write_reg(m, FT5x06_ID_G_THTEMP, 0x01); + + // Touch difference threshold + write_reg(m, FT5x06_ID_G_THDIFF, 0xA0); + + // Delay to enter 'Monitor' status (s) + write_reg(m, FT5x06_ID_G_TIME_ENTER_MONITOR, 0x0A); + + // Period of 'Active' status (ms) + write_reg(m, FT5x06_ID_G_PERIODACTIVE, 0x06); + + // Timer to enter 'idle' when in 'Monitor' (ms) + write_reg(m, FT5x06_ID_G_PERIODMONITOR, 0x28); + + release_bus(m); + return TRUE; +} + +static void MouseXYZ(GMouse* m, GMouseReading* pdr) +{ + // Assume not touched. + pdr->buttons = 0; + pdr->z = 0; + + aquire_bus(m); + + // Only take a reading if we are touched. + if ((read_byte(m, FT5x06_TOUCH_POINTS) & 0x07)) { + + /* Get the X, Y, Z values */ + pdr->x = (coord_t)(read_word(m, FT5x06_TOUCH1_XH) & 0x0fff); + pdr->y = (coord_t)read_word(m, FT5x06_TOUCH1_YH); + pdr->z = 1; + + #if GMOUSE_FT5x06_SELF_CALIBRATE + // Rescale X,Y,Z - If we are using self-calibration + pdr->x = gdispGGetWidth(m->display) - pdr->x / (4096/gdispGGetWidth(m->display)); + pdr->y = pdr->y / (4096/gdispGGetHeight(m->display)); + #endif + } + + release_bus(m); +} + +const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ + { + GDRIVER_TYPE_TOUCH, + #if GMOUSE_FT5x06_SELF_CALIBRATE + GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_POORUPDOWN, + #else + GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_POORUPDOWN | GMOUSE_VFLG_CALIBRATE | GMOUSE_VFLG_CAL_TEST, + #endif + sizeof(GMouse) + GMOUSE_FT5x06_BOARD_DATA_SIZE, + _gmouseInitDriver, + _gmousePostInitDriver, + _gmouseDeInitDriver + }, + 1, // z_max - (currently?) not supported + 0, // z_min - (currently?) not supported + 1, // z_touchon + 0, // z_touchoff + { // pen_jitter + GMOUSE_FT5x06_PEN_CALIBRATE_ERROR, // calibrate + GMOUSE_FT5x06_PEN_CLICK_ERROR, // click + GMOUSE_FT5x06_PEN_MOVE_ERROR // move + }, + { // finger_jitter + GMOUSE_FT5x06_FINGER_CALIBRATE_ERROR, // calibrate + GMOUSE_FT5x06_FINGER_CLICK_ERROR, // click + GMOUSE_FT5x06_FINGER_MOVE_ERROR // move + }, + MouseInit, // init + 0, // deinit + read_xyz, // get + 0, // calsave + 0 // calload +}}; + +#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */ + diff --git a/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06_board_template.h b/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06_board_template.h new file mode 100644 index 00000000..46680a16 --- /dev/null +++ b/drivers/ginput/touch/FT5x06/gmouse_lld_FT5x06_board_template.h @@ -0,0 +1,46 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _GINPUT_LLD_MOUSE_BOARD_H +#define _GINPUT_LLD_MOUSE_BOARD_H + +// Resolution and Accuracy Settings +#define GMOUSE_FT5x06_PEN_CALIBRATE_ERROR 8 +#define GMOUSE_FT5x06_PEN_CLICK_ERROR 6 +#define GMOUSE_FT5x06_PEN_MOVE_ERROR 4 +#define GMOUSE_FT5x06_FINGER_CALIBRATE_ERROR 14 +#define GMOUSE_FT5x06_FINGER_CLICK_ERROR 18 +#define GMOUSE_FT5x06_FINGER_MOVE_ERROR 14 + +// How much extra data to allocate at the end of the GMouse structure for the board's use +#define GMOUSE_FT5x06_BOARD_DATA_SIZE 0 + +// Set this to TRUE if you want self-calibration. +// NOTE: This is not as accurate as real calibration. +// It requires the orientation of the touch panel to match the display. +// It requires the active area of the touch panel to exactly match the display size. +#define GMOUSE_FT5x06_SELF_CALIBRATE FALSE + +static bool_t init_board(GMouse* m, unsigned driverinstance) { +} + +static inline void aquire_bus(GMouse* m) { +} + +static inline void release_bus(GMouse* m) { +} + +static void write_reg(GMouse* m, uint8_t reg, uint8_t val) { +} + +static uint8_t read_byte(GMouse* m, uint8_t reg) { +} + +static uint16_t read_word(GMouse* m, uint8_t reg) { +} + +#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ -- cgit v1.2.3