Пример #1
0
void ConnectionInit() {
  int i;
  USBInitialize();
  for (i = 0; i < CHANNEL_TYPE_MAX; ++i) {
    factories[i]->init(buf, BUF_SIZE);
  }
}
Пример #2
0
Файл: main.c Проект: 21rcc/ioio
int main() {
  log_init();

  // If bootloader mode not requested, go immediately to app.
  if (!ShouldEnterBootloader()) {
    OscCalibrateCached();
    log_printf("Running app...");
    __asm__("goto __APP_RESET");
  }

  // We need to enter bootloader mode, wait for the boot pin to be released.
  while (!led_read());

  // Now we can start!
  led_init();
#ifdef SIGNAL_AFTER_BAD_RESET
  if (RCON & 0b1100001001000000) {
    SignalRcon();
  }
#endif

  log_printf("Hello from Bootloader!!!");
  if (IsPin1Grounded()) {
    log_printf("Erasing config.");
    EraseConfig();
  }
  OscCalibrateCached();
  Blink(5);
  USBInitialize();

  while (1) {
    // Wait for connection
    while (!(USBGetDeviceState() == CONFIGURED_STATE
      && CDCIsDtePresent())) USBTasks();

    log_printf("Connected!");
    BootProtocolInit();

    while (USBGetDeviceState() == CONFIGURED_STATE && CDCIsDtePresent()) {
      static char in_buf[64];
      USBTasks();

      BYTE size = getsUSBUSART(in_buf, sizeof(in_buf));
      if (!BootProtocolProcess(in_buf, size)) {
        log_printf("Protocol error. Will detach / re-attach.");
        USBSoftDetach();
        __delay_ms(2000);
        USBDeviceAttach();
        break;
      }
      BootProtocolTasks();
    }
    log_printf("Disconnected!");
  }
  return 0;
}
Пример #3
0
void bootloader(void)
{
	FSFILE* file;

	USBInitialize(0);

	if (!FSInit())
	{
		// File system failed - pretty much DISKmount didn't work
		AT45D_FormatFS();
		if (!FSInit())
		{
			error(ERR_FS_INIT);
		}
	}

	while (1)
	{
		USBTasks();
		BlinkBlueLED();

		// User Application USB tasks
		if ((USBDeviceState < CONFIGURED_STATE) || (USBSuspendControl == 1))
		{
			// do nothing
		}
		else
		{
			BlinkGreenLED();
			MSDTasks();
		}
		if (_T1IF)
		{
			_T1IF = 0;

			// check for MSD activity...
			if (MDD_AT45D_Write_Activity)
			{
				MDD_AT45D_Write_Activity = 0;
			}
			else
			{
				file = FSfopen("image.hex", "r");
				if (file != NULL)
				{
					file_flash(file);
					FSfclose(file);
					FSremove("image.hex");
					//AT45D_FormatFS();
					return;
				}
			}
		}
	}
}
Пример #4
0
int main( void )
{
    GOL_MSG msg;                                    // GOL message structure to interact with GOL

    RGBMapColorPins();

    TRISBbits.TRISB1 = 0; // Debug
    LATBbits.LATB1   = 0;

    #ifdef USE_FRC
        OSCCON = 0x1102;    // Enable secondary oscillator, use FRC oscillator
        CLKDIV = 0x0000;    // FRC post-scaler (1:1), USB postscaler (1:1), CPU postscaler (1:1)
    #else
        #ifdef GO_SLOW
            OSCCON = 0x3302;    // Enable secondary oscillator, use HS oscillator
            CLKDIV = 0x0080;    // (not needed - FRC post-scaler (1:1)), USB postscaler (4:1), CPU postscaler (1:1)
        #else
            OSCCON = 0x3302;    // Enable secondary oscillator, use HS oscillator
            CLKDIV = 0x0000;    // (not needed - FRC post-scaler (1:1)), USB postscaler (1:1), CPU postscaler (1:1)
        #endif
    #endif
    RCON = 0;

    // Initialize USB Embedded Host
    USBInitialize( 0 );

    // Initialize the RTCC
    RTCCInit();

    // Initialize the graphics library
    GOLInit();

    // Initialize the touch pads.
    CTMUInit();

    // Initialize the reference timer.
    TickInit();


    while (1)
    {
        if (GOLDraw())                          // Draw the screen
        {
            TouchSenseButtonsMsg( &msg );       // Get a raw touchpad message
            if ((msg.uiEvent != EVENT_INVALID) && ((tick - displayChangeTime) > MESSAGE_DEAD_TIME))
            {
                TranslateTouchpad( &msg );      // Translate the raw message
                GOLMsg( &msg );                 // Process the message
            }
        }
    }
}
Пример #5
0
// *--------------------------------------------------------------------------------*
int main(){
	UINT16 Count=0;
	
    mJTAGPortEnable(0);							// JTAG des-habilitado
	SYSTEMConfigPerformance(GetSystemClock()); 	// Activa pre-cache.-
	
	LED1_OUTPUT();
	LED2_OUTPUT();
	INTEnableSystemMultiVectoredInt();
	deviceAttached = FALSE;
    //Initialize the stack
    USBInitialize(0);
    
	while(1){
		//USB stack process function
        USBTasks();
		if(++Count==0){
			LED1_TOGGLE();
		}
        //if thumbdrive is plugged in
        if(USBHostMSDSCSIMediaDetect()){
            deviceAttached = TRUE;
            LED1_OFF();
            //now a device is attached
            //See if the device is attached and in the right format
            if(FSInit()){
                //Opening a file in mode "w" will create the file if it doesn't
                //  exist.  If the file does exist it will delete the old file
                //  and create a new one that is blank.
                myFile = FSfopen("test.txt","w");

                //Write some data to the new file.
                FSfwrite("This is a test.",1,15,myFile);                

                //Always make sure to close the file so that the data gets
                //  written to the drive.
                FSfclose(myFile);

                //Just sit here until the device is removed.
                while(deviceAttached == TRUE){
                    USBTasks();
                    if(++Count==0){
						LED2_TOGGLE();
					}
                }
                LED2_OFF();
            }
        }
	}
}
Пример #6
0
Файл: main.c Проект: 21rcc/ioio
// Calibrate the oscillar according to the SOF clock coming from a USB host.
// This function will first block until a USB connection has been established.
// Then it will wait for 32 SOF's for the tuning process (will hang if they do
// not arrive!). Then, if will disconnect from the USB bus and wait 2 seconds.
// Upon exit, the _TUN register will hold the correct value.
static void OscCalibrate() {
  int i;

  led_init();
  USBInitialize();

  // Start timer2/3 as 32-bit, system clock (16MHz).
  T2CON = 0x0008;
  PR2 = PR3 = 0xFFFF;
  T2CON = 0x8008;

  // Wait for a USB connection. Blink meanwhile.
  int led_counter = 0;
  while (USBGetDeviceState() != POWERED_STATE) {
    USBTasks();
    if ((led_counter++ & 0x3FFF) == 0) led_toggle();
  }
  led_off();

  log_printf("Connected to host. Starting calibration.");

  // Start from 0 (redundant, but better be explicit).
  _TUN = 0;

  for (i = 0; i < 32; ++i) {
    uint32_t duration;
    // Repeat for sanity: if for some reason the SOF is too long or too short,
    // ignore it.
    do {
      duration = MeasureSOF();
    } while (duration < 15000 || duration > 17000);

    if (duration < 16000 && _TUN != 31) {
      // We're running too slow.
      _TUN++;
    } else if (duration > 16000 && _TUN != 32) {
      // We're running too fast.
      _TUN--;
    }
  }
  log_printf("Duration: %lu, TUN=%d", MeasureSOF(), _TUN);

  // Undo side-effects.
  T2CON = 0x0000;

  // Detach, wait.
  USBShutdown();
  __delay_ms(2000);
}
Пример #7
0
/****************************************************************************
  Function:
    int main(void)

  Summary:
    main function

  Description:
    main function

  Precondition:
    None

  Parameters:
    None

  Return Values:
    int - exit code for main function

  Remarks:
    None
  ***************************************************************************/
int main(void)
{
    DWORD size = 0;
    BOOL responseNeeded;

    BYTE mode = 0;

    BYTE wasMode = 0;
    BYTE pushButtonValues = 0xFF;
    BYTE potPercentage = 0xFF;
    BOOL buttonsNeedUpdate = FALSE;
    BOOL potNeedsUpdate = FALSE;
    BOOL motorON = FALSE;
    BOOL readyToRead = TRUE;
    BOOL writeInProgress = FALSE;
    BYTE tempValue = 0xFF;
    BYTE errorCode;
    ACCESSORY_APP_PACKET* command_packet = NULL;

    CLKDIV =  0; /* set for default clock operations Fcyc = 4MHz */
    AD1PCFGL = 0xffff;
    AD1PCFGH = 0x0003;

    BOOL connected_to_app = FALSE;
    BOOL need_to_disconnect_from_app = FALSE;

    #if defined(__PIC32MX__)
        InitPIC32();
    #endif

  #if defined(__dsPIC33EP512MU810__) || defined (__PIC24EP512GU810__)

    // Configure the device PLL to obtain 60 MIPS operation. The crystal
    // frequency is 8MHz. Divide 8MHz by 2, multiply by 60 and divide by
    // 2. This results in Fosc of 120MHz. The CPU clock frequency is
    // Fcy = Fosc/2 = 60MHz. Wait for the Primary PLL to lock and then
    // configure the auxilliary PLL to provide 48MHz needed for USB
    // Operation.

	PLLFBD = 38;				/* M  = 60	*/
	CLKDIVbits.PLLPOST = 0;		/* N1 = 2	*/
	CLKDIVbits.PLLPRE = 0;		/* N2 = 2	*/
	OSCTUN = 0;

    /*	Initiate Clock Switch to Primary
     *	Oscillator with PLL (NOSC= 0x3)*/

    __builtin_write_OSCCONH(0x03);
	__builtin_write_OSCCONL(0x01);
	while (OSCCONbits.COSC != 0x3);

    // Configuring the auxiliary PLL, since the primary
    // oscillator provides the source clock to the auxiliary
    // PLL, the auxiliary oscillator is disabled. Note that
    // the AUX PLL is enabled. The input 8MHz clock is divided
    // by 2, multiplied by 24 and then divided by 2. Wait till
    // the AUX PLL locks.

    ACLKCON3 = 0x24C1;
    ACLKDIV3 = 0x7;
    ACLKCON3bits.ENAPLL = 1;
    while(ACLKCON3bits.APLLCK != 1);

    TRISBbits.TRISB5 = 0;
    LATBbits.LATB5 = 1;

    #endif

    USBInitialize(0);
    AndroidAppStart(&myDeviceInfo);

    responseNeeded = FALSE;
    mInitPOT();
    InitializeTimer2For_PWM();
    PwmInit();

    //InitMOTOR();

    DEBUG_Init(0);

    InitAllLEDs();

    while(1)
    {
        //Keep the USB stack running
        USBTasks();



        //If the device isn't attached yet,
        if(device_attached == FALSE || mode == 1)
        {
            buttonsNeedUpdate = TRUE;
            potNeedsUpdate = TRUE;
            need_to_disconnect_from_app = FALSE;
            connected_to_app = FALSE;
            size = 0;

            /**/
            BYTE curPush = GetPushbuttons();

            if ((curPush == 0x8) || (mode == 1)) {
                LED0_On();

                mode = 1;
                if (wasMode == 0) {

                    pot2LEDs();
                    PwmInit();


                }

                tempValue = ReadPOT();


                wasMode = 1;

                //If it is different than the last time we read the pot, then we need
                //  to send it to the Android device

                if(tempValue != potPercentage) {
                    potNeedsUpdate = TRUE;
                    //setRPM(tempValue);

                    setPWM();
                }
            }
            if ((curPush == 0x4)  || (mode == 0)) {
                    mode = 0;
                    //LED0_Off();

                    if (wasMode == 1) {
                        SetLEDs(0b00000000);
                        wasMode = 0;
                        setRPM(0);
                    }
                    //Reset the accessory state variables
                    InitAllLEDs();

                    //Continue to the top of the while loop to start the check over again.
                    continue;
                }
               /* //Reset the accessory state variables
                InitAllLEDs();

                //Continue to the top of the while loop to start the check over again.
                continue;
            }*/
            //}






        }

        //If the accessory is ready, then this is where we run all of the demo code

        if(readyToRead == TRUE && mode == 0)
        {
            errorCode = AndroidAppRead(device_handle, (BYTE*)&read_buffer, (DWORD)sizeof(read_buffer));
            //If the device is attached, then lets wait for a command from the application
            if( errorCode != USB_SUCCESS)
            {
                //Error
                DEBUG_PrintString("Error trying to start read");
            }
            else
            {
                readyToRead = FALSE;
            }
        }

        size = 0;

        if(AndroidAppIsReadComplete(device_handle, &errorCode, &size) == TRUE)
        {
            //We've received a command over the USB from the Android device.
            if(errorCode == USB_SUCCESS)
            {
                //Maybe process the data here.  Maybe process it somewhere else.
                command_packet = (ACCESSORY_APP_PACKET*)&read_buffer[0];
            }
            else
            {
                //Error
                DEBUG_PrintString("Error trying to complete read request");
            }

        }

        while(size > 0)
        {
            if(connected_to_app == FALSE)
            {
                if(command_packet->command == COMMAND_APP_CONNECT)
                {
                    connected_to_app = TRUE;
                    need_to_disconnect_from_app = FALSE;
                }
            }
            else
            {
                switch(command_packet->command)
                {
                    case COMMAND_SET_LEDS:
                        SetLEDs(command_packet->data);
                        break;

                    case COMMAND_APP_DISCONNECT:
                        need_to_disconnect_from_app = TRUE;
                        break;

                    case COMMAND_SET_PWM:
                        setRPM(command_packet->data);
                        break;

                    default:
                        //Error, unknown command
                        DEBUG_PrintString("Error: unknown command received");
                        break;
                }
            }
            //All commands in this example are two bytes, so remove that from the queue
            size -= 2;
            //And move the pointer to the next packet (this works because
            //  all command packets are 2 bytes.  If variable packet size
            //  then need to handle moving the pointer by the size of the
            //  command type that arrived.
            command_packet++;

            if(need_to_disconnect_from_app == TRUE)
            {
                break;
            }
        }

        if(size == 0)
        {
            readyToRead = TRUE;
        }

        //Get the current pushbutton settings
        tempValue = GetPushbuttons();

        //If the current button settings are different than the last time
        //  we read the button values, then we need to send an update to the
        //  attached Android device
        if(tempValue != pushButtonValues)
        {
            buttonsNeedUpdate = TRUE;
            pushButtonValues = tempValue;
        }

        //Get the current potentiometer setting
        tempValue = ReadPOT();

        //If it is different than the last time we read the pot, then we need
        //  to send it to the Android device
        if(tempValue != potPercentage)
        {
            potNeedsUpdate = TRUE;
            potPercentage = tempValue;
        }

        //If there is a write already in progress, we need to check its status
        if( writeInProgress == TRUE )
        {
            if(AndroidAppIsWriteComplete(device_handle, &errorCode, &size) == TRUE)
            {
                writeInProgress = FALSE;
                if(need_to_disconnect_from_app == TRUE)
                {
                    connected_to_app = FALSE;
                    need_to_disconnect_from_app = FALSE;
                }

                if(errorCode != USB_SUCCESS)
                {
                    //Error
                    DEBUG_PrintString("Error trying to complete write");
                }
            }
        }

        if((need_to_disconnect_from_app == TRUE) && (writeInProgress == FALSE))
        {
            outgoing_packet.command = COMMAND_APP_DISCONNECT;
            outgoing_packet.data = 0;
            writeInProgress = TRUE;

            errorCode = AndroidAppWrite(device_handle,(BYTE*)&outgoing_packet, 2);
            if( errorCode != USB_SUCCESS )
            {
                DEBUG_PrintString("Error trying to send button update");
            }
        }

        if(connected_to_app == FALSE)
        {
            //If the app hasn't told us to start sending data, let's not do anything else.
            continue;
        }

        //If we need up update the button status on the Android device and we aren't
        //  already busy in a write, then we can send the new button data.
        if((buttonsNeedUpdate == TRUE) && (writeInProgress == FALSE))
        {
            outgoing_packet.command = COMMAND_UPDATE_PUSHBUTTONS;
            outgoing_packet.data = pushButtonValues;



            errorCode = AndroidAppWrite(device_handle,(BYTE*)&outgoing_packet, 2);
            if( errorCode != USB_SUCCESS )
            {
                DEBUG_PrintString("Error trying to send button update");
            }

            buttonsNeedUpdate = FALSE;
            writeInProgress = TRUE;
        }

        //If we need up update the pot status on the Android device and we aren't
        //  already busy in a write, then we can send the new pot data.
        if((potNeedsUpdate == TRUE) && (writeInProgress == FALSE))
        {
            outgoing_packet.command = COMMAND_UPDATE_POT;
            outgoing_packet.data = potPercentage;

            errorCode = AndroidAppWrite(device_handle,(BYTE*)&outgoing_packet, 2);
            if( errorCode != USB_SUCCESS )
            {
                DEBUG_PrintString("Error trying to send pot update");
            }

            potNeedsUpdate = FALSE;
            writeInProgress = TRUE;
        }
    } //while(1) main loop
}
Пример #8
0
void USB_Mode(void) 
{
	gb_cmd_timeout=0;
	set_clock_mode(CLOCK_MODE_USB); 
    PowerOn_Init_USB();
	Fill_EndpointDataTable_Into_ExRamBase();
	USBInitialize(); 
	Init_Flash_Reg();
	Init_Flash_Variable();
	gc_WriteProof = 0x00;
	InitFlash();
	
	USB_REG[0x27]    = 0x00; 	// 080304 jay change for new fpga
	GLOBAL_REG[0x17] = 0x01;	// UDC O/P	
    IE = 0x83;	   

	gdw_USB_CountDown = USB_DETECT_TIMEOUT;
	EA=1;	
	while(!gc_USBRST_ISR_Detected)                        // Bulk_In_Out  將跳出while 迴圈  //20090630 chiayen modify
	{
		USB_PlugDetect();
    	if((--gdw_USB_CountDown==0))  //080925chiayen add
		{
			gb_cmd_timeout=1;
    	  	break;
    	}
		if(!gbt_USB_Detected)
		{
			break;
		}
	}
	
	EA=0;
	if(gb_cmd_timeout==1)  //080925chiayen modify
	{
		USB_DisConnect();
		set_clock_mode(CLOCK_MODE_MP3); 
		InitFlash();
		return;
	}
	if(!gb_cmd_timeout)
	{
		LCM_clear();
		LCM_Disp_PC();
		LCM_Disp_PCConnect();
		LCM_Disp_MyMP3Logo();
	}
	   
	for(;;)
	{
		USB_PlugDetect();
		if(!gbt_USB_Detected)
		{//usb connected 
			USB_DisConnect();
			set_clock_mode(CLOCK_MODE_MP3);
			InitFlash();
			break;
		}
		else
		{
			if (gc_USBStage == CBWStage) 
			{			
				if(gbt_USB_Connect_Flag)
				{
				    //tdw_CMD_In_Count =0x02FFFFF;
				}
				else
				{
				    gdw_USB_CountDown =0x01FFFF;  //081208  detect charge first
				}
				EA=1;							
				while (!gbt_USB_CMD_IN)                        // Bulk_In_Out  將跳出while 迴圈
				{
					USB_PlugDetect();
					if(!gbt_USB_Detected)
					{
						break;
					}
					if(gbt_USB_Connect_Flag)
					{
					    if(gbt_USER_Remove_Flag)
						{
					        gb_cmd_timeout=1;
						    break;
						}
					} 
					else
					{
				    	if((--gdw_USB_CountDown==0)&&(!gb_USB_ISR_Detected)) 
						{
							gb_cmd_timeout=1;
				    	  	break;							
				    	}
					}
				}
				EA=0;                                       // 表示有 SCSI CMD 進入 關閉中斷避免常常進入			
				if((!gbt_USB_Detected)||(gb_cmd_timeout==1))  //080925chiayen modify
				{
					USB_DisConnect();
					set_clock_mode(CLOCK_MODE_MP3); 
					InitFlash();
					break;
				}
				gbt_USB_CMD_IN = 0;
				SD_Card_Detect();		
				gbt_USB_Connect_Flag =1; // 081208 jay add			
				Save_CBW_Packet();
				Decode_CBW_Command();                             // 解CBW和記錄相關手續		    
			}

			if(gw_USBDisplayTime==0)
			{
				USB_Mode_Disp();
			}

			if (gc_USBStage == BulkInReadSectorsStage) 
			{
				USB_REG[0xD2]      &= 0xDD;				//Disable Bulk-Out中斷
				ReadSectors();			    
				USB_REG[0xE9]       = 0x11;
				if (gc_ErrorCode == SET_ABRT) 
				{
					gc_RequestSenseCode = 0x06;        //ECC Error				
					gdw_dCBW_DataXferLength.LW = ((LWORD)TotalXferPageNum.WD) << 9;
					gc_bCSWStatus = 0x01;
				}
				else if (gc_ErrorCode == ID_NOT_FND) 
				{
					gc_RequestSenseCode = 0x07;        				//over range
					gdw_dCBW_DataXferLength.LW = ((LWORD)TotalXferPageNum.WD) << 9;
					gc_bCSWStatus = 0x01;
				}
				else 
				{
					gdw_dCBW_DataXferLength.LW = 0;
				}
				gc_USBStage = CSWStage;                                   // 進入Comand Status Wrapper
			}
			if (gc_USBStage == BulkOutWriteSectorsStage) 
			{
				USB_REG[0xD2]      &= 0xDD;				//Disable Bulk-Out中斷
				USB_REG[0x11]       = 0x01;   //HW auto ACK 
				WriteSectors();
				USB_REG[0x11]       = 0x00;
				USB_REG[0xE9]       = 0x22;

				if (gc_ErrorCode == SET_ABRT) 
				{
					gc_bCSWStatus = 0x01;
					gc_RequestSenseCode = 0x08;       					// write error 
				}
				else if (gc_ErrorCode == ID_NOT_FND) 
				{
					gc_RequestSenseCode = 0x07;      					//over range
					gc_bCSWStatus = 0x01;
				}
				else 
				{
					gc_bCSWStatus = 0x00;
					gc_RequestSenseCode = 0xFF;                        // normal
				}
				gdw_dCBW_DataXferLength.LW = 0;
				gc_USBStage = CSWStage;
			}
			if (gc_USBStage == BulkInResponseStage) 
			{                          // '4' BulkInProcess
				USB_REG[0xD2]      &= 0xDD;				//Disable Bulk-Out中斷
				if (gbt_XferNormalResponseData_or_ModeSense) 
				{                      // '1':Normal
			   		if (COMD_IN[0] == 0x23) 
					{
						gdw_dCBW_DataXferLength.WD[1] = 0x00;
						USB_REG[0x16]  = 0x00;
						USB_REG[0x15]  = 0x0C;
						USB_REG[0xA1] |= 0x01;
						while (USB_REG[0xA1] & 0x01)
						{
							USB_PlugDetect();  // 081014 Jay add for usb plug out
							if(!gbt_USB_Detected) break;
						}
						USB_REG[0xE9]  = 0x01;
			   		}
			   		else 
					{
						while (gdw_dCBW_DataXferLength.WD[1]) 
						{
							if (gdw_dCBW_DataXferLength.WD[1] > 64) 
							{
								gdw_dCBW_DataXferLength.WD[1] = gdw_dCBW_DataXferLength.WD[1] - 64;
					       		USB_REG[0x16] = 0x00;
								USB_REG[0x15] = 0x40;
							}
							else 
							{
					       		USB_REG[0x16] = gdw_dCBW_DataXferLength.BY[2] & 0x0F;
								USB_REG[0x15] = gdw_dCBW_DataXferLength.BY[3];
					       		gdw_dCBW_DataXferLength.WD[1] = 0x00;
					       	}
							USB_REG[0xA1] |= 0x01;
							while (USB_REG[0xA1] & 0x01)
							{  //081014 Jay add for usb plug out
								USB_PlugDetect();
								if(!gbt_USB_Detected) break;
							}
							USB_REG[0xE9]  = 0x01;
						}
		   			}
				}
				else 
				{
					if (COMD_IN[0] == 0x1A) 
					{
						gdw_dCBW_DataXferLength.WD[1] = 0x00;
						USB_REG[0x15]  = 0x04;
						USB_REG[0x16]  = 0x00;
						USB_REG[0xA1] |= 0x01;
						while (USB_REG[0xA1] & 0x01)
						{  //081014 Jay add for usb plug out
								USB_PlugDetect();
								if(!gbt_USB_Detected) break;
						}
						USB_REG[0xE9]  = 0x01;
					}
					else 
					{
						gdw_dCBW_DataXferLength.WD[1] = 0x00;
						USB_REG[0x15]  = 0x08;
						USB_REG[0x16]  = 0x00;
						USB_REG[0xA1] |= 0x01;
						while (USB_REG[0xA1] & 0x01)
						{  //081014 Jay add for usb plug out
								USB_PlugDetect();
								if(!gbt_USB_Detected) break;
						}
						USB_REG[0xE9]  = 0x01;
					}
					gbt_XferNormalResponseData_or_ModeSense = NormalResponseData;// 將預設設為一般型
				}
				gc_USBStage = CSWStage;
			}
			if (gc_USBStage == BulkStallStage) 
			{
				StallBulkRW();
				gc_USBStage = CSWStage;
			}
			if (gc_USBStage == BulkInReadBufferStage) 
			{
				USB_REG[0xD2]      &= 0xDD;				//Disable Bulk-Out中斷
				NoCard_ReadSectors();		    
				USB_REG[0xE9]       = 0x11;
				gdw_dCBW_DataXferLength.LW = 0;			
				gc_USBStage = CSWStage;                                   // 進入Comand Status Wrapper			                          
			}
			if (gc_USBStage == BulkOutWriteBufferStage) 
			{
				USB_REG[0xD2]      &= 0xDD;				//Disable Bulk-Out中斷
				USB_REG[0x11]       = 0x01;   //HW auto ACK 
				NoCard_WriteSectors();			
				USB_REG[0x11]       = 0x00;
				USB_REG[0xE9]       = 0x22;
				gdw_dCBW_DataXferLength.LW = 0;
				gc_USBStage = CSWStage;
			}				
			if (gc_USBStage == CSWStage) 
			{
				gc_USBStage = CBWStage;                                   // 重新準備收下一筆command
				USB_BUF_Bank0[ 0] = 'U';					// 以下由SetCSWData expand
				USB_BUF_Bank0[ 1] = 'S';
				USB_BUF_Bank0[ 2] = 'B';
				USB_BUF_Bank0[ 3] = 'S';
				USB_BUF_Bank0[ 4] = dCBW_Tag[0];
				USB_BUF_Bank0[ 5] = dCBW_Tag[1];
				USB_BUF_Bank0[ 6] = dCBW_Tag[2];
				USB_BUF_Bank0[ 7] = dCBW_Tag[3];
				USB_BUF_Bank0[ 8] = gdw_dCBW_DataXferLength.BY[3];                  // LSB 記錄剩下未被傳輸的資料
				USB_BUF_Bank0[ 9] = gdw_dCBW_DataXferLength.BY[2];                  //     記錄剩下未被傳輸的資料
				USB_BUF_Bank0[10] = gdw_dCBW_DataXferLength.BY[1];                  //     記錄剩下未被傳輸的資料
				USB_BUF_Bank0[11] = gdw_dCBW_DataXferLength.BY[0];                  // MSB 記錄剩下未被傳輸的資料
				USB_BUF_Bank0[12] = gc_bCSWStatus;                                 // Command Status 見BulkOnly P.15說明各種碼的情形
				USB_REG[0x2B]  = 0x00; 
				USB_REG[0x16]  = 0x00;
				USB_REG[0x15]  = 0x0D;
				USB_REG[0xA1] |= 0x01;
				while (USB_REG[0xA1] & 0x01)
				{  //081014 Jay add for usb plug out
					USB_PlugDetect();
					if(!gbt_USB_Detected) break;
				}
			}
			USB_REG[0xE9]  = 0x01;			
			USB_REG[0xD2]  |= 0x02;	//Enable Bulk-Out中斷
			USB_REG[0xA1]  |= 0x02;		//下一筆31Byte Bulk-Out
		}
	}
}
Пример #9
0
//******************************************************************************
//******************************************************************************
// Main
//******************************************************************************
//******************************************************************************
int main (void)
{
	BYTE i;
	DWORD temp;

	int  value;

	value = SYSTEMConfigWaitStatesAndPB( GetSystemClock() );

	mJTAGPortEnable(DEBUG_JTAGPORT_OFF);

	// Enable the cache for the best performance
	CheKseg0CacheOn();

	value = OSCCON;
	while (!(value & 0x00000020))
	{
		value = OSCCON;    // Wait for PLL lock to stabilize
	}

	InitKeyboardDriver();

	INTEnableSystemMultiVectoredInt();

	// Init status LED
	mPORTCSetBits(BIT_0);
	mPORTCSetPinsDigitalOut(BIT_0);

	//DBINIT();

	// Initialize USB layers
	USBInitialize(0);

	while (1)
	{
		USBTasks();
		App_Detect_Device();
		switch (App_State_Keyboard)
		{
			case DEVICE_NOT_CONNECTED:
				mPORTCSetBits(BIT_0);
				USBTasks();
				if (DisplayDeatachOnce == FALSE)
				{
					DBPRINTF("Device Detached\n");
					DisplayDeatachOnce = TRUE;
				}
				if (USBHostHID_ApiDeviceDetect()) /* True if report descriptor is parsed with no error */
				{
					DBPRINTF("Device Attached\n");
					App_State_Keyboard = DEVICE_CONNECTED;
					DisplayConnectOnce = FALSE;
				}
				break;
			case DEVICE_CONNECTED:
				mPORTCClearBits(BIT_0);
				App_State_Keyboard = READY_TO_TX_RX_REPORT;
				if (DisplayConnectOnce == FALSE)
				{
					DisplayConnectOnce = TRUE;
					DisplayDeatachOnce = FALSE;
				}
				InitializeTimer(); // start 10ms timer to schedule input reports

				break;
			case READY_TO_TX_RX_REPORT:
				if (!USBHostHID_ApiDeviceDetect())
				{
					App_State_Keyboard = DEVICE_NOT_CONNECTED;
					//                                DisplayOnce = FALSE;
				}
				break;
			case GET_INPUT_REPORT:
				if (USBHostHID_ApiGetReport(Appl_raw_report_buffer.Report_ID, Appl_ModifierKeysDetails.interfaceNum,
																		Appl_raw_report_buffer.ReportSize, Appl_raw_report_buffer.ReportData))
				{
					/* Host may be busy/error -- keep trying */
				}
				else
				{
					App_State_Keyboard = INPUT_REPORT_PENDING;
				}
				USBTasks();
				break;
			case INPUT_REPORT_PENDING:
				if (USBHostHID_ApiTransferIsComplete(&ErrorDriver, &NumOfBytesRcvd))
				{
					if (ErrorDriver || (NumOfBytesRcvd !=     Appl_raw_report_buffer.ReportSize ))
					{
						ErrorCounter++ ;
						if (MAX_ERROR_COUNTER <= ErrorDriver)
							App_State_Keyboard = ERROR_REPORTED;
						else
							App_State_Keyboard = READY_TO_TX_RX_REPORT;
					}
					else
					{
						ErrorCounter = 0;
						ReportBufferUpdated = TRUE;
						App_State_Keyboard = READY_TO_TX_RX_REPORT;

						if (DisplayConnectOnce == TRUE)
						{
							for (i = 0; i < Appl_raw_report_buffer.ReportSize; i++)
							{
								if (Appl_raw_report_buffer.ReportData[i] != 0)
								{
									//LCDClear();
									//LCDL1Home();
									DisplayConnectOnce = FALSE;
								}
							}
						}

						App_ProcessInputReport();
						App_PrepareOutputReport();
					}
				}
				break;

			case SEND_OUTPUT_REPORT: /* Will be done while implementing Keyboard */
				if (USBHostHID_ApiSendReport(Appl_LED_Indicator.reportID, Appl_LED_Indicator.interfaceNum, Appl_LED_Indicator.reportLength,
																		(BYTE*) & Appl_led_report_buffer))
				{
					/* Host may be busy/error -- keep trying */
				}
				else
				{
					App_State_Keyboard = OUTPUT_REPORT_PENDING;
				}
				USBTasks();

				break;
			case OUTPUT_REPORT_PENDING:
				if (USBHostHID_ApiTransferIsComplete(&ErrorDriver, &NumOfBytesRcvd))
				{
					if (ErrorDriver)
					{
						ErrorCounter++ ;
						if (MAX_ERROR_COUNTER <= ErrorDriver)
							App_State_Keyboard = ERROR_REPORTED;

						//                                App_State_Keyboard = READY_TO_TX_RX_REPORT;
					}
					else
					{
						ErrorCounter = 0;
						App_State_Keyboard = READY_TO_TX_RX_REPORT;
					}
				}
				break;

			case ERROR_REPORTED:
				break;
			default:
				break;
		}
	}
}
Пример #10
0
void BootloaderConnInit() {
  USBInitialize();
  adb_state = STATE_ADB_DISCONNECTED;
  unknown_device_attached = FALSE;
}
Пример #11
0
int main(void)
{
    int  value;
    int junk;
    millisec = 0;
    value = SYSTEMConfigWaitStatesAndPB( GetSystemClock() );

    // Enable the cache for the best performance
    CheKseg0CacheOn();

    //Setupt input for inteface button JF8 (RA01) (0x02)
    TRISASET = 0x02;
    //RED LED - JF9 (RA04)  (0x10)
    TRISACLR = 0x10;
    ODCACLR = 0x10;
    LATASET = 0x10;
    //Green LED -JF7 (RE9)  (0x200)
    TRISECLR = 0x200;
    ODCECLR = 0x200;
    LATESET = 0x200;
    //Setupt Input for DataFlag Button - JF10 - RA5 0x20
    TRISASET = 0x20;
    //Setup Output for Clutch Hold (Launch) JE1 RD14 0x4000
    //This function is active low, driving the FET on the PDU
    TRISDCLR = 0x4000;
    ODCDCLR = 0x4000;
    LATDSET = 0x4000; //Default state is high (off)

    CAN1Init();//CAN1 ACCL 500kbs
    CAN2Init();//Motec 1mbs
    DelayInit();

    initUART2(); // GPS UART
    prevButton1 = 0;
    prevButton2 = 0;
    millisec = 0;

   // Configure Timer 2 to request a real-time interrupt once per millisecond.
   // The period of Timer 2 is (16 * 5000)/(80 MHz) = 1 ms.
   OpenTimer2(T2_ON | T2_IDLE_CON | T2_SOURCE_INT | T2_PS_1_16 | T2_GATE_OFF, 5000);

   // Configure the CPU to respond to Timer 2's interrupt requests.
   INTEnableSystemMultiVectoredInt();
   INTSetVectorPriority(INT_TIMER_2_VECTOR, INT_PRIORITY_LEVEL_2);
   INTClearFlag(INT_T2);
   INTEnable(INT_T2, INT_ENABLED);

   //UART GPS Interrupts
   INTSetVectorPriority(INT_UART_2_VECTOR ,INT_PRIORITY_LEVEL_1); //Make sure UART interrupt is top priority
   INTClearFlag(INT_U2RX);
   INTEnable(INT_U2RX, INT_ENABLED);


    value = OSCCON;
    while (!(value & 0x00000020))
    {
        value = OSCCON;    // Wait for PLL lock to stabilize
    }

    deviceAttached = FALSE;

    //Initialize the stack
    USBInitialize(0);

    shouldLog = FALSE;
    shouldStop = FALSE;
    //count = 0;
    angularRateInfoRec = FALSE;
    accelerationSensorRec = FALSE;
    HRaccelerationSensorRec = FALSE;

       //init tim er 3 to convert adc at 100hz
    OpenTimer3(T3_ON|T3_PS_1_256|T3_SOURCE_INT, 1562);

    //initialize i2c for the psoc
    initI2CPSoC();
    
    state = wait;
    logNum = 0;

    initI2CEEPROM();
    short addy = 0x0000;
    BYTE num = 0x00;
    logNum = readEEPROM(addy);
    if(logNum >= 0xEF)  //Address stored in EEPROM  if greater than 0xEF reset to zero, limited to a single byte with current code configuration
    {
        writeEEPROM(addy, 0x00);
    }
    char GroupString[550];//Group Names (Line1)
    char UnitString[550];//Units (line2)
    char ParamString[650];//Paramater Names (line3)
    sprintf(GroupString,"Time,Accelerometer,Accelerometer,Accelerometer,Accelerometer,Accelerometer,Accelerometer,Accelerometer,Accelerometer,Accelerometer,Engine,Engine,Engine,Engine,Engine,Engine,Engine,Engine,Engine,Engine,Drivetrain,Drivetrain,Electrical,Drivetrain,Drivetrain,Drivetrain,Drivetrain,Engine,Engine,Engine,Engine,Electrical,Electrical,Electrical,Electrical,Electrical,Electrical,Suspension,Suspension,Suspension,Suspension,Suspension,Drivetrain,Driver\n");
    sprintf(UnitString,"ms,deg/s,deg/s,deg/s,m/s^2,m/s^2,m/s^2,m/s^2,m/s^2,m/s^2,rpm,%,kpa,degF,degF,lambda,psi,degF,na,na,psi,psi,V,mph,mph,mph,mph,s,gal,degF,degBTDC,mV,mV,mV,mV,mV,mV,mV,mV,mV,mV,mV,mV,\n");
    sprintf(ParamString, "Millisec,pitch(deg/sec),roll(deg/sec),yaw(deg/sec),lat(m/s^2),long(m/s^2),vert(m/s^2),latHR(m/s^2),longHR(m/s^2),vertHR(m/s^2),rpm,tps(percent),MAP(kpa),AT(degF),ect(degF),lambda,fuel pres,egt(degF),launch,neutral,brake pres,brake pres filtered,BattVolt(V),ld speed(mph), lg speed(mph),rd speed(mph),rg speed(mph),run time(s),fuel used,Oil Temp (deg F), Ignition Adv (degBTDC),Overall Consumption(mV),Overall Production(mV),Fuel Pump(mV),Fuel Injector(mV),Ignition(mV),Vref(mV),Back Left(mV),Back Right(mV),Front Left(mV),Front Right(mV),Steering Angle(mV),Brake Temp(mV),Data Flag,GPRMC,Time,Valid,Lat,N/S,Long,E/W,Speed,Course,Date,Variation,E/W\n");

    LATACLR = 0x10; //Turn on Red LED
   // LATECLR = 0x200;

    UARTSendString(UART2,PMTK_HOT_RESTART);
    int i = 0;
    while(!UARTTransmissionHasCompleted(UART2)){
        i++;
    }

    while(1)
    {
        GPSDataRead();
        GPSSentenceParse();
        ClutchHold(); //This function handles the venting direction of the clutch actuator
        DataFlagFunc(); //This function handles the updates of the data flag variable
        //USB stack process function
        USBTasks();

        switch(state){
            case wait:
                USBTasks();
                millisec = 0;
                if(CheckLogStateChange() == 1){ //start the transition from wait to log
                    state = startLog;
                }
                break;
            case startLog:
                //if thumbdrive is plugged in
                if(USBHostMSDSCSIMediaDetect())
                {
                    deviceAttached = TRUE;
                    //now a device is attached
                    //See if the device is attached and in the right format
                    if(FSInit())
                    {
                        //Opening a file in mode "w" will create the file if it doesn't
                        //  exist.  If the file does exist it will delete the old file
                        //  and create a new one that is blank.
                        logNum = readEEPROM(addy);
                        sprintf(nameString, "test%d.csv", logNum);
                        myFile = FSfopen(nameString,"w");
                        FSfwrite(GroupString,1,strlen(GroupString),myFile);
                        FSfwrite(UnitString,1,strlen(UnitString),myFile);
                        FSfwrite(ParamString,1, strlen(ParamString),myFile);
                        millisec = 0;
                        //LATDSET = 0x4000; //Send sync pulse (aeroprobe)
                       // while(millisec < 1000){} //Wait 1s then move to log, the aeroprobe ADC waits 1s.
                            state = log;
                        LATECLR = 0x200; //Turn on Green
                        LATASET = 0x10; //Turn off Red
                    }
                }
                break;
            case log:
                //This uses MOTEC as the master timer.  Data is only written to the USB after all the motec Data is received
                if(motec0Read && motec1Read && motec2Read && motec3Read && motec4Read && motec5Read){
                    WriteToUSB();
                }
                else{}//Wait for motec data to write the next row
                if(CheckLogStateChange() == 2){ //Start the transition from log to wait
                    state = stopLog;
                }
                if(millisec > 2000){
                    LATDCLR = 0x4000; //After 2 seconds pass no need to keep output high
                }
                //Add a function to check for a flag button and set a variable
                break;
            case stopLog:
                //Always make sure to close the file so that the data gets written to the drive.
                FSfwrite("endFile", 1, 7, myFile);
                FSfclose(myFile);
                state = wait;
                logNum++;
                writeEEPROM(addy, logNum);
                LATACLR = 0x10; //Turn on Red
                LATESET = 0x200; //Turn off Green
                break;
            default:
                state = wait;
                break;
        }


        //CAN Handlers
        CANRxMessageBuffer* CAN1RxMessage = CAN1RxMsgProcess();
        if(CAN1RxMessage){
            WriteAccelData(CAN1RxMessage); //Accel is on CAN 1
        }
        CANRxMessageBuffer* CAN2RxMessage = CAN2RxMsgProcess();
        if(CAN2RxMessage){
            writeCan2Msg(CAN2RxMessage); //Motec is on CAN 2
        }
    }
    return 0;
}
Пример #12
0
int main (void)
{

    #if defined (__C30__) || defined __XC16__
        #if defined( __PIC24FJ256GB110__ ) || defined(__PIC24FJ256GB210__)
            // Configure U2RX - put on pin 49 (RP10)
            RPINR19bits.U2RXR = 10;
            // Configure U2TX - put on pin 50 (RP17)
            RPOR8bits.RP17R = 5;

            // Configure SPI2 Data In - put on pin 11 (RP26)
            RPINR22bits.SDI2R = 26;

            // Configure SPI2 Clock Out - put on pin 10 (RP21)
            RPOR10bits.RP21R = 11;

            // Configure SPI2 Data Out - put on pin 12 (RP19)
            RPOR9bits.RP19R = 10;
            OSCCON = 0x3302;    // Enable secondary oscillator
            CLKDIV = 0x0000;    // Set PLL prescaler (1:1)
        #elif defined(__PIC24FJ64GB004__)
            //On the PIC24FJ64GB004 Family of USB microcontrollers, the PLL will not power up and be enabled
            //by default, even if a PLL enabled oscillator configuration is selected (such as HS+PLL).
            //This allows the device to power up at a lower initial operating frequency, which can be
            //advantageous when powered from a source which is not gauranteed to be adequate for 32MHz
            //operation.  On these devices, user firmware needs to manually set the CLKDIV<PLLEN> bit to
            //power up the PLL.
            {
                unsigned int pll_startup_counter = 600;
                CLKDIVbits.PLLEN = 1;
                while(pll_startup_counter--);
            }
            
            //Device switches over automatically to PLL output after PLL is locked and ready.
        #elif defined(__PIC24FJ256DA210__)
            //TX RF3 RP16
            //RX RD0 RP11
            // Configure U2RX - put on RP11
            RPINR19bits.U2RXR = 11;
            // Configure U2TX - put on RP16
            RPOR8bits.RP16R = 5;
        #endif

    #elif defined(__PIC32MX__)
        {
            int  value;

            value = SYSTEMConfigWaitStatesAndPB( GetSystemClock() );

            // Enable the cache for the best performance
            CheKseg0CacheOn();

            INTEnableSystemMultiVectoredInt();

            value = OSCCON;
            while (!(value & 0x00000020))
            {
                value = OSCCON;    // Wait for PLL lock to stabilize
            }
        }

        AD1PCFG = 0xFFFF;   // Set analog pins to digital.
        TRISF   = 0x00;
    #else
        #error Cannot initialize.
    #endif

    UART2Init();

    UART2PrintString( "\r\n\r\nUSB Embedded Host Simple Full Sheet Printer Demo\r\n" );

    // Initialize USB Embedded Host
    USBInitialize(0);

    // Turn on the A/D converter to monitor Vbus.
    InitializeVbusMonitor();


    while(1)
    {
        MonitorVBUS();
        USBTasks();

        if (status.printerAttached)
        {
            if(status.printerStatusDone == 0)
            {
                if(status.printerStatusSent == 0)
                {
                    if(USBHostPrinterGetStatus( printerInfo.deviceAddress, &status.printer ) == USB_SUCCESS)
                    {
                        status.printerStatusSent = 1;
                    }
                }
            } 
            else
            {

                if(status.printer != 0x18)
                {
                    //if there was an error in the printer status then setup to 
                    //  check the status again
                    status.printerStatusSent = 0;
                    status.printerStatusDone = 0;
                }
                else
                {
    
                    if (!status.pagePrinted)
                    {
                        status.pagePrinted = 1;
        
                        UART2PrintString( "Printing to full sheet printer...\r\n" );
        
                        // Initialize
                        USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_JOB_START, USB_NULL, 0, 0 );
        
                        if (!printerInfo.support.supportFlags.supportsVectorGraphics)
                        {
                            // In the demo's initial configuration, this section executes for the HP Deskjet 460.
        
                            UART2PrintString( "Vector graphics are not supported.\r\n" );
        
                            imageInfo.resolution    = 75;
                            imageInfo.scale         = 1.0;
                            imageInfo.positionX     = (PRINTER_PAGE_PORTRAIT_WIDTH - 0x120)/2;
                            imageInfo.positionY     = 100;
                            #if defined( __C30__ ) || defined __XC16__
                                PrintImageFullSheet( (BYTE __prog__ *)(logoMCHP.address), &imageInfo );
                            #elif defined( __PIC32MX__ )
                                PrintImageFullSheet( (const BYTE *)(logoMCHP.address), &imageInfo );
                            #endif
        
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_FONT_NAME, USB_NULL, USB_PRINTER_FONT_COURIER, 0 );
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_FONT_SIZE, USB_NULL, (DWORD)24, 0 );
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_FONT_BOLD, USB_NULL, 0, 0 );
        
                            WriteLine( 200, 325, &(businessCard[0][0]) );
        
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_FONT_MEDIUM, USB_NULL, 0, 0 );
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_FONT_SIZE, USB_NULL, (DWORD)20, 0 );
        
                            WriteLine( 200, 350, &(businessCard[1][0]) );
                            WriteLine( 200, 375, &(businessCard[2][0]) );
                            WriteLine( 200, 400, &(businessCard[3][0]) );
                            WriteLine( 200, 425, &(businessCard[4][0]) );
                            WriteLine( 200, 450, &(businessCard[5][0]) );
                            WriteLine( 200, 475, &(businessCard[6][0]) );
                            WriteLine( 200, 500, &(businessCard[7][0]) );
        
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_FONT_NAME, USB_NULL, USB_PRINTER_FONT_TIMES_NEW_ROMAN, 0 );
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_FONT_SIZE, USB_NULL, (DWORD)18, 0 );
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_FONT_BOLD, USB_NULL, 0, 0 );
        
                            WriteLine( 50, PRINTER_PAGE_PORTRAIT_HEIGHT - 145, &(adddressMicrochip[0][0]) );
        
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_FONT_MEDIUM, USB_NULL, 0, 0 );
        
                            WriteLine( 50, PRINTER_PAGE_PORTRAIT_HEIGHT - 120, &(adddressMicrochip[1][0]) );
                            WriteLine( 50, PRINTER_PAGE_PORTRAIT_HEIGHT - 95, &(adddressMicrochip[2][0]) );
                            WriteLine( 50, PRINTER_PAGE_PORTRAIT_HEIGHT - 70, &(adddressMicrochip[3][0]) );
                        }
                        else
                        {
                            // In the demo's initial configuration, this section executes for the Lexmark E250dn.
        
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_ORIENTATION_LANDSCAPE, USB_NULL, 0, 0 );

                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_GRAPHICS_LINE_WIDTH, USB_NULL, PRINTER_LINE_WIDTH_THICK, 0 );
        
                            params.sBevel.xL    = 50;     // X-axis position of the left side of the bevel.
                            params.sBevel.yT    = 50;     // Y-axis position of the top of the bevel.
                            params.sBevel.xR    = PRINTER_PAGE_LANDSCAPE_WIDTH  - 50;     // X-axis position of the right side of the bevel.
                            params.sBevel.yB    = PRINTER_PAGE_LANDSCAPE_HEIGHT - 50;     // Y-axis position of the bottom of the bevel.
                            params.sBevel.r     = 20;      // The radius of the cicle that defines the rounded corner
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_GRAPHICS_BEVEL, USB_DATA_POINTER_RAM(&params), sizeof(params.sBevel), 0 );
        
                            imageInfo.resolution    = 75;
                            imageInfo.scale         = 1.0;
                            imageInfo.positionX     = 100;
                            imageInfo.positionY     = 100;
                            #if defined( __C30__ ) || defined __XC16__
                                PrintImageFullSheet( (BYTE __prog__ *)(logoMCHP.address), &imageInfo );
                            #elif defined( __PIC32MX__ )
                                PrintImageFullSheet( (const BYTE *)(logoMCHP.address), &imageInfo );
                            #endif
        
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_FONT_NAME, USB_NULL, USB_PRINTER_FONT_HELVETICA, 0 );
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_FONT_SIZE, USB_NULL, (DWORD)18, 0 );
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_FONT_BOLD, USB_NULL, 0, 0 );
        
                            WriteLine( 100, PRINTER_PAGE_LANDSCAPE_HEIGHT - 145, &(adddressMicrochip[0][0]) );
        
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_FONT_MEDIUM, USB_NULL, 0, 0 );
        
                            WriteLine( 100, PRINTER_PAGE_LANDSCAPE_HEIGHT - 120, &(adddressMicrochip[1][0]) );
                            WriteLine( 100, PRINTER_PAGE_LANDSCAPE_HEIGHT - 95, &(adddressMicrochip[2][0]) );
                            WriteLine( 100, PRINTER_PAGE_LANDSCAPE_HEIGHT - 70, &(adddressMicrochip[3][0]) );
        
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_FONT_NAME, USB_NULL, USB_PRINTER_FONT_AVANT_GARDE, 0 );
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_FONT_SIZE, USB_NULL, (DWORD)24, 0 );
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_FONT_BOLD, USB_NULL, 0, 0 );
        
                            WriteLine( 450, 125, &(businessCard[0][0]) );
        
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_FONT_MEDIUM, USB_NULL, 0, 0 );
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_FONT_SIZE, USB_NULL, (DWORD)20, 0 );

                            WriteLine( 450, 150, &(businessCard[1][0]) );
                            WriteLine( 450, 175, &(businessCard[2][0]) );
                            WriteLine( 450, 200, &(businessCard[3][0]) );
                            WriteLine( 450, 225, &(businessCard[4][0]) );
                            WriteLine( 450, 250, &(businessCard[5][0]) );
                            WriteLine( 450, 275, &(businessCard[6][0]) );
                            WriteLine( 450, 300, &(businessCard[7][0]) );
        
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_FONT_NAME, USB_NULL, USB_PRINTER_FONT_PALATINO, 0 );
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_FONT_SIZE, USB_NULL, (DWORD)16, 0 );
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_FONT_ITALIC, USB_NULL, 0, 0 );
        
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_GRAPHICS_LINE_WIDTH, USB_NULL, PRINTER_LINE_WIDTH_NORMAL, 0 );
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_GRAPHICS_LINE_TYPE, USB_NULL, PRINTER_LINE_TYPE_DASHED, 0 );

                            WriteLine( 120, 310, &(notes[0][0]) );
                            params.sLine.x1 = 170;
                            params.sLine.y1 = 290;
                            params.sLine.x2 = 220;
                            params.sLine.y2 = 260;
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_GRAPHICS_LINE, USB_DATA_POINTER_RAM(&params), sizeof(params.sLine), 0 );
        
                            WriteLine( 216, 396, &(notes[1][0]) );
                            params.sLine.x1 = 266;
                            params.sLine.y1 = 400;
                            params.sLine.x2 = 216;
                            params.sLine.y2 = 445;
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_GRAPHICS_LINE, USB_DATA_POINTER_RAM(&params), sizeof(params.sLine), 0 );
        
                            WriteLine( 440, 330, &(notes[2][0]) );
                            params.sLine.x1 = 490;
                            params.sLine.y1 = 310;
                            params.sLine.x2 = 515;
                            params.sLine.y2 = 280;
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_GRAPHICS_LINE, USB_DATA_POINTER_RAM(&params), sizeof(params.sLine), 0 );
        
                            WriteLine( 450, 410, &(notes[3][0]) );
                            params.sLine.x1 = 550;
                            params.sLine.y1 = 415;
                            params.sLine.x2 = 590;
                            params.sLine.y2 = 430;
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_GRAPHICS_LINE, USB_DATA_POINTER_RAM(&params), sizeof(params.sLine), 0 );
                            params.sLine.x1 = 500;
                            params.sLine.y1 = 415;
                            params.sLine.x2 = 500;
                            params.sLine.y2 = 540;
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_GRAPHICS_LINE, USB_DATA_POINTER_RAM(&params), sizeof(params.sLine), 0 );

                            #define TAO_UNIT    4
                            #define TAO_XL      (PRINTER_PAGE_LANDSCAPE_WIDTH - 200)
                            #define TAO_YT      (PRINTER_PAGE_LANDSCAPE_HEIGHT - 200)
                            #define TAO_XC      (TAO_XL + TAU_UNIT * 12)
                            #define TAO_YC      (TAO_YL + TAU_UNIT * 12)
        
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_GRAPHICS_LINE_WIDTH, USB_NULL, PRINTER_LINE_WIDTH_NORMAL, 0 );
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_GRAPHICS_LINE_TYPE, USB_NULL, PRINTER_LINE_TYPE_SOLID, 0 );
        
                            params.sArc.xL       = TAO_XL;
                            params.sArc.yT       = TAO_YT;
                            params.sArc.xR       = TAO_XL + TAO_UNIT * 24;
                            params.sArc.yB       = TAO_YT + TAO_UNIT * 24;
                            params.sArc.r1       = 0;
                            params.sArc.r2       = TAO_UNIT * 12;
                            params.sArc.octant   = 0xF0;
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_GRAPHICS_ARC, USB_DATA_POINTER_RAM(&params), sizeof(params.sArc), 0 );
        
                            params.sCircle.x    = TAO_XL + TAO_UNIT * 12;
                            params.sCircle.y    = TAO_YT + TAO_UNIT * 18;
                            params.sCircle.r    = TAO_UNIT * 6;
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_GRAPHICS_CIRCLE_FILLED, USB_DATA_POINTER_RAM(&params), sizeof(params.sCircle), 0 );
        
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_GRAPHICS_COLOR, USB_NULL, PRINTER_COLOR_WHITE, 0 );

                            params.sCircle.x    = TAO_XL + TAO_UNIT * 12;
                            params.sCircle.y    = TAO_YT + TAO_UNIT * 6;
                            params.sCircle.r    = TAO_UNIT * 6;
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_GRAPHICS_CIRCLE_FILLED, USB_DATA_POINTER_RAM(&params), sizeof(params.sCircle), 0 );
        
                            params.sCircle.x    = TAO_XL + TAO_UNIT * 12;
                            params.sCircle.y    = TAO_YT + TAO_UNIT * 18;
                            params.sCircle.r    = TAO_UNIT;
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_GRAPHICS_CIRCLE_FILLED, USB_DATA_POINTER_RAM(&params), sizeof(params.sCircle), 0 );
        
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_GRAPHICS_COLOR, USB_NULL, PRINTER_COLOR_BLACK, 0 );
        
                            params.sCircle.x    = TAO_XL + TAO_UNIT * 12;
                            params.sCircle.y    = TAO_YT + TAO_UNIT * 6;
                            params.sCircle.r    = TAO_UNIT;
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_GRAPHICS_CIRCLE_FILLED, USB_DATA_POINTER_RAM(&params), sizeof(params.sCircle), 0 );
        
                            params.sCircle.x    = TAO_XL + TAO_UNIT * 12;
                            params.sCircle.y    = TAO_YT + TAO_UNIT * 12;
                            params.sCircle.r    = TAO_UNIT * 12;
                            USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_GRAPHICS_CIRCLE, USB_DATA_POINTER_RAM(&params), sizeof(params.sCircle), 0 );
                        }
        
                        // Terminate
                        UART2PrintString( "Demo complete.\r\n" );
                        USBHostPrinterCommandWithReadyWait( &returnCode, printerInfo.deviceAddress, USB_PRINTER_JOB_STOP, USB_NULL, 0, 0 );
                    }
                }
            }
        }

    }
}