From a48d4e0b1330a34e32f56a6d4a65c77eca84f655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Sun, 7 May 2023 18:18:49 +0200 Subject: [PATCH] Power optimization - Enable HRS3300 (heart rate sensor) sleep mode. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Put the HRS3300 to sleep mode when InfiniTime is going to sleep. This change reduces the power consumption by 130µA when the heart rate sensor is disabled. --- src/drivers/Hrs3300.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/drivers/Hrs3300.cpp b/src/drivers/Hrs3300.cpp index 004c5362..7dfd301c 100644 --- a/src/drivers/Hrs3300.cpp +++ b/src/drivers/Hrs3300.cpp @@ -14,6 +14,10 @@ using namespace Pinetime::Drivers; +namespace { + static constexpr uint8_t ledDriveCurrentValue = 0x2f; +} + /** Driver for the HRS3300 heart rate sensor. * Original implementation from wasp-os : https://github.com/daniel-thompson/wasp-os/blob/master/wasp/drivers/hrs3300.py * @@ -35,7 +39,7 @@ void Hrs3300::Init() { // Note: Setting low nibble to 0x8 per the datasheet results in // modulated LED driver output. Setting to 0xF results in clean, // steady output during the ADC conversion period. - WriteRegister(static_cast(Registers::PDriver), 0x2f); + WriteRegister(static_cast(Registers::PDriver), ledDriveCurrentValue); // HRS and ALS both in 15-bit mode results in ~50ms LED drive period // and presumably ~50ms ADC conversion period. @@ -50,6 +54,8 @@ void Hrs3300::Enable() { auto value = ReadRegister(static_cast(Registers::Enable)); value |= 0x80; WriteRegister(static_cast(Registers::Enable), value); + + WriteRegister(static_cast(Registers::PDriver), ledDriveCurrentValue); } void Hrs3300::Disable() { @@ -57,6 +63,8 @@ void Hrs3300::Disable() { auto value = ReadRegister(static_cast(Registers::Enable)); value &= ~0x80; WriteRegister(static_cast(Registers::Enable), value); + + WriteRegister(static_cast(Registers::PDriver), 0); } uint32_t Hrs3300::ReadHrs() {