Merge pull request #49 from resset/master
STMPE811: attempt to use FIFO
This commit is contained in:
commit
49550c4999
4 changed files with 49 additions and 23 deletions
|
@ -69,19 +69,19 @@ void ginput_lld_mouse_init(void)
|
||||||
chThdSleepMilliseconds(10);
|
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_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_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, internaal voltage refernce
|
write_reg(STMPE811_REG_ADC_CTRL1, 1, 0x48); // ADC conversion time = 80 clock ticks, 12-bit ADC, internal voltage refernce
|
||||||
chThdSleepMilliseconds(2);
|
chThdSleepMilliseconds(2);
|
||||||
|
|
||||||
write_reg(STMPE811_REG_ADC_CTRL2, 1, 0x01); // ADC speed 3.25MHz
|
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_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_TH, 1, 0x01); // FIFO threshold = 1
|
||||||
write_reg(STMPE811_REG_FIFO_STA, 1, 0x01); // FIFO reset enable
|
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_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_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_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_STA, 1, 0xFF); // Clear all interrupts
|
||||||
write_reg(STMPE811_REG_INT_CTRL, 1, 0x01); // Level interrupt, enable intrrupts
|
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)
|
void ginput_lld_mouse_get_reading(MouseReading *pt)
|
||||||
{
|
{
|
||||||
uint16_t buf;
|
//uint16_t buf;
|
||||||
uint8_t int_status;
|
uint8_t int_status;
|
||||||
|
|
||||||
// If not touched, return the previous results
|
// 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);
|
int_status = read_reg(STMPE811_REG_INT_STA, 1);
|
||||||
|
|
||||||
// If it is TOUCH interrupt, clear it and go on
|
// If it is TOUCH interrupt, clear it and go on
|
||||||
if (int_status & 0x01) {
|
if (int_status & 0x02) {
|
||||||
write_reg(STMPE811_REG_INT_STA, 1, 0x01);
|
|
||||||
|
|
||||||
/* Get the X value */
|
uint8_t size = 0;
|
||||||
buf = read_reg(STMPE811_REG_TSC_DATA_X, 2);
|
size = read_reg(STMPE811_REG_FIFO_SIZE, 1);
|
||||||
lastx = (coord_t)(buf);
|
|
||||||
|
|
||||||
/* Get the Y value */
|
if (size) {
|
||||||
buf = read_reg(STMPE811_REG_TSC_DATA_Y, 2);
|
uint8_t buffer[size * 4];
|
||||||
lasty = (coord_t)(buf);
|
read_reg_n(STMPE811_REG_TSC_DATA_AI, size * 4, buffer);
|
||||||
|
|
||||||
/* Get the Z value */
|
lastx = (coord_t)((buffer[0] << 4) | (buffer[1] >> 4));
|
||||||
buf = read_reg(STMPE811_REG_TSC_DATA_Z, 1);
|
lasty = (coord_t)(((buffer[1] & 0x0F) << 8) | buffer[2]);
|
||||||
lastz = (buf & 0x00FF);
|
lastz = (coord_t)buffer[3];
|
||||||
|
|
||||||
// Return the results. ADC gives values from 0 to 2^12
|
/* Get the X value */
|
||||||
pt->x = lastx / 13;
|
//buf = read_reg(STMPE811_REG_TSC_DATA_X, 2);
|
||||||
pt->y = lasty / 17;
|
//lastx = (coord_t)(buf);
|
||||||
pt->z = 100;
|
|
||||||
pt->buttons = GINPUT_TOUCH_PRESSED;
|
/* 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,5 +123,17 @@ static uint16_t read_reg(uint8_t reg, uint8_t n)
|
||||||
return ret;
|
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 */
|
#endif /* _GINPUT_LLD_MOUSE_BOARD_H */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -31,10 +31,10 @@
|
||||||
#define _LLD_GINPUT_MOUSE_CONFIG_H
|
#define _LLD_GINPUT_MOUSE_CONFIG_H
|
||||||
|
|
||||||
#define GINPUT_MOUSE_EVENT_TYPE GEVENT_TOUCH
|
#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_LLD_CALIBRATION_LOADSAVE FALSE
|
||||||
#define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 5
|
#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_POLL_PERIOD 25
|
||||||
#define GINPUT_MOUSE_MAX_CLICK_JITTER 10
|
#define GINPUT_MOUSE_MAX_CLICK_JITTER 10
|
||||||
#define GINPUT_MOUSE_MAX_MOVE_JITTER 2
|
#define GINPUT_MOUSE_MAX_MOVE_JITTER 2
|
||||||
|
|
|
@ -92,6 +92,7 @@
|
||||||
#define STMPE811_REG_TSC_DATA_XYZ 0x52 // 32-bit
|
#define STMPE811_REG_TSC_DATA_XYZ 0x52 // 32-bit
|
||||||
#define STMPE811_REG_TSC_FRACT_XYZ 0x56
|
#define STMPE811_REG_TSC_FRACT_XYZ 0x56
|
||||||
#define STMPE811_REG_TSC_DATA 0x57
|
#define STMPE811_REG_TSC_DATA 0x57
|
||||||
|
#define STMPE811_REG_TSC_DATA_AI 0xD7
|
||||||
#define STMPE811_REG_TSC_I_DRIVE 0x58
|
#define STMPE811_REG_TSC_I_DRIVE 0x58
|
||||||
#define STMPE811_REG_TSC_SHIELD 0x59
|
#define STMPE811_REG_TSC_SHIELD 0x59
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue