-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add pwmoutput and analogoutput to stm32f767 mcal
- Loading branch information
Tamara Xu
committed
Oct 14, 2024
1 parent
ba75eec
commit 5a885f1
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/// @author Tamara Xu | ||
/// @date 2024-10-13 | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
#include "shared/periph/analog_output.h" | ||
#include "shared/util/mappers/clamper.h" | ||
#include "stm32f7xx_hal.h" | ||
|
||
namespace mcal::stm32f767::periph { | ||
|
||
class AnalogOutput : public shared::periph::AnalogOutput { | ||
public: | ||
AnalogOutput(TIM_HandleTypeDef* htim, uint32_t channel) | ||
: htim_(htim), channel_(channel) {} | ||
|
||
void SetVoltage (float voltage) override { | ||
voltage_ = shared::util::Clamper<float>::Evaluate(voltage, 0, 3.3); | ||
uint32_t pulse = (voltage_ * float(__HAL_TIM_GetAutoreload(htim_))) / | ||
(3.3 * 100.0f); | ||
|
||
__HAL_TIM_SetCompare(htim_, channel_, pulse); | ||
} | ||
|
||
private: | ||
TIM_HandleTypeDef* htim_; | ||
uint32_t channel_; | ||
float voltage_; | ||
}; | ||
|
||
} // namespace mcal::stm32f767::periph |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters