Exemplo n.º 1
0
/******************************************************************************
 * Function:        void BlinkUSBStatus(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        BlinkUSBStatus turns on and off LEDs corresponding to
 *                  the USB device state.
 *
 * Note:            mLED macros can be found in io_cfg.h
 *                  usb_device_state is declared in usbmmap.c and is modified
 *                  in usbdrv.c, usbctrltrf.c, and usb9.c
 *****************************************************************************/
void BlinkUSBStatus(void)
{
	static word led_count=0;
	static char startup_state=0xFF;
	
	if(led_count == 0)led_count = 10000U;
		led_count--;
	
	if(UCONbits.SUSPND == 1)
	{
		//USBWakeFromSuspend();
		if(led_count==0)
		{
			mLED_1_Off();
			mLED_2_Off();
			mLED_3_Toggle();
		}//end if
	}
	else
	{
		if(usb_device_state == DETACHED_STATE)
		{
			setLeds(1);
		}
		else if(usb_device_state == ATTACHED_STATE)
		{
			setLeds(2);
		}
		else if(usb_device_state == POWERED_STATE)
		{
			setLeds(4);
		}
		else if(usb_device_state == DEFAULT_STATE)
		{
			setLeds(2);
		}
		else if(usb_device_state == ADDRESS_STATE)
		{
			setLeds(LEDS_ON);
		}
		else if(usb_device_state == CONFIGURED_STATE)
		{
			startup_state=0;
		}
	}
}
Exemplo n.º 2
0
//left (clear) shift FIFO
char emptyShiftInputCommandBuffer(void){
	char iterator = 0;
	char *dataMoveInputPointer  = headInputPointer;
	char shiftAmount = (char)(headInputPointer - commandInBuffer);
	char bytesToShift = (char)(tailInputPointer - headInputPointer);
	
	if (headInputPointer == tailInputPointer){
		flushInputCommandBuffer();	
		return fifoBufferStatusEmpty;
	}	 
	
	if (headInputPointer == commandInBuffer){	
		return fifoBufferStatusGood;
	}	 

	if (shiftAmount == 0) return fifoBufferStatusGood;
	
	//iffy statement
	headInputPointer = headInputPointer - bytesToShift;
	tailInputPointer = tailInputPointer - bytesToShift;
	
	for (iterator = 0; iterator < bytesToShift; iterator++){
		*(dataMoveInputPointer - shiftAmount) = *(dataMoveInputPointer);
		dataMoveInputPointer++;	
		
				if(iterator > 5){
						while (1){
						mLED_1_On();
						mLED_2_Off();
						Delay10KTCYx(1);
						mLED_2_On();
						mLED_1_Off();
						Delay10KTCYx(1);
						mLED_2_On();
						mLED_2_On();
						Delay10KTCYx(1);
						}
					}	
	}	
	
	return fifoBufferStatusGood;
}
Exemplo n.º 3
0
// Secondary callback function that gets called when the above
// control transfer completes for the USBHIDCBSetReportHandler()
void USBHIDCBSetReportComplete(void) {
  // 1 byte of LED state data should now be in the CtrlTrfData buffer.

  // Num Lock LED state is in Bit0.
  if (CtrlTrfData[0] & 0x01)  // Make LED1 and LED2 match Num Lock state.
  {
    mLED_1_On();
    mLED_2_On();
  } else {
    mLED_1_Off();
    mLED_2_Off();
  }

  // Stop toggling the LEDs, so you can temporily see the Num lock LED state
  // instead.
  // Once the g_usb_led_timer reaches 0, the LEDs will go back to showing USB
  // state instead.
  g_blink_status_valid = FALSE;
  g_usb_led_timer = 140000;
}
Exemplo n.º 4
0
// ****************************************************************************
// ************** USB Callback Functions **************************************
// ****************************************************************************
void USBCBSuspend(void) {
  // Example power saving code.  Insert appropriate code here for the desired
  // application behavior.  If the microcontroller will be put to sleep, a
  // process similar to that shown below may be used:

  // ConfigureIOPinsForLowPower();
  // SaveStateOfAllInterruptEnableBits();
  // DisableAllInterruptEnableBits();
  // EnableOnlyTheInterruptsWhichWillBeUsedToWakeTheMicro();  //should enable at
  // least USBActivityIF as a wake source
  // Sleep();
  // RestoreStateOfAllPreviouslySavedInterruptEnableBits();  //Preferrably, this
  // should be done in the USBCBWakeFromSuspend() function instead.
  // RestoreIOPinsToNormal();                  //Preferrably, this should be
  // done in the USBCBWakeFromSuspend() function instead.

  // Alternatively, the microcontorller may use clock switching to reduce
  // current consumption.
  // Configure device for low power consumption
  mLED_1_Off();
  mLED_2_Off();
  // Should also configure all other I/O pins for lowest power consumption.
  // Typically this is done by driving unused I/O pins as outputs and driving
  // them high or low.
  // In this example, this is not done however, in case the user is expecting
  // the I/O pins
  // to remain tri-state and has hooked something up to them.
  // Leaving the I/O pins floating will waste power and should not be done in a
  // real application.

  // Note: The clock switching code needed is processor specific, as the
  // clock trees and registers aren't identical accross all PIC18 USB device
  // families.
  // Sleep on sleep, 125kHz selected as microcontroller clock source
  OSCCON = 0x13;
  // IMPORTANT NOTE: Do not clear the USBActivityIF (ACTVIF) bit here.  This bit
  // is
  // cleared inside the usb_device.c file.  Clearing USBActivityIF here will
  // cause
  // things to not work as intended.
}
Exemplo n.º 5
0
/********************************************************************
 * Function:        void BlinkUSBStatus(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        BlinkUSBStatus turns on and off LEDs 
 *                  corresponding to the USB device state.
 *
 * Note:            mLED macros can be found in HardwareProfile.h
 *                  USBDeviceState is declared and updated in
 *                  usb_device.c.
 *******************************************************************/
void led_off(void) {mLED_1_Off();mLED_2_Off();}
Exemplo n.º 6
0
void SATURN3D_main (void) {
	SATURN3D_Init_Pins();
	mLED_1_Off();
	mLED_2_On();

	while(1) {
		while (!SATURN3D_SEL || !SATURN3D_REQ) { } //initial sync- both TR and TH are high 
		while (SATURN3D_SEL) { } //wait for this controller to be selected (active low)
		while (SATURN3D_REQ) { } //wait for data request

		mLED_1_Toggle();

		//first send the peripheral id
		//3D controller in digital mode id = 0000
		SATURN3D_D0 = SATURN3D_D1 = SATURN3D_D2 = SATURN3D_D3 = 0;
		SATURN3D_ACK = 0; //tell saturn we're clear to send

		mLED_2_Toggle();

		while (!SATURN3D_REQ && !SATURN3D_SEL) {} //wait for data request toggle

		//now send the data size
		//only 2 bytes of data for digital, so = 0010
		SATURN3D_D1 = 1;
		SATURN3D_ACK = 1; //tell saturn we're clear to send first nibble

		while (SATURN3D_REQ && !SATURN3D_SEL) {} //wait for data request toggle

		//now send directions, UDLR
		SATURN3D_D0 = Stick_Up;
		SATURN3D_D1 = Stick_Down;
		SATURN3D_D2 = Stick_Left;
		SATURN3D_D3 = Stick_Right;
		SATURN3D_ACK = 0;

		while (!SATURN3D_REQ && !SATURN3D_SEL) {} //wait for data request toggle

		//now send kick buttons, in order B/C/A/Start
		SATURN3D_D0 = Stick_Forward;
		SATURN3D_D1 = Stick_Roundhouse;
		SATURN3D_D2 = Stick_Short;
		SATURN3D_D3 = Stick_Start;
		SATURN3D_ACK = 1;
			
		while (SATURN3D_REQ && !SATURN3D_SEL) {} //wait for data request toggle

		//now send punch buttons, in order ZYXR
		SATURN3D_D0 = Stick_Fierce;
		SATURN3D_D1 = Stick_Strong;
		SATURN3D_D2 = Stick_Jab;
#ifdef EXTRA_BUTTONS
		SATURN3D_D3 = Stick_Extra1; //R
#else
		SATURN3D_D3 = 1;
#endif
		SATURN3D_ACK = 0;
		
		while (!SATURN3D_REQ && !SATURN3D_SEL) {} //wait for data request toggle

		//now send the final nibble of data
		SATURN3D_D0 = SATURN3D_D1 = SATURN3D_D2 = 1;
#ifdef EXTRA_BUTTONS
		SATURN3D_D3 = Stick_Extra0; //L
#else
		SATURN3D_D3 = 1;
#endif
		SATURN3D_ACK = 1;

		while (SATURN3D_REQ && !SATURN3D_SEL) {} //wait for data request toggle

		//we have an 'end byte' to send now
		//first nibble = 0000
		SATURN3D_D0 = SATURN3D_D1 = SATURN3D_D2 = SATURN3D_D3 = 0;
		SATURN3D_ACK = 0; //tell saturn we're clear to send

		while (!SATURN3D_REQ && !SATURN3D_SEL) {} //wait for data request toggle

		//second nibble = 0001
		SATURN3D_D0 = 1;
		SATURN3D_ACK = 1;

		//and we're done.
		FrameUpdate();
	}
}