diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index be0b7b0c..3942e463 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -440,11 +440,11 @@ list(APPEND SOURCE_FILES drivers/nrf52/Spi.cpp drivers/nrf52/TwiMaster.cpp drivers/spiFlash/SpiNorFlash.cpp - drivers/Watchdog.cpp + drivers/nrf52/Watchdog.cpp drivers/DebugPins.cpp drivers/InternalFlash.cpp - drivers/Hrs3300.cpp - drivers/Bma421.cpp + drivers/heartRateSensors/Hrs3300.cpp + drivers/motionSensors/Bma421.cpp drivers/Bma421_C/bma4.c drivers/Bma421_C/bma423.c components/battery/BatteryController.cpp @@ -507,11 +507,11 @@ list(APPEND RECOVERY_SOURCE_FILES drivers/nrf52/Spi.cpp drivers/nrf52/TwiMaster.cpp drivers/spiFlash/SpiNorFlash.cpp - drivers/Watchdog.cpp + drivers/nrf52/Watchdog.cpp drivers/DebugPins.cpp drivers/InternalFlash.cpp - drivers/Hrs3300.cpp - drivers/Bma421.cpp + drivers/heartRateSensors/Hrs3300.cpp + drivers/motionSensors/Bma421.cpp drivers/Bma421_C/bma4.c drivers/Bma421_C/bma423.c components/battery/BatteryController.cpp @@ -627,9 +627,9 @@ set(INCLUDE_FILES drivers/Watchdog.h drivers/DebugPins.h drivers/InternalFlash.h - drivers/Hrs3300.h + drivers/heartRateSensors/Hrs3300.h drivers/PinMap.h - drivers/Bma421.h + drivers/motionSensors/Bma421.h drivers/Bma421_C/bma4.c drivers/Bma421_C/bma423.c components/battery/BatteryController.h diff --git a/src/displayapp/screens/SystemInfo.cpp b/src/displayapp/screens/SystemInfo.cpp index 56d1de3e..aa664398 100644 --- a/src/displayapp/screens/SystemInfo.cpp +++ b/src/displayapp/screens/SystemInfo.cpp @@ -11,7 +11,7 @@ #include "components/brightness/BrightnessController.h" #include "components/datetime/DateTimeController.h" #include "components/motion/MotionController.h" -#include "drivers/Watchdog.h" +#include "drivers/WatchdogView.h" #include "displayapp/InfiniTimeTheme.h" using namespace Pinetime::Applications::Screens; @@ -101,23 +101,23 @@ std::unique_ptr SystemInfo::CreateScreen2() { auto batteryPercent = batteryController.PercentRemaining(); auto resetReason = [this]() { switch (watchdog.ResetReason()) { - case Drivers::Watchdog::ResetReasons::Watchdog: + case Drivers::Watchdogs::ResetReasons::Watchdog: return "wtdg"; - case Drivers::Watchdog::ResetReasons::HardReset: + case Drivers::Watchdogs::ResetReasons::HardReset: return "hardr"; - case Drivers::Watchdog::ResetReasons::NFC: + case Drivers::Watchdogs::ResetReasons::NFC: return "nfc"; - case Drivers::Watchdog::ResetReasons::SoftReset: + case Drivers::Watchdogs::ResetReasons::SoftReset: return "softr"; - case Drivers::Watchdog::ResetReasons::CpuLockup: + case Drivers::Watchdogs::ResetReasons::CpuLockup: return "cpulock"; - case Drivers::Watchdog::ResetReasons::SystemOff: + case Drivers::Watchdogs::ResetReasons::SystemOff: return "off"; - case Drivers::Watchdog::ResetReasons::LpComp: + case Drivers::Watchdogs::ResetReasons::LpComp: return "lpcomp"; - case Drivers::Watchdog::ResetReasons::DebugInterface: + case Drivers::Watchdogs::ResetReasons::DebugInterface: return "dbg"; - case Drivers::Watchdog::ResetReasons::ResetPin: + case Drivers::Watchdogs::ResetReasons::ResetPin: return "rst"; default: return "?"; diff --git a/src/drivers/HeartRateSensor.h b/src/drivers/HeartRateSensor.h new file mode 100644 index 00000000..b49cf133 --- /dev/null +++ b/src/drivers/HeartRateSensor.h @@ -0,0 +1,63 @@ +#pragma once +#include +#include +#include + +namespace Pinetime { + namespace Drivers { + template + concept IsHeartRateSensor = requires(HeartRateSensorImpl sensor, uint8_t gain, uint8_t drive) { + { sensor.Init() }; + { sensor.Enable() }; + { sensor.Disable() }; + { sensor.ReadHrs() } -> std::same_as; + { sensor.ReadAls() } -> std::same_as; + { sensor.SetGain(gain) }; + { sensor.SetDrive(drive) }; + }; + + namespace Interface { + template + requires IsHeartRateSensor + class HeartRateSensor { + public: + explicit HeartRateSensor(T& impl) : impl {impl} {} + HeartRateSensor(const HeartRateSensor&) = delete; + HeartRateSensor& operator=(const HeartRateSensor&) = delete; + HeartRateSensor(HeartRateSensor&&) = delete; + HeartRateSensor& operator=(HeartRateSensor&&) = delete; + + void Init() { + impl.Init(); + } + + void Enable() { + impl.Enable(); + } + + void Disable() { + impl.Disable(); + } + + uint32_t ReadHrs() { + return impl.ReadHrs(); + } + + uint32_t ReadAls() { + return impl.ReadAls(); + } + + void SetGain(uint8_t gain) { + impl.SetGain(gain); + } + + void SetDrive(uint8_t drive) { + impl.SetDrive(drive); + } + + private: + T& impl; + }; + } + } +} diff --git a/src/drivers/Hrs3300.h b/src/drivers/Hrs3300.h deleted file mode 100644 index 7372a976..00000000 --- a/src/drivers/Hrs3300.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include "drivers/TwiMaster.h" -#include "port/TwiMaster.h" - -namespace Pinetime { - namespace Drivers { - class Hrs3300 { - public: - enum class Registers : uint8_t { - Id = 0x00, - Enable = 0x01, - EnableHen = 0x80, - C1dataM = 0x08, - C0DataM = 0x09, - C0DataH = 0x0a, - PDriver = 0x0c, - C1dataH = 0x0d, - C1dataL = 0x0e, - C0dataL = 0x0f, - Res = 0x16, - Hgain = 0x17 - }; - - Hrs3300(TwiMaster& twiMaster, uint8_t twiAddress); - Hrs3300(const Hrs3300&) = delete; - Hrs3300& operator=(const Hrs3300&) = delete; - Hrs3300(Hrs3300&&) = delete; - Hrs3300& operator=(Hrs3300&&) = delete; - - void Init(); - void Enable(); - void Disable(); - uint32_t ReadHrs(); - uint32_t ReadAls(); - void SetGain(uint8_t gain); - void SetDrive(uint8_t drive); - - private: - TwiMaster& twiMaster; - uint8_t twiAddress; - - void WriteRegister(uint8_t reg, uint8_t data); - uint8_t ReadRegister(uint8_t reg); - }; - } -} diff --git a/src/drivers/Watchdog.cpp b/src/drivers/Watchdog.cpp deleted file mode 100644 index d0907a65..00000000 --- a/src/drivers/Watchdog.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "drivers/Watchdog.h" -#include -using namespace Pinetime::Drivers; - -void Watchdog::Setup(uint8_t timeoutSeconds) { - NRF_WDT->CONFIG &= ~(WDT_CONFIG_SLEEP_Msk << WDT_CONFIG_SLEEP_Pos); - NRF_WDT->CONFIG |= (WDT_CONFIG_HALT_Run << WDT_CONFIG_SLEEP_Pos); - - NRF_WDT->CONFIG &= ~(WDT_CONFIG_HALT_Msk << WDT_CONFIG_HALT_Pos); - NRF_WDT->CONFIG |= (WDT_CONFIG_HALT_Pause << WDT_CONFIG_HALT_Pos); - - /* timeout (s) = (CRV + 1) / 32768 */ - // JF : 7500 = 7.5s - uint32_t crv = (((timeoutSeconds * 1000u) << 15u) / 1000) - 1; - NRF_WDT->CRV = crv; - - /* Enable reload requests */ - NRF_WDT->RREN = (WDT_RREN_RR0_Enabled << WDT_RREN_RR0_Pos); - - resetReason = ActualResetReason(); -} - -void Watchdog::Start() { - NRF_WDT->TASKS_START = 1; -} - -void Watchdog::Kick() { - NRF_WDT->RR[0] = WDT_RR_RR_Reload; -} - -Watchdog::ResetReasons Watchdog::ActualResetReason() const { - uint32_t reason = NRF_POWER->RESETREAS; - NRF_POWER->RESETREAS = 0xffffffff; - - if (reason & 0x01u) - return ResetReasons::ResetPin; - if ((reason >> 1u) & 0x01u) - return ResetReasons::Watchdog; - if ((reason >> 2u) & 0x01u) - return ResetReasons::SoftReset; - if ((reason >> 3u) & 0x01u) - return ResetReasons::CpuLockup; - if ((reason >> 16u) & 0x01u) - return ResetReasons::SystemOff; - if ((reason >> 17u) & 0x01u) - return ResetReasons::LpComp; - if ((reason) &0x01u) - return ResetReasons::DebugInterface; - if ((reason >> 19u) & 0x01u) - return ResetReasons::NFC; - return ResetReasons::HardReset; -} - -const char* Watchdog::ResetReasonToString(Watchdog::ResetReasons reason) { - switch (reason) { - case ResetReasons::ResetPin: - return "Reset pin"; - case ResetReasons::Watchdog: - return "Watchdog"; - case ResetReasons::DebugInterface: - return "Debug interface"; - case ResetReasons::LpComp: - return "LPCOMP"; - case ResetReasons::SystemOff: - return "System OFF"; - case ResetReasons::CpuLockup: - return "CPU Lock-up"; - case ResetReasons::SoftReset: - return "Soft reset"; - case ResetReasons::NFC: - return "NFC"; - case ResetReasons::HardReset: - return "Hard reset"; - default: - return "Unknown"; - } -} diff --git a/src/drivers/Watchdog.h b/src/drivers/Watchdog.h index 03807d61..56a4f3d8 100644 --- a/src/drivers/Watchdog.h +++ b/src/drivers/Watchdog.h @@ -1,34 +1,75 @@ #pragma once +#include #include namespace Pinetime { namespace Drivers { - class Watchdog { - public: + namespace Watchdogs { enum class ResetReasons { ResetPin, Watchdog, SoftReset, CpuLockup, SystemOff, LpComp, DebugInterface, NFC, HardReset }; - void Setup(uint8_t timeoutSeconds); - void Start(); - void Kick(); - ResetReasons ResetReason() const { - return resetReason; - } - static const char* ResetReasonToString(ResetReasons reason); + } - private: - ResetReasons resetReason; - ResetReasons ActualResetReason() const; - }; + template + concept IsWatchdog = requires(WatchdogImpl watchdog) { + { watchdog.Start() }; + { watchdog.Kick() }; + { watchdog.ResetReason() } -> std::same_as; + }; - class WatchdogView { - public: - WatchdogView(const Watchdog& watchdog) : watchdog {watchdog} { - } - Watchdog::ResetReasons ResetReason() const { - return watchdog.ResetReason(); - } + namespace Interface { + template + requires IsWatchdog + class Watchdog { + public: + explicit Watchdog(T& impl) : impl {impl} {} + Watchdog(const Watchdog&) = delete; + Watchdog& operator=(const Watchdog&) = delete; + Watchdog(Watchdog&&) = delete; + Watchdog& operator=(Watchdog&&) = delete; - private: - const Watchdog& watchdog; - }; + void Setup(uint8_t timeoutSeconds) { + impl.Setup(timeoutSeconds); + } + + void Start() { + impl.Start(); + } + + void Kick() { + impl.Kick(); + } + + Watchdogs::ResetReasons ResetReason() const { + return impl.ResetReason(); + } + + static const char* ResetReasonToString(Watchdogs::ResetReasons reason) { + switch (reason) { + case Watchdogs::ResetReasons::ResetPin: + return "Reset pin"; + case Watchdogs::ResetReasons::Watchdog: + return "Watchdog"; + case Watchdogs::ResetReasons::DebugInterface: + return "Debug interface"; + case Watchdogs::ResetReasons::LpComp: + return "LPCOMP"; + case Watchdogs::ResetReasons::SystemOff: + return "System OFF"; + case Watchdogs::ResetReasons::CpuLockup: + return "CPU Lock-up"; + case Watchdogs::ResetReasons::SoftReset: + return "Soft reset"; + case Watchdogs::ResetReasons::NFC: + return "NFC"; + case Watchdogs::ResetReasons::HardReset: + return "Hard reset"; + default: + return "Unknown"; + } + } + + private: + T& impl; + }; + } } } diff --git a/src/drivers/WatchdogView.h b/src/drivers/WatchdogView.h new file mode 100644 index 00000000..ed42aadb --- /dev/null +++ b/src/drivers/WatchdogView.h @@ -0,0 +1,20 @@ +#pragma once +#include + +namespace Pinetime { + namespace Drivers { + class WatchdogView { + public: + explicit WatchdogView(const Watchdog& watchdog) : watchdog {watchdog} { + } + + Watchdogs::ResetReasons ResetReason() const { + return watchdog.ResetReason(); + } + + private: + const Watchdog& watchdog; + }; + } +} + diff --git a/src/drivers/Hrs3300.cpp b/src/drivers/heartRateSensors/Hrs3300.cpp similarity index 97% rename from src/drivers/Hrs3300.cpp rename to src/drivers/heartRateSensors/Hrs3300.cpp index ec620af2..e329bb47 100644 --- a/src/drivers/Hrs3300.cpp +++ b/src/drivers/heartRateSensors/Hrs3300.cpp @@ -4,7 +4,7 @@ C++ port Copyright (C) 2021 Jean-François Milants */ -#include "drivers/Hrs3300.h" +#include "Hrs3300.h" #include #include @@ -12,7 +12,7 @@ #include #include -using namespace Pinetime::Drivers; +using namespace Pinetime::Drivers::HeartRateSensors; /** 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 */ diff --git a/src/drivers/heartRateSensors/Hrs3300.h b/src/drivers/heartRateSensors/Hrs3300.h new file mode 100644 index 00000000..43ec44f7 --- /dev/null +++ b/src/drivers/heartRateSensors/Hrs3300.h @@ -0,0 +1,49 @@ +#pragma once + +#include "drivers/TwiMaster.h" +#include "port/TwiMaster.h" + +namespace Pinetime { + namespace Drivers { + namespace HeartRateSensors { + class Hrs3300 { + public: + enum class Registers : uint8_t { + Id = 0x00, + Enable = 0x01, + EnableHen = 0x80, + C1dataM = 0x08, + C0DataM = 0x09, + C0DataH = 0x0a, + PDriver = 0x0c, + C1dataH = 0x0d, + C1dataL = 0x0e, + C0dataL = 0x0f, + Res = 0x16, + Hgain = 0x17 + }; + + Hrs3300(TwiMaster& twiMaster, uint8_t twiAddress); + Hrs3300(const Hrs3300&) = delete; + Hrs3300& operator=(const Hrs3300&) = delete; + Hrs3300(Hrs3300&&) = delete; + Hrs3300& operator=(Hrs3300&&) = delete; + + void Init(); + void Enable(); + void Disable(); + uint32_t ReadHrs(); + uint32_t ReadAls(); + void SetGain(uint8_t gain); + void SetDrive(uint8_t drive); + + private: + TwiMaster& twiMaster; + uint8_t twiAddress; + + void WriteRegister(uint8_t reg, uint8_t data); + uint8_t ReadRegister(uint8_t reg); + }; + } + } +} diff --git a/src/drivers/Bma421.cpp b/src/drivers/motionSensors/Bma421.cpp similarity index 99% rename from src/drivers/Bma421.cpp rename to src/drivers/motionSensors/Bma421.cpp index ee3a88ca..8335bca1 100644 --- a/src/drivers/Bma421.cpp +++ b/src/drivers/motionSensors/Bma421.cpp @@ -1,4 +1,4 @@ -#include "drivers/Bma421.h" +#include "Bma421.h" #include #include #include "drivers/TwiMaster.h" diff --git a/src/drivers/Bma421.h b/src/drivers/motionSensors/Bma421.h similarity index 100% rename from src/drivers/Bma421.h rename to src/drivers/motionSensors/Bma421.h diff --git a/src/drivers/nrf52/Watchdog.cpp b/src/drivers/nrf52/Watchdog.cpp new file mode 100644 index 00000000..50845158 --- /dev/null +++ b/src/drivers/nrf52/Watchdog.cpp @@ -0,0 +1,52 @@ +#include "Watchdog.h" +#include +using namespace Pinetime::Drivers::Nrf52; + +void Watchdog::Setup(uint8_t timeoutSeconds) { + NRF_WDT->CONFIG &= ~(WDT_CONFIG_SLEEP_Msk << WDT_CONFIG_SLEEP_Pos); + NRF_WDT->CONFIG |= (WDT_CONFIG_HALT_Run << WDT_CONFIG_SLEEP_Pos); + + NRF_WDT->CONFIG &= ~(WDT_CONFIG_HALT_Msk << WDT_CONFIG_HALT_Pos); + NRF_WDT->CONFIG |= (WDT_CONFIG_HALT_Pause << WDT_CONFIG_HALT_Pos); + + /* timeout (s) = (CRV + 1) / 32768 */ + // JF : 7500 = 7.5s + uint32_t crv = (((timeoutSeconds * 1000u) << 15u) / 1000) - 1; + NRF_WDT->CRV = crv; + + /* Enable reload requests */ + NRF_WDT->RREN = (WDT_RREN_RR0_Enabled << WDT_RREN_RR0_Pos); + + resetReason = ActualResetReason(); +} + +void Watchdog::Start() { + NRF_WDT->TASKS_START = 1; +} + +void Watchdog::Kick() { + NRF_WDT->RR[0] = WDT_RR_RR_Reload; +} + +Pinetime::Drivers::Watchdogs::ResetReasons Watchdog::ActualResetReason() const { + uint32_t reason = NRF_POWER->RESETREAS; + NRF_POWER->RESETREAS = 0xffffffff; + + if (reason & 0x01u) + return Watchdogs::ResetReasons::ResetPin; + if ((reason >> 1u) & 0x01u) + return Watchdogs::ResetReasons::Watchdog; + if ((reason >> 2u) & 0x01u) + return Watchdogs::ResetReasons::SoftReset; + if ((reason >> 3u) & 0x01u) + return Watchdogs::ResetReasons::CpuLockup; + if ((reason >> 16u) & 0x01u) + return Watchdogs::ResetReasons::SystemOff; + if ((reason >> 17u) & 0x01u) + return Watchdogs::ResetReasons::LpComp; + if ((reason) &0x01u) + return Watchdogs::ResetReasons::DebugInterface; + if ((reason >> 19u) & 0x01u) + return Watchdogs::ResetReasons::NFC; + return Watchdogs::ResetReasons::HardReset; +} diff --git a/src/drivers/nrf52/Watchdog.h b/src/drivers/nrf52/Watchdog.h new file mode 100644 index 00000000..92f19f52 --- /dev/null +++ b/src/drivers/nrf52/Watchdog.h @@ -0,0 +1,24 @@ +#pragma once +#include "drivers/Watchdog.h" +#include + +namespace Pinetime { + namespace Drivers { + namespace Nrf52 { + class Watchdog { + public: + enum class ResetReasons { ResetPin, Watchdog, SoftReset, CpuLockup, SystemOff, LpComp, DebugInterface, NFC, HardReset }; + void Setup(uint8_t timeoutSeconds); + void Start(); + void Kick(); + Watchdogs::ResetReasons ResetReason() const { + return resetReason; + } + + private: + Watchdogs::ResetReasons resetReason; + Watchdogs::ResetReasons ActualResetReason() const; + }; + } + } +} diff --git a/src/heartratetask/HeartRateTask.cpp b/src/heartratetask/HeartRateTask.cpp index bc227624..72bd11a7 100644 --- a/src/heartratetask/HeartRateTask.cpp +++ b/src/heartratetask/HeartRateTask.cpp @@ -1,11 +1,11 @@ #include "heartratetask/HeartRateTask.h" -#include +#include #include #include using namespace Pinetime::Applications; -HeartRateTask::HeartRateTask(Drivers::Hrs3300& heartRateSensor, Controllers::HeartRateController& controller) +HeartRateTask::HeartRateTask(Drivers::HeartRateSensor & heartRateSensor, Controllers::HeartRateController& controller) : heartRateSensor {heartRateSensor}, controller {controller}, ppg {} { } diff --git a/src/heartratetask/HeartRateTask.h b/src/heartratetask/HeartRateTask.h index 0796dc74..8ed310f8 100644 --- a/src/heartratetask/HeartRateTask.h +++ b/src/heartratetask/HeartRateTask.h @@ -3,11 +3,9 @@ #include #include #include +#include "port/HeartRateSensor.h" namespace Pinetime { - namespace Drivers { - class Hrs3300; - } namespace Controllers { class HeartRateController; } @@ -17,7 +15,7 @@ namespace Pinetime { enum class Messages : uint8_t { GoToSleep, WakeUp, StartMeasurement, StopMeasurement }; enum class States { Idle, Running }; - explicit HeartRateTask(Drivers::Hrs3300& heartRateSensor, Controllers::HeartRateController& controller); + explicit HeartRateTask(Drivers::HeartRateSensor& heartRateSensor, Controllers::HeartRateController& controller); void Start(); void Work(); void PushMessage(Messages msg); @@ -30,7 +28,7 @@ namespace Pinetime { TaskHandle_t taskHandle; QueueHandle_t messageQueue; States state = States::Running; - Drivers::Hrs3300& heartRateSensor; + Drivers::HeartRateSensor& heartRateSensor; Controllers::HeartRateController& controller; Controllers::Ppg ppg; bool measurementStarted = false; diff --git a/src/main.cpp b/src/main.cpp index f02756fb..c1287de8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,9 +25,8 @@ #include #include #include -#include -#include -#include +#include +#include #include "BootloaderVersion.h" #include "components/battery/BatteryController.h" @@ -47,6 +46,8 @@ #include "drivers/PinMap.h" #include "systemtask/SystemTask.h" #include "drivers/PinMap.h" +#include "drivers/Watchdog.h" +#include "drivers/WatchdogView.h" #include "touchhandler/TouchHandler.h" #include "buttonhandler/ButtonHandler.h" @@ -60,6 +61,8 @@ Pinetime::Logging::DummyLogger logger; #include "port/TouchPanel.h" #include "port/MotionSensor.h" +#include "port/HeartRateSensor.h" +#include "port/Watchdog.h" static constexpr uint8_t touchPanelTwiAddress = 0x15; static constexpr uint8_t motionSensorTwiAddress = 0x18; @@ -104,7 +107,9 @@ Pinetime::Components::LittleVgl lvgl {lcd, touchPanel}; Pinetime::Drivers::MotionSensors::Bma421 motionSensorImpl {twiMaster, motionSensorTwiAddress}; Pinetime::Drivers::MotionSensor motionSensor {motionSensorImpl}; -Pinetime::Drivers::Hrs3300 heartRateSensor {twiMaster, heartRateSensorTwiAddress}; + +Pinetime::Drivers::HeartRateSensors::Hrs3300 heartRateSensorImpl {twiMaster, heartRateSensorTwiAddress}; +Pinetime::Drivers::HeartRateSensor heartRateSensor{heartRateSensorImpl}; TimerHandle_t debounceTimer; TimerHandle_t debounceChargeTimer; @@ -119,8 +124,9 @@ Pinetime::Controllers::Settings settingsController {fs}; Pinetime::Controllers::MotorController motorController {}; Pinetime::Controllers::DateTime dateTimeController {settingsController}; -Pinetime::Drivers::Watchdog watchdog; -Pinetime::Drivers::WatchdogView watchdogView(watchdog); +Pinetime::Drivers::Nrf52::Watchdog watchdogImpl; +Pinetime::Drivers::Watchdog watchdog{watchdogImpl}; +Pinetime::Drivers::WatchdogView watchdogView{watchdog}; Pinetime::Controllers::NotificationManager notificationManager; Pinetime::Controllers::MotionController motionController; Pinetime::Controllers::TimerController timerController; diff --git a/src/port/HeartRateSensor.h b/src/port/HeartRateSensor.h new file mode 100644 index 00000000..b28e7d56 --- /dev/null +++ b/src/port/HeartRateSensor.h @@ -0,0 +1,16 @@ +#pragma once +#include "drivers/HeartRateSensor.h" + +#ifdef TARGET_DEVICE_PINETIME + #include +#endif + +namespace Pinetime { + namespace Drivers { +#ifdef TARGET_DEVICE_PINETIME + using HeartRateSensor = Interface::HeartRateSensor; +#else + #error "No target device specified!" +#endif + } +} diff --git a/src/port/MotionSensor.h b/src/port/MotionSensor.h index 5a927274..f6d51f45 100644 --- a/src/port/MotionSensor.h +++ b/src/port/MotionSensor.h @@ -2,7 +2,7 @@ #include "drivers/MotionSensor.h" #ifdef TARGET_DEVICE_PINETIME - #include + #include #endif namespace Pinetime { diff --git a/src/port/Watchdog.h b/src/port/Watchdog.h new file mode 100644 index 00000000..ff66ac66 --- /dev/null +++ b/src/port/Watchdog.h @@ -0,0 +1,16 @@ +#pragma once +#include "drivers/Watchdog.h" + +#ifdef TARGET_DEVICE_PINETIME + #include +#endif + +namespace Pinetime { + namespace Drivers { +#ifdef TARGET_DEVICE_PINETIME + using Watchdog = Interface::Watchdog; +#else + #error "No target device specified!" +#endif + } +} diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 966a86cc..5d91b6f1 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -7,7 +7,7 @@ #include "components/ble/BleController.h" #include "displayapp/TouchEvents.h" #include "drivers/St7789.h" -#include "drivers/Hrs3300.h" +#include "drivers/heartRateSensors/Hrs3300.h" #include "drivers/PinMap.h" #include "main.h" #include "BootErrors.h" @@ -53,7 +53,7 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi, Drivers::Watchdog& watchdog, Pinetime::Controllers::NotificationManager& notificationManager, Pinetime::Controllers::MotorController& motorController, - Pinetime::Drivers::Hrs3300& heartRateSensor, + Pinetime::Drivers::HeartRateSensor& heartRateSensor, Pinetime::Controllers::MotionController& motionController, Pinetime::Drivers::MotionSensor& motionSensor, Controllers::Settings& settingsController, diff --git a/src/systemtask/SystemTask.h b/src/systemtask/SystemTask.h index 543e1253..33584116 100644 --- a/src/systemtask/SystemTask.h +++ b/src/systemtask/SystemTask.h @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include @@ -37,12 +37,13 @@ #include "systemtask/Messages.h" #include "port/SpiMaster.h" #include "port/MotionSensor.h" +#include "port/HeartRateSensor.h" +#include "port/Watchdog.h" extern std::chrono::time_point NoInit_BackUpTime; namespace Pinetime { namespace Drivers { class St7789; - class Hrs3300; } namespace Controllers { class Battery; @@ -67,7 +68,7 @@ namespace Pinetime { Drivers::Watchdog& watchdog, Pinetime::Controllers::NotificationManager& notificationManager, Pinetime::Controllers::MotorController& motorController, - Pinetime::Drivers::Hrs3300& heartRateSensor, + Pinetime::Drivers::HeartRateSensor& heartRateSensor, Pinetime::Controllers::MotionController& motionController, Pinetime::Drivers::MotionSensor& motionSensor, Controllers::Settings& settingsController, @@ -113,7 +114,7 @@ namespace Pinetime { Pinetime::Drivers::Watchdog& watchdog; Pinetime::Controllers::NotificationManager& notificationManager; Pinetime::Controllers::MotorController& motorController; - Pinetime::Drivers::Hrs3300& heartRateSensor; + Pinetime::Drivers::HeartRateSensor& heartRateSensor; Pinetime::Drivers::MotionSensor& motionSensor; Pinetime::Controllers::Settings& settingsController; Pinetime::Controllers::HeartRateController& heartRateController;