From b82d1fdcc3fdf53d33becb38ed2b93ad4a022152 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 3 Jan 2020 17:07:40 +0100 Subject: [PATCH] Move all Rotary interrupt code to iRAM Move all Rotary interrupt code to iRAM (#7410) --- tasmota/support_rotary.ino | 49 ++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/tasmota/support_rotary.ino b/tasmota/support_rotary.ino index a7c9860c1..cb6782da1 100644 --- a/tasmota/support_rotary.ino +++ b/tasmota/support_rotary.ino @@ -36,41 +36,34 @@ struct ROTARY { /********************************************************************************************/ -void update_position(void) -{ - uint8_t s; - - /* - * https://github.com/PaulStoffregen/Encoder/blob/master/Encoder.h - */ - - s = Rotary.state & 3; - if (digitalRead(pin[GPIO_ROT1A])) s |= 4; - if (digitalRead(pin[GPIO_ROT1B])) s |= 8; - switch (s) { - case 0: case 5: case 10: case 15: - break; - case 1: case 7: case 8: case 14: - Rotary.position++; break; - case 2: case 4: case 11: case 13: - Rotary.position--; break; - case 3: case 12: - Rotary.position = Rotary.position + 2; break; - default: - Rotary.position = Rotary.position - 2; break; - } - Rotary.state = (s >> 2); -} - #ifndef ARDUINO_ESP8266_RELEASE_2_3_0 // Fix core 2.5.x ISR not in IRAM Exception void update_rotary(void) ICACHE_RAM_ATTR; #endif // ARDUINO_ESP8266_RELEASE_2_3_0 void update_rotary(void) { - if (MI_DESK_LAMP == my_module_type){ + if (MI_DESK_LAMP == my_module_type) { if (LightPower()) { - update_position(); + /* + * https://github.com/PaulStoffregen/Encoder/blob/master/Encoder.h + */ + + uint8_t s = Rotary.state & 3; + if (digitalRead(pin[GPIO_ROT1A])) { s |= 4; } + if (digitalRead(pin[GPIO_ROT1B])) { s |= 8; } + switch (s) { + case 0: case 5: case 10: case 15: + break; + case 1: case 7: case 8: case 14: + Rotary.position++; break; + case 2: case 4: case 11: case 13: + Rotary.position--; break; + case 3: case 12: + Rotary.position = Rotary.position + 2; break; + default: + Rotary.position = Rotary.position - 2; break; + } + Rotary.state = (s >> 2); } } }