
#include "ccm_drv.h"
#include "pwm_drv.h"
#include "pwm_func.h"

void Backlight_Init(void)
{
	//PWM_Csr:0=1/2 ,1=1/4 ,2=1/8 ,3=1/16  ,others=1
	//PWMoutput=75Mhz/(PWM_Prescaler+1)/(PWM_Csr)/(PWM_Period+1)
	
	//PWM_OutputInit(PWM_PORT3,4,PWM_CLK_DIV_1,99,0,0);    // 74=2k  24=6k   14=10k   4=30k, duty=0
	PWM_Init(PWM,PWM_PORT3,1000,80,0);	//Freq=1000, Duty cycle=80, polaity= Nagative for BL 
	CCM->PCFG3 |= (7<<0);
}

//±³¹âÁÁ¶È

void Backlight_Adjust(u8 brightness)
{
	//PWM->PWM_CMR3 = brightness;								//high leve = duty+1
	if (brightness>100) brightness=100;
	PWM_AdjustDutyCycle(PWM,PWM_PORT3,brightness);
}

void Backlight_Enable(bool state)
{
	if (state) CCM->PCFG3 |= (7<<0);
	else CCM->PCFG3 &= ~(7<<0);	
}
