/******************************************************************************
文 件 名：Line_In.c
功能描述：线路输入信号处理函数头文件
作    者：张暄
版    本：V1.1
日    期：2016.11.4
******************************************************************************/
/******************************************************************************

                           线路输入IO管脚名称定义

-------------------------------------------------------------------------------
注意：在GPIO.h中定义线路输入对应的IO管脚时，必须使用下表中列出的名称
-------------------------------------------------------------------------------
    线路输入IO管脚名称     | 有效电平  |      功能
-------------------------------------------------------------------------------
LINE_IN_KEY0               |  高电平   | 按键0输入
LINE_IN_KEY0n              |  低电平   |
LINE_IN_KEY1               |  高电平   | 按键1输入
LINE_IN_KEY1n              |  低电平   |
LINE_IN_KEY2               |  高电平   | 按键2输入
LINE_IN_KEY2n              |  低电平   |
-------------------------------------------------------------------------------
******************************************************************************/

/******************************************************************************

                                信号名称列表

------------------------------------------------------------------------------
说明：1.信号名称的命名规则为 <线路输入IO管脚名称>_SIGNAL .移植程序时应严格按上
        表中的管脚名称命名对应线路输入的IO端口, 则该线路输入所对应的信号自动变
        为可用
      2.不同车型有不同的线路输入信号,因此并非下面列表中所有信号都是可用的.应将
        可用的信号名称标注于下表中,便于查找
      3.当Line_In_Debounce_Service服务被以20ms周期调用后, 以下列表中各可用信号
        会状态跟随外部线路输入变化而变化,这些信号的作用域是整个工程,可在工程中
        的任意文件中自由调用
      4.这些信号表示线路输入的逻辑状态,即 无效(0值) 和 有效(非0值) ,并非线路的
        电平高低
------------------------------------------------------------------------------
  当前可用  |      信号名称                  |       功能
------------------------------------------------------------------------------
            | LINE_IN_EPB_SIGNAL             | 电子驻车状态
            | LINE_IN_ESPOFF_SIGNAL          | ESP关闭状态
      *     | LINE_IN_KEY0_SIGNAL            | 按键0状态(Timer按键)
      *     | LINE_IN_KEY1_SIGNAL            | 按键1状态(Reset按键)
      *     | LINE_IN_KEY2_SIGNAL            | 按键2状态(Trip 按键)
-------------------------------------------------------------------------------
******************************************************************************/
#ifndef _LINE_IN_H_
#define _LINE_IN_H_

#include "GPIO.h"
#include "Analog_Signal_Conversion.h"
/******************************************************************************
按键消抖时间定义
******************************************************************************/
#define   LINE_IN_DEBOUNCE_TIME             500
#define   LINE_TIME                         200
#define   LINE_IN_DEBOUNCE_L_TIME           200     //2021.01.29由80改为200
/******************************************************************************
结构体定义
******************************************************************************/
typedef struct
{
  uint8_t   Current;
  uint8_t   Last;
  uint16_t  Timer;
}LineInDebounceStruct;

/******************************************************************************
信号预处理
******************************************************************************/
#define   LINE_IN_DEBOUNCE_L_CNT           (LINE_IN_DEBOUNCE_L_TIME / 20)
#define   LINE_IN_DEBOUNCE_CNT             (LINE_IN_DEBOUNCE_TIME / 20)
#define   LINE_TIME_CNT                    (LINE_TIME / 20)

/******************************************************************************
按键消抖周期
******************************************************************************/
#define   LINE_IN_DEBOUNCE_CYCLE            20    //消抖服务函数调用周期,单位ms

 /***Key***/
 
extern volatile uint8_t    KeyLeftinStatus; 
#define    KEY_LEFT_IN     KeyLeftinStatus

#if  ((defined  KEY_LEFT_IN) || (defined KEY_LEFT_INn))
                                                                    
  extern volatile uint8_t    KeyLeftStatus;

  #define    KEY_LEFT_SIGNAL            KeyLeftStatus
  #define    KEY_LEFT_DEFAULT           0
  #define    KEY_DEB_RISE 80    //上升沿消抖时间(ms)
  #define    KEY_DEB_FALL 80    //下降沿消抖时间(ms)
#endif

extern volatile uint8_t    KeyRightinStatus; 
#define    KEY_RIGHT_IN    KeyRightinStatus

#if  ((defined  KEY_RIGHT_IN) || (defined KEY_RIGHT_INn))
                                                                    
  extern volatile uint8_t    KeyRightStatus;

  #define    KEY_RIGHT_SIGNAL            KeyRightStatus
  #define    KEY_RIGHT_DEFAULT           0
#endif

extern volatile uint8_t    KeyEnterinStatus; 
#define    KEY_ENTER_IN    KeyEnterinStatus

#if  ((defined  KEY_ENTER_IN) || (defined KEY_ENTER_INn))
                                                                    
  extern volatile uint8_t    KeyEnterStatus;

  #define    KEY_ENTER_SIGNAL            KeyEnterStatus
  #define    KEY_ENTER_DEFAULT           0
#endif

/***LED_SEATBELT_R ***/    //主安全带
#if  ((defined  LINE_IN_SEATBELT) || (defined LINE_IN_SEATBELTn))  		   

  extern volatile uint8_t    LineInSEATBELTStatus;

  #define    LINE_IN_SEATBELT_SIGNAL     LineInSEATBELTStatus
  #define    LINE_IN_SEATBELT_DEFAULT    0
#endif

/***LED_POSITION_G ***/
#if  ((defined  LINE_IN_POSITION) || (defined LINE_IN_POSITIONn))  		   

  extern volatile uint8_t    LineInPOSITIONStatus;

  #define    LINE_IN_POSITION_SIGNAL     LineInPOSITIONStatus
  #define    LINE_IN_POSITION_DEFAULT    0
#endif

////////////////////////////////////////////////////////////////////////
/***LED_MIL_Y ***/
#if  ((defined  LINE_IN_MIL) || (defined LINE_IN_MILn))  	   

  extern volatile uint8_t    LineInMILStatus;

  #define    LINE_IN_MIL_SIGNAL          LineInMILStatus
  #define    LINE_IN_MIL_DEFAULT         0
#endif

/***PTO ***/
#if  ((defined  LINE_IN_PTO) || (defined LINE_IN_PTOn))      

  extern volatile uint8_t    LineInPTOStatus;
 
  #define    LINE_IN_PTO_SIGNAL          LineInPTOStatus
  #define    LINE_IN_PTO_DEFAULT         0  
#endif

/*** LINE_IN_BREAK_FLUID_SIGNAL ***/        
#if  ((defined LINE_IN_BREAK_FLUID) || (defined LINE_IN_BREAK_FLUIDn))  

  extern volatile uint8_t   LineInBREAKFLUIDStatus;
  
  #define    LINE_IN_BREAK_FLUID_SIGNAL  LineInBREAKFLUIDStatus
  #define    LINE_IN_BREAK_FLUID_DEFAULT 0
#endif

/*** LINE_IN_BREAK_SIGNAL ***/         
#if  ((defined LINE_IN_BREAK) || (defined LINE_IN_BREAKn))  

  extern volatile uint8_t   LineInBREAKStatus;
  
  #define    LINE_IN_BREAK_SIGNAL        LineInBREAKStatus
  #define    LINE_IN_BREAK_DEFAULT       0
#endif

/*** LINE_IN_RF_HOOVES_SIGNAL ***/         
#if  ((defined LINE_IN_RF_HOOVES) || (defined LINE_IN_RF_HOOVESn))  

  extern volatile uint8_t   LineInRFHOOVESStatus;
  
  #define    LINE_IN_RF_HOOVES_SIGNAL    LineInRFHOOVESStatus
  #define    LINE_IN_RF_HOOVES_DEFAULT   0
#endif

/*** LINE_IN_RR_HOOVES_SIGNAL ***/         
#if  ((defined LINE_IN_RR_HOOVES) || (defined LINE_IN_RR_HOOVESn))  

  extern volatile uint8_t   LineInRRHOOVESStatus;
  
  #define    LINE_IN_RR_HOOVES_SIGNAL    LineInRRHOOVESStatus
  #define    LINE_IN_RR_HOOVES_DEFAULT   0
#endif

/*** LINE_IN_CAB_LOCK_SIGNAL ***/         
#if  ((defined LINE_IN_CAB_LOCK) || (defined LINE_IN_CAB_LOCKn))  

  extern volatile uint8_t   LineInCABLOCKStatus;
  
  #define    LINE_IN_CAB_LOCK_SIGNAL     LineInCABLOCKStatus
  #define    LINE_IN_CAB_LOCK_DEFAULT    0
#endif

/*** LINE_IN_FILT_BLOCK_SIGNAL ***/         
#if  ((defined LINE_IN_FILT_BLOCK) || (defined LINE_IN_FILT_BLOCKn))  

  extern volatile uint8_t   LineInFILTBLOCKStatus;
  
  #define    LINE_IN_FILT_BLOCK_SIGNAL   LineInFILTBLOCKStatus
  #define    LINE_IN_FILT_BLOCK_DEFAULT  0
#endif

/*** LINE_IN_CHARGE_SIGNAL ***/         
#if  ((defined LINE_IN_CHARGE) || (defined LINE_IN_CHARGEn))  

  extern volatile uint8_t   LineInCHARGEStatus;
  
  #define    LINE_IN_CHARGE_SIGNAL       LineInCHARGEStatus
  #define    LINE_IN_CHARGE_DEFAULT      0
#endif

/*** LINE_IN_GEAR_SIGNAL ***/        
#if  ((defined LINE_IN_GEAR) || (defined LINE_IN_GEARn))  

  extern volatile uint8_t   LineInGEARStatus;
  
  #define    LINE_IN_GEAR_SIGNAL         LineInGEARStatus
  #define    LINE_IN_GEAR_DEFAULT        0
#endif
/******************************************************************************
函数声明
******************************************************************************/
void    Line_In_Enable(uint8_t Enable);
void    Line_In_Status_Reset(void);
void    Line_In_Debounce_Service(void);          //必须每20ms调用一次

#endif