#include "AnalogChannelCtrl_2d5g_base.h"
#include "delay.h"

#include "CommandsDefine.h"
#include "ProjectConfig.h"
#include "usart.h"
u8 IsChannelSetting;
u32 Low32HC595;
u32 High8HC595;
//u32 DAC1_CMD_offset;
//u32 DAC2_CMD_offset;
//u32 DAC3_CMD_offset;
//u16 DAC_CMDs[3][12];
//u32 DAC1_CMD_bias;
//u32 DAC2_CMD_bias;
//u32 DAC3_CMD_bias;
//u32 Low32HC595_new;
//u32 High8HC595_new;

//锟斤拷始锟斤拷IIC5675
void IIC5675_Init(void)
{
    GPIO_InitTypeDef  GPIO_InitStructure;

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);//使锟斤拷GPIOB时锟斤拷

    //GPIOB8,B9锟斤拷始锟斤拷锟斤拷锟斤拷
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 ;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//锟斤拷通锟斤拷锟侥Ｊ?
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//锟斤拷锟斤拷锟斤拷锟?
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//锟斤拷锟斤拷
    GPIO_Init(GPIOB, &GPIO_InitStructure);//锟斤拷始锟斤拷
		 
    IIC5675_SCL=1;
    IIC5675_SDA=1;
	 
		GPIO_SetBits(GPIOD,GPIO_Pin_0); 

		GPIO_SetBits(GPIOB,GPIO_Pin_13); 

		GPIO_SetBits(GPIOA,GPIO_Pin_2); 
    
}
//锟斤拷锟斤拷IIC5675锟斤拷始锟脚猴拷
void IIC5675_Start(void)
{
    SDA5675_OUT();     //SDA5675锟斤拷锟斤拷锟?
    IIC5675_SDA=1;
    IIC5675_SCL=1;
    delay_us(4);
    IIC5675_SDA=0;//START:when CLK is high,DATA change form high to low
    delay_us(4);
    IIC5675_SCL=0;//钳住I2C锟斤拷锟竭ｏ拷准锟斤拷锟斤拷锟酵伙拷锟斤拷锟斤拷锟斤拷锟?
}
//锟斤拷锟斤拷IIC5675停止锟脚猴拷
void IIC5675_Stop(void)
{
    SDA5675_OUT();//SDA5675锟斤拷锟斤拷锟?
    IIC5675_SCL=0;
    IIC5675_SDA=0;//STOP:when CLK is high DATA change form low to high
    delay_us(4);
    IIC5675_SCL=1;
    IIC5675_SDA=1;//锟斤拷锟斤拷I2C锟斤拷锟竭斤拷锟斤拷锟脚猴拷
    delay_us(4);
}
//锟饺达拷应锟斤拷锟脚号碉拷锟斤拷
//锟斤拷锟斤拷值锟斤拷1锟斤拷锟斤拷锟斤拷应锟斤拷失锟斤拷
//        0锟斤拷锟斤拷锟斤拷应锟斤拷晒锟?
u8 IIC5675_Wait_Ack(void)
{
    u8 ucErrTime=0;
    SDA5675_IN();      //SDA5675锟斤拷锟斤拷为锟斤拷锟斤拷
    IIC5675_SDA=1;
    delay_us(1);
    IIC5675_SCL=1;
    delay_us(1);
    while(READ_SDA5675)
    {
        ucErrTime++;
        if(ucErrTime>250)
        {
            IIC5675_Stop();
            return 1;
        }
    }
    IIC5675_SCL=0;//时锟斤拷锟斤拷锟?0
    return 0;
}
//锟斤拷锟斤拷ACK应锟斤拷
void IIC5675_Ack(void)
{
    IIC5675_SCL=0;
    SDA5675_OUT();
    IIC5675_SDA=0;
    delay_us(2);
    IIC5675_SCL=1;
    delay_us(2);
    IIC5675_SCL=0;
}
//锟斤拷锟斤拷锟斤拷ACK应锟斤拷
void IIC5675_NAck(void)
{
    IIC5675_SCL=0;
    SDA5675_OUT();
    IIC5675_SDA=1;
    delay_us(2);
    IIC5675_SCL=1;
    delay_us(2);
    IIC5675_SCL=0;
}
//IIC5675锟斤拷锟斤拷一锟斤拷锟街斤拷

void IIC5675_Send_Byte(u8 txd)
{
    u8 t;
    SDA5675_OUT();
    IIC5675_SCL=0;//锟斤拷锟斤拷时锟接匡拷始锟斤拷锟捷达拷锟斤拷
    for(t=0; t<8; t++)
    {
        IIC5675_SDA=(txd&0x80)>>7;
        txd<<=1;
        delay_us(2);   //锟斤拷TEA5767锟斤拷锟斤拷锟斤拷锟斤拷时锟斤拷锟角憋拷锟斤拷锟?
        IIC5675_SCL=1;
        delay_us(2);
        IIC5675_SCL=0;
        delay_us(2);
    }
}
//锟斤拷1锟斤拷锟街节ｏ拷ack=1时锟斤拷锟斤拷锟斤拷ACK锟斤拷ack=0锟斤拷锟斤拷锟斤拷nACK
u8 IIC5675_Read_Byte(unsigned char ack)
{
    unsigned char i,receive=0;
    SDA5675_IN();//SDA5675锟斤拷锟斤拷为锟斤拷锟斤拷
    for(i=0; i<8; i++ )
    {
        IIC5675_SCL=0;
        delay_us(2);
        IIC5675_SCL=1;
        receive<<=1;
        if(READ_SDA5675)receive++;
        delay_us(1);
    }
    if (!ack)
        IIC5675_NAck();//锟斤拷锟斤拷nACK
    else
        IIC5675_Ack(); //锟斤拷锟斤拷ACK
    return receive;
}
 

/*DSA_PE43711
* PB0:  CH1_DSA_CS
* PB1:  CH2_DSA_CS
* PB2:  CH3_DSA_CS
* PB3:  CH4_DSA_CS
* PB4:  DATA
* PB5:  CLK
*/
// 锟斤拷锟斤拷衰锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
void DSA_PE43711(u8 addrDev,u8 data,u8 CHx_DSA_CSn)
{
    u8 i=0;
    unsigned char addr1 = addrDev;

    GPIOPin csGpioPin;  //SPI片选锟杰斤拷

    GPIOPin dataGpioPin;  //SPI锟斤拷锟捷管斤拷
    dataGpioPin.gpioType = GPIOD;
    dataGpioPin.pinIndex = GPIO_Pin_11;

    GPIOPin clkGpioPin;  //SPI时锟接管斤拷
    clkGpioPin.gpioType = GPIOD;
    clkGpioPin.pinIndex = GPIO_Pin_13;

    //片选锟斤拷始,锟斤拷锟斤拷
    switch(CHx_DSA_CSn)
    {
        case CH1_DSA_CS :
        {
            csGpioPin.gpioType = GPIOD;
            csGpioPin.pinIndex = GPIO_Pin_12;
            break;
        }
        case CH2_DSA_CS :
        {
            csGpioPin.gpioType = GPIOE;
            csGpioPin.pinIndex = GPIO_Pin_12;
			break;
        }
        case CH3_DSA_CS  :
        {
            csGpioPin.gpioType = GPIOA;
            csGpioPin.pinIndex = GPIO_Pin_1;
			break;
        }
        case CH4_DSA_CS  :
        {
            csGpioPin.gpioType = GPIOE;
            csGpioPin.pinIndex = GPIO_Pin_4;
			break;
        }
        default:
                break;
    }
    GPIO_ResetBits(csGpioPin.gpioType, csGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
    delay_us(2);
		
    //锟斤拷锟斤拷6401锟斤拷锟斤拷43711锟斤拷式锟斤拷锟斤拷
    if(addr1 != 0)
    {
        for( i = 0; i < 8; i++ )
        {
            u8 j = (addr1 & 0x80);

            if(j == 0x80)
            {
                GPIO_SetBits(dataGpioPin.gpioType, dataGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            }
            else
            {
                GPIO_ResetBits(dataGpioPin.gpioType, dataGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            }
            delay_us(2);

            GPIO_SetBits(clkGpioPin.gpioType, clkGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            delay_us(2);
            GPIO_ResetBits(clkGpioPin.gpioType, clkGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            delay_us(2);

            addr1 =(addr1<<1);
        }
            
        for( i = 0; i < 8; i++ )
        {
            u8 j=( data & 0x80);

            if(j == 0x80)
            {
                GPIO_SetBits(dataGpioPin.gpioType, dataGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            }
            else
            {
                GPIO_ResetBits(dataGpioPin.gpioType, dataGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            }
            delay_us(2);

            GPIO_SetBits(clkGpioPin.gpioType, clkGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            delay_us(2);
            GPIO_ResetBits(clkGpioPin.gpioType, clkGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            delay_us(2);

            data=(data<<1);
        }
    }
    else
    {
        for( i=0; i<8; i++ )
        {
            u8	j=(data&0x01);

            if(j == 0x01)
            {
                GPIO_SetBits(dataGpioPin.gpioType, dataGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            }
            else
            {
                GPIO_ResetBits(dataGpioPin.gpioType, dataGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            }
            delay_us(2);

            GPIO_SetBits(clkGpioPin.gpioType, clkGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            delay_us(2);
            GPIO_ResetBits(clkGpioPin.gpioType, clkGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            delay_us(2);

            data=(data>>1);
        }
    }

    //片选锟斤拷锟斤拷锟斤拷锟斤拷锟竭碉拷
    GPIO_SetBits(csGpioPin.gpioType, csGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
    delay_us(2);
    GPIO_ResetBits(csGpioPin.gpioType, csGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
    delay_us(2);
}

/// @brief 通锟斤拷595锟斤拷使锟杰碉拷DSA锟斤拷锟斤拷
/// @param addrDev 
/// @param data 
void DSA2_PE43711(u8 addrDev,u8 data,u8 CHx_DSA_CSn)
{
    u8 i=0;
    unsigned char addr1 = addrDev;
    GPIOPin csGpioPin;  //SPI cs gpio

    GPIOPin dataGpioPin;  //SPI锟斤拷锟捷管斤拷
    dataGpioPin.gpioType = GPIOD;
    dataGpioPin.pinIndex = GPIO_Pin_11;

    GPIOPin clkGpioPin;  //SPI时锟接管斤拷
    clkGpioPin.gpioType = GPIOD;
    clkGpioPin.pinIndex = GPIO_Pin_13;

    //define the cs gpio
    switch(CHx_DSA_CSn)
    {
        case CH1_DSA_CS :
        {
            csGpioPin.gpioType = GPIOC;
            csGpioPin.pinIndex = GPIO_Pin_4;
            break;
        }
        case CH2_DSA_CS :
        {
            csGpioPin.gpioType = GPIOC;
            csGpioPin.pinIndex = GPIO_Pin_5;
			break;
        }
        case CH3_DSA_CS  :
        {
            csGpioPin.gpioType = GPIOB;
            csGpioPin.pinIndex = GPIO_Pin_0;
			break;
        }
        case CH4_DSA_CS  :
        {
            csGpioPin.gpioType = GPIOB;
            csGpioPin.pinIndex = GPIO_Pin_1;
			break;
        }
        default:
                break;
    }

    //reset cs before send data
    GPIO_ResetBits(csGpioPin.gpioType, csGpioPin.pinIndex);
    delay_us(2);

    //锟斤拷锟斤拷6401锟斤拷锟斤拷43711锟斤拷式锟斤拷锟斤拷
    if(addr1 != 0)
    {
        for( i = 0; i < 8; i++ )
        {
            u8 j = (addr1 & 0x80);

            if(j == 0x80)
            {
                GPIO_SetBits(dataGpioPin.gpioType, dataGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            }
            else
            {
                GPIO_ResetBits(dataGpioPin.gpioType, dataGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            }
            delay_us(2);

            GPIO_SetBits(clkGpioPin.gpioType, clkGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            delay_us(2);
            GPIO_ResetBits(clkGpioPin.gpioType, clkGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            delay_us(2);

            addr1 =(addr1<<1);
        }
            
        for( i = 0; i < 8; i++ )
        {
            u8 j=( data & 0x80);

            if(j == 0x80)
            {
                GPIO_SetBits(dataGpioPin.gpioType, dataGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            }
            else
            {
                GPIO_ResetBits(dataGpioPin.gpioType, dataGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            }
            delay_us(2);

            GPIO_SetBits(clkGpioPin.gpioType, clkGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            delay_us(2);
            GPIO_ResetBits(clkGpioPin.gpioType, clkGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            delay_us(2);

            data=(data<<1);
        }
    }
    else
    {
        for( i=0; i<8; i++ )
        {
            u8	j=(data&0x01);

            if(j == 0x1)
            {
                GPIO_SetBits(dataGpioPin.gpioType, dataGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            }
            else
            {
                GPIO_ResetBits(dataGpioPin.gpioType, dataGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            }
            delay_us(2);

            GPIO_SetBits(clkGpioPin.gpioType, clkGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            delay_us(2);
            GPIO_ResetBits(clkGpioPin.gpioType, clkGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            delay_us(2);

            data=(data>>1);
        }
    }
    
    //set and reset after send data
    GPIO_SetBits(csGpioPin.gpioType, csGpioPin.pinIndex);
    delay_us(2);
    GPIO_ResetBits(csGpioPin.gpioType, csGpioPin.pinIndex);
    delay_us(2);
}

// 锟斤拷锟斤拷DAC 偏锟矫碉拷锟斤拷,I2C Send
void DAC_AD5675(unsigned long data,unsigned int DACx_CS)
{
    u8 device_addr = 0;
    u8 port = (data>>16)&0xF;
    u8 cmd = (3<<4)|port;
    u16 sendData = data & 0xFFFF;
    GPIOPin ldacGpioPin;  //片选锟杰斤拷

    switch(DACx_CS)
    {
        case DAC1:
        {			
            device_addr = 12<<1; //0b1100
            ldacGpioPin.gpioType = GPIOD;			 
            ldacGpioPin.pinIndex = GPIO_Pin_0;			 
            break;
        }
        case DAC2:
        {		
            device_addr = 13<<1; //0b1101
            ldacGpioPin.gpioType = GPIOB;			 
            ldacGpioPin.pinIndex = GPIO_Pin_13;		 
            break;
        }
        case DAC3:
        {				 
            device_addr = 14<<1; //0b1110
            ldacGpioPin.gpioType = GPIOA;			 
            ldacGpioPin.pinIndex = GPIO_Pin_2;	
            break; 
        }
        default:
            return;
    }
    IIC5675_Start();
    IIC5675_Send_Byte(device_addr);
    
    if (IIC5675_Wait_Ack() != 0)
    {
        goto cmd_fail;	
    }
    IIC5675_Send_Byte(cmd);
    if (IIC5675_Wait_Ack() != 0)
    {
        goto cmd_fail;	
    }
		
    IIC5675_Send_Byte((sendData>>8)&0xff); 
    if (IIC5675_Wait_Ack() != 0)
    {
        goto cmd_fail;	
    }
	
    IIC5675_Send_Byte(sendData&0xff);
    if (IIC5675_Wait_Ack() != 0)
    {
        goto cmd_fail;	
    }
    IIC5675_Stop();//锟斤拷锟斤拷一锟斤拷停止锟斤拷锟斤拷
	
    //锟斤拷锟斤拷片选
    GPIO_ResetBits(ldacGpioPin.gpioType,ldacGpioPin.pinIndex); 
    delay_us(5);
    GPIO_SetBits(ldacGpioPin.gpioType,ldacGpioPin.pinIndex); 
    delay_ms(1);
    return;

    cmd_fail:
        IIC5675_Stop();//锟斤拷锟斤拷一锟斤拷停止锟斤拷锟斤拷
}

// 锟斤拷锟斤拷DAC 偏锟矫碉拷锟斤拷
void DAC_AD5628(unsigned long data,unsigned int DACx_CS)
{
    u8 i=0;
    u8 j=0;
    unsigned long DAC_data_bit_status=0;

    GPIOPin csGpioPin;  //SPI片选锟杰斤拷

    GPIOPin dataGpioPin;  //SPI锟斤拷锟捷管斤拷
    dataGpioPin.gpioType = GPIOB;
    dataGpioPin.pinIndex = GPIO_Pin_11;
    
    GPIOPin clkGpioPin;  //SPI时锟接管斤拷
    clkGpioPin.gpioType = GPIOB;
    clkGpioPin.pinIndex = GPIO_Pin_12;

    //片选锟斤拷始锟斤拷锟斤拷锟酵高碉拷
    switch(DACx_CS)
    {
        case DAC1:
        {
            csGpioPin.gpioType = GPIOD;
            csGpioPin.pinIndex = GPIO_Pin_0;
            break;
        }
        case DAC2:
        {
            csGpioPin.gpioType = GPIOB;
            csGpioPin.pinIndex = GPIO_Pin_13;
        }
        case DAC3:
        {
            csGpioPin.gpioType = GPIOA;
            csGpioPin.pinIndex = GPIO_Pin_2;
        }
        default:
                break;
    }
    GPIO_ResetBits(csGpioPin.gpioType, csGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
    delay_us(1);
    GPIO_SetBits(csGpioPin.gpioType, csGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
    delay_us(1);
    GPIO_ResetBits(csGpioPin.gpioType, csGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
    delay_us(1);

    //锟斤拷锟斤拷SPI锟斤拷锟捷猴拷时锟斤拷
    GPIO_SetBits(dataGpioPin.gpioType, dataGpioPin.pinIndex);
    GPIO_SetBits(clkGpioPin.gpioType, clkGpioPin.pinIndex);
    delay_us(1);
    GPIO_ResetBits(dataGpioPin.gpioType, dataGpioPin.pinIndex);
    delay_us(1);
    GPIO_ResetBits(clkGpioPin.gpioType, clkGpioPin.pinIndex);
    delay_us(1);

    for	 (i=0; i<4; i++)
    {
        for( j=0; j<8; j++ )
        {
            DAC_data_bit_status = (data & 0x80000000);
            if(DAC_data_bit_status)
            {
                GPIO_SetBits(dataGpioPin.gpioType, dataGpioPin.pinIndex);
            }
            else
            {
                GPIO_ResetBits(dataGpioPin.gpioType, dataGpioPin.pinIndex);
            }
            delay_us(1);

            GPIO_SetBits(clkGpioPin.gpioType, clkGpioPin.pinIndex);
            delay_us(1);
            GPIO_ResetBits(clkGpioPin.gpioType, clkGpioPin.pinIndex);
            delay_us(2);
            data = (data<<1);
        }

        GPIO_ResetBits(dataGpioPin.gpioType, dataGpioPin.pinIndex);
        delay_us(1);
        GPIO_SetBits(clkGpioPin.gpioType, clkGpioPin.pinIndex);
        delay_us(1);
        GPIO_ResetBits(clkGpioPin.gpioType, clkGpioPin.pinIndex);
        delay_us(2);


    }
    GPIO_SetBits(clkGpioPin.gpioType, clkGpioPin.pinIndex);
    delay_us(1);
    GPIO_SetBits(dataGpioPin.gpioType, dataGpioPin.pinIndex);
    delay_us(1);
 
    //片选锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
    GPIO_SetBits(csGpioPin.gpioType, csGpioPin.pinIndex); 
    delay_us(1);
}

// 位锟狡寄达拷锟斤拷锟斤拷 锟斤拷锟狡继碉拷锟斤拷锟斤拷模锟解开锟截★拷锟斤拷锟斤拷锟斤拷锟斤拷
void CD_4094(unsigned long data,unsigned char data_bit)
{
    unsigned char i=0;
    unsigned long ShiftReg_data_bit_status=0;

    GPIOPin csGpioPin;  //SPI片选锟杰斤拷
    csGpioPin.gpioType = GPIOB;
    csGpioPin.pinIndex = GPIO_Pin_15;
    
    GPIOPin dataGpioPin;  //SPI锟斤拷锟捷管斤拷
    dataGpioPin.gpioType = GPIOC;
    dataGpioPin.pinIndex = GPIO_Pin_12;
    
    GPIOPin clkGpioPin;  //SPI时锟接管斤拷
    clkGpioPin.gpioType = GPIOB;
    clkGpioPin.pinIndex = GPIO_Pin_14;

    if(data_bit == 1)
    {
        for( i=0; i<8; i++ )
        {
            ShiftReg_data_bit_status=((unsigned char)data & 0x80);
            if(ShiftReg_data_bit_status)
            {
                GPIO_SetBits(dataGpioPin.gpioType,dataGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
                delay_us(1);
            }
            else
            {
                GPIO_ResetBits(dataGpioPin.gpioType,dataGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
                delay_us(1);
            }
            GPIO_SetBits(clkGpioPin.gpioType,clkGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            delay_us(1);
            GPIO_ResetBits(clkGpioPin.gpioType,clkGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            delay_us(1);
            data=(data<<1);
        }
    }
    else if (data_bit==4)
    {
        for( i=0; i<32; i++ )
        {
            ShiftReg_data_bit_status=(data&0x80000000);
            if(ShiftReg_data_bit_status)//data_bit32=1
            {
                GPIO_SetBits(dataGpioPin.gpioType,dataGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
                delay_us(1);
            }
            else
            {
                GPIO_ResetBits(dataGpioPin.gpioType,dataGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
                delay_us(1);
            }
            GPIO_SetBits(clkGpioPin.gpioType,clkGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            delay_us(1);
            GPIO_ResetBits(clkGpioPin.gpioType,clkGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
            delay_us(1);
            data=(data<<1);
        }
        GPIO_SetBits(csGpioPin.gpioType,csGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
        delay_us(1);
        GPIO_ResetBits(csGpioPin.gpioType,csGpioPin.pinIndex);//锟斤拷要锟斤拷锟斤拷锟接筹拷
        delay_us(1);
    }
 
}
