diff --git a/boards/base/Embest-STM32-DMSTF4BB/ginput_lld_mouse_board.h b/boards/base/Embest-STM32-DMSTF4BB/ginput_lld_mouse_board.h deleted file mode 100644 index d525e268..00000000 --- a/boards/base/Embest-STM32-DMSTF4BB/ginput_lld_mouse_board.h +++ /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 - */ - -#ifndef _GINPUT_LLD_MOUSE_BOARD_H -#define _GINPUT_LLD_MOUSE_BOARD_H - -static const I2CConfig i2ccfg = { - OPMODE_I2C, - 400000, - FAST_DUTY_CYCLE_2, -}; - -static void init_board(void) -{ - palSetPadMode(GPIOC, 13, PAL_MODE_INPUT | PAL_STM32_PUDR_FLOATING); /* TP IRQ */ - palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SCL */ - palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SDA */ - - i2cStart(&I2CD1, &i2ccfg); -} - -static inline bool_t getpin_irq(void) -{ - return (!(palReadPad(GPIOC, 13))); -} - -static void write_reg(uint8_t reg, uint8_t n, uint16_t val) -{ - uint8_t txbuf[3]; - - i2cAcquireBus(&I2CD1); - - txbuf[0] = reg; - - if (n == 1) { - txbuf[1] = val; - i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 2, 0, 0, MS2ST(STMPE811_TIMEOUT)); - } else if (n == 2) { - txbuf[1] = ((val & 0xFF00) >> 8); - txbuf[2] = (val & 0x00FF); - i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 3, 0, 0, MS2ST(STMPE811_TIMEOUT)); - } - - i2cReleaseBus(&I2CD1); -} - -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(&I2CD1); - - txbuf[0] = reg; - i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 1, rxbuf, n, MS2ST(STMPE811_TIMEOUT)); - - if (n == 1) { - ret = rxbuf[0]; - } else if (n == 2) { - ret = ((rxbuf[0] << 8) | (rxbuf[1] & 0xFF)); - } - - i2cReleaseBus(&I2CD1); - - return ret; -} - -static void read_reg_n(uint8_t reg, uint8_t n, uint8_t *rxbuf) -{ - uint8_t txbuf[1]; - - i2cAcquireBus(&I2CD1); - - txbuf[0] = reg; - i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 1, rxbuf, n, MS2ST(STMPE811_TIMEOUT)); - - i2cReleaseBus(&I2CD1); -} - -#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ - diff --git a/boards/base/Embest-STM32-DMSTF4BB/ginput_lld_mouse_config.h b/boards/base/Embest-STM32-DMSTF4BB/ginput_lld_mouse_config.h deleted file mode 100644 index f3a89208..00000000 --- a/boards/base/Embest-STM32-DMSTF4BB/ginput_lld_mouse_config.h +++ /dev/null @@ -1,22 +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 12 -#define GINPUT_MOUSE_READ_CYCLES 4 -#define GINPUT_MOUSE_POLL_PERIOD 3 -#define GINPUT_MOUSE_MAX_CLICK_JITTER 2 -#define GINPUT_MOUSE_MAX_MOVE_JITTER 2 -#define GINPUT_MOUSE_CLICK_TIME 500 - -#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */ - diff --git a/boards/base/Embest-STM32-DMSTF4BB/gmouse_lld_STMPE811_board.h b/boards/base/Embest-STM32-DMSTF4BB/gmouse_lld_STMPE811_board.h new file mode 100644 index 00000000..ebbe0d5b --- /dev/null +++ b/boards/base/Embest-STM32-DMSTF4BB/gmouse_lld_STMPE811_board.h @@ -0,0 +1,112 @@ +/* + * 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_STMPE811_PEN_CALIBRATE_ERROR 8 +#define GMOUSE_STMPE811_PEN_CLICK_ERROR 6 +#define GMOUSE_STMPE811_PEN_MOVE_ERROR 4 +#define GMOUSE_STMPE811_FINGER_CALIBRATE_ERROR 14 +#define GMOUSE_STMPE811_FINGER_CLICK_ERROR 18 +#define GMOUSE_STMPE811_FINGER_MOVE_ERROR 14 + +// How much extra data to allocate at the end of the GMouse structure for the board's use +#define GMOUSE_STMPE811_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_STMPE811_SELF_CALIBRATE FALSE + +// If TRUE this board has the STMPE811 IRQ pin connected to a GPIO. +#define GMOUSE_STMPE811_GPIO_IRQPIN TRUE + +// If TRUE this is a really slow CPU and we should always clear the FIFO between reads. +#define GMOUSE_STMPE811_SLOW_CPU FALSE + +static const I2CConfig i2ccfg = { + OPMODE_I2C, + 400000, + FAST_DUTY_CYCLE_2, +}; + +static bool_t init_board(GMouse* m, unsigned driverinstance) { + (void) m; + + // This board only supports one touch panel + if (driverInstance) + return FALSE; + + palSetPadMode(GPIOC, 13, PAL_MODE_INPUT | PAL_STM32_PUDR_FLOATING); /* TP IRQ */ + palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SCL */ + palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN); /* SDA */ + + i2cStart(&I2CD1, &i2ccfg); + return TRUE; +} + +#if GMOUSE_STMPE811_GPIO_IRQPIN + static bool_t getpin_irq(GMouse* m) { + (void) m; + + return !palReadPad(GPIOC, 13); + } +#endif + +static inline void aquire_bus(GMouse* m) { + (void) m; + +} + +static inline void release_bus(GMouse* m) { + (void) m; + +} + +static void write_reg(GMouse* m, uint8_t reg, uint8_t val) { + uint8_t txbuf[2]; + (void) m; + + txbuf[0] = reg; + txbuf[1] = val; + + i2cAcquireBus(&I2CD1); + i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 2, 0, 0, MS2ST(STMPE811_TIMEOUT)); + i2cReleaseBus(&I2CD1); +} + +static uint8_t read_byte(GMouse* m, uint8_t reg) { + uint8_t rxbuf[1]; + (void) m; + + rxbuf[0] = 0; + + i2cAcquireBus(&I2CD1); + i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, ®, 1, rxbuf, 1, MS2ST(STMPE811_TIMEOUT)); + i2cReleaseBus(&I2CD1); + + return rxbuf[0]; +} + +static uint16_t read_word(GMouse* m, uint8_t reg) { + uint8_t rxbuf[2]; + (void) m; + + rxbuf[0] = 0; + rxbuf[1] = 0; + + i2cAcquireBus(&I2CD1); + i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, ®, 1, rxbuf, 2, MS2ST(STMPE811_TIMEOUT)); + i2cReleaseBus(&I2CD1); + + return (((uint16_t)rxbuf[0]) << 8) | rxbuf[1]; +} + +#endif /* _GINPUT_LLD_MOUSE_BOARD_H */ diff --git a/drivers/ginput/touch/STMPE811/driver.mk b/drivers/ginput/touch/STMPE811/driver.mk index 5147e989..cf12507b 100644 --- a/drivers/ginput/touch/STMPE811/driver.mk +++ b/drivers/ginput/touch/STMPE811/driver.mk @@ -1,5 +1,2 @@ # List the required driver. -GFXSRC += $(GFXLIB)/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c - -# Required include directories -GFXINC += $(GFXLIB)/drivers/ginput/touch/STMPE811 +GFXSRC += $(GFXLIB)/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c deleted file mode 100644 index e658fae2..00000000 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c +++ /dev/null @@ -1,132 +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/STMPE811/stmpe811.h" - -#include "ginput_lld_mouse_board.h" - -#ifndef STMP811_NO_GPIO_IRQPIN - #define STMP811_NO_GPIO_IRQPIN FALSE -#endif -#ifndef STMP811_SLOW_CPU - #define STMP811_SLOW_CPU FALSE -#endif - -static coord_t x, y, z; -static uint8_t touched; - -/* set the active window of the stmpe811. bl is bottom left, tr is top right */ -static void setActiveWindow(uint16_t bl_x, uint16_t bl_y, uint16_t tr_x, uint16_t tr_y) -{ - write_reg(STMPE811_REG_WDW_TR_X, 2, tr_x); - write_reg(STMPE811_REG_WDW_TR_Y, 2, tr_y); - write_reg(STMPE811_REG_WDW_BL_X, 2, bl_x); - write_reg(STMPE811_REG_WDW_BL_Y, 2, bl_y); -} - -void ginput_lld_mouse_init(void) -{ - init_board(); - - write_reg(STMPE811_REG_SYS_CTRL1, 1, 0x02); // Software chip reset - gfxSleepMilliseconds(10); - - write_reg(STMPE811_REG_SYS_CTRL2, 1, 0x0C); // Temperature sensor clock off, GPIO clock off, touch clock on, ADC clock on -#if STMP811_NO_GPIO_IRQPIN - write_reg(STMPE811_REG_INT_EN, 1, 0x00); // Interrupt on INT pin when touch is detected -#else - write_reg(STMPE811_REG_INT_EN, 1, 0x01); // Interrupt on INT pin when touch is detected -#endif - write_reg(STMPE811_REG_ADC_CTRL1, 1, 0x48); // ADC conversion time = 80 clock ticks, 12-bit ADC, internal voltage refernce - gfxSleepMilliseconds(2); - - write_reg(STMPE811_REG_ADC_CTRL2, 1, 0x01); // ADC speed 3.25MHz - write_reg(STMPE811_REG_GPIO_AF, 1, 0x00); // GPIO alternate function - OFF - write_reg(STMPE811_REG_TSC_CFG, 1, 0x9A); // Averaging 4, touch detect delay 500 us, panel driver settling time 500 us - write_reg(STMPE811_REG_FIFO_TH, 1, 0x40); // FIFO threshold = 64 - write_reg(STMPE811_REG_FIFO_STA, 1, 0x01); // FIFO reset enable - write_reg(STMPE811_REG_FIFO_STA, 1, 0x00); // FIFO reset disable - write_reg(STMPE811_REG_TSC_FRACT_XYZ, 1, 0x07); // Z axis data format - write_reg(STMPE811_REG_TSC_I_DRIVE, 1, 0x01); // 50mA touchscreen line current - write_reg(STMPE811_REG_TSC_CTRL, 1, 0x00); // X&Y&Z - write_reg(STMPE811_REG_TSC_CTRL, 1, 0x01); // X&Y&Z, TSC enable - write_reg(STMPE811_REG_INT_STA, 1, 0xFF); // Clear all interrupts -#if !STMP811_NO_GPIO_IRQPIN - touched = (uint8_t)read_reg(STMPE811_REG_TSC_CTRL, 1) & 0x80; -#endif - write_reg(STMPE811_REG_INT_CTRL, 1, 0x01); // Level interrupt, enable intrrupts -} - -void ginput_lld_mouse_get_reading(MouseReading *pt) -{ - bool_t clearfifo; // Do we need to clear the FIFO - -#if STMP811_NO_GPIO_IRQPIN - // Poll to get the touched status - uint8_t last_touched; - - last_touched = touched; - touched = (uint8_t)read_reg(STMPE811_REG_TSC_CTRL, 1) & 0x80; - clearfifo = (touched != last_touched); -#else - // Check if the touch controller IRQ pin has gone off - clearfifo = false; - if(getpin_irq()) { // please rename this to getpin_irq - write_reg(STMPE811_REG_INT_STA, 1, 0xFF); // clear all interrupts - touched = (uint8_t)read_reg(STMPE811_REG_TSC_CTRL, 1) & 0x80; // set the new touched status - clearfifo = true; // only take the last FIFO reading - } -#endif - - // If not touched, return the previous results - if (!touched) { - pt->x = x; - pt->y = y; - pt->z = 0; - pt->buttons = 0; - return; - } - -#if !STMP811_SLOW_CPU - if (!clearfifo && (read_reg(STMPE811_REG_FIFO_STA, 1) & 0xD0)) -#endif - clearfifo = true; - - do { - /* Get the X, Y, Z values */ - /* This could be done in a single 4 byte read to STMPE811_REG_TSC_DATA_XYZ (incr or non-incr) */ - x = (coord_t)read_reg(STMPE811_REG_TSC_DATA_X, 2); - y = (coord_t)read_reg(STMPE811_REG_TSC_DATA_Y, 2); - z = (coord_t)read_reg(STMPE811_REG_TSC_DATA_Z, 1); - } while(clearfifo && !(read_reg(STMPE811_REG_FIFO_STA, 1) & 0x20)); - - // 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 - z = (((z&0xFF) * 100)>>8) + 1; - - // 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; - - /* Force another read if we have more results */ - if (!clearfifo && !(read_reg(STMPE811_REG_FIFO_STA, 1) & 0x20)) - ginputMouseWakeup(); - -} - -#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */ diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_template.h b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_template.h deleted file mode 100644 index b7744a49..00000000 --- a/drivers/ginput/touch/STMPE811/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/STMPE811/ginput_lld_mouse_config.h b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h deleted file mode 100644 index 5cd512eb..00000000 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h +++ /dev/null @@ -1,25 +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 5 -#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 - -/* default values - over write these in your boad files */ -#define STMP811_SLOWER_RESPONSE FALSE -#define STMP811_NO_GPIO_IRQPIN FALSE - -#endif /* _LLD_GINPUT_MOUSE_CONFIG_H */ diff --git a/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c new file mode 100644 index 00000000..396e9eb0 --- /dev/null +++ b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811.c @@ -0,0 +1,164 @@ +/* + * 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_STMPE811 +#include "src/ginput/driver_mouse.h" + +#define GMOUSE_STMPE811_FLG_TOUCHED (GMOUSE_FLG_DRIVER_FIRST<<0) + +// Get the hardware interface +#include "gmouse_lld_STMPE811_board.h" + +// Hardware definitions +#include "drivers/ginput/touch/STMPE811/stmpe811.h" + +static bool_t MouseInit(GMouse* m, unsigned driverinstance) { + if (!init_board(m, driverinstance)) + return FALSE; + + aquire_bus(m); + + write_reg(m, STMPE811_REG_SYS_CTRL1, 0x02); // Software chip reset + gfxSleepMilliseconds(10); + + write_reg(m, STMPE811_REG_SYS_CTRL2, 0x0C); // Temperature sensor clock off, GPIO clock off, touch clock on, ADC clock on + + #if GMOUSE_STMPE811_GPIO_IRQPIN + write_reg(m, STMPE811_REG_INT_EN, 0x01); // Interrupt on INT pin when touch is detected + #else + write_reg(m, STMPE811_REG_INT_EN, 0x00); // Don't Interrupt on INT pin when touch is detected + #endif + + write_reg(m, STMPE811_REG_ADC_CTRL1, 0x48); // ADC conversion time = 80 clock ticks, 12-bit ADC, internal voltage refernce + gfxSleepMilliseconds(2); + + write_reg(m, STMPE811_REG_ADC_CTRL2, 0x01); // ADC speed 3.25MHz + write_reg(m, STMPE811_REG_GPIO_AF, 0x00); // GPIO alternate function - OFF + write_reg(m, STMPE811_REG_TSC_CFG, 0x9A); // Averaging 4, touch detect delay 500 us, panel driver settling time 500 us + write_reg(m, STMPE811_REG_FIFO_TH, 0x40); // FIFO threshold = 64 + write_reg(m, STMPE811_REG_FIFO_STA, 0x01); // FIFO reset enable + write_reg(m, STMPE811_REG_FIFO_STA, 0x00); // FIFO reset disable + write_reg(m, STMPE811_REG_TSC_FRACT_XYZ, 0x07); // Z axis data format + write_reg(m, STMPE811_REG_TSC_I_DRIVE, 0x01); // 50mA touchscreen line current + write_reg(m, STMPE811_REG_TSC_CTRL, 0x00); // X&Y&Z + write_reg(m, STMPE811_REG_TSC_CTRL, 0x01); // X&Y&Z, TSC enable + write_reg(m, STMPE811_REG_INT_STA, 0xFF); // Clear all interrupts + #if GMOUSE_STMPE811_GPIO_IRQPIN + if (read_byte(m, STMPE811_REG_TSC_CTRL) & 0x80) + m->flags |= GMOUSE_STMPE811_FLG_TOUCHED; + #endif + write_reg(m, STMPE811_REG_INT_CTRL, 0x01); // Level interrupt, enable interrupts + + release_bus(m); + return TRUE; +} + +static void MouseXYZ(GMouse* m, GMouseReading* pdr) +{ + bool_t clearfifo; // Do we need to clear the FIFO + + // Assume not touched. + pdr->buttons = 0; + pdr->z = 0; + + aquire_bus(m); + + #if GMOUSE_STMPE811_GPIO_IRQPIN + // Check if the touch controller IRQ pin has gone off + clearfifo = false; + if(getpin_irq(m)) { + write_reg(m, STMPE811_REG_INT_STA, 0xFF); // clear all interrupts + if (read_byte(STMPE811_REG_TSC_CTRL) & 0x80) // set the new touched status + m->flags |= GMOUSE_STMPE811_FLG_TOUCHED; + else + m->flags &= ~GMOUSE_STMPE811_FLG_TOUCHED; + clearfifo = TRUE; // only take the last FIFO reading + } + + #else + // Poll to get the touched status + uint16_t last_touched; + + last_touched = m->flags; + if (read_byte(m, STMPE811_REG_TSC_CTRL) & 0x80) // set the new touched status + m->flags |= GMOUSE_STMPE811_FLG_TOUCHED; + else + m->flags &= ~GMOUSE_STMPE811_FLG_TOUCHED; + clearfifo = ((m->flags ^ last_touched) & GMOUSE_STMPE811_FLG_TOUCHED) ? TRUE : FALSE; + #endif + + // If not touched don't do any more + if ((m->flags &= ~GMOUSE_STMPE811_FLG_TOUCHED)) { + + // Clear the fifo if it is too full + #if !GMOUSE_STMPE811_SLOW_CPU + if (!clearfifo && (read_byte(m, STMPE811_REG_FIFO_STA) & 0xD0)) + #endif + clearfifo = true; + + do { + /* Get the X, Y, Z values */ + /* This could be done in a single 4 byte read to STMPE811_REG_TSC_DATA_XYZ (incr or non-incr) */ + pdr->x = (coord_t)read_word(m, STMPE811_REG_TSC_DATA_X); + pdr->y = (coord_t)read_word(m, STMPE811_REG_TSC_DATA_Y); + pdr->z = (coord_t)read_byte(m, STMPE811_REG_TSC_DATA_Z); + } while(clearfifo && !(read_byte(m, STMPE811_REG_FIFO_STA) & 0x20)); + + #if GMOUSE_STMPE811_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 + + /* Force another read if we have more results */ + if (!clearfifo && !(read_byte(m, STMPE811_REG_FIFO_STA) & 0x20)) + _gmouseWakeup(m); + } + + release_bus(m); +} + +const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{ + { + GDRIVER_TYPE_TOUCH, + #if GMOUSE_STMPE811_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_STMPE811_BOARD_DATA_SIZE, + _gmouseInitDriver, + _gmousePostInitDriver, + _gmouseDeInitDriver + }, + 255, // z_max + 0, // z_min + 200, // z_touchon + 20, // z_touchoff + { // pen_jitter + GMOUSE_STMPE811_PEN_CALIBRATE_ERROR, // calibrate + GMOUSE_STMPE811_PEN_CLICK_ERROR, // click + GMOUSE_STMPE811_PEN_MOVE_ERROR // move + }, + { // finger_jitter + GMOUSE_STMPE811_FINGER_CALIBRATE_ERROR, // calibrate + GMOUSE_STMPE811_FINGER_CLICK_ERROR, // click + GMOUSE_STMPE811_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/STMPE811/gmouse_lld_STMPE811_board_template.h b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811_board_template.h new file mode 100644 index 00000000..437abc09 --- /dev/null +++ b/drivers/ginput/touch/STMPE811/gmouse_lld_STMPE811_board_template.h @@ -0,0 +1,58 @@ +/* + * 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_STMPE811_PEN_CALIBRATE_ERROR 8 +#define GMOUSE_STMPE811_PEN_CLICK_ERROR 6 +#define GMOUSE_STMPE811_PEN_MOVE_ERROR 4 +#define GMOUSE_STMPE811_FINGER_CALIBRATE_ERROR 14 +#define GMOUSE_STMPE811_FINGER_CLICK_ERROR 18 +#define GMOUSE_STMPE811_FINGER_MOVE_ERROR 14 + +// How much extra data to allocate at the end of the GMouse structure for the board's use +#define GMOUSE_STMPE811_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_STMPE811_SELF_CALIBRATE FALSE + +// If TRUE this board has the STMPE811 IRQ pin connected to a GPIO. +#define GMOUSE_STMPE811_GPIO_IRQPIN FALSE + +// If TRUE this is a really slow CPU and we should always clear the FIFO between reads. +#define GMOUSE_STMPE811_SLOW_CPU FALSE + +static bool_t init_board(GMouse* m, unsigned driverinstance) { +} + +#if GMOUSE_STMPE811_GPIO_IRQPIN + static bool_t getpin_irq(GMouse* m) { + + } +#endif + +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 */