diff options
| author | Dean <Dean@d5102386-fcda-11dd-9fdb-3debd5008f28> | 2011-05-27 03:33:40 +0000 |
|---|---|---|
| committer | Dean <Dean@d5102386-fcda-11dd-9fdb-3debd5008f28> | 2011-05-27 03:33:40 +0000 |
| commit | d62e9a7debc6ec46bc9391ab3ead969be257f7a9 (patch) | |
| tree | e659843a1038393b9e7023c08665af3d7ec5603c /LUFA/Drivers | |
| parent | 01f728dc3d8f2f912583a893ed8f6f89c2bee36c (diff) | |
Merge over trunk changes to the 110528 BETA to form the 110528 release.
git-svn-id: http://lufa-lib.googlecode.com/svn/tags/LUFA-110528@1768 d5102386-fcda-11dd-9fdb-3debd5008f28
Diffstat (limited to 'LUFA/Drivers')
| -rw-r--r-- | LUFA/Drivers/USB/Class/Common/CDC.h | 4 | ||||
| -rw-r--r-- | LUFA/Drivers/USB/Class/Common/RNDIS.h | 23 | ||||
| -rw-r--r-- | LUFA/Drivers/USB/Class/Device/RNDIS.c | 126 | ||||
| -rw-r--r-- | LUFA/Drivers/USB/Class/Device/RNDIS.h | 48 | ||||
| -rw-r--r-- | LUFA/Drivers/USB/Class/Host/RNDIS.c | 9 | ||||
| -rw-r--r-- | LUFA/Drivers/USB/Class/Host/RNDIS.h | 18 | ||||
| -rw-r--r-- | LUFA/Drivers/USB/Core/AVR8/Device_AVR8.h | 22 | ||||
| -rw-r--r-- | LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.h | 5 | ||||
| -rw-r--r-- | LUFA/Drivers/USB/Core/ConfigDescriptor.c | 10 | ||||
| -rw-r--r-- | LUFA/Drivers/USB/Core/ConfigDescriptor.h | 13 | ||||
| -rw-r--r-- | LUFA/Drivers/USB/Core/Device.h | 7 | ||||
| -rw-r--r-- | LUFA/Drivers/USB/Core/DeviceStandardReq.c | 2 | ||||
| -rw-r--r-- | LUFA/Drivers/USB/Core/StdDescriptors.h | 26 | ||||
| -rw-r--r-- | LUFA/Drivers/USB/Core/UC3/Device_UC3.h | 23 | ||||
| -rw-r--r-- | LUFA/Drivers/USB/Core/UC3/Endpoint_UC3.c | 2 | ||||
| -rw-r--r-- | LUFA/Drivers/USB/Core/UC3/Pipe_UC3.c | 2 | ||||
| -rw-r--r-- | LUFA/Drivers/USB/Core/UC3/USBController_UC3.c | 2 | ||||
| -rw-r--r-- | LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.c | 8 |
18 files changed, 230 insertions, 120 deletions
diff --git a/LUFA/Drivers/USB/Class/Common/CDC.h b/LUFA/Drivers/USB/Class/Common/CDC.h index 91686d86..e74b0f1d 100644 --- a/LUFA/Drivers/USB/Class/Common/CDC.h +++ b/LUFA/Drivers/USB/Class/Common/CDC.h @@ -145,10 +145,10 @@ CDC_CSCP_ATCommandProtocol = 0x01, /**< Descriptor Protocol value indicating that the device or interface * belongs to the AT Command protocol of the CDC class. */ - CDC_CSCP_NoSpecificProtocol = 0x00, /**< Descriptor Class value indicating that the device or interface + CDC_CSCP_NoSpecificProtocol = 0x00, /**< Descriptor Protocol value indicating that the device or interface * belongs to no specific protocol of the CDC class. */ - CDC_CSCP_VendorSpecificProtocol = 0xFF, /**< Descriptor Class value indicating that the device or interface + CDC_CSCP_VendorSpecificProtocol = 0xFF, /**< Descriptor Protocol value indicating that the device or interface * belongs to a vendor-specific protocol of the CDC class. */ CDC_CSCP_CDCDataClass = 0x0A, /**< Descriptor Class value indicating that the device or interface diff --git a/LUFA/Drivers/USB/Class/Common/RNDIS.h b/LUFA/Drivers/USB/Class/Common/RNDIS.h index f98fc6d8..0ca50d5a 100644 --- a/LUFA/Drivers/USB/Class/Common/RNDIS.h +++ b/LUFA/Drivers/USB/Class/Common/RNDIS.h @@ -68,6 +68,9 @@ #endif /* Macros: */ + /** Additional error code for RNDIS functions when a device returns a logical command failure. */ + #define RNDIS_ERROR_LOGICAL_CMD_FAILED 0x80 + /** Implemented RNDIS Version Major. */ #define REMOTE_NDIS_VERSION_MAJOR 0x01 @@ -205,25 +208,25 @@ }; /* Type Defines: */ - /** \brief MAC Address Structure. + /** \brief Ethernet Frame Packet Information Structure. * - * Type define for a physical MAC address of a device on a network. + * Type define for an Ethernet frame buffer data and information structure. This can be used to conveniently + * store both the size and data in an Ethernet frame. */ typedef struct { - uint8_t Octets[6]; /**< Individual bytes of a MAC address */ - } ATTR_PACKED MAC_Address_t; + uint8_t FrameData[ETHERNET_FRAME_SIZE_MAX]; /**< Ethernet frame contents. */ + uint16_t FrameLength; /**< Length in bytes of the Ethernet frame stored in the buffer. */ + } Ethernet_Frame_Info_t; - /** \brief RNDIS Ethernet Frame Packet Information Structure. + /** \brief MAC Address Structure. * - * Type define for an Ethernet frame buffer data and information structure. + * Type define for a physical MAC address of a device on a network. */ typedef struct { - uint8_t FrameData[ETHERNET_FRAME_SIZE_MAX]; /**< Ethernet frame contents. */ - uint16_t FrameLength; /**< Length in bytes of the Ethernet frame stored in the buffer. */ - bool FrameInBuffer; /**< Indicates if a frame is currently stored in the buffer. */ - } ATTR_PACKED Ethernet_Frame_Info_t; + uint8_t Octets[6]; /**< Individual bytes of a MAC address */ + } ATTR_PACKED MAC_Address_t; /** \brief RNDIS Common Message Header Structure. * diff --git a/LUFA/Drivers/USB/Class/Device/RNDIS.c b/LUFA/Drivers/USB/Class/Device/RNDIS.c index 616af5f7..a9bbcfab 100644 --- a/LUFA/Drivers/USB/Class/Device/RNDIS.c +++ b/LUFA/Drivers/USB/Class/Device/RNDIS.c @@ -163,8 +163,6 @@ void RNDIS_Device_USBTask(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo if (USB_DeviceState != DEVICE_STATE_Configured) return; - RNDIS_Message_Header_t* MessageHeader = (RNDIS_Message_Header_t*)&RNDISInterfaceInfo->State.RNDISMessageBuffer; - Endpoint_SelectEndpoint(RNDISInterfaceInfo->Config.NotificationEndpointNumber); if (Endpoint_IsINReady() && RNDISInterfaceInfo->State.ResponseReady) @@ -184,50 +182,6 @@ void RNDIS_Device_USBTask(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo RNDISInterfaceInfo->State.ResponseReady = false; } - - if ((RNDISInterfaceInfo->State.CurrRNDISState == RNDIS_Data_Initialized) && !(MessageHeader->MessageLength)) - { - RNDIS_Packet_Message_t RNDISPacketHeader; - - Endpoint_SelectEndpoint(RNDISInterfaceInfo->Config.DataOUTEndpointNumber); - - if (Endpoint_IsOUTReceived() && !(RNDISInterfaceInfo->State.FrameIN.FrameInBuffer)) - { - Endpoint_Read_Stream_LE(&RNDISPacketHeader, sizeof(RNDIS_Packet_Message_t), NULL); - - if (RNDISPacketHeader.DataLength > ETHERNET_FRAME_SIZE_MAX) - { - Endpoint_StallTransaction(); - return; - } - - Endpoint_Read_Stream_LE(RNDISInterfaceInfo->State.FrameIN.FrameData, RNDISPacketHeader.DataLength, NULL); - - Endpoint_ClearOUT(); - - RNDISInterfaceInfo->State.FrameIN.FrameLength = RNDISPacketHeader.DataLength; - - RNDISInterfaceInfo->State.FrameIN.FrameInBuffer = true; - } - - Endpoint_SelectEndpoint(RNDISInterfaceInfo->Config.DataINEndpointNumber); - - if (Endpoint_IsINReady() && RNDISInterfaceInfo->State.FrameOUT.FrameInBuffer) - { - memset(&RNDISPacketHeader, 0, sizeof(RNDIS_Packet_Message_t)); - - RNDISPacketHeader.MessageType = REMOTE_NDIS_PACKET_MSG; - RNDISPacketHeader.MessageLength = (sizeof(RNDIS_Packet_Message_t) + RNDISInterfaceInfo->State.FrameOUT.FrameLength); - RNDISPacketHeader.DataOffset = (sizeof(RNDIS_Packet_Message_t) - sizeof(RNDIS_Message_Header_t)); - RNDISPacketHeader.DataLength = RNDISInterfaceInfo->State.FrameOUT.FrameLength; - - Endpoint_Write_Stream_LE(&RNDISPacketHeader, sizeof(RNDIS_Packet_Message_t), NULL); - Endpoint_Write_Stream_LE(RNDISInterfaceInfo->State.FrameOUT.FrameData, RNDISPacketHeader.DataLength, NULL); - Endpoint_ClearIN(); - - RNDISInterfaceInfo->State.FrameOUT.FrameInBuffer = false; - } - } } void RNDIS_Device_ProcessRNDISControlMessage(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo) @@ -493,5 +447,85 @@ static bool RNDIS_Device_ProcessNDISSet(USB_ClassInfo_RNDIS_Device_t* const RNDI } } +bool RNDIS_Device_IsPacketReceived(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo) +{ + if ((USB_DeviceState != DEVICE_STATE_Configured) || + (RNDISInterfaceInfo->State.CurrRNDISState != RNDIS_Data_Initialized)) + { + return false; + } + + Endpoint_SelectEndpoint(RNDISInterfaceInfo->Config.DataOUTEndpointNumber); + return Endpoint_IsOUTReceived(); +} + +uint8_t RNDIS_Device_ReadPacket(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo, + void* Buffer, + uint16_t* const PacketLength) +{ + if ((USB_DeviceState != DEVICE_STATE_Configured) || + (RNDISInterfaceInfo->State.CurrRNDISState != RNDIS_Data_Initialized)) + { + return ENDPOINT_RWSTREAM_DeviceDisconnected; + } + + Endpoint_SelectEndpoint(RNDISInterfaceInfo->Config.DataOUTEndpointNumber); + + *PacketLength = 0; + + if (!(Endpoint_IsOUTReceived())) + return ENDPOINT_RWSTREAM_NoError; + + RNDIS_Packet_Message_t RNDISPacketHeader; + Endpoint_Read_Stream_LE(&RNDISPacketHeader, sizeof(RNDIS_Packet_Message_t), NULL); + + if (RNDISPacketHeader.DataLength > ETHERNET_FRAME_SIZE_MAX) + { + Endpoint_StallTransaction(); + + return RNDIS_ERROR_LOGICAL_CMD_FAILED; + } + + *PacketLength = (uint16_t)RNDISPacketHeader.DataLength; + + Endpoint_Read_Stream_LE(Buffer, RNDISPacketHeader.DataLength, NULL); + Endpoint_ClearOUT(); + + return ENDPOINT_RWSTREAM_NoError; +} + +uint8_t RNDIS_Device_SendPacket(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo, + void* Buffer, + const uint16_t PacketLength) +{ + uint8_t ErrorCode; + + if ((USB_DeviceState != DEVICE_STATE_Configured) || + (RNDISInterfaceInfo->State.CurrRNDISState != RNDIS_Data_Initialized)) + { + return ENDPOINT_RWSTREAM_DeviceDisconnected; + } + + Endpoint_SelectEndpoint(RNDISInterfaceInfo->Config.DataINEndpointNumber); + + if ((ErrorCode = Endpoint_WaitUntilReady()) != ENDPOINT_READYWAIT_NoError) + return ErrorCode; + + RNDIS_Packet_Message_t RNDISPacketHeader; + + memset(&RNDISPacketHeader, 0, sizeof(RNDIS_Packet_Message_t)); + + RNDISPacketHeader.MessageType = REMOTE_NDIS_PACKET_MSG; + RNDISPacketHeader.MessageLength = (sizeof(RNDIS_Packet_Message_t) + PacketLength); + RNDISPacketHeader.DataOffset = (sizeof(RNDIS_Packet_Message_t) - sizeof(RNDIS_Message_Header_t)); + RNDISPacketHeader.DataLength = PacketLength; + + Endpoint_Write_Stream_LE(&RNDISPacketHeader, sizeof(RNDIS_Packet_Message_t), NULL); + Endpoint_Write_Stream_LE(Buffer, PacketLength, NULL); + Endpoint_ClearIN(); + + return ENDPOINT_RWSTREAM_NoError; +} + #endif diff --git a/LUFA/Drivers/USB/Class/Device/RNDIS.h b/LUFA/Drivers/USB/Class/Device/RNDIS.h index f53a8e01..734ceb3f 100644 --- a/LUFA/Drivers/USB/Class/Device/RNDIS.h +++ b/LUFA/Drivers/USB/Class/Device/RNDIS.h @@ -106,12 +106,6 @@ bool ResponseReady; /**< Internal flag indicating if a RNDIS message is waiting to be returned to the host. */ uint8_t CurrRNDISState; /**< Current RNDIS state of the adapter, a value from the \ref RNDIS_States_t enum. */ uint32_t CurrPacketFilter; /**< Current packet filter mode, used internally by the class driver. */ - Ethernet_Frame_Info_t FrameIN; /**< Structure holding the last received Ethernet frame from the host, for user - * processing. - */ - Ethernet_Frame_Info_t FrameOUT; /**< Structure holding the next Ethernet frame to send to the host, populated by the - * user application. - */ } State; /**< State data for the USB class interface within the device. All elements in this section * are reset to their defaults when the interface is enumerated. */ @@ -146,6 +140,48 @@ */ void RNDIS_Device_USBTask(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); + /** Determines if a packet is currently waiting for the device to read in and process. + * + * \pre This function must only be called when the Device state machine is in the \ref DEVICE_STATE_Configured state or the + * call will fail. + * + * \param[in,out] RNDISInterfaceInfo Pointer to a structure containing an RNDIS Class configuration and state. + * + * \return Boolean \c true if a packet is waiting to be read in by the host, \c false otherwise. + */ + bool RNDIS_Device_IsPacketReceived(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo); + + /** Retrieves the next pending packet from the device, discarding the remainder of the RNDIS packet header to leave + * only the packet contents for processing by the device in the nominated buffer. + * + * \pre This function must only be called when the Device state machine is in the \ref DEVICE_STATE_Configured state or the + * call will fail. + * + * \param[in,out] RNDISInterfaceInfo Pointer to a structure containing an RNDIS Class configuration and state. + * \param[out] Buffer Pointer to a buffer where the packer data is to be written to. + * \param[out] PacketLength Pointer to where the length in bytes of the read packet is to be stored. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t RNDIS_Device_ReadPacket(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo, + void* Buffer, + uint16_t* const PacketLength); + + /** Sends the given packet to the attached RNDIS device, after adding a RNDIS packet message header. + * + * \pre This function must only be called when the Device state machine is in the \ref DEVICE_STATE_Configured state or the + * call will fail. + * + * \param[in,out] RNDISInterfaceInfo Pointer to a structure containing an RNDIS Class configuration and state. + * \param[in] Buffer Pointer to a buffer where the packer data is to be read from. + * \param[in] PacketLength Length in bytes of the packet to send. + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t RNDIS_Device_SendPacket(USB_ClassInfo_RNDIS_Device_t* const RNDISInterfaceInfo, + void* Buffer, + const uint16_t PacketLength); + /* Private Interface - For use in library only: */ #if !defined(__DOXYGEN__) /* Function Prototypes: */ diff --git a/LUFA/Drivers/USB/Class/Host/RNDIS.c b/LUFA/Drivers/USB/Class/Host/RNDIS.c index 23497574..a75adcc9 100644 --- a/LUFA/Drivers/USB/Class/Host/RNDIS.c +++ b/LUFA/Drivers/USB/Class/Host/RNDIS.c @@ -315,7 +315,7 @@ uint8_t RNDIS_Host_InitializeDevice(USB_ClassInfo_RNDIS_Host_t* const RNDISInter } if (InitMessageResponse.Status != REMOTE_NDIS_STATUS_SUCCESS) - return RNDIS_COMMAND_FAILED; + return RNDIS_ERROR_LOGICAL_CMD_FAILED; RNDISInterfaceInfo->State.DeviceMaxPacketSize = InitMessageResponse.MaxTransferSize; @@ -361,7 +361,7 @@ uint8_t RNDIS_Host_SetRNDISProperty(USB_ClassInfo_RNDIS_Host_t* const RNDISInter } if (SetMessageResponse.Status != REMOTE_NDIS_STATUS_SUCCESS) - return RNDIS_COMMAND_FAILED; + return RNDIS_ERROR_LOGICAL_CMD_FAILED; return HOST_SENDCONTROL_Successful; } @@ -403,7 +403,7 @@ uint8_t RNDIS_Host_QueryRNDISProperty(USB_ClassInfo_RNDIS_Host_t* const RNDISInt } if (QueryMessageResponseData.QueryMessageResponse.Status != REMOTE_NDIS_STATUS_SUCCESS) - return RNDIS_COMMAND_FAILED; + return RNDIS_ERROR_LOGICAL_CMD_FAILED; memcpy(Buffer, &QueryMessageResponseData.ContiguousBuffer, MaxLength); @@ -458,7 +458,8 @@ uint8_t RNDIS_Host_ReadPacket(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceIn *PacketLength = (uint16_t)DeviceMessage.DataLength; - Pipe_Discard_Stream(DeviceMessage.DataOffset - (sizeof(RNDIS_Packet_Message_t) - sizeof(RNDIS_Message_Header_t)), + Pipe_Discard_Stream(DeviceMessage.DataOffset - + (sizeof(RNDIS_Packet_Message_t) - sizeof(RNDIS_Message_Header_t)), NULL); Pipe_Read_Stream_LE(Buffer, *PacketLength, NULL); diff --git a/LUFA/Drivers/USB/Class/Host/RNDIS.h b/LUFA/Drivers/USB/Class/Host/RNDIS.h index 376cc592..41b235bd 100644 --- a/LUFA/Drivers/USB/Class/Host/RNDIS.h +++ b/LUFA/Drivers/USB/Class/Host/RNDIS.h @@ -124,10 +124,6 @@ RNDIS_ENUMERROR_PipeConfigurationFailed = 3, /**< One or more pipes for the specified interface could not be configured correctly. */ }; - /* Macros: */ - /** Additional error code for RNDIS functions when a device returns a logical command failure. */ - #define RNDIS_COMMAND_FAILED 0xC0 - /* Function Prototypes: */ /** Host interface configuration routine, to configure a given RNDIS host interface instance using the Configuration * Descriptor read from an attached USB device. This function automatically updates the given RNDIS Host instance's @@ -154,7 +150,7 @@ * * \param[in,out] RNDISInterfaceInfo Pointer to a structure containing an RNDIS Class host configuration and state. * - * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum or \ref RNDIS_COMMAND_FAILED if the device returned a + * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum or \ref RNDIS_ERROR_LOGICAL_CMD_FAILED if the device returned a * logical command failure. */ uint8_t RNDIS_Host_SendKeepAlive(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); @@ -164,8 +160,8 @@ * * \param[in,out] RNDISInterfaceInfo Pointer to a structure containing an RNDIS Class host configuration and state. * - * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum or \ref RNDIS_COMMAND_FAILED if the device returned a - * logical command failure. + * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum or \ref RNDIS_ERROR_LOGICAL_CMD_FAILED if the + * device returned a logical command failure. */ uint8_t RNDIS_Host_InitializeDevice(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); @@ -176,8 +172,8 @@ * \param[in] Buffer Pointer to where the property data is to be sourced from. * \param[in] Length Length in bytes of the property data to sent to the device. * - * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum or \ref RNDIS_COMMAND_FAILED if the device returned a - * logical command failure. + * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum or \ref RNDIS_ERROR_LOGICAL_CMD_FAILED if the + * device returned a logical command failure. */ uint8_t RNDIS_Host_SetRNDISProperty(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo, const uint32_t Oid, @@ -191,8 +187,8 @@ * \param[in] Buffer Pointer to where the property data is to be written to. * \param[in] MaxLength Length in bytes of the destination buffer size. * - * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum or \ref RNDIS_COMMAND_FAILED if the device returned a - * logical command failure. + * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum or \ref RNDIS_ERROR_LOGICAL_CMD_FAILED if the + * device returned a logical command failure. */ uint8_t RNDIS_Host_QueryRNDISProperty(USB_ClassInfo_RNDIS_Host_t* const RNDISInterfaceInfo, const uint32_t Oid, diff --git a/LUFA/Drivers/USB/Core/AVR8/Device_AVR8.h b/LUFA/Drivers/USB/Core/AVR8/Device_AVR8.h index f88c2f1b..c98e17cd 100644 --- a/LUFA/Drivers/USB/Core/AVR8/Device_AVR8.h +++ b/LUFA/Drivers/USB/Core/AVR8/Device_AVR8.h @@ -99,16 +99,22 @@ * On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR and so will force the host to create a pseudo-serial * number for the device. */ - #define USE_INTERNAL_SERIAL 0xDC + #define USE_INTERNAL_SERIAL 0xDC /** Length of the device's unique internal serial number, in bits, if present on the selected microcontroller * model. */ - #define INTERNAL_SERIAL_LENGTH_BITS 80 + #define INTERNAL_SERIAL_LENGTH_BITS 80 + + /** Start address of the internal serial number, in the appropriate address space, if present on the selected microcontroller + * model. + */ + #define INTERNAL_SERIAL_START_ADDRESS 0x0E #else - #define USE_INTERNAL_SERIAL NO_DESCRIPTOR + #define USE_INTERNAL_SERIAL NO_DESCRIPTOR - #define INTERNAL_SERIAL_LENGTH_BITS 0 + #define INTERNAL_SERIAL_LENGTH_BITS 0 + #define INTERNAL_SERIAL_START_ADDRESS 0 #endif /* Function Prototypes: */ @@ -198,12 +204,13 @@ return (UDADDR & (1 << ADDEN)); } - static inline void USB_Device_GetSerialString(uint16_t* UnicodeString) + #if (USE_INTERNAL_SERIAL != NO_DESCRIPTOR) + static inline void USB_Device_GetSerialString(uint16_t* const UnicodeString) { uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask(); GlobalInterruptDisable(); - uint8_t SigReadAddress = 0x0E; + uint8_t SigReadAddress = INTERNAL_SERIAL_START_ADDRESS; for (uint8_t SerialCharNum = 0; SerialCharNum < (INTERNAL_SERIAL_LENGTH_BITS / 4); SerialCharNum++) { @@ -223,7 +230,8 @@ SetGlobalInterruptMask(CurrentGlobalInt); } - + #endif + #endif #endif diff --git a/LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.h b/LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.h index a6e0067e..6be41fd9 100644 --- a/LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.h +++ b/LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.h @@ -119,14 +119,15 @@ /** \name USB Controller Option Masks */ //@{ /** Regulator disable option mask for \ref USB_Init(). This indicates that the internal 3.3V USB data pad - * regulator should be enabled to regulate the data pin voltages to within the USB standard. + * regulator should be disabled and the AVR's VCC level used for the data pads. * * \note See USB AVR data sheet for more information on the internal pad regulator. */ #define USB_OPT_REG_DISABLED (1 << 1) /** Regulator enable option mask for \ref USB_Init(). This indicates that the internal 3.3V USB data pad - * regulator should be disabled and the AVR's VCC level used for the data pads. + * regulator should be enabled to regulate the data pin voltages from the VBUS level down to a level within + * the range allowable by the USB standard. * * \note See USB AVR data sheet for more information on the internal pad regulator. */ diff --git a/LUFA/Drivers/USB/Core/ConfigDescriptor.c b/LUFA/Drivers/USB/Core/ConfigDescriptor.c index 9671659d..a7f4d3ba 100644 --- a/LUFA/Drivers/USB/Core/ConfigDescriptor.c +++ b/LUFA/Drivers/USB/Core/ConfigDescriptor.c @@ -32,8 +32,10 @@ #include "ConfigDescriptor.h" #if defined(USB_CAN_BE_HOST) -uint8_t USB_Host_GetDeviceConfigDescriptor(uint8_t ConfigNumber, uint16_t* const ConfigSizePtr, - void* BufferPtr, uint16_t BufferSize) +uint8_t USB_Host_GetDeviceConfigDescriptor(const uint8_t ConfigNumber, + uint16_t* const ConfigSizePtr, + void* const BufferPtr, + const uint16_t BufferSize) { uint8_t ErrorCode; uint8_t ConfigHeader[sizeof(USB_Descriptor_Configuration_Header_t)]; @@ -114,7 +116,9 @@ void USB_GetNextDescriptorOfTypeAfter(uint16_t* const BytesRem, USB_GetNextDescriptorOfType(BytesRem, CurrConfigLoc, Type); } -uint8_t USB_GetNextDescriptorComp(uint16_t* const BytesRem, void** const CurrConfigLoc, ConfigComparatorPtr_t const ComparatorRoutine) +uint8_t USB_GetNextDescriptorComp(uint16_t* const BytesRem, + void** const CurrConfigLoc, + const ConfigComparatorPtr_t const ComparatorRoutine) { uint8_t ErrorCode; diff --git a/LUFA/Drivers/USB/Core/ConfigDescriptor.h b/LUFA/Drivers/USB/Core/ConfigDescriptor.h index 54bf14da..634dc8ff 100644 --- a/LUFA/Drivers/USB/Core/ConfigDescriptor.h +++ b/LUFA/Drivers/USB/Core/ConfigDescriptor.h @@ -166,8 +166,10 @@ * * \return A value from the \ref USB_Host_GetConfigDescriptor_ErrorCodes_t enum. */ - uint8_t USB_Host_GetDeviceConfigDescriptor(uint8_t ConfigNumber, uint16_t* const ConfigSizePtr, void* BufferPtr, - uint16_t BufferSize) ATTR_NON_NULL_PTR_ARG(2) ATTR_NON_NULL_PTR_ARG(3); + uint8_t USB_Host_GetDeviceConfigDescriptor(const uint8_t ConfigNumber, + uint16_t* const ConfigSizePtr, + void* const BufferPtr, + const uint16_t BufferSize) ATTR_NON_NULL_PTR_ARG(2) ATTR_NON_NULL_PTR_ARG(3); /** Skips to the next sub-descriptor inside the configuration descriptor of the specified type value. * The bytes remaining value is automatically decremented. @@ -254,7 +256,7 @@ */ uint8_t USB_GetNextDescriptorComp(uint16_t* const BytesRem, void** const CurrConfigLoc, - ConfigComparatorPtr_t const ComparatorRoutine); + const ConfigComparatorPtr_t const ComparatorRoutine); /* Inline Functions: */ /** Skips over the current sub-descriptor inside the configuration descriptor, so that the pointer then @@ -269,8 +271,11 @@ void** CurrConfigLoc) { uint16_t CurrDescriptorSize = DESCRIPTOR_CAST(*CurrConfigLoc, USB_Descriptor_Header_t).Size; + + if (*BytesRem < CurrDescriptorSize) + CurrDescriptorSize = *BytesRem; - *CurrConfigLoc = ((uint8_t*)*CurrConfigLoc) + CurrDescriptorSize; + *CurrConfigLoc = (void*)((uintptr_t)*CurrConfigLoc + CurrDescriptorSize); *BytesRem -= CurrDescriptorSize; } diff --git a/LUFA/Drivers/USB/Core/Device.h b/LUFA/Drivers/USB/Core/Device.h index be3dfd11..0e866241 100644 --- a/LUFA/Drivers/USB/Core/Device.h +++ b/LUFA/Drivers/USB/Core/Device.h @@ -63,6 +63,13 @@ /* Public Interface - May be used in end-application: */
/* Enums: */
+ /** Enum for the various states of the USB Device state machine. Only some states are
+ * implemented in the LUFA library - other states are left to the user to implement.
+ *
+ * For information on each possible USB device state, refer to the USB 2.0 specification.
+ *
+ * \see \ref USB_DeviceState, which stores the current device state machine state.
+ */
enum USB_Device_States_t
{
DEVICE_STATE_Unattached = 0, /**< Internally implemented by the library. This state indicates
diff --git a/LUFA/Drivers/USB/Core/DeviceStandardReq.c b/LUFA/Drivers/USB/Core/DeviceStandardReq.c index 2e6d8f8c..f9c64b6f 100644 --- a/LUFA/Drivers/USB/Core/DeviceStandardReq.c +++ b/LUFA/Drivers/USB/Core/DeviceStandardReq.c @@ -114,7 +114,7 @@ void USB_Device_ProcessControlRequest(void) static void USB_Device_SetAddress(void) { - uint8_t DeviceAddress = (USB_ControlRequest.wValue & 0x7F); + uint8_t DeviceAddress = (USB_ControlRequest.wValue & 0x7F); uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask(); GlobalInterruptDisable(); diff --git a/LUFA/Drivers/USB/Core/StdDescriptors.h b/LUFA/Drivers/USB/Core/StdDescriptors.h index 32777cc0..7840bcb8 100644 --- a/LUFA/Drivers/USB/Core/StdDescriptors.h +++ b/LUFA/Drivers/USB/Core/StdDescriptors.h @@ -612,17 +612,21 @@ { USB_Descriptor_Header_t Header; /**< Descriptor header, including type and size. */ - wchar_t UnicodeString[]; /**< String data, as unicode characters (alternatively, - * string language IDs). If normal ASCII characters are - * to be used, they must be added as an array of characters - * rather than a normal C string so that they are widened to - * Unicode size. - * - * Under GCC, strings prefixed with the "L" character (before - * the opening string quotation mark) are considered to be - * Unicode strings, and may be used instead of an explicit - * array of ASCII characters. - */ + #if (ARCH == ARCH_AVR8) + wchar_t UnicodeString[]; + #else + uint16_t UnicodeString[]; /**< String data, as unicode characters (alternatively, + * string language IDs). If normal ASCII characters are + * to be used, they must be added as an array of characters + * rather than a normal C string so that they are widened to + * Unicode size. + * + * Under GCC, strings prefixed with the "L" character (before + * the opening string quotation mark) are considered to be + * Unicode strings, and may be used instead of an explicit + * array of ASCII characters. + */ + #endif } ATTR_PACKED USB_Descriptor_String_t; /** \brief Standard USB String Descriptor (USB-IF naming conventions). diff --git a/LUFA/Drivers/USB/Core/UC3/Device_UC3.h b/LUFA/Drivers/USB/Core/UC3/Device_UC3.h index ed740985..8bc8188d 100644 --- a/LUFA/Drivers/USB/Core/UC3/Device_UC3.h +++ b/LUFA/Drivers/USB/Core/UC3/Device_UC3.h @@ -89,18 +89,24 @@ * On unsupported devices, this will evaluate to \ref NO_DESCRIPTOR and so will force the host to create a pseudo-serial
* number for the device.
*/
- #define USE_INTERNAL_SERIAL 0xDC
+ #define USE_INTERNAL_SERIAL 0xDC
/** Length of the device's unique internal serial number, in bits, if present on the selected microcontroller
* model.
*/
- #define INTERNAL_SERIAL_LENGTH_BITS 120
+ #define INTERNAL_SERIAL_LENGTH_BITS 120
+
+ /** Start address of the internal serial number, in the appropriate address space, if present on the selected microcontroller
+ * model.
+ */
+ #define INTERNAL_SERIAL_START_ADDRESS 0x80800204
#else
- #define USE_INTERNAL_SERIAL NO_DESCRIPTOR
+ #define USE_INTERNAL_SERIAL NO_DESCRIPTOR
- #define INTERNAL_SERIAL_LENGTH_BITS 0
+ #define INTERNAL_SERIAL_LENGTH_BITS 0
+ #define INTERNAL_SERIAL_START_ADDRESS 0
#endif
-
+
/* Function Prototypes: */
/** Sends a Remote Wakeup request to the host. This signals to the host that the device should
* be taken out of suspended mode, and communications should resume.
@@ -186,12 +192,13 @@ return AVR32_USBB.UDCON.adden;
}
- static inline void USB_Device_GetSerialString(uint16_t* UnicodeString)
+ #if (USE_INTERNAL_SERIAL != NO_DESCRIPTOR)
+ static inline void USB_Device_GetSerialString(uint16_t* const UnicodeString)
{
uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
GlobalInterruptDisable();
- uint8_t* SigReadAddress = (uint8_t*)0x80800204;
+ uint8_t* SigReadAddress = (uint8_t*)INTERNAL_SERIAL_START_ADDRESS;
for (uint8_t SerialCharNum = 0; SerialCharNum < (INTERNAL_SERIAL_LENGTH_BITS / 4); SerialCharNum++)
{
@@ -211,6 +218,8 @@ SetGlobalInterruptMask(CurrentGlobalInt);
}
+ #endif
+
#endif
#endif
diff --git a/LUFA/Drivers/USB/Core/UC3/Endpoint_UC3.c b/LUFA/Drivers/USB/Core/UC3/Endpoint_UC3.c index b978ec7f..9c7d6b62 100644 --- a/LUFA/Drivers/USB/Core/UC3/Endpoint_UC3.c +++ b/LUFA/Drivers/USB/Core/UC3/Endpoint_UC3.c @@ -61,7 +61,7 @@ void Endpoint_ClearEndpoints(void) {
Endpoint_SelectEndpoint(EPNum);
(&AVR32_USBB.uecfg0)[EPNum] = 0;
- (&AVR32_USBB.uecon0clr)[EPNum] = 0xFFFFFFFF;
+ (&AVR32_USBB.uecon0clr)[EPNum] = -1;
USB_EndpointFIFOPos[EPNum] = &AVR32_USBB_SLAVE[EPNum * 0x10000];
Endpoint_DisableEndpoint();
}
diff --git a/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.c b/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.c index 86bed038..92589a87 100644 --- a/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.c +++ b/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.c @@ -69,7 +69,7 @@ void Pipe_ClearPipes(void) {
Pipe_SelectPipe(PNum);
(&AVR32_USBB.upcfg0)[PNum] = 0;
- (&AVR32_USBB.upcon0clr)[PNum] = 0xFFFFFFFF;
+ (&AVR32_USBB.upcon0clr)[PNum] = -1;
USB_PipeFIFOPos[PNum] = &AVR32_USBB_SLAVE[PNum * 0x10000];
Pipe_DisablePipe();
}
diff --git a/LUFA/Drivers/USB/Core/UC3/USBController_UC3.c b/LUFA/Drivers/USB/Core/UC3/USBController_UC3.c index e3d97d68..0b0d04d6 100644 --- a/LUFA/Drivers/USB/Core/UC3/USBController_UC3.c +++ b/LUFA/Drivers/USB/Core/UC3/USBController_UC3.c @@ -72,6 +72,8 @@ void USB_Init( AVR32_USBB.USBCON.uide = false;
USB_CurrentMode = Mode;
}
+ #else
+ AVR32_USBB.USBCON.uide = false;
#endif
USB_IsInitialized = true;
diff --git a/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.c b/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.c index 76f4ef02..5191ee67 100644 --- a/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.c +++ b/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.c @@ -36,8 +36,8 @@ void USB_INT_DisableAllInterrupts(void) AVR32_USBB.USBCON.vbuste = false;
AVR32_USBB.USBCON.idte = false;
- AVR32_USBB.uhinteclr = 0xFFFFFFFF;
- AVR32_USBB.udinteclr = 0xFFFFFFFF;
+ AVR32_USBB.uhinteclr = -1;
+ AVR32_USBB.udinteclr = -1;
}
void USB_INT_ClearAllInterrupts(void)
@@ -45,8 +45,8 @@ void USB_INT_ClearAllInterrupts(void) AVR32_USBB.USBSTACLR.vbustic = true;
AVR32_USBB.USBSTACLR.idtic = true;
- AVR32_USBB.uhintclr = 0xFFFFFFFF;
- AVR32_USBB.udintclr = 0xFFFFFFFF;
+ AVR32_USBB.uhintclr = -1;
+ AVR32_USBB.udintclr = -1;
}
ISR(USB_GEN_vect)
|
