/******************************************************************* * Function: void USBCBInitEP(uint8_t ConfigurationIndex) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: This function is called when the device becomes * initialized, which occurs after the host sends a * SET_CONFIGURATION request. This * callback function should initialize the endpoints * for the device's usage according to the current * configuration. * * Note: If the host ever "unconfigures" the device, it will * set the configuration to '0'. In this case, this * callback gets called with ConfigurationIndex == 0, where * the firmware should disable all non-EP0 endpoints (until * the next non-zero SET_CONFIGURATION request is received, * which will cause this callback to execute again). *******************************************************************/ void USBCBInitEP(uint8_t ConfigurationIndex) { //Check what configuration "index" the host has requested us to select. //Configuration index 0 is special and represents that the device should be //un-configured. However, when the host sets the confguration (with index //matching the valid/implemenented configuration from the configuration descriptor), //the firmware should enable the application endpoints associated with that //configuration, and (re)initialize all application state variables associated //with the USB application endpoints operation. if(ConfigurationIndex == 1) //This application only implements one configuration, with index == 1. { //The host sent us a non-zero set configuration index. In this //case we should prepare the application endpoints to be ready //to use, and to (re-)initialize any application variables associated //with the endpoints. HIDInitEP(); //(Re-)Initialize the application variables associated with the USB interface UserInit(); // See BootPIC[xxxx].c. Initializes the bootloader firmware state machine variables. } //else the host set the configuration back to 0 (indicating unconfigured), or //to some higher (non-implemented value). In either case, we don't need to //do anything specifically, unless the application requires some kind of //"safe shutdown" code to execute after the host has deconfigured the device. }
/****************************************************************************** * Function: void USBStdSetCfgHandler(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: This routine first disables all endpoints by clearing * UEP registers. It then configures (initializes) endpoints * specified in the modifiable section. * * Note: None *****************************************************************************/ void USBStdSetCfgHandler(void) { ctrl_trf_session_owner = MUID_USB9; mDisableEP1to7(); // See usbdrv.h ClearArray((byte*)&usb_alt_intf,MAX_NUM_INT); usb_active_cfg = SetupPkt.bCfgValue; if(SetupPkt.bCfgValue == 0) usb_device_state = ADDRESS_STATE; else { usb_device_state = CONFIGURED_STATE; /* Modifiable Section */ #if defined(USB_USE_HID) // See autofiles\usbcfg.h HIDInitEP(); #endif /* End modifiable section */ }//end if(SetupPkt.bcfgValue == 0) }//end USBStdSetCfgHandler