#include "bsp.h"
void AdcInit(void)
{
        CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);
	ADC_Init(ADC1,ADC_ConversionMode_Single,ADC_Resolution_12Bit,ADC_Prescaler_1);
	ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_384Cycles);
	ADC_Cmd(ADC1,ENABLE);       
	ADC_Cmd(ADC1,ENABLE);
	ADC_Cmd(ADC1,ENABLE); 
        ADC_Cmd(ADC1,DISABLE);      
}
void bsp_init(void)
{
      disableInterrupts();
      //bsp_usart_init();
      bsp_clk_init();
      motor_init();
      RtcConfig();
      //bsp_time4_init();
      if(!LOW_POWER_TEST)bsp_usart_init();
      SpiInit1();
      bsp_gpio_init();
      SoftDelayMs(10);
      FixedParaDeal();
      SoftDelayMs(10);
      AdcInit();
      enableInterrupts();
      
      bsp_DelayMS(1000);
      BatVolDec(1);
      if(1)
      enableInterrupts();
      if(LIMIT_READ)LockCarState.MotorActResults = RISE_OK;
      else
      if(LOW_POWER_TEST)
      {
        CLK_PeripheralClockConfig(CLK_Peripheral_SPI1,ENABLE);
        //GPIO_Init(MOTOR_GPIO,MOTOR_FALL_PIN,GPIO_Mode_In_FL_No_IT);
        //GPIO_Init(MOTOR_GPIO,MOTOR_RISE_PIN,GPIO_Mode_In_FL_No_IT);
          CarAction(0,0,1,2);
          memset(QMC5883LStr.QMC_BASE,0,3*sizeof(int16_t));
        CLK_PeripheralClockConfig(CLK_Peripheral_SPI1,ENABLE);
//        GPIO_Init(MOTOR_GPIO,MOTOR_FALL_PIN,GPIO_Mode_Out_PP_High_Fast);
//	GPIO_Init(MOTOR_GPIO,MOTOR_RISE_PIN,GPIO_Mode_Out_PP_High_Fast);
        
        GPIO_Init(MOTOR_GPIO,MOTOR_FALL_PIN,GPIO_Mode_In_FL_No_IT);
        GPIO_Init(MOTOR_GPIO,MOTOR_RISE_PIN,GPIO_Mode_In_FL_No_IT);
      }
      
      if(1){
          if(LIMIT_READ)LockCarState.MotorActResults = RISE_OK;
          else
          {
              CarAction(0,0,1,2);
              memset(QMC5883LStr.QMC_BASE,0,3*sizeof(int16_t));
          }
      }
      BeepStart(2,0);
      enableInterrupts();
      if(!LOW_POWER_TEST){
          if(LIMIT_READ)LockCarState.MotorActResults = RISE_OK;
          else
          {
              CarAction(0,0,1,2);
              memset(QMC5883LStr.QMC_BASE,0,3*sizeof(int16_t));
          }
          BeepStart(2,0);
      }
//        CarRecDataStr.CmdSource = 0;
//        SendData(PC_REQ);
}

