30
30
#include "peripherals/touch.h"
31
31
#include "shared-bindings/microcontroller/Pin.h"
32
32
33
- static uint16_t get_raw_reading (touchio_touchin_obj_t * self ) {
34
- #if defined(CONFIG_IDF_TARGET_ESP32 )
35
- uint16_t touch_value ;
36
- #else
37
- uint32_t touch_value ;
38
- #endif ;
39
- touch_pad_read_raw_data (self -> pin -> touch_channel , & touch_value );
40
- if (touch_value > UINT16_MAX ) {
41
- return UINT16_MAX ;
42
- }
43
- return (uint16_t )touch_value ;
44
- }
45
-
46
33
void common_hal_touchio_touchin_construct (touchio_touchin_obj_t * self ,
47
34
const mcu_pin_obj_t * pin ) {
48
- if (pin -> touch_channel == TOUCH_PAD_MAX ) {
35
+ if (pin -> touch_channel == NO_TOUCH_CHANNEL ) {
49
36
raise_ValueError_invalid_pin ();
50
37
}
51
38
claim_pin (pin );
52
39
53
40
// initialize touchpad
54
41
peripherals_touch_init (pin -> touch_channel );
55
42
56
- // wait for touch data to reset
57
- mp_hal_delay_ms (10 );
58
-
59
43
// Set a "touched" threshold not too far above the initial value.
60
44
// For simple finger touch, the values may vary as much as a factor of two,
61
45
// but for touches using fruit or other objects, the difference is much less.
62
46
63
47
self -> pin = pin ;
64
- self -> threshold = get_raw_reading (self ) + 100 ;
48
+ self -> threshold = common_hal_touchio_touchin_get_raw_value (self ) + 100 ;
65
49
}
66
50
67
51
bool common_hal_touchio_touchin_deinited (touchio_touchin_obj_t * self ) {
@@ -77,11 +61,11 @@ void common_hal_touchio_touchin_deinit(touchio_touchin_obj_t *self) {
77
61
}
78
62
79
63
bool common_hal_touchio_touchin_get_value (touchio_touchin_obj_t * self ) {
80
- return get_raw_reading (self ) > self -> threshold ;
64
+ return common_hal_touchio_touchin_get_raw_value (self ) > self -> threshold ;
81
65
}
82
66
83
67
uint16_t common_hal_touchio_touchin_get_raw_value (touchio_touchin_obj_t * self ) {
84
- return get_raw_reading (self );
68
+ return peripherals_touch_read (self -> pin -> touch_channel );
85
69
}
86
70
87
71
uint16_t common_hal_touchio_touchin_get_threshold (touchio_touchin_obj_t * self ) {
0 commit comments