diff --git a/drivers/ginput/touch/FT5x06/ft5x06.h b/drivers/ginput/touch/FT5x06/ft5x06.h new file mode 100644 index 00000000..e0d212ce --- /dev/null +++ b/drivers/ginput/touch/FT5x06/ft5x06.h @@ -0,0 +1,82 @@ +/* + * 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://chibios-gfx.com/license.html + */ + +/** + * @file drivers/ginput/touch/FT5x06/ft5x05.h + * @brief Register definition header for the STMPE811 touch controller. + * + * @addtogroup GINPUT + * @{ + */ + +#ifndef _FT5x06_H +#define _FT5x06_H + +// Slave address +#define FT5x06_ADDR (0x70 >> 1) + +// Maximum timeout +#define FT5x06_TIMEOUT 0x3000 + +#define FT5x06_DEVICE_MODE 0x00 +#define FT5x06_GESTURE_ID 0x01 +#define FT5x06_TOUCH_POINTS 0x02 + +#define FT5x06_TOUCH1_EV_FLAG 0x03 +#define FT5x06_TOUCH1_XH 0x03 +#define FT5x06_TOUCH1_XL 0x04 +#define FT5x06_TOUCH1_YH 0x05 +#define FT5x06_TOUCH1_YL 0x06 + +#define FT5x06_TOUCH2_EV_FLAG 0x09 +#define FT5x06_TOUCH2_XH 0x09 +#define FT5x06_TOUCH2_XL 0x0A +#define FT5x06_TOUCH2_YH 0x0B +#define FT5x06_TOUCH2_YL 0x0C + +#define FT5x06_TOUCH3_EV_FLAG 0x0F +#define FT5x06_TOUCH3_XH 0x0F +#define FT5x06_TOUCH3_XL 0x10 +#define FT5x06_TOUCH3_YH 0x11 +#define FT5x06_TOUCH3_YL 0x12 + +#define FT5x06_TOUCH4_EV_FLAG 0x15 +#define FT5x06_TOUCH4_XH 0x15 +#define FT5x06_TOUCH4_XL 0x16 +#define FT5x06_TOUCH4_YH 0x17 +#define FT5x06_TOUCH4_YL 0x18 + +#define FT5x06_TOUCH5_EV_FLAG 0x1B +#define FT5x06_TOUCH5_XH 0x1B +#define FT5x06_TOUCH5_XL 0x1C +#define FT5x06_TOUCH5_YH 0x1D +#define FT5x06_TOUCH5_YL 0x1E + +#define FT5x06_ID_G_THGROUP 0x80 +#define FT5x06_ID_G_THPEAK 0x81 +#define FT5x06_ID_G_THCAL 0x82 +#define FT5x06_ID_G_THWATER 0x83 +#define FT5x06_ID_G_THTEMP 0x84 +#define FT5x06_ID_G_THDIFF 0x85 +#define FT5x06_ID_G_CTRL 0x86 +#define FT5x06_ID_G_TIME_ENTER_MONITOR 0x87 +#define FT5x06_ID_G_PERIODACTIVE 0x88 +#define FT5x06_ID_G_PERIODMONITOR 0x89 +#define FT5x06_ID_G_AUTO_CLB_MODE 0xA0 +#define FT5x06_ID_G_LIB_VERSION_H 0xA1 +#define FT5x06_ID_G_LIB_VERSION_L 0xA2 +#define FT5x06_ID_G_CIPHER 0xA3 +#define FT5x06_ID_G_MODE 0xA4 +#define FT5x06_ID_G_PMODE 0xA5 +#define FT5x06_ID_G_FIRMID 0xA6 +#define FT5x06_ID_G_STATE 0xA7 +#define FT5x06_ID_G_FT5201ID 0xA8 +#define FT5x06_ID_G_ERR 0xA9 + +#endif /* _FT5x06_H */ +/** @} */ + diff --git a/drivers/ginput/touch/FT5x06/ginput_lld.mk b/drivers/ginput/touch/FT5x06/ginput_lld.mk new file mode 100644 index 00000000..17d38c61 --- /dev/null +++ b/drivers/ginput/touch/FT5x06/ginput_lld.mk @@ -0,0 +1,5 @@ +# List the required driver. +GFXSRC += $(GFXLIB)/drivers/ginput/touch/FT5x06/ginput_lld_mouse.c + +# Required include directories +GFXINC += $(GFXLIB)/drivers/ginput/touch/FT5x06 diff --git a/drivers/ginput/touch/FT5x06/ginput_lld_mouse.c b/drivers/ginput/touch/FT5x06/ginput_lld_mouse.c new file mode 100644 index 00000000..fd62e1e0 --- /dev/null +++ b/drivers/ginput/touch/FT5x06/ginput_lld_mouse.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://chibios-gfx.com/license.html + */ + +/** + * @file drivers/ginput/touch/STMPE811/ginput_lld_mouse.c + * @brief GINPUT Touch low level driver source for the STMPE811. + * + * @defgroup Mouse Mouse + * @ingroup GINPUT + * @{ + */ + +#include "ch.h" +#include "hal.h" +#include "gfx.h" + +#include "ft5x06.h" + +#if (GFX_USE_GINPUT && GINPUT_NEED_MOUSE) /*|| defined(__DOXYGEN__)*/ + +#include "ginput/lld/mouse.h" + +// include board abstraction +#include "ginput_lld_mouse_board.h" + +static coord_t x, y, z; +static uint8_t touched; + +/** + * @brief Initialise the mouse/touch. + * + * @notapi + */ +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); +} + +/** + * @brief Read the mouse/touch position. + * + * @param[in] pt A pointer to the structure to fill + * + * @note For drivers that don't support returning a position + * when the touch is up (most touch devices), it should + * return the previous position with the new Z value. + * The z value is the pressure for those touch devices + * that support it (-100 to 100 where > 0 is touched) + * or, 0 or 100 for those drivers that don't. + * + * @notapi + */ +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.h b/drivers/ginput/touch/FT5x06/ginput_lld_mouse_board.h new file mode 100644 index 00000000..b04c0024 --- /dev/null +++ b/drivers/ginput/touch/FT5x06/ginput_lld_mouse_board.h @@ -0,0 +1,111 @@ +/* + * 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://chibios-gfx.com/license.html + */ + +/** + * @file drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_.h + * @brief GINPUT Touch low level driver source for the FT5x06. + * + * @defgroup Mouse Mouse + * @ingroup GINPUT + * @{ + */ + +#ifndef _GINPUT_LLD_MOUSE_BOARD_H +#define _GINPUT_LLD_MOUSE_BOARD_H + +/* I2C interface #2 - Touchscreen controller */ +static const I2CConfig i2cfg2 = { + OPMODE_I2C, + 400000, + FAST_DUTY_CYCLE_2, +}; + +/** + * @brief Initialise the board for the touch. + * + * @notapi + */ +static void init_board(void) { + i2cStart(&I2CD2, %i2ccfg2); +} + + +/** + * @brief Write a value into a certain register + * + * @param[in] reg The register address + * @param[in] n The amount of bytes (one or two) + * @param[in] val The value + * + * @notapi + */ +static void write_reg(uint8_t reg, uint8_t n, uint16_t val) { + uint8_t txbuf[3]; + + i2cAcquireBus(&I2CD2); + + txbuf[0] = reg; + + if (n == 1) { + txbuf[1] = val; + i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, txbuf, 2, NULL, 0, MS2ST(FT5x06_TIMEOUT)); + } else if (n == 2) { + txbuf[1] = ((val & 0xFF00) >> 8); + txbuf[2] = (val & 0x00FF); + i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, txbuf, 3, NULL, 0, MS2ST(FT5x06_TIMEOUT)); + } + + i2cReleaseBus(&I2CD2); +} + +/** + * @brief Read the value of a certain register + * + * @param[in] reg The register address + * @param[in] n The amount of bytes (one or two) + * + * @return Data read from device (one byte or two depending on n param) + * + * @notapi + */ +static uint16_t read_reg(uint8_t reg, uint8_t n) { + uint8_t txbuf[1], rxbuf[2]; + uint16_t ret; + + rxbuf[0] = 0; + rxbuf[1] = 0; + + i2cAcquireBus(&I2CD2); + + txbuf[0] = reg; + i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, txbuf, 1, rxbuf, n, MS2ST(FT5x06_TIMEOUT)); + + if (n == 1) { + ret = rxbuf[0]; + } else if (n == 2) { + ret = ((rxbuf[0] << 8) | (rxbuf[1] & 0xFF)); + } + + i2cReleaseBus(&I2CD2); + + return ret; +} + +static void read_reg_n(uint8_t reg, uint8_t n, uint8_t *rxbuf) { + uint8_t txbuf[1]; + + i2cAcquireBus(&I2CD2); + + txbuf[0] = reg; + i2cMasterTransmitTimeout(&I2CD2, FT5x06_ADDR, txbuf, 1, rxbuf, n, MS2ST(FT5x06_TIMEOUT)); + + i2cReleaseBus(&I2CD2); +} + +#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ +/** @} */ + diff --git a/drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_example.h b/drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_example.h new file mode 100644 index 00000000..19e824e5 --- /dev/null +++ b/drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_example.h @@ -0,0 +1,72 @@ +/* + * 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://chibios-gfx.com/license.html + */ + +/** + * @file drivers/ginput/touch/FT5x06/ginput_lld_mouse_board_example.h + * @brief GINPUT Touch low level driver source for the FT5x06 on the example board. + * + * @defgroup Mouse Mouse + * @ingroup GINPUT + * @{ + */ + +#ifndef _GINPUT_LLD_MOUSE_BOARD_H +#define _GINPUT_LLD_MOUSE_BOARD_H + +/** + * @brief Initialise the board for the touch. + * + * @notapi + */ +static void init_board(void) { + /* Code here */ + #error "ginputFT5x06: You must supply a definition for init_board for your board" +} + +/** + * @brief Check whether an interrupt is raised + * @return TRUE if there is an interrupt signal present + * + * @notapi + */ +static inline bool_t getpin_irq(void) { + /* Code here */ + #error "ginputFT5x06: You must supply a definition for getpin_irq for your board" +} + +/** + * @brief Write a value into a certain register + * + * @param[in] reg The register address + * @param[in] n The amount of bytes (one or two) + * @param[in] val The value + * + * @notapi + */ +static void write_reg(uint8_t reg, uint8_t n, uint16_t val) { + /* Code here */ + #error "ginputFT5x06: You must supply a definition for write_reg for your board" +} + +/** + * @brief Read the value of a certain register + * + * @param[in] reg The register address + * @param[in] n The amount of bytes (one or two) + * + * @return Data read from device (one byte or two depending on n param) + * + * @notapi + */ +static uint16_t read_reg(uint8_t reg, uint8_t n) { + /* Code here */ + #error "ginputFT5x06: You must supply a definition for read_reg for your board" +} + +#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 new file mode 100644 index 00000000..c990e921 --- /dev/null +++ b/drivers/ginput/touch/FT5x06/ginput_lld_mouse_config.h @@ -0,0 +1,32 @@ +/* + * 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://chibios-gfx.com/license.html + */ + +/** + * @file drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h + * @brief GINPUT LLD header file for mouse/touch driver. + * + * @defgroup Mouse Mouse + * @ingroup GINPUT + * + * @{ + */ + +#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/readme.txt b/drivers/ginput/touch/FT5x06/readme.txt new file mode 100644 index 00000000..ec3ae757 --- /dev/null +++ b/drivers/ginput/touch/FT5x06/readme.txt @@ -0,0 +1,8 @@ +To use this driver: + +1. Add in your gfxconf.h: + a) #define GFX_USE_GINPUT TRUE + b) #define GINPUT_NEED_MOUSE TRUE + +2. To your makefile add the following lines: + include $(GFXLIB)/drivers/ginput/touch/FT5x06/ginput_lld.mk diff --git a/releases.txt b/releases.txt index 5878daf3..d071674b 100644 --- a/releases.txt +++ b/releases.txt @@ -36,6 +36,7 @@ FEATURE: Added enhanced notepad demo by user 'Abhishek' FEATURE: Added GOS module (including sub modules such as GQUEUE) FEATURE: Added some functionalities to the TDISP module by user 'Frysk' FEATURE: Added RA8875 GDISP driver +FEATURE: Added FT5x06 GINPUT/touch driver *** changes after 1.4 ***