#ifndef __YX5200_UAET2_H
#define __YX5200_UAET2_H
#include "main.h"
#include "YX5200_MSG.h"

#define YX5200_MSGLEN	(10)
#define MAX_MAIN_VOL      30   //最大音量

#define QUERYACKTIME      20
#define SYSRETURNTIME     20

/************************************************************************
          LED灯 --- 播放指示灯
*************************************************************************/
#define PLAYLEDCNT          6      //按键有效灯的闪烁时间
#define PLAYLED_ON		    //led = 0
#define PLAYLED_OFF		    //led = 1
#define PLAYLED_FLASH	    //led ^= 1

extern uint8_t TxBufferUart2[];
extern uint8_t RxBufferUart2[];
extern __IO uint8_t TxCounterUart2;
extern __IO uint8_t RxCounterUart2;
extern uint8_t Uart2SendCount;

extern uint8_t YX5200HaveRecFlag;

extern void Configuration_YX5200_Usart2 ( void );
extern void NVIC_Configuration_YX5200_USART2 ( void );
extern void Uart2Send ( char *buffe2r, int nBytes );

extern void Let_One_Music_play ( u8 fold, u16 file );
extern void Random_play_music ( u8 num );
/********************************************************************/
#define bit  u8
#define INT8U  u8
#define INT16U u16


/************************常用函数的声明*************************/
#define BIT(n)		(1L << (n))


#define  DIR_IN   0xff
#define  DIR_OUT  0x00
#define  HIGH2LOW(Uc_Data)   (((Uc_Data&BIT(7))>>7)|((Uc_Data&BIT(6))>>5)|((Uc_Data&BIT(5))>>3)|((Uc_Data&BIT(4))>>1)|((Uc_Data&BIT(3))<<1)|((Uc_Data&BIT(2))<<3)|((Uc_Data&BIT(1))<<5)|((Uc_Data&BIT(0))<<7))
#define  DATA_X_MIRROR(Uc_Data)(((Uc_Data&BIT(0))>>0)|((Uc_Data&BIT(1))<<4)|((Uc_Data&BIT(2))<<2)|((Uc_Data&BIT(3))>>0)|((Uc_Data&BIT(4))>>2)|((Uc_Data&BIT(5))>>4)|((Uc_Data&BIT(6))<<0))

typedef struct aa
{
    INT8U a: 1 ;
    INT8U b: 1 ;
    INT8U c: 1 ;
    INT8U d: 1 ;
    INT8U e: 1 ;
    INT8U f: 1 ;
    INT8U g: 1 ;
    INT8U h: 1 ;
} cc ;

extern cc Status0 , Status1 , Status2, Status3;
extern INT8U bcd_number[5];

#define System_Flag_Prin_Time_Temp	Status3.a
#define System_Flag_Prin_Music      Status3.b
#define System_Flag_Music_NormKey	Status3.c
#define System_Flag_Music_ShortKey  Status3.d

#define System_Flag_2Ms	        Status2.a
#define System_Flag_10Ms        Status2.b
#define System_Flag_100Ms       Status2.c
#define System_Flag_200Ms       Status2.d
#define System_Flag_500Ms	    Status2.e
#define System_Flag_1s        	Status2.f
#define System_Flag_8s       	Status2.g
#define System_Flag_20s       	Status2.h


//#define System_Flag_2Ms	        Status0.a
//#define System_Flag_10Ms        Status0.b
//#define System_Flag_100Ms       Status0.c
//#define System_Flag_500Ms       Status0.d
#define RecvOver_Flag		    Status0.e
#define Resend_Flag             Status0.f //重发标志位
#define Resend_Flag_Enable      Status0.g //重发功能标志位
#define RecvError_Flag          Status0.h


#define Busy_Flag               Status1.a
#define RecvBusy_Flag           Status1.b
#define Resend_Enable_Flag      Status1.c
#define TrigEnable              Status1.d
#define MainEnable              Status1.e
#define PointFolNum_Flag        Status1.f
#define PlayAllFlag             Status1.g

enum
{
    SYS_STATUS_IDLE = 0,
    SYS_STATUS_INIT ,
    SYS_STATUS_WORK ,
    SYS_STATUS_SLEEP ,
} ;

enum//
{
    EQ_NORMAL = 0,
    EQ_POP,
    EQ_ROCK,
    EQ_JAZZ,
    EQ_CLASSIC,
    EQ_BASS,
};

enum
{
    REPEAT_ALL = 0,
    REPEAT_FOLDER,
    REPEAT_ONE,
    REPEAT_RANDOM,
    MAX_PLAY_MODE,
} ;

enum
{
    PLAYDEVICE_NULL = 0 ,
    PLAYDEVICE_UDISK = 1,
    PLAYDEVICE_TFCARD ,
    PLAYDEVICE_PC ,
    PLAYDEVICE_FLASH ,
    PLAYDEVICE_SLEEP,
    PLAYDEVICE_MAX ,
} ;

enum
{
    ONLINE_NULL  = 0 ,
    ONLINE_UDIDK = 0x01 ,
    ONLINE_TFCARD = 0x02 ,
    ONLINE_PC    = 0x04 ,
    ONLINE_FLASH = 0x08 ,
} ;

enum
{
    POINTNUM_NULL = 0 ,
    POINTNUM_ONE ,//指定单曲播放
    POINTNUM_LOOP ,//指定单曲循环播放
    POINTNUM_FOLDER ,//指定文件播放
    POINTNUM_MAX ,
} ;

enum
{
    _UDISK = 0 ,
    _TFCARD ,
    _PC ,
    _FLASH ,
} ;

//按键门槛值

#define KEY_BASE_CNT  4
#define KEY_LONG_CNT  75
#define KEY_HOLD_CNT  15


enum
{
    KEY_SHORT_UP ,
    KEY_LONG ,
    KEY_HOLD ,
    KEY_LONG_UP ,
} ;


#define NO_KEY          0xff


enum
{
    KEY_NULL  = 0 ,
    KEY_VALUE1 = 1 ,
    KEY_VALUE2 = 2 ,
    KEY_VALUE3 = 3 ,
    KEY_VALUE4 = 4 ,
    KEY_VALUE5 = 5 ,
    KEY_VALUE6 = 6
} ;

enum
{
    SET_PLAYLED_NONE,
    SET_PLAYLED_ON,
    SET_PLAYLED_OFF,
    SET_PLAYLED_100MS_FLASH,
    SET_PLAYLED_500MS_FLASH,
    SET_PLAYLED_900MS_ON_100MS_OFF,
    SET_PLAYLED_100MS_ON_900MS_OFF,
};

enum
{
    ERROR_IDLE = 0 ,
    ERROR_Busy ,//返回忙
    ERROR_SLEEP ,
    ERROR_RecvError ,//返回串口接收错误
    ERROR_CheckSError ,//返回校验出错
    ERROR_FolPointOver ,//返回指定文件输入错误[数据超范围]
    ERROR_FolPointNo ,//未找到指定的文件
};




/************************* 对 外 的 变 量 **************************/
extern INT8U UartRecvStatus ;
extern INT8U PlayledStatus;
extern INT8U UartRecv_100Ms ;
extern INT16U UartRecvACK ;
extern bool UartRecvACKFlag;

extern INT8U System_Status ;
extern INT8U FEEDBACK ;//是否需要反馈[=1:要应答][=0:不要应答]
extern INT8U OutTimeCnt ;
extern INT8U ResendCount ;//重发次数
extern INT8U PlayledCnt ;//测试led点亮的时间
extern INT8U CurrentEQ ;//当前的EQ
extern INT8U PlayMode  ;//当前的播放模式
extern INT8U input_vol ;//当前的音量
extern INT8U PlayDevice ;//当前播放的设备
extern INT8U OnlineDevice ;//检测到模块在线的设备
extern INT8U CurrentModule ;//当前的模块型号
extern INT8U SysReturnTime  ;
extern INT8U QueryACKTime ;//等待应答计时
extern INT8U DelayTime ;
extern INT8U _ErrorStatus ;
extern INT8U PointFunc ;

extern INT16U input_number ;
extern INT16U CurDevTotal ;
extern INT16U TFTotal ;
extern INT16U UDiskTotal ;
extern INT16U FlashTotal ;

extern INT16U CurDevNUM ;
extern INT16U UDiskCurFile  ;
extern INT16U TFCurFile ;
extern INT16U FlashCurFile ;

extern INT16U input_cur_fold;
extern INT16U CurFileNum;//当前文件数目
extern INT16U CurFoldNum;//当前文件夹数目

extern void put_msg_lifo ( INT8U msg );
extern INT8U app_get_msg ( void );


/************************* 对 外 的 接 口 **************************/

void Time_Task ( void ) ;
void key_scan ( void );
void Key_Task ( void ) ;
void Indicator_Scan ( void );
void MSG_Task ( void );
//void put_msg_lifo(INT8U msg);
//INT8U app_get_msg(void);




#endif


