From 4c9b77ea1308ef3fe72a81d888560161d19485d6 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 15 May 2024 15:57:16 +1000 Subject: [PATCH] Support setting the samd charge rate We default to the fast one, and do not try setting the charge rate bit on older samd versions --- src/drivers/include/drivers/samd.hpp | 1 + src/drivers/samd.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/drivers/include/drivers/samd.hpp b/src/drivers/include/drivers/samd.hpp index 55ea513c..897e78d6 100644 --- a/src/drivers/include/drivers/samd.hpp +++ b/src/drivers/include/drivers/samd.hpp @@ -56,6 +56,7 @@ class Samd { auto UpdateUsbStatus() -> void; auto ResetToFlashSamd() -> void; + auto SetFastChargeEnabled(bool) -> void; auto PowerDown() -> void; auto UsbMassStorage(bool en) -> void; diff --git a/src/drivers/samd.cpp b/src/drivers/samd.cpp index c5e8c08a..e4aa73ad 100644 --- a/src/drivers/samd.cpp +++ b/src/drivers/samd.cpp @@ -51,6 +51,7 @@ Samd::Samd() { UpdateChargeStatus(); UpdateUsbStatus(); + SetFastChargeEnabled(true); } Samd::~Samd() {} @@ -125,6 +126,18 @@ auto Samd::ResetToFlashSamd() -> void { ESP_ERROR_CHECK(transaction.Execute(3)); } +auto Samd::SetFastChargeEnabled(bool en) -> void { + if (version_ < 4) { + return; + } + I2CTransaction transaction; + transaction.start() + .write_addr(kAddress, I2C_MASTER_WRITE) + .write_ack(Registers::kPowerControl, (en << 1)) + .stop(); + ESP_ERROR_CHECK(transaction.Execute(3)); +} + auto Samd::PowerDown() -> void { I2CTransaction transaction; transaction.start()