From 01390c2ca6d0851d396c2670238c7eb94c862d97 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 26 Apr 2021 13:56:44 +0200 Subject: [PATCH] Add ESP32 pulldown buttons ``Button_d`` and ``Button_id`` Add ESP32 pulldown buttons ``Button_d`` and ``Button_id`` (#10814) --- CHANGELOG.md | 1 + RELEASENOTES.md | 1 + tasmota/support_button.ino | 7 ++++++- tasmota/support_tasmota.ino | 11 +++++++++++ tasmota/tasmota_template.h | 12 ++++++++++++ 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c087f80bb..d1f78d769 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. ## [9.4.0.2] ### Added - Initial support for optional ``Template`` JSON fieldpair ``"CMND":";;..."`` (#11788) +- ESP32 pulldown buttons ``Button_d`` and ``Button_id`` (#10814) ## [Released] diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 574d5cc82..80d1a08ab 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -79,6 +79,7 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota ## Changelog v9.4.0.2 ### Added - Initial support for optional ``Template`` JSON fieldpair ``"CMND":";;..."`` [#11788](https://github.com/arendst/Tasmota/issues/11788) +- ESP32 pulldown buttons ``Button_d`` and ``Button_id`` [#10814](https://github.com/arendst/Tasmota/issues/10814) ### Breaking Changed diff --git a/tasmota/support_button.ino b/tasmota/support_button.ino index ca3338502..a4b0d9ef3 100644 --- a/tasmota/support_button.ino +++ b/tasmota/support_button.ino @@ -35,6 +35,7 @@ const char kMultiPress[] PROGMEM = struct BUTTON { uint32_t debounce = 0; // Button debounce timer uint32_t no_pullup_mask = 0; // key no pullup flag (1 = no pullup) + uint32_t pulldown_mask = 0; // key pulldown flag (1 = pulldown) uint32_t inverted_mask = 0; // Key inverted flag (1 = inverted) #ifdef ESP32 uint32_t touch_mask = 0; // Touch flag (1 = inverted) @@ -67,6 +68,10 @@ void ButtonPullupFlag(uint32_t button_bit) { bitSet(Button.no_pullup_mask, button_bit); } +void ButtonPulldownFlag(uint32_t button_bit) { + bitSet(Button.pulldown_mask, button_bit); +} + void ButtonInvertFlag(uint32_t button_bit) { bitSet(Button.inverted_mask, button_bit); } @@ -92,7 +97,7 @@ void ButtonInit(void) { pinMode(Pin(GPIO_KEY1, i), bitRead(Button.no_pullup_mask, i) ? INPUT : ((16 == Pin(GPIO_KEY1, i)) ? INPUT_PULLDOWN_16 : INPUT_PULLUP)); #endif // ESP8266 #ifdef ESP32 - pinMode(Pin(GPIO_KEY1, i), bitRead(Button.no_pullup_mask, i) ? INPUT : INPUT_PULLUP); + pinMode(Pin(GPIO_KEY1, i), bitRead(Button.pulldown_mask, i) ? INPUT_PULLDOWN : bitRead(Button.no_pullup_mask, i) ? INPUT : INPUT_PULLUP); #endif // ESP32 } #ifdef USE_ADC diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index c1f086645..7dcc83f59 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -1672,6 +1672,12 @@ void GpioInit(void) ButtonPullupFlag(mpin - AGPIO(GPIO_KEY1_NP)); // 0 .. 3 mpin -= (AGPIO(GPIO_KEY1_NP) - AGPIO(GPIO_KEY1)); } +#ifdef ESP32 + else if ((mpin >= AGPIO(GPIO_KEY1_PD)) && (mpin < (AGPIO(GPIO_KEY1_PD) + MAX_KEYS))) { + ButtonPulldownFlag(mpin - AGPIO(GPIO_KEY1_PD)); // 0 .. 3 + mpin -= (AGPIO(GPIO_KEY1_PD) - AGPIO(GPIO_KEY1)); + } +#endif else if ((mpin >= AGPIO(GPIO_KEY1_INV)) && (mpin < (AGPIO(GPIO_KEY1_INV) + MAX_KEYS))) { ButtonInvertFlag(mpin - AGPIO(GPIO_KEY1_INV)); // 0 .. 3 mpin -= (AGPIO(GPIO_KEY1_INV) - AGPIO(GPIO_KEY1)); @@ -1682,6 +1688,11 @@ void GpioInit(void) mpin -= (AGPIO(GPIO_KEY1_INV_NP) - AGPIO(GPIO_KEY1)); } #ifdef ESP32 + else if ((mpin >= AGPIO(GPIO_KEY1_INV_PD)) && (mpin < (AGPIO(GPIO_KEY1_INV_PD) + MAX_KEYS))) { + ButtonPulldownFlag(mpin - AGPIO(GPIO_KEY1_INV_PD)); // 0 .. 3 + ButtonInvertFlag(mpin - AGPIO(GPIO_KEY1_INV_PD)); // 0 .. 3 + mpin -= (AGPIO(GPIO_KEY1_INV_PD) - AGPIO(GPIO_KEY1)); + } else if ((mpin >= AGPIO(GPIO_KEY1_TC)) && (mpin < (AGPIO(GPIO_KEY1_TC) + MAX_KEYS))) { ButtonTouchFlag(mpin - AGPIO(GPIO_KEY1_TC)); // 0 .. 3 mpin -= (AGPIO(GPIO_KEY1_TC) - AGPIO(GPIO_KEY1)); diff --git a/tasmota/tasmota_template.h b/tasmota/tasmota_template.h index 542539331..060722c58 100644 --- a/tasmota/tasmota_template.h +++ b/tasmota/tasmota_template.h @@ -163,6 +163,9 @@ enum UserSelectablePins { GPIO_EPD_DATA, // Base connection EPD driver #endif GPIO_INPUT, +#ifdef ESP32 + GPIO_KEY1_PD, GPIO_KEY1_INV_PD, +#endif GPIO_SENSOR_END }; enum ProgramSelectablePins { @@ -346,6 +349,9 @@ const char kSensorNames[] PROGMEM = D_SENSOR_EPD_DATA "|" #endif D_SENSOR_INPUT "|" +#ifdef ESP32 + D_SENSOR_BUTTON "_d|" D_SENSOR_BUTTON "_id|" +#endif ; const char kSensorNamesFixed[] PROGMEM = @@ -362,9 +368,15 @@ const uint16_t kGpioNiceList[] PROGMEM = { AGPIO(GPIO_OPTION_A) + MAX_OPTIONS_A, // Device specific options AGPIO(GPIO_KEY1) + MAX_KEYS, // Buttons AGPIO(GPIO_KEY1_NP) + MAX_KEYS, +#ifdef ESP32 + AGPIO(GPIO_KEY1_PD) + MAX_KEYS, +#endif AGPIO(GPIO_KEY1_INV) + MAX_KEYS, AGPIO(GPIO_KEY1_INV_NP) + MAX_KEYS, +#ifdef ESP32 + AGPIO(GPIO_KEY1_INV_PD) + MAX_KEYS, AGPIO(GPIO_KEY1_TC) + MAX_KEYS, // Touch button +#endif AGPIO(GPIO_SWT1) + MAX_SWITCHES, // User connected external switches AGPIO(GPIO_SWT1_NP) + MAX_SWITCHES, #ifdef ROTARY_V1