mirror of
https://github.com/InfiniTimeOrg/InfiniTime.git
synced 2026-05-05 20:26:39 +02:00
Refactor HRS3300 and Watchdog as a generic class.
This commit is contained in:
parent
7d2ca5c63f
commit
8b2c875f02
@ -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
|
||||
|
||||
@ -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<Screen> 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 "?";
|
||||
|
||||
63
src/drivers/HeartRateSensor.h
Normal file
63
src/drivers/HeartRateSensor.h
Normal file
@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
#include <concepts>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Drivers {
|
||||
template <typename HeartRateSensorImpl>
|
||||
concept IsHeartRateSensor = requires(HeartRateSensorImpl sensor, uint8_t gain, uint8_t drive) {
|
||||
{ sensor.Init() };
|
||||
{ sensor.Enable() };
|
||||
{ sensor.Disable() };
|
||||
{ sensor.ReadHrs() } -> std::same_as<uint32_t>;
|
||||
{ sensor.ReadAls() } -> std::same_as<uint32_t>;
|
||||
{ sensor.SetGain(gain) };
|
||||
{ sensor.SetDrive(drive) };
|
||||
};
|
||||
|
||||
namespace Interface {
|
||||
template <class T>
|
||||
requires IsHeartRateSensor<T>
|
||||
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;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1,77 +0,0 @@
|
||||
#include "drivers/Watchdog.h"
|
||||
#include <mdk/nrf.h>
|
||||
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";
|
||||
}
|
||||
}
|
||||
@ -1,34 +1,75 @@
|
||||
#pragma once
|
||||
#include <concepts>
|
||||
#include <cstdint>
|
||||
|
||||
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 <typename WatchdogImpl>
|
||||
concept IsWatchdog = requires(WatchdogImpl watchdog) {
|
||||
{ watchdog.Start() };
|
||||
{ watchdog.Kick() };
|
||||
{ watchdog.ResetReason() } -> std::same_as<Watchdogs::ResetReasons>;
|
||||
};
|
||||
|
||||
class WatchdogView {
|
||||
public:
|
||||
WatchdogView(const Watchdog& watchdog) : watchdog {watchdog} {
|
||||
}
|
||||
Watchdog::ResetReasons ResetReason() const {
|
||||
return watchdog.ResetReason();
|
||||
}
|
||||
namespace Interface {
|
||||
template <class T>
|
||||
requires IsWatchdog<T>
|
||||
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;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
20
src/drivers/WatchdogView.h
Normal file
20
src/drivers/WatchdogView.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
C++ port Copyright (C) 2021 Jean-François Milants
|
||||
*/
|
||||
|
||||
#include "drivers/Hrs3300.h"
|
||||
#include "Hrs3300.h"
|
||||
#include <algorithm>
|
||||
#include <nrf_gpio.h>
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
#include <task.h>
|
||||
#include <nrf_log.h>
|
||||
|
||||
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
|
||||
*/
|
||||
49
src/drivers/heartRateSensors/Hrs3300.h
Normal file
49
src/drivers/heartRateSensors/Hrs3300.h
Normal file
@ -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);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
#include "drivers/Bma421.h"
|
||||
#include "Bma421.h"
|
||||
#include <libraries/delay/nrf_delay.h>
|
||||
#include <libraries/log/nrf_log.h>
|
||||
#include "drivers/TwiMaster.h"
|
||||
52
src/drivers/nrf52/Watchdog.cpp
Normal file
52
src/drivers/nrf52/Watchdog.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include "Watchdog.h"
|
||||
#include <mdk/nrf.h>
|
||||
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;
|
||||
}
|
||||
24
src/drivers/nrf52/Watchdog.h
Normal file
24
src/drivers/nrf52/Watchdog.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include "drivers/Watchdog.h"
|
||||
#include <cstdint>
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,11 @@
|
||||
#include "heartratetask/HeartRateTask.h"
|
||||
#include <drivers/Hrs3300.h>
|
||||
#include <drivers/heartRateSensors/Hrs3300.h>
|
||||
#include <components/heartrate/HeartRateController.h>
|
||||
#include <nrf_log.h>
|
||||
|
||||
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 {} {
|
||||
}
|
||||
|
||||
|
||||
@ -3,11 +3,9 @@
|
||||
#include <task.h>
|
||||
#include <queue.h>
|
||||
#include <components/heartrate/Ppg.h>
|
||||
#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;
|
||||
|
||||
18
src/main.cpp
18
src/main.cpp
@ -25,9 +25,8 @@
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
#include <timers.h>
|
||||
#include <drivers/Hrs3300.h>
|
||||
#include <drivers/Bma421.h>
|
||||
#include <drivers/SpiMaster.h>
|
||||
#include <drivers/heartRateSensors/Hrs3300.h>
|
||||
#include <drivers/motionSensors/Bma421.h>
|
||||
|
||||
#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;
|
||||
|
||||
16
src/port/HeartRateSensor.h
Normal file
16
src/port/HeartRateSensor.h
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include "drivers/HeartRateSensor.h"
|
||||
|
||||
#ifdef TARGET_DEVICE_PINETIME
|
||||
#include <drivers/heartRateSensors/Hrs3300.h>
|
||||
#endif
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Drivers {
|
||||
#ifdef TARGET_DEVICE_PINETIME
|
||||
using HeartRateSensor = Interface::HeartRateSensor<Pinetime::Drivers::HeartRateSensors::Hrs3300>;
|
||||
#else
|
||||
#error "No target device specified!"
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -2,7 +2,7 @@
|
||||
#include "drivers/MotionSensor.h"
|
||||
|
||||
#ifdef TARGET_DEVICE_PINETIME
|
||||
#include <drivers/Bma421.h>
|
||||
#include <drivers/motionSensors/Bma421.h>
|
||||
#endif
|
||||
|
||||
namespace Pinetime {
|
||||
|
||||
16
src/port/Watchdog.h
Normal file
16
src/port/Watchdog.h
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include "drivers/Watchdog.h"
|
||||
|
||||
#ifdef TARGET_DEVICE_PINETIME
|
||||
#include <drivers/nrf52//Watchdog.h>
|
||||
#endif
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Drivers {
|
||||
#ifdef TARGET_DEVICE_PINETIME
|
||||
using Watchdog = Interface::Watchdog<Pinetime::Drivers::Nrf52::Watchdog>;
|
||||
#else
|
||||
#error "No target device specified!"
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -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,
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
#include <timers.h>
|
||||
#include <heartratetask/HeartRateTask.h>
|
||||
#include <components/settings/Settings.h>
|
||||
#include <drivers/Bma421.h>
|
||||
#include <drivers/motionSensors/Bma421.h>
|
||||
#include <drivers/PinMap.h>
|
||||
#include <components/motion/MotionController.h>
|
||||
#include <drivers/SpiMaster.h>
|
||||
@ -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<std::chrono::system_clock, std::chrono::nanoseconds> 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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user