#include "PC_Control.h"
#include "TPS2HB35AQPWPRQ1.h"
#include "MC33984EHFK.h"
#include "SGM4591Q.h"
#include "Dio.h"
#include "CAN_CH0_CAN_Communication_Matrix.h"
#include "Simulated_SPI_Master.h"
/*此文件用于上位机控制U16和U48*/

uint8_t state_23 = 0;
/*U16*/
void PC_Control_U16(void)
{
  uint8_t state_24 = 1;
  state_23 = Get_ID_18000000_Sig_PC_Control_U16_Power();
  /*DIA_EN 引脚置为高电平*/
  SGM4591Q_Chip3_2_Segment1.BIT.PIN_3 = 1;
  SGM4591Q_Global_Control(SGM4591Q_Chip3_2, SGM4591Q_Segment1);
  /*OUT23*/
  if (state_23 == 1)
  {
    TPS2HB35_SetOutput3A_OUT23(1);
  }
  else if (state_23 == 0)
  {
    TPS2HB35_SetOutput3A_OUT23(0);
  }
  else
  {
    ;
  }

  /*OUT24*/
  // if (state_24 == 1)
  // {
  //   TPS2HB35_SetOutput3A_OUT24(1);
  // }
  // else if (state_24 == 0)
  // {
  //   TPS2HB35_SetOutput3A_OUT24(0);
  // }
  // else
  // {
  //   ;
  // }
}

/*U48*/
uint8_t state_U48_1 = 0;
void PC_Control_U48(void)
{
  static uint8_t U48_Overcurrent_Last = 0;

  uint8_t U48_Overcurrent = 0;
  uint8_t U48_Overcurrent_LOW = 0;
  uint8_t U48_Overcurrent_HIGH = 0;
  state_U48_1 = Get_ID_18000000_Sig_PC_Control_U48_Power();
  /*20A_OUT2*/
  if (state_U48_1 == 1)
  {
    Dio_WriteChannel(DioConf_DioChannel_P20_09, STD_HIGH);
  }
  else if (state_U48_1 == 0)
  {
    Dio_WriteChannel(DioConf_DioChannel_P20_09, STD_LOW);
  }
  else
  {
    ;
  }
  U48_Overcurrent_LOW = Get_ID_18000000_Sig_PC_Control_U48_LOW();
  U48_Overcurrent_HIGH = Get_ID_18000000_Sig_PC_Control_U48_HIGH();
  U48_Overcurrent = U48_Overcurrent_LOW + U48_Overcurrent_HIGH << 3;
  if (U48_Overcurrent_Last != U48_Overcurrent)
  {
    /*3.过电流高/低选择*/
    MC33984EHFK_CS1_Output_Low();
    Sim_SPI_Master_0_Byte_Write(MC33984_SOCHLR_1);
    Sim_SPI_Master_0_Byte_Write(U48_Overcurrent);
    MC33984EHFK_CS1_Output_High();
    U48_Overcurrent_Last = U48_Overcurrent;
  }
}
