3131
3232#if SOC_TOUCH_SENSOR_SUPPORTED
3333
34- #if SOC_TOUCH_VERSION_1 // ESP32 only
34+ #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL (5 , 3 , 0 )
35+ #if SOC_TOUCH_VERSION_1
36+ #define SOC_TOUCH_SENSOR_VERSION (1)
37+ #elif SOC_TOUCH_VERSION_2
38+ #define SOC_TOUCH_SENSOR_VERSION (2)
39+ #endif
40+ #endif
41+
42+ #if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32 only
3543#include "driver/touch_pad.h"
36- #elif SOC_TOUCH_VERSION_2 // All other SoCs with touch, to date
44+ #elif SOC_TOUCH_SENSOR_VERSION == 2 // All other SoCs with touch, to date
3745#include "driver/touch_sensor.h"
3846#else
3947#error "Unknown touch hardware version"
@@ -98,13 +106,13 @@ static mp_obj_t mtp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
98106 touch_pad_set_fsm_mode (TOUCH_FSM_MODE_TIMER );
99107 initialized = 1 ;
100108 }
101- #if SOC_TOUCH_VERSION_1
109+ #if SOC_TOUCH_SENSOR_VERSION == 1
102110 esp_err_t err = touch_pad_config (self -> touchpad_id , 0 );
103- #elif SOC_TOUCH_VERSION_2
111+ #elif SOC_TOUCH_SENSOR_VERSION == 2
104112 esp_err_t err = touch_pad_config (self -> touchpad_id );
105113 #endif
106114 if (err == ESP_OK ) {
107- #if SOC_TOUCH_VERSION_2
115+ #if SOC_TOUCH_SENSOR_VERSION == 2
108116 touch_pad_fsm_start ();
109117 #endif
110118
@@ -115,10 +123,10 @@ static mp_obj_t mtp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
115123
116124static mp_obj_t mtp_config (mp_obj_t self_in , mp_obj_t value_in ) {
117125 mtp_obj_t * self = self_in ;
118- #if SOC_TOUCH_VERSION_1
126+ #if SOC_TOUCH_SENSOR_VERSION == 1
119127 uint16_t value = mp_obj_get_int (value_in );
120128 esp_err_t err = touch_pad_config (self -> touchpad_id , value );
121- #elif SOC_TOUCH_VERSION_2
129+ #elif SOC_TOUCH_SENSOR_VERSION == 2
122130 esp_err_t err = touch_pad_config (self -> touchpad_id );
123131 #endif
124132 if (err == ESP_OK ) {
@@ -130,10 +138,10 @@ MP_DEFINE_CONST_FUN_OBJ_2(mtp_config_obj, mtp_config);
130138
131139static mp_obj_t mtp_read (mp_obj_t self_in ) {
132140 mtp_obj_t * self = self_in ;
133- #if SOC_TOUCH_VERSION_1
141+ #if SOC_TOUCH_SENSOR_VERSION == 1
134142 uint16_t value ;
135143 esp_err_t err = touch_pad_read (self -> touchpad_id , & value );
136- #elif SOC_TOUCH_VERSION_2
144+ #elif SOC_TOUCH_SENSOR_VERSION == 2
137145 uint32_t value ;
138146 esp_err_t err = touch_pad_read_raw_data (self -> touchpad_id , & value );
139147 #endif
0 commit comments