diff --git a/docs/releases.txt b/docs/releases.txt index 9468d73c..a7df3a41 100644 --- a/docs/releases.txt +++ b/docs/releases.txt @@ -5,6 +5,7 @@ *** Changes after 2.5 *** FIX: Fixing bug where the list item count wasn't decremented when an item was removed FEATURE: Add options GFILE_FATFS_EXTERNAL_LIB and GFILE_PETITFSFS_EXTERNAL_LIB +FEATURE: Added FT6x06 driver *** Release 2.5 *** diff --git a/drivers/ginput/touch/FT6x06/driver.mk b/drivers/ginput/touch/FT6x06/driver.mk new file mode 100644 index 00000000..f26f2573 --- /dev/null +++ b/drivers/ginput/touch/FT6x06/driver.mk @@ -0,0 +1 @@ +GFXSRC += $(GFXLIB)/drivers/ginput/touch/FT6x06/gmouse_lld_FT6x06.c diff --git a/drivers/ginput/touch/FT6x06/ft6x06.h b/drivers/ginput/touch/FT6x06/ft6x06.h new file mode 100644 index 00000000..63545c4b --- /dev/null +++ b/drivers/ginput/touch/FT6x06/ft6x06.h @@ -0,0 +1,88 @@ +/* + * 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 _FT6x06_H +#define _FT6x06_H + +// Slave address +#define FT6x06_ADDR 0x70//(0x70 >> 1) + +// Maximum timeout +#define FT6x06_TIMEOUT 0x3000 + +#define FT6x06_DEVICE_MODE 0x00 +#define FT6x06_GESTURE_ID 0x01 +#define FT6x06_TOUCH_POINTS 0x02 + +#define FT6x06_TOUCH1_EV_FLAG 0x03 +#define FT6x06_TOUCH1_XH 0x03 +#define FT6x06_TOUCH1_XL 0x04 +#define FT6x06_TOUCH1_YH 0x05 +#define FT6x06_TOUCH1_YL 0x06 +#define FT6x06_P1_WEIGHT 0x07 +#define FT6x06_P1_AREA 0x08 + +#define FT6x06_TOUCH2_EV_FLAG 0x09 +#define FT6x06_TOUCH2_XH 0x09 +#define FT6x06_TOUCH2_XL 0x0A +#define FT6x06_TOUCH2_YH 0x0B +#define FT6x06_TOUCH2_YL 0x0C +#define FT6x06_P2_WEIGHT 0x0D +#define FT6x06_P2_AREA 0x0E + +#define FT6x06_TOUCH3_EV_FLAG 0x0F +#define FT6x06_TOUCH3_XH 0x0F +#define FT6x06_TOUCH3_XL 0x10 +#define FT6x06_TOUCH3_YH 0x11 +#define FT6x06_TOUCH3_YL 0x12 +#define FT6x06_P3_WEIGHT 0x13 +#define FT6x06_P3_AREA 0x14 + +#define FT6x06_TOUCH4_EV_FLAG 0x15 +#define FT6x06_TOUCH4_XH 0x15 +#define FT6x06_TOUCH4_XL 0x16 +#define FT6x06_TOUCH4_YH 0x17 +#define FT6x06_TOUCH4_YL 0x18 +#define FT6x06_P4_WEIGHT 0x19 +#define FT6x06_P4_AREA 0x1A + +#define FT6x06_TOUCH5_EV_FLAG 0x1B +#define FT6x06_TOUCH5_XH 0x1B +#define FT6x06_TOUCH5_XL 0x1C +#define FT6x06_TOUCH5_YH 0x1D +#define FT6x06_TOUCH5_YL 0x1E +#define FT6x06_P5_WEIGHT 0x1F +#define FT6x06_P5_AREA 0x20 + +#define FT6x06_ID_G_THGROUP 0x80 +#define FT6x06_ID_G_THPEAK 0x81 +#define FT6x06_ID_G_THCAL 0x82 +#define FT6x06_ID_G_THWATER 0x83 +#define FT6x06_ID_G_THTEMP 0x84 +#define FT6x06_ID_G_THDIFF 0x85 +#define FT6x06_ID_G_CTRL 0x86 +#define FT6x06_ID_G_TIME_ENTER_MONITOR 0x87 +#define FT6x06_ID_G_PERIODACTIVE 0x88 +#define FT6x06_ID_G_PERIODMONITOR 0x89 +#define FT6x06_RADIAN_VALUE 0x91 +#define FT6x06_OFFSET_LEFT_RIGHT 0x92 +#define FT6x06_OFFSET_UP_DOWN 0x93 +//#define FT6x06_OFFSET_LEFT_RIGHT 0x94 +#define FT6x06_DISTANCE_U_D 0x95 +#define FT6x06_DISTANCE_ZOOM 0x96 +#define FT6x06_ID_G_AUTO_CLB_MODE 0xA0 +#define FT6x06_ID_G_LIB_VERSION_H 0xA1 +#define FT6x06_ID_G_LIB_VERSION_L 0xA2 +#define FT6x06_ID_G_CIPHER 0xA3 +#define FT6x06_ID_G_MODE 0xA4 +#define FT6x06_ID_G_PMODE 0xA5 +#define FT6x06_ID_G_FIRMID 0xA6 +#define FT6x06_ID_G_STATE 0xA7 +#define FT6x06_ID_G_ID 0xA8 +#define FT6x06_ID_G_ERR 0xA9 + +#endif /* _FT6x06_H */ diff --git a/drivers/ginput/touch/FT6x06/gmouse_lld_FT6x06.c b/drivers/ginput/touch/FT6x06/gmouse_lld_FT6x06.c new file mode 100644 index 00000000..0fc21d18 --- /dev/null +++ b/drivers/ginput/touch/FT6x06/gmouse_lld_FT6x06.c @@ -0,0 +1,137 @@ +/* + * 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_FT6x06 +#include "../../../../src/ginput/ginput_driver_mouse.h" + +// Get the hardware interface +#include "gmouse_lld_FT6x06_board.h" + +// Hardware definitions +#include "ft6x06.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, FT6x06_ID_G_THGROUP, 0x16); + + // valid touching peak detect threshold + write_reg(m, FT6x06_ID_G_THPEAK, 0x3C); + + // Touch focus threshold + write_reg(m, FT6x06_ID_G_THCAL, 0xE9); + + // threshold when there is surface water + write_reg(m, FT6x06_ID_G_THWATER, 0x01); + + // threshold of temperature compensation + write_reg(m, FT6x06_ID_G_THTEMP, 0x01); + + // Touch difference threshold + write_reg(m, FT6x06_ID_G_THDIFF, 0xA0); + + // Delay to enter 'Monitor' status (s) + write_reg(m, FT6x06_ID_G_TIME_ENTER_MONITOR, 0x0A); + + // Period of 'Active' status (ms) + write_reg(m, FT6x06_ID_G_PERIODACTIVE, 0x06); + + // Timer to enter 'idle' when in 'Monitor' (ms) + write_reg(m, FT6x06_ID_G_PERIODMONITOR, 0x28); + + release_bus(m); + return TRUE; +} + +static bool_t read_xyz(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, FT6x06_TOUCH_POINTS) & 0x07)) { + + /* Get the X, Y, Z values */ + pdr->x = (coord_t)(read_word(m, FT6x06_TOUCH1_XH) & 0x0fff); + pdr->y = (coord_t)read_word(m, FT6x06_TOUCH1_YH); + pdr->z = 1; + + // Rescale X,Y if we are using self-calibration + #if GMOUSE_FT6x06_SELF_CALIBRATE + #if GDISP_NEED_CONTROL + switch(gdispGGetOrientation(m->display)) { + default: + case GDISP_ROTATE_0: + case GDISP_ROTATE_180: + pdr->x = gdispGGetWidth(m->display) - pdr->x / (4096/gdispGGetWidth(m->display)); + pdr->y = pdr->y / (4096/gdispGGetHeight(m->display)); + break; + case GDISP_ROTATE_90: + case GDISP_ROTATE_270: + pdr->x = gdispGGetHeight(m->display) - pdr->x / (4096/gdispGGetHeight(m->display)); + pdr->y = pdr->y / (4096/gdispGGetWidth(m->display)); + break; + } + #else + pdr->x = gdispGGetWidth(m->display) - pdr->x / (4096/gdispGGetWidth(m->display)); + pdr->y = pdr->y / (4096/gdispGGetHeight(m->display)); + #endif + #endif + } + + release_bus(m); + return TRUE; +} + +const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ + { + GDRIVER_TYPE_TOUCH, + #if GMOUSE_FT6x06_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_FT6x06_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_FT6x06_PEN_CALIBRATE_ERROR, // calibrate + GMOUSE_FT6x06_PEN_CLICK_ERROR, // click + GMOUSE_FT6x06_PEN_MOVE_ERROR // move + }, + { // finger_jitter + GMOUSE_FT6x06_FINGER_CALIBRATE_ERROR, // calibrate + GMOUSE_FT6x06_FINGER_CLICK_ERROR, // click + GMOUSE_FT6x06_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/FT6x06/gmouse_lld_FT6x06_board_template.h b/drivers/ginput/touch/FT6x06/gmouse_lld_FT6x06_board_template.h new file mode 100644 index 00000000..7c0b6663 --- /dev/null +++ b/drivers/ginput/touch/FT6x06/gmouse_lld_FT6x06_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_FT6x06_PEN_CALIBRATE_ERROR 8 +#define GMOUSE_FT6x06_PEN_CLICK_ERROR 6 +#define GMOUSE_FT6x06_PEN_MOVE_ERROR 4 +#define GMOUSE_FT6x06_FINGER_CALIBRATE_ERROR 14 +#define GMOUSE_FT6x06_FINGER_CLICK_ERROR 18 +#define GMOUSE_FT6x06_FINGER_MOVE_ERROR 14 + +// How much extra data to allocate at the end of the GMouse structure for the board's use +#define GMOUSE_FT6x06_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_FT6x06_SELF_CALIBRATE FALSE + +static bool_t init_board(GMouse* m, unsigned driverinstance) { +} + +static GFXINLINE void aquire_bus(GMouse* m) { +} + +static GFXINLINE 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 */