#include "common_include.h"


en_port_gpio_level_t Can1Rx_IN;

en_port_gpio_level_t BUTTON_S30_IN;
en_port_gpio_level_t BUTTON_S15_IN;
en_port_gpio_level_t BUTTON_S30__IN;
en_port_gpio_level_t BUTTON_Luminosity_IN;
en_port_gpio_level_t BUTTON_Back_light_IN;
en_port_gpio_level_t BUTTON_AUTO_IN;
en_port_gpio_level_t BUTTON_EOL_IN;
en_port_gpio_level_t BUTTON_SPEED_UP_IN;
en_port_gpio_level_t BUTTON_SPEED_DOWN_IN;
en_port_gpio_level_t BUTTON_LED_IN;
en_port_gpio_level_t BUTTON_IOL_UP_IN;
en_port_gpio_level_t BUTTON_IOL_DOWN_IN;
en_port_gpio_level_t BUTTON_TFT_UP_IN;
en_port_gpio_level_t BUTTON_TFT_DOWN_IN;
en_port_gpio_level_t BUTTON_ELSE_IN;
en_port_gpio_level_t BUTTON_END_IN;

en_port_gpio_level_t BUTTON_S_IN;
en_port_gpio_level_t BUTTON_D_IN;
en_port_gpio_level_t BUTTON_N_IN;
en_port_gpio_level_t BUTTON_R_IN;
en_port_gpio_level_t BUTTON_P_IN;

en_port_gpio_level_t BUTTON_DEFOG_IN;
en_port_gpio_level_t BUTTON_HOODOPEN_IN;
en_port_gpio_level_t BUTTON_SEATBELT_IN;
en_port_gpio_level_t BUTTON_ALTL_IN;
en_port_gpio_level_t BUTTON_BREAKOIL_IN;
en_port_gpio_level_t BUTTON_BackLigth_IN;
en_port_gpio_level_t BUTTON_DETENT_IN;
en_port_gpio_level_t BUTTON_GND_Signal3_IN;
en_port_gpio_level_t BUTTON_EngRun_IN;   //  EngRunState_OUT-
void Api_GPIO_Init(void)
{

    stc_port_pin_config_t stc_IN_pin_config_UP =
    {
        .enOutputFunction      = PortOutputResourceGPIO,
        .enOutputDrive         = PortOutputDriveD,
        .enPullResistor        = PortPullResistorUp,
        .bInputEnable          = TRUE,
        .bNoiseFilterEnable    = TRUE,
        .enGpioDirection       = PortGpioInput,
        .enGpioInitOutputLevel = PortGpioLow,
    };
    //-----------------------IN---------------------------//
    stc_port_pin_config_t stc_IN_pin_config =
    {
        .enOutputFunction      = PortOutputResourceGPIO,
        .enOutputDrive         = PortOutputDriveD,
        .enPullResistor        = PortPullResistorNone,
        .bInputEnable          = TRUE,
        .bNoiseFilterEnable    = TRUE,
        .enGpioDirection       = PortGpioInput,
        .enGpioInitOutputLevel = PortGpioLow,
    };
    //��������
    Port_SetPinConfig(0, 24, &stc_IN_pin_config); //    SW 13
    Port_SetPinConfig(1, 26, &stc_IN_pin_config); //    SW 1
    Port_SetPinConfig(1, 27, &stc_IN_pin_config); //    SW 2
    Port_SetPinConfig(0, 5, &stc_IN_pin_config); //     SW 12
    Port_SetPinConfig(1, 30, &stc_IN_pin_config); //    SW 5
    Port_SetPinConfig(1, 28,  &stc_IN_pin_config); //   SW 3
    Port_SetPinConfig(1, 31,  &stc_IN_pin_config); //   SW 6
    Port_SetPinConfig(0, 9,  &stc_IN_pin_config); //    SW 7
    Port_SetPinConfig(0, 1,  &stc_IN_pin_config); //    SW 8
    Port_SetPinConfig(0, 2,  &stc_IN_pin_config); //    SW 9
    Port_SetPinConfig(0, 3,  &stc_IN_pin_config); //    SW 10
    Port_SetPinConfig(0, 4,  &stc_IN_pin_config); //    SW 11
    Port_SetPinConfig(1, 3, &stc_IN_pin_config); // 静态电流
    // Port_SetPinConfig(1, 7, &stc_IN_pin_config); //不知道什么功能连着5V电源
    
    Port_SetPinConfig(1, 10, &stc_IN_pin_config); // 左转向输出采AD
    
    Port_EnableInput();
    //-----------------------OUT---------------------------//
    
    stc_port_pin_config_t stc_OUT_pin_config =
    {
        .enOutputFunction      = PortOutputResourceGPIO,
        .enOutputDrive         = PortOutputDriveA,
        .enPullResistor        = PortPullResistorNone,
        .enInputLevel          = PortInputLevelCmosA,
        .bInputEnable          = FALSE,
        .bNoiseFilterEnable    = TRUE,
        .enGpioDirection       = PortGpioOutput,
        .enGpioInitOutputLevel = PortGpioLow,
    };
    
    
    
    Port_SetPinConfig(2, 6, &stc_OUT_pin_config);  //上移动键
    Port_SetPinConfig(2, 7, &stc_OUT_pin_config);  //下移动键
    Port_SetPinConfig(2, 8, &stc_OUT_pin_config);  //返回键
    Port_SetPinConfig(2, 20, &stc_OUT_pin_config); //复位按键
    Port_SetPinConfig(2, 21, &stc_OUT_pin_config); //双闪按键
    Port_SetPinConfig(2, 14, &stc_OUT_pin_config);  //按键+
    Port_SetPinConfig(2, 13, &stc_OUT_pin_config); //按键-

    Port_SetPinConfig(0, 30, &stc_OUT_pin_config);  //蓝牙指示灯
    Port_SetPinConfig(2, 0, &stc_OUT_pin_config);   //远光
    Port_SetPinConfig(2, 1, &stc_OUT_pin_config);   //近光
    Port_SetPinConfig(2, 29, &stc_OUT_pin_config); //右转
    Port_SetPinConfig(1, 24, &stc_OUT_pin_config); //ABS指示灯
    Port_SetPinConfig(1, 25, &stc_OUT_pin_config); //位置灯
    Port_SetPortPinLevel(2,0,PortGpioLow);

    
    Port_SetPinConfig(1, 18, &stc_OUT_pin_config); //蜂鸣器
    Port_SetPinConfig(1, 4, &stc_OUT_pin_config); //485EN
    Port_SetPortPinLevel(1, 4,PortGpioLow);
    // Port_SetPinConfig(1, 8, &stc_OUT_pin_config);  //I2C_SCL_OUT 
    // Port_SetPinConfig(1, 9, &stc_OUT_pin_config);  //I2C_SDA_OUT
    //IIC����
    Port_SetPinConfig(1, 19, &stc_OUT_pin_config); // VBAT~
    Port_SetPinConfig(1, 20, &stc_OUT_pin_config); // VBAT
    Port_SetPinConfig(1, 21, &stc_OUT_pin_config); //DC12V
    Port_SetPinConfig(1, 15, &stc_OUT_pin_config); // ACC1

    

    Port_SetPinConfig(2, 12, &stc_OUT_pin_config); //��λ6
    Port_SetPinConfig(2, 27, &stc_OUT_pin_config); //��λ5

    //Port_SetPinConfig(1, 17, &stc_OUT_pin_config); //P_Speed_OUT-
//    Port_SetPinConfig(1, 6, &stc_OUT_pin_config); // 
//    Port_SetPinConfig(1, 7, &stc_OUT_pin_config); // 
//    Port_SetPortPinLevel(1, 6, PortGpioLow);
//    Port_SetPortPinLevel(1, 7, PortGpioHigh);
    stc_port_pin_config_t PwmConfig = { 
        .enOutputFunction      = PortOutputResourceG,
        .enOutputDrive         = PortOutputDriveD,
        .enPullResistor        = PortPullResistorNone,
        .enInputLevel          = PortInputLevelCmosA,
        .bInputEnable          = FALSE,
        .bNoiseFilterEnable    = TRUE,
        .enGpioDirection       = PortGpioOutput,
        .enGpioInitOutputLevel = PortGpioLow
    };
    // Port_SetPinConfig(1, 16, &PwmConfig); //P_Speed_OUT-
    stc_port_pin_config_t stc_OUT_pin_high_config =
    {
        .enOutputFunction      = PortOutputResourceGPIO,
        .enOutputDrive         = PortOutputDriveA,
        .enPullResistor        = PortPullResistorNone,
        .enInputLevel          = PortInputLevelCmosA,
        .bInputEnable          = FALSE,
        .bNoiseFilterEnable    = TRUE,
        .enGpioDirection       = PortGpioOutput,
        .enGpioInitOutputLevel = PortGpioHigh,
    };
    // Port_SetPinConfig(2, 28, &stc_OUT_pin_high_config); //AIRBAG_OFF_OUT 

}


void Line_Temp(void)
{
    if(Linestep != HJ_OtherKeyCurrent.count )
    {
        Linestep = HJ_OtherKeyCurrent.count;
        zhenduanflag = 2;
    }
    
    switch (HJ_OtherKeyCurrent.count)
    {
    case 0:
        LINE_LampLowOFF;
        LINE_LampHighOFF;
        LINE_weizhiOFF;
        LINE_TurnLeftOFF;
        LINE_TurnRightOFF;
        LINE_ABSON;
        LINE_BLEOFF;
        zhenduanflag = 0;
        
        break;
    case  1:
        LINE_LampLowON;
        LINE_LampHighOFF;
        LINE_weizhiOFF;
        LINE_TurnLeftOFF;
        LINE_TurnRightOFF;
        LINE_ABSOFF;
        LINE_BLEOFF;
        lineNum = 5;
        if(zhenduanflag != 2)
        {
            if(LineGetSta.lowlight1 != 1)
            {
                linewrong = 1;
            }
        }
        break;
    case  2:
        LINE_LampLowOFF;
        LINE_LampHighON;
        LINE_weizhiOFF;
        LINE_TurnLeftON;
        LINE_TurnRightOFF;
        LINE_ABSOFF;
        LINE_BLEOFF;
        lineNum = 6;
        if(zhenduanflag != 2)
        {
            if(LineGetSta.highlight1 != 1)
            {
                linewrong = 1;
            }
        }
        break;
    case  3:
        LINE_LampLowOFF;
        LINE_LampHighOFF;
        LINE_weizhiON;
        LINE_TurnLeftOFF;
        LINE_TurnRightON;
        LINE_ABSOFF;
        LINE_BLEOFF;
        lineNum = 7;
        if(zhenduanflag != 2)
        {
            if(LineGetSta.weizhilight1 != 1)
            {
                linewrong = 1;
            }
        }
        break;
    case  4:
        LINE_LampLowOFF;
        LINE_LampHighOFF;
        LINE_weizhiOFF;
        LINE_TurnLeftOFF;
        LINE_TurnRightOFF;
        LINE_ABSOFF;
        LINE_BLEOFF;
        zhenduanflag = 0;
        break;
    case  5:
        LINE_LampLowOFF;
        LINE_LampHighOFF;
        LINE_weizhiOFF;
        LINE_TurnLeftOFF;
        LINE_TurnRightOFF;
        LINE_ABSOFF;
        LINE_BLEOFF;
        zhenduanflag = 0;
        break;
    case  6:
        LINE_LampLowOFF;
        LINE_LampHighOFF;
        LINE_weizhiOFF;
        LINE_TurnLeftOFF;
        LINE_TurnRightOFF;
        LINE_ABSOFF;
        LINE_BLEOFF;
        zhenduanflag = 0;
        break;
    case  7:
        LINE_LampLowOFF;
        LINE_LampHighOFF;
        LINE_weizhiOFF;
        LINE_TurnLeftOFF;
        LINE_TurnRightOFF;
        LINE_ABSON;
        LINE_BLEOFF;
        lineNum = 4;
        if(zhenduanflag != 2)
        {
            if(LineGetSta.ABSlight1 != 1)
            {
                linewrong = 1;
            }
        }
        break;
    case  8:
        LINE_LampLowOFF;
        LINE_LampHighOFF;
        LINE_weizhiOFF;
        LINE_TurnLeftOFF;
        LINE_TurnRightOFF;
        LINE_ABSOFF;
        LINE_BLEON;
        lineNum = 1;
        if(zhenduanflag != 2)
        {
            if(LineGetSta.ble1 != 1)
            {
                linewrong = 1;
            }
        }
        break;  
    case  9:
        LINE_LampLowOFF;
        LINE_LampHighOFF;
        LINE_weizhiOFF;
        LINE_TurnLeftOFF;
        LINE_TurnRightOFF;
        LINE_ABSOFF;
        LINE_BLEOFF;
        zhenduanflag = 0;
        break;  
    case  10:
        LINE_LampLowON;
        LINE_LampHighON;
        LINE_weizhiON;
        LINE_TurnLeftON;
        LINE_TurnRightON;
        LINE_ABSON;
        LINE_BLEON;
        zhenduanflag = 0;
        break;
    default:
        LINE_LampLowOFF;
        LINE_LampHighOFF;
        LINE_weizhiOFF;
        LINE_TurnLeftOFF;
        LINE_TurnRightOFF;
        LINE_ABSOFF;
        LINE_BLEOFF;
        zhenduanflag = 0;
        break;
    }
}  
  

