/***********************************************************************
 * Copyright (c)  2017 - 2022, Unicmicro Co.,Ltd .
 * All rights reserved.
 * Filename    : atim_pwmout.c
 * Description : atim_pwmout source file
 * Author(s)   : Hackett
 * version     : V1.0
 * Modify date : 2022-07-10
 ***********************************************************************/
#include  "atim_pwmout.h"
#include  "uart0.h"
#include  "uart1.h"
#include  "uart2.h"
#include  "atimer.h"
#include  "gpio.h"

/************************************************************************
 * function   : atimer_pwmout_pro
 * Description: atimer_pwmout_pro atimer处理回调函数
 * input : none
 * return: none
 ************************************************************************/
void atimer_pwmout_pro(void)
{	
	if(atimer_get_status(ATIM_STATUS_BIF))
	{
		printfS("Brake!!! \r\n");//开启刹车功能时打开	
	}		
}


/************************************************************************
 * function   : atimer_pwmout_test
 * Description: PWM输出
 * input : none
 * return: none
 ************************************************************************/
void atimer_pwmout_test(void)
{
	printfS("start atimer pwmout test! \r\n");
	
	gpio_init(GPIOF, PIN0, 7);		//PF0 ATIM_CH1
	gpio_init(GPIOG, PIN3, 13);		//PG3 ATIM_CH1N（互补通道）
	gpio_init(GPIOG, PIN0, 12);		//PG0 ATIM_ETR（外部触发）
	atimer_module_enable();			//使能时钟并复位定时器模块
	atimer_pwm_init(48000, 1, ATIM_PWMOUTPUT, ATIM_CHANNEL1);
	atimer_counter(ATIM_ENABLE);		//计数器使能
	atimer_irq(ATIM_UIE, ATIMER_IRQn, ATIM_DISABLE, atimer_pwmout_pro);//允许更新事件中断,开启中断(pwm输出频率较高不开中断)

	atimer_set_compare(ATIM_CHANNEL1, (48000 / 2));//通道1的输出比较值

}



