/********************************** (C) COPYRIGHT *******************************
 * File Name          : main.c
 * Author             : Wingcool
 * Version            : V1.0.0
 * Date               : 2024/01/05
 * Description        : Main program body.
 *********************************************************************************/
#include "include.h"
#include "GoodixTouch.h"
#include "HidReport.h"
#include "usb_com.h"
//#include "uart_transfer.h"
/*********************************************************************
 * @fn      main
 *
 * @brief   Main program.
 *
 * @return  none
 */
void touch_init(void)
{
    tmos_init();

//#if AUTO_TEST
//    AutoTestInit();
//#endif
    Touch_IIC_Init();

#if USBCONFIG
    ConfigInit();

    //uart_transfer_init(9600);
#else
    uart_transfer_init(9600);
#endif
//
//    //CheckFlag();
//
    //CHIP_TYPE chip_type = GetChipTypeFromFlash();

    /*
    if(IsBerlinSeries())
    {
      if(!IsBerlinChipType(chip_type) || chip_type==CHIP_TYPE_UNKNOW)
      {
          ChipType = CHIP_TYPE_BERLIND;
      }
      else
      {
          ChipType = chip_type;
      }
      isBerlinSeries = TRUE;
    }
    else
    {
      if(IsBerlinChipType(chip_type) || chip_type==CHIP_TYPE_UNKNOW)
      {
          ChipType = CHIP_TYPE_9XXX;
      }
      else
      {
          ChipType = chip_type;
      }

      isBerlinSeries = FALSE;
    }


   if(chip_type==CHIP_TYPE_UNKNOW)
   {
      IICTouchInit();

//      if(config.intf == EN_USB_IIC)
//      {
//         SoftResetChip();
//      }
    #if USB_EN
        dev_init(40, 40);
        usb_init();
        usb_device_init();
    #endif // USB_EN

   }
   else
   {
       // ChipType = CHIP_TYPE_BERLINB;
       PRINT("Chip type in flash is %d\n", chip_type);
    #if USB_EN
        dev_init(40, 40);
        usb_init();
        usb_device_init();
    #endif // USB_EN

//       if(config.intf == EN_USB_IIC)
//       {
//           while(UsbReportPosEn == FALSE);
//       }
       IICTouchInit();
   }
   */
    //chip_type = CHIP_TYPE_JD9366;
    ChipType = CHIP_TYPE_JD9366;
    isBerlinSeries = FALSE;

    IICTouchInit();

    PRINT("Initial finish\n");
}


void touch_process(void)
{
#if AUTO_TEST
    AutoTestHandle();
#endif
    //CheckUart0Comand();
    // CheckTouchInt();
    CommandHandle();

    TMOS_SystemProcess();
}
