File tree Expand file tree Collapse file tree
ports/esp32s2/common-hal/touchio Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525 */
2626
2727#include "shared-bindings/touchio/TouchIn.h"
28- #include "py/runtime.h"
2928
29+ #include "py/runtime.h"
3030#include "driver/touch_pad.h"
3131
32+ bool touch_inited = false;
33+
3234static uint16_t get_raw_reading (touchio_touchin_obj_t * self ) {
3335 uint32_t touch_value ;
3436 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,
4547 }
4648 claim_pin (pin );
4749
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+ }
5056
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 );
5358
5459 // wait for "raw data" to reset
5560 mp_hal_delay_ms (10 );
@@ -79,8 +84,7 @@ void common_hal_touchio_touchin_deinit(touchio_touchin_obj_t* self) {
7984}
8085
8186bool 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 ;
8488}
8589
8690uint16_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