From 6fc5a8bcb6b85c25d376b467f10b6cd4861917d9 Mon Sep 17 00:00:00 2001 From: Emilio <emilio.corigliano@skywarder.eu> Date: Thu, 8 Jun 2023 11:58:06 +0200 Subject: [PATCH] [TimerUtils] Added `masterModeFromChannel` method --- src/shared/drivers/timer/TimerUtils.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/shared/drivers/timer/TimerUtils.h b/src/shared/drivers/timer/TimerUtils.h index 16693ece4..106c7fbd4 100644 --- a/src/shared/drivers/timer/TimerUtils.h +++ b/src/shared/drivers/timer/TimerUtils.h @@ -24,6 +24,8 @@ #include <utils/ClockUtils.h> +#include <cassert> + namespace Boardcore { @@ -358,6 +360,11 @@ float getMaxDuration(TIM_TypeDef *timer); */ uint16_t computePrescalerValue(TIM_TypeDef *timer, int targetFrequency); +/** + * @brief Returns the corresponding master for for the given channel. + */ +MasterMode masterModeFromChannel(const Channel channel); + } // namespace TimerUtils inline ClockUtils::APB TimerUtils::getTimerInputClock(const TIM_TypeDef *timer) @@ -446,4 +453,23 @@ inline uint16_t TimerUtils::computePrescalerValue(TIM_TypeDef *timer, return targetPrescaler >= 0 ? targetPrescaler : 0; } +inline TimerUtils::MasterMode TimerUtils::masterModeFromChannel( + const Channel channel) +{ + switch (channel) + { + case Channel::CHANNEL_1: + return MasterMode::OC1REF_OUTPUT; + case Channel::CHANNEL_2: + return MasterMode::OC2REF_OUTPUT; + case Channel::CHANNEL_3: + return MasterMode::OC3REF_OUTPUT; + case Channel::CHANNEL_4: + return MasterMode::OC4REF_OUTPUT; + default: + assert(false && "Invalid channel!"); + return MasterMode::RESET; + } +} + } // namespace Boardcore -- GitLab