diff --git a/module_usb_aud_shared/endpoint0/endpoint0.xc b/module_usb_aud_shared/endpoint0/endpoint0.xc index a2361f57..4fd0cb12 100755 --- a/module_usb_aud_shared/endpoint0/endpoint0.xc +++ b/module_usb_aud_shared/endpoint0/endpoint0.xc @@ -19,6 +19,7 @@ #include "audiostream.h" #include "vendorrequests.h" #include "dfu_types.h" +#include "xc_ptr.h" /* Windows does not have a built in DFU driver (windows will prompt), so warn that DFU will not be functional in Audio 1.0 mode. * Of course, OSX is unaffected. @@ -94,6 +95,9 @@ unsigned g_curUsbSpeed = 0; void VendorHostActive(int active); #endif +/* Global used for signalling reset to decouple */ +extern unsigned g_iap_reset; + /* Used when setting/clearing EP halt */ void SetEndpointStatus(unsigned epNum, unsigned status) { @@ -797,7 +801,10 @@ void Endpoint0( chanend c_ep0_out, chanend c_ep0_in, chanend c_audioControl, cha if (retVal < 0) { + int iap_reset = 1; g_curUsbSpeed = XUD_ResetEndpoint(ep0_in, ep0_out); + SET_SHARED_GLOBAL(g_iap_reset, iap_reset); + //printstrln("Resetting"); g_config = 0; diff --git a/module_usb_aud_shared/usb_buffer/decouple.xc b/module_usb_aud_shared/usb_buffer/decouple.xc index 4c65a405..9de7b17f 100644 --- a/module_usb_aud_shared/usb_buffer/decouple.xc +++ b/module_usb_aud_shared/usb_buffer/decouple.xc @@ -158,6 +158,7 @@ int midi_from_host_usb_ep = 0; #ifdef IAP #ifdef IAP_BUFFERED +unsigned g_iap_reset = 0; unsigned g_iap_from_host_flag = 0; unsigned g_iap_to_host_flag = 0; int iap_to_host_usb_ep = 0; @@ -672,6 +673,7 @@ void decouple(chanend c_mix_out, int is_ack_iap; int is_reset; + int iap_reset; unsigned int datum_iap; int iap_data_remaining_to_device = 0; int iap_data_collected_from_device = 0; @@ -764,7 +766,6 @@ void decouple(chanend c_mix_out, // send the current host -> device buffer out of the fifo XUD_SetReady(iap_from_host_usb_ep, 1); - iap_send_reset(c_iap); #endif #endif @@ -1172,6 +1173,12 @@ void decouple(chanend c_mix_out, #ifdef IAP #ifdef IAP_BUFFERED + GET_SHARED_GLOBAL(iap_reset, g_iap_reset); + if (iap_reset) { + iap_send_reset(c_iap); // What if this happen in the middle of a send/ack? + iap_reset = 0; + SET_SHARED_GLOBAL(g_iap_reset, iap_reset); // Reset has been signalled + } // Need to handle sending ZLP on iap_to_host_usb_ep_int to signal iOS device to collect from bulk endpoint. /* Check if buffer() has send IAP packet to host */ GET_SHARED_GLOBAL(iap_to_host_flag, g_iap_to_host_flag);