
#ifndef _CD4051BPWR_H_
#define _CD4051BPWR_H_

#include "r_typedefs.h"

typedef struct
{
 
    uint8_t PIN_X0:1; //X0引脚状态
    uint8_t PIN_X1:1;
    uint8_t PIN_X2:1;
    uint8_t PIN_X3:1;
    uint8_t PIN_X4:1;
    uint8_t PIN_X5:1;
    uint8_t PIN_X6:1;
    uint8_t PIN_X7:1;

} NLHV4051Type_st_t;

typedef struct
{
	/* uint8_t u8Enable;     硬线是否使能*/
	uint8_t  u8Status;		  /*硬线最后输出状态*/
	uint16_t u16TimeCount;  /*消抖计时变量*/
	uint8_t  u8PinInput;	  /*实际硬线输入引脚*/
	uint8_t  u8PinInputLast; /*实际硬线输入引脚记忆的上一次状态*/
} LineInControl;

typedef struct
{
	//    uint8_t *u8PinInput;    /*指向实际硬线输入引脚*/
	uint8_t  u8ValidLevel;	   /*有效电平*/
	uint16_t u16ValidTime;   /*从无效到有效的消抖时间 ms*/
	uint16_t u16InvalidTime; /*从有效到无效的消抖时间*/
	uint8_t  u8PowerStatus;   /*电源状态,暂定1表示IGNON,0表示ignoff，2都工作*/

} LineInAttribute_st_t;



/*所有硬线输入的索引*/
typedef enum
{
	Low_significant_3_N,        //低有效3_N
  Low_significant_2_N,        //低有效2_N
  Low_valid_1_N,              //低有效1_N
  Install_lift_N,             //上装举升报警_N
  ECAS_lifting_shaft_N,       //ECAS提升轴指示_N
  The_lamp_faulty_N,          //灯具故障_N
  Gas_leak_N,                 //燃气泄漏报警_N
  Parking_brake_N,            //驻车制动_N
  
  Battery_charging_N,         //蓄电池充电指示_N
  Brake_shoe_wear_N,          //刹车蹄片磨损报警_N
  Oil_water_separation_N,     //油水分离警报_N
  ASR_indicates_N,            //ASR指示_N
  Shaft_differential_lock_N,  //轴间差速锁指示_N
  Trailer_Brake_shoe_wear_N,  //挂车刹车蹄片磨损报警_N
  ABS_trailer_fault_N,        //ABS挂车故障警报_N
  VCU_fault_alert_N,          //VCU故障警报_N

  Engine_warm_up_N,           //发动机预热指示_N
  Engine_failure,             //发动机故障警报_N
  OBD_emission_failure_N,     //OBD排放故障_N
  Seat_belt_fastened,         //安全带未系警报_N
  Wheel_differential_lock_N,  //轮间差速锁指示_N
  Force_retractor_working_N,  //取力器工作指示_N
  Air_filter_blocked_N,       //空气滤清器堵塞警报_N
  Cab_rollover_N,             //驾驶室翻转警报_N

  Highly_significant_2_P,     //高有效2_P
  Engine_failure_P,           //发动机故障警报_P
  High_effective_1_P,         //高有效1_P
  Gas_leak_P,                 //燃气泄漏报警_P
  High_effective_3_P,         //高有效3_P
  Transmission_failure_P,     //变速箱故障警报_P
  Highly_significant_4_P,     //高有效4_P

  Turn_left_P,                //左转向指示_P
  Trailer_right_turn_P,       //挂车右转向指示_P
  Trailer_left_turn_P,        //挂车左转向指示_P
  Turn_right_P,               //右转向指示_P
  The_high_beam_P,            //远光灯指示_P
  Instrument_lighting_P,      //仪表照明信号_P

	LINE_IN_MAX,
} LineInChannel;

extern NLHV4051Type_st_t g_stNLHV4051Chip1;
extern NLHV4051Type_st_t g_stNLHV4051Chip2;
extern NLHV4051Type_st_t g_stNLHV4051Chip3;
extern NLHV4051Type_st_t g_stNLHV4051Chip4;
extern NLHV4051Type_st_t g_stNLHV4051Chip5;

extern void CD4051_KL30_Init(void);
extern void CD4051_Check_Service(void);
extern void CD4051_Wakeup_Init(void);
extern void CD4051_Sleep_Init(void);
//推荐值10ms
extern void CD4051_In_Debounce_Service(void);
/*1表示硬线有效，0硬线无效*/
extern uint8_t Line_In_Get_Status(LineInChannel Channel);
extern void Line_In_KL30_Init(void);
extern void Line_In_KL15_ON_Init(void);
extern void Line_In_KL15_OFF_Init(void);
extern void Line_In_Wakeup_Init(void);
extern void Line_In_Sleep_Init(void);

#endif
