Renamed all library events to properly seperate out Device and Host mode events. Changed the firing conditions for some events to ensure that events are fired by their own USB mode only.
Remove VBUS events - not needed as the library takes care of VBUS detection and feedback on supported AVRs via the USB_Device_Connected and USB_Device_Disconnected events. Fixed incorrect Host state assignment in the incomplete BluetoothHost demo.
This commit is contained in:
parent
357ccc577b
commit
c5038f1bf4
120 changed files with 666 additions and 759 deletions
|
@ -39,7 +39,7 @@ uint8_t USB_ConfigurationNumber;
|
|||
bool USB_RemoteWakeupEnabled;
|
||||
bool USB_CurrentlySelfPowered;
|
||||
|
||||
void USB_Device_ProcessControlPacket(void)
|
||||
void USB_Device_ProcessControlRequest(void)
|
||||
{
|
||||
bool RequestHandled = false;
|
||||
uint8_t* RequestHeader = (uint8_t*)&USB_ControlRequest;
|
||||
|
@ -106,7 +106,7 @@ void USB_Device_ProcessControlPacket(void)
|
|||
}
|
||||
|
||||
if (!(RequestHandled))
|
||||
EVENT_USB_UnhandledControlPacket();
|
||||
EVENT_USB_Device_UnhandledControlRequest();
|
||||
|
||||
if (Endpoint_IsSETUPReceived())
|
||||
{
|
||||
|
@ -139,8 +139,6 @@ static void USB_Device_SetAddress(void)
|
|||
|
||||
static void USB_Device_SetConfiguration(void)
|
||||
{
|
||||
bool AlreadyConfigured = (USB_ConfigurationNumber != 0);
|
||||
|
||||
#if defined(FIXED_NUM_CONFIGURATIONS)
|
||||
if ((uint8_t)USB_ControlRequest.wValue > FIXED_NUM_CONFIGURATIONS)
|
||||
return;
|
||||
|
@ -195,18 +193,11 @@ static void USB_Device_SetConfiguration(void)
|
|||
Endpoint_ClearIN();
|
||||
|
||||
if (USB_ConfigurationNumber)
|
||||
{
|
||||
USB_DeviceState = DEVICE_STATE_Configured;
|
||||
|
||||
if (!(AlreadyConfigured))
|
||||
EVENT_USB_DeviceEnumerationComplete();
|
||||
}
|
||||
USB_DeviceState = DEVICE_STATE_Configured;
|
||||
else
|
||||
{
|
||||
USB_DeviceState = DEVICE_STATE_Addressed;
|
||||
}
|
||||
USB_DeviceState = DEVICE_STATE_Addressed;
|
||||
|
||||
EVENT_USB_ConfigurationChanged();
|
||||
EVENT_USB_Device_ConfigurationChanged();
|
||||
}
|
||||
|
||||
void USB_Device_GetConfiguration(void)
|
||||
|
|
|
@ -113,7 +113,7 @@
|
|||
#endif
|
||||
|
||||
/* Function Prototypes: */
|
||||
void USB_Device_ProcessControlPacket(void);
|
||||
void USB_Device_ProcessControlRequest(void);
|
||||
|
||||
#if defined(INCLUDE_FROM_DEVCHAPTER9_C)
|
||||
static void USB_Device_SetAddress(void);
|
||||
|
|
|
@ -92,8 +92,6 @@ void USB_Host_ProcessNextHostState(void)
|
|||
|
||||
USB_INT_Clear(USB_INT_VBERRI);
|
||||
USB_INT_Enable(USB_INT_VBERRI);
|
||||
|
||||
EVENT_USB_Connect();
|
||||
|
||||
USB_Host_ResumeBus();
|
||||
Pipe_ClearPipes();
|
||||
|
@ -185,19 +183,18 @@ void USB_Host_ProcessNextHostState(void)
|
|||
case HOST_STATE_Default_PostAddressSet:
|
||||
USB_Host_SetDeviceAddress(USB_HOST_DEVICEADDRESS);
|
||||
|
||||
EVENT_USB_DeviceEnumerationComplete();
|
||||
EVENT_USB_Host_DeviceEnumerationComplete();
|
||||
USB_HostState = HOST_STATE_Addressed;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((ErrorCode != HOST_ENUMERROR_NoError) && (USB_HostState != HOST_STATE_Unattached))
|
||||
{
|
||||
EVENT_USB_DeviceEnumerationFailed(ErrorCode, SubErrorCode);
|
||||
EVENT_USB_Host_DeviceEnumerationFailed(ErrorCode, SubErrorCode);
|
||||
|
||||
USB_Host_VBUS_Auto_Off();
|
||||
|
||||
EVENT_USB_DeviceUnattached();
|
||||
EVENT_USB_Disconnect();
|
||||
EVENT_USB_Host_DeviceUnattached();
|
||||
|
||||
USB_ResetInterface();
|
||||
}
|
||||
|
|
|
@ -312,7 +312,7 @@
|
|||
*/
|
||||
};
|
||||
|
||||
/** Enum for the error codes for the \ref EVENT_USB_HostError() event.
|
||||
/** Enum for the error codes for the \ref EVENT_USB_Host_HostError() event.
|
||||
*
|
||||
* \see \ref Group_Events for more information on this event.
|
||||
*/
|
||||
|
@ -326,14 +326,14 @@
|
|||
*/
|
||||
};
|
||||
|
||||
/** Enum for the error codes for the \ref EVENT_USB_DeviceEnumerationFailed() event.
|
||||
/** Enum for the error codes for the \ref EVENT_USB_Host_DeviceEnumerationFailed() event.
|
||||
*
|
||||
* \see \ref Group_Events for more information on this event.
|
||||
*/
|
||||
enum USB_Host_EnumerationErrorCodes_t
|
||||
{
|
||||
HOST_ENUMERROR_NoError = 0, /**< No error occurred. Used internally, this is not a valid
|
||||
* ErrorCode parameter value for the \ref EVENT_USB_DeviceEnumerationFailed()
|
||||
* ErrorCode parameter value for the \ref EVENT_USB_Host_DeviceEnumerationFailed()
|
||||
* event.
|
||||
*/
|
||||
HOST_ENUMERROR_WaitStage = 1, /**< One of the delays between enumeration steps failed
|
||||
|
|
|
@ -108,16 +108,6 @@ void USB_Init(
|
|||
|
||||
void USB_ShutDown(void)
|
||||
{
|
||||
#if defined(USB_CAN_BE_DEVICE)
|
||||
if (USB_DeviceState != DEVICE_STATE_Unattached)
|
||||
EVENT_USB_Disconnect();
|
||||
#endif
|
||||
|
||||
#if defined(USB_CAN_BE_HOST)
|
||||
if (USB_HostState != HOST_STATE_Unattached)
|
||||
EVENT_USB_Disconnect();
|
||||
#endif
|
||||
|
||||
USB_ResetInterface();
|
||||
USB_Detach();
|
||||
USB_Controller_Disable();
|
||||
|
@ -191,8 +181,6 @@ void USB_ResetInterface(void)
|
|||
USB_Device_SetLowSpeed();
|
||||
else
|
||||
USB_Device_SetFullSpeed();
|
||||
|
||||
USB_INT_Enable(USB_INT_VBUS);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -204,11 +192,11 @@ void USB_ResetInterface(void)
|
|||
if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DeviceDescriptorPtr) != NO_DESCRIPTOR)
|
||||
{
|
||||
#if defined(USE_RAM_DESCRIPTORS)
|
||||
USB_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size;
|
||||
USB_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size;
|
||||
#elif defined(USE_EEPROM_DESCRIPTORS)
|
||||
USB_ControlEndpointSize = eeprom_read_byte(&DeviceDescriptorPtr->Endpoint0Size);
|
||||
USB_ControlEndpointSize = eeprom_read_byte(&DeviceDescriptorPtr->Endpoint0Size);
|
||||
#else
|
||||
USB_ControlEndpointSize = pgm_read_byte(&DeviceDescriptorPtr->Endpoint0Size);
|
||||
USB_ControlEndpointSize = pgm_read_byte(&DeviceDescriptorPtr->Endpoint0Size);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -216,13 +204,19 @@ void USB_ResetInterface(void)
|
|||
|
||||
USB_Attach();
|
||||
|
||||
#if defined(USB_DEVICE_ONLY)
|
||||
#if defined(USB_DEVICE_ONLY)
|
||||
USB_INT_Clear(USB_INT_SUSPEND);
|
||||
USB_INT_Enable(USB_INT_SUSPEND);
|
||||
USB_INT_Clear(USB_INT_EORSTI);
|
||||
USB_INT_Enable(USB_INT_EORSTI);
|
||||
#if defined(CONTROL_ONLY_DEVICE)
|
||||
UENUM = ENDPOINT_CONTROLEP;
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
|
||||
USB_INT_Enable(USB_INT_VBUS);
|
||||
#endif
|
||||
|
||||
#if defined(CONTROL_ONLY_DEVICE)
|
||||
UENUM = ENDPOINT_CONTROLEP;
|
||||
#endif
|
||||
#elif defined(USB_HOST_ONLY)
|
||||
USB_Host_HostMode_On();
|
||||
|
||||
|
@ -237,9 +231,15 @@ void USB_ResetInterface(void)
|
|||
#else
|
||||
if (USB_CurrentMode == USB_MODE_DEVICE)
|
||||
{
|
||||
USB_INT_Clear(USB_INT_SUSPEND);
|
||||
USB_INT_Enable(USB_INT_SUSPEND);
|
||||
USB_INT_Clear(USB_INT_EORSTI);
|
||||
USB_INT_Enable(USB_INT_EORSTI);
|
||||
|
||||
#if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
|
||||
USB_INT_Enable(USB_INT_VBUS);
|
||||
#endif
|
||||
|
||||
#if defined(CONTROL_ONLY_DEVICE)
|
||||
UENUM = ENDPOINT_CONTROLEP;
|
||||
#endif
|
||||
|
|
|
@ -191,7 +191,7 @@
|
|||
#endif
|
||||
|
||||
/** Detaches the device from the USB bus. This has the effect of removing the device from any
|
||||
* host if, ceasing USB communications. If no host is present, this prevents any host from
|
||||
* attached host, ceasing USB communications. If no host is present, this prevents any host from
|
||||
* enumerating the device once attached until \ref USB_Attach() is called.
|
||||
*/
|
||||
#define USB_Detach() MACROS{ UDCON |= (1 << DETACH); }MACROE
|
||||
|
@ -342,7 +342,7 @@
|
|||
|
||||
#define USB_Controller_Enable() MACROS{ USBCON |= (1 << USBE); }MACROE
|
||||
#define USB_Controller_Disable() MACROS{ USBCON &= ~(1 << USBE); }MACROE
|
||||
#define USB_Controller_Reset() MACROS{ uint8_t Temp = USBCON; USBCON = (Temp & ~(1 << USBE)); \
|
||||
#define USB_Controller_Reset() MACROS{ const uint8_t Temp = USBCON; USBCON = (Temp & ~(1 << USBE)); \
|
||||
USBCON = (Temp | (1 << USBE)); }MACROE
|
||||
|
||||
/* Inline Functions: */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue