-
Notifications
You must be signed in to change notification settings - Fork 2.1k
drivers/ft5x06: fix initialization if callback function parameter is NULL #19880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
bors merge |
19880: drivers/ft5x06: fix initialization if callback function parameter is NULL r=benpicco a=gschorcht ### Contribution description This PR fixes the `ft5x06` driver initialization if the callback function parameter `cb` is `NULL. This might be the case for example if the application uses the touch device in polling mode. If the interrupt pin is initialized if the callback function parameter `cb` is `NULL`, the driver crashes the first time an interrupt is triggered. Therefore, the INT pin must be initialized only if also the callback function parameter `cb` is not `NULL`. To be able to test the polling mode, this PR also includes a change of the `tests/drivers/ft5x06` application which introduces the environment variables `FT5X06_POLLING_MODE` `FT5X06_POLLING_PERIOD` and in the makefile. ### Testing procedure 1. Use any board with a FTXXXX touch device and test it in polling mode, for example: ``` FT5X06_POLLING_MODE=1 BOARD=stm32f746g-disco make -C tests/drivers/ft5x06 flash term ``` It should work as expected. ``` main(): This is RIOT! (Version: 2023.10-devel-119-g92a44a-drivers/ft5x06_fix_cb_null) FT5x06 test application +------------Initializing------------+ Initialization successful 1 touch detected Touch 1 - X: 236, Y:111 Touch 1 - X: 236, Y:111 ... Touch 1 - X: 236, Y:111 Released! ``` 2. Checkout master branch and cerry-pick commit 691a5e6. The test application `tests/drivers/ft5x06` will crash once a touch event occur: ``` +------------Initializing------------+ Initialization successful 1 touch detected Context before hardfault: ``` ### Issues/PRs references Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
Build failed: |
This needs a rebase |
To be able to test the FT5x06 device driver in polling mode, variable `FT5X06_POLLING_MODE` is introduced. It is set to 0 by default and can be overriden by 1 to use the polling mode. The polling period can be controlled by the `FT5X06_POLLING_PERIOD` variable.
If the INT pin is initialized if the callback function parameter `cb` is `NULL`, the driver crashes the first time an interrupt is triggered. Therefore, the INT pin must be initialized only if also the callback function parameter `cb` is not `NULL`.
0b72051
to
7acf801
Compare
@benpicco I had to add a small change (commit 7acf801). The INT pin must not be initialized if It worked before without this change because the interrupt trigger mode is the default mode after reset. That is, we could also drop its configuration completely. |
Just tested this PR on stm32f723e-disco and I get a hard fault when enabling polling mode:
The interrupt mode still works though. |
If I revert 7acf801, polling mode works. |
I think the following diff makes more sense (instead of 7acf801): diff --git a/drivers/ft5x06/ft5x06.c b/drivers/ft5x06/ft5x06.c
index d455e8b1b8..e13ee7dc4d 100644
--- a/drivers/ft5x06/ft5x06.c
+++ b/drivers/ft5x06/ft5x06.c
@@ -83,9 +83,10 @@ int ft5x06_init(ft5x06_t *dev, const ft5x06_params_t *params, ft5x06_event_cb_t
if (gpio_is_valid(dev->params->int_pin) && cb) {
DEBUG("[ft5x06] init: configuring touchscreen interrupt\n");
gpio_init_int(dev->params->int_pin, GPIO_IN, GPIO_RISING, cb, arg);
- i2c_write_reg(FT5X06_BUS, FT5X06_ADDR, FT5X06_G_MODE_REG, FT5X06_G_MODE_INTERRUPT_TRIGGER & 0x01, 0);
}
+ i2c_write_reg(FT5X06_BUS, FT5X06_ADDR, FT5X06_G_MODE_REG, FT5X06_G_MODE_INTERRUPT_TRIGGER & 0x01, 0);
+
i2c_release(FT5X06_BUS);
return 0; (keep the |
The interrupt mode has to be configured independent on whether the INT pin is initialized already by the `ft5x06_init` function if parameter `cb` is defined or later, for example by the `touch_dev` implementation.
e15615c
to
bf720c0
Compare
🙈 This was exactly what I intended by the last change. I shouldn't have changed the source on my mobile. Of course I fixed it and squashed this small fix directly. |
bors merge |
19880: drivers/ft5x06: fix initialization if callback function parameter is NULL r=aabadie a=gschorcht ### Contribution description This PR fixes the `ft5x06` driver initialization if the callback function parameter `cb` is `NULL. This might be the case for example if the application uses the touch device in polling mode. If the interrupt pin is initialized if the callback function parameter `cb` is `NULL`, the driver crashes the first time an interrupt is triggered. Therefore, the INT pin must be initialized only if also the callback function parameter `cb` is not `NULL`. To be able to test the polling mode, this PR also includes a change of the `tests/drivers/ft5x06` application which introduces the environment variables `FT5X06_POLLING_MODE` `FT5X06_POLLING_PERIOD` and in the makefile. ### Testing procedure 1. Use any board with a FTXXXX touch device and test it in polling mode, for example: ``` FT5X06_POLLING_MODE=1 BOARD=stm32f746g-disco make -C tests/drivers/ft5x06 flash term ``` It should work as expected. ``` main(): This is RIOT! (Version: 2023.10-devel-119-g92a44a-drivers/ft5x06_fix_cb_null) FT5x06 test application +------------Initializing------------+ Initialization successful 1 touch detected Touch 1 - X: 236, Y:111 Touch 1 - X: 236, Y:111 ... Touch 1 - X: 236, Y:111 Released! ``` 2. Checkout master branch and cerry-pick commit 691a5e6. The test application `tests/drivers/ft5x06` will crash once a touch event occur: ``` +------------Initializing------------+ Initialization successful 1 touch detected Context before hardfault: ``` ### Issues/PRs references Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
Build failed: |
bors merge |
19880: drivers/ft5x06: fix initialization if callback function parameter is NULL r=aabadie a=gschorcht ### Contribution description This PR fixes the `ft5x06` driver initialization if the callback function parameter `cb` is `NULL. This might be the case for example if the application uses the touch device in polling mode. If the interrupt pin is initialized if the callback function parameter `cb` is `NULL`, the driver crashes the first time an interrupt is triggered. Therefore, the INT pin must be initialized only if also the callback function parameter `cb` is not `NULL`. To be able to test the polling mode, this PR also includes a change of the `tests/drivers/ft5x06` application which introduces the environment variables `FT5X06_POLLING_MODE` `FT5X06_POLLING_PERIOD` and in the makefile. ### Testing procedure 1. Use any board with a FTXXXX touch device and test it in polling mode, for example: ``` FT5X06_POLLING_MODE=1 BOARD=stm32f746g-disco make -C tests/drivers/ft5x06 flash term ``` It should work as expected. ``` main(): This is RIOT! (Version: 2023.10-devel-119-g92a44a-drivers/ft5x06_fix_cb_null) FT5x06 test application +------------Initializing------------+ Initialization successful 1 touch detected Touch 1 - X: 236, Y:111 Touch 1 - X: 236, Y:111 ... Touch 1 - X: 236, Y:111 Released! ``` 2. Checkout master branch and cerry-pick commit 691a5e6. The test application `tests/drivers/ft5x06` will crash once a touch event occur: ``` +------------Initializing------------+ Initialization successful 1 touch detected Context before hardfault: ``` ### Issues/PRs references Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
Build failed: |
bors merge ... |
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
Thanks for reviewing and merging 😄 |
19882: tests/drivers/touch_dev: allow to test a touch device in polling mode r=aabadie a=gschorcht ### Contribution description To be able to test the touch device in polling mode, variable `TOUCH_DEV_POLLING` is introduced. It is set to 0 by default and can be overriden by 1 to use the polling mode. The polling period can be controlled by the `TOUCH_DEV_POLLING_PERIOD` variable. To use it for `ft5x06` and `stmpe811` drivers, the polling mode has to be fixed for these touch device drivers (PR #19880 respective PR #19881). ### Testing procedure Use any board with touch device driver that uses the generic touch device API, for example (PR #19881 is required) ``` TOUCH_DEV_POLLING_MODE=1 TOUCH_DEV_POLLING_PERIOD=100 \ BOARD=stm32f429i-disc1 make -C tests/drivers/touch_dev flash term ``` or (PR #19880 is required) ``` TOUCH_DEV_POLLING_MODE=1 TOUCH_DEV_POLLING_PERIOD=100 \ BOARD=stm32f746g-disco make -C tests/drivers/touch_dev flash term ``` ### Issues/PRs references Depends partially on PR #19880 Depends partially on PR #19881 Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
Contribution description
This PR fixes the
ft5x06
driver initialization if the callback function parametercb
is `NULL. This might be the case for example if the application uses the touch device in polling mode.If the interrupt pin is initialized if the callback function parameter
cb
isNULL
, the driver crashes the first time an interrupt is triggered. Therefore, the INT pin must be initialized only if also the callback function parametercb
is notNULL
.To be able to test the polling mode, this PR also includes a change of the
tests/drivers/ft5x06
application which introduces the environment variablesFT5X06_POLLING_MODE
FT5X06_POLLING_PERIOD
and in the makefile.Testing procedure
Use any board with a FTXXXX touch device and test it in polling mode, for example:
It should work as expected.
Checkout master branch and cerry-pick commit 691a5e6. The test application
tests/drivers/ft5x06
will crash once a touch event occur:Issues/PRs references