11namespace esp32_touch {
13static const char *
const TAG =
"esp32_touch";
16 ESP_LOGCONFIG(TAG,
"Running setup");
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 && defined(USE_ESP32_VARIANT_ESP32)
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();
79 "Config for ESP32 Touch Hub:\n"
80 " Meas cycle: %.2fms\n"
81 " Sleep cycle: %.2fms",
102 ESP_LOGCONFIG(TAG,
" Low Voltage Reference: %s", lv_s);
106 case TOUCH_HVOLT_2V4:
109 case TOUCH_HVOLT_2V5:
112 case TOUCH_HVOLT_2V6:
115 case TOUCH_HVOLT_2V7:
122 ESP_LOGCONFIG(TAG,
" High Voltage Reference: %s", hv_s);
126 case TOUCH_HVOLT_ATTEN_1V5:
129 case TOUCH_HVOLT_ATTEN_1V:
132 case TOUCH_HVOLT_ATTEN_0V5:
135 case TOUCH_HVOLT_ATTEN_0V:
142 ESP_LOGCONFIG(TAG,
" Voltage Attenuation: %s", atten_s);
144#if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)
146 const char *filter_mode_s;
148 case TOUCH_PAD_FILTER_IIR_4:
149 filter_mode_s =
"IIR_4";
151 case TOUCH_PAD_FILTER_IIR_8:
152 filter_mode_s =
"IIR_8";
154 case TOUCH_PAD_FILTER_IIR_16:
155 filter_mode_s =
"IIR_16";
157 case TOUCH_PAD_FILTER_IIR_32:
158 filter_mode_s =
"IIR_32";
160 case TOUCH_PAD_FILTER_IIR_64:
161 filter_mode_s =
"IIR_64";
163 case TOUCH_PAD_FILTER_IIR_128:
164 filter_mode_s =
"IIR_128";
166 case TOUCH_PAD_FILTER_IIR_256:
167 filter_mode_s =
"IIR_256";
169 case TOUCH_PAD_FILTER_JITTER:
170 filter_mode_s =
"JITTER";
173 filter_mode_s =
"UNKNOWN";
178 " Debounce count: %" PRIu32
"\n"
179 " Noise threshold coefficient: %" PRIu32
"\n"
180 " Jitter filter step size: %" PRIu32,
182 const char *smooth_level_s;
184 case TOUCH_PAD_SMOOTH_OFF:
185 smooth_level_s =
"OFF";
187 case TOUCH_PAD_SMOOTH_IIR_2:
188 smooth_level_s =
"IIR_2";
190 case TOUCH_PAD_SMOOTH_IIR_4:
191 smooth_level_s =
"IIR_4";
193 case TOUCH_PAD_SMOOTH_IIR_8:
194 smooth_level_s =
"IIR_8";
197 smooth_level_s =
"UNKNOWN";
200 ESP_LOGCONFIG(TAG,
" Smooth level: %s", smooth_level_s);
206 case TOUCH_PAD_DENOISE_BIT12:
209 case TOUCH_PAD_DENOISE_BIT10:
212 case TOUCH_PAD_DENOISE_BIT8:
215 case TOUCH_PAD_DENOISE_BIT4:
222 ESP_LOGCONFIG(TAG,
" Denoise grade: %s", grade_s);
224 const char *cap_level_s;
226 case TOUCH_PAD_DENOISE_CAP_L0:
229 case TOUCH_PAD_DENOISE_CAP_L1:
232 case TOUCH_PAD_DENOISE_CAP_L2:
235 case TOUCH_PAD_DENOISE_CAP_L3:
238 case TOUCH_PAD_DENOISE_CAP_L4:
241 case TOUCH_PAD_DENOISE_CAP_L5:
244 case TOUCH_PAD_DENOISE_CAP_L6:
247 case TOUCH_PAD_DENOISE_CAP_L7:
251 cap_level_s =
"UNKNOWN";
254 ESP_LOGCONFIG(TAG,
" Denoise capacitance level: %s", cap_level_s);
258 ESP_LOGCONFIG(TAG,
" IIR Filter: %" PRIu32
"ms", this->
iir_filter_);
260 ESP_LOGCONFIG(TAG,
" IIR Filter DISABLED");
265 ESP_LOGCONFIG(TAG,
" Setup Mode ENABLED");
269 LOG_BINARY_SENSOR(
" ",
"Touch Pad", child);
270 ESP_LOGCONFIG(TAG,
" Pad: T%" PRIu32, (uint32_t) child->get_touch_pad());
271 ESP_LOGCONFIG(TAG,
" Threshold: %" PRIu32, child->get_threshold());
276#if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)
279 touch_pad_filter_read_smooth(tp, &value);
281 touch_pad_read_raw_data(tp, &value);
286 touch_pad_read_filtered(tp, &value);
288 touch_pad_read(tp, &value);
299#if !(defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3))
300 child->publish_state(child->value_ < child->get_threshold());
302 child->publish_state(child->value_ > child->get_threshold());
306 ESP_LOGD(TAG,
"Touch Pad '%s' (T%" PRIu32
"): %" PRIu32, child->get_name().c_str(),
307 (uint32_t) child->get_touch_pad(), child->value_);
315 this->setup_mode_last_log_print_ = now;
320 bool is_wakeup_source =
false;
322#if !(defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3))
324 touch_pad_filter_stop();
325 touch_pad_filter_delete();
330 if (child->get_wakeup_threshold() != 0) {
331 if (!is_wakeup_source) {
332 is_wakeup_source =
true;
334 touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER);
337#if !(defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3))
339 touch_pad_config(child->get_touch_pad(), child->get_wakeup_threshold());
344 if (!is_wakeup_source) {
350 : touch_pad_(touch_pad), threshold_(threshold), wakeup_threshold_(wakeup_threshold) {}
void feed_wdt(uint32_t time=0)
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
ESP32TouchBinarySensor(touch_pad_t touch_pad, uint32_t threshold, uint32_t wakeup_threshold)
touch_volt_atten_t voltage_attenuation_
touch_filter_mode_t filter_mode_
bool filter_configured_() const
bool iir_filter_enabled_() const
touch_pad_t waterproof_guard_ring_pad_
uint32_t setup_mode_last_log_print_
uint32_t component_touch_pad_read(touch_pad_t tp)
bool waterproof_configured_() const
touch_pad_denoise_grade_t grade_
bool denoise_configured_() const
void on_shutdown() override
touch_high_volt_t high_voltage_reference_
touch_pad_shield_driver_t waterproof_shield_driver_
uint32_t noise_threshold_
touch_smooth_mode_t smooth_level_
std::vector< ESP32TouchBinarySensor * > children_
touch_pad_denoise_cap_t cap_level_
touch_low_volt_t low_voltage_reference_
void dump_config() override
Providing packet encoding functions for exchanging data with a remote host.
Application App
Global storage of Application pointer - only one Application can exist.