diff options
author | Mateusz Tomaszkiewicz <silentdemon@gmail.com> | 2013-03-29 01:15:07 +0100 |
---|---|---|
committer | Mateusz Tomaszkiewicz <silentdemon@gmail.com> | 2013-03-29 01:15:07 +0100 |
commit | 2f7b6fc80b89d4ccce19d919b8c2d4a793a3ce98 (patch) | |
tree | a57df0e589c9a8f57b4a7f1be19e10c39cb9a2c4 | |
parent | 2a00dd667df1fec0692d21ca2ef1001dbf9589ef (diff) | |
download | uGFX-2f7b6fc80b89d4ccce19d919b8c2d4a793a3ce98.tar.gz uGFX-2f7b6fc80b89d4ccce19d919b8c2d4a793a3ce98.tar.bz2 uGFX-2f7b6fc80b89d4ccce19d919b8c2d4a793a3ce98.zip |
STMPE811: attempt to use FIFO
Very early version of using FIFO threshold interrupt.
4 files changed, 53 insertions, 27 deletions
diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c index bfdc964b..4f648a78 100644 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c +++ b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c @@ -69,19 +69,19 @@ void ginput_lld_mouse_init(void) chThdSleepMilliseconds(10);
write_reg(STMPE811_REG_SYS_CTRL2, 1, 0x0C); // Temperature sensor clock off, GPIO clock off, touch clock on, ADC clock on
- write_reg(STMPE811_REG_INT_EN, 1, 0x01); // Interrupt on INT pin when FIFO is equal or above threshold value OR touch is detected
- write_reg(STMPE811_REG_ADC_CTRL1, 1, 0x48); // ADC conversion time = 80 clock ticks, 12-bit ADC, internaal voltage refernce
+ write_reg(STMPE811_REG_INT_EN, 1, 0x02); // Interrupt on INT pin when FIFO is equal or above threshold value OR touch is detected
+ write_reg(STMPE811_REG_ADC_CTRL1, 1, 0x48); // ADC conversion time = 80 clock ticks, 12-bit ADC, internal voltage refernce
chThdSleepMilliseconds(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_TSC_CFG, 1, 0x9A); // Averaging 4, touch detect delay 500 us, panel driver settling time 500 us
write_reg(STMPE811_REG_FIFO_TH, 1, 0x01); // FIFO threshold = 1
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, 0x03); // X&Y only, TSC enable
+ write_reg(STMPE811_REG_TSC_CTRL, 1, 0x01); // X&Y&Z, TSC enable
write_reg(STMPE811_REG_INT_STA, 1, 0xFF); // Clear all interrupts
write_reg(STMPE811_REG_INT_CTRL, 1, 0x01); // Level interrupt, enable intrrupts
}
@@ -102,7 +102,7 @@ void ginput_lld_mouse_init(void) */
void ginput_lld_mouse_get_reading(MouseReading *pt)
{
- uint16_t buf;
+ //uint16_t buf;
uint8_t int_status;
// If not touched, return the previous results
@@ -118,26 +118,39 @@ void ginput_lld_mouse_get_reading(MouseReading *pt) int_status = read_reg(STMPE811_REG_INT_STA, 1);
// If it is TOUCH interrupt, clear it and go on
- if (int_status & 0x01) {
- write_reg(STMPE811_REG_INT_STA, 1, 0x01);
-
- /* Get the X value */
- buf = read_reg(STMPE811_REG_TSC_DATA_X, 2);
- lastx = (coord_t)(buf);
-
- /* Get the Y value */
- buf = read_reg(STMPE811_REG_TSC_DATA_Y, 2);
- lasty = (coord_t)(buf);
-
- /* Get the Z value */
- buf = read_reg(STMPE811_REG_TSC_DATA_Z, 1);
- lastz = (buf & 0x00FF);
-
- // Return the results. ADC gives values from 0 to 2^12
- pt->x = lastx / 13;
- pt->y = lasty / 17;
- pt->z = 100;
- pt->buttons = GINPUT_TOUCH_PRESSED;
+ if (int_status & 0x02) {
+
+ uint8_t size = 0;
+ size = read_reg(STMPE811_REG_FIFO_SIZE, 1);
+
+ if (size) {
+ uint8_t buffer[size * 4];
+ read_reg_n(STMPE811_REG_TSC_DATA_AI, size * 4, buffer);
+
+ lastx = (coord_t)((buffer[0] << 4) | (buffer[1] >> 4));
+ lasty = (coord_t)(((buffer[1] & 0x0F) << 8) | buffer[2]);
+ lastz = (coord_t)buffer[3];
+
+ /* Get the X value */
+ //buf = read_reg(STMPE811_REG_TSC_DATA_X, 2);
+ //lastx = (coord_t)(buf);
+
+ /* Get the Y value */
+ //buf = read_reg(STMPE811_REG_TSC_DATA_Y, 2);
+ //lasty = (coord_t)(buf);
+
+ /* Get the Z value */
+ //buf = read_reg(STMPE811_REG_TSC_DATA_Z, 1);
+ //lastz = (buf & 0x00FF);
+
+ // Return the results. ADC gives values from 0 to 2^12
+ pt->x = 320 - lastx / 13;
+ pt->y = lasty / 17;
+ pt->z = lastz;
+ pt->buttons = GINPUT_TOUCH_PRESSED;
+ }
+
+ write_reg(STMPE811_REG_INT_STA, 1, 0x02);
}
}
diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_embest_dmstf4bb.h b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_embest_dmstf4bb.h index f14714f1..d7a360cd 100644 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_embest_dmstf4bb.h +++ b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_embest_dmstf4bb.h @@ -123,5 +123,17 @@ static uint16_t read_reg(uint8_t reg, uint8_t n) 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/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h index 398fd7fb..b99b6f14 100644 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h +++ b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h @@ -31,10 +31,10 @@ #define _LLD_GINPUT_MOUSE_CONFIG_H
#define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH
-#define GINPUT_MOUSE_NEED_CALIBRATION FALSE
+#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//4
+#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 2
diff --git a/drivers/ginput/touch/STMPE811/stmpe811.h b/drivers/ginput/touch/STMPE811/stmpe811.h index 401734a4..36101cd4 100644 --- a/drivers/ginput/touch/STMPE811/stmpe811.h +++ b/drivers/ginput/touch/STMPE811/stmpe811.h @@ -92,6 +92,7 @@ #define STMPE811_REG_TSC_DATA_XYZ 0x52 // 32-bit #define STMPE811_REG_TSC_FRACT_XYZ 0x56 #define STMPE811_REG_TSC_DATA 0x57 +#define STMPE811_REG_TSC_DATA_AI 0xD7 #define STMPE811_REG_TSC_I_DRIVE 0x58 #define STMPE811_REG_TSC_SHIELD 0x59 |