#include "led.h"
#include "bsp.h"

static u16 timer_on = 0,timer_off = 0;
static u16 nCnt = 0;
static u8 nNum = 0;

void LED_Init(void)//IO初始化
{
	GPIO_InitTypeDef GPIO_InitStructure;

	RCC_APB2PeriphClockCmd(RCC_HTTP_LED|RCC_APB2Periph_AFIO,ENABLE);

	GPIO_InitStructure.GPIO_Pin = PIN_HTTP_LED;//端口配置
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//IO口速度为50MHz
	GPIO_Init(PORT_HTTP_LED, &GPIO_InitStructure);//根据设定参数初始化
}

//用户调用函数(次数,开时间,关时间)单位10mS,其中num=0xff为连续模式 SetLed(0xff,18,18);
void SetLed(u8 num,u16 on_time,u16 off_time)     
{
	nNum = num;
	timer_on = on_time;
	timer_off = off_time;
	HTTP_LED = 0;
	nCnt = 0;
}

void Led_10mS_Conut(void)//定期器10mS调度任务
{
	if(nCnt)
	{
		nCnt--;
		if(nCnt == timer_off)
			HTTP_LED = 0;
	}
	else
	{
		if(nNum == 0XFF)
		{
			HTTP_LED = 1;
			nCnt = timer_on + timer_off;
		}
		else if(nNum)
		{
			HTTP_LED = 1;
			nNum --;
			nCnt = timer_on + timer_off;
		}
	}
}
