3 Copyright (C) Dean Camera, 2009.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
31 #include "../HighLevel/USBMode.h"
33 #if defined(USB_CAN_BE_HOST)
37 uint8_t USB_Host_WaitMS(uint8_t MS
)
39 bool BusSuspended
= USB_Host_IsBusSuspended();
40 uint8_t ErrorCode
= HOST_WAITERROR_Successful
;
42 USB_INT_Clear(USB_INT_HSOFI
);
47 if (USB_INT_HasOccurred(USB_INT_HSOFI
))
49 USB_INT_Clear(USB_INT_HSOFI
);
53 if ((USB_IsConnected
== false) || (USB_CurrentMode
== USB_MODE_DEVICE
))
55 ErrorCode
= HOST_WAITERROR_DeviceDisconnect
;
60 if (Pipe_IsError() == true)
63 ErrorCode
= HOST_WAITERROR_PipeError
;
68 if (Pipe_IsStalled() == true)
71 ErrorCode
= HOST_WAITERROR_SetupStalled
;
78 USB_Host_SuspendBus();
83 void USB_Host_ResetDevice(void)
85 bool BusSuspended
= USB_Host_IsBusSuspended();
87 USB_INT_Disable(USB_INT_DDISCI
);
90 while (!(USB_Host_IsBusResetComplete()));
92 USB_INT_Clear(USB_INT_HSOFI
);
95 for (uint8_t MSRem
= 10; MSRem
!= 0; MSRem
--)
97 /* Workaround for powerless-pull-up devices. After a USB bus reset,
98 all disconnection interrupts are suppressed while a USB frame is
99 looked for - if it is found within 10ms, the device is still
102 if (USB_INT_HasOccurred(USB_INT_HSOFI
))
104 USB_INT_Clear(USB_INT_DDISCI
);
112 USB_Host_SuspendBus();
114 USB_INT_Enable(USB_INT_DDISCI
);