11 namespace esp32_touch {
13 static const char *
const TAG =
"esp32_touch";
16 ESP_LOGCONFIG(TAG,
"Setting up ESP32 Touch Hub...");
19 #if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) 21 touch_filter_config_t filter_info = {
28 touch_pad_filter_set_config(&filter_info);
29 touch_pad_filter_enable();
33 touch_pad_denoise_t denoise = {
37 touch_pad_denoise_set_config(&denoise);
38 touch_pad_denoise_enable();
42 touch_pad_waterproof_t waterproof = {
46 touch_pad_waterproof_set_config(&waterproof);
47 touch_pad_waterproof_enable();
55 #if ESP_IDF_VERSION_MAJOR >= 5 56 touch_pad_set_measurement_clock_cycles(this->
meas_cycle_);
64 #if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) 65 touch_pad_config(child->get_touch_pad());
68 touch_pad_config(child->get_touch_pad(), 0);
71 #if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) 72 touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER);
73 touch_pad_fsm_start();
78 ESP_LOGCONFIG(TAG,
"Config for ESP32 Touch Hub:");
79 ESP_LOGCONFIG(TAG,
" Meas cycle: %.2fms", this->
meas_cycle_ / (8000000.0f / 1000.0f));
80 ESP_LOGCONFIG(TAG,
" Sleep cycle: %.2fms", this->
sleep_cycle_ / (150000.0f / 1000.0f));
100 ESP_LOGCONFIG(TAG,
" Low Voltage Reference: %s", lv_s);
104 case TOUCH_HVOLT_2V4:
107 case TOUCH_HVOLT_2V5:
110 case TOUCH_HVOLT_2V6:
113 case TOUCH_HVOLT_2V7:
120 ESP_LOGCONFIG(TAG,
" High Voltage Reference: %s", hv_s);
124 case TOUCH_HVOLT_ATTEN_1V5:
127 case TOUCH_HVOLT_ATTEN_1V:
130 case TOUCH_HVOLT_ATTEN_0V5:
133 case TOUCH_HVOLT_ATTEN_0V:
140 ESP_LOGCONFIG(TAG,
" Voltage Attenuation: %s", atten_s);
142 #if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) 144 const char *filter_mode_s;
146 case TOUCH_PAD_FILTER_IIR_4:
147 filter_mode_s =
"IIR_4";
149 case TOUCH_PAD_FILTER_IIR_8:
150 filter_mode_s =
"IIR_8";
152 case TOUCH_PAD_FILTER_IIR_16:
153 filter_mode_s =
"IIR_16";
155 case TOUCH_PAD_FILTER_IIR_32:
156 filter_mode_s =
"IIR_32";
158 case TOUCH_PAD_FILTER_IIR_64:
159 filter_mode_s =
"IIR_64";
161 case TOUCH_PAD_FILTER_IIR_128:
162 filter_mode_s =
"IIR_128";
164 case TOUCH_PAD_FILTER_IIR_256:
165 filter_mode_s =
"IIR_256";
167 case TOUCH_PAD_FILTER_JITTER:
168 filter_mode_s =
"JITTER";
171 filter_mode_s =
"UNKNOWN";
174 ESP_LOGCONFIG(TAG,
" Filter mode: %s", filter_mode_s);
175 ESP_LOGCONFIG(TAG,
" Debounce count: %" PRIu32, this->
debounce_count_);
176 ESP_LOGCONFIG(TAG,
" Noise threshold coefficient: %" PRIu32, this->
noise_threshold_);
177 ESP_LOGCONFIG(TAG,
" Jitter filter step size: %" PRIu32, this->
jitter_step_);
178 const char *smooth_level_s;
180 case TOUCH_PAD_SMOOTH_OFF:
181 smooth_level_s =
"OFF";
183 case TOUCH_PAD_SMOOTH_IIR_2:
184 smooth_level_s =
"IIR_2";
186 case TOUCH_PAD_SMOOTH_IIR_4:
187 smooth_level_s =
"IIR_4";
189 case TOUCH_PAD_SMOOTH_IIR_8:
190 smooth_level_s =
"IIR_8";
193 smooth_level_s =
"UNKNOWN";
196 ESP_LOGCONFIG(TAG,
" Smooth level: %s", smooth_level_s);
202 case TOUCH_PAD_DENOISE_BIT12:
205 case TOUCH_PAD_DENOISE_BIT10:
208 case TOUCH_PAD_DENOISE_BIT8:
211 case TOUCH_PAD_DENOISE_BIT4:
218 ESP_LOGCONFIG(TAG,
" Denoise grade: %s", grade_s);
220 const char *cap_level_s;
222 case TOUCH_PAD_DENOISE_CAP_L0:
225 case TOUCH_PAD_DENOISE_CAP_L1:
228 case TOUCH_PAD_DENOISE_CAP_L2:
231 case TOUCH_PAD_DENOISE_CAP_L3:
234 case TOUCH_PAD_DENOISE_CAP_L4:
237 case TOUCH_PAD_DENOISE_CAP_L5:
240 case TOUCH_PAD_DENOISE_CAP_L6:
243 case TOUCH_PAD_DENOISE_CAP_L7:
247 cap_level_s =
"UNKNOWN";
250 ESP_LOGCONFIG(TAG,
" Denoise capacitance level: %s", cap_level_s);
254 ESP_LOGCONFIG(TAG,
" IIR Filter: %" PRIu32
"ms", this->
iir_filter_);
256 ESP_LOGCONFIG(TAG,
" IIR Filter DISABLED");
261 ESP_LOGCONFIG(TAG,
" Setup Mode ENABLED");
265 LOG_BINARY_SENSOR(
" ",
"Touch Pad", child);
266 ESP_LOGCONFIG(TAG,
" Pad: T%" PRIu32, (uint32_t) child->get_touch_pad());
267 ESP_LOGCONFIG(TAG,
" Threshold: %" PRIu32, child->get_threshold());
272 #if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) 275 touch_pad_filter_read_smooth(tp, &value);
277 touch_pad_read_raw_data(tp, &value);
282 touch_pad_read_filtered(tp, &value);
284 touch_pad_read(tp, &value);
291 const uint32_t now =
millis();
295 #if !(defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)) 296 child->publish_state(child->value_ < child->get_threshold());
298 child->publish_state(child->value_ > child->get_threshold());
302 ESP_LOGD(TAG,
"Touch Pad '%s' (T%" PRIu32
"): %" PRIu32, child->get_name().c_str(),
303 (uint32_t) child->get_touch_pad(), child->value_);
311 this->setup_mode_last_log_print_ = now;
316 bool is_wakeup_source =
false;
318 #if !(defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)) 320 touch_pad_filter_stop();
321 touch_pad_filter_delete();
326 if (child->get_wakeup_threshold() != 0) {
327 if (!is_wakeup_source) {
328 is_wakeup_source =
true;
330 touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER);
333 #if !(defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)) 335 touch_pad_config(child->get_touch_pad(), child->get_wakeup_threshold());
340 if (!is_wakeup_source) {
346 : touch_pad_(touch_pad), threshold_(threshold), wakeup_threshold_(wakeup_threshold) {}
uint32_t setup_mode_last_log_print_
void on_shutdown() override
touch_filter_mode_t filter_mode_
bool iir_filter_enabled_() const
touch_smooth_mode_t smooth_level_
std::vector< ESP32TouchBinarySensor * > children_
touch_pad_denoise_cap_t cap_level_
bool filter_configured_() const
void dump_config() override
ESP32TouchBinarySensor(touch_pad_t touch_pad, uint32_t threshold, uint32_t wakeup_threshold)
uint32_t component_touch_pad_read(touch_pad_t tp)
uint32_t IRAM_ATTR HOT millis()
touch_volt_atten_t voltage_attenuation_
touch_pad_shield_driver_t waterproof_shield_driver_
Application App
Global storage of Application pointer - only one Application can exist.
touch_high_volt_t high_voltage_reference_
uint32_t noise_threshold_
Implementation of SPI Controller mode.
bool denoise_configured_() const
bool waterproof_configured_() const
touch_pad_denoise_grade_t grade_
touch_low_volt_t low_voltage_reference_
touch_pad_t waterproof_guard_ring_pad_