29
29
#include "modmachine.h"
30
30
#include "driver/gpio.h"
31
31
32
- #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
32
+ #if SOC_TOUCH_SENSOR_SUPPORTED
33
33
34
- #if CONFIG_IDF_TARGET_ESP32
34
+ #if SOC_TOUCH_VERSION_1 // ESP32 only
35
35
#include "driver/touch_pad.h"
36
- #elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
36
+ #elif SOC_TOUCH_VERSION_2 // All other SoCs with touch, to date
37
37
#include "driver/touch_sensor.h"
38
+ #else
39
+ #error "Unknown touch hardware version"
38
40
#endif
39
41
40
42
typedef struct _mtp_obj_t {
@@ -70,6 +72,8 @@ static const mtp_obj_t touchpad_obj[] = {
70
72
{{& machine_touchpad_type }, GPIO_NUM_12 , TOUCH_PAD_NUM12 },
71
73
{{& machine_touchpad_type }, GPIO_NUM_13 , TOUCH_PAD_NUM13 },
72
74
{{& machine_touchpad_type }, GPIO_NUM_14 , TOUCH_PAD_NUM14 },
75
+ #else
76
+ #error "Please add GPIO mapping for this SoC"
73
77
#endif
74
78
};
75
79
@@ -92,14 +96,14 @@ static mp_obj_t mtp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
92
96
if (!initialized ) {
93
97
touch_pad_init ();
94
98
touch_pad_set_fsm_mode (TOUCH_FSM_MODE_TIMER );
95
- #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
99
+ #if TOUCH_HW_VER == 2
96
100
touch_pad_fsm_start ();
97
101
#endif
98
102
initialized = 1 ;
99
103
}
100
- #if CONFIG_IDF_TARGET_ESP32
104
+ #if SOC_TOUCH_VERSION_1
101
105
esp_err_t err = touch_pad_config (self -> touchpad_id , 0 );
102
- #elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
106
+ #elif SOC_TOUCH_VERSION_2
103
107
esp_err_t err = touch_pad_config (self -> touchpad_id );
104
108
#endif
105
109
if (err == ESP_OK ) {
@@ -110,10 +114,10 @@ static mp_obj_t mtp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
110
114
111
115
static mp_obj_t mtp_config (mp_obj_t self_in , mp_obj_t value_in ) {
112
116
mtp_obj_t * self = self_in ;
113
- #if CONFIG_IDF_TARGET_ESP32
117
+ #if SOC_TOUCH_VERSION_1
114
118
uint16_t value = mp_obj_get_int (value_in );
115
119
esp_err_t err = touch_pad_config (self -> touchpad_id , value );
116
- #elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
120
+ #elif SOC_TOUCH_VERSION_2
117
121
esp_err_t err = touch_pad_config (self -> touchpad_id );
118
122
#endif
119
123
if (err == ESP_OK ) {
@@ -125,10 +129,10 @@ MP_DEFINE_CONST_FUN_OBJ_2(mtp_config_obj, mtp_config);
125
129
126
130
static mp_obj_t mtp_read (mp_obj_t self_in ) {
127
131
mtp_obj_t * self = self_in ;
128
- #if CONFIG_IDF_TARGET_ESP32
132
+ #if SOC_TOUCH_VERSION_1
129
133
uint16_t value ;
130
134
esp_err_t err = touch_pad_read (self -> touchpad_id , & value );
131
- #elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
135
+ #elif SOC_TOUCH_VERSION_2
132
136
uint32_t value ;
133
137
esp_err_t err = touch_pad_read_raw_data (self -> touchpad_id , & value );
134
138
#endif
@@ -155,4 +159,4 @@ MP_DEFINE_CONST_OBJ_TYPE(
155
159
locals_dict , & mtp_locals_dict
156
160
);
157
161
158
- #endif
162
+ #endif // SOC_TOUCH_SENSOR_SUPPORTED
0 commit comments