#include <stddef.h>
// #include "RTE.h"
#include "BU91R65_Porting.h"
#include "RTE_GPIO.h"

int32_t BU91R65_GPIO_Init(BU91R65_Pin_Map_st_t *pstPinMap)
{
    int32_t i32Result;

    i32Result = -1;
    if (pstPinMap != NULL)
    {
        i32Result = 0;
        
        /* CSB = 1 */
        // if (i32Result == 0)
        // {
            // RTE_GPIO_Set_GPIO_Mode(pstPinMap->u16PinCS);
            // RTE_GPIO_Set_Direction(pstPinMap->u16PinCS, RTE_GPIO_DIR_OUT);
            // RTE_GPIO_Set_Level(pstPinMap->u16PinCS, GPIO_Level_High);
            BU91R65_CHIP0_CSB = GPIO_Level_High;
            BU91R65_CHIP1_CSB = GPIO_Level_High;

            BU91R65_CHIP0_CSBb = GPIO_Level_High;
            BU91R65_CHIP1_CSBb = GPIO_Level_High;

            BU91R65_CHIP0_CSBa = GPIO_Level_High;
            BU91R65_CHIP1_CSBa = GPIO_Level_High;

            // BU91R65_CHIP0_CSBc = GPIO_Level_High;
            // BU91R65_CHIP1_CSBc = GPIO_Level_High;

            // BU91R65_CHIP0_CSBd = GPIO_Level_High;
            // BU91R65_CHIP1_CSBd = GPIO_Level_High;
        // }

        /* SCLK = 1 */
        // if (i32Result == 0)
        // {
            // RTE_GPIO_Set_GPIO_Mode(pstPinMap->u16PinSCLK);
            // RTE_GPIO_Set_Direction(pstPinMap->u16PinSCLK, RTE_GPIO_DIR_OUT);
            // RTE_GPIO_Set_Level(pstPinMap->u16PinSCLK, GPIO_Level_Low);
            BU91R65_CHIP0_SCL = GPIO_Level_High;
            BU91R65_CHIP1_SCL = GPIO_Level_High;

            BU91R65_CHIP0_SCLb = GPIO_Level_High;
            BU91R65_CHIP1_SCLb = GPIO_Level_High;

            BU91R65_CHIP0_SCLa = GPIO_Level_High;
            BU91R65_CHIP1_SCLa = GPIO_Level_High;

            // BU91R65_CHIP0_SCLc = GPIO_Level_High;
            // BU91R65_CHIP1_SCLc = GPIO_Level_High;

            // BU91R65_CHIP0_SCLd = GPIO_Level_High;
            // BU91R65_CHIP1_SCLd = GPIO_Level_High;
        // }

        /* SD = 0 */
        // if (i32Result == 0)/*Note: SD = 1*/
        // {
            // RTE_GPIO_Set_GPIO_Mode(pstPinMap->u16PinSD);
            // RTE_GPIO_Set_Direction(pstPinMap->u16PinSD, RTE_GPIO_DIR_OUT);
            // RTE_GPIO_Set_Level(pstPinMap->u16PinSD, GPIO_Level_Low);
            BU91R65_CHIP0_SD = GPIO_Level_Low;
            BU91R65_CHIP1_SD = GPIO_Level_Low;

            BU91R65_CHIP0_SDb = GPIO_Level_Low;
            BU91R65_CHIP1_SDb = GPIO_Level_Low;

            BU91R65_CHIP0_SDa = GPIO_Level_Low;
            BU91R65_CHIP1_SDa = GPIO_Level_Low;

            // BU91R65_CHIP0_SDc = GPIO_Level_Low;
            // BU91R65_CHIP1_SDc = GPIO_Level_Low;

            // BU91R65_CHIP0_SDd = GPIO_Level_Low;
            // BU91R65_CHIP1_SDd = GPIO_Level_Low;
        // }
    }

    return i32Result;
}

void BU91R65_Chip0_Set_nCS(uint8_t u8Level)
{
    BU91R65_CHIP0_CSB = u8Level;
}

void BU91R65_Chip0_Set_SCLK(uint8_t u8Level)
{
    BU91R65_CHIP0_SCL = u8Level;
}

void BU91R65_Chip0_Set_SD(uint8_t u8Level)
{
    BU91R65_CHIP0_SD = u8Level;
}
void BU91R65_Chip1_Set_nCS(uint8_t u8Level)
{
    BU91R65_CHIP1_CSB = u8Level;
}

void BU91R65_Chip1_Set_SCLK(uint8_t u8Level)
{
    BU91R65_CHIP1_SCL = u8Level;
}

void BU91R65_Chip1_Set_SD(uint8_t u8Level)
{
    BU91R65_CHIP1_SD = u8Level;
}


void BU91R65_Chip0_Set_nCSb(uint8_t u8Level)
{
    BU91R65_CHIP0_CSBb = u8Level;
}

void BU91R65_Chip0_Set_SCLKb(uint8_t u8Level)
{
    BU91R65_CHIP0_SCLb = u8Level;
}

void BU91R65_Chip0_Set_SDb(uint8_t u8Level)
{
    BU91R65_CHIP0_SDb = u8Level;
}
void BU91R65_Chip1_Set_nCSb(uint8_t u8Level)
{
    BU91R65_CHIP1_CSBb = u8Level;
}

void BU91R65_Chip1_Set_SCLKb(uint8_t u8Level)
{
    BU91R65_CHIP1_SCLb = u8Level;
}

void BU91R65_Chip1_Set_SDb(uint8_t u8Level)
{
    BU91R65_CHIP1_SDb = u8Level;
}


void BU91R65_Chip0_Set_nCSa(uint8_t u8Level)
{
    BU91R65_CHIP0_CSBa = u8Level;
}

void BU91R65_Chip0_Set_SCLKa(uint8_t u8Level)
{
    BU91R65_CHIP0_SCLa = u8Level;
}

void BU91R65_Chip0_Set_SDa(uint8_t u8Level)
{
    BU91R65_CHIP0_SDa = u8Level;
}
void BU91R65_Chip1_Set_nCSa(uint8_t u8Level)
{
    BU91R65_CHIP1_CSBa = u8Level;
}

void BU91R65_Chip1_Set_SCLKa(uint8_t u8Level)
{
    BU91R65_CHIP1_SCLa = u8Level;
}

void BU91R65_Chip1_Set_SDa(uint8_t u8Level)
{
    BU91R65_CHIP1_SDa = u8Level;
}




// void BU91R65_Chip0_Set_nCSc(uint8_t u8Level)
// {
//     BU91R65_CHIP0_CSBc = u8Level;
// }

// void BU91R65_Chip0_Set_SCLKc(uint8_t u8Level)
// {
//     BU91R65_CHIP0_SCLc = u8Level;
// }

// void BU91R65_Chip0_Set_SDc(uint8_t u8Level)
// {
//     BU91R65_CHIP0_SDc = u8Level;
// }
// void BU91R65_Chip1_Set_nCSc(uint8_t u8Level)
// {
//     BU91R65_CHIP1_CSBc = u8Level;
// }

// void BU91R65_Chip1_Set_SCLKc(uint8_t u8Level)
// {
//     BU91R65_CHIP1_SCLc = u8Level;
// }

// void BU91R65_Chip1_Set_SDc(uint8_t u8Level)
// {
//     BU91R65_CHIP1_SDc = u8Level;
// }



// void BU91R65_Chip0_Set_nCSd(uint8_t u8Level)
// {
//     BU91R65_CHIP0_CSBd = u8Level;
// }

// void BU91R65_Chip0_Set_SCLKd(uint8_t u8Level)
// {
//     BU91R65_CHIP0_SCLd = u8Level;
// }

// void BU91R65_Chip0_Set_SDd(uint8_t u8Level)
// {
//     BU91R65_CHIP0_SDd = u8Level;
// }
// void BU91R65_Chip1_Set_nCSd(uint8_t u8Level)
// {
//     BU91R65_CHIP1_CSBd = u8Level;
// }

// void BU91R65_Chip1_Set_SCLKd(uint8_t u8Level)
// {
//     BU91R65_CHIP1_SCLd = u8Level;
// }

// void BU91R65_Chip1_Set_SDd(uint8_t u8Level)
// {
//     BU91R65_CHIP1_SDd = u8Level;
// }
