#include "tim.h"
#include "TestTimer.h"

#define MAX 31250-1
#define MOY MAX/2
#define MIN 0x0


void testTim(){
	TIM_OC_InitTypeDef sConfigOC = {0};
	sConfigOC.Pulse = MAX;
	HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC,TIM_CHANNEL_1);
	sConfigOC.Pulse = MIN;
	HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC,TIM_CHANNEL_2);
	sConfigOC.Pulse = MOY;
	HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC,TIM_CHANNEL_3);

	HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
	HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);
	HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3);
}

void testLed(){
	TIM_OC_InitTypeDef sConfigOC = {0};

	for(int i =MIN;i<MAX;i++){
		sConfigOC.Pulse = i;
		HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC,TIM_CHANNEL_2);
		HAL_Delay(10);
	}
}

void user_pwm_setvalue(uint16_t value)
{
    TIM_OC_InitTypeDef sConfigOC;

    sConfigOC.OCMode = TIM_OCMODE_PWM1;
    sConfigOC.Pulse = value;
    sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
    sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
    HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_1);
    HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_1);
}



/* USER CODE BEGIN 2
  HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_1);
/* USER CODE END 2 */

/* Infinite loop */
/* USER CODE BEGIN WHILE
while (1)
{
/* USER CODE END WHILE */

/* USER CODE BEGIN 3
  HAL_Delay(100);
  if(pwm_value == 0) step = 100;
  if(pwm_value == 2000) step = -100;
  pwm_value += step;
  user_pwm_setvalue(pwm_value);
}
/* USER CODE END 3 */
