| 151 | } |
| 152 | |
| 153 | static error_t stop() { |
| 154 | if (hp_detect_timer != nullptr) { |
| 155 | if (xTimerStop(hp_detect_timer, pdMS_TO_TICKS(100)) != pdPASS) { |
| 156 | LOG_W(TAG, "Failed to stop hp_detect timer"); |
| 157 | } |
| 158 | if (xTimerDelete(hp_detect_timer, pdMS_TO_TICKS(100)) != pdPASS) { |
| 159 | LOG_E(TAG, "Failed to delete hp_detect timer"); |
| 160 | } |
| 161 | // Always clear the handle — stale non-null handle is worse than a resource leak, |
| 162 | // as it would cause start() to silently skip re-creating the timer. |
| 163 | hp_detect_timer = nullptr; |
| 164 | io_expander0_cached.store(nullptr, std::memory_order_release); |
| 165 | } |
| 166 | |
| 167 | if (kb_detect_timer != nullptr) { |
| 168 | if (xTimerStop(kb_detect_timer, pdMS_TO_TICKS(100)) != pdPASS) { |
| 169 | LOG_W(TAG, "Failed to stop kb_detect timer"); |
| 170 | } |
| 171 | if (xTimerDelete(kb_detect_timer, pdMS_TO_TICKS(100)) != pdPASS) { |
| 172 | LOG_E(TAG, "Failed to delete kb_detect timer"); |
| 173 | } |
| 174 | kb_detect_timer = nullptr; |
| 175 | } |
| 176 | |
| 177 | return ERROR_NONE; |
| 178 | } |
| 179 | |
| 180 | Module m5stack_tab5_module = { |
| 181 | .name = "m5stack-tab5", |