//背光调节
#ifndef _BackLight_H_
#define _BackLight_H_

#include "GPIO.h"
#include "PWM.h"
//#include "TIMER0.h"
#include "Warning_Processor.h"
#include "Popup_Scheduler.h"
#include "Startup_Animation.h"
#include "IPC.h"
#include "GPIO.h"
#include "main.h"
#include "Menus.h"
/******************************************************************************
全局变量
******************************************************************************/
//extern volatile uint8_t BLPWMDutyCycle;
//#define   BL_PWM_DUTY_CYCLE                 dutyCycle

/******************************************************************************
背光设置
******************************************************************************/
#define   BL_PWM_DUTY_CYCLE_FILTER          5    //接收到的占空比差大于此值认为是无效占空比
#define   BL_PWM_FILTER_MAX_CNT             10   //最大阻止接收次数
#define   BL_SAMPLE_POINT                   10   //10
#define   BL_PWM_DUTY_CYCLE_MAX             95
#define   BL_PWM_DUTY_CYCLE_MIN             7
#define   BL_PWM_DUTY_CYCLE_HYSTERESIS      5    //回差
#define   BL_PWM_DUTY_CYCLE_APPR_FACTOR     8    //占空比逼近系数 
#define   BL_PWM_DUTY_CYCLE_APPR_SPEED      20   //占空比逼近周期,单位ms  

#define   BL_OFF_TIME_DOOR_OPEN_ONLY        150

/******************************************************************************
结构声明
******************************************************************************/
typedef struct
{
  uint8_t   Backup;
  uint16_t  Timer;
  uint16_t  HiLvTimer;
} BlPWMCaptureStruct;

typedef struct
{
  uint8_t   InitTimer;
  uint8_t   Backup;
  uint8_t   BackupCnt;
  uint8_t   Sample[BL_SAMPLE_POINT];
  uint8_t   Ptr;
  uint8_t   Cnt;
  uint8_t   Locked;
  uint8_t   Timer;
  uint8_t   Current;
} BlPWMFilterStruct;

typedef struct
{
  uint8_t   DoorStatusBackup;
  uint16_t  Timer;
} BlOFFCtrlStruct;
/*************************函数*********************************/
void BackLight_Plate_Needle_Set(uint8_t duty);
void BackLight_Plate_Needle_Close(void);
void BackLight_TFT_Set(uint8_t duty);
void BackLight_TFT_Close(void);
void BL_Management_Service(void);
void PWM_INIT(void);
void BL_Init(void);
//void BL_PWM_Duty_Cycle_Capture_ISR(void);
#endif