41 lines
752 B
C++
41 lines
752 B
C++
/*
|
|
* PWM_Pin_STM32.cpp
|
|
*
|
|
* Created on: Feb 11, 2024
|
|
* Author: Gabriel
|
|
*/
|
|
|
|
#include "PWM_Pin_STM32.hpp"
|
|
|
|
PWM_Pin_STM32::PWM_Pin_STM32(TIM_HandleTypeDef* hTim, uint32_t channel) :
|
|
hTim(hTim), channel(channel){
|
|
|
|
}
|
|
|
|
PWM_Pin_STM32::~PWM_Pin_STM32() {
|
|
|
|
}
|
|
|
|
int32_t PWM_Pin_STM32::init() {
|
|
if(HAL_TIM_PWM_Start(hTim, channel) == HAL_OK){
|
|
return 0;
|
|
}else{
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
int32_t PWM_Pin_STM32::setDuty(float dutyCycle) {
|
|
if(dutyCycle<0 || dutyCycle>1){
|
|
// Invalid parameter
|
|
return -1;
|
|
}
|
|
uint32_t ccr = dutyCycle*__HAL_TIM_GET_AUTORELOAD(hTim);
|
|
__HAL_TIM_SET_COMPARE(hTim, channel, ccr);
|
|
return 0;
|
|
}
|
|
|
|
int32_t PWM_Pin_STM32::setFreq(float freq) {
|
|
// TODO Implement this function
|
|
return -2;
|
|
}
|