#include "bsp_buzzer.h"

#include <main.h>
#include <tim.h>



int8_t BSP_Buzzer_Start(void) {
  if (HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3) == HAL_OK) return BSP_OK;
  return BSP_ERR;
}

int8_t BSP_Buzzer_Set(float freq, float duty_cycle) {
  uint16_t pulse = duty_cycle;
  __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_3, pulse);

  pulse = (uint16_t)freq;
  __HAL_TIM_PRESCALER(&htim4, pulse);
  return BSP_OK;
}

int8_t BSP_Buzzer_Stop(void) {
  if (HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_3) == HAL_OK) return BSP_OK;
  return BSP_ERR;
}
