Add rotary No Pullup GPIO selection

Add rotary No Pullup GPIO selection ``Rotary A/B_n`` (#10407)
This commit is contained in:
Theo Arends 2021-01-06 12:51:12 +01:00
parent e3def2d60b
commit f8de9150d0
5 changed files with 25 additions and 3 deletions

View File

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

View File

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

View File

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

View File

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

View File

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