From bd3b08f1e825ee6d60d007cae931c0469f9eea94 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 4 Aug 2021 17:52:31 +0200 Subject: [PATCH] Fix panic on Mi Desk rotary use - attempt 3 --- tasmota/support_rotary.ino | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/tasmota/support_rotary.ino b/tasmota/support_rotary.ino index 9e40f4cef..d4104cb21 100644 --- a/tasmota/support_rotary.ino +++ b/tasmota/support_rotary.ino @@ -47,6 +47,9 @@ #endif const uint8_t rotary_offset = 128; +#ifdef ESP8266 +const int8_t rotary_state_pos[16] = { 0, 1, -1, 2, -1, 0, -2, 1, 1, -2, 0, -1, 2, -1, 1, 0 }; +#endif // ESP8266 struct ROTARY { uint8_t no_pullup_mask_a = 0; // Rotary A pull-up bitmask flags @@ -111,21 +114,13 @@ void IRAM_ATTR RotaryIsrArgMiDesk(void *arg) { if (digitalRead(encoder->pina)) { state |= 4; } if (digitalRead(encoder->pinb)) { state |= 8; } -// This fails intermittendly with panic (Cache disabled but cached memory region accessed) -// int8_t rotary_state_pos[16] = { 0, 1, -1, 2, -1, 0, -2, 1, 1, -2, 0, -1, 2, -1, 1, 0 }; -// encoder->position += rotary_state_pos[state]; -// The below code does the same but is forced in IRAM as being code - switch (state) { - case 1: case 7: case 8: case 14: - encoder->position++; break; - case 2: case 4: case 11: case 13: - encoder->position--; break; - case 3: case 12: - encoder->position += 2; break; - case 6: case 9: - encoder->position -= 2; break; - } +#ifdef ESP32 +// This fails intermittendly with panic (Cache disabled but cached memory region accessed) if not in DRAM +// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/memory-types.html + const static DRAM_ATTR int8_t rotary_state_pos[16] = { 0, 1, -1, 2, -1, 0, -2, 1, 1, -2, 0, -1, 2, -1, 1, 0 }; +#endif // ESP32 + encoder->position += rotary_state_pos[state]; encoder->state = (state >> 2); }