#include "uksi_dc_control.h"

HAL_StatusTypeDef DC_Init(UKSI_DC_t *dc, TIM_HandleTypeDef *htim, uint32_t activemode, uint32_t inactivemode)
{
  if(check_null_ptr_2(dc, htim))
    return HAL_ERROR;
  
  dc->htim = htim;
  dc->ActiveMode = activemode;
  dc->InactiveMode = inactivemode;
  
  HAL_TIMEx_OCN_Start(htim, TIM_CHANNEL_1);
  return HAL_TIM_OC_Start(htim, TIM_CHANNEL_1);
}


HAL_StatusTypeDef DC_Enable(UKSI_DC_t *dc, uint8_t state)
{
  if(check_null_ptr_1(dc))
    return HAL_ERROR;
  
  dc->htim->Instance->CCMR1 &= ~TIM_OCMODE_PWM2;
  if(state)
  {
    dc->htim->Instance->CCMR1 |= dc->ActiveMode;  
  }
  else
  {
    dc->htim->Instance->CCMR1 |= dc->InactiveMode;  
  }
  
  return HAL_OK;
}