/* Project name:
     HID_Read_Write (USB HID Read & Write Test)
 * Copyright:
     (c) Mikroelektronika, 2012.
 * Revision History:
     20111223:
       - initial release;
 * Description:
     This example establishes connection with the HID terminal that is active
     on the PC. Upon connection establishment, the HID Device Name will appear
     in the respective window. The character that user sends to MCU from the HID
     terminal will be re-sent back to user.
 * Test configuration:
     MCU:             LM3S9B95
                      http://www.ti.com/lit/ds/symlink/lm3s9b95.pdf
     Dev.Board:       EasyMx v7 for Stellaris(R) ARM(R) - ac:USB
                      http://www.mikroe.com/easymx-pro/stellaris/
     Oscillator:      XT-PLL, 80.000MHz
     Ext. Modules:    -
     SW:              mikroC PRO for ARM
                      http://www.mikroe.com/mikroc/arm/
 * NOTES:  -  Turn on USB VBUS switch SW10.8
*/

char cnt;
char readbuff[64];
char writebuff[64];

void USB0Interrupt() iv IVT_INT_USB0{
  USB_Interrupt_Proc();
}


void main(void){

  int Count = 0;
  GPIO_Digital_Output(&GPIO_PORTA, _GPIO_PINMASK_ALL); // Set PORTA as digital output
  GPIO_PORTA_DATA = 0;

  HID_Enable(&readbuff,&writebuff);

  while(1){
    while(!HID_Read())
      ;

    for(cnt=0;cnt<64;cnt++)
      writebuff[cnt]=readbuff[cnt];
      
      GPIO_PORTA_DATA  = readbuff[63];     //Toggle LED
      writebuff[0] = ++Count;   //send Count
      
    while(!HID_Write(&writebuff,64))
      ;
  }
}