aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ginput/touch/STMPE811/ginput_lld_mouse.c')
-rw-r--r--drivers/ginput/touch/STMPE811/ginput_lld_mouse.c69
1 files changed, 43 insertions, 26 deletions
diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c
index bdae310e..bfdc964b 100644
--- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c
+++ b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c
@@ -37,12 +37,19 @@
#include "ginput/lld/mouse.h"
+#if defined(GINPUT_MOUSE_USE_CUSTOM_BOARD) && GINPUT_MOUSE_USE_CUSTOM_BOARD
+ #include "ginput_lld_mouse_board.h"
+#elif defined(BOARD_EMBEST_DMSTF4BB)
#include "ginput_lld_mouse_board_embest_dmstf4bb.h"
+#else
+ #include "ginput_lld_mouse_board_example.h"
+#endif
static coord_t lastx, lasty, lastz;
/* 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) {
+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);
@@ -54,21 +61,22 @@ static void setActiveWindow(uint16_t bl_x, uint16_t bl_y, uint16_t tr_x, uint16_
*
* @notapi
*/
-void ginput_lld_mouse_init(void) {
+void ginput_lld_mouse_init(void)
+{
init_board();
write_reg(STMPE811_REG_SYS_CTRL1, 1, 0x02); // Software chip reset
- write_reg(STMPE811_REG_SYS_CTRL2, 1, 0x0C); // Temp. sensor clock off, GPIO clock off, touch clock on, ADC clock on
- write_reg(STMPE811_REG_INT_EN, 1, 0x03); // 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
+ 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
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
- // @TODO: decide which value should STMPE811_REG_TSC_CFG have - either 0x9A or from comment;)
- write_reg(STMPE811_REG_TSC_CFG, 1, 0x9A); // Averaging 4, Touch detect delay 1ms, Panel driver settling time 1ms
- write_reg(STMPE811_REG_FIFO_TH, 1, 0x01); // FIFO threshold =1
+ 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
@@ -92,11 +100,13 @@ void ginput_lld_mouse_init(void) {
*
* @notapi
*/
-void ginput_lld_mouse_get_reading(MouseReading *pt) {
+void ginput_lld_mouse_get_reading(MouseReading *pt)
+{
uint16_t buf;
+ uint8_t int_status;
- // if not touched, return the previous results
- if(!getpin_pressed()) {
+ // If not touched, return the previous results
+ if (!getpin_pressed()) {
pt->x = lastx;
pt->y = lasty;
pt->z = 0;
@@ -104,25 +114,32 @@ void ginput_lld_mouse_get_reading(MouseReading *pt) {
return;
}
- /* Get the X value */
- buf = read_reg(STMPE811_REG_TSC_DATA_X, 2);
- lastx = (coord_t)(buf);
+ // Find out what caused an interrupt
+ 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 Y value */
- buf = read_reg(STMPE811_REG_TSC_DATA_Y, 2);
- lasty = (coord_t)(buf);
+ /* Get the X value */
+ buf = read_reg(STMPE811_REG_TSC_DATA_X, 2);
+ lastx = (coord_t)(buf);
- /* Get the Z value */
- buf = read_reg(STMPE811_REG_TSC_DATA_Z, 1);
- lastz = (buf & 0x00FF);
+ /* Get the Y value */
+ buf = read_reg(STMPE811_REG_TSC_DATA_Y, 2);
+ lasty = (coord_t)(buf);
- // Return the results
- pt->x = lastx;
- pt->y = lasty;
- pt->z = 100;
- pt->buttons = GINPUT_TOUCH_PRESSED;
+ /* 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;
+ }
}
#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */
/** @} */
-