#include "main.h"
#include "options.h"
#include "utils.h"
#include "drivers\flash\flashChip.h"
#ifdef USBTMC


  #define _USB_OPTIONS_C  
  #include "usb_options.h"
  #include "drivers\flash\flashchip.h"

  #define DEV_OPTIONS_SIZE  8

  unsigned char DeviceOptions[DEV_OPTIONS_SIZE];
         
  //-------------------------------
  int LoadOptions( USB_DEVICE_INFO * udi )
  {
      BREAKPOINT;
      return flash_API_ReadOptions( FLASH_OPT_MAIN, DeviceOptions, DEV_OPTIONS_SIZE );
  }
  //-------------------------------
  int StoreOptions( USB_DEVICE_INFO * udi )
  {   
      BREAKPOINT;
      return flash_API_WriteOptions( FLASH_OPT_MAIN, DeviceOptions, DEV_OPTIONS_SIZE );      
  }
  //-------------------------------  
  int InterfaceSwitch( USB_DEVICE_INFO * udi, USB_INTERFACE interface )
  {
     if(interface == USB_INTERFACE_CONT )
     {            
            s_memset( DeviceOptions, 0xFF, DEV_OPTIONS_SIZE );
     }
     else
     {
            #ifdef USBTMC_LOCKED
            s_memset( DeviceOptions, 0xFF, DEV_OPTIONS_SIZE );
            #else
            s_memcpy( DeviceOptions, "USBTMC!", DEV_OPTIONS_SIZE );
            #endif
     }

     return StoreOptions ( udi );
  }
  //-------------------------------
  USB_INTERFACE GetInterface( USB_DEVICE_INFO * udi )
  {    
  //#ifndef DEBUG_FIRST_RELEASE  // отладочный образец - только переключение ключей для Сазонова.
  //BREAKPOINT;
  //#endif

  //#ifndef DEBUG_FIRST_RELEASE
  //flash_Debug();
  //#endif

  ///*debug!*/tn_arm_enable_interrupts();
  ///*debug!*/return USB_INTERFACE_CONT; // NO USBTMC!
  ///*debug!*/while(1);  
  LoadOptions( udi );
  
  #ifndef USBTMC_LOCKED
    if( DeviceOptions[0] == 'U' )
     if( DeviceOptions[1] == 'S' ) 
      if( DeviceOptions[2] == 'B' ) 
       if( DeviceOptions[3] == 'T' ) 
        if( DeviceOptions[4] == 'M' ) 
         if( DeviceOptions[5] == 'C' ) 
          if( DeviceOptions[6] == '!' ) 
           if( DeviceOptions[7] == 0   )       
             return USB_INTERFACE_SCPI;   
  #endif   
  return USB_INTERFACE_CONT;
  } 
  //-------------------------------

#endif