File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed
ports/esp32s2/common-hal/touchio Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 25
25
*/
26
26
27
27
#include "shared-bindings/touchio/TouchIn.h"
28
- #include "py/runtime.h"
29
28
29
+ #include "py/runtime.h"
30
30
#include "driver/touch_pad.h"
31
31
32
+ bool touch_inited = false;
33
+
32
34
static uint16_t get_raw_reading (touchio_touchin_obj_t * self ) {
33
35
uint32_t touch_value ;
34
36
touch_pad_read_raw_data ((touch_pad_t )self -> pin -> touch_channel , & touch_value );
@@ -45,11 +47,14 @@ void common_hal_touchio_touchin_construct(touchio_touchin_obj_t* self,
45
47
}
46
48
claim_pin (pin );
47
49
48
- touch_pad_init ();
49
- touch_pad_config ((touch_pad_t )pin -> touch_channel );
50
+ if (!touch_inited ) {
51
+ touch_pad_init ();
52
+ touch_pad_set_fsm_mode (TOUCH_FSM_MODE_TIMER );
53
+ touch_pad_fsm_start ();
54
+ touch_inited = true;
55
+ }
50
56
51
- touch_pad_set_fsm_mode (TOUCH_FSM_MODE_TIMER );
52
- touch_pad_fsm_start ();
57
+ touch_pad_config ((touch_pad_t )pin -> touch_channel );
53
58
54
59
// wait for "raw data" to reset
55
60
mp_hal_delay_ms (10 );
@@ -79,8 +84,7 @@ void common_hal_touchio_touchin_deinit(touchio_touchin_obj_t* self) {
79
84
}
80
85
81
86
bool common_hal_touchio_touchin_get_value (touchio_touchin_obj_t * self ) {
82
- uint16_t reading = get_raw_reading (self );
83
- return reading > self -> threshold ;
87
+ return get_raw_reading (self ) > self -> threshold ;
84
88
}
85
89
86
90
uint16_t common_hal_touchio_touchin_get_raw_value (touchio_touchin_obj_t * self ) {
You can’t perform that action at this time.
0 commit comments