From f8de9150d0164b0aaff891d19a154a1f723db56d Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 6 Jan 2021 12:51:12 +0100 Subject: [PATCH] Add rotary No Pullup GPIO selection Add rotary No Pullup GPIO selection ``Rotary A/B_n`` (#10407) --- CHANGELOG.md | 1 + RELEASENOTES.md | 1 + tasmota/support_rotary.ino | 14 ++++++++++++-- tasmota/support_tasmota.ino | 10 ++++++++++ tasmota/xdrv_01_webserver.ino | 2 +- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15fe8f318..277d5877c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file. - Command ``RuleTimer0`` to access all RuleTimers at once (#10352) - SPI display driver SSD1331 Color oled by Jeroen Vermeulen (#10376) - IRremoteESP8266 library from v2.7.13 to v2.7.14 +- Rotary No Pullup GPIO selection ``Rotary A/B_n`` (#10407) ### Breaking Changed - Replaced MFRC522 13.56MHz rfid card reader GPIO selection from ``SPI CS`` by ``RC522 CS`` diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 95a449d99..c17382b99 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -65,6 +65,7 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota - Command ``SetOption119 1`` to remove the device addr from json payload, can be used with zb_topic_fname where the addr is already known from the topic [#10355](https://github.com/arendst/Tasmota/issues/10355) - Milliseconds to console output [#10152](https://github.com/arendst/Tasmota/issues/10152) - Gpio ``Option_a1`` enabling PWM2 high impedance if powered off as used by Wyze bulbs [#10196](https://github.com/arendst/Tasmota/issues/10196) +- Rotary No Pullup GPIO selection ``Rotary A/B_n`` [#10407](https://github.com/arendst/Tasmota/issues/10407) - BSSID and Signal Strength Indicator to GUI wifi scan result [#10253](https://github.com/arendst/Tasmota/issues/10253) - Support for P9813 RGB Led MOSFET controller [#10104](https://github.com/arendst/Tasmota/issues/10104) - Support for GPIO option selection diff --git a/tasmota/support_rotary.ino b/tasmota/support_rotary.ino index 7470a0985..538aeff2f 100644 --- a/tasmota/support_rotary.ino +++ b/tasmota/support_rotary.ino @@ -55,6 +55,8 @@ const uint8_t rotary_offset = 128; const int8_t rotary_state_pos[16] = { 0, 1, -1, 2, -1, 0, -2, 1, 1, -2, 0, -1, 2, -1, 1, 0 }; struct ROTARY { + uint8_t no_pullup_mask_a = 0; // Rotary A pull-up bitmask flags + uint8_t no_pullup_mask_b = 0; // Rotary B pull-up bitmask flags uint8_t model; bool present; } Rotary; @@ -74,6 +76,14 @@ tEncoder Encoder[MAX_ROTARIES]; /********************************************************************************************/ +void RotaryAPullupFlag(uint32 switch_bit) { + bitSet(Rotary.no_pullup_mask_a, switch_bit); +} + +void RotaryBPullupFlag(uint32 switch_bit) { + bitSet(Rotary.no_pullup_mask_b, switch_bit); +} + bool RotaryButtonPressed(uint32_t button_index) { if (!Rotary.present) { return false; } @@ -136,8 +146,8 @@ void RotaryInit(void) { Encoder[index].position = rotary_offset; Encoder[index].pina = Pin(GPIO_ROT1A, index); Encoder[index].pinb = Pin(GPIO_ROT1B, index); - pinMode(Encoder[index].pina, INPUT_PULLUP); - pinMode(Encoder[index].pinb, INPUT_PULLUP); + pinMode(Encoder[index].pina, bitRead(Rotary.no_pullup_mask_a, index) ? INPUT : INPUT_PULLUP); + pinMode(Encoder[index].pinb, bitRead(Rotary.no_pullup_mask_b, index) ? INPUT : INPUT_PULLUP); if (0 == Rotary.model) { attachInterruptArg(Encoder[index].pina, RotaryIsrArgMiDesk, &Encoder[index], CHANGE); attachInterruptArg(Encoder[index].pinb, RotaryIsrArgMiDesk, &Encoder[index], CHANGE); diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index d58447337..060f71eb4 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -1538,6 +1538,16 @@ void GpioInit(void) bitSet(TasmotaGlobal.gpio_optiona.data, mpin - AGPIO(GPIO_OPTION_A)); mpin = GPIO_NONE; } +#ifdef ROTARY_V1 + else if ((mpin >= AGPIO(GPIO_ROT1A_NP)) && (mpin < (AGPIO(GPIO_ROT1A_NP) + MAX_ROTARIES))) { + RotaryAPullupFlag(mpin - AGPIO(GPIO_ROT1A_NP)); + mpin -= (AGPIO(GPIO_ROT1A_NP) - AGPIO(GPIO_ROT1A)); + } + else if ((mpin >= AGPIO(GPIO_ROT1B_NP)) && (mpin < (AGPIO(GPIO_ROT1B_NP) + MAX_ROTARIES))) { + RotaryBPullupFlag(mpin - AGPIO(GPIO_ROT1B_NP)); + mpin -= (AGPIO(GPIO_ROT1B_NP) - AGPIO(GPIO_ROT1B)); + } +#endif // ROTARY_V1 else if ((mpin >= AGPIO(GPIO_SWT1_NP)) && (mpin < (AGPIO(GPIO_SWT1_NP) + MAX_SWITCHES))) { SwitchPullupFlag(mpin - AGPIO(GPIO_SWT1_NP)); mpin -= (AGPIO(GPIO_SWT1_NP) - AGPIO(GPIO_SWT1)); diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 3d57bdc95..4a63588f8 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -1583,7 +1583,7 @@ void ModuleSaveSettings(void) } else { if (ValidGPIO(i, template_gp.io[i])) { Settings.my_gp.io[i] = WebGetGpioArg(i); - gpios += F(", " D_GPIO ); gpios += String(i); gpios += F(" "); gpios += String(Settings.my_gp.io[i]); + gpios += F(", "); gpios += String(i); gpios += F(" "); gpios += String(Settings.my_gp.io[i]); } } }