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();
59 #if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) 60 touch_pad_config(child->get_touch_pad());
63 touch_pad_config(child->get_touch_pad(), 0);
66 #if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) 67 touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER);
68 touch_pad_fsm_start();
73 ESP_LOGCONFIG(TAG,
"Config for ESP32 Touch Hub:");
74 ESP_LOGCONFIG(TAG,
" Meas cycle: %.2fms", this->
meas_cycle_ / (8000000.0f / 1000.0f));
75 ESP_LOGCONFIG(TAG,
" Sleep cycle: %.2fms", this->
sleep_cycle_ / (150000.0f / 1000.0f));
95 ESP_LOGCONFIG(TAG,
" Low Voltage Reference: %s", lv_s);
102 case TOUCH_HVOLT_2V5:
105 case TOUCH_HVOLT_2V6:
108 case TOUCH_HVOLT_2V7:
115 ESP_LOGCONFIG(TAG,
" High Voltage Reference: %s", hv_s);
119 case TOUCH_HVOLT_ATTEN_1V5:
122 case TOUCH_HVOLT_ATTEN_1V:
125 case TOUCH_HVOLT_ATTEN_0V5:
128 case TOUCH_HVOLT_ATTEN_0V:
135 ESP_LOGCONFIG(TAG,
" Voltage Attenuation: %s", atten_s);
137 #if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) 139 const char *filter_mode_s;
141 case TOUCH_PAD_FILTER_IIR_4:
142 filter_mode_s =
"IIR_4";
144 case TOUCH_PAD_FILTER_IIR_8:
145 filter_mode_s =
"IIR_8";
147 case TOUCH_PAD_FILTER_IIR_16:
148 filter_mode_s =
"IIR_16";
150 case TOUCH_PAD_FILTER_IIR_32:
151 filter_mode_s =
"IIR_32";
153 case TOUCH_PAD_FILTER_IIR_64:
154 filter_mode_s =
"IIR_64";
156 case TOUCH_PAD_FILTER_IIR_128:
157 filter_mode_s =
"IIR_128";
159 case TOUCH_PAD_FILTER_IIR_256:
160 filter_mode_s =
"IIR_256";
162 case TOUCH_PAD_FILTER_JITTER:
163 filter_mode_s =
"JITTER";
166 filter_mode_s =
"UNKNOWN";
169 ESP_LOGCONFIG(TAG,
" Filter mode: %s", filter_mode_s);
170 ESP_LOGCONFIG(TAG,
" Debounce count: %" PRIu32, this->
debounce_count_);
171 ESP_LOGCONFIG(TAG,
" Noise threshold coefficient: %" PRIu32, this->
noise_threshold_);
172 ESP_LOGCONFIG(TAG,
" Jitter filter step size: %" PRIu32, this->
jitter_step_);
173 const char *smooth_level_s;
175 case TOUCH_PAD_SMOOTH_OFF:
176 smooth_level_s =
"OFF";
178 case TOUCH_PAD_SMOOTH_IIR_2:
179 smooth_level_s =
"IIR_2";
181 case TOUCH_PAD_SMOOTH_IIR_4:
182 smooth_level_s =
"IIR_4";
184 case TOUCH_PAD_SMOOTH_IIR_8:
185 smooth_level_s =
"IIR_8";
188 smooth_level_s =
"UNKNOWN";
191 ESP_LOGCONFIG(TAG,
" Smooth level: %s", smooth_level_s);
197 case TOUCH_PAD_DENOISE_BIT12:
200 case TOUCH_PAD_DENOISE_BIT10:
203 case TOUCH_PAD_DENOISE_BIT8:
206 case TOUCH_PAD_DENOISE_BIT4:
213 ESP_LOGCONFIG(TAG,
" Denoise grade: %s", grade_s);
215 const char *cap_level_s;
217 case TOUCH_PAD_DENOISE_CAP_L0:
220 case TOUCH_PAD_DENOISE_CAP_L1:
223 case TOUCH_PAD_DENOISE_CAP_L2:
226 case TOUCH_PAD_DENOISE_CAP_L3:
229 case TOUCH_PAD_DENOISE_CAP_L4:
232 case TOUCH_PAD_DENOISE_CAP_L5:
235 case TOUCH_PAD_DENOISE_CAP_L6:
238 case TOUCH_PAD_DENOISE_CAP_L7:
242 cap_level_s =
"UNKNOWN";
245 ESP_LOGCONFIG(TAG,
" Denoise capacitance level: %s", cap_level_s);
249 ESP_LOGCONFIG(TAG,
" IIR Filter: %" PRIu32
"ms", this->
iir_filter_);
251 ESP_LOGCONFIG(TAG,
" IIR Filter DISABLED");
256 ESP_LOGCONFIG(TAG,
" Setup Mode ENABLED");
260 LOG_BINARY_SENSOR(
" ",
"Touch Pad", child);
261 ESP_LOGCONFIG(TAG,
" Pad: T%" PRIu32, (uint32_t) child->get_touch_pad());
262 ESP_LOGCONFIG(TAG,
" Threshold: %" PRIu32, child->get_threshold());
267 #if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) 270 touch_pad_filter_read_smooth(tp, &value);
272 touch_pad_read_raw_data(tp, &value);
277 touch_pad_read_filtered(tp, &value);
279 touch_pad_read(tp, &value);
286 const uint32_t now =
millis();
290 #if !(defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)) 291 child->publish_state(child->value_ < child->get_threshold());
293 child->publish_state(child->value_ > child->get_threshold());
297 ESP_LOGD(TAG,
"Touch Pad '%s' (T%" PRIu32
"): %" PRIu32, child->get_name().c_str(),
298 (uint32_t) child->get_touch_pad(), child->value_);
306 this->setup_mode_last_log_print_ = now;
311 bool is_wakeup_source =
false;
313 #if !(defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)) 315 touch_pad_filter_stop();
316 touch_pad_filter_delete();
321 if (child->get_wakeup_threshold() != 0) {
322 if (!is_wakeup_source) {
323 is_wakeup_source =
true;
325 touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER);
328 #if !(defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)) 330 touch_pad_config(child->get_touch_pad(), child->get_wakeup_threshold());
335 if (!is_wakeup_source) {
341 : 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_