Add ESP32 pulldown buttons ``Button_d`` and ``Button_id``

Add ESP32 pulldown buttons ``Button_d`` and ``Button_id`` (#10814)
This commit is contained in:
Theo Arends 2021-04-26 13:56:44 +02:00
parent 61cecdef2f
commit 01390c2ca6
5 changed files with 31 additions and 1 deletions

View File

@ -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":"<any template related command>;<any template related command>;..."`` (#11788)
- ESP32 pulldown buttons ``Button_d`` and ``Button_id`` (#10814)
## [Released]

View File

@ -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":"<any template related command>;<any template related command>;..."`` [#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

View File

@ -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

View File

@ -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));

View File

@ -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