#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); // 30 1
    Port_SetPinConfig(1, 26, &stc_IN_pin_config); // 15 2

    Port_SetPinConfig(1, 27, &stc_IN_pin_config); // AUTO 3
    Port_SetPinConfig(0, 5, &stc_IN_pin_config); //  EOL 4
    Port_SetPinConfig(1, 29, &stc_IN_pin_config); // SPEED UP 5
    Port_SetPinConfig(1, 30, &stc_IN_pin_config); // SPEED DOWN 6
    Port_SetPinConfig(1, 28,  &stc_IN_pin_config); // LED 7
    Port_SetPinConfig(1, 31,  &stc_IN_pin_config); // IOL UP 8
    Port_SetPinConfig(0, 9,  &stc_IN_pin_config); // IOL DOWN 9
    Port_SetPinConfig(0, 1,  &stc_IN_pin_config); // TFT UP 10
    Port_SetPinConfig(0, 2,  &stc_IN_pin_config); // TFT DOWN 11
    Port_SetPinConfig(0, 3,  &stc_IN_pin_config); // ELSE 12
    Port_SetPinConfig(0, 4,  &stc_IN_pin_config); // END 13
    //��������
    
    //��λ��
    //Port_SetPinConfig(1, 21, &stc_IN_pin_config); // N
    //Port_SetPinConfig(1, 22, &stc_IN_pin_config); // R
    
    Port_SetPinConfig(1, 6, &stc_IN_pin_config); // BUTTON_DETENT_IN

    
    //AD�ɼ���
    Port_SetPinConfig(1, 3, &stc_IN_pin_config); //
    Port_SetPinConfig(1, 7, &stc_IN_pin_config); //
    Port_SetPinConfig(1, 4, &stc_IN_pin_config); //NEW BUTTON 7 AD �ɼ�
    Port_SetPinConfig(1, 15, &stc_IN_pin_config); // b+~
    Port_SetPinConfig(1, 10, &stc_IN_pin_config); // test
    //AD�ɼ���

    Port_SetPinConfig(0, 30, &stc_IN_pin_config_UP);//Error Pin  �ɵ���Ϊ����MCAN
    Port_SetPinConfig(0, 31, &stc_IN_pin_config_UP);//Error Pin  �ɵ���Ϊ����CCAN
    
    Port_SetPinConfig(0, 17, &stc_IN_pin_config);  //GND_Signal3
    
    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,
    };
    
    
    //BD8379����
    Port_SetPinConfig(2, 4, &stc_OUT_pin_config);  //L_ONEBitCLU_OUT 
    Port_SetPinConfig(2, 5, &stc_OUT_pin_config);  //L_CLKBitCLU_OUT 
    Port_SetPinConfig(2, 6, &stc_OUT_pin_config);  //L_SerinBitCLU_OUT 
    Port_SetPinConfig(2, 7, &stc_OUT_pin_config);  //BD8379_RESB_PIN 
    Port_SetPinConfig(2, 8, &stc_OUT_pin_config);  //L_LATCHBitCLU_OUT 
    //BD8379���� 
    Port_SetPinConfig(2, 3, &stc_OUT_pin_config);  //SEATSAFE��
    Port_SetPinConfig(2, 20, &stc_OUT_pin_config); //����ѹ��
    Port_SetPinConfig(2, 26, &stc_OUT_pin_config); //DEFOG

    Port_SetPinConfig(2, 14, &stc_OUT_pin_config);  //QYC��ʻģʽ
    Port_SetPinConfig(2, 19, &stc_OUT_pin_config); //HOODOPEN
    Port_SetPinConfig(2, 29, &stc_OUT_pin_config); //SEATBELT
    Port_SetPinConfig(2, 28, &stc_OUT_pin_config); //SEATMAT
  //  Port_SetPinConfig(0, 0, &stc_OUT_pin_config);  //ALTL   
    Port_SetPinConfig(2, 21, &stc_OUT_pin_config); //BREAK OIL
    Port_SetPinConfig(1, 24, &stc_OUT_pin_config); //R_MT
    //Port_SetPinConfig(2, 14, &stc_OUT_pin_config); //����
    Port_SetPinConfig(1, 18, &stc_OUT_pin_config); //������

    Port_SetPinConfig(0, 0, &stc_OUT_pin_config); //WBATTER
    //IIC����
    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); // S
    Port_SetPinConfig(1, 20, &stc_OUT_pin_config); // D
    
    Port_SetPinConfig(2, 0, &stc_OUT_pin_config);  //CSB0LCD_OUT 
    Port_SetPinConfig(1, 13, &stc_OUT_pin_config);  //����ʻ��ȫ����Ϣ
    Port_SetPinConfig(2, 1, &stc_OUT_pin_config); //WaterSeparator
    
    Port_SetPinConfig(1, 21, &stc_OUT_pin_config); 
    Port_SetPinConfig(1, 22, &stc_OUT_pin_config); 
    Port_SetPinConfig(1, 23, &stc_OUT_pin_config); 

    
    Port_SetPinConfig(1, 25, &stc_OUT_pin_config); //WaterSeparator
    //Port_SetPinConfig(2, 1, &stc_OUT_pin_config);  //SEG0LCD_OUT 
    //TFT���� 
    
    //CANSTB��
    Port_SetPinConfig(1, 2, &stc_OUT_pin_config); // 
    Port_SetPinConfig(0, 29, &stc_OUT_pin_config); // 
    //CANSTB��
    
    //��̬������
    //Port_SetPinConfig(1, 4, &stc_OUT_pin_config); //GS1
    Port_SetPinConfig(1, 5, &stc_OUT_pin_config); //GS0
    //��̬������
    //Port_SetPortPinLevel(1, 4, PortGpioLow);
    Port_SetPortPinLevel(1, 5, PortGpioHigh);
    
    Port_SetPinConfig(2, 13, &stc_OUT_pin_config); //backlight down

    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, 10, &PwmConfig); //P_Speed_OUT-
    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 ApiPowerSupply(void)
{
    //�ϵ�ʱ�� 
    //DelayMs(6);//6ms
    
    P_VCC4V2_EN_NEW(PortGpioLow);// P1_25 Pin97
    
    //DelayMs(1000);//125ms
    
    P_3V3MCU_EN(PortGpioHigh);//64pin     104
    
    //DelayMs(1500);//1500ms
    
    P_VCC3V3_EN(PortGpioHigh);//106pin    200
    
    //DelayMs(2);//1ms 
    
    F_LCD_RESET(PortGpioHigh);//103pin      129
    
    F_LCD_STBYB(PortGpioHigh);//6pin      004
    
    //DelayMs(1);
    
    P_1531_EN(PortGpioHigh);
    
    //DelayMs(115);//115ms
    
    P_61194_EN(PortGpioHigh);//125pin    213
    
    P_APOWER_OUT(PortGpioHigh);//91pin     119
    
    NEW_F_Sound_EN(PortGpioHigh);//����ʹ��
    
    P_BD12_EN(PortGpioHigh);
    
    P_TPA6211_EN(PortGpioHigh);
}  
  

