diff --git a/arduino/beken-72xx/cores/arduino/LibreTuyaAPI.cpp b/arduino/beken-72xx/cores/arduino/LibreTuyaAPI.cpp index aeea2f8..0c36da2 100644 --- a/arduino/beken-72xx/cores/arduino/LibreTuyaAPI.cpp +++ b/arduino/beken-72xx/cores/arduino/LibreTuyaAPI.cpp @@ -32,6 +32,10 @@ void LibreTuya::restart() { bk_reboot(); } +void LibreTuya::restartDownloadMode() { + bk_reboot(); +} + ResetReason LibreTuya::getResetReason() { switch (bk_misc_get_start_type()) { case RESET_SOURCE_POWERON: diff --git a/arduino/libretuya/core/LibreTuyaClass.h b/arduino/libretuya/core/LibreTuyaClass.h index e419c30..be2a42a 100644 --- a/arduino/libretuya/core/LibreTuyaClass.h +++ b/arduino/libretuya/core/LibreTuyaClass.h @@ -63,6 +63,10 @@ class LibreTuya { * @brief Reboot the CPU. */ void restart(); + /** + * @brief Reboot the CPU and stay in download mode (if possible). + */ + void restartDownloadMode(); /** * @brief Get the reason of last chip reset. */ diff --git a/arduino/realtek-ambz/cores/arduino/LibreTuyaAPI.cpp b/arduino/realtek-ambz/cores/arduino/LibreTuyaAPI.cpp index 40e94cf..fc5d054 100644 --- a/arduino/realtek-ambz/cores/arduino/LibreTuyaAPI.cpp +++ b/arduino/realtek-ambz/cores/arduino/LibreTuyaAPI.cpp @@ -15,6 +15,14 @@ void LibreTuya::restart() { while (1) {} } +void LibreTuya::restartDownloadMode() { + // mww 0x40000138 0x8 + HAL_WRITE32(SYSTEM_CTRL_BASE, REG_SYS_NORESET_FF, 0x08); + // reboot it the ugly way + sys_reset(); + while (1) {} +} + ResetReason LibreTuya::getResetReason() { return RESET_REASON_UNKNOWN; }