diff --git a/src/app_console/app_console.cpp b/src/app_console/app_console.cpp index f6b23215..9aff20dc 100644 --- a/src/app_console/app_console.cpp +++ b/src/app_console/app_console.cpp @@ -483,7 +483,7 @@ void RegisterBtList() { } int CmdSamd(int argc, char** argv) { - static const std::string usage = "usage: samd [flash|charge]"; + static const std::string usage = "usage: samd [flash|charge|off]"; if (argc != 2) { std::cout << usage << std::endl; return 1; @@ -493,7 +493,6 @@ int CmdSamd(int argc, char** argv) { if (cmd == "flash") { std::cout << "resetting samd..." << std::endl; vTaskDelay(pdMS_TO_TICKS(5)); - AppConsole::sSamd->ResetToFlashSamd(); } else if (cmd == "charge") { auto res = AppConsole::sSamd->GetChargeStatus(); @@ -521,6 +520,10 @@ int CmdSamd(int argc, char** argv) { } else { std::cout << "unknown" << std::endl; } + } else if (cmd == "off") { + std::cout << "bye !!!" << std::endl; + vTaskDelay(pdMS_TO_TICKS(5)); + AppConsole::sSamd->PowerDown(); } else { std::cout << usage << std::endl; return 1; diff --git a/src/drivers/include/samd.hpp b/src/drivers/include/samd.hpp index 4a31a577..2640eb8b 100644 --- a/src/drivers/include/samd.hpp +++ b/src/drivers/include/samd.hpp @@ -52,6 +52,7 @@ class Samd { auto UpdateUsbStatus() -> void; auto ResetToFlashSamd() -> void; + auto PowerDown() -> void; static auto CreateReadPending() -> SemaphoreHandle_t; diff --git a/src/drivers/samd.cpp b/src/drivers/samd.cpp index 455e9ce5..176da241 100644 --- a/src/drivers/samd.cpp +++ b/src/drivers/samd.cpp @@ -138,6 +138,15 @@ auto Samd::ResetToFlashSamd() -> void { ESP_ERROR_CHECK(transaction.Execute()); } +auto Samd::PowerDown() -> void { + I2CTransaction transaction; + transaction.start() + .write_addr(kAddress, I2C_MASTER_WRITE) + .write_ack(Registers::kPowerControl, 0b1) + .stop(); + ESP_ERROR_CHECK(transaction.Execute()); +} + auto Samd::CreateReadPending() -> SemaphoreHandle_t { sReadPending = xSemaphoreCreateBinary(); return sReadPending;