Example #1
0
void ConsoleInit(void)
{
#if defined(ENABLE_CONSOLE)
		unsigned long i = 0;
		
		// Don't attempt anything if not connected
		if (!USB_BUS_SENSE) return;

		USBInitializeSystem();
		USBDeviceAttach();

		// This will only work in an interrupt driven USB system - exits on button press, only exits after enumeration is usb is detected
		while (USBDeviceState < CONFIGURED_STATE)
		{
			#ifndef USB_INTERRUPT
			USBDeviceTasks(); 	// Interrupt or polling method.  If using polling, must call
			#endif
			USBProcessIO();
			Delay10us(1);
			
			// Timed-out starting connection (perhaps a charger or disconnected?)
			if (i++ >= 1000000ul) 
			{ 
				// The USB connection has failed -- if we're not using the PLL when the radio is on, turn it off now
				USBDeviceDetach();
				return;
			}
		}
		

 		// Gives host time to assign CDC port
 		i = 0;
		while (USBDeviceState >= CONFIGURED_STATE && i++ < 600000ul)
		{
			MRF_LED = 1;
			#ifndef USB_INTERRUPT
			USBDeviceTasks(); 	// Interrupt or polling method.  If using polling, must call
			#endif
			USBProcessIO();
			Delay10us(10);
			if (usb_haschar())
			{
				break;
			}	
		}
		MRF_LED = 0;
#endif
	return;
}
Example #2
0
void high_isr()
{
    
#if defined(USB_INTERRUPT)
        USBDeviceTasks();
#endif
}
Example #3
0
/******************************************************************************
 * Function:        void main(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Main program entry point.
 *
 * Note:            None
 *****************************************************************************/
int main(void)
{   
    InitializeSystem();

    #if defined(USB_INTERRUPT)
        USBDeviceAttach();
    #endif

    while(1)
    {
        #if defined(USB_POLLING)
		// Check bus status and service USB interrupts.
        USBDeviceTasks(); // Interrupt or polling method.  If using polling, must call
        				  // this function periodically.  This function will take care
        				  // of processing and responding to SETUP transactions 
        				  // (such as during the enumeration process when you first
        				  // plug in).  USB hosts require that USB devices should accept
        				  // and process SETUP packets in a timely fashion.  Therefore,
        				  // when using polling, this function should be called 
        				  // regularly (such as once every 1.8ms or faster** [see 
        				  // inline code comments in usb_device.c for explanation when
        				  // "or faster" applies])  In most cases, the USBDeviceTasks() 
        				  // function does not take very long to execute (ex: <100 
        				  // instruction cycles) before it returns.
        #endif
    				  

		// Application-specific tasks.
		// Application related code may be added here, or in the ProcessIO() function.
        ProcessIO();        
    }//end while
}//end main
Example #4
0
BYTE ReadStringUART(BYTE *Dest, BYTE BufferLen)
{
	BYTE c;
	BYTE count = 0;

	if(BufferLen == 0) return 0;

	while(BufferLen--)
	{
		*Dest = '\0';

		while(!usb_haschar())
		{	
			#ifndef USB_INTERRUPT
			USBDeviceTasks(); 	// Interrupt or polling method.  If using polling, must call
			#endif
			USBProcessIO();
		}
		c = usb_getchar();

		if(c == '\r' || c == '\n')
			break;

		count++;
		*Dest++ = c;
	}

	return count;
}
Example #5
0
int main(void) {
    InitializeSystem();
    initADCDMA();

    
    #if defined(USB_INTERRUPT)
        if(USB_BUS_SENSE && (USBGetDeviceState() == DETACHED_STATE))
        {
            USBDeviceAttach();
        }
    #endif

    #if defined(USB_POLLING)
            // Check bus status and service USB interrupts.
            USBDeviceTasks();
    #endif
    while(1)
    {
        if (!ADC_DATA_READY)
            continue;
                
        ADC_DATA_READY = 0;
        
        RunFFT();

        putrsUSBUSART((char*)&fftOut[0].real);
        
        ProcessIO();
    }
    return (EXIT_SUCCESS);
}
Example #6
0
void interrupt ISRCode()
{
    //if(RCIF)
    if(IOCBF)
        ResultRx();
    //if(TMR0IF)
    //    WorkTick();
    //if(RCIF)
    //    ResultRx();
    //if(TMR1GIF)
    //    UpdateFanSpeed();
    /*if(BCL1IF) {
        BCL1IF = 0; I2CState.Next = 0;
    }
    if(SSP1IF) {
        SSP1IF = 0;
        if(I2CState.Slave)
            I2CSlave();
        else if(I2CState.Next < I2C_WRITE) // split because not enough contigous code space
            I2CRead();
        else
            I2CWrite();
    }*/
    #if defined(USB_INTERRUPT)
        USBDeviceTasks();
    #endif
}
Example #7
0
int main(void){   
	unsigned long timer;
	#define longDelay(x) timer=x; while(timer--)
    CLKDIV = 0x0000;    // Set PLL prescaler (1:1)
    init();			//setup the crystal, pins, hold the FPGA in reset
	usbbufflush();	//setup the USB byte buffer
	

    USBDeviceInit();//setup usb

    while(1){
        USBDeviceTasks(); 

    	if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) continue;
		usbbufservice();//load any USB data into byte buffer

			//send data from the FPGA receive buffer to USB
			//if((mUSBUSARTIsTxTrfReady()) && (uartincnt > 0)){
			//	putUSBUSART(&buf[0], uartincnt);
			//}

    	CDCTxService();

    }//end while

}//end main
Example #8
0
/*****************************************************************************
 * void BinaryMemoryUpload(void)
 *****************************************************************************/
void BinaryMemoryUpload(void)
{
    #ifdef USE_COMM_PKT_MEDIA_USB
    #if defined(USB_INTERRUPT)
        USBDeviceAttach();
    #endif
    #endif

    COMM_PKT_Init();

    while(!BinaryHandlePacket())
    {
        COMM_PKT_Update(FLASH_PROGRAMMER_COMMUNICATION_MEDIUM);

        #ifdef USE_COMM_PKT_MEDIA_USB
        #if defined(USB_POLLING)
		// Check bus status and service USB interrupts.
        USBDeviceTasks(); // Interrupt or polling method.  If using polling, must call
        				  // this function periodically.  This function will take care
        				  // of processing and responding to SETUP transactions 
        				  // (such as during the enumeration process when you first
        				  // plug in).  USB hosts require that USB devices should accept
        				  // and process SETUP packets in a timely fashion.  Therefore,
        				  // when using polling, this function should be called 
        				  // regularly (such as once every 1.8ms or faster** [see 
        				  // inline code comments in usb_device.c for explanation when
        				  // "or faster" applies])  In most cases, the USBDeviceTasks() 
        				  // function does not take very long to execute (ex: <100 
        				  // instruction cycles) before it returns.
        #endif
        #endif
    }
}
void interrupt INTERRUPT_InterruptManager (void)
{
   // interrupt handler
    if(PIE1bits.TMR1IE == 1 && PIR1bits.TMR1IF == 1)
    {
        TMR1_ISR();
        // Call Timer Handler
        TMRapp_Tick();      // Handle Every mS
    }
    else if( (PIE1bits.RCIE == 1) && (PIR1bits.RCIF == 1) )
    {
        USBapp_setrxByteFlag();
        EUSART_Receive_ISR();
    }
    else if( (PIE1bits.TXIE == 1) && (PIR1bits.TXIF == 1) )
    {
        EUSART_Transmit_ISR();
    }
    else if(PIE2bits.C1IE == 1 && PIR2bits.C1IF == 1)
    {
        CMP1_ISR();
    }
    else
    {
        //Unhandled Interrupt
        USBDeviceTasks(); // USB things
    }
}
Example #10
0
void highPrioISR(void)
{
#if defined(USB_INTERRUPT)
    /* if (PIR2bits.USBIF) */
        USBDeviceTasks();
#endif
}	//This return will be a "retfie fast", since this is in a #pragma interrupt section
Example #11
0
void  DelayMs(uint16_t time)
{
    uint16_t delay;

    //Caller wants to block for a possibly very long time.  If USB is enabled
    //and operated in polling mode, we must call USBDeviceTasks() periodically
    //so we can still process mandatory USB control transfer requests from the
    //host within the time allowed by the USB specs.
    #if defined(USB_POLLING)
        if(U1CONbits.USBEN == 1)
        {
            while(time--)
            {
                for(delay=0; delay < 240u; delay++)
                {
                    USBDeviceTasks();   //Assuming 50 inst cycles/call @ 12 MIPS = ~240 calls/ms
                }
            }
        }
		else
		{
            while(time--)
            {
                for(delay=0; delay<DELAY_1MS; delay++);
            }		
		}
    #else
        while(time--)
        {
            for(delay=0; delay<DELAY_1MS; delay++);
        }
    #endif
}
Example #12
0
// Main program entry point
void main(void)
{   
	// Initialise and configure the PIC ready to go
    initialisePic();



	// If we are running in interrupt mode attempt to attach the USB device
    #if defined(USB_INTERRUPT)
        USBDeviceAttach();
    #endif
	

	// Main processing loop
    while(1)
    {
        #if defined(USB_POLLING)
			// If we are in polling mode the USB device tasks must be processed here
			// (otherwise the interrupt is performing this task)
	        USBDeviceTasks();
        #endif
    	
    	// Process USB Commands
        processUsbCommands();  
        
        // Note: Other application specific actions can be placed here      
    }
}
Example #13
0
/********************************************************************
 * Function:        void main(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Main program entry point.
 *
 * Note:            None
 *******************************************************************/
MAIN_RETURN main(void)
{
    SYSTEM_Initialize(SYSTEM_STATE_USB_START);

    USBDeviceInit();
    USBDeviceAttach();
    setup();

    while(1)
    {
        SYSTEM_Tasks();

        #if defined(USB_POLLING)
            // Interrupt or polling method.  If using polling, must call
            // this function periodically.  This function will take care
            // of processing and responding to SETUP transactions
            // (such as during the enumeration process when you first
            // plug in).  USB hosts require that USB devices should accept
            // and process SETUP packets in a timely fashion.  Therefore,
            // when using polling, this function should be called
            // regularly (such as once every 1.8ms or faster** [see
            // inline code comments in usb_device.c for explanation when
            // "or faster" applies])  In most cases, the USBDeviceTasks()
            // function does not take very long to execute (ex: <100
            // instruction cycles) before it returns.
            USBDeviceTasks();
        #endif

        //Application specific tasks
        APP_DeviceCDCBasicDemoTasks();

    }//end while
}//end main
Example #14
0
int main(void) {
    InitializeSystem();

    // Wait for reset button to be released
    while (_PORT(PIO_BTN1) == HIGH) { }

    //ADCInitialize();
    PWMInitialize();
    PWMEnable();
    USBDeviceInit();

    //ADCStartCapture();
    _LAT(PIO_LED1) = HIGH;

    ColourEngine::Initialize();
    //ColourEngine::PowerOn(1000); // Fade in
    ColourEngine::SetPower(power, 0);

    //_LAT(PIO_LED2) = HIGH;

    while (1) {
        USBDeviceTasks();
        USBUserProcess();
    }

    return 0;
}
Example #15
0
int main(void)
#endif
{
    InitializeSystem();

#if defined(USB_INTERRUPT)
    USBDeviceAttach();
#endif

    while(1)
    {
#if defined(USB_POLLING)
        // Check bus status and service USB interrupts.
        USBDeviceTasks(); // Interrupt or polling method.  If using polling, must call
        // this function periodically.  This function will take care
        // of processing and responding to SETUP transactions
        // (such as during the enumeration process when you first
        // plug in).  USB hosts require that USB devices should accept
        // and process SETUP packets in a timely fashion.  Therefore,
        // when using polling, this function should be called
        // frequently (such as once about every 100 microseconds) at any
        // time that a SETUP packet might reasonably be expected to
        // be sent by the host to your device.  In most cases, the
        // USBDeviceTasks() function does not take very long to
        // execute (~50 instruction cycles) before it returns.
#endif


        // Application-specific tasks.
        // Application related code may be added here, or in the ProcessIO() function.
        ProcessIO();
    }//end while
}//end main
Example #16
0
// *--------------------------------------------------------------------------------*
int main(){
	
    mJTAGPortEnable(0);							// JTAG des-habilitado
	SYSTEMConfigPerformance(GetSystemClock()); 	// Activa pre-cache.-
	
	AD1PCFG = 0xFFFF;
	LED1_OUTPUT();
	LED2_OUTPUT();
	SW1_INPUT();
	SW2_INPUT();
	
	buttonCount = 0;
    buttonPressed = FALSE;
    stringPrinted = TRUE;
	
	USBDeviceInit();	
	while(1){
		#if defined(USB_INTERRUPT)
		if(USB_BUS_SENSE && (USBGetDeviceState() == DETACHED_STATE)){
			USBDeviceAttach();
		}
		#endif
		#if defined(USB_POLLING)
			// Check bus status and service USB interrupts.
			USBDeviceTasks();
		#endif
		ProcessIO();
	}
}
Example #17
0
void BootMain(void)
#endif
{
    //NOTE: The c018.o file is not included in the linker script for this project.
    //The C initialization code in the c018.c (comes with C18 compiler in the src directory)
    //file is instead modified and included here manually.  This is done so as to provide
    //a more convenient entry method into the bootloader firmware.  Ordinarily the _entry_scn
    //program code section starts at 0x00 and is created by the code of c018.o.  However,
    //the linker will not work if there is more than one section of code trying to occupy 0x00.
    //Therefore, must not use the c018.o code, must instead manually include the useful code
    //here instead.

    //Make sure interrupts are disabled for this code (could still be on,
    //if the application firmware jumped into the bootloader via software methods)
    INTCON = 0x00;  

    //Initialize the C stack pointer, and other compiler managed items as 
    //normally done in the c018.c file (applicable when using C18 compiler)
    #ifndef __XC8__
        _asm
            lfsr 1, _stack
            lfsr 2, _stack
            clrf TBLPTRU, 0
        _endasm
    #endif

    //Clear the stack pointer, in case the user application jumped into 
    //bootloader mode with excessive junk on the call stack
    STKPTR = 0x00;  

    // End of the important parts of the C initializer.  This bootloader firmware does not use
    // any C initialized user variables (idata memory sections).  Therefore, the above is all
    // the initialization that is required.



    //Call other initialization code and (re)enable the USB module
    InitializeSystem();     //Some USB, I/O pins, and other initialization
    
    //Execute main loop
    while(1)
    {
        ClrWdt();
        
        //Need to call USBDeviceTasks() periodically.  This function takes care of
        //processing non-USB application related USB packets (ex: "Chapter 9" 
        //packets associated with USB enumeration)
        USBDeviceTasks();

        BlinkUSBStatus();   //When enabled, blinks LEDs on the board, based on USB bus state
        
        LowVoltageCheck();  //Regularly monitor voltage to make sure it is sufficient
                            //for safe operation at full frequency and for erase/write
                            //operations.       
        
        ProcessIO();        //This is where all the actual bootloader related data transfer/self programming takes
                            //place see ProcessIO() function in the BootPIC[xxxx].c file.
    }//end while    
}    
Example #18
0
/*
 * Main program entry point.
 */
int main (void)
{
	AD1PCFG = 0xFFFF;

	//Initialize all of the LED pins
	LATE |= 0x000F;
	TRISE &= 0xFFF0;

	USBDeviceInit();	//usb_device.c.  Initializes USB module SFRs and firmware
    				//variables to known states.
	PMCON = 0;

	for (;;) {
		// Check bus status and service USB interrupts.
		USBDeviceTasks(); // Interrupt or polling method.  If using polling, must call
        			  // this function periodically.  This function will take care
        			  // of processing and responding to SETUP transactions
        			  // (such as during the enumeration process when you first
        			  // plug in).  USB hosts require that USB devices should accept
        			  // and process SETUP packets in a timely fashion.  Therefore,
        			  // when using polling, this function should be called
        			  // frequently (such as once about every 100 microseconds) at any
        			  // time that a SETUP packet might reasonably be expected to
        			  // be sent by the host to your device.  In most cases, the
        			  // USBDeviceTasks() function does not take very long to
        			  // execute (~50 instruction cycles) before it returns.

		// Application-specific tasks.
		// Blink the LEDs according to the USB device status
		BlinkUSBStatus();

		// User Application USB tasks
		if (USBDeviceState >= CONFIGURED_STATE && ! (U1PWRC & PIC32_U1PWRC_USUSPEND)) {
			unsigned nbytes_read;
			static unsigned char inbuf[64], outbuf[64];
			static unsigned led3_count = 0;

			// Pull in some new data if there is new data to pull in
			nbytes_read = getsUSBUSART ((char*) inbuf, 64);
			if (nbytes_read != 0) {
				snprintf (outbuf, sizeof(outbuf),
					"Received %d bytes: %02x...\r\n",
					nbytes_read, inbuf[0]);
				putUSBUSART ((char*) outbuf, strlen (outbuf));
				mLED_2_Toggle();
				mLED_3_On();
				led3_count = 10000;
			}
			if (led3_count) {
				// Turn off LED3 when timeout expired.
				led3_count--;
				if (led3_count == 0)
					mLED_3_Off();
			}

			CDCTxService();
		}
	}
}
Example #19
0
void putsUART2(unsigned int *buffer)
{
	#ifndef USB_INTERRUPT
	USBDeviceTasks(); 	// Interrupt or polling method.  If using polling, must call
	#endif
	USBProcessIO();
    usb_write(buffer, strlen((char*)buffer));
}
Example #20
0
char DataRdyUART2(void)
{
	#ifndef USB_INTERRUPT
	USBDeviceTasks(); 	// Interrupt or polling method.  If using polling, must call
	#endif
	USBProcessIO();
	return usb_haschar();
}
Example #21
0
File: usb.c Project: deadbok/kb10
	void YourHighPriorityISRCode()
	{
            MIDI_task();
        #if defined(USB_INTERRUPT)
	        USBDeviceTasks();
        #endif

	}	//This return will be a "retfie fast", since this is in a #pragma interrupt section
Example #22
0
char BusyUART2(void)
{
	#ifndef USB_INTERRUPT
	USBDeviceTasks(); 	// Interrupt or polling method.  If using polling, must call
	#endif
	USBProcessIO();
	return USBCDCBusy();
}
Example #23
0
void WriteUART2(unsigned int data)
{
	#ifndef USB_INTERRUPT
	USBDeviceTasks(); 	// Interrupt or polling method.  If using polling, must call
	#endif
	USBProcessIO();
    usb_putchar((unsigned char)data);
}
Example #24
0
unsigned int ReadUART2(void)
{
	#ifndef USB_INTERRUPT
	USBDeviceTasks(); 	// Interrupt or polling method.  If using polling, must call
	#endif
	USBProcessIO();
	return usb_getchar();
}
Example #25
0
MAIN_RETURN main(void)
{
    SYSTEM_Initialize(SYSTEM_STATE_USB_START);

    USBDeviceInit();
    USBDeviceAttach();

    IPR1 = 0;   //All others interrupt sources will be Low priority
    IPR2 = 32; //USB interrupt is High priority
    RCONbits.IPEN = 1;  //Enabling interrupt priority
    ADCON1bits.PCFG = 0x0F; //By default all I/O digital
    CMCONbits.CM = 7; //Comparators off by default

    while(1)
    {
        SYSTEM_Tasks();

        #if defined(USB_POLLING)
            // Interrupt or polling method.  If using polling, must call
            // this function periodically.  This function will take care
            // of processing and responding to SETUP transactions
            // (such as during the enumeration process when you first
            // plug in).  USB hosts require that USB devices should accept
            // and process SETUP packets in a timely fashion.  Therefore,
            // when using polling, this function should be called
            // regularly (such as once every 1.8ms or faster** [see
            // inline code comments in usb_device.c for explanation when
            // "or faster" applies])  In most cases, the USBDeviceTasks()
            // function does not take very long to execute (ex: <100
            // instruction cycles) before it returns.
            USBDeviceTasks();
        #endif

        /* If the USB device isn't configured yet, we can't really do anything
         * else since we don't have a host to talk to.  So jump back to the
         * top of the while loop. */
        if( USBGetDeviceState() < CONFIGURED_STATE )
        {
            /* Jump back to the top of the while loop. */
            continue;
        }

        /* If we are currently suspended, then we need to see if we need to
         * issue a remote wakeup.  In either case, we shouldn't process any
         * keyboard commands since we aren't currently communicating to the host
         * thus just continue back to the start of the while loop. */
        if( USBIsDeviceSuspended() == true )
        {
            /* Jump back to the top of the while loop. */
            continue;
        }

        //Application specific tasks
        APP_DeviceCustomHIDTasks();

    }//end while
}//end main
void usbbufservice(void) {

    if (usbbuf.cnt == 0) {//if the buffer is empty, get more data
        usbbuf.cnt = getsUSBUSART(usbbuf.inBuf, CDC_BUFFER_SIZE); //JTR2
        if (usbbuf.cnt)
            USBDeviceTasks();
        usbbuf.rdptr = 0;
    }
}
Example #27
0
// Main program entry point
void main(void)
{   
	UINT16 i;

	// Initialise and configure the PIC ready to go
    initialisePic();

	// If we are running in interrupt mode attempt to attach the USB device
    #if defined(USB_INTERRUPT)
        USBDeviceAttach();
    #endif
	
	// Initialise the debug log functions
    //debugInitialise();
    
    // Show that we are up and running
    //mStatusLED0_on();
	
/*	sprintf(debugString, "USB Generic HID Demonstration 3");
	debugOut(debugString);

	//sprintf(debugString, "(C)2011 Simon Inns - http://www.waitingforfriday.com");
	//debugOut(debugString);
	
	sprintf(debugString, "USB Device Initialised. ");
	debugOut(debugString);

	sprintf(debugString, "Initializing N64 Controller.");
	debugOut(debugString);

	InitController();
	sprintf(debugString, "N64 Controller Initialised.");
	debugOut(debugString);*/
	
	for(i = 0; i < 32000; i++);
	for(i = 0; i < 32000; i++);
	for(i = 0; i < 32000; i++);
	for(i = 0; i < 32000; i++);
	for(i = 0; i < 32000; i++);
	for(i = 0; i < 32000; i++);
	for(i = 0; i < 32000; i++);

	// Main processing loop
    while(1)
    {
        #if defined(USB_POLLING)
			// If we are in polling mode the USB device tasks must be processed here
			// (otherwise the interrupt is performing this task)
	        USBDeviceTasks();
        #endif
    	
    	// Process USB Commands
        processUsbCommands();  
        
        // Note: Other application specific actions can be placed here      
    }
}
Example #28
0
void ngc_tasks() {
    if (pollNeeded && (in_menu || (config.input_ngc && config.output_mode != output_ngc))) {
        USBDeviceTasks();
        di();
        ngc_poll();
        // waste some more instructions before sampling
        _delay(40);
        asm("lfsr 0, _sample_buff+25"); // setup FSR0
        ngc_sample();
        asm("movff FSR0L, _sample_w+0"); // update sample_w
    }
    
    if (packets.ngc_test) {
        if (!in_menu && config.output_mode == output_ngc && !config.input_ngc) {
            ngc_fakeout_test();
            WRITETIMER3(65000); // schedule next fake poll soon
        }
        else ngc_handle_packet();
        packets.ngc_test = false;
    }
    
    INTCONbits.IOCIF = 0; // don't bother with stuff that happened in the meantime
    ei();

    if (packets.ngc_avail) {
        // see if this packet is equal to the last transmitted one, and if so, discard it
        // also when in menu, menu_tasks will clear bit
        if (in_menu) return;
        else if (memcmp(&joydata_ngc_raw, &joydata_ngc_last_raw, sizeof(ngc_packet_t))) {
            // dbgs("new packets.ngc_avail\n");
            // new, changed packet available; unpack if faking and send over usb
            
            if (config.input_sources & input_ngc && config.output_mode == output_n64) {
                // dbgs("ngc_create_n64_fake()\n");
                ngc_to_n64();
                fake_unpack((uint8_t*)&joydata_n64_raw, sizeof(n64_packet_t));
            }
        
            else if (config.input_sources & input_ngc && config.output_mode == output_snes) {
                // dbgs("ngc_create_snes_fake()\n");
                ngc_to_snes();
                fake_unpack((uint8_t*)&joydata_snes_raw, sizeof(snes_packet_t));
            }
            
            if (USB_READY && !HIDTxHandleBusy(USBInHandleNGC)) {
                // dbgs("ngc_joydata_createhid()\n");
                ngc_joydata_createhid();
                USBInHandleNGC = HIDTxPacket(HID_EP_NGC, (uint8_t*)&joydata_ngc_usb, sizeof(ngc_packet_t));
            }
            
            // save last packet
            memcpy(&joydata_ngc_last_raw, &joydata_ngc_raw, sizeof(ngc_packet_t));
        }
        packets.ngc_avail = false; // now consumed
    }    
}
Example #29
0
/********************************************************************
 * Function:        void main(void)
 *******************************************************************/
MAIN_RETURN main(void)
{
    SYSTEM_Initialize();

    USBDeviceInit();
    USBDeviceAttach();

    while(1)
    {
        SYSTEM_Tasks();

        #if defined(USB_POLLING)
            USBDeviceTasks();
        #endif

        /* If the USB device isn't configured yet, we can't really do anything
         * else since we don't have a host to talk to.  So jump back to the
         * top of the while loop. */
        if( USBGetDeviceState() < CONFIGURED_STATE )
        {
            /* Jump back to the top of the while loop. */
            continue;
        }

        /* If we are currently suspended, then we need to see if we need to
         * issue a remote wakeup.  In either case, we shouldn't process any
         * keyboard commands since we aren't currently communicating to the host
         * thus just continue back to the start of the while loop. */
        if( USBIsDeviceSuspended() == true )
        {
            /* Jump back to the top of the while loop. */
            continue;
        }
        // implement nMCLR button
        if ( BUTTON_IsPressed(BUTTON_S1)) {
            LUNSoftDetach(0);       // mark the media as temporarily unavailable 
            ICSP_nMCLR = SLAVE_RESET;
            LED_Off(GREEN_LED);     // turn off RED LED to indicate ready for download
            LED_On (RED_LED);
            DIRECT_Initialize();    // reset the programming state machine
        }
        else { // simply act as a slave reset 
            LUNSoftAttach(0);                       // mark the media as available
            if ( !DIRECT_ProgrammingInProgress()) {  // do not release during prog.!
                ICSP_nMCLR = SLAVE_RUN;
                LED_On(GREEN_LED);   // turn off RED LED to indicate ready for download
                LED_Off(RED_LED);
            }
        }

        //Application specific tasks
        APP_DeviceMSDTasks();
        APP_DeviceCDCEmulatorTasks();

    }//end while
}//end main
Example #30
0
void highPriorityISRCode()
{
	// Application specific high-priority ISR code goes here
	
	#if defined(USB_INTERRUPT)
		// Perform USB device tasks
		USBDeviceTasks();
	#endif

}