mirror of https://github.com/arendst/Tasmota.git
Add ESP32-S2 and ESP32-S3 touch input support
This commit is contained in:
parent
4f42f6bd53
commit
f668ea44ed
|
@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
|
|||
|
||||
## [12.1.1.3]
|
||||
### Added
|
||||
- ESP32-S2 and ESP32-S3 touch input support
|
||||
|
||||
### Changed
|
||||
|
||||
|
|
|
@ -125,6 +125,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo
|
|||
- Support of optional file calib.dat on ADE7953 based energy monitors like Shelly EM [#16486](https://github.com/arendst/Tasmota/issues/16486)
|
||||
- Support for Ethernet in ESP32 safeboot firmware [#16388](https://github.com/arendst/Tasmota/issues/16388)
|
||||
- ESP32-S3 support for internal temperature sensor
|
||||
- ESP32-S2 and ESP32-S3 touch input support
|
||||
- Berry has persistent MQTT subscriptions: auto-subscribe at (re)connection
|
||||
- Berry automated solidification of code
|
||||
|
||||
|
|
|
@ -836,9 +836,10 @@ typedef struct {
|
|||
uint8_t modbus_sbaudrate; // F61
|
||||
uint8_t modbus_sconfig; // F62
|
||||
|
||||
uint8_t free_f63[17]; // F63 - Decrement if adding new Setting variables just above and below
|
||||
uint8_t free_f63[13]; // F63 - Decrement if adding new Setting variables just above and below
|
||||
|
||||
// Only 32 bit boundary variables below
|
||||
uint32_t touch_threshold; // F70
|
||||
SOBitfield6 flag6; // F74
|
||||
uint16_t flowratemeter_calibration[2];// F78
|
||||
int32_t energy_kWhexport_ph[3]; // F7C
|
||||
|
|
|
@ -1015,6 +1015,13 @@
|
|||
|
||||
#define SET_ESP32_STACK_SIZE (8 * 1024) // Set the stack size for Tasmota. The default value is 8192 for Arduino, some builds might need to increase it
|
||||
|
||||
#ifdef SOC_TOUCH_VERSION_1
|
||||
#define ESP32_TOUCH_THRESHOLD 40
|
||||
#endif
|
||||
#ifdef SOC_TOUCH_VERSION_2
|
||||
#define ESP32_TOUCH_THRESHOLD 40000
|
||||
#endif
|
||||
|
||||
#define USE_ESP32_SENSORS // Add support for ESP32 temperature and optional hall effect sensor
|
||||
|
||||
//#define USE_SONOFF_SPM // Add support for ESP32 based Sonoff Smart Stackable Power Meter (+11k code)
|
||||
|
|
|
@ -976,6 +976,7 @@ void SettingsDefaultSet2(void) {
|
|||
flag.button_swap |= KEY_SWAP_DOUBLE_PRESS;
|
||||
flag.button_single |= KEY_ONLY_SINGLE_PRESS;
|
||||
Settings->param[P_HOLD_TIME] = KEY_HOLD_TIME; // Default 4 seconds hold time
|
||||
Settings->touch_threshold = ESP32_TOUCH_THRESHOLD;
|
||||
|
||||
// Switch
|
||||
for (uint32_t i = 0; i < MAX_SWITCHES_SET; i++) { Settings->switchmode[i] = SWITCH_MODE; }
|
||||
|
@ -1573,6 +1574,9 @@ void SettingsDelta(void) {
|
|||
if (Settings->version < 0x0C000204) { // 12.0.2.4
|
||||
Settings->param[P_BISTABLE_PULSE] = APP_BISTABLE_PULSE;
|
||||
}
|
||||
if (Settings->version < 0x0C010103) { // 12.1.1.3
|
||||
Settings->touch_threshold = ESP32_TOUCH_THRESHOLD;
|
||||
}
|
||||
|
||||
Settings->version = VERSION;
|
||||
SettingsSave(1);
|
||||
|
|
|
@ -25,10 +25,7 @@
|
|||
* Inspired by (https://github.com/OLIMEX/olimex-iot-firmware-esp8266/blob/master/olimex/user/user_switch2.c)
|
||||
\*********************************************************************************************/
|
||||
|
||||
#define MAX_RELAY_BUTTON1 5 // Max number of relay controlled by BUTTON1
|
||||
|
||||
#define TOUCH_PIN_THRESHOLD 12 // Smaller value will treated as button press
|
||||
#define TOUCH_HIT_THRESHOLD 3 // successful hits to filter out noise
|
||||
#define MAX_RELAY_BUTTON1 5 // Max number of relay controlled by BUTTON1
|
||||
|
||||
const uint8_t BUTTON_PROBE_INTERVAL = 10; // Time in milliseconds between button input probe
|
||||
const uint8_t BUTTON_FAST_PROBE_INTERVAL = 2; // Time in milliseconds between button input probe for AC detection
|
||||
|
@ -63,7 +60,6 @@ struct BUTTON {
|
|||
struct TOUCH_BUTTON {
|
||||
uint32_t touch_mask = 0; // Touch flag (1 = enabled)
|
||||
uint32_t calibration = 0; // Bitfield
|
||||
uint32_t pin_threshold = TOUCH_PIN_THRESHOLD;
|
||||
uint8_t hits[MAX_KEYS] = { 0 }; // Hits in a row to filter out noise
|
||||
} TOUCH_BUTTON;
|
||||
#endif // ESP32 SOC_TOUCH_VERSION_1 or SOC_TOUCH_VERSION_2
|
||||
|
@ -121,7 +117,11 @@ void ButtonProbe(void) {
|
|||
if (bitRead(TOUCH_BUTTON.touch_mask, i)) {
|
||||
if (ac_detect || bitRead(TOUCH_BUTTON.calibration, i +1)) { continue; } // Touch is slow. Takes 21mS to read
|
||||
uint32_t value = touchRead(Pin(GPIO_KEY1, i));
|
||||
button_not_activated = ((value == 0) || (value > TOUCH_BUTTON.pin_threshold));
|
||||
#ifdef SOC_TOUCH_VERSION_2
|
||||
button_not_activated = (value < Settings->touch_threshold); // ESPS3 No touch = 24200, Touch > 40000
|
||||
#else
|
||||
button_not_activated = ((value == 0) || (value > Settings->touch_threshold)); // ESP32 No touch = 74, Touch < 40
|
||||
#endif
|
||||
} else
|
||||
#endif // ESP32 SOC_TOUCH_VERSION_1 or SOC_TOUCH_VERSION_2
|
||||
button_not_activated = (digitalRead(Pin(GPIO_KEY1, i)) != bitRead(Button.inverted_mask, i));
|
||||
|
@ -306,7 +306,11 @@ void ButtonHandler(void) {
|
|||
#if defined(SOC_TOUCH_VERSION_1) || defined(SOC_TOUCH_VERSION_2)
|
||||
if (bitRead(TOUCH_BUTTON.touch_mask, button_index) && bitRead(TOUCH_BUTTON.calibration, button_index +1)) { // Touch
|
||||
uint32_t _value = touchRead(Pin(GPIO_KEY1, button_index));
|
||||
if ((_value > 0) && (_value < TOUCH_BUTTON.pin_threshold)) { // Probably read-error (0)
|
||||
#ifdef SOC_TOUCH_VERSION_2
|
||||
if (_value > Settings->touch_threshold) { // ESPS3 No touch = 24200, Touch = 100000
|
||||
#else
|
||||
if ((_value > 0) && (_value < Settings->touch_threshold)) { // ESP32 No touch = 74, Touch = 20 (Probably read-error (0))
|
||||
#endif
|
||||
TOUCH_BUTTON.hits[button_index]++;
|
||||
} else {
|
||||
TOUCH_BUTTON.hits[button_index] = 0;
|
||||
|
|
|
@ -46,7 +46,7 @@ const char kTasmotaCommands[] PROGMEM = "|" // No prefix
|
|||
#endif // USE_DEVICE_GROUPS
|
||||
D_CMND_SETSENSOR "|" D_CMND_SENSOR "|" D_CMND_DRIVER "|" D_CMND_JSON
|
||||
#ifdef ESP32
|
||||
"|Info|"
|
||||
"|Info|"
|
||||
#if defined(SOC_TOUCH_VERSION_1) || defined(SOC_TOUCH_VERSION_2)
|
||||
D_CMND_TOUCH_CAL "|" D_CMND_TOUCH_THRES "|"
|
||||
#endif // ESP32 SOC_TOUCH_VERSION_1 or SOC_TOUCH_VERSION_2
|
||||
|
@ -85,9 +85,9 @@ void (* const TasmotaCommand[])(void) PROGMEM = {
|
|||
#endif // USE_DEVICE_GROUPS
|
||||
&CmndSetSensor, &CmndSensor, &CmndDriver, &CmndJson
|
||||
#ifdef ESP32
|
||||
, &CmndInfo,
|
||||
, &CmndInfo,
|
||||
#if defined(SOC_TOUCH_VERSION_1) || defined(SOC_TOUCH_VERSION_2)
|
||||
&CmndTouchCal, &CmndTouchThres,
|
||||
&CmndTouchCal, &CmndTouchThres,
|
||||
#endif // ESP32 SOC_TOUCH_VERSION_1 or SOC_TOUCH_VERSION_2
|
||||
&CmndCpuFrequency
|
||||
#endif // ESP32
|
||||
|
@ -2634,10 +2634,10 @@ void CmndTouchCal(void) {
|
|||
}
|
||||
|
||||
void CmndTouchThres(void) {
|
||||
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 32000)) {
|
||||
TOUCH_BUTTON.pin_threshold = XdrvMailbox.payload;
|
||||
if (XdrvMailbox.data_len > 0) {
|
||||
Settings->touch_threshold = XdrvMailbox.payload;
|
||||
}
|
||||
ResponseCmndNumber(TOUCH_BUTTON.pin_threshold);
|
||||
ResponseCmndNumber(Settings->touch_threshold);
|
||||
}
|
||||
#endif // ESP32 SOC_TOUCH_VERSION_1 or SOC_TOUCH_VERSION_2
|
||||
|
||||
|
|
Loading…
Reference in New Issue