Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add configuration struct to init #262

6 changes: 3 additions & 3 deletions hal_st/stm32fxxx/WatchDogStm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace hal
{
WatchDogStm::WatchDogStm(const infra::Function<void()>& onExpired)
WatchDogStm::WatchDogStm(const infra::Function<void()>& onExpired, const Config& config)
: onExpired(onExpired)
, interruptRegistration(WWDG_IRQn, [this]()
{
Expand All @@ -17,7 +17,7 @@ namespace hal
// min time (mS) = 1000 * (Counter _ Window) / WWDG clock --> 0
AleksKovalenko marked this conversation as resolved.
Show resolved Hide resolved
// max time (mS) = 1000 * (Counter _ 0x40) / WWDG clock --> 36 ms
handle.Instance = WWDG;
handle.Init.Prescaler = WWDG_PRESCALER_8;
handle.Init.Prescaler = config.prescaler;
handle.Init.Window = WWDG_CR_T;
handle.Init.Counter = WWDG_CR_T;
#ifdef STM32F7
Expand All @@ -33,7 +33,7 @@ namespace hal
NVIC_SetPriority(WWDG_IRQn, 0);
WWDG->CFR |= WWDG_CFR_EWI;

feedingTimer.Start(std::chrono::milliseconds(25), [this]()
feedingTimer.Start(config.feedTimerInterval, [this]()
{
Feed();
});
Expand Down
11 changes: 10 additions & 1 deletion hal_st/stm32fxxx/WatchDogStm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ namespace hal
class WatchDogStm
{
public:
WatchDogStm(const infra::Function<void()>& onExpired);

struct Config
{
constexpr Config()
{}
uint32_t prescaler { WWDG_PRESCALER_8 };
infra::Duration feedTimerInterval{ std::chrono::milliseconds(25) };
};

WatchDogStm(const infra::Function<void()>& onExpired, const Config& config = Config());

void Interrupt();

Expand Down
Loading