File tree Expand file tree Collapse file tree 2 files changed +23
-8
lines changed Expand file tree Collapse file tree 2 files changed +23
-8
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
+
34
+ void touchin_reset (void ) {
35
+ if (touch_inited ) {
36
+ touch_pad_deinit ();
37
+ touch_inited = false;
38
+ }
39
+ }
40
+
32
41
static uint16_t get_raw_reading (touchio_touchin_obj_t * self ) {
33
42
uint32_t touch_value ;
34
43
touch_pad_read_raw_data ((touch_pad_t )self -> pin -> touch_channel , & touch_value );
@@ -45,11 +54,14 @@ void common_hal_touchio_touchin_construct(touchio_touchin_obj_t* self,
45
54
}
46
55
claim_pin (pin );
47
56
48
- touch_pad_init ();
49
- touch_pad_config ((touch_pad_t )pin -> touch_channel );
57
+ if (!touch_inited ) {
58
+ touch_pad_init ();
59
+ touch_pad_set_fsm_mode (TOUCH_FSM_MODE_TIMER );
60
+ touch_pad_fsm_start ();
61
+ touch_inited = true;
62
+ }
50
63
51
- touch_pad_set_fsm_mode (TOUCH_FSM_MODE_TIMER );
52
- touch_pad_fsm_start ();
64
+ touch_pad_config ((touch_pad_t )pin -> touch_channel );
53
65
54
66
// wait for "raw data" to reset
55
67
mp_hal_delay_ms (10 );
@@ -73,14 +85,12 @@ void common_hal_touchio_touchin_deinit(touchio_touchin_obj_t* self) {
73
85
if (common_hal_touchio_touchin_deinited (self )) {
74
86
return ;
75
87
}
76
- touch_pad_deinit ();
77
88
reset_pin_number (self -> pin -> touch_channel );
78
89
self -> pin = NULL ;
79
90
}
80
91
81
92
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 ;
93
+ return get_raw_reading (self ) > self -> threshold ;
84
94
}
85
95
86
96
uint16_t common_hal_touchio_touchin_get_raw_value (touchio_touchin_obj_t * self ) {
Original file line number Diff line number Diff line change 44
44
#include "common-hal/ps2io/Ps2.h"
45
45
#include "common-hal/pulseio/PulseIn.h"
46
46
#include "common-hal/pwmio/PWMOut.h"
47
+ #include "common-hal/touchio/TouchIn.h"
47
48
#include "common-hal/watchdog/WatchDogTimer.h"
48
49
#include "common-hal/wifi/__init__.h"
49
50
#include "supervisor/memory.h"
@@ -146,6 +147,10 @@ void reset_port(void) {
146
147
rtc_reset ();
147
148
#endif
148
149
150
+ #if CIRCUITPY_TOUCHIO_USE_NATIVE
151
+ touchin_reset ();
152
+ #endif
153
+
149
154
#if CIRCUITPY_WATCHDOG
150
155
watchdog_reset ();
151
156
#endif
You can’t perform that action at this time.
0 commit comments