Merge pull request #14531 from benpicco/drivers/stmpe811/fix_polarity
drivers/stmpe811: fix interrupt polarity & interrupt generation
This commit is contained in:
commit
09fe0c7667
@ -162,7 +162,7 @@ int stmpe811_init(stmpe811_t *dev, const stmpe811_params_t * params, touch_event
|
||||
|
||||
if ((dev->params.int_pin != GPIO_UNDEF) && cb) {
|
||||
DEBUG("[stmpe811] init: configuring touchscreen interrupt\n");
|
||||
gpio_init_int(dev->params.int_pin, GPIO_IN, GPIO_RISING, cb, arg);
|
||||
gpio_init_int(dev->params.int_pin, GPIO_IN, GPIO_FALLING, cb, arg);
|
||||
|
||||
/* Enable touchscreen interrupt */
|
||||
ret += i2c_write_reg(STMPE811_DEV_I2C, STMPE811_DEV_ADDR,
|
||||
@ -170,7 +170,7 @@ int stmpe811_init(stmpe811_t *dev, const stmpe811_params_t * params, touch_event
|
||||
|
||||
/* Enable global interrupt */
|
||||
ret += i2c_write_reg(STMPE811_DEV_I2C, STMPE811_DEV_ADDR,
|
||||
STMPE811_INT_CTRL, STMPE811_INT_CTRL_GLOBAL_INT, 0);
|
||||
STMPE811_INT_CTRL, STMPE811_INT_CTRL_GLOBAL_INT | STMPE811_INT_CTRL_INT_TYPE, 0);
|
||||
}
|
||||
|
||||
if (ret < 0) {
|
||||
@ -194,6 +194,13 @@ int stmpe811_read_touch_position(stmpe811_t *dev, stmpe811_touch_position_t *pos
|
||||
/* Acquire I2C device */
|
||||
i2c_acquire(STMPE811_DEV_I2C);
|
||||
|
||||
/* Ensure there's a least one position measured in the FIFO */
|
||||
uint8_t fifo_size = 0;
|
||||
do {
|
||||
i2c_read_reg(STMPE811_DEV_I2C, STMPE811_DEV_ADDR,
|
||||
STMPE811_FIFO_SIZE, &fifo_size, 0);
|
||||
} while (!fifo_size);
|
||||
|
||||
uint8_t xyz[4];
|
||||
uint32_t xyz_ul;
|
||||
|
||||
@ -203,7 +210,6 @@ int stmpe811_read_touch_position(stmpe811_t *dev, stmpe811_touch_position_t *pos
|
||||
i2c_release(STMPE811_DEV_I2C);
|
||||
return -STMPE811_ERR_I2C;
|
||||
}
|
||||
_reset_fifo(dev);
|
||||
|
||||
/* Release I2C device */
|
||||
i2c_release(STMPE811_DEV_I2C);
|
||||
@ -262,8 +268,9 @@ int stmpe811_read_touch_state(const stmpe811_t *dev, stmpe811_touch_state_t *sta
|
||||
return -STMPE811_ERR_I2C;
|
||||
}
|
||||
|
||||
_clear_interrupt_status(dev);
|
||||
|
||||
if ((val & STMPE811_TSC_CTRL_STA)) {
|
||||
_clear_interrupt_status(dev);
|
||||
*state = STMPE811_TOUCH_STATE_PRESSED;
|
||||
}
|
||||
else {
|
||||
|
||||
@ -2,7 +2,6 @@ BOARD ?= stm32f429i-disc1
|
||||
|
||||
include ../Makefile.tests_common
|
||||
|
||||
USEMODULE += xtimer
|
||||
USEMODULE += stmpe811
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
||||
@ -13,21 +13,17 @@ make -C tests/driver_stmpe811 flash term
|
||||
## Expected output
|
||||
|
||||
The application initializes the STMPE811 and displays "Pressed!" when a touch
|
||||
event is detected.
|
||||
Current touch positions are printed in terminal while holding the screen
|
||||
pressed.
|
||||
event is detected. The position of the touch event is also displayed.
|
||||
"Released" is displayed when the screen is released.
|
||||
|
||||
```
|
||||
2020-02-10 10:20:17,647 # Pressed!
|
||||
2020-02-10 10:20:17,653 # X: 167, Y:81
|
||||
2020-02-10 10:20:17,659 # X: 165, Y:75
|
||||
2020-02-10 10:20:17,671 # X: 165, Y:69
|
||||
2020-02-10 10:20:17,689 # X: 166, Y:68
|
||||
2020-02-10 10:20:17,701 # X: 167, Y:68
|
||||
2020-02-10 10:20:17,713 # X: 169, Y:69
|
||||
2020-02-10 10:20:17,725 # X: 170, Y:69
|
||||
2020-02-10 10:20:17,737 # X: 170, Y:70
|
||||
2020-02-10 10:20:17,755 # X: 173, Y:69
|
||||
2020-02-10 10:20:17,761 # Released!
|
||||
2020-07-21 21:24:49,286 # Pressed!
|
||||
2020-07-21 21:24:49,293 # X: 132, Y:138
|
||||
2020-07-21 21:24:49,826 # Released!
|
||||
2020-07-21 21:24:51,218 # Pressed!
|
||||
2020-07-21 21:24:51,219 # X: 42, Y:16
|
||||
2020-07-21 21:24:51,614 # Released!
|
||||
2020-07-21 21:24:53,385 # Pressed!
|
||||
2020-07-21 21:24:53,385 # X: 197, Y:64
|
||||
2020-07-21 21:24:53,588 # Released!
|
||||
```
|
||||
|
||||
@ -20,25 +20,25 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "xtimer.h"
|
||||
#include "mutex.h"
|
||||
|
||||
#include "stmpe811.h"
|
||||
#include "stmpe811_params.h"
|
||||
|
||||
static void _touch_event_cb(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
puts("Pressed!");
|
||||
mutex_unlock(arg);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
mutex_t lock = MUTEX_INIT_LOCKED;
|
||||
stmpe811_t dev;
|
||||
|
||||
puts("STMPE811 test application\n");
|
||||
|
||||
printf("+------------Initializing------------+\n");
|
||||
int ret = stmpe811_init(&dev, &stmpe811_params[0], _touch_event_cb, NULL);
|
||||
int ret = stmpe811_init(&dev, &stmpe811_params[0], _touch_event_cb, &lock);
|
||||
if (ret != STMPE811_OK) {
|
||||
puts("[Error] Initialization failed");
|
||||
return 1;
|
||||
@ -51,8 +51,16 @@ int main(void)
|
||||
stmpe811_touch_state_t last_touch_state = current_touch_state;
|
||||
|
||||
while (1) {
|
||||
|
||||
/* wait for touch event */
|
||||
mutex_lock(&lock);
|
||||
|
||||
stmpe811_read_touch_state(&dev, ¤t_touch_state);
|
||||
|
||||
if (current_touch_state != last_touch_state) {
|
||||
if (current_touch_state == STMPE811_TOUCH_STATE_PRESSED) {
|
||||
puts("Pressed!");
|
||||
}
|
||||
if (current_touch_state == STMPE811_TOUCH_STATE_RELEASED) {
|
||||
puts("Released!");
|
||||
}
|
||||
@ -65,8 +73,6 @@ int main(void)
|
||||
stmpe811_read_touch_position(&dev, &position);
|
||||
printf("X: %i, Y:%i\n", position.x, position.y);
|
||||
}
|
||||
|
||||
xtimer_usleep(10 * US_PER_MS);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user