aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2011-05-10 16:41:37 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2011-05-10 16:41:37 -0400
commit9cfd9ba5d6e2933e72dd93b048e62b9e9494fafb (patch)
treec002f6a389e38576fec44777557e62064e342d02 /libmaple
parent19ea6ba4ea3f1ecb9830cf4d3e1366513f4f96e3 (diff)
downloadlibrambutan-9cfd9ba5d6e2933e72dd93b048e62b9e9494fafb.tar.gz
librambutan-9cfd9ba5d6e2933e72dd93b048e62b9e9494fafb.zip
Converting all files to UNIX newlines.
Committing the results of running the following on the libmaple root directory: $ fromdos `grep --exclude-dir='[.]git' -Ilsr $'\r$' .`
Diffstat (limited to 'libmaple')
-rw-r--r--libmaple/usb/usb_lib/usb_core.c2026
-rw-r--r--libmaple/usb/usb_lib/usb_core.h502
-rw-r--r--libmaple/usb/usb_lib/usb_def.h176
-rw-r--r--libmaple/usb/usb_lib/usb_init.c128
-rw-r--r--libmaple/usb/usb_lib/usb_init.h114
-rw-r--r--libmaple/usb/usb_lib/usb_int.c384
-rw-r--r--libmaple/usb/usb_lib/usb_int.h82
-rw-r--r--libmaple/usb/usb_lib/usb_lib.h74
-rw-r--r--libmaple/usb/usb_lib/usb_mem.c146
-rw-r--r--libmaple/usb/usb_lib/usb_mem.h80
-rw-r--r--libmaple/usb/usb_lib/usb_regs.c1496
-rw-r--r--libmaple/usb/usb_lib/usb_regs.h1254
-rw-r--r--libmaple/usb/usb_lib/usb_type.h154
13 files changed, 3308 insertions, 3308 deletions
diff --git a/libmaple/usb/usb_lib/usb_core.c b/libmaple/usb/usb_lib/usb_core.c
index afe8798..5cf9e87 100644
--- a/libmaple/usb/usb_lib/usb_core.c
+++ b/libmaple/usb/usb_lib/usb_core.c
@@ -1,1013 +1,1013 @@
-/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
-* File Name : usb_core.c
-* Author : MCD Application Team
-* Version : V2.2.1
-* Date : 09/22/2008
-* Description : Standard protocol processing (USB v2.0)
-********************************************************************************
-* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
-* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
-* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
-* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
-* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
-* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
-*******************************************************************************/
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_lib.h"
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-#define ValBit(VAR,Place) (VAR & (1 << Place))
-#define SetBit(VAR,Place) (VAR |= (1 << Place))
-#define ClrBit(VAR,Place) (VAR &= ((1 << Place) ^ 255))
-
-#define Send0LengthData() { _SetEPTxCount(ENDP0, 0); \
- vSetEPTxStatus(EP_TX_VALID); \
- }
-
-#define vSetEPRxStatus(st) (SaveRState = st)
-#define vSetEPTxStatus(st) (SaveTState = st)
-
-#define USB_StatusIn() Send0LengthData()
-#define USB_StatusOut() vSetEPRxStatus(EP_RX_VALID)
-
-#define StatusInfo0 StatusInfo.bw.bb1 /* Reverse bb0 & bb1 */
-#define StatusInfo1 StatusInfo.bw.bb0
-
-/* Private macro -------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-u16_u8 StatusInfo;
-USB_Bool Data_Mul_MaxPacketSize = FALSE;
-/* Private function prototypes -----------------------------------------------*/
-static void DataStageOut(void);
-static void DataStageIn(void);
-static void NoData_Setup0(void);
-static void Data_Setup0(void);
-/* Private functions ---------------------------------------------------------*/
-
-/*******************************************************************************
-* Function Name : Standard_GetConfiguration.
-* Description : Return the current configuration variable address.
-* Input : Length - How many bytes are needed.
-* Output : None.
-* Return : Return 1 , if the request is invalid when "Length" is 0.
-* Return "Buffer" if the "Length" is not 0.
-*******************************************************************************/
-u8 *Standard_GetConfiguration(u16 Length)
-{
- if (Length == 0)
- {
- pInformation->Ctrl_Info.Usb_wLength =
- sizeof(pInformation->Current_Configuration);
- return 0;
- }
- pUser_Standard_Requests->User_GetConfiguration();
- return (u8 *)&pInformation->Current_Configuration;
-}
-
-/*******************************************************************************
-* Function Name : Standard_SetConfiguration.
-* Description : This routine is called to set the configuration value
-* Then each class should configure device themself.
-* Input : None.
-* Output : None.
-* Return : Return USB_SUCCESS, if the request is performed.
-* Return USB_UNSUPPORT, if the request is invalid.
-*******************************************************************************/
-RESULT Standard_SetConfiguration(void)
-{
-
- if ((pInformation->USBwValue0 <=
- Device_Table.Total_Configuration) && (pInformation->USBwValue1 == 0)
- && (pInformation->USBwIndex == 0)) /*call Back usb spec 2.0*/
- {
- pInformation->Current_Configuration = pInformation->USBwValue0;
- pUser_Standard_Requests->User_SetConfiguration();
- return USB_SUCCESS;
- }
- else
- {
- return USB_UNSUPPORT;
- }
-}
-
-/*******************************************************************************
-* Function Name : Standard_GetInterface.
-* Description : Return the Alternate Setting of the current interface.
-* Input : Length - How many bytes are needed.
-* Output : None.
-* Return : Return 0, if the request is invalid when "Length" is 0.
-* Return "Buffer" if the "Length" is not 0.
-*******************************************************************************/
-u8 *Standard_GetInterface(u16 Length)
-{
- if (Length == 0)
- {
- pInformation->Ctrl_Info.Usb_wLength =
- sizeof(pInformation->Current_AlternateSetting);
- return 0;
- }
- pUser_Standard_Requests->User_GetInterface();
- return (u8 *)&pInformation->Current_AlternateSetting;
-}
-
-/*******************************************************************************
-* Function Name : Standard_SetInterface.
-* Description : This routine is called to set the interface.
-* Then each class should configure the interface them self.
-* Input : None.
-* Output : None.
-* Return : - Return USB_SUCCESS, if the request is performed.
-* - Return USB_UNSUPPORT, if the request is invalid.
-*******************************************************************************/
-RESULT Standard_SetInterface(void)
-{
- RESULT Re;
- /*Test if the specified Interface and Alternate Setting are supported by
- the application Firmware*/
- Re = (*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, pInformation->USBwValue0);
-
- if (pInformation->Current_Configuration != 0)
- {
- if ((Re != USB_SUCCESS) || (pInformation->USBwIndex1 != 0)
- || (pInformation->USBwValue1 != 0))
- {
- return USB_UNSUPPORT;
- }
- else if (Re == USB_SUCCESS)
- {
- pUser_Standard_Requests->User_SetInterface();
- pInformation->Current_Interface = pInformation->USBwIndex0;
- pInformation->Current_AlternateSetting = pInformation->USBwValue0;
- return USB_SUCCESS;
- }
-
- }
-
- return USB_UNSUPPORT;
-}
-
-/*******************************************************************************
-* Function Name : Standard_GetStatus.
-* Description : Copy the device request data to "StatusInfo buffer".
-* Input : - Length - How many bytes are needed.
-* Output : None.
-* Return : Return 0, if the request is at end of data block,
-* or is invalid when "Length" is 0.
-*******************************************************************************/
-u8 *Standard_GetStatus(u16 Length)
-{
- if (Length == 0)
- {
- pInformation->Ctrl_Info.Usb_wLength = 2;
- return 0;
- }
-
- StatusInfo.w = 0;
- /* Reset Status Information */
-
- if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
- {
- /*Get Device Status */
- u8 Feature = pInformation->Current_Feature;
-
- /* Remote Wakeup enabled */
- if (ValBit(Feature, 5))
- {
- SetBit(StatusInfo0, 1);
- }
-
- /* Bus-powered */
- if (ValBit(Feature, 6))
- {
- ClrBit(StatusInfo0, 0);
- }
- else /* Self-powered */
- {
- SetBit(StatusInfo0, 0);
- }
- }
- /*Interface Status*/
- else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
- {
- return (u8 *)&StatusInfo;
- }
- /*Get EndPoint Status*/
- else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
- {
- u8 Related_Endpoint;
- u8 wIndex0 = pInformation->USBwIndex0;
-
- Related_Endpoint = (wIndex0 & 0x0f);
- if (ValBit(wIndex0, 7))
- {
- /* IN endpoint */
- if (_GetTxStallStatus(Related_Endpoint))
- {
- SetBit(StatusInfo0, 0); /* IN Endpoint stalled */
- }
- }
- else
- {
- /* OUT endpoint */
- if (_GetRxStallStatus(Related_Endpoint))
- {
- SetBit(StatusInfo0, 0); /* OUT Endpoint stalled */
- }
- }
-
- }
- else
- {
- return NULL;
- }
- pUser_Standard_Requests->User_GetStatus();
- return (u8 *)&StatusInfo;
-}
-
-/*******************************************************************************
-* Function Name : Standard_ClearFeature.
-* Description : Clear or disable a specific feature.
-* Input : None.
-* Output : None.
-* Return : - Return USB_SUCCESS, if the request is performed.
-* - Return USB_UNSUPPORT, if the request is invalid.
-*******************************************************************************/
-RESULT Standard_ClearFeature(void)
-{
- u32 Type_Rec = Type_Recipient;
- u32 Status;
-
-
- if (Type_Rec == (STANDARD_REQUEST | DEVICE_RECIPIENT))
- {/*Device Clear Feature*/
- ClrBit(pInformation->Current_Feature, 5);
- return USB_SUCCESS;
- }
- else if (Type_Rec == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
- {/*EndPoint Clear Feature*/
- DEVICE* pDev;
- u32 Related_Endpoint;
- u32 wIndex0;
- u32 rEP;
-
- if ((pInformation->USBwValue != ENDPOINT_STALL)
- || (pInformation->USBwIndex1 != 0))
- {
- return USB_UNSUPPORT;
- }
-
- pDev = &Device_Table;
- wIndex0 = pInformation->USBwIndex0;
- rEP = wIndex0 & ~0x80;
- Related_Endpoint = ENDP0 + rEP;
-
- if (ValBit(pInformation->USBwIndex0, 7))
- {
- /*Get Status of endpoint & stall the request if the related_ENdpoint
- is Disabled*/
- Status = _GetEPTxStatus(Related_Endpoint);
- }
- else
- {
- Status = _GetEPRxStatus(Related_Endpoint);
- }
-
- if ((rEP >= pDev->Total_Endpoint) || (Status == 0)
- || (pInformation->Current_Configuration == 0))
- {
- return USB_UNSUPPORT;
- }
-
-
- if (wIndex0 & 0x80)
- {
- /* IN endpoint */
- if (_GetTxStallStatus(Related_Endpoint ))
- {
- ClearDTOG_TX(Related_Endpoint);
- SetEPTxStatus(Related_Endpoint, EP_TX_VALID);
- }
- }
- else
- {
- /* OUT endpoint */
- if (_GetRxStallStatus(Related_Endpoint))
- {
- if (Related_Endpoint == ENDP0)
- {
- /* After clear the STALL, enable the default endpoint receiver */
- SetEPRxCount(Related_Endpoint, Device_Property.MaxPacketSize);
- _SetEPRxStatus(Related_Endpoint, EP_RX_VALID);
- }
- else
- {
- ClearDTOG_RX(Related_Endpoint);
- _SetEPRxStatus(Related_Endpoint, EP_RX_VALID);
- }
- }
- }
- pUser_Standard_Requests->User_ClearFeature();
- return USB_SUCCESS;
- }
-
- return USB_UNSUPPORT;
-}
-
-/*******************************************************************************
-* Function Name : Standard_SetEndPointFeature
-* Description : Set or enable a specific feature of EndPoint
-* Input : None.
-* Output : None.
-* Return : - Return USB_SUCCESS, if the request is performed.
-* - Return USB_UNSUPPORT, if the request is invalid.
-*******************************************************************************/
-RESULT Standard_SetEndPointFeature(void)
-{
- u32 wIndex0;
- u32 Related_Endpoint;
- u32 rEP;
- u32 Status;
-
- wIndex0 = pInformation->USBwIndex0;
- rEP = wIndex0 & ~0x80;
- Related_Endpoint = ENDP0 + rEP;
-
- if (ValBit(pInformation->USBwIndex0, 7))
- {
- /* get Status of endpoint & stall the request if the related_ENdpoint
- is Disabled*/
- Status = _GetEPTxStatus(Related_Endpoint);
- }
- else
- {
- Status = _GetEPRxStatus(Related_Endpoint);
- }
-
- if (Related_Endpoint >= Device_Table.Total_Endpoint
- || pInformation->USBwValue != 0 || Status == 0
- || pInformation->Current_Configuration == 0)
- {
- return USB_UNSUPPORT;
- }
- else
- {
- if (wIndex0 & 0x80)
- {
- /* IN endpoint */
- _SetEPTxStatus(Related_Endpoint, EP_TX_STALL);
- }
-
- else
- {
- /* OUT endpoint */
- _SetEPRxStatus(Related_Endpoint, EP_RX_STALL);
- }
- }
- pUser_Standard_Requests->User_SetEndPointFeature();
- return USB_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name : Standard_SetDeviceFeature.
-* Description : Set or enable a specific feature of Device.
-* Input : None.
-* Output : None.
-* Return : - Return USB_SUCCESS, if the request is performed.
-* - Return USB_UNSUPPORT, if the request is invalid.
-*******************************************************************************/
-RESULT Standard_SetDeviceFeature(void)
-{
- SetBit(pInformation->Current_Feature, 5);
- pUser_Standard_Requests->User_SetDeviceFeature();
- return USB_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name : Standard_GetDescriptorData.
-* Description : Standard_GetDescriptorData is used for descriptors transfer.
-* : This routine is used for the descriptors resident in Flash
-* or RAM
-* pDesc can be in either Flash or RAM
-* The purpose of this routine is to have a versatile way to
-* response descriptors request. It allows user to generate
-* certain descriptors with software or read descriptors from
-* external storage part by part.
-* Input : - Length - Length of the data in this transfer.
-* - pDesc - A pointer points to descriptor struct.
-* The structure gives the initial address of the descriptor and
-* its original size.
-* Output : None.
-* Return : Address of a part of the descriptor pointed by the Usb_
-* wOffset The buffer pointed by this address contains at least
-* Length bytes.
-*******************************************************************************/
-u8 *Standard_GetDescriptorData(u16 Length, ONE_DESCRIPTOR *pDesc)
-{
- u32 wOffset;
-
- wOffset = pInformation->Ctrl_Info.Usb_wOffset;
- if (Length == 0)
- {
- pInformation->Ctrl_Info.Usb_wLength = pDesc->Descriptor_Size - wOffset;
- return 0;
- }
-
- return pDesc->Descriptor + wOffset;
-}
-
-/*******************************************************************************
-* Function Name : DataStageOut.
-* Description : Data stage of a Control Write Transfer.
-* Input : None.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void DataStageOut(void)
-{
- ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info;
- u32 save_rLength;
-
- save_rLength = pEPinfo->Usb_rLength;
-
- if (pEPinfo->CopyData && save_rLength)
- {
- u8 *Buffer;
- u32 Length;
-
- Length = pEPinfo->PacketSize;
- if (Length > save_rLength)
- {
- Length = save_rLength;
- }
-
- Buffer = (*pEPinfo->CopyData)(Length);
- pEPinfo->Usb_rLength -= Length;
- pEPinfo->Usb_rOffset += Length;
-
- PMAToUserBufferCopy(Buffer, GetEPRxAddr(ENDP0), Length);
- }
-
- if (pEPinfo->Usb_rLength != 0)
- {
- vSetEPRxStatus(EP_RX_VALID);/* re-enable for next data reception */
- SetEPTxCount(ENDP0, 0);
- vSetEPTxStatus(EP_TX_VALID);/* Expect the host to abort the data OUT stage */
- }
- /* Set the next State*/
- if (pEPinfo->Usb_rLength >= pEPinfo->PacketSize)
- {
- pInformation->ControlState = OUT_DATA;
- }
- else
- {
- if (pEPinfo->Usb_rLength > 0)
- {
- pInformation->ControlState = LAST_OUT_DATA;
- }
- else if (pEPinfo->Usb_rLength == 0)
- {
- pInformation->ControlState = WAIT_STATUS_IN;
- USB_StatusIn();
- }
- }
-}
-
-/*******************************************************************************
-* Function Name : DataStageIn.
-* Description : Data stage of a Control Read Transfer.
-* Input : None.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void DataStageIn(void)
-{
- ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info;
- u32 save_wLength = pEPinfo->Usb_wLength;
- u32 ControlState = pInformation->ControlState;
-
- u8 *DataBuffer;
- u32 Length;
-
- if ((save_wLength == 0) && (ControlState == LAST_IN_DATA))
- {
- if(Data_Mul_MaxPacketSize == TRUE)
- {
- /* No more data to send and empty packet */
- Send0LengthData();
- ControlState = LAST_IN_DATA;
- Data_Mul_MaxPacketSize = FALSE;
- }
- else
- {
- /* No more data to send so STALL the TX Status*/
- ControlState = WAIT_STATUS_OUT;
- vSetEPTxStatus(EP_TX_STALL);
- }
-
- goto Expect_Status_Out;
- }
-
- Length = pEPinfo->PacketSize;
- ControlState = (save_wLength <= Length) ? LAST_IN_DATA : IN_DATA;
-
- if (Length > save_wLength)
- {
- Length = save_wLength;
- }
-
- DataBuffer = (*pEPinfo->CopyData)(Length);
-
- UserToPMABufferCopy(DataBuffer, GetEPTxAddr(ENDP0), Length);
-
- SetEPTxCount(ENDP0, Length);
-
- pEPinfo->Usb_wLength -= Length;
- pEPinfo->Usb_wOffset += Length;
- vSetEPTxStatus(EP_TX_VALID);
-
- USB_StatusOut();/* Expect the host to abort the data IN stage */
-
-Expect_Status_Out:
- pInformation->ControlState = ControlState;
-}
-
-/*******************************************************************************
-* Function Name : NoData_Setup0.
-* Description : Proceed the processing of setup request without data stage.
-* Input : None.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void NoData_Setup0(void)
-{
- RESULT Result = USB_UNSUPPORT;
- u32 RequestNo = pInformation->USBbRequest;
- u32 ControlState;
-
- if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
- {
- /* Device Request*/
- /* SET_CONFIGURATION*/
- if (RequestNo == SET_CONFIGURATION)
- {
- Result = Standard_SetConfiguration();
- }
-
- /*SET ADDRESS*/
- else if (RequestNo == SET_ADDRESS)
- {
- if ((pInformation->USBwValue0 > 127) || (pInformation->USBwValue1 != 0)
- || (pInformation->USBwIndex != 0)
- || (pInformation->Current_Configuration != 0))
- /* Device Address should be 127 or less*/
- {
- ControlState = STALLED;
- goto exit_NoData_Setup0;
- }
- else
- {
- Result = USB_SUCCESS;
- }
- }
- /*SET FEATURE for Device*/
- else if (RequestNo == SET_FEATURE)
- {
- if ((pInformation->USBwValue0 == DEVICE_REMOTE_WAKEUP)
- && (pInformation->USBwIndex == 0)
- && (ValBit(pInformation->Current_Feature, 5)))
- {
- Result = Standard_SetDeviceFeature();
- }
- else
- {
- Result = USB_UNSUPPORT;
- }
- }
- /*Clear FEATURE for Device */
- else if (RequestNo == CLEAR_FEATURE)
- {
- if (pInformation->USBwValue0 == DEVICE_REMOTE_WAKEUP
- && pInformation->USBwIndex == 0
- && ValBit(pInformation->Current_Feature, 5))
- {
- Result = Standard_ClearFeature();
- }
- else
- {
- Result = USB_UNSUPPORT;
- }
- }
-
- }
-
- /* Interface Request*/
- else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
- {
- /*SET INTERFACE*/
- if (RequestNo == SET_INTERFACE)
- {
- Result = Standard_SetInterface();
- }
- }
-
- /* EndPoint Request*/
- else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
- {
- /*CLEAR FEATURE for EndPoint*/
- if (RequestNo == CLEAR_FEATURE)
- {
- Result = Standard_ClearFeature();
- }
- /* SET FEATURE for EndPoint*/
- else if (RequestNo == SET_FEATURE)
- {
- Result = Standard_SetEndPointFeature();
- }
- }
- else
- {
- Result = USB_UNSUPPORT;
- }
-
-
- if (Result != USB_SUCCESS)
- {
- Result = (*pProperty->Class_NoData_Setup)(RequestNo);
- if (Result == USB_NOT_READY)
- {
- ControlState = PAUSE;
- goto exit_NoData_Setup0;
- }
- }
-
- if (Result != USB_SUCCESS)
- {
- ControlState = STALLED;
- goto exit_NoData_Setup0;
- }
-
- ControlState = WAIT_STATUS_IN;/* After no data stage SETUP */
-
- USB_StatusIn();
-
-exit_NoData_Setup0:
- pInformation->ControlState = ControlState;
- return;
-}
-
-/*******************************************************************************
-* Function Name : Data_Setup0.
-* Description : Proceed the processing of setup request with data stage.
-* Input : None.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void Data_Setup0(void)
-{
- u8 *(*CopyRoutine)(u16);
- RESULT Result;
- u32 Request_No = pInformation->USBbRequest;
-
- u32 Related_Endpoint, Reserved;
- u32 wOffset, Status;
-
-
-
- CopyRoutine = NULL;
- wOffset = 0;
-
- if (Request_No == GET_DESCRIPTOR)
- {
- if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
- {
- u8 wValue1 = pInformation->USBwValue1;
- if (wValue1 == DEVICE_DESCRIPTOR)
- {
- CopyRoutine = pProperty->GetDeviceDescriptor;
- }
- else if (wValue1 == CONFIG_DESCRIPTOR)
- {
- CopyRoutine = pProperty->GetConfigDescriptor;
- }
- else if (wValue1 == STRING_DESCRIPTOR)
- {
- CopyRoutine = pProperty->GetStringDescriptor;
- } /* End of GET_DESCRIPTOR */
- }
- }
-
- /*GET STATUS*/
- else if ((Request_No == GET_STATUS) && (pInformation->USBwValue == 0)
- && (pInformation->USBwLength == 0x0002)
- && (pInformation->USBwIndex1 == 0))
- {
- /* GET STATUS for Device*/
- if ((Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
- && (pInformation->USBwIndex == 0))
- {
- CopyRoutine = Standard_GetStatus;
- }
-
- /* GET STATUS for Interface*/
- else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
- {
- if (((*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, 0) == USB_SUCCESS)
- && (pInformation->Current_Configuration != 0))
- {
- CopyRoutine = Standard_GetStatus;
- }
- }
-
- /* GET STATUS for EndPoint*/
- else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
- {
- Related_Endpoint = (pInformation->USBwIndex0 & 0x0f);
- Reserved = pInformation->USBwIndex0 & 0x70;
-
- if (ValBit(pInformation->USBwIndex0, 7))
- {
- /*Get Status of endpoint & stall the request if the related_ENdpoint
- is Disabled*/
- Status = _GetEPTxStatus(Related_Endpoint);
- }
- else
- {
- Status = _GetEPRxStatus(Related_Endpoint);
- }
-
- if ((Related_Endpoint < Device_Table.Total_Endpoint) && (Reserved == 0)
- && (Status != 0))
- {
- CopyRoutine = Standard_GetStatus;
- }
- }
-
- }
-
- /*GET CONFIGURATION*/
- else if (Request_No == GET_CONFIGURATION)
- {
- if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
- {
- CopyRoutine = Standard_GetConfiguration;
- }
- }
- /*GET INTERFACE*/
- else if (Request_No == GET_INTERFACE)
- {
- if ((Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
- && (pInformation->Current_Configuration != 0) && (pInformation->USBwValue == 0)
- && (pInformation->USBwIndex1 == 0) && (pInformation->USBwLength == 0x0001)
- && ((*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, 0) == USB_SUCCESS))
- {
- CopyRoutine = Standard_GetInterface;
- }
-
- }
-
- if (CopyRoutine)
- {
- pInformation->Ctrl_Info.Usb_wOffset = wOffset;
- pInformation->Ctrl_Info.CopyData = CopyRoutine;
- /* sb in the original the cast to word was directly */
- /* now the cast is made step by step */
- (*CopyRoutine)(0);
- Result = USB_SUCCESS;
- }
- else
- {
- Result = (*pProperty->Class_Data_Setup)(pInformation->USBbRequest);
- if (Result == USB_NOT_READY)
- {
- pInformation->ControlState = PAUSE;
- return;
- }
- }
-
- if (pInformation->Ctrl_Info.Usb_wLength == 0xFFFF)
- {
- /* Data is not ready, wait it */
- pInformation->ControlState = PAUSE;
- return;
- }
- if ((Result == USB_UNSUPPORT) || (pInformation->Ctrl_Info.Usb_wLength == 0))
- {
- /* Unsupported request */
- pInformation->ControlState = STALLED;
- return;
- }
-
-
- if (ValBit(pInformation->USBbmRequestType, 7))
- {
- /* Device ==> Host */
- vu32 wLength = pInformation->USBwLength;
-
- /* Restrict the data length to be the one host asks */
- if (pInformation->Ctrl_Info.Usb_wLength > wLength)
- {
- pInformation->Ctrl_Info.Usb_wLength = wLength;
- }
-
- else if (pInformation->Ctrl_Info.Usb_wLength < pInformation->USBwLength)
- {
- if (pInformation->Ctrl_Info.Usb_wLength < pProperty->MaxPacketSize)
- {
- Data_Mul_MaxPacketSize = FALSE;
- }
- else if ((pInformation->Ctrl_Info.Usb_wLength % pProperty->MaxPacketSize) == 0)
- {
- Data_Mul_MaxPacketSize = TRUE;
- }
- }
-
- pInformation->Ctrl_Info.PacketSize = pProperty->MaxPacketSize;
- DataStageIn();
- }
- else
- {
- pInformation->ControlState = OUT_DATA;
- vSetEPRxStatus(EP_RX_VALID); /* enable for next data reception */
- }
-
- return;
-}
-
-/*******************************************************************************
-* Function Name : Setup0_Process
-* Description : Get the device request data and dispatch to individual process.
-* Input : None.
-* Output : None.
-* Return : Post0_Process.
-*******************************************************************************/
-u8 Setup0_Process(void)
-{
-
- union
- {
- u8* b;
- u16* w;
- } pBuf;
-
- pBuf.b = PMAAddr + (u8 *)(_GetEPRxAddr(ENDP0) * 2); /* *2 for 32 bits addr */
-
- if (pInformation->ControlState != PAUSE)
- {
- pInformation->USBbmRequestType = *pBuf.b++; /* bmRequestType */
- pInformation->USBbRequest = *pBuf.b++; /* bRequest */
- pBuf.w++; /* word not accessed because of 32 bits addressing */
- pInformation->USBwValue = ByteSwap(*pBuf.w++); /* wValue */
- pBuf.w++; /* word not accessed because of 32 bits addressing */
- pInformation->USBwIndex = ByteSwap(*pBuf.w++); /* wIndex */
- pBuf.w++; /* word not accessed because of 32 bits addressing */
- pInformation->USBwLength = *pBuf.w; /* wLength */
- }
-
- pInformation->ControlState = SETTING_UP;
- if (pInformation->USBwLength == 0)
- {
- /* Setup with no data stage */
- NoData_Setup0();
- }
- else
- {
- /* Setup with data stage */
- Data_Setup0();
- }
- return Post0_Process();
-}
-
-/*******************************************************************************
-* Function Name : In0_Process
-* Description : Process the IN token on all default endpoint.
-* Input : None.
-* Output : None.
-* Return : Post0_Process.
-*******************************************************************************/
-u8 In0_Process(void)
-{
- u32 ControlState = pInformation->ControlState;
-
- if ((ControlState == IN_DATA) || (ControlState == LAST_IN_DATA))
- {
- DataStageIn();
- /* ControlState may be changed outside the function */
- ControlState = pInformation->ControlState;
- }
-
- else if (ControlState == WAIT_STATUS_IN)
- {
- if ((pInformation->USBbRequest == SET_ADDRESS) &&
- (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)))
- {
- SetDeviceAddress(pInformation->USBwValue0);
- pUser_Standard_Requests->User_SetDeviceAddress();
- }
- (*pProperty->Process_Status_IN)();
- ControlState = STALLED;
- }
-
- else
- {
- ControlState = STALLED;
- }
-
- pInformation->ControlState = ControlState;
-
- return Post0_Process();
-}
-
-/*******************************************************************************
-* Function Name : Out0_Process
-* Description : Process the OUT token on all default endpoint.
-* Input : None.
-* Output : None.
-* Return : Post0_Process.
-*******************************************************************************/
-u8 Out0_Process(void)
-{
- u32 ControlState = pInformation->ControlState;
-
- if ((ControlState == OUT_DATA) || (ControlState == LAST_OUT_DATA))
- {
- DataStageOut();
- ControlState = pInformation->ControlState; /* may be changed outside the function */
- }
-
- else if (ControlState == WAIT_STATUS_OUT)
- {
- (*pProperty->Process_Status_OUT)();
- ControlState = STALLED;
- }
-
- else if ((ControlState == IN_DATA) || (ControlState == LAST_IN_DATA))
- {
- /* host aborts the transfer before finish */
- ControlState = STALLED;
- }
-
- /* Unexpect state, STALL the endpoint */
- else
- {
- ControlState = STALLED;
- }
-
- pInformation->ControlState = ControlState;
-
- return Post0_Process();
-}
-
-/*******************************************************************************
-* Function Name : Post0_Process
-* Description : Stall the Endpoint 0 in case of error.
-* Input : None.
-* Output : None.
-* Return : - 0 if the control State is in PAUSE
-* - 1 if not.
-*******************************************************************************/
-u8 Post0_Process(void)
-{
- SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
-
- if (pInformation->ControlState == STALLED)
- {
- vSetEPRxStatus(EP_RX_STALL);
- vSetEPTxStatus(EP_TX_STALL);
- }
-
- return (pInformation->ControlState == PAUSE);
-}
-
-/*******************************************************************************
-* Function Name : SetDeviceAddress.
-* Description : Set the device and all the used Endpoints addresses.
-* Input : - Val: device adress.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetDeviceAddress(u8 Val)
-{
- u32 i;
- u32 nEP = Device_Table.Total_Endpoint;
-
- /* set address in every used endpoint */
- for (i = 0; i < nEP; i++)
- {
- _SetEPAddress((u8)i, (u8)i);
- } /* for */
- _SetDADDR(Val | DADDR_EF); /* set device address and enable function */
-}
-
-/*******************************************************************************
-* Function Name : NOP_Process
-* Description : No operation function.
-* Input : None.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void NOP_Process(void)
-{
-}
-
-/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_core.c
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Standard protocol processing (USB v2.0)
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Includes ------------------------------------------------------------------*/
+#include "usb_lib.h"
+/* Private typedef -----------------------------------------------------------*/
+/* Private define ------------------------------------------------------------*/
+#define ValBit(VAR,Place) (VAR & (1 << Place))
+#define SetBit(VAR,Place) (VAR |= (1 << Place))
+#define ClrBit(VAR,Place) (VAR &= ((1 << Place) ^ 255))
+
+#define Send0LengthData() { _SetEPTxCount(ENDP0, 0); \
+ vSetEPTxStatus(EP_TX_VALID); \
+ }
+
+#define vSetEPRxStatus(st) (SaveRState = st)
+#define vSetEPTxStatus(st) (SaveTState = st)
+
+#define USB_StatusIn() Send0LengthData()
+#define USB_StatusOut() vSetEPRxStatus(EP_RX_VALID)
+
+#define StatusInfo0 StatusInfo.bw.bb1 /* Reverse bb0 & bb1 */
+#define StatusInfo1 StatusInfo.bw.bb0
+
+/* Private macro -------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+u16_u8 StatusInfo;
+USB_Bool Data_Mul_MaxPacketSize = FALSE;
+/* Private function prototypes -----------------------------------------------*/
+static void DataStageOut(void);
+static void DataStageIn(void);
+static void NoData_Setup0(void);
+static void Data_Setup0(void);
+/* Private functions ---------------------------------------------------------*/
+
+/*******************************************************************************
+* Function Name : Standard_GetConfiguration.
+* Description : Return the current configuration variable address.
+* Input : Length - How many bytes are needed.
+* Output : None.
+* Return : Return 1 , if the request is invalid when "Length" is 0.
+* Return "Buffer" if the "Length" is not 0.
+*******************************************************************************/
+u8 *Standard_GetConfiguration(u16 Length)
+{
+ if (Length == 0)
+ {
+ pInformation->Ctrl_Info.Usb_wLength =
+ sizeof(pInformation->Current_Configuration);
+ return 0;
+ }
+ pUser_Standard_Requests->User_GetConfiguration();
+ return (u8 *)&pInformation->Current_Configuration;
+}
+
+/*******************************************************************************
+* Function Name : Standard_SetConfiguration.
+* Description : This routine is called to set the configuration value
+* Then each class should configure device themself.
+* Input : None.
+* Output : None.
+* Return : Return USB_SUCCESS, if the request is performed.
+* Return USB_UNSUPPORT, if the request is invalid.
+*******************************************************************************/
+RESULT Standard_SetConfiguration(void)
+{
+
+ if ((pInformation->USBwValue0 <=
+ Device_Table.Total_Configuration) && (pInformation->USBwValue1 == 0)
+ && (pInformation->USBwIndex == 0)) /*call Back usb spec 2.0*/
+ {
+ pInformation->Current_Configuration = pInformation->USBwValue0;
+ pUser_Standard_Requests->User_SetConfiguration();
+ return USB_SUCCESS;
+ }
+ else
+ {
+ return USB_UNSUPPORT;
+ }
+}
+
+/*******************************************************************************
+* Function Name : Standard_GetInterface.
+* Description : Return the Alternate Setting of the current interface.
+* Input : Length - How many bytes are needed.
+* Output : None.
+* Return : Return 0, if the request is invalid when "Length" is 0.
+* Return "Buffer" if the "Length" is not 0.
+*******************************************************************************/
+u8 *Standard_GetInterface(u16 Length)
+{
+ if (Length == 0)
+ {
+ pInformation->Ctrl_Info.Usb_wLength =
+ sizeof(pInformation->Current_AlternateSetting);
+ return 0;
+ }
+ pUser_Standard_Requests->User_GetInterface();
+ return (u8 *)&pInformation->Current_AlternateSetting;
+}
+
+/*******************************************************************************
+* Function Name : Standard_SetInterface.
+* Description : This routine is called to set the interface.
+* Then each class should configure the interface them self.
+* Input : None.
+* Output : None.
+* Return : - Return USB_SUCCESS, if the request is performed.
+* - Return USB_UNSUPPORT, if the request is invalid.
+*******************************************************************************/
+RESULT Standard_SetInterface(void)
+{
+ RESULT Re;
+ /*Test if the specified Interface and Alternate Setting are supported by
+ the application Firmware*/
+ Re = (*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, pInformation->USBwValue0);
+
+ if (pInformation->Current_Configuration != 0)
+ {
+ if ((Re != USB_SUCCESS) || (pInformation->USBwIndex1 != 0)
+ || (pInformation->USBwValue1 != 0))
+ {
+ return USB_UNSUPPORT;
+ }
+ else if (Re == USB_SUCCESS)
+ {
+ pUser_Standard_Requests->User_SetInterface();
+ pInformation->Current_Interface = pInformation->USBwIndex0;
+ pInformation->Current_AlternateSetting = pInformation->USBwValue0;
+ return USB_SUCCESS;
+ }
+
+ }
+
+ return USB_UNSUPPORT;
+}
+
+/*******************************************************************************
+* Function Name : Standard_GetStatus.
+* Description : Copy the device request data to "StatusInfo buffer".
+* Input : - Length - How many bytes are needed.
+* Output : None.
+* Return : Return 0, if the request is at end of data block,
+* or is invalid when "Length" is 0.
+*******************************************************************************/
+u8 *Standard_GetStatus(u16 Length)
+{
+ if (Length == 0)
+ {
+ pInformation->Ctrl_Info.Usb_wLength = 2;
+ return 0;
+ }
+
+ StatusInfo.w = 0;
+ /* Reset Status Information */
+
+ if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
+ {
+ /*Get Device Status */
+ u8 Feature = pInformation->Current_Feature;
+
+ /* Remote Wakeup enabled */
+ if (ValBit(Feature, 5))
+ {
+ SetBit(StatusInfo0, 1);
+ }
+
+ /* Bus-powered */
+ if (ValBit(Feature, 6))
+ {
+ ClrBit(StatusInfo0, 0);
+ }
+ else /* Self-powered */
+ {
+ SetBit(StatusInfo0, 0);
+ }
+ }
+ /*Interface Status*/
+ else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
+ {
+ return (u8 *)&StatusInfo;
+ }
+ /*Get EndPoint Status*/
+ else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
+ {
+ u8 Related_Endpoint;
+ u8 wIndex0 = pInformation->USBwIndex0;
+
+ Related_Endpoint = (wIndex0 & 0x0f);
+ if (ValBit(wIndex0, 7))
+ {
+ /* IN endpoint */
+ if (_GetTxStallStatus(Related_Endpoint))
+ {
+ SetBit(StatusInfo0, 0); /* IN Endpoint stalled */
+ }
+ }
+ else
+ {
+ /* OUT endpoint */
+ if (_GetRxStallStatus(Related_Endpoint))
+ {
+ SetBit(StatusInfo0, 0); /* OUT Endpoint stalled */
+ }
+ }
+
+ }
+ else
+ {
+ return NULL;
+ }
+ pUser_Standard_Requests->User_GetStatus();
+ return (u8 *)&StatusInfo;
+}
+
+/*******************************************************************************
+* Function Name : Standard_ClearFeature.
+* Description : Clear or disable a specific feature.
+* Input : None.
+* Output : None.
+* Return : - Return USB_SUCCESS, if the request is performed.
+* - Return USB_UNSUPPORT, if the request is invalid.
+*******************************************************************************/
+RESULT Standard_ClearFeature(void)
+{
+ u32 Type_Rec = Type_Recipient;
+ u32 Status;
+
+
+ if (Type_Rec == (STANDARD_REQUEST | DEVICE_RECIPIENT))
+ {/*Device Clear Feature*/
+ ClrBit(pInformation->Current_Feature, 5);
+ return USB_SUCCESS;
+ }
+ else if (Type_Rec == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
+ {/*EndPoint Clear Feature*/
+ DEVICE* pDev;
+ u32 Related_Endpoint;
+ u32 wIndex0;
+ u32 rEP;
+
+ if ((pInformation->USBwValue != ENDPOINT_STALL)
+ || (pInformation->USBwIndex1 != 0))
+ {
+ return USB_UNSUPPORT;
+ }
+
+ pDev = &Device_Table;
+ wIndex0 = pInformation->USBwIndex0;
+ rEP = wIndex0 & ~0x80;
+ Related_Endpoint = ENDP0 + rEP;
+
+ if (ValBit(pInformation->USBwIndex0, 7))
+ {
+ /*Get Status of endpoint & stall the request if the related_ENdpoint
+ is Disabled*/
+ Status = _GetEPTxStatus(Related_Endpoint);
+ }
+ else
+ {
+ Status = _GetEPRxStatus(Related_Endpoint);
+ }
+
+ if ((rEP >= pDev->Total_Endpoint) || (Status == 0)
+ || (pInformation->Current_Configuration == 0))
+ {
+ return USB_UNSUPPORT;
+ }
+
+
+ if (wIndex0 & 0x80)
+ {
+ /* IN endpoint */
+ if (_GetTxStallStatus(Related_Endpoint ))
+ {
+ ClearDTOG_TX(Related_Endpoint);
+ SetEPTxStatus(Related_Endpoint, EP_TX_VALID);
+ }
+ }
+ else
+ {
+ /* OUT endpoint */
+ if (_GetRxStallStatus(Related_Endpoint))
+ {
+ if (Related_Endpoint == ENDP0)
+ {
+ /* After clear the STALL, enable the default endpoint receiver */
+ SetEPRxCount(Related_Endpoint, Device_Property.MaxPacketSize);
+ _SetEPRxStatus(Related_Endpoint, EP_RX_VALID);
+ }
+ else
+ {
+ ClearDTOG_RX(Related_Endpoint);
+ _SetEPRxStatus(Related_Endpoint, EP_RX_VALID);
+ }
+ }
+ }
+ pUser_Standard_Requests->User_ClearFeature();
+ return USB_SUCCESS;
+ }
+
+ return USB_UNSUPPORT;
+}
+
+/*******************************************************************************
+* Function Name : Standard_SetEndPointFeature
+* Description : Set or enable a specific feature of EndPoint
+* Input : None.
+* Output : None.
+* Return : - Return USB_SUCCESS, if the request is performed.
+* - Return USB_UNSUPPORT, if the request is invalid.
+*******************************************************************************/
+RESULT Standard_SetEndPointFeature(void)
+{
+ u32 wIndex0;
+ u32 Related_Endpoint;
+ u32 rEP;
+ u32 Status;
+
+ wIndex0 = pInformation->USBwIndex0;
+ rEP = wIndex0 & ~0x80;
+ Related_Endpoint = ENDP0 + rEP;
+
+ if (ValBit(pInformation->USBwIndex0, 7))
+ {
+ /* get Status of endpoint & stall the request if the related_ENdpoint
+ is Disabled*/
+ Status = _GetEPTxStatus(Related_Endpoint);
+ }
+ else
+ {
+ Status = _GetEPRxStatus(Related_Endpoint);
+ }
+
+ if (Related_Endpoint >= Device_Table.Total_Endpoint
+ || pInformation->USBwValue != 0 || Status == 0
+ || pInformation->Current_Configuration == 0)
+ {
+ return USB_UNSUPPORT;
+ }
+ else
+ {
+ if (wIndex0 & 0x80)
+ {
+ /* IN endpoint */
+ _SetEPTxStatus(Related_Endpoint, EP_TX_STALL);
+ }
+
+ else
+ {
+ /* OUT endpoint */
+ _SetEPRxStatus(Related_Endpoint, EP_RX_STALL);
+ }
+ }
+ pUser_Standard_Requests->User_SetEndPointFeature();
+ return USB_SUCCESS;
+}
+
+/*******************************************************************************
+* Function Name : Standard_SetDeviceFeature.
+* Description : Set or enable a specific feature of Device.
+* Input : None.
+* Output : None.
+* Return : - Return USB_SUCCESS, if the request is performed.
+* - Return USB_UNSUPPORT, if the request is invalid.
+*******************************************************************************/
+RESULT Standard_SetDeviceFeature(void)
+{
+ SetBit(pInformation->Current_Feature, 5);
+ pUser_Standard_Requests->User_SetDeviceFeature();
+ return USB_SUCCESS;
+}
+
+/*******************************************************************************
+* Function Name : Standard_GetDescriptorData.
+* Description : Standard_GetDescriptorData is used for descriptors transfer.
+* : This routine is used for the descriptors resident in Flash
+* or RAM
+* pDesc can be in either Flash or RAM
+* The purpose of this routine is to have a versatile way to
+* response descriptors request. It allows user to generate
+* certain descriptors with software or read descriptors from
+* external storage part by part.
+* Input : - Length - Length of the data in this transfer.
+* - pDesc - A pointer points to descriptor struct.
+* The structure gives the initial address of the descriptor and
+* its original size.
+* Output : None.
+* Return : Address of a part of the descriptor pointed by the Usb_
+* wOffset The buffer pointed by this address contains at least
+* Length bytes.
+*******************************************************************************/
+u8 *Standard_GetDescriptorData(u16 Length, ONE_DESCRIPTOR *pDesc)
+{
+ u32 wOffset;
+
+ wOffset = pInformation->Ctrl_Info.Usb_wOffset;
+ if (Length == 0)
+ {
+ pInformation->Ctrl_Info.Usb_wLength = pDesc->Descriptor_Size - wOffset;
+ return 0;
+ }
+
+ return pDesc->Descriptor + wOffset;
+}
+
+/*******************************************************************************
+* Function Name : DataStageOut.
+* Description : Data stage of a Control Write Transfer.
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void DataStageOut(void)
+{
+ ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info;
+ u32 save_rLength;
+
+ save_rLength = pEPinfo->Usb_rLength;
+
+ if (pEPinfo->CopyData && save_rLength)
+ {
+ u8 *Buffer;
+ u32 Length;
+
+ Length = pEPinfo->PacketSize;
+ if (Length > save_rLength)
+ {
+ Length = save_rLength;
+ }
+
+ Buffer = (*pEPinfo->CopyData)(Length);
+ pEPinfo->Usb_rLength -= Length;
+ pEPinfo->Usb_rOffset += Length;
+
+ PMAToUserBufferCopy(Buffer, GetEPRxAddr(ENDP0), Length);
+ }
+
+ if (pEPinfo->Usb_rLength != 0)
+ {
+ vSetEPRxStatus(EP_RX_VALID);/* re-enable for next data reception */
+ SetEPTxCount(ENDP0, 0);
+ vSetEPTxStatus(EP_TX_VALID);/* Expect the host to abort the data OUT stage */
+ }
+ /* Set the next State*/
+ if (pEPinfo->Usb_rLength >= pEPinfo->PacketSize)
+ {
+ pInformation->ControlState = OUT_DATA;
+ }
+ else
+ {
+ if (pEPinfo->Usb_rLength > 0)
+ {
+ pInformation->ControlState = LAST_OUT_DATA;
+ }
+ else if (pEPinfo->Usb_rLength == 0)
+ {
+ pInformation->ControlState = WAIT_STATUS_IN;
+ USB_StatusIn();
+ }
+ }
+}
+
+/*******************************************************************************
+* Function Name : DataStageIn.
+* Description : Data stage of a Control Read Transfer.
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void DataStageIn(void)
+{
+ ENDPOINT_INFO *pEPinfo = &pInformation->Ctrl_Info;
+ u32 save_wLength = pEPinfo->Usb_wLength;
+ u32 ControlState = pInformation->ControlState;
+
+ u8 *DataBuffer;
+ u32 Length;
+
+ if ((save_wLength == 0) && (ControlState == LAST_IN_DATA))
+ {
+ if(Data_Mul_MaxPacketSize == TRUE)
+ {
+ /* No more data to send and empty packet */
+ Send0LengthData();
+ ControlState = LAST_IN_DATA;
+ Data_Mul_MaxPacketSize = FALSE;
+ }
+ else
+ {
+ /* No more data to send so STALL the TX Status*/
+ ControlState = WAIT_STATUS_OUT;
+ vSetEPTxStatus(EP_TX_STALL);
+ }
+
+ goto Expect_Status_Out;
+ }
+
+ Length = pEPinfo->PacketSize;
+ ControlState = (save_wLength <= Length) ? LAST_IN_DATA : IN_DATA;
+
+ if (Length > save_wLength)
+ {
+ Length = save_wLength;
+ }
+
+ DataBuffer = (*pEPinfo->CopyData)(Length);
+
+ UserToPMABufferCopy(DataBuffer, GetEPTxAddr(ENDP0), Length);
+
+ SetEPTxCount(ENDP0, Length);
+
+ pEPinfo->Usb_wLength -= Length;
+ pEPinfo->Usb_wOffset += Length;
+ vSetEPTxStatus(EP_TX_VALID);
+
+ USB_StatusOut();/* Expect the host to abort the data IN stage */
+
+Expect_Status_Out:
+ pInformation->ControlState = ControlState;
+}
+
+/*******************************************************************************
+* Function Name : NoData_Setup0.
+* Description : Proceed the processing of setup request without data stage.
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void NoData_Setup0(void)
+{
+ RESULT Result = USB_UNSUPPORT;
+ u32 RequestNo = pInformation->USBbRequest;
+ u32 ControlState;
+
+ if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
+ {
+ /* Device Request*/
+ /* SET_CONFIGURATION*/
+ if (RequestNo == SET_CONFIGURATION)
+ {
+ Result = Standard_SetConfiguration();
+ }
+
+ /*SET ADDRESS*/
+ else if (RequestNo == SET_ADDRESS)
+ {
+ if ((pInformation->USBwValue0 > 127) || (pInformation->USBwValue1 != 0)
+ || (pInformation->USBwIndex != 0)
+ || (pInformation->Current_Configuration != 0))
+ /* Device Address should be 127 or less*/
+ {
+ ControlState = STALLED;
+ goto exit_NoData_Setup0;
+ }
+ else
+ {
+ Result = USB_SUCCESS;
+ }
+ }
+ /*SET FEATURE for Device*/
+ else if (RequestNo == SET_FEATURE)
+ {
+ if ((pInformation->USBwValue0 == DEVICE_REMOTE_WAKEUP)
+ && (pInformation->USBwIndex == 0)
+ && (ValBit(pInformation->Current_Feature, 5)))
+ {
+ Result = Standard_SetDeviceFeature();
+ }
+ else
+ {
+ Result = USB_UNSUPPORT;
+ }
+ }
+ /*Clear FEATURE for Device */
+ else if (RequestNo == CLEAR_FEATURE)
+ {
+ if (pInformation->USBwValue0 == DEVICE_REMOTE_WAKEUP
+ && pInformation->USBwIndex == 0
+ && ValBit(pInformation->Current_Feature, 5))
+ {
+ Result = Standard_ClearFeature();
+ }
+ else
+ {
+ Result = USB_UNSUPPORT;
+ }
+ }
+
+ }
+
+ /* Interface Request*/
+ else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
+ {
+ /*SET INTERFACE*/
+ if (RequestNo == SET_INTERFACE)
+ {
+ Result = Standard_SetInterface();
+ }
+ }
+
+ /* EndPoint Request*/
+ else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
+ {
+ /*CLEAR FEATURE for EndPoint*/
+ if (RequestNo == CLEAR_FEATURE)
+ {
+ Result = Standard_ClearFeature();
+ }
+ /* SET FEATURE for EndPoint*/
+ else if (RequestNo == SET_FEATURE)
+ {
+ Result = Standard_SetEndPointFeature();
+ }
+ }
+ else
+ {
+ Result = USB_UNSUPPORT;
+ }
+
+
+ if (Result != USB_SUCCESS)
+ {
+ Result = (*pProperty->Class_NoData_Setup)(RequestNo);
+ if (Result == USB_NOT_READY)
+ {
+ ControlState = PAUSE;
+ goto exit_NoData_Setup0;
+ }
+ }
+
+ if (Result != USB_SUCCESS)
+ {
+ ControlState = STALLED;
+ goto exit_NoData_Setup0;
+ }
+
+ ControlState = WAIT_STATUS_IN;/* After no data stage SETUP */
+
+ USB_StatusIn();
+
+exit_NoData_Setup0:
+ pInformation->ControlState = ControlState;
+ return;
+}
+
+/*******************************************************************************
+* Function Name : Data_Setup0.
+* Description : Proceed the processing of setup request with data stage.
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void Data_Setup0(void)
+{
+ u8 *(*CopyRoutine)(u16);
+ RESULT Result;
+ u32 Request_No = pInformation->USBbRequest;
+
+ u32 Related_Endpoint, Reserved;
+ u32 wOffset, Status;
+
+
+
+ CopyRoutine = NULL;
+ wOffset = 0;
+
+ if (Request_No == GET_DESCRIPTOR)
+ {
+ if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
+ {
+ u8 wValue1 = pInformation->USBwValue1;
+ if (wValue1 == DEVICE_DESCRIPTOR)
+ {
+ CopyRoutine = pProperty->GetDeviceDescriptor;
+ }
+ else if (wValue1 == CONFIG_DESCRIPTOR)
+ {
+ CopyRoutine = pProperty->GetConfigDescriptor;
+ }
+ else if (wValue1 == STRING_DESCRIPTOR)
+ {
+ CopyRoutine = pProperty->GetStringDescriptor;
+ } /* End of GET_DESCRIPTOR */
+ }
+ }
+
+ /*GET STATUS*/
+ else if ((Request_No == GET_STATUS) && (pInformation->USBwValue == 0)
+ && (pInformation->USBwLength == 0x0002)
+ && (pInformation->USBwIndex1 == 0))
+ {
+ /* GET STATUS for Device*/
+ if ((Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
+ && (pInformation->USBwIndex == 0))
+ {
+ CopyRoutine = Standard_GetStatus;
+ }
+
+ /* GET STATUS for Interface*/
+ else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
+ {
+ if (((*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, 0) == USB_SUCCESS)
+ && (pInformation->Current_Configuration != 0))
+ {
+ CopyRoutine = Standard_GetStatus;
+ }
+ }
+
+ /* GET STATUS for EndPoint*/
+ else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
+ {
+ Related_Endpoint = (pInformation->USBwIndex0 & 0x0f);
+ Reserved = pInformation->USBwIndex0 & 0x70;
+
+ if (ValBit(pInformation->USBwIndex0, 7))
+ {
+ /*Get Status of endpoint & stall the request if the related_ENdpoint
+ is Disabled*/
+ Status = _GetEPTxStatus(Related_Endpoint);
+ }
+ else
+ {
+ Status = _GetEPRxStatus(Related_Endpoint);
+ }
+
+ if ((Related_Endpoint < Device_Table.Total_Endpoint) && (Reserved == 0)
+ && (Status != 0))
+ {
+ CopyRoutine = Standard_GetStatus;
+ }
+ }
+
+ }
+
+ /*GET CONFIGURATION*/
+ else if (Request_No == GET_CONFIGURATION)
+ {
+ if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
+ {
+ CopyRoutine = Standard_GetConfiguration;
+ }
+ }
+ /*GET INTERFACE*/
+ else if (Request_No == GET_INTERFACE)
+ {
+ if ((Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
+ && (pInformation->Current_Configuration != 0) && (pInformation->USBwValue == 0)
+ && (pInformation->USBwIndex1 == 0) && (pInformation->USBwLength == 0x0001)
+ && ((*pProperty->Class_Get_Interface_Setting)(pInformation->USBwIndex0, 0) == USB_SUCCESS))
+ {
+ CopyRoutine = Standard_GetInterface;
+ }
+
+ }
+
+ if (CopyRoutine)
+ {
+ pInformation->Ctrl_Info.Usb_wOffset = wOffset;
+ pInformation->Ctrl_Info.CopyData = CopyRoutine;
+ /* sb in the original the cast to word was directly */
+ /* now the cast is made step by step */
+ (*CopyRoutine)(0);
+ Result = USB_SUCCESS;
+ }
+ else
+ {
+ Result = (*pProperty->Class_Data_Setup)(pInformation->USBbRequest);
+ if (Result == USB_NOT_READY)
+ {
+ pInformation->ControlState = PAUSE;
+ return;
+ }
+ }
+
+ if (pInformation->Ctrl_Info.Usb_wLength == 0xFFFF)
+ {
+ /* Data is not ready, wait it */
+ pInformation->ControlState = PAUSE;
+ return;
+ }
+ if ((Result == USB_UNSUPPORT) || (pInformation->Ctrl_Info.Usb_wLength == 0))
+ {
+ /* Unsupported request */
+ pInformation->ControlState = STALLED;
+ return;
+ }
+
+
+ if (ValBit(pInformation->USBbmRequestType, 7))
+ {
+ /* Device ==> Host */
+ vu32 wLength = pInformation->USBwLength;
+
+ /* Restrict the data length to be the one host asks */
+ if (pInformation->Ctrl_Info.Usb_wLength > wLength)
+ {
+ pInformation->Ctrl_Info.Usb_wLength = wLength;
+ }
+
+ else if (pInformation->Ctrl_Info.Usb_wLength < pInformation->USBwLength)
+ {
+ if (pInformation->Ctrl_Info.Usb_wLength < pProperty->MaxPacketSize)
+ {
+ Data_Mul_MaxPacketSize = FALSE;
+ }
+ else if ((pInformation->Ctrl_Info.Usb_wLength % pProperty->MaxPacketSize) == 0)
+ {
+ Data_Mul_MaxPacketSize = TRUE;
+ }
+ }
+
+ pInformation->Ctrl_Info.PacketSize = pProperty->MaxPacketSize;
+ DataStageIn();
+ }
+ else
+ {
+ pInformation->ControlState = OUT_DATA;
+ vSetEPRxStatus(EP_RX_VALID); /* enable for next data reception */
+ }
+
+ return;
+}
+
+/*******************************************************************************
+* Function Name : Setup0_Process
+* Description : Get the device request data and dispatch to individual process.
+* Input : None.
+* Output : None.
+* Return : Post0_Process.
+*******************************************************************************/
+u8 Setup0_Process(void)
+{
+
+ union
+ {
+ u8* b;
+ u16* w;
+ } pBuf;
+
+ pBuf.b = PMAAddr + (u8 *)(_GetEPRxAddr(ENDP0) * 2); /* *2 for 32 bits addr */
+
+ if (pInformation->ControlState != PAUSE)
+ {
+ pInformation->USBbmRequestType = *pBuf.b++; /* bmRequestType */
+ pInformation->USBbRequest = *pBuf.b++; /* bRequest */
+ pBuf.w++; /* word not accessed because of 32 bits addressing */
+ pInformation->USBwValue = ByteSwap(*pBuf.w++); /* wValue */
+ pBuf.w++; /* word not accessed because of 32 bits addressing */
+ pInformation->USBwIndex = ByteSwap(*pBuf.w++); /* wIndex */
+ pBuf.w++; /* word not accessed because of 32 bits addressing */
+ pInformation->USBwLength = *pBuf.w; /* wLength */
+ }
+
+ pInformation->ControlState = SETTING_UP;
+ if (pInformation->USBwLength == 0)
+ {
+ /* Setup with no data stage */
+ NoData_Setup0();
+ }
+ else
+ {
+ /* Setup with data stage */
+ Data_Setup0();
+ }
+ return Post0_Process();
+}
+
+/*******************************************************************************
+* Function Name : In0_Process
+* Description : Process the IN token on all default endpoint.
+* Input : None.
+* Output : None.
+* Return : Post0_Process.
+*******************************************************************************/
+u8 In0_Process(void)
+{
+ u32 ControlState = pInformation->ControlState;
+
+ if ((ControlState == IN_DATA) || (ControlState == LAST_IN_DATA))
+ {
+ DataStageIn();
+ /* ControlState may be changed outside the function */
+ ControlState = pInformation->ControlState;
+ }
+
+ else if (ControlState == WAIT_STATUS_IN)
+ {
+ if ((pInformation->USBbRequest == SET_ADDRESS) &&
+ (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)))
+ {
+ SetDeviceAddress(pInformation->USBwValue0);
+ pUser_Standard_Requests->User_SetDeviceAddress();
+ }
+ (*pProperty->Process_Status_IN)();
+ ControlState = STALLED;
+ }
+
+ else
+ {
+ ControlState = STALLED;
+ }
+
+ pInformation->ControlState = ControlState;
+
+ return Post0_Process();
+}
+
+/*******************************************************************************
+* Function Name : Out0_Process
+* Description : Process the OUT token on all default endpoint.
+* Input : None.
+* Output : None.
+* Return : Post0_Process.
+*******************************************************************************/
+u8 Out0_Process(void)
+{
+ u32 ControlState = pInformation->ControlState;
+
+ if ((ControlState == OUT_DATA) || (ControlState == LAST_OUT_DATA))
+ {
+ DataStageOut();
+ ControlState = pInformation->ControlState; /* may be changed outside the function */
+ }
+
+ else if (ControlState == WAIT_STATUS_OUT)
+ {
+ (*pProperty->Process_Status_OUT)();
+ ControlState = STALLED;
+ }
+
+ else if ((ControlState == IN_DATA) || (ControlState == LAST_IN_DATA))
+ {
+ /* host aborts the transfer before finish */
+ ControlState = STALLED;
+ }
+
+ /* Unexpect state, STALL the endpoint */
+ else
+ {
+ ControlState = STALLED;
+ }
+
+ pInformation->ControlState = ControlState;
+
+ return Post0_Process();
+}
+
+/*******************************************************************************
+* Function Name : Post0_Process
+* Description : Stall the Endpoint 0 in case of error.
+* Input : None.
+* Output : None.
+* Return : - 0 if the control State is in PAUSE
+* - 1 if not.
+*******************************************************************************/
+u8 Post0_Process(void)
+{
+ SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
+
+ if (pInformation->ControlState == STALLED)
+ {
+ vSetEPRxStatus(EP_RX_STALL);
+ vSetEPTxStatus(EP_TX_STALL);
+ }
+
+ return (pInformation->ControlState == PAUSE);
+}
+
+/*******************************************************************************
+* Function Name : SetDeviceAddress.
+* Description : Set the device and all the used Endpoints addresses.
+* Input : - Val: device adress.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetDeviceAddress(u8 Val)
+{
+ u32 i;
+ u32 nEP = Device_Table.Total_Endpoint;
+
+ /* set address in every used endpoint */
+ for (i = 0; i < nEP; i++)
+ {
+ _SetEPAddress((u8)i, (u8)i);
+ } /* for */
+ _SetDADDR(Val | DADDR_EF); /* set device address and enable function */
+}
+
+/*******************************************************************************
+* Function Name : NOP_Process
+* Description : No operation function.
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void NOP_Process(void)
+{
+}
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/libmaple/usb/usb_lib/usb_core.h b/libmaple/usb/usb_lib/usb_core.h
index d8c099f..fa29a18 100644
--- a/libmaple/usb/usb_lib/usb_core.h
+++ b/libmaple/usb/usb_lib/usb_core.h
@@ -1,251 +1,251 @@
-/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
-* File Name : usb_core.h
-* Author : MCD Application Team
-* Version : V2.2.1
-* Date : 09/22/2008
-* Description : Standard protocol processing functions prototypes
-********************************************************************************
-* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
-* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
-* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
-* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
-* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
-* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
-*******************************************************************************/
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __USB_CORE_H
-#define __USB_CORE_H
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-/* Includes ------------------------------------------------------------------*/
-/* Exported types ------------------------------------------------------------*/
-typedef enum _CONTROL_STATE
-{
- WAIT_SETUP, /* 0 */
- SETTING_UP, /* 1 */
- IN_DATA, /* 2 */
- OUT_DATA, /* 3 */
- LAST_IN_DATA, /* 4 */
- LAST_OUT_DATA, /* 5 */
- WAIT_STATUS_IN, /* 7 */
- WAIT_STATUS_OUT, /* 8 */
- STALLED, /* 9 */
- PAUSE /* 10 */
-} CONTROL_STATE; /* The state machine states of a control pipe */
-
-typedef struct OneDescriptor
-{
- u8 *Descriptor;
- u16 Descriptor_Size;
-}
-ONE_DESCRIPTOR, *PONE_DESCRIPTOR;
-/* All the request process routines return a value of this type
- If the return value is not SUCCESS or NOT_READY,
- the software will STALL the correspond endpoint */
-typedef enum _RESULT
-{
- USB_SUCCESS = 0, /* Process sucessfully */
- USB_ERROR,
- USB_UNSUPPORT,
- USB_NOT_READY /* The process has not been finished, endpoint will be
- NAK to further rquest */
-} RESULT;
-
-
-/*-*-*-*-*-*-*-*-*-*-* Definitions for endpoint level -*-*-*-*-*-*-*-*-*-*-*-*/
-typedef struct _ENDPOINT_INFO
-{
- /* When send data out of the device,
- CopyData() is used to get data buffer 'Length' bytes data
- if Length is 0,
- CopyData() returns the total length of the data
- if the request is not supported, returns 0
- (NEW Feature )
- if CopyData() returns -1, the calling routine should not proceed
- further and will resume the SETUP process by the class device
- if Length is not 0,
- CopyData() returns a pointer to indicate the data location
- Usb_wLength is the data remain to be sent,
- Usb_wOffset is the Offset of original data
- When receive data from the host,
- CopyData() is used to get user data buffer which is capable
- of Length bytes data to copy data from the endpoint buffer.
- if Length is 0,
- CopyData() returns the available data length,
- if Length is not 0,
- CopyData() returns user buffer address
- Usb_rLength is the data remain to be received,
- Usb_rPointer is the Offset of data buffer
- */
- u16 Usb_wLength;
- u16 Usb_wOffset;
- u16 PacketSize;
- u8 *(*CopyData)(u16 Length);
-}ENDPOINT_INFO;
-
-/*-*-*-*-*-*-*-*-*-*-*-* Definitions for device level -*-*-*-*-*-*-*-*-*-*-*-*/
-
-typedef struct _DEVICE
-{
- u8 Total_Endpoint; /* Number of endpoints that are used */
- u8 Total_Configuration;/* Number of configuration available */
-}
-DEVICE;
-
-typedef union
-{
- u16 w;
- struct BW
- {
- u8 bb1;
- u8 bb0;
- }
- bw;
-} u16_u8;
-
-typedef struct _DEVICE_INFO
-{
- u8 USBbmRequestType; /* bmRequestType */
- u8 USBbRequest; /* bRequest */
- u16_u8 USBwValues; /* wValue */
- u16_u8 USBwIndexs; /* wIndex */
- u16_u8 USBwLengths; /* wLength */
-
- u8 ControlState; /* of type CONTROL_STATE */
- u8 Current_Feature;
- u8 Current_Configuration; /* Selected configuration */
- u8 Current_Interface; /* Selected interface of current configuration */
- u8 Current_AlternateSetting;/* Selected Alternate Setting of current
- interface*/
-
- ENDPOINT_INFO Ctrl_Info;
-}DEVICE_INFO;
-
-typedef struct _DEVICE_PROP
-{
- void (*Init)(void); /* Initialize the device */
- void (*Reset)(void); /* Reset routine of this device */
-
- /* Device dependent process after the status stage */
- void (*Process_Status_IN)(void);
- void (*Process_Status_OUT)(void);
-
- /* Procedure of process on setup stage of a class specified request with data stage */
- /* All class specified requests with data stage are processed in Class_Data_Setup
- Class_Data_Setup()
- responses to check all special requests and fills ENDPOINT_INFO
- according to the request
- If IN tokens are expected, then wLength & wOffset will be filled
- with the total transferring bytes and the starting position
- If OUT tokens are expected, then rLength & rOffset will be filled
- with the total expected bytes and the starting position in the buffer
-
- If the request is valid, Class_Data_Setup returns SUCCESS, else UNSUPPORT
-
- CAUTION:
- Since GET_CONFIGURATION & GET_INTERFACE are highly related to
- the individual classes, they will be checked and processed here.
- */
- RESULT (*Class_Data_Setup)(u8 RequestNo);
-
- /* Procedure of process on setup stage of a class specified request without data stage */
- /* All class specified requests without data stage are processed in Class_NoData_Setup
- Class_NoData_Setup
- responses to check all special requests and perform the request
-
- CAUTION:
- Since SET_CONFIGURATION & SET_INTERFACE are highly related to
- the individual classes, they will be checked and processed here.
- */
- RESULT (*Class_NoData_Setup)(u8 RequestNo);
-
- /*Class_Get_Interface_Setting
- This function is used by the file usb_core.c to test if the selected Interface
- and Alternate Setting (u8 Interface, u8 AlternateSetting) are supported by
- the application.
- This function is writing by user. It should return "SUCCESS" if the Interface
- and Alternate Setting are supported by the application or "UNSUPPORT" if they
- are not supported. */
-
- RESULT (*Class_Get_Interface_Setting)(u8 Interface, u8 AlternateSetting);
-
- u8* (*GetDeviceDescriptor)(u16 Length);
- u8* (*GetConfigDescriptor)(u16 Length);
- u8* (*GetStringDescriptor)(u16 Length);
-
- u8* RxEP_buffer;
- u8 MaxPacketSize;
-
-}DEVICE_PROP;
-
-typedef struct _USER_STANDARD_REQUESTS
-{
- void (*User_GetConfiguration)(void); /* Get Configuration */
- void (*User_SetConfiguration)(void); /* Set Configuration */
- void (*User_GetInterface)(void); /* Get Interface */
- void (*User_SetInterface)(void); /* Set Interface */
- void (*User_GetStatus)(void); /* Get Status */
- void (*User_ClearFeature)(void); /* Clear Feature */
- void (*User_SetEndPointFeature)(void); /* Set Endpoint Feature */
- void (*User_SetDeviceFeature)(void); /* Set Device Feature */
- void (*User_SetDeviceAddress)(void); /* Set Device Address */
-}
-USER_STANDARD_REQUESTS;
-
-/* Exported constants --------------------------------------------------------*/
-#define Type_Recipient (pInformation->USBbmRequestType & (REQUEST_TYPE | RECIPIENT))
-
-#define Usb_rLength Usb_wLength
-#define Usb_rOffset Usb_wOffset
-
-#define USBwValue USBwValues.w
-#define USBwValue0 USBwValues.bw.bb0
-#define USBwValue1 USBwValues.bw.bb1
-#define USBwIndex USBwIndexs.w
-#define USBwIndex0 USBwIndexs.bw.bb0
-#define USBwIndex1 USBwIndexs.bw.bb1
-#define USBwLength USBwLengths.w
-#define USBwLength0 USBwLengths.bw.bb0
-#define USBwLength1 USBwLengths.bw.bb1
-
-/* Exported macro ------------------------------------------------------------*/
-/* Exported functions ------------------------------------------------------- */
-u8 Setup0_Process(void);
-u8 Post0_Process(void);
-u8 Out0_Process(void);
-u8 In0_Process(void);
-
-RESULT Standard_SetEndPointFeature(void);
-RESULT Standard_SetDeviceFeature(void);
-
-u8 *Standard_GetConfiguration(u16 Length);
-RESULT Standard_SetConfiguration(void);
-u8 *Standard_GetInterface(u16 Length);
-RESULT Standard_SetInterface(void);
-u8 *Standard_GetDescriptorData(u16 Length, PONE_DESCRIPTOR pDesc);
-
-u8 *Standard_GetStatus(u16 Length);
-RESULT Standard_ClearFeature(void);
-void SetDeviceAddress(u8);
-void NOP_Process(void);
-
-extern DEVICE_PROP Device_Property;
-extern USER_STANDARD_REQUESTS User_Standard_Requests;
-extern DEVICE Device_Table;
-extern DEVICE_INFO Device_Info;
-
-/* cells saving status during interrupt servicing */
-extern u16 SaveRState;
-extern u16 SaveTState;
-
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /* __USB_CORE_H */
-
-/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_core.h
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Standard protocol processing functions prototypes
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USB_CORE_H
+#define __USB_CORE_H
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+/* Exported types ------------------------------------------------------------*/
+typedef enum _CONTROL_STATE
+{
+ WAIT_SETUP, /* 0 */
+ SETTING_UP, /* 1 */
+ IN_DATA, /* 2 */
+ OUT_DATA, /* 3 */
+ LAST_IN_DATA, /* 4 */
+ LAST_OUT_DATA, /* 5 */
+ WAIT_STATUS_IN, /* 7 */
+ WAIT_STATUS_OUT, /* 8 */
+ STALLED, /* 9 */
+ PAUSE /* 10 */
+} CONTROL_STATE; /* The state machine states of a control pipe */
+
+typedef struct OneDescriptor
+{
+ u8 *Descriptor;
+ u16 Descriptor_Size;
+}
+ONE_DESCRIPTOR, *PONE_DESCRIPTOR;
+/* All the request process routines return a value of this type
+ If the return value is not SUCCESS or NOT_READY,
+ the software will STALL the correspond endpoint */
+typedef enum _RESULT
+{
+ USB_SUCCESS = 0, /* Process sucessfully */
+ USB_ERROR,
+ USB_UNSUPPORT,
+ USB_NOT_READY /* The process has not been finished, endpoint will be
+ NAK to further rquest */
+} RESULT;
+
+
+/*-*-*-*-*-*-*-*-*-*-* Definitions for endpoint level -*-*-*-*-*-*-*-*-*-*-*-*/
+typedef struct _ENDPOINT_INFO
+{
+ /* When send data out of the device,
+ CopyData() is used to get data buffer 'Length' bytes data
+ if Length is 0,
+ CopyData() returns the total length of the data
+ if the request is not supported, returns 0
+ (NEW Feature )
+ if CopyData() returns -1, the calling routine should not proceed
+ further and will resume the SETUP process by the class device
+ if Length is not 0,
+ CopyData() returns a pointer to indicate the data location
+ Usb_wLength is the data remain to be sent,
+ Usb_wOffset is the Offset of original data
+ When receive data from the host,
+ CopyData() is used to get user data buffer which is capable
+ of Length bytes data to copy data from the endpoint buffer.
+ if Length is 0,
+ CopyData() returns the available data length,
+ if Length is not 0,
+ CopyData() returns user buffer address
+ Usb_rLength is the data remain to be received,
+ Usb_rPointer is the Offset of data buffer
+ */
+ u16 Usb_wLength;
+ u16 Usb_wOffset;
+ u16 PacketSize;
+ u8 *(*CopyData)(u16 Length);
+}ENDPOINT_INFO;
+
+/*-*-*-*-*-*-*-*-*-*-*-* Definitions for device level -*-*-*-*-*-*-*-*-*-*-*-*/
+
+typedef struct _DEVICE
+{
+ u8 Total_Endpoint; /* Number of endpoints that are used */
+ u8 Total_Configuration;/* Number of configuration available */
+}
+DEVICE;
+
+typedef union
+{
+ u16 w;
+ struct BW
+ {
+ u8 bb1;
+ u8 bb0;
+ }
+ bw;
+} u16_u8;
+
+typedef struct _DEVICE_INFO
+{
+ u8 USBbmRequestType; /* bmRequestType */
+ u8 USBbRequest; /* bRequest */
+ u16_u8 USBwValues; /* wValue */
+ u16_u8 USBwIndexs; /* wIndex */
+ u16_u8 USBwLengths; /* wLength */
+
+ u8 ControlState; /* of type CONTROL_STATE */
+ u8 Current_Feature;
+ u8 Current_Configuration; /* Selected configuration */
+ u8 Current_Interface; /* Selected interface of current configuration */
+ u8 Current_AlternateSetting;/* Selected Alternate Setting of current
+ interface*/
+
+ ENDPOINT_INFO Ctrl_Info;
+}DEVICE_INFO;
+
+typedef struct _DEVICE_PROP
+{
+ void (*Init)(void); /* Initialize the device */
+ void (*Reset)(void); /* Reset routine of this device */
+
+ /* Device dependent process after the status stage */
+ void (*Process_Status_IN)(void);
+ void (*Process_Status_OUT)(void);
+
+ /* Procedure of process on setup stage of a class specified request with data stage */
+ /* All class specified requests with data stage are processed in Class_Data_Setup
+ Class_Data_Setup()
+ responses to check all special requests and fills ENDPOINT_INFO
+ according to the request
+ If IN tokens are expected, then wLength & wOffset will be filled
+ with the total transferring bytes and the starting position
+ If OUT tokens are expected, then rLength & rOffset will be filled
+ with the total expected bytes and the starting position in the buffer
+
+ If the request is valid, Class_Data_Setup returns SUCCESS, else UNSUPPORT
+
+ CAUTION:
+ Since GET_CONFIGURATION & GET_INTERFACE are highly related to
+ the individual classes, they will be checked and processed here.
+ */
+ RESULT (*Class_Data_Setup)(u8 RequestNo);
+
+ /* Procedure of process on setup stage of a class specified request without data stage */
+ /* All class specified requests without data stage are processed in Class_NoData_Setup
+ Class_NoData_Setup
+ responses to check all special requests and perform the request
+
+ CAUTION:
+ Since SET_CONFIGURATION & SET_INTERFACE are highly related to
+ the individual classes, they will be checked and processed here.
+ */
+ RESULT (*Class_NoData_Setup)(u8 RequestNo);
+
+ /*Class_Get_Interface_Setting
+ This function is used by the file usb_core.c to test if the selected Interface
+ and Alternate Setting (u8 Interface, u8 AlternateSetting) are supported by
+ the application.
+ This function is writing by user. It should return "SUCCESS" if the Interface
+ and Alternate Setting are supported by the application or "UNSUPPORT" if they
+ are not supported. */
+
+ RESULT (*Class_Get_Interface_Setting)(u8 Interface, u8 AlternateSetting);
+
+ u8* (*GetDeviceDescriptor)(u16 Length);
+ u8* (*GetConfigDescriptor)(u16 Length);
+ u8* (*GetStringDescriptor)(u16 Length);
+
+ u8* RxEP_buffer;
+ u8 MaxPacketSize;
+
+}DEVICE_PROP;
+
+typedef struct _USER_STANDARD_REQUESTS
+{
+ void (*User_GetConfiguration)(void); /* Get Configuration */
+ void (*User_SetConfiguration)(void); /* Set Configuration */
+ void (*User_GetInterface)(void); /* Get Interface */
+ void (*User_SetInterface)(void); /* Set Interface */
+ void (*User_GetStatus)(void); /* Get Status */
+ void (*User_ClearFeature)(void); /* Clear Feature */
+ void (*User_SetEndPointFeature)(void); /* Set Endpoint Feature */
+ void (*User_SetDeviceFeature)(void); /* Set Device Feature */
+ void (*User_SetDeviceAddress)(void); /* Set Device Address */
+}
+USER_STANDARD_REQUESTS;
+
+/* Exported constants --------------------------------------------------------*/
+#define Type_Recipient (pInformation->USBbmRequestType & (REQUEST_TYPE | RECIPIENT))
+
+#define Usb_rLength Usb_wLength
+#define Usb_rOffset Usb_wOffset
+
+#define USBwValue USBwValues.w
+#define USBwValue0 USBwValues.bw.bb0
+#define USBwValue1 USBwValues.bw.bb1
+#define USBwIndex USBwIndexs.w
+#define USBwIndex0 USBwIndexs.bw.bb0
+#define USBwIndex1 USBwIndexs.bw.bb1
+#define USBwLength USBwLengths.w
+#define USBwLength0 USBwLengths.bw.bb0
+#define USBwLength1 USBwLengths.bw.bb1
+
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+u8 Setup0_Process(void);
+u8 Post0_Process(void);
+u8 Out0_Process(void);
+u8 In0_Process(void);
+
+RESULT Standard_SetEndPointFeature(void);
+RESULT Standard_SetDeviceFeature(void);
+
+u8 *Standard_GetConfiguration(u16 Length);
+RESULT Standard_SetConfiguration(void);
+u8 *Standard_GetInterface(u16 Length);
+RESULT Standard_SetInterface(void);
+u8 *Standard_GetDescriptorData(u16 Length, PONE_DESCRIPTOR pDesc);
+
+u8 *Standard_GetStatus(u16 Length);
+RESULT Standard_ClearFeature(void);
+void SetDeviceAddress(u8);
+void NOP_Process(void);
+
+extern DEVICE_PROP Device_Property;
+extern USER_STANDARD_REQUESTS User_Standard_Requests;
+extern DEVICE Device_Table;
+extern DEVICE_INFO Device_Info;
+
+/* cells saving status during interrupt servicing */
+extern u16 SaveRState;
+extern u16 SaveTState;
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __USB_CORE_H */
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/libmaple/usb/usb_lib/usb_def.h b/libmaple/usb/usb_lib/usb_def.h
index aa6bcba..80aa303 100644
--- a/libmaple/usb/usb_lib/usb_def.h
+++ b/libmaple/usb/usb_lib/usb_def.h
@@ -1,88 +1,88 @@
-/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
-* File Name : usb_def.h
-* Author : MCD Application Team
-* Version : V2.2.1
-* Date : 09/22/2008
-* Description : Definitions related to USB Core
-********************************************************************************
-* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
-* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
-* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
-* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
-* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
-* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
-*******************************************************************************/
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __USB_DEF_H
-#define __USB_DEF_H
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-/* Includes ------------------------------------------------------------------*/
-/* Exported types ------------------------------------------------------------*/
-typedef enum _RECIPIENT_TYPE
-{
- DEVICE_RECIPIENT, /* Recipient device */
- INTERFACE_RECIPIENT, /* Recipient interface */
- ENDPOINT_RECIPIENT, /* Recipient endpoint */
- OTHER_RECIPIENT
-} RECIPIENT_TYPE;
-
-
-typedef enum _STANDARD_REQUESTS
-{
- GET_STATUS = 0,
- CLEAR_FEATURE,
- RESERVED1,
- SET_FEATURE,
- RESERVED2,
- SET_ADDRESS,
- GET_DESCRIPTOR,
- SET_DESCRIPTOR,
- GET_CONFIGURATION,
- SET_CONFIGURATION,
- GET_INTERFACE,
- SET_INTERFACE,
- TOTAL_sREQUEST, /* Total number of Standard request */
- SYNCH_FRAME = 12
-} STANDARD_REQUESTS;
-
-/* Definition of "USBwValue" */
-typedef enum _DESCRIPTOR_TYPE
-{
- DEVICE_DESCRIPTOR = 1,
- CONFIG_DESCRIPTOR,
- STRING_DESCRIPTOR,
- INTERFACE_DESCRIPTOR,
- ENDPOINT_DESCRIPTOR
-} DESCRIPTOR_TYPE;
-
-/* Feature selector of a SET_FEATURE or CLEAR_FEATURE */
-typedef enum _FEATURE_SELECTOR
-{
- ENDPOINT_STALL,
- DEVICE_REMOTE_WAKEUP
-} FEATURE_SELECTOR;
-
-/* Exported constants --------------------------------------------------------*/
-/* Definition of "USBbmRequestType" */
-#define REQUEST_TYPE 0x60 /* Mask to get request type */
-#define STANDARD_REQUEST 0x00 /* Standard request */
-#define CLASS_REQUEST 0x20 /* Class request */
-#define VENDOR_REQUEST 0x40 /* Vendor request */
-
-#define RECIPIENT 0x1F /* Mask to get recipient */
-
-/* Exported macro ------------------------------------------------------------*/
-/* Exported functions ------------------------------------------------------- */
-
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /* __USB_DEF_H */
-
-/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_def.h
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Definitions related to USB Core
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USB_DEF_H
+#define __USB_DEF_H
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+/* Exported types ------------------------------------------------------------*/
+typedef enum _RECIPIENT_TYPE
+{
+ DEVICE_RECIPIENT, /* Recipient device */
+ INTERFACE_RECIPIENT, /* Recipient interface */
+ ENDPOINT_RECIPIENT, /* Recipient endpoint */
+ OTHER_RECIPIENT
+} RECIPIENT_TYPE;
+
+
+typedef enum _STANDARD_REQUESTS
+{
+ GET_STATUS = 0,
+ CLEAR_FEATURE,
+ RESERVED1,
+ SET_FEATURE,
+ RESERVED2,
+ SET_ADDRESS,
+ GET_DESCRIPTOR,
+ SET_DESCRIPTOR,
+ GET_CONFIGURATION,
+ SET_CONFIGURATION,
+ GET_INTERFACE,
+ SET_INTERFACE,
+ TOTAL_sREQUEST, /* Total number of Standard request */
+ SYNCH_FRAME = 12
+} STANDARD_REQUESTS;
+
+/* Definition of "USBwValue" */
+typedef enum _DESCRIPTOR_TYPE
+{
+ DEVICE_DESCRIPTOR = 1,
+ CONFIG_DESCRIPTOR,
+ STRING_DESCRIPTOR,
+ INTERFACE_DESCRIPTOR,
+ ENDPOINT_DESCRIPTOR
+} DESCRIPTOR_TYPE;
+
+/* Feature selector of a SET_FEATURE or CLEAR_FEATURE */
+typedef enum _FEATURE_SELECTOR
+{
+ ENDPOINT_STALL,
+ DEVICE_REMOTE_WAKEUP
+} FEATURE_SELECTOR;
+
+/* Exported constants --------------------------------------------------------*/
+/* Definition of "USBbmRequestType" */
+#define REQUEST_TYPE 0x60 /* Mask to get request type */
+#define STANDARD_REQUEST 0x00 /* Standard request */
+#define CLASS_REQUEST 0x20 /* Class request */
+#define VENDOR_REQUEST 0x40 /* Vendor request */
+
+#define RECIPIENT 0x1F /* Mask to get recipient */
+
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __USB_DEF_H */
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/libmaple/usb/usb_lib/usb_init.c b/libmaple/usb/usb_lib/usb_init.c
index 5862145..94f3a83 100644
--- a/libmaple/usb/usb_lib/usb_init.c
+++ b/libmaple/usb/usb_lib/usb_init.c
@@ -1,64 +1,64 @@
-/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
-* File Name : usb_init.c
-* Author : MCD Application Team
-* Version : V2.2.1
-* Date : 09/22/2008
-* Description : Initialization routines & global variables
-********************************************************************************
-* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
-* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
-* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
-* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
-* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
-* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
-*******************************************************************************/
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_lib.h"
-
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-/* Private macro -------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-/* The number of current endpoint, it will be used to specify an endpoint */
- u8 EPindex;
-/* The number of current device, it is an index to the Device_Table */
-/* u8 Device_no; */
-/* Points to the DEVICE_INFO structure of current device */
-/* The purpose of this register is to speed up the execution */
-DEVICE_INFO *pInformation;
-/* Points to the DEVICE_PROP structure of current device */
-/* The purpose of this register is to speed up the execution */
-DEVICE_PROP *pProperty;
-/* Temporary save the state of Rx & Tx status. */
-/* Whenever the Rx or Tx state is changed, its value is saved */
-/* in this variable first and will be set to the EPRB or EPRA */
-/* at the end of interrupt process */
-u16 SaveState ;
-u16 wInterrupt_Mask;
-DEVICE_INFO Device_Info;
-USER_STANDARD_REQUESTS *pUser_Standard_Requests;
-
-/* Extern variables ----------------------------------------------------------*/
-/* Private function prototypes -----------------------------------------------*/
-/* Private functions ---------------------------------------------------------*/
-
-/*******************************************************************************
-* Function Name : USB_Init
-* Description : USB system initialization
-* Input : None.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void USB_Init(void)
-{
- pInformation = &Device_Info;
- pInformation->ControlState = 2;
- pProperty = &Device_Property;
- pUser_Standard_Requests = &User_Standard_Requests;
- /* Initialize devices one by one */
-
- pProperty->Init();
-}
-
-/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_init.c
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Initialization routines & global variables
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Includes ------------------------------------------------------------------*/
+#include "usb_lib.h"
+
+/* Private typedef -----------------------------------------------------------*/
+/* Private define ------------------------------------------------------------*/
+/* Private macro -------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+/* The number of current endpoint, it will be used to specify an endpoint */
+ u8 EPindex;
+/* The number of current device, it is an index to the Device_Table */
+/* u8 Device_no; */
+/* Points to the DEVICE_INFO structure of current device */
+/* The purpose of this register is to speed up the execution */
+DEVICE_INFO *pInformation;
+/* Points to the DEVICE_PROP structure of current device */
+/* The purpose of this register is to speed up the execution */
+DEVICE_PROP *pProperty;
+/* Temporary save the state of Rx & Tx status. */
+/* Whenever the Rx or Tx state is changed, its value is saved */
+/* in this variable first and will be set to the EPRB or EPRA */
+/* at the end of interrupt process */
+u16 SaveState ;
+u16 wInterrupt_Mask;
+DEVICE_INFO Device_Info;
+USER_STANDARD_REQUESTS *pUser_Standard_Requests;
+
+/* Extern variables ----------------------------------------------------------*/
+/* Private function prototypes -----------------------------------------------*/
+/* Private functions ---------------------------------------------------------*/
+
+/*******************************************************************************
+* Function Name : USB_Init
+* Description : USB system initialization
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void USB_Init(void)
+{
+ pInformation = &Device_Info;
+ pInformation->ControlState = 2;
+ pProperty = &Device_Property;
+ pUser_Standard_Requests = &User_Standard_Requests;
+ /* Initialize devices one by one */
+
+ pProperty->Init();
+}
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/libmaple/usb/usb_lib/usb_init.h b/libmaple/usb/usb_lib/usb_init.h
index 1091ce5..80ee2fb 100644
--- a/libmaple/usb/usb_lib/usb_init.h
+++ b/libmaple/usb/usb_lib/usb_init.h
@@ -1,57 +1,57 @@
-/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
-* File Name : usb_init.h
-* Author : MCD Application Team
-* Version : V2.2.1
-* Date : 09/22/2008
-* Description : Initialization routines & global variables
-********************************************************************************
-* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
-* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
-* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
-* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
-* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
-* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
-*******************************************************************************/
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __USB_INIT_H
-#define __USB_INIT_H
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-/* Includes ------------------------------------------------------------------*/
-/* Exported types ------------------------------------------------------------*/
-/* Exported constants --------------------------------------------------------*/
-/* Exported macro ------------------------------------------------------------*/
-/* Exported functions ------------------------------------------------------- */
-void USB_Init(void);
-
-/* External variables --------------------------------------------------------*/
-/* The number of current endpoint, it will be used to specify an endpoint */
-extern u8 EPindex;
-/* The number of current device, it is an index to the Device_Table */
-/*extern u8 Device_no; */
-/* Points to the DEVICE_INFO structure of current device */
-/* The purpose of this register is to speed up the execution */
-extern DEVICE_INFO* pInformation;
-/* Points to the DEVICE_PROP structure of current device */
-/* The purpose of this register is to speed up the execution */
-extern DEVICE_PROP* pProperty;
-/* Temporary save the state of Rx & Tx status. */
-/* Whenever the Rx or Tx state is changed, its value is saved */
-/* in this variable first and will be set to the EPRB or EPRA */
-/* at the end of interrupt process */
-extern USER_STANDARD_REQUESTS *pUser_Standard_Requests;
-
-extern u16 SaveState ;
-extern u16 wInterrupt_Mask;
-
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /* __USB_INIT_H */
-
-/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_init.h
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Initialization routines & global variables
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USB_INIT_H
+#define __USB_INIT_H
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+void USB_Init(void);
+
+/* External variables --------------------------------------------------------*/
+/* The number of current endpoint, it will be used to specify an endpoint */
+extern u8 EPindex;
+/* The number of current device, it is an index to the Device_Table */
+/*extern u8 Device_no; */
+/* Points to the DEVICE_INFO structure of current device */
+/* The purpose of this register is to speed up the execution */
+extern DEVICE_INFO* pInformation;
+/* Points to the DEVICE_PROP structure of current device */
+/* The purpose of this register is to speed up the execution */
+extern DEVICE_PROP* pProperty;
+/* Temporary save the state of Rx & Tx status. */
+/* Whenever the Rx or Tx state is changed, its value is saved */
+/* in this variable first and will be set to the EPRB or EPRA */
+/* at the end of interrupt process */
+extern USER_STANDARD_REQUESTS *pUser_Standard_Requests;
+
+extern u16 SaveState ;
+extern u16 wInterrupt_Mask;
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __USB_INIT_H */
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/libmaple/usb/usb_lib/usb_int.c b/libmaple/usb/usb_lib/usb_int.c
index f1d82be..61a989b 100644
--- a/libmaple/usb/usb_lib/usb_int.c
+++ b/libmaple/usb/usb_lib/usb_int.c
@@ -1,192 +1,192 @@
-/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
-* File Name : usb_int.c
-* Author : MCD Application Team
-* Version : V2.2.1
-* Date : 09/22/2008
-* Description : Endpoint CTR (Low and High) interrupt's service routines
-********************************************************************************
-* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
-* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
-* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
-* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
-* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
-* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
-*******************************************************************************/
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_lib.h"
-
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-/* Private macro -------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-u16 SaveRState;
-u16 SaveTState;
-
-/* Extern variables ----------------------------------------------------------*/
-extern void (*pEpInt_IN[7])(void); /* Handles IN interrupts */
-extern void (*pEpInt_OUT[7])(void); /* Handles OUT interrupts */
-
-/* Private function prototypes -----------------------------------------------*/
-/* Private functions ---------------------------------------------------------*/
-
-/*******************************************************************************
-* Function Name : CTR_LP.
-* Description : Low priority Endpoint Correct Transfer interrupt's service
-* routine.
-* Input : None.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void CTR_LP(void)
-{
- u32 wEPVal = 0;
- /* stay in loop while pending ints */
- while (((wIstr = _GetISTR()) & ISTR_CTR) != 0)
- {
- _SetISTR((u16)CLR_CTR); /* clear CTR flag */
- /* extract highest priority endpoint number */
- EPindex = (u8)(wIstr & ISTR_EP_ID);
- if (EPindex == 0)
- {
- /* Decode and service control endpoint interrupt */
- /* calling related service routine */
- /* (Setup0_Process, In0_Process, Out0_Process) */
-
- /* save RX & TX status */
- /* and set both to NAK */
- SaveRState = _GetEPRxStatus(ENDP0);
- SaveTState = _GetEPTxStatus(ENDP0);
- _SetEPRxStatus(ENDP0, EP_RX_NAK);
- _SetEPTxStatus(ENDP0, EP_TX_NAK);
-
-
- /* DIR bit = origin of the interrupt */
-
- if ((wIstr & ISTR_DIR) == 0)
- {
- /* DIR = 0 */
-
- /* DIR = 0 => IN int */
- /* DIR = 0 implies that (EP_CTR_TX = 1) always */
-
-
- _ClearEP_CTR_TX(ENDP0);
- In0_Process();
-
- /* before terminate set Tx & Rx status */
- _SetEPRxStatus(ENDP0, SaveRState);
- _SetEPTxStatus(ENDP0, SaveTState);
- return;
- }
- else
- {
- /* DIR = 1 */
-
- /* DIR = 1 & CTR_RX => SETUP or OUT int */
- /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */
-
- wEPVal = _GetENDPOINT(ENDP0);
- if ((wEPVal & EP_CTR_TX) != 0)
- {
- _ClearEP_CTR_TX(ENDP0);
- In0_Process();
- /* before terminate set Tx & Rx status */
- _SetEPRxStatus(ENDP0, SaveRState);
- _SetEPTxStatus(ENDP0, SaveTState);
- return;
- }
- else if ((wEPVal &EP_SETUP) != 0)
- {
- _ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */
- Setup0_Process();
- /* before terminate set Tx & Rx status */
- _SetEPRxStatus(ENDP0, SaveRState);
- _SetEPTxStatus(ENDP0, SaveTState);
- return;
- }
-
- else if ((wEPVal & EP_CTR_RX) != 0)
- {
- _ClearEP_CTR_RX(ENDP0);
- Out0_Process();
- /* before terminate set Tx & Rx status */
- _SetEPRxStatus(ENDP0, SaveRState);
- _SetEPTxStatus(ENDP0, SaveTState);
- return;
- }
- }
- }/* if(EPindex == 0) */
- else
- {
- /* Decode and service non control endpoints interrupt */
-
- /* process related endpoint register */
- wEPVal = _GetENDPOINT(EPindex);
- if ((wEPVal & EP_CTR_RX) != 0)
- {
- /* clear int flag */
- _ClearEP_CTR_RX(EPindex);
-
- /* call OUT service function */
- (*pEpInt_OUT[EPindex-1])();
-
- } /* if((wEPVal & EP_CTR_RX) */
-
- if ((wEPVal & EP_CTR_TX) != 0)
- {
- /* clear int flag */
- _ClearEP_CTR_TX(EPindex);
-
- /* call IN service function */
- (*pEpInt_IN[EPindex-1])();
- } /* if((wEPVal & EP_CTR_TX) != 0) */
-
- }/* if(EPindex == 0) else */
-
- }/* while(...) */
-}
-
-/*******************************************************************************
-* Function Name : CTR_HP.
-* Description : High Priority Endpoint Correct Transfer interrupt's service
-* routine.
-* Input : None.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void CTR_HP(void)
-{
- u32 wEPVal = 0;
-
- while (((wIstr = _GetISTR()) & ISTR_CTR) != 0)
- {
- _SetISTR((u16)CLR_CTR); /* clear CTR flag */
- /* extract highest priority endpoint number */
- EPindex = (u8)(wIstr & ISTR_EP_ID);
- /* process related endpoint register */
- wEPVal = _GetENDPOINT(EPindex);
- if ((wEPVal & EP_CTR_RX) != 0)
- {
- /* clear int flag */
- _ClearEP_CTR_RX(EPindex);
-
- /* call OUT service function */
- (*pEpInt_OUT[EPindex-1])();
-
- } /* if((wEPVal & EP_CTR_RX) */
- else if ((wEPVal & EP_CTR_TX) != 0)
- {
- /* clear int flag */
- _ClearEP_CTR_TX(EPindex);
-
- /* call IN service function */
- (*pEpInt_IN[EPindex-1])();
-
-
- } /* if((wEPVal & EP_CTR_TX) != 0) */
-
- }/* while(...) */
-}
-
-/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_int.c
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Endpoint CTR (Low and High) interrupt's service routines
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Includes ------------------------------------------------------------------*/
+#include "usb_lib.h"
+
+/* Private typedef -----------------------------------------------------------*/
+/* Private define ------------------------------------------------------------*/
+/* Private macro -------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+u16 SaveRState;
+u16 SaveTState;
+
+/* Extern variables ----------------------------------------------------------*/
+extern void (*pEpInt_IN[7])(void); /* Handles IN interrupts */
+extern void (*pEpInt_OUT[7])(void); /* Handles OUT interrupts */
+
+/* Private function prototypes -----------------------------------------------*/
+/* Private functions ---------------------------------------------------------*/
+
+/*******************************************************************************
+* Function Name : CTR_LP.
+* Description : Low priority Endpoint Correct Transfer interrupt's service
+* routine.
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void CTR_LP(void)
+{
+ u32 wEPVal = 0;
+ /* stay in loop while pending ints */
+ while (((wIstr = _GetISTR()) & ISTR_CTR) != 0)
+ {
+ _SetISTR((u16)CLR_CTR); /* clear CTR flag */
+ /* extract highest priority endpoint number */
+ EPindex = (u8)(wIstr & ISTR_EP_ID);
+ if (EPindex == 0)
+ {
+ /* Decode and service control endpoint interrupt */
+ /* calling related service routine */
+ /* (Setup0_Process, In0_Process, Out0_Process) */
+
+ /* save RX & TX status */
+ /* and set both to NAK */
+ SaveRState = _GetEPRxStatus(ENDP0);
+ SaveTState = _GetEPTxStatus(ENDP0);
+ _SetEPRxStatus(ENDP0, EP_RX_NAK);
+ _SetEPTxStatus(ENDP0, EP_TX_NAK);
+
+
+ /* DIR bit = origin of the interrupt */
+
+ if ((wIstr & ISTR_DIR) == 0)
+ {
+ /* DIR = 0 */
+
+ /* DIR = 0 => IN int */
+ /* DIR = 0 implies that (EP_CTR_TX = 1) always */
+
+
+ _ClearEP_CTR_TX(ENDP0);
+ In0_Process();
+
+ /* before terminate set Tx & Rx status */
+ _SetEPRxStatus(ENDP0, SaveRState);
+ _SetEPTxStatus(ENDP0, SaveTState);
+ return;
+ }
+ else
+ {
+ /* DIR = 1 */
+
+ /* DIR = 1 & CTR_RX => SETUP or OUT int */
+ /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */
+
+ wEPVal = _GetENDPOINT(ENDP0);
+ if ((wEPVal & EP_CTR_TX) != 0)
+ {
+ _ClearEP_CTR_TX(ENDP0);
+ In0_Process();
+ /* before terminate set Tx & Rx status */
+ _SetEPRxStatus(ENDP0, SaveRState);
+ _SetEPTxStatus(ENDP0, SaveTState);
+ return;
+ }
+ else if ((wEPVal &EP_SETUP) != 0)
+ {
+ _ClearEP_CTR_RX(ENDP0); /* SETUP bit kept frozen while CTR_RX = 1 */
+ Setup0_Process();
+ /* before terminate set Tx & Rx status */
+ _SetEPRxStatus(ENDP0, SaveRState);
+ _SetEPTxStatus(ENDP0, SaveTState);
+ return;
+ }
+
+ else if ((wEPVal & EP_CTR_RX) != 0)
+ {
+ _ClearEP_CTR_RX(ENDP0);
+ Out0_Process();
+ /* before terminate set Tx & Rx status */
+ _SetEPRxStatus(ENDP0, SaveRState);
+ _SetEPTxStatus(ENDP0, SaveTState);
+ return;
+ }
+ }
+ }/* if(EPindex == 0) */
+ else
+ {
+ /* Decode and service non control endpoints interrupt */
+
+ /* process related endpoint register */
+ wEPVal = _GetENDPOINT(EPindex);
+ if ((wEPVal & EP_CTR_RX) != 0)
+ {
+ /* clear int flag */
+ _ClearEP_CTR_RX(EPindex);
+
+ /* call OUT service function */
+ (*pEpInt_OUT[EPindex-1])();
+
+ } /* if((wEPVal & EP_CTR_RX) */
+
+ if ((wEPVal & EP_CTR_TX) != 0)
+ {
+ /* clear int flag */
+ _ClearEP_CTR_TX(EPindex);
+
+ /* call IN service function */
+ (*pEpInt_IN[EPindex-1])();
+ } /* if((wEPVal & EP_CTR_TX) != 0) */
+
+ }/* if(EPindex == 0) else */
+
+ }/* while(...) */
+}
+
+/*******************************************************************************
+* Function Name : CTR_HP.
+* Description : High Priority Endpoint Correct Transfer interrupt's service
+* routine.
+* Input : None.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void CTR_HP(void)
+{
+ u32 wEPVal = 0;
+
+ while (((wIstr = _GetISTR()) & ISTR_CTR) != 0)
+ {
+ _SetISTR((u16)CLR_CTR); /* clear CTR flag */
+ /* extract highest priority endpoint number */
+ EPindex = (u8)(wIstr & ISTR_EP_ID);
+ /* process related endpoint register */
+ wEPVal = _GetENDPOINT(EPindex);
+ if ((wEPVal & EP_CTR_RX) != 0)
+ {
+ /* clear int flag */
+ _ClearEP_CTR_RX(EPindex);
+
+ /* call OUT service function */
+ (*pEpInt_OUT[EPindex-1])();
+
+ } /* if((wEPVal & EP_CTR_RX) */
+ else if ((wEPVal & EP_CTR_TX) != 0)
+ {
+ /* clear int flag */
+ _ClearEP_CTR_TX(EPindex);
+
+ /* call IN service function */
+ (*pEpInt_IN[EPindex-1])();
+
+
+ } /* if((wEPVal & EP_CTR_TX) != 0) */
+
+ }/* while(...) */
+}
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/libmaple/usb/usb_lib/usb_int.h b/libmaple/usb/usb_lib/usb_int.h
index 10a33fb..5c14711 100644
--- a/libmaple/usb/usb_lib/usb_int.h
+++ b/libmaple/usb/usb_lib/usb_int.h
@@ -1,41 +1,41 @@
-/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
-* File Name : usb_int.h
-* Author : MCD Application Team
-* Version : V2.2.1
-* Date : 09/22/2008
-* Description : Endpoint CTR (Low and High) interrupt's service routines
-* prototypes
-********************************************************************************
-* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
-* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
-* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
-* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
-* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
-* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
-*******************************************************************************/
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __USB_INT_H
-#define __USB_INT_H
-
-/* Includes ------------------------------------------------------------------*/
-/* Exported types ------------------------------------------------------------*/
-/* Exported constants --------------------------------------------------------*/
-/* Exported macro ------------------------------------------------------------*/
-/* Exported functions ------------------------------------------------------- */
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-void CTR_LP(void);
-void CTR_HP(void);
-
-/* External variables --------------------------------------------------------*/
-
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /* __USB_INT_H */
-
-/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_int.h
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Endpoint CTR (Low and High) interrupt's service routines
+* prototypes
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USB_INT_H
+#define __USB_INT_H
+
+/* Includes ------------------------------------------------------------------*/
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+void CTR_LP(void);
+void CTR_HP(void);
+
+/* External variables --------------------------------------------------------*/
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __USB_INT_H */
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/libmaple/usb/usb_lib/usb_lib.h b/libmaple/usb/usb_lib/usb_lib.h
index 5d14b5a..4437b8d 100644
--- a/libmaple/usb/usb_lib/usb_lib.h
+++ b/libmaple/usb/usb_lib/usb_lib.h
@@ -1,37 +1,37 @@
-/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
-* File Name : usb_lib.h
-* Author : MCD Application Team
-* Version : V2.2.1
-* Date : 09/22/2008
-* Description : USB library include files
-********************************************************************************
-* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
-* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
-* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
-* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
-* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
-* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
-*******************************************************************************/
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __USB_LIB_H
-#define __USB_LIB_H
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_type.h"
-#include "usb_regs.h"
-#include "usb_def.h"
-#include "usb_core.h"
-#include "usb_init.h"
-#include "usb_mem.h"
-#include "usb_int.h"
-
-/* Exported types ------------------------------------------------------------*/
-/* Exported constants --------------------------------------------------------*/
-/* Exported macro ------------------------------------------------------------*/
-/* Exported functions ------------------------------------------------------- */
-/* External variables --------------------------------------------------------*/
-
-#endif /* __USB_LIB_H */
-
-/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_lib.h
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : USB library include files
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USB_LIB_H
+#define __USB_LIB_H
+
+/* Includes ------------------------------------------------------------------*/
+#include "usb_type.h"
+#include "usb_regs.h"
+#include "usb_def.h"
+#include "usb_core.h"
+#include "usb_init.h"
+#include "usb_mem.h"
+#include "usb_int.h"
+
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+/* External variables --------------------------------------------------------*/
+
+#endif /* __USB_LIB_H */
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/libmaple/usb/usb_lib/usb_mem.c b/libmaple/usb/usb_lib/usb_mem.c
index 90ffc62..ad9740a 100644
--- a/libmaple/usb/usb_lib/usb_mem.c
+++ b/libmaple/usb/usb_lib/usb_mem.c
@@ -1,73 +1,73 @@
-/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
-* File Name : usb_mem.c
-* Author : MCD Application Team
-* Version : V2.2.1
-* Date : 09/22/2008
-* Description : Utility functions for memory transfers to/from PMA
-********************************************************************************
-* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
-* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
-* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
-* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
-* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
-* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
-*******************************************************************************/
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_lib.h"
-
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-/* Private macro -------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-/* Extern variables ----------------------------------------------------------*/
-/* Private function prototypes -----------------------------------------------*/
-/* Private functions ---------------------------------------------------------*/
-/*******************************************************************************
-* Function Name : UserToPMABufferCopy
-* Description : Copy a buffer from user memory area to packet memory area (PMA)
-* Input : - pbUsrBuf: pointer to user memory area.
-* - wPMABufAddr: address into PMA.
-* - wNBytes: no. of bytes to be copied.
-* Output : None.
-* Return : None .
-*******************************************************************************/
-void UserToPMABufferCopy(const u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes)
-{
- u32 n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */
- u32 i, temp1, temp2;
- u16 *pdwVal;
- pdwVal = (u16 *)(wPMABufAddr * 2 + PMAAddr);
- for (i = n; i != 0; i--)
- {
- temp1 = (u16) * pbUsrBuf;
- pbUsrBuf++;
- temp2 = temp1 | (u16) * pbUsrBuf << 8;
- *pdwVal++ = temp2;
- pdwVal++;
- pbUsrBuf++;
- }
-}
-/*******************************************************************************
-* Function Name : PMAToUserBufferCopy
-* Description : Copy a buffer from user memory area to packet memory area (PMA)
-* Input : - pbUsrBuf = pointer to user memory area.
-* - wPMABufAddr = address into PMA.
-* - wNBytes = no. of bytes to be copied.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void PMAToUserBufferCopy(u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes)
-{
- u32 n = (wNBytes + 1) >> 1;/* /2*/
- u32 i;
- u32 *pdwVal;
- pdwVal = (u32 *)(wPMABufAddr * 2 + PMAAddr);
- for (i = n; i != 0; i--)
- {
- *(u16*)pbUsrBuf++ = *pdwVal++;
- pbUsrBuf++;
- }
-}
-
-/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_mem.c
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Utility functions for memory transfers to/from PMA
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Includes ------------------------------------------------------------------*/
+#include "usb_lib.h"
+
+/* Private typedef -----------------------------------------------------------*/
+/* Private define ------------------------------------------------------------*/
+/* Private macro -------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+/* Extern variables ----------------------------------------------------------*/
+/* Private function prototypes -----------------------------------------------*/
+/* Private functions ---------------------------------------------------------*/
+/*******************************************************************************
+* Function Name : UserToPMABufferCopy
+* Description : Copy a buffer from user memory area to packet memory area (PMA)
+* Input : - pbUsrBuf: pointer to user memory area.
+* - wPMABufAddr: address into PMA.
+* - wNBytes: no. of bytes to be copied.
+* Output : None.
+* Return : None .
+*******************************************************************************/
+void UserToPMABufferCopy(const u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes)
+{
+ u32 n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */
+ u32 i, temp1, temp2;
+ u16 *pdwVal;
+ pdwVal = (u16 *)(wPMABufAddr * 2 + PMAAddr);
+ for (i = n; i != 0; i--)
+ {
+ temp1 = (u16) * pbUsrBuf;
+ pbUsrBuf++;
+ temp2 = temp1 | (u16) * pbUsrBuf << 8;
+ *pdwVal++ = temp2;
+ pdwVal++;
+ pbUsrBuf++;
+ }
+}
+/*******************************************************************************
+* Function Name : PMAToUserBufferCopy
+* Description : Copy a buffer from user memory area to packet memory area (PMA)
+* Input : - pbUsrBuf = pointer to user memory area.
+* - wPMABufAddr = address into PMA.
+* - wNBytes = no. of bytes to be copied.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void PMAToUserBufferCopy(u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes)
+{
+ u32 n = (wNBytes + 1) >> 1;/* /2*/
+ u32 i;
+ u32 *pdwVal;
+ pdwVal = (u32 *)(wPMABufAddr * 2 + PMAAddr);
+ for (i = n; i != 0; i--)
+ {
+ *(u16*)pbUsrBuf++ = *pdwVal++;
+ pbUsrBuf++;
+ }
+}
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/libmaple/usb/usb_lib/usb_mem.h b/libmaple/usb/usb_lib/usb_mem.h
index 60ff9f1..b0e0474 100644
--- a/libmaple/usb/usb_lib/usb_mem.h
+++ b/libmaple/usb/usb_lib/usb_mem.h
@@ -1,40 +1,40 @@
-/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
-* File Name : usb_mem.h
-* Author : MCD Application Team
-* Version : V2.2.1
-* Date : 09/22/2008
-* Description : Utility prototypes functions for memory/PMA transfers
-********************************************************************************
-* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
-* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
-* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
-* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
-* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
-* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
-*******************************************************************************/
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __USB_MEM_H
-#define __USB_MEM_H
-
-/* Includes ------------------------------------------------------------------*/
-/* Exported types ------------------------------------------------------------*/
-/* Exported constants --------------------------------------------------------*/
-/* Exported macro ------------------------------------------------------------*/
-/* Exported functions ------------------------------------------------------- */
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-void UserToPMABufferCopy(const u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes);
-void PMAToUserBufferCopy(u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes);
-
-#if defined(__cplusplus)
-}
-#endif
-
-/* External variables --------------------------------------------------------*/
-
-#endif /*__USB_MEM_H*/
-
-/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_mem.h
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Utility prototypes functions for memory/PMA transfers
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USB_MEM_H
+#define __USB_MEM_H
+
+/* Includes ------------------------------------------------------------------*/
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+void UserToPMABufferCopy(const u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes);
+void PMAToUserBufferCopy(u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes);
+
+#if defined(__cplusplus)
+}
+#endif
+
+/* External variables --------------------------------------------------------*/
+
+#endif /*__USB_MEM_H*/
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/libmaple/usb/usb_lib/usb_regs.c b/libmaple/usb/usb_lib/usb_regs.c
index c28ef5a..c7e0276 100644
--- a/libmaple/usb/usb_lib/usb_regs.c
+++ b/libmaple/usb/usb_lib/usb_regs.c
@@ -1,748 +1,748 @@
-/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
-* File Name : usb_regs.c
-* Author : MCD Application Team
-* Version : V2.2.1
-* Date : 09/22/2008
-* Description : Interface functions to USB cell registers
-********************************************************************************
-* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
-* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
-* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
-* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
-* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
-* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
-*******************************************************************************/
-
-/* Includes ------------------------------------------------------------------*/
-#include "usb_lib.h"
-
-/* Private typedef -----------------------------------------------------------*/
-/* Private define ------------------------------------------------------------*/
-/* Private macro -------------------------------------------------------------*/
-/* Private variables ---------------------------------------------------------*/
-/* Extern variables ----------------------------------------------------------*/
-/* Private function prototypes -----------------------------------------------*/
-/* Private functions ---------------------------------------------------------*/
-
-/*******************************************************************************
-* Function Name : SetCNTR.
-* Description : Set the CNTR register value.
-* Input : wRegValue: new register value.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetCNTR(u16 wRegValue)
-{
- _SetCNTR(wRegValue);
-}
-
-/*******************************************************************************
-* Function Name : GetCNTR.
-* Description : returns the CNTR register value.
-* Input : None.
-* Output : None.
-* Return : CNTR register Value.
-*******************************************************************************/
-u16 GetCNTR(void)
-{
- return(_GetCNTR());
-}
-
-/*******************************************************************************
-* Function Name : SetISTR.
-* Description : Set the ISTR register value.
-* Input : wRegValue: new register value.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetISTR(u16 wRegValue)
-{
- _SetISTR(wRegValue);
-}
-
-/*******************************************************************************
-* Function Name : GetISTR
-* Description : Returns the ISTR register value.
-* Input : None.
-* Output : None.
-* Return : ISTR register Value
-*******************************************************************************/
-u16 GetISTR(void)
-{
- return(_GetISTR());
-}
-
-/*******************************************************************************
-* Function Name : GetFNR
-* Description : Returns the FNR register value.
-* Input : None.
-* Output : None.
-* Return : FNR register Value
-*******************************************************************************/
-u16 GetFNR(void)
-{
- return(_GetFNR());
-}
-
-/*******************************************************************************
-* Function Name : SetDADDR
-* Description : Set the DADDR register value.
-* Input : wRegValue: new register value.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetDADDR(u16 wRegValue)
-{
- _SetDADDR(wRegValue);
-}
-
-/*******************************************************************************
-* Function Name : GetDADDR
-* Description : Returns the DADDR register value.
-* Input : None.
-* Output : None.
-* Return : DADDR register Value
-*******************************************************************************/
-u16 GetDADDR(void)
-{
- return(_GetDADDR());
-}
-
-/*******************************************************************************
-* Function Name : SetBTABLE
-* Description : Set the BTABLE.
-* Input : wRegValue: New register value.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetBTABLE(u16 wRegValue)
-{
- _SetBTABLE(wRegValue);
-}
-
-/*******************************************************************************
-* Function Name : GetBTABLE.
-* Description : Returns the BTABLE register value.
-* Input : None.
-* Output : None.
-* Return : BTABLE address.
-*******************************************************************************/
-u16 GetBTABLE(void)
-{
- return(_GetBTABLE());
-}
-
-/*******************************************************************************
-* Function Name : SetENDPOINT
-* Description : Setthe Endpoint register value.
-* Input : bEpNum: Endpoint Number.
-* wRegValue.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetENDPOINT(u8 bEpNum, u16 wRegValue)
-{
- _SetENDPOINT(bEpNum, wRegValue);
-}
-
-/*******************************************************************************
-* Function Name : GetENDPOINT
-* Description : Return the Endpoint register value.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : Endpoint register value.
-*******************************************************************************/
-u16 GetENDPOINT(u8 bEpNum)
-{
- return(_GetENDPOINT(bEpNum));
-}
-
-/*******************************************************************************
-* Function Name : SetEPType
-* Description : sets the type in the endpoint register.
-* Input : bEpNum: Endpoint Number.
-* wType: type definition.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetEPType(u8 bEpNum, u16 wType)
-{
- _SetEPType(bEpNum, wType);
-}
-
-/*******************************************************************************
-* Function Name : GetEPType
-* Description : Returns the endpoint type.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : Endpoint Type
-*******************************************************************************/
-u16 GetEPType(u8 bEpNum)
-{
- return(_GetEPType(bEpNum));
-}
-
-/*******************************************************************************
-* Function Name : SetEPTxStatus
-* Description : Set the status of Tx endpoint.
-* Input : bEpNum: Endpoint Number.
-* wState: new state.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetEPTxStatus(u8 bEpNum, u16 wState)
-{
- _SetEPTxStatus(bEpNum, wState);
-}
-
-/*******************************************************************************
-* Function Name : SetEPRxStatus
-* Description : Set the status of Rx endpoint.
-* Input : bEpNum: Endpoint Number.
-* wState: new state.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetEPRxStatus(u8 bEpNum, u16 wState)
-{
- _SetEPRxStatus(bEpNum, wState);
-}
-
-/*******************************************************************************
-* Function Name : SetDouBleBuffEPStall
-* Description : sets the status for Double Buffer Endpoint to STALL
-* Input : bEpNum: Endpoint Number.
-* bDir: Endpoint direction.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetDouBleBuffEPStall(u8 bEpNum, u8 bDir)
-{
- u16 Endpoint_DTOG_Status;
- Endpoint_DTOG_Status = GetENDPOINT(bEpNum);
- if (bDir == EP_DBUF_OUT)
- { /* OUT double buffered endpoint */
- _SetENDPOINT(bEpNum, Endpoint_DTOG_Status & ~EPRX_DTOG1);
- }
- else if (bDir == EP_DBUF_IN)
- { /* IN double buffered endpoint */
- _SetENDPOINT(bEpNum, Endpoint_DTOG_Status & ~EPTX_DTOG1);
- }
-}
-
-/*******************************************************************************
-* Function Name : GetEPTxStatus
-* Description : Returns the endpoint Tx status.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : Endpoint TX Status
-*******************************************************************************/
-u16 GetEPTxStatus(u8 bEpNum)
-{
- return(_GetEPTxStatus(bEpNum));
-}
-
-/*******************************************************************************
-* Function Name : GetEPRxStatus
-* Description : Returns the endpoint Rx status.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : Endpoint RX Status
-*******************************************************************************/
-u16 GetEPRxStatus(u8 bEpNum)
-{
- return(_GetEPRxStatus(bEpNum));
-}
-
-/*******************************************************************************
-* Function Name : SetEPTxValid
-* Description : Valid the endpoint Tx Status.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetEPTxValid(u8 bEpNum)
-{
- _SetEPTxStatus(bEpNum, EP_TX_VALID);
-}
-
-/*******************************************************************************
-* Function Name : SetEPRxValid
-* Description : Valid the endpoint Rx Status.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetEPRxValid(u8 bEpNum)
-{
- _SetEPRxStatus(bEpNum, EP_RX_VALID);
-}
-
-/*******************************************************************************
-* Function Name : SetEP_KIND
-* Description : Clear the EP_KIND bit.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetEP_KIND(u8 bEpNum)
-{
- _SetEP_KIND(bEpNum);
-}
-
-/*******************************************************************************
-* Function Name : ClearEP_KIND
-* Description : set the EP_KIND bit.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void ClearEP_KIND(u8 bEpNum)
-{
- _ClearEP_KIND(bEpNum);
-}
-/*******************************************************************************
-* Function Name : Clear_Status_Out
-* Description : Clear the Status Out of the related Endpoint
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void Clear_Status_Out(u8 bEpNum)
-{
- _ClearEP_KIND(bEpNum);
-}
-/*******************************************************************************
-* Function Name : Set_Status_Out
-* Description : Set the Status Out of the related Endpoint
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void Set_Status_Out(u8 bEpNum)
-{
- _SetEP_KIND(bEpNum);
-}
-/*******************************************************************************
-* Function Name : SetEPDoubleBuff
-* Description : Enable the double buffer feature for the endpoint.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetEPDoubleBuff(u8 bEpNum)
-{
- _SetEP_KIND(bEpNum);
-}
-/*******************************************************************************
-* Function Name : ClearEPDoubleBuff
-* Description : Disable the double buffer feature for the endpoint.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void ClearEPDoubleBuff(u8 bEpNum)
-{
- _ClearEP_KIND(bEpNum);
-}
-/*******************************************************************************
-* Function Name : GetTxStallStatus
-* Description : Returns the Stall status of the Tx endpoint.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : Tx Stall status.
-*******************************************************************************/
-u16 GetTxStallStatus(u8 bEpNum)
-{
- return(_GetTxStallStatus(bEpNum));
-}
-/*******************************************************************************
-* Function Name : GetRxStallStatus
-* Description : Returns the Stall status of the Rx endpoint.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : Rx Stall status.
-*******************************************************************************/
-u16 GetRxStallStatus(u8 bEpNum)
-{
- return(_GetRxStallStatus(bEpNum));
-}
-/*******************************************************************************
-* Function Name : ClearEP_CTR_RX
-* Description : Clear the CTR_RX bit.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void ClearEP_CTR_RX(u8 bEpNum)
-{
- _ClearEP_CTR_RX(bEpNum);
-}
-/*******************************************************************************
-* Function Name : ClearEP_CTR_TX
-* Description : Clear the CTR_TX bit.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void ClearEP_CTR_TX(u8 bEpNum)
-{
- _ClearEP_CTR_TX(bEpNum);
-}
-/*******************************************************************************
-* Function Name : ToggleDTOG_RX
-* Description : Toggle the DTOG_RX bit.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void ToggleDTOG_RX(u8 bEpNum)
-{
- _ToggleDTOG_RX(bEpNum);
-}
-/*******************************************************************************
-* Function Name : ToggleDTOG_TX
-* Description : Toggle the DTOG_TX bit.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void ToggleDTOG_TX(u8 bEpNum)
-{
- _ToggleDTOG_TX(bEpNum);
-}
-/*******************************************************************************
-* Function Name : ClearDTOG_RX.
-* Description : Clear the DTOG_RX bit.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void ClearDTOG_RX(u8 bEpNum)
-{
- _ClearDTOG_RX(bEpNum);
-}
-/*******************************************************************************
-* Function Name : ClearDTOG_TX.
-* Description : Clear the DTOG_TX bit.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void ClearDTOG_TX(u8 bEpNum)
-{
- _ClearDTOG_TX(bEpNum);
-}
-/*******************************************************************************
-* Function Name : SetEPAddress
-* Description : Set the endpoint address.
-* Input : bEpNum: Endpoint Number.
-* bAddr: New endpoint address.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetEPAddress(u8 bEpNum, u8 bAddr)
-{
- _SetEPAddress(bEpNum, bAddr);
-}
-/*******************************************************************************
-* Function Name : GetEPAddress
-* Description : Get the endpoint address.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : Endpoint address.
-*******************************************************************************/
-u8 GetEPAddress(u8 bEpNum)
-{
- return(_GetEPAddress(bEpNum));
-}
-/*******************************************************************************
-* Function Name : SetEPTxAddr
-* Description : Set the endpoint Tx buffer address.
-* Input : bEpNum: Endpoint Number.
-* wAddr: new address.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetEPTxAddr(u8 bEpNum, u16 wAddr)
-{
- _SetEPTxAddr(bEpNum, wAddr);
-}
-/*******************************************************************************
-* Function Name : SetEPRxAddr
-* Description : Set the endpoint Rx buffer address.
-* Input : bEpNum: Endpoint Number.
-* wAddr: new address.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetEPRxAddr(u8 bEpNum, u16 wAddr)
-{
- _SetEPRxAddr(bEpNum, wAddr);
-}
-/*******************************************************************************
-* Function Name : GetEPTxAddr
-* Description : Returns the endpoint Tx buffer address.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : Rx buffer address.
-*******************************************************************************/
-u16 GetEPTxAddr(u8 bEpNum)
-{
- return(_GetEPTxAddr(bEpNum));
-}
-/*******************************************************************************
-* Function Name : GetEPRxAddr.
-* Description : Returns the endpoint Rx buffer address.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : Rx buffer address.
-*******************************************************************************/
-u16 GetEPRxAddr(u8 bEpNum)
-{
- return(_GetEPRxAddr(bEpNum));
-}
-/*******************************************************************************
-* Function Name : SetEPTxCount.
-* Description : Set the Tx count.
-* Input : bEpNum: Endpoint Number.
-* wCount: new count value.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetEPTxCount(u8 bEpNum, u16 wCount)
-{
- _SetEPTxCount(bEpNum, wCount);
-}
-/*******************************************************************************
-* Function Name : SetEPCountRxReg.
-* Description : Set the Count Rx Register value.
-* Input : *pdwReg: point to the register.
-* wCount: the new register value.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetEPCountRxReg(u32 *pdwReg, u16 wCount)
-{
- _SetEPCountRxReg(dwReg, wCount);
-}
-/*******************************************************************************
-* Function Name : SetEPRxCount
-* Description : Set the Rx count.
-* Input : bEpNum: Endpoint Number.
-* wCount: the new count value.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetEPRxCount(u8 bEpNum, u16 wCount)
-{
- _SetEPRxCount(bEpNum, wCount);
-}
-/*******************************************************************************
-* Function Name : GetEPTxCount
-* Description : Get the Tx count.
-* Input : bEpNum: Endpoint Number.
-* Output : None
-* Return : Tx count value.
-*******************************************************************************/
-u16 GetEPTxCount(u8 bEpNum)
-{
- return(_GetEPTxCount(bEpNum));
-}
-/*******************************************************************************
-* Function Name : GetEPRxCount
-* Description : Get the Rx count.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : Rx count value.
-*******************************************************************************/
-u16 GetEPRxCount(u8 bEpNum)
-{
- return(_GetEPRxCount(bEpNum));
-}
-/*******************************************************************************
-* Function Name : SetEPDblBuffAddr
-* Description : Set the addresses of the buffer 0 and 1.
-* Input : bEpNum: Endpoint Number.
-* wBuf0Addr: new address of buffer 0.
-* wBuf1Addr: new address of buffer 1.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetEPDblBuffAddr(u8 bEpNum, u16 wBuf0Addr, u16 wBuf1Addr)
-{
- _SetEPDblBuffAddr(bEpNum, wBuf0Addr, wBuf1Addr);
-}
-/*******************************************************************************
-* Function Name : SetEPDblBuf0Addr
-* Description : Set the Buffer 1 address.
-* Input : bEpNum: Endpoint Number
-* wBuf0Addr: new address.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetEPDblBuf0Addr(u8 bEpNum, u16 wBuf0Addr)
-{
- _SetEPDblBuf0Addr(bEpNum, wBuf0Addr);
-}
-/*******************************************************************************
-* Function Name : SetEPDblBuf1Addr
-* Description : Set the Buffer 1 address.
-* Input : bEpNum: Endpoint Number
-* wBuf1Addr: new address.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetEPDblBuf1Addr(u8 bEpNum, u16 wBuf1Addr)
-{
- _SetEPDblBuf1Addr(bEpNum, wBuf1Addr);
-}
-/*******************************************************************************
-* Function Name : GetEPDblBuf0Addr
-* Description : Returns the address of the Buffer 0.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-u16 GetEPDblBuf0Addr(u8 bEpNum)
-{
- return(_GetEPDblBuf0Addr(bEpNum));
-}
-/*******************************************************************************
-* Function Name : GetEPDblBuf1Addr
-* Description : Returns the address of the Buffer 1.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : Address of the Buffer 1.
-*******************************************************************************/
-u16 GetEPDblBuf1Addr(u8 bEpNum)
-{
- return(_GetEPDblBuf1Addr(bEpNum));
-}
-/*******************************************************************************
-* Function Name : SetEPDblBuffCount
-* Description : Set the number of bytes for a double Buffer
-* endpoint.
-* Input : bEpNum,bDir, wCount
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetEPDblBuffCount(u8 bEpNum, u8 bDir, u16 wCount)
-{
- _SetEPDblBuffCount(bEpNum, bDir, wCount);
-}
-/*******************************************************************************
-* Function Name : SetEPDblBuf0Count
-* Description : Set the number of bytes in the buffer 0 of a double Buffer
-* endpoint.
-* Input : bEpNum, bDir, wCount
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetEPDblBuf0Count(u8 bEpNum, u8 bDir, u16 wCount)
-{
- _SetEPDblBuf0Count(bEpNum, bDir, wCount);
-}
-/*******************************************************************************
-* Function Name : SetEPDblBuf1Count
-* Description : Set the number of bytes in the buffer 0 of a double Buffer
-* endpoint.
-* Input : bEpNum, bDir, wCount
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void SetEPDblBuf1Count(u8 bEpNum, u8 bDir, u16 wCount)
-{
- _SetEPDblBuf1Count(bEpNum, bDir, wCount);
-}
-/*******************************************************************************
-* Function Name : GetEPDblBuf0Count
-* Description : Returns the number of byte received in the buffer 0 of a double
-* Buffer endpoint.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : Endpoint Buffer 0 count
-*******************************************************************************/
-u16 GetEPDblBuf0Count(u8 bEpNum)
-{
- return(_GetEPDblBuf0Count(bEpNum));
-}
-/*******************************************************************************
-* Function Name : GetEPDblBuf1Count
-* Description : Returns the number of data received in the buffer 1 of a double
-* Buffer endpoint.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : Endpoint Buffer 1 count.
-*******************************************************************************/
-u16 GetEPDblBuf1Count(u8 bEpNum)
-{
- return(_GetEPDblBuf1Count(bEpNum));
-}
-/*******************************************************************************
-* Function Name : GetEPDblBufDir
-* Description : gets direction of the double buffered endpoint
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : EP_DBUF_OUT, EP_DBUF_IN,
-* EP_DBUF_ERR if the endpoint counter not yet programmed.
-*******************************************************************************/
-EP_DBUF_DIR GetEPDblBufDir(u8 bEpNum)
-{
- if ((u16)(*_pEPRxCount(bEpNum) & 0xFC00) != 0)
- return(EP_DBUF_OUT);
- else if (((u16)(*_pEPTxCount(bEpNum)) & 0x03FF) != 0)
- return(EP_DBUF_IN);
- else
- return(EP_DBUF_ERR);
-}
-/*******************************************************************************
-* Function Name : FreeUserBuffer
-* Description : free buffer used from the application realizing it to the line
- toggles bit SW_BUF in the double buffered endpoint register
-* Input : bEpNum, bDir
-* Output : None.
-* Return : None.
-*******************************************************************************/
-void FreeUserBuffer(u8 bEpNum, u8 bDir)
-{
- if (bDir == EP_DBUF_OUT)
- { /* OUT double buffered endpoint */
- _ToggleDTOG_TX(bEpNum);
- }
- else if (bDir == EP_DBUF_IN)
- { /* IN double buffered endpoint */
- _ToggleDTOG_RX(bEpNum);
- }
-}
-
-/*******************************************************************************
-* Function Name : ToWord
-* Description : merge two byte in a word.
-* Input : bh: byte high, bl: bytes low.
-* Output : None.
-* Return : resulted word.
-*******************************************************************************/
-u16 ToWord(u8 bh, u8 bl)
-{
- u16 wRet;
- wRet = (u16)bl | ((u16)bh << 8);
- return(wRet);
-}
-/*******************************************************************************
-* Function Name : ByteSwap
-* Description : Swap two byte in a word.
-* Input : wSwW: word to Swap.
-* Output : None.
-* Return : resulted word.
-*******************************************************************************/
-u16 ByteSwap(u16 wSwW)
-{
- u8 bTemp;
- u16 wRet;
- bTemp = (u8)(wSwW & 0xff);
- wRet = (wSwW >> 8) | ((u16)bTemp << 8);
- return(wRet);
-}
-
-/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_regs.c
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Interface functions to USB cell registers
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Includes ------------------------------------------------------------------*/
+#include "usb_lib.h"
+
+/* Private typedef -----------------------------------------------------------*/
+/* Private define ------------------------------------------------------------*/
+/* Private macro -------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+/* Extern variables ----------------------------------------------------------*/
+/* Private function prototypes -----------------------------------------------*/
+/* Private functions ---------------------------------------------------------*/
+
+/*******************************************************************************
+* Function Name : SetCNTR.
+* Description : Set the CNTR register value.
+* Input : wRegValue: new register value.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetCNTR(u16 wRegValue)
+{
+ _SetCNTR(wRegValue);
+}
+
+/*******************************************************************************
+* Function Name : GetCNTR.
+* Description : returns the CNTR register value.
+* Input : None.
+* Output : None.
+* Return : CNTR register Value.
+*******************************************************************************/
+u16 GetCNTR(void)
+{
+ return(_GetCNTR());
+}
+
+/*******************************************************************************
+* Function Name : SetISTR.
+* Description : Set the ISTR register value.
+* Input : wRegValue: new register value.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetISTR(u16 wRegValue)
+{
+ _SetISTR(wRegValue);
+}
+
+/*******************************************************************************
+* Function Name : GetISTR
+* Description : Returns the ISTR register value.
+* Input : None.
+* Output : None.
+* Return : ISTR register Value
+*******************************************************************************/
+u16 GetISTR(void)
+{
+ return(_GetISTR());
+}
+
+/*******************************************************************************
+* Function Name : GetFNR
+* Description : Returns the FNR register value.
+* Input : None.
+* Output : None.
+* Return : FNR register Value
+*******************************************************************************/
+u16 GetFNR(void)
+{
+ return(_GetFNR());
+}
+
+/*******************************************************************************
+* Function Name : SetDADDR
+* Description : Set the DADDR register value.
+* Input : wRegValue: new register value.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetDADDR(u16 wRegValue)
+{
+ _SetDADDR(wRegValue);
+}
+
+/*******************************************************************************
+* Function Name : GetDADDR
+* Description : Returns the DADDR register value.
+* Input : None.
+* Output : None.
+* Return : DADDR register Value
+*******************************************************************************/
+u16 GetDADDR(void)
+{
+ return(_GetDADDR());
+}
+
+/*******************************************************************************
+* Function Name : SetBTABLE
+* Description : Set the BTABLE.
+* Input : wRegValue: New register value.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetBTABLE(u16 wRegValue)
+{
+ _SetBTABLE(wRegValue);
+}
+
+/*******************************************************************************
+* Function Name : GetBTABLE.
+* Description : Returns the BTABLE register value.
+* Input : None.
+* Output : None.
+* Return : BTABLE address.
+*******************************************************************************/
+u16 GetBTABLE(void)
+{
+ return(_GetBTABLE());
+}
+
+/*******************************************************************************
+* Function Name : SetENDPOINT
+* Description : Setthe Endpoint register value.
+* Input : bEpNum: Endpoint Number.
+* wRegValue.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetENDPOINT(u8 bEpNum, u16 wRegValue)
+{
+ _SetENDPOINT(bEpNum, wRegValue);
+}
+
+/*******************************************************************************
+* Function Name : GetENDPOINT
+* Description : Return the Endpoint register value.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Endpoint register value.
+*******************************************************************************/
+u16 GetENDPOINT(u8 bEpNum)
+{
+ return(_GetENDPOINT(bEpNum));
+}
+
+/*******************************************************************************
+* Function Name : SetEPType
+* Description : sets the type in the endpoint register.
+* Input : bEpNum: Endpoint Number.
+* wType: type definition.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPType(u8 bEpNum, u16 wType)
+{
+ _SetEPType(bEpNum, wType);
+}
+
+/*******************************************************************************
+* Function Name : GetEPType
+* Description : Returns the endpoint type.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Endpoint Type
+*******************************************************************************/
+u16 GetEPType(u8 bEpNum)
+{
+ return(_GetEPType(bEpNum));
+}
+
+/*******************************************************************************
+* Function Name : SetEPTxStatus
+* Description : Set the status of Tx endpoint.
+* Input : bEpNum: Endpoint Number.
+* wState: new state.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPTxStatus(u8 bEpNum, u16 wState)
+{
+ _SetEPTxStatus(bEpNum, wState);
+}
+
+/*******************************************************************************
+* Function Name : SetEPRxStatus
+* Description : Set the status of Rx endpoint.
+* Input : bEpNum: Endpoint Number.
+* wState: new state.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPRxStatus(u8 bEpNum, u16 wState)
+{
+ _SetEPRxStatus(bEpNum, wState);
+}
+
+/*******************************************************************************
+* Function Name : SetDouBleBuffEPStall
+* Description : sets the status for Double Buffer Endpoint to STALL
+* Input : bEpNum: Endpoint Number.
+* bDir: Endpoint direction.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetDouBleBuffEPStall(u8 bEpNum, u8 bDir)
+{
+ u16 Endpoint_DTOG_Status;
+ Endpoint_DTOG_Status = GetENDPOINT(bEpNum);
+ if (bDir == EP_DBUF_OUT)
+ { /* OUT double buffered endpoint */
+ _SetENDPOINT(bEpNum, Endpoint_DTOG_Status & ~EPRX_DTOG1);
+ }
+ else if (bDir == EP_DBUF_IN)
+ { /* IN double buffered endpoint */
+ _SetENDPOINT(bEpNum, Endpoint_DTOG_Status & ~EPTX_DTOG1);
+ }
+}
+
+/*******************************************************************************
+* Function Name : GetEPTxStatus
+* Description : Returns the endpoint Tx status.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Endpoint TX Status
+*******************************************************************************/
+u16 GetEPTxStatus(u8 bEpNum)
+{
+ return(_GetEPTxStatus(bEpNum));
+}
+
+/*******************************************************************************
+* Function Name : GetEPRxStatus
+* Description : Returns the endpoint Rx status.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Endpoint RX Status
+*******************************************************************************/
+u16 GetEPRxStatus(u8 bEpNum)
+{
+ return(_GetEPRxStatus(bEpNum));
+}
+
+/*******************************************************************************
+* Function Name : SetEPTxValid
+* Description : Valid the endpoint Tx Status.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPTxValid(u8 bEpNum)
+{
+ _SetEPTxStatus(bEpNum, EP_TX_VALID);
+}
+
+/*******************************************************************************
+* Function Name : SetEPRxValid
+* Description : Valid the endpoint Rx Status.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPRxValid(u8 bEpNum)
+{
+ _SetEPRxStatus(bEpNum, EP_RX_VALID);
+}
+
+/*******************************************************************************
+* Function Name : SetEP_KIND
+* Description : Clear the EP_KIND bit.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEP_KIND(u8 bEpNum)
+{
+ _SetEP_KIND(bEpNum);
+}
+
+/*******************************************************************************
+* Function Name : ClearEP_KIND
+* Description : set the EP_KIND bit.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void ClearEP_KIND(u8 bEpNum)
+{
+ _ClearEP_KIND(bEpNum);
+}
+/*******************************************************************************
+* Function Name : Clear_Status_Out
+* Description : Clear the Status Out of the related Endpoint
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void Clear_Status_Out(u8 bEpNum)
+{
+ _ClearEP_KIND(bEpNum);
+}
+/*******************************************************************************
+* Function Name : Set_Status_Out
+* Description : Set the Status Out of the related Endpoint
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void Set_Status_Out(u8 bEpNum)
+{
+ _SetEP_KIND(bEpNum);
+}
+/*******************************************************************************
+* Function Name : SetEPDoubleBuff
+* Description : Enable the double buffer feature for the endpoint.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPDoubleBuff(u8 bEpNum)
+{
+ _SetEP_KIND(bEpNum);
+}
+/*******************************************************************************
+* Function Name : ClearEPDoubleBuff
+* Description : Disable the double buffer feature for the endpoint.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void ClearEPDoubleBuff(u8 bEpNum)
+{
+ _ClearEP_KIND(bEpNum);
+}
+/*******************************************************************************
+* Function Name : GetTxStallStatus
+* Description : Returns the Stall status of the Tx endpoint.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Tx Stall status.
+*******************************************************************************/
+u16 GetTxStallStatus(u8 bEpNum)
+{
+ return(_GetTxStallStatus(bEpNum));
+}
+/*******************************************************************************
+* Function Name : GetRxStallStatus
+* Description : Returns the Stall status of the Rx endpoint.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Rx Stall status.
+*******************************************************************************/
+u16 GetRxStallStatus(u8 bEpNum)
+{
+ return(_GetRxStallStatus(bEpNum));
+}
+/*******************************************************************************
+* Function Name : ClearEP_CTR_RX
+* Description : Clear the CTR_RX bit.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void ClearEP_CTR_RX(u8 bEpNum)
+{
+ _ClearEP_CTR_RX(bEpNum);
+}
+/*******************************************************************************
+* Function Name : ClearEP_CTR_TX
+* Description : Clear the CTR_TX bit.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void ClearEP_CTR_TX(u8 bEpNum)
+{
+ _ClearEP_CTR_TX(bEpNum);
+}
+/*******************************************************************************
+* Function Name : ToggleDTOG_RX
+* Description : Toggle the DTOG_RX bit.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void ToggleDTOG_RX(u8 bEpNum)
+{
+ _ToggleDTOG_RX(bEpNum);
+}
+/*******************************************************************************
+* Function Name : ToggleDTOG_TX
+* Description : Toggle the DTOG_TX bit.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void ToggleDTOG_TX(u8 bEpNum)
+{
+ _ToggleDTOG_TX(bEpNum);
+}
+/*******************************************************************************
+* Function Name : ClearDTOG_RX.
+* Description : Clear the DTOG_RX bit.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void ClearDTOG_RX(u8 bEpNum)
+{
+ _ClearDTOG_RX(bEpNum);
+}
+/*******************************************************************************
+* Function Name : ClearDTOG_TX.
+* Description : Clear the DTOG_TX bit.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void ClearDTOG_TX(u8 bEpNum)
+{
+ _ClearDTOG_TX(bEpNum);
+}
+/*******************************************************************************
+* Function Name : SetEPAddress
+* Description : Set the endpoint address.
+* Input : bEpNum: Endpoint Number.
+* bAddr: New endpoint address.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPAddress(u8 bEpNum, u8 bAddr)
+{
+ _SetEPAddress(bEpNum, bAddr);
+}
+/*******************************************************************************
+* Function Name : GetEPAddress
+* Description : Get the endpoint address.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Endpoint address.
+*******************************************************************************/
+u8 GetEPAddress(u8 bEpNum)
+{
+ return(_GetEPAddress(bEpNum));
+}
+/*******************************************************************************
+* Function Name : SetEPTxAddr
+* Description : Set the endpoint Tx buffer address.
+* Input : bEpNum: Endpoint Number.
+* wAddr: new address.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPTxAddr(u8 bEpNum, u16 wAddr)
+{
+ _SetEPTxAddr(bEpNum, wAddr);
+}
+/*******************************************************************************
+* Function Name : SetEPRxAddr
+* Description : Set the endpoint Rx buffer address.
+* Input : bEpNum: Endpoint Number.
+* wAddr: new address.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPRxAddr(u8 bEpNum, u16 wAddr)
+{
+ _SetEPRxAddr(bEpNum, wAddr);
+}
+/*******************************************************************************
+* Function Name : GetEPTxAddr
+* Description : Returns the endpoint Tx buffer address.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Rx buffer address.
+*******************************************************************************/
+u16 GetEPTxAddr(u8 bEpNum)
+{
+ return(_GetEPTxAddr(bEpNum));
+}
+/*******************************************************************************
+* Function Name : GetEPRxAddr.
+* Description : Returns the endpoint Rx buffer address.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Rx buffer address.
+*******************************************************************************/
+u16 GetEPRxAddr(u8 bEpNum)
+{
+ return(_GetEPRxAddr(bEpNum));
+}
+/*******************************************************************************
+* Function Name : SetEPTxCount.
+* Description : Set the Tx count.
+* Input : bEpNum: Endpoint Number.
+* wCount: new count value.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPTxCount(u8 bEpNum, u16 wCount)
+{
+ _SetEPTxCount(bEpNum, wCount);
+}
+/*******************************************************************************
+* Function Name : SetEPCountRxReg.
+* Description : Set the Count Rx Register value.
+* Input : *pdwReg: point to the register.
+* wCount: the new register value.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPCountRxReg(u32 *pdwReg, u16 wCount)
+{
+ _SetEPCountRxReg(dwReg, wCount);
+}
+/*******************************************************************************
+* Function Name : SetEPRxCount
+* Description : Set the Rx count.
+* Input : bEpNum: Endpoint Number.
+* wCount: the new count value.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPRxCount(u8 bEpNum, u16 wCount)
+{
+ _SetEPRxCount(bEpNum, wCount);
+}
+/*******************************************************************************
+* Function Name : GetEPTxCount
+* Description : Get the Tx count.
+* Input : bEpNum: Endpoint Number.
+* Output : None
+* Return : Tx count value.
+*******************************************************************************/
+u16 GetEPTxCount(u8 bEpNum)
+{
+ return(_GetEPTxCount(bEpNum));
+}
+/*******************************************************************************
+* Function Name : GetEPRxCount
+* Description : Get the Rx count.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Rx count value.
+*******************************************************************************/
+u16 GetEPRxCount(u8 bEpNum)
+{
+ return(_GetEPRxCount(bEpNum));
+}
+/*******************************************************************************
+* Function Name : SetEPDblBuffAddr
+* Description : Set the addresses of the buffer 0 and 1.
+* Input : bEpNum: Endpoint Number.
+* wBuf0Addr: new address of buffer 0.
+* wBuf1Addr: new address of buffer 1.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPDblBuffAddr(u8 bEpNum, u16 wBuf0Addr, u16 wBuf1Addr)
+{
+ _SetEPDblBuffAddr(bEpNum, wBuf0Addr, wBuf1Addr);
+}
+/*******************************************************************************
+* Function Name : SetEPDblBuf0Addr
+* Description : Set the Buffer 1 address.
+* Input : bEpNum: Endpoint Number
+* wBuf0Addr: new address.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPDblBuf0Addr(u8 bEpNum, u16 wBuf0Addr)
+{
+ _SetEPDblBuf0Addr(bEpNum, wBuf0Addr);
+}
+/*******************************************************************************
+* Function Name : SetEPDblBuf1Addr
+* Description : Set the Buffer 1 address.
+* Input : bEpNum: Endpoint Number
+* wBuf1Addr: new address.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPDblBuf1Addr(u8 bEpNum, u16 wBuf1Addr)
+{
+ _SetEPDblBuf1Addr(bEpNum, wBuf1Addr);
+}
+/*******************************************************************************
+* Function Name : GetEPDblBuf0Addr
+* Description : Returns the address of the Buffer 0.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+u16 GetEPDblBuf0Addr(u8 bEpNum)
+{
+ return(_GetEPDblBuf0Addr(bEpNum));
+}
+/*******************************************************************************
+* Function Name : GetEPDblBuf1Addr
+* Description : Returns the address of the Buffer 1.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Address of the Buffer 1.
+*******************************************************************************/
+u16 GetEPDblBuf1Addr(u8 bEpNum)
+{
+ return(_GetEPDblBuf1Addr(bEpNum));
+}
+/*******************************************************************************
+* Function Name : SetEPDblBuffCount
+* Description : Set the number of bytes for a double Buffer
+* endpoint.
+* Input : bEpNum,bDir, wCount
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPDblBuffCount(u8 bEpNum, u8 bDir, u16 wCount)
+{
+ _SetEPDblBuffCount(bEpNum, bDir, wCount);
+}
+/*******************************************************************************
+* Function Name : SetEPDblBuf0Count
+* Description : Set the number of bytes in the buffer 0 of a double Buffer
+* endpoint.
+* Input : bEpNum, bDir, wCount
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPDblBuf0Count(u8 bEpNum, u8 bDir, u16 wCount)
+{
+ _SetEPDblBuf0Count(bEpNum, bDir, wCount);
+}
+/*******************************************************************************
+* Function Name : SetEPDblBuf1Count
+* Description : Set the number of bytes in the buffer 0 of a double Buffer
+* endpoint.
+* Input : bEpNum, bDir, wCount
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void SetEPDblBuf1Count(u8 bEpNum, u8 bDir, u16 wCount)
+{
+ _SetEPDblBuf1Count(bEpNum, bDir, wCount);
+}
+/*******************************************************************************
+* Function Name : GetEPDblBuf0Count
+* Description : Returns the number of byte received in the buffer 0 of a double
+* Buffer endpoint.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Endpoint Buffer 0 count
+*******************************************************************************/
+u16 GetEPDblBuf0Count(u8 bEpNum)
+{
+ return(_GetEPDblBuf0Count(bEpNum));
+}
+/*******************************************************************************
+* Function Name : GetEPDblBuf1Count
+* Description : Returns the number of data received in the buffer 1 of a double
+* Buffer endpoint.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Endpoint Buffer 1 count.
+*******************************************************************************/
+u16 GetEPDblBuf1Count(u8 bEpNum)
+{
+ return(_GetEPDblBuf1Count(bEpNum));
+}
+/*******************************************************************************
+* Function Name : GetEPDblBufDir
+* Description : gets direction of the double buffered endpoint
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : EP_DBUF_OUT, EP_DBUF_IN,
+* EP_DBUF_ERR if the endpoint counter not yet programmed.
+*******************************************************************************/
+EP_DBUF_DIR GetEPDblBufDir(u8 bEpNum)
+{
+ if ((u16)(*_pEPRxCount(bEpNum) & 0xFC00) != 0)
+ return(EP_DBUF_OUT);
+ else if (((u16)(*_pEPTxCount(bEpNum)) & 0x03FF) != 0)
+ return(EP_DBUF_IN);
+ else
+ return(EP_DBUF_ERR);
+}
+/*******************************************************************************
+* Function Name : FreeUserBuffer
+* Description : free buffer used from the application realizing it to the line
+ toggles bit SW_BUF in the double buffered endpoint register
+* Input : bEpNum, bDir
+* Output : None.
+* Return : None.
+*******************************************************************************/
+void FreeUserBuffer(u8 bEpNum, u8 bDir)
+{
+ if (bDir == EP_DBUF_OUT)
+ { /* OUT double buffered endpoint */
+ _ToggleDTOG_TX(bEpNum);
+ }
+ else if (bDir == EP_DBUF_IN)
+ { /* IN double buffered endpoint */
+ _ToggleDTOG_RX(bEpNum);
+ }
+}
+
+/*******************************************************************************
+* Function Name : ToWord
+* Description : merge two byte in a word.
+* Input : bh: byte high, bl: bytes low.
+* Output : None.
+* Return : resulted word.
+*******************************************************************************/
+u16 ToWord(u8 bh, u8 bl)
+{
+ u16 wRet;
+ wRet = (u16)bl | ((u16)bh << 8);
+ return(wRet);
+}
+/*******************************************************************************
+* Function Name : ByteSwap
+* Description : Swap two byte in a word.
+* Input : wSwW: word to Swap.
+* Output : None.
+* Return : resulted word.
+*******************************************************************************/
+u16 ByteSwap(u16 wSwW)
+{
+ u8 bTemp;
+ u16 wRet;
+ bTemp = (u8)(wSwW & 0xff);
+ wRet = (wSwW >> 8) | ((u16)bTemp << 8);
+ return(wRet);
+}
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/libmaple/usb/usb_lib/usb_regs.h b/libmaple/usb/usb_lib/usb_regs.h
index 9a4df75..a888f72 100644
--- a/libmaple/usb/usb_lib/usb_regs.h
+++ b/libmaple/usb/usb_lib/usb_regs.h
@@ -1,627 +1,627 @@
-/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
-* File Name : usb_regs.h
-* Author : MCD Application Team
-* Version : V2.2.1
-* Date : 09/22/2008
-* Description : Interface prototype functions to USB cell registers
-********************************************************************************
-* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
-* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
-* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
-* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
-* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
-* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
-*******************************************************************************/
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __USB_REGS_H
-#define __USB_REGS_H
-
-/* Includes ------------------------------------------------------------------*/
-/* Exported types ------------------------------------------------------------*/
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-typedef enum _EP_DBUF_DIR
-{
- /* double buffered endpoint direction */
- EP_DBUF_ERR,
- EP_DBUF_OUT,
- EP_DBUF_IN
-}EP_DBUF_DIR;
-
-/* endpoint buffer number */
-enum EP_BUF_NUM
-{
- EP_NOBUF,
- EP_BUF0,
- EP_BUF1
-};
-
-/* Exported constants --------------------------------------------------------*/
-#define RegBase (0x40005C00L) /* USB_IP Peripheral Registers base address */
-#define PMAAddr (0x40006000L) /* USB_IP Packet Memory Area base address */
-
-/******************************************************************************/
-/* General registers */
-/******************************************************************************/
-
-/* Control register */
-#define CNTR ((volatile unsigned *)(RegBase + 0x40))
-/* Interrupt status register */
-#define ISTR ((volatile unsigned *)(RegBase + 0x44))
-/* Frame number register */
-#define FNR ((volatile unsigned *)(RegBase + 0x48))
-/* Device address register */
-#define DADDR ((volatile unsigned *)(RegBase + 0x4C))
-/* Buffer Table address register */
-#define BTABLE ((volatile unsigned *)(RegBase + 0x50))
-/******************************************************************************/
-/* Endpoint registers */
-/******************************************************************************/
-#define EP0REG ((volatile unsigned *)(RegBase)) /* endpoint 0 register address */
-
-/* endpoints enumeration */
-#define ENDP0 ((u8)0)
-#define ENDP1 ((u8)1)
-#define ENDP2 ((u8)2)
-#define ENDP3 ((u8)3)
-#define ENDP4 ((u8)4)
-#define ENDP5 ((u8)5)
-#define ENDP6 ((u8)6)
-#define ENDP7 ((u8)7)
-/******************************************************************************/
-/* ISTR interrupt events */
-/******************************************************************************/
-#define ISTR_CTR (0x8000) /* Correct TRansfer (clear-only bit) */
-#define ISTR_DOVR (0x4000) /* DMA OVeR/underrun (clear-only bit) */
-#define ISTR_ERR (0x2000) /* ERRor (clear-only bit) */
-#define ISTR_WKUP (0x1000) /* WaKe UP (clear-only bit) */
-#define ISTR_SUSP (0x0800) /* SUSPend (clear-only bit) */
-#define ISTR_RESET (0x0400) /* RESET (clear-only bit) */
-#define ISTR_SOF (0x0200) /* Start Of Frame (clear-only bit) */
-#define ISTR_ESOF (0x0100) /* Expected Start Of Frame (clear-only bit) */
-
-
-#define ISTR_DIR (0x0010) /* DIRection of transaction (read-only bit) */
-#define ISTR_EP_ID (0x000F) /* EndPoint IDentifier (read-only bit) */
-
-#define CLR_CTR (~ISTR_CTR) /* clear Correct TRansfer bit */
-#define CLR_DOVR (~ISTR_DOVR) /* clear DMA OVeR/underrun bit*/
-#define CLR_ERR (~ISTR_ERR) /* clear ERRor bit */
-#define CLR_WKUP (~ISTR_WKUP) /* clear WaKe UP bit */
-#define CLR_SUSP (~ISTR_SUSP) /* clear SUSPend bit */
-#define CLR_RESET (~ISTR_RESET) /* clear RESET bit */
-#define CLR_SOF (~ISTR_SOF) /* clear Start Of Frame bit */
-#define CLR_ESOF (~ISTR_ESOF) /* clear Expected Start Of Frame bit */
-
-/******************************************************************************/
-/* CNTR control register bits definitions */
-/******************************************************************************/
-#define CNTR_CTRM (0x8000) /* Correct TRansfer Mask */
-#define CNTR_DOVRM (0x4000) /* DMA OVeR/underrun Mask */
-#define CNTR_ERRM (0x2000) /* ERRor Mask */
-#define CNTR_WKUPM (0x1000) /* WaKe UP Mask */
-#define CNTR_SUSPM (0x0800) /* SUSPend Mask */
-#define CNTR_RESETM (0x0400) /* RESET Mask */
-#define CNTR_SOFM (0x0200) /* Start Of Frame Mask */
-#define CNTR_ESOFM (0x0100) /* Expected Start Of Frame Mask */
-
-
-#define CNTR_RESUME (0x0010) /* RESUME request */
-#define CNTR_FSUSP (0x0008) /* Force SUSPend */
-#define CNTR_LPMODE (0x0004) /* Low-power MODE */
-#define CNTR_PDWN (0x0002) /* Power DoWN */
-#define CNTR_FRES (0x0001) /* Force USB RESet */
-
-/******************************************************************************/
-/* FNR Frame Number Register bit definitions */
-/******************************************************************************/
-#define FNR_RXDP (0x8000) /* status of D+ data line */
-#define FNR_RXDM (0x4000) /* status of D- data line */
-#define FNR_LCK (0x2000) /* LoCKed */
-#define FNR_LSOF (0x1800) /* Lost SOF */
-#define FNR_FN (0x07FF) /* Frame Number */
-/******************************************************************************/
-/* DADDR Device ADDRess bit definitions */
-/******************************************************************************/
-#define DADDR_EF (0x80)
-#define DADDR_ADD (0x7F)
-/******************************************************************************/
-/* Endpoint register */
-/******************************************************************************/
-/* bit positions */
-#define EP_CTR_RX (0x8000) /* EndPoint Correct TRansfer RX */
-#define EP_DTOG_RX (0x4000) /* EndPoint Data TOGGLE RX */
-#define EPRX_STAT (0x3000) /* EndPoint RX STATus bit field */
-#define EP_SETUP (0x0800) /* EndPoint SETUP */
-#define EP_T_FIELD (0x0600) /* EndPoint TYPE */
-#define EP_KIND (0x0100) /* EndPoint KIND */
-#define EP_CTR_TX (0x0080) /* EndPoint Correct TRansfer TX */
-#define EP_DTOG_TX (0x0040) /* EndPoint Data TOGGLE TX */
-#define EPTX_STAT (0x0030) /* EndPoint TX STATus bit field */
-#define EPADDR_FIELD (0x000F) /* EndPoint ADDRess FIELD */
-
-/* EndPoint REGister MASK (no toggle fields) */
-#define EPREG_MASK (EP_CTR_RX|EP_SETUP|EP_T_FIELD|EP_KIND|EP_CTR_TX|EPADDR_FIELD)
-
-/* EP_TYPE[1:0] EndPoint TYPE */
-#define EP_TYPE_MASK (0x0600) /* EndPoint TYPE Mask */
-#define EP_BULK (0x0000) /* EndPoint BULK */
-#define EP_CONTROL (0x0200) /* EndPoint CONTROL */
-#define EP_ISOCHRONOUS (0x0400) /* EndPoint ISOCHRONOUS */
-#define EP_INTERRUPT (0x0600) /* EndPoint INTERRUPT */
-#define EP_T_MASK (~EP_T_FIELD & EPREG_MASK)
-
-
-/* EP_KIND EndPoint KIND */
-#define EPKIND_MASK (~EP_KIND & EPREG_MASK)
-
-/* STAT_TX[1:0] STATus for TX transfer */
-#define EP_TX_DIS (0x0000) /* EndPoint TX DISabled */
-#define EP_TX_STALL (0x0010) /* EndPoint TX STALLed */
-#define EP_TX_NAK (0x0020) /* EndPoint TX NAKed */
-#define EP_TX_VALID (0x0030) /* EndPoint TX VALID */
-#define EPTX_DTOG1 (0x0010) /* EndPoint TX Data TOGgle bit1 */
-#define EPTX_DTOG2 (0x0020) /* EndPoint TX Data TOGgle bit2 */
-#define EPTX_DTOGMASK (EPTX_STAT|EPREG_MASK)
-
-/* STAT_RX[1:0] STATus for RX transfer */
-#define EP_RX_DIS (0x0000) /* EndPoint RX DISabled */
-#define EP_RX_STALL (0x1000) /* EndPoint RX STALLed */
-#define EP_RX_NAK (0x2000) /* EndPoint RX NAKed */
-#define EP_RX_VALID (0x3000) /* EndPoint RX VALID */
-#define EPRX_DTOG1 (0x1000) /* EndPoint RX Data TOGgle bit1 */
-#define EPRX_DTOG2 (0x2000) /* EndPoint RX Data TOGgle bit1 */
-#define EPRX_DTOGMASK (EPRX_STAT|EPREG_MASK)
-/* Exported macro ------------------------------------------------------------*/
-/* SetCNTR */
-#define _SetCNTR(wRegValue) (*CNTR = (u16)wRegValue)
-
-/* SetISTR */
-#define _SetISTR(wRegValue) (*ISTR = (u16)wRegValue)
-
-/* SetDADDR */
-#define _SetDADDR(wRegValue) (*DADDR = (u16)wRegValue)
-
-/* SetBTABLE */
-#define _SetBTABLE(wRegValue)(*BTABLE = (u16)(wRegValue & 0xFFF8))
-
-/* GetCNTR */
-#define _GetCNTR() ((u16) *CNTR)
-
-/* GetISTR */
-#define _GetISTR() ((u16) *ISTR)
-
-/* GetFNR */
-#define _GetFNR() ((u16) *FNR)
-
-/* GetDADDR */
-#define _GetDADDR() ((u16) *DADDR)
-
-/* GetBTABLE */
-#define _GetBTABLE() ((u16) *BTABLE)
-
-/* SetENDPOINT */
-#define _SetENDPOINT(bEpNum,wRegValue) (*(EP0REG + bEpNum)= \
- (u16)wRegValue)
-
-/* GetENDPOINT */
-#define _GetENDPOINT(bEpNum) ((u16)(*(EP0REG + bEpNum)))
-
-/*******************************************************************************
-* Macro Name : SetEPType
-* Description : sets the type in the endpoint register(bits EP_TYPE[1:0])
-* Input : bEpNum: Endpoint Number.
-* wType
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPType(bEpNum,wType) (_SetENDPOINT(bEpNum,\
- ((_GetENDPOINT(bEpNum) & EP_T_MASK) | wType)))
-
-/*******************************************************************************
-* Macro Name : GetEPType
-* Description : gets the type in the endpoint register(bits EP_TYPE[1:0])
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : Endpoint Type
-*******************************************************************************/
-#define _GetEPType(bEpNum) (_GetENDPOINT(bEpNum) & EP_T_FIELD)
-
-/*******************************************************************************
-* Macro Name : SetEPTxStatus
-* Description : sets the status for tx transfer (bits STAT_TX[1:0]).
-* Input : bEpNum: Endpoint Number.
-* wState: new state
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPTxStatus(bEpNum,wState) {\
- register u16 _wRegVal; \
- _wRegVal = _GetENDPOINT(bEpNum) & EPTX_DTOGMASK;\
- /* toggle first bit ? */ \
- if((EPTX_DTOG1 & wState)!= 0) \
- _wRegVal ^= EPTX_DTOG1; \
- /* toggle second bit ? */ \
- if((EPTX_DTOG2 & wState)!= 0) \
- _wRegVal ^= EPTX_DTOG2; \
- _SetENDPOINT(bEpNum, _wRegVal); \
- } /* _SetEPTxStatus */
-
-/*******************************************************************************
-* Macro Name : SetEPRxStatus
-* Description : sets the status for rx transfer (bits STAT_TX[1:0])
-* Input : bEpNum: Endpoint Number.
-* wState: new state.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPRxStatus(bEpNum,wState) {\
- register u16 _wRegVal; \
- \
- _wRegVal = _GetENDPOINT(bEpNum) & EPRX_DTOGMASK;\
- /* toggle first bit ? */ \
- if((EPRX_DTOG1 & wState)!= 0) \
- _wRegVal ^= EPRX_DTOG1; \
- /* toggle second bit ? */ \
- if((EPRX_DTOG2 & wState)!= 0) \
- _wRegVal ^= EPRX_DTOG2; \
- _SetENDPOINT(bEpNum, _wRegVal); \
- } /* _SetEPRxStatus */
-/*******************************************************************************
-* Macro Name : GetEPTxStatus / GetEPRxStatus
-* Description : gets the status for tx/rx transfer (bits STAT_TX[1:0]
-* /STAT_RX[1:0])
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : status .
-*******************************************************************************/
-#define _GetEPTxStatus(bEpNum) ((u16)_GetENDPOINT(bEpNum) & EPTX_STAT)
-
-#define _GetEPRxStatus(bEpNum) ((u16)_GetENDPOINT(bEpNum) & EPRX_STAT)
-
-/*******************************************************************************
-* Macro Name : SetEPTxValid / SetEPRxValid
-* Description : sets directly the VALID tx/rx-status into the enpoint register
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPTxValid(bEpNum) (_SetEPTxStatus(bEpNum, EP_TX_VALID))
-
-#define _SetEPRxValid(bEpNum) (_SetEPRxStatus(bEpNum, EP_RX_VALID))
-
-/*******************************************************************************
-* Macro Name : GetTxStallStatus / GetRxStallStatus.
-* Description : checks stall condition in an endpoint.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : TRUE = endpoint in stall condition.
-*******************************************************************************/
-#define _GetTxStallStatus(bEpNum) (_GetEPTxStatus(bEpNum) \
- == EP_TX_STALL)
-#define _GetRxStallStatus(bEpNum) (_GetEPRxStatus(bEpNum) \
- == EP_RX_STALL)
-
-/*******************************************************************************
-* Macro Name : SetEP_KIND / ClearEP_KIND.
-* Description : set & clear EP_KIND bit.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEP_KIND(bEpNum) (_SetENDPOINT(bEpNum, \
- (_GetENDPOINT(bEpNum) | EP_KIND) & EPREG_MASK))
-#define _ClearEP_KIND(bEpNum) (_SetENDPOINT(bEpNum, \
- (_GetENDPOINT(bEpNum) & EPKIND_MASK)))
-
-/*******************************************************************************
-* Macro Name : Set_Status_Out / Clear_Status_Out.
-* Description : Sets/clears directly STATUS_OUT bit in the endpoint register.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _Set_Status_Out(bEpNum) _SetEP_KIND(bEpNum)
-#define _Clear_Status_Out(bEpNum) _ClearEP_KIND(bEpNum)
-
-/*******************************************************************************
-* Macro Name : SetEPDoubleBuff / ClearEPDoubleBuff.
-* Description : Sets/clears directly EP_KIND bit in the endpoint register.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPDoubleBuff(bEpNum) _SetEP_KIND(bEpNum)
-#define _ClearEPDoubleBuff(bEpNum) _ClearEP_KIND(bEpNum)
-
-/*******************************************************************************
-* Macro Name : ClearEP_CTR_RX / ClearEP_CTR_TX.
-* Description : Clears bit CTR_RX / CTR_TX in the endpoint register.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _ClearEP_CTR_RX(bEpNum) (_SetENDPOINT(bEpNum,\
- _GetENDPOINT(bEpNum) & 0x7FFF & EPREG_MASK))
-#define _ClearEP_CTR_TX(bEpNum) (_SetENDPOINT(bEpNum,\
- _GetENDPOINT(bEpNum) & 0xFF7F & EPREG_MASK))
-
-/*******************************************************************************
-* Macro Name : ToggleDTOG_RX / ToggleDTOG_TX .
-* Description : Toggles DTOG_RX / DTOG_TX bit in the endpoint register.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _ToggleDTOG_RX(bEpNum) (_SetENDPOINT(bEpNum, \
- EP_DTOG_RX | _GetENDPOINT(bEpNum) & EPREG_MASK))
-#define _ToggleDTOG_TX(bEpNum) (_SetENDPOINT(bEpNum, \
- EP_DTOG_TX | _GetENDPOINT(bEpNum) & EPREG_MASK))
-
-/*******************************************************************************
-* Macro Name : ClearDTOG_RX / ClearDTOG_TX.
-* Description : Clears DTOG_RX / DTOG_TX bit in the endpoint register.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _ClearDTOG_RX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_RX) != 0)\
- _ToggleDTOG_RX(bEpNum)
-#define _ClearDTOG_TX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_TX) != 0)\
- _ToggleDTOG_TX(bEpNum)
-/*******************************************************************************
-* Macro Name : SetEPAddress.
-* Description : Sets address in an endpoint register.
-* Input : bEpNum: Endpoint Number.
-* bAddr: Address.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPAddress(bEpNum,bAddr) _SetENDPOINT(bEpNum,\
- _GetENDPOINT(bEpNum) & EPREG_MASK | bAddr)
-
-/*******************************************************************************
-* Macro Name : GetEPAddress.
-* Description : Gets address in an endpoint register.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _GetEPAddress(bEpNum) ((u8)(_GetENDPOINT(bEpNum) & EPADDR_FIELD))
-
-#define _pEPTxAddr(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8 )*2 + PMAAddr))
-#define _pEPTxCount(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8+2)*2 + PMAAddr))
-#define _pEPRxAddr(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8+4)*2 + PMAAddr))
-#define _pEPRxCount(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8+6)*2 + PMAAddr))
-
-/*******************************************************************************
-* Macro Name : SetEPTxAddr / SetEPRxAddr.
-* Description : sets address of the tx/rx buffer.
-* Input : bEpNum: Endpoint Number.
-* wAddr: address to be set (must be word aligned).
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPTxAddr(bEpNum,wAddr) (*_pEPTxAddr(bEpNum) = ((wAddr >> 1) << 1))
-#define _SetEPRxAddr(bEpNum,wAddr) (*_pEPRxAddr(bEpNum) = ((wAddr >> 1) << 1))
-
-/*******************************************************************************
-* Macro Name : GetEPTxAddr / GetEPRxAddr.
-* Description : Gets address of the tx/rx buffer.
-* Input : bEpNum: Endpoint Number.
-* Output : None.
-* Return : address of the buffer.
-*******************************************************************************/
-#define _GetEPTxAddr(bEpNum) ((u16)*_pEPTxAddr(bEpNum))
-#define _GetEPRxAddr(bEpNum) ((u16)*_pEPRxAddr(bEpNum))
-
-/*******************************************************************************
-* Macro Name : SetEPCountRxReg.
-* Description : Sets counter of rx buffer with no. of blocks.
-* Input : pdwReg: pointer to counter.
-* wCount: Counter.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _BlocksOf32(dwReg,wCount,wNBlocks) {\
- wNBlocks = wCount >> 5;\
- if((wCount & 0x1f) == 0)\
- wNBlocks--;\
- *pdwReg = (u32)((wNBlocks << 10) | 0x8000);\
- }/* _BlocksOf32 */
-
-#define _BlocksOf2(dwReg,wCount,wNBlocks) {\
- wNBlocks = wCount >> 1;\
- if((wCount & 0x1) != 0)\
- wNBlocks++;\
- *pdwReg = (u32)(wNBlocks << 10);\
- }/* _BlocksOf2 */
-
-#define _SetEPCountRxReg(dwReg,wCount) {\
- u16 wNBlocks;\
- if(wCount > 62){_BlocksOf32(dwReg,wCount,wNBlocks);}\
- else {_BlocksOf2(dwReg,wCount,wNBlocks);}\
- }/* _SetEPCountRxReg */
-
-
-
-#define _SetEPRxDblBuf0Count(bEpNum,wCount) {\
- u32 *pdwReg = _pEPTxCount(bEpNum); \
- _SetEPCountRxReg(pdwReg, wCount);\
- }
-/*******************************************************************************
-* Macro Name : SetEPTxCount / SetEPRxCount.
-* Description : sets counter for the tx/rx buffer.
-* Input : bEpNum: endpoint number.
-* wCount: Counter value.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPTxCount(bEpNum,wCount) (*_pEPTxCount(bEpNum) = wCount)
-#define _SetEPRxCount(bEpNum,wCount) {\
- u32 *pdwReg = _pEPRxCount(bEpNum); \
- _SetEPCountRxReg(pdwReg, wCount);\
- }
-/*******************************************************************************
-* Macro Name : GetEPTxCount / GetEPRxCount.
-* Description : gets counter of the tx buffer.
-* Input : bEpNum: endpoint number.
-* Output : None.
-* Return : Counter value.
-*******************************************************************************/
-#define _GetEPTxCount(bEpNum)((u16)(*_pEPTxCount(bEpNum)) & 0x3ff)
-#define _GetEPRxCount(bEpNum)((u16)(*_pEPRxCount(bEpNum)) & 0x3ff)
-
-/*******************************************************************************
-* Macro Name : SetEPDblBuf0Addr / SetEPDblBuf1Addr.
-* Description : Sets buffer 0/1 address in a double buffer endpoint.
-* Input : bEpNum: endpoint number.
-* : wBuf0Addr: buffer 0 address.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPDblBuf0Addr(bEpNum,wBuf0Addr) {_SetEPTxAddr(bEpNum, wBuf0Addr);}
-#define _SetEPDblBuf1Addr(bEpNum,wBuf1Addr) {_SetEPRxAddr(bEpNum, wBuf1Addr);}
-
-/*******************************************************************************
-* Macro Name : SetEPDblBuffAddr.
-* Description : Sets addresses in a double buffer endpoint.
-* Input : bEpNum: endpoint number.
-* : wBuf0Addr: buffer 0 address.
-* : wBuf1Addr = buffer 1 address.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPDblBuffAddr(bEpNum,wBuf0Addr,wBuf1Addr) { \
- _SetEPDblBuf0Addr(bEpNum, wBuf0Addr);\
- _SetEPDblBuf1Addr(bEpNum, wBuf1Addr);\
- } /* _SetEPDblBuffAddr */
-
-/*******************************************************************************
-* Macro Name : GetEPDblBuf0Addr / GetEPDblBuf1Addr.
-* Description : Gets buffer 0/1 address of a double buffer endpoint.
-* Input : bEpNum: endpoint number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _GetEPDblBuf0Addr(bEpNum) (_GetEPTxAddr(bEpNum))
-#define _GetEPDblBuf1Addr(bEpNum) (_GetEPRxAddr(bEpNum))
-
-/*******************************************************************************
-* Macro Name : SetEPDblBuffCount / SetEPDblBuf0Count / SetEPDblBuf1Count.
-* Description : Gets buffer 0/1 address of a double buffer endpoint.
-* Input : bEpNum: endpoint number.
-* : bDir: endpoint dir EP_DBUF_OUT = OUT
-* EP_DBUF_IN = IN
-* : wCount: Counter value
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _SetEPDblBuf0Count(bEpNum, bDir, wCount) { \
- if(bDir == EP_DBUF_OUT)\
- /* OUT endpoint */ \
- {_SetEPRxDblBuf0Count(bEpNum,wCount);} \
- else if(bDir == EP_DBUF_IN)\
- /* IN endpoint */ \
- *_pEPTxCount(bEpNum) = (u32)wCount; \
- } /* SetEPDblBuf0Count*/
-
-#define _SetEPDblBuf1Count(bEpNum, bDir, wCount) { \
- if(bDir == EP_DBUF_OUT)\
- /* OUT endpoint */ \
- {_SetEPRxCount(bEpNum,wCount);}\
- else if(bDir == EP_DBUF_IN)\
- /* IN endpoint */\
- *_pEPRxCount(bEpNum) = (u32)wCount; \
- } /* SetEPDblBuf1Count */
-
-#define _SetEPDblBuffCount(bEpNum, bDir, wCount) {\
- _SetEPDblBuf0Count(bEpNum, bDir, wCount); \
- _SetEPDblBuf1Count(bEpNum, bDir, wCount); \
- } /* _SetEPDblBuffCount */
-
-/*******************************************************************************
-* Macro Name : GetEPDblBuf0Count / GetEPDblBuf1Count.
-* Description : Gets buffer 0/1 rx/tx counter for double buffering.
-* Input : bEpNum: endpoint number.
-* Output : None.
-* Return : None.
-*******************************************************************************/
-#define _GetEPDblBuf0Count(bEpNum) (_GetEPTxCount(bEpNum))
-#define _GetEPDblBuf1Count(bEpNum) (_GetEPRxCount(bEpNum))
-
-
-/* External variables --------------------------------------------------------*/
-extern volatile u16 wIstr; /* ISTR register last read value */
-
-/* Exported functions ------------------------------------------------------- */
-void SetCNTR(u16 /*wRegValue*/);
-void SetISTR(u16 /*wRegValue*/);
-void SetDADDR(u16 /*wRegValue*/);
-void SetBTABLE(u16 /*wRegValue*/);
-u16 GetCNTR(void);
-u16 GetISTR(void);
-u16 GetFNR(void);
-u16 GetDADDR(void);
-u16 GetBTABLE(void);
-void SetENDPOINT(u8 /*bEpNum*/, u16 /*wRegValue*/);
-u16 GetENDPOINT(u8 /*bEpNum*/);
-void SetEPType(u8 /*bEpNum*/, u16 /*wType*/);
-u16 GetEPType(u8 /*bEpNum*/);
-void SetEPTxStatus(u8 /*bEpNum*/, u16 /*wState*/);
-void SetEPRxStatus(u8 /*bEpNum*/, u16 /*wState*/);
-void SetDouBleBuffEPStall(u8 /*bEpNum*/, u8 bDir);
-u16 GetEPTxStatus(u8 /*bEpNum*/);
-u16 GetEPRxStatus(u8 /*bEpNum*/);
-void SetEPTxValid(u8 /*bEpNum*/);
-void SetEPRxValid(u8 /*bEpNum*/);
-u16 GetTxStallStatus(u8 /*bEpNum*/);
-u16 GetRxStallStatus(u8 /*bEpNum*/);
-void SetEP_KIND(u8 /*bEpNum*/);
-void ClearEP_KIND(u8 /*bEpNum*/);
-void Set_Status_Out(u8 /*bEpNum*/);
-void Clear_Status_Out(u8 /*bEpNum*/);
-void SetEPDoubleBuff(u8 /*bEpNum*/);
-void ClearEPDoubleBuff(u8 /*bEpNum*/);
-void ClearEP_CTR_RX(u8 /*bEpNum*/);
-void ClearEP_CTR_TX(u8 /*bEpNum*/);
-void ToggleDTOG_RX(u8 /*bEpNum*/);
-void ToggleDTOG_TX(u8 /*bEpNum*/);
-void ClearDTOG_RX(u8 /*bEpNum*/);
-void ClearDTOG_TX(u8 /*bEpNum*/);
-void SetEPAddress(u8 /*bEpNum*/, u8 /*bAddr*/);
-u8 GetEPAddress(u8 /*bEpNum*/);
-void SetEPTxAddr(u8 /*bEpNum*/, u16 /*wAddr*/);
-void SetEPRxAddr(u8 /*bEpNum*/, u16 /*wAddr*/);
-u16 GetEPTxAddr(u8 /*bEpNum*/);
-u16 GetEPRxAddr(u8 /*bEpNum*/);
-void SetEPCountRxReg(u32 * /*pdwReg*/, u16 /*wCount*/);
-void SetEPTxCount(u8 /*bEpNum*/, u16 /*wCount*/);
-void SetEPRxCount(u8 /*bEpNum*/, u16 /*wCount*/);
-u16 GetEPTxCount(u8 /*bEpNum*/);
-u16 GetEPRxCount(u8 /*bEpNum*/);
-void SetEPDblBuf0Addr(u8 /*bEpNum*/, u16 /*wBuf0Addr*/);
-void SetEPDblBuf1Addr(u8 /*bEpNum*/, u16 /*wBuf1Addr*/);
-void SetEPDblBuffAddr(u8 /*bEpNum*/, u16 /*wBuf0Addr*/, u16 /*wBuf1Addr*/);
-u16 GetEPDblBuf0Addr(u8 /*bEpNum*/);
-u16 GetEPDblBuf1Addr(u8 /*bEpNum*/);
-void SetEPDblBuffCount(u8 /*bEpNum*/, u8 /*bDir*/, u16 /*wCount*/);
-void SetEPDblBuf0Count(u8 /*bEpNum*/, u8 /*bDir*/, u16 /*wCount*/);
-void SetEPDblBuf1Count(u8 /*bEpNum*/, u8 /*bDir*/, u16 /*wCount*/);
-u16 GetEPDblBuf0Count(u8 /*bEpNum*/);
-u16 GetEPDblBuf1Count(u8 /*bEpNum*/);
-EP_DBUF_DIR GetEPDblBufDir(u8 /*bEpNum*/);
-void FreeUserBuffer(u8 bEpNum/*bEpNum*/, u8 bDir);
-u16 ToWord(u8, u8);
-u16 ByteSwap(u16);
-
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /* __USB_REGS_H */
-
-/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_regs.h
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Interface prototype functions to USB cell registers
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USB_REGS_H
+#define __USB_REGS_H
+
+/* Includes ------------------------------------------------------------------*/
+/* Exported types ------------------------------------------------------------*/
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+typedef enum _EP_DBUF_DIR
+{
+ /* double buffered endpoint direction */
+ EP_DBUF_ERR,
+ EP_DBUF_OUT,
+ EP_DBUF_IN
+}EP_DBUF_DIR;
+
+/* endpoint buffer number */
+enum EP_BUF_NUM
+{
+ EP_NOBUF,
+ EP_BUF0,
+ EP_BUF1
+};
+
+/* Exported constants --------------------------------------------------------*/
+#define RegBase (0x40005C00L) /* USB_IP Peripheral Registers base address */
+#define PMAAddr (0x40006000L) /* USB_IP Packet Memory Area base address */
+
+/******************************************************************************/
+/* General registers */
+/******************************************************************************/
+
+/* Control register */
+#define CNTR ((volatile unsigned *)(RegBase + 0x40))
+/* Interrupt status register */
+#define ISTR ((volatile unsigned *)(RegBase + 0x44))
+/* Frame number register */
+#define FNR ((volatile unsigned *)(RegBase + 0x48))
+/* Device address register */
+#define DADDR ((volatile unsigned *)(RegBase + 0x4C))
+/* Buffer Table address register */
+#define BTABLE ((volatile unsigned *)(RegBase + 0x50))
+/******************************************************************************/
+/* Endpoint registers */
+/******************************************************************************/
+#define EP0REG ((volatile unsigned *)(RegBase)) /* endpoint 0 register address */
+
+/* endpoints enumeration */
+#define ENDP0 ((u8)0)
+#define ENDP1 ((u8)1)
+#define ENDP2 ((u8)2)
+#define ENDP3 ((u8)3)
+#define ENDP4 ((u8)4)
+#define ENDP5 ((u8)5)
+#define ENDP6 ((u8)6)
+#define ENDP7 ((u8)7)
+/******************************************************************************/
+/* ISTR interrupt events */
+/******************************************************************************/
+#define ISTR_CTR (0x8000) /* Correct TRansfer (clear-only bit) */
+#define ISTR_DOVR (0x4000) /* DMA OVeR/underrun (clear-only bit) */
+#define ISTR_ERR (0x2000) /* ERRor (clear-only bit) */
+#define ISTR_WKUP (0x1000) /* WaKe UP (clear-only bit) */
+#define ISTR_SUSP (0x0800) /* SUSPend (clear-only bit) */
+#define ISTR_RESET (0x0400) /* RESET (clear-only bit) */
+#define ISTR_SOF (0x0200) /* Start Of Frame (clear-only bit) */
+#define ISTR_ESOF (0x0100) /* Expected Start Of Frame (clear-only bit) */
+
+
+#define ISTR_DIR (0x0010) /* DIRection of transaction (read-only bit) */
+#define ISTR_EP_ID (0x000F) /* EndPoint IDentifier (read-only bit) */
+
+#define CLR_CTR (~ISTR_CTR) /* clear Correct TRansfer bit */
+#define CLR_DOVR (~ISTR_DOVR) /* clear DMA OVeR/underrun bit*/
+#define CLR_ERR (~ISTR_ERR) /* clear ERRor bit */
+#define CLR_WKUP (~ISTR_WKUP) /* clear WaKe UP bit */
+#define CLR_SUSP (~ISTR_SUSP) /* clear SUSPend bit */
+#define CLR_RESET (~ISTR_RESET) /* clear RESET bit */
+#define CLR_SOF (~ISTR_SOF) /* clear Start Of Frame bit */
+#define CLR_ESOF (~ISTR_ESOF) /* clear Expected Start Of Frame bit */
+
+/******************************************************************************/
+/* CNTR control register bits definitions */
+/******************************************************************************/
+#define CNTR_CTRM (0x8000) /* Correct TRansfer Mask */
+#define CNTR_DOVRM (0x4000) /* DMA OVeR/underrun Mask */
+#define CNTR_ERRM (0x2000) /* ERRor Mask */
+#define CNTR_WKUPM (0x1000) /* WaKe UP Mask */
+#define CNTR_SUSPM (0x0800) /* SUSPend Mask */
+#define CNTR_RESETM (0x0400) /* RESET Mask */
+#define CNTR_SOFM (0x0200) /* Start Of Frame Mask */
+#define CNTR_ESOFM (0x0100) /* Expected Start Of Frame Mask */
+
+
+#define CNTR_RESUME (0x0010) /* RESUME request */
+#define CNTR_FSUSP (0x0008) /* Force SUSPend */
+#define CNTR_LPMODE (0x0004) /* Low-power MODE */
+#define CNTR_PDWN (0x0002) /* Power DoWN */
+#define CNTR_FRES (0x0001) /* Force USB RESet */
+
+/******************************************************************************/
+/* FNR Frame Number Register bit definitions */
+/******************************************************************************/
+#define FNR_RXDP (0x8000) /* status of D+ data line */
+#define FNR_RXDM (0x4000) /* status of D- data line */
+#define FNR_LCK (0x2000) /* LoCKed */
+#define FNR_LSOF (0x1800) /* Lost SOF */
+#define FNR_FN (0x07FF) /* Frame Number */
+/******************************************************************************/
+/* DADDR Device ADDRess bit definitions */
+/******************************************************************************/
+#define DADDR_EF (0x80)
+#define DADDR_ADD (0x7F)
+/******************************************************************************/
+/* Endpoint register */
+/******************************************************************************/
+/* bit positions */
+#define EP_CTR_RX (0x8000) /* EndPoint Correct TRansfer RX */
+#define EP_DTOG_RX (0x4000) /* EndPoint Data TOGGLE RX */
+#define EPRX_STAT (0x3000) /* EndPoint RX STATus bit field */
+#define EP_SETUP (0x0800) /* EndPoint SETUP */
+#define EP_T_FIELD (0x0600) /* EndPoint TYPE */
+#define EP_KIND (0x0100) /* EndPoint KIND */
+#define EP_CTR_TX (0x0080) /* EndPoint Correct TRansfer TX */
+#define EP_DTOG_TX (0x0040) /* EndPoint Data TOGGLE TX */
+#define EPTX_STAT (0x0030) /* EndPoint TX STATus bit field */
+#define EPADDR_FIELD (0x000F) /* EndPoint ADDRess FIELD */
+
+/* EndPoint REGister MASK (no toggle fields) */
+#define EPREG_MASK (EP_CTR_RX|EP_SETUP|EP_T_FIELD|EP_KIND|EP_CTR_TX|EPADDR_FIELD)
+
+/* EP_TYPE[1:0] EndPoint TYPE */
+#define EP_TYPE_MASK (0x0600) /* EndPoint TYPE Mask */
+#define EP_BULK (0x0000) /* EndPoint BULK */
+#define EP_CONTROL (0x0200) /* EndPoint CONTROL */
+#define EP_ISOCHRONOUS (0x0400) /* EndPoint ISOCHRONOUS */
+#define EP_INTERRUPT (0x0600) /* EndPoint INTERRUPT */
+#define EP_T_MASK (~EP_T_FIELD & EPREG_MASK)
+
+
+/* EP_KIND EndPoint KIND */
+#define EPKIND_MASK (~EP_KIND & EPREG_MASK)
+
+/* STAT_TX[1:0] STATus for TX transfer */
+#define EP_TX_DIS (0x0000) /* EndPoint TX DISabled */
+#define EP_TX_STALL (0x0010) /* EndPoint TX STALLed */
+#define EP_TX_NAK (0x0020) /* EndPoint TX NAKed */
+#define EP_TX_VALID (0x0030) /* EndPoint TX VALID */
+#define EPTX_DTOG1 (0x0010) /* EndPoint TX Data TOGgle bit1 */
+#define EPTX_DTOG2 (0x0020) /* EndPoint TX Data TOGgle bit2 */
+#define EPTX_DTOGMASK (EPTX_STAT|EPREG_MASK)
+
+/* STAT_RX[1:0] STATus for RX transfer */
+#define EP_RX_DIS (0x0000) /* EndPoint RX DISabled */
+#define EP_RX_STALL (0x1000) /* EndPoint RX STALLed */
+#define EP_RX_NAK (0x2000) /* EndPoint RX NAKed */
+#define EP_RX_VALID (0x3000) /* EndPoint RX VALID */
+#define EPRX_DTOG1 (0x1000) /* EndPoint RX Data TOGgle bit1 */
+#define EPRX_DTOG2 (0x2000) /* EndPoint RX Data TOGgle bit1 */
+#define EPRX_DTOGMASK (EPRX_STAT|EPREG_MASK)
+/* Exported macro ------------------------------------------------------------*/
+/* SetCNTR */
+#define _SetCNTR(wRegValue) (*CNTR = (u16)wRegValue)
+
+/* SetISTR */
+#define _SetISTR(wRegValue) (*ISTR = (u16)wRegValue)
+
+/* SetDADDR */
+#define _SetDADDR(wRegValue) (*DADDR = (u16)wRegValue)
+
+/* SetBTABLE */
+#define _SetBTABLE(wRegValue)(*BTABLE = (u16)(wRegValue & 0xFFF8))
+
+/* GetCNTR */
+#define _GetCNTR() ((u16) *CNTR)
+
+/* GetISTR */
+#define _GetISTR() ((u16) *ISTR)
+
+/* GetFNR */
+#define _GetFNR() ((u16) *FNR)
+
+/* GetDADDR */
+#define _GetDADDR() ((u16) *DADDR)
+
+/* GetBTABLE */
+#define _GetBTABLE() ((u16) *BTABLE)
+
+/* SetENDPOINT */
+#define _SetENDPOINT(bEpNum,wRegValue) (*(EP0REG + bEpNum)= \
+ (u16)wRegValue)
+
+/* GetENDPOINT */
+#define _GetENDPOINT(bEpNum) ((u16)(*(EP0REG + bEpNum)))
+
+/*******************************************************************************
+* Macro Name : SetEPType
+* Description : sets the type in the endpoint register(bits EP_TYPE[1:0])
+* Input : bEpNum: Endpoint Number.
+* wType
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPType(bEpNum,wType) (_SetENDPOINT(bEpNum,\
+ ((_GetENDPOINT(bEpNum) & EP_T_MASK) | wType)))
+
+/*******************************************************************************
+* Macro Name : GetEPType
+* Description : gets the type in the endpoint register(bits EP_TYPE[1:0])
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : Endpoint Type
+*******************************************************************************/
+#define _GetEPType(bEpNum) (_GetENDPOINT(bEpNum) & EP_T_FIELD)
+
+/*******************************************************************************
+* Macro Name : SetEPTxStatus
+* Description : sets the status for tx transfer (bits STAT_TX[1:0]).
+* Input : bEpNum: Endpoint Number.
+* wState: new state
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPTxStatus(bEpNum,wState) {\
+ register u16 _wRegVal; \
+ _wRegVal = _GetENDPOINT(bEpNum) & EPTX_DTOGMASK;\
+ /* toggle first bit ? */ \
+ if((EPTX_DTOG1 & wState)!= 0) \
+ _wRegVal ^= EPTX_DTOG1; \
+ /* toggle second bit ? */ \
+ if((EPTX_DTOG2 & wState)!= 0) \
+ _wRegVal ^= EPTX_DTOG2; \
+ _SetENDPOINT(bEpNum, _wRegVal); \
+ } /* _SetEPTxStatus */
+
+/*******************************************************************************
+* Macro Name : SetEPRxStatus
+* Description : sets the status for rx transfer (bits STAT_TX[1:0])
+* Input : bEpNum: Endpoint Number.
+* wState: new state.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPRxStatus(bEpNum,wState) {\
+ register u16 _wRegVal; \
+ \
+ _wRegVal = _GetENDPOINT(bEpNum) & EPRX_DTOGMASK;\
+ /* toggle first bit ? */ \
+ if((EPRX_DTOG1 & wState)!= 0) \
+ _wRegVal ^= EPRX_DTOG1; \
+ /* toggle second bit ? */ \
+ if((EPRX_DTOG2 & wState)!= 0) \
+ _wRegVal ^= EPRX_DTOG2; \
+ _SetENDPOINT(bEpNum, _wRegVal); \
+ } /* _SetEPRxStatus */
+/*******************************************************************************
+* Macro Name : GetEPTxStatus / GetEPRxStatus
+* Description : gets the status for tx/rx transfer (bits STAT_TX[1:0]
+* /STAT_RX[1:0])
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : status .
+*******************************************************************************/
+#define _GetEPTxStatus(bEpNum) ((u16)_GetENDPOINT(bEpNum) & EPTX_STAT)
+
+#define _GetEPRxStatus(bEpNum) ((u16)_GetENDPOINT(bEpNum) & EPRX_STAT)
+
+/*******************************************************************************
+* Macro Name : SetEPTxValid / SetEPRxValid
+* Description : sets directly the VALID tx/rx-status into the enpoint register
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPTxValid(bEpNum) (_SetEPTxStatus(bEpNum, EP_TX_VALID))
+
+#define _SetEPRxValid(bEpNum) (_SetEPRxStatus(bEpNum, EP_RX_VALID))
+
+/*******************************************************************************
+* Macro Name : GetTxStallStatus / GetRxStallStatus.
+* Description : checks stall condition in an endpoint.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : TRUE = endpoint in stall condition.
+*******************************************************************************/
+#define _GetTxStallStatus(bEpNum) (_GetEPTxStatus(bEpNum) \
+ == EP_TX_STALL)
+#define _GetRxStallStatus(bEpNum) (_GetEPRxStatus(bEpNum) \
+ == EP_RX_STALL)
+
+/*******************************************************************************
+* Macro Name : SetEP_KIND / ClearEP_KIND.
+* Description : set & clear EP_KIND bit.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEP_KIND(bEpNum) (_SetENDPOINT(bEpNum, \
+ (_GetENDPOINT(bEpNum) | EP_KIND) & EPREG_MASK))
+#define _ClearEP_KIND(bEpNum) (_SetENDPOINT(bEpNum, \
+ (_GetENDPOINT(bEpNum) & EPKIND_MASK)))
+
+/*******************************************************************************
+* Macro Name : Set_Status_Out / Clear_Status_Out.
+* Description : Sets/clears directly STATUS_OUT bit in the endpoint register.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _Set_Status_Out(bEpNum) _SetEP_KIND(bEpNum)
+#define _Clear_Status_Out(bEpNum) _ClearEP_KIND(bEpNum)
+
+/*******************************************************************************
+* Macro Name : SetEPDoubleBuff / ClearEPDoubleBuff.
+* Description : Sets/clears directly EP_KIND bit in the endpoint register.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPDoubleBuff(bEpNum) _SetEP_KIND(bEpNum)
+#define _ClearEPDoubleBuff(bEpNum) _ClearEP_KIND(bEpNum)
+
+/*******************************************************************************
+* Macro Name : ClearEP_CTR_RX / ClearEP_CTR_TX.
+* Description : Clears bit CTR_RX / CTR_TX in the endpoint register.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _ClearEP_CTR_RX(bEpNum) (_SetENDPOINT(bEpNum,\
+ _GetENDPOINT(bEpNum) & 0x7FFF & EPREG_MASK))
+#define _ClearEP_CTR_TX(bEpNum) (_SetENDPOINT(bEpNum,\
+ _GetENDPOINT(bEpNum) & 0xFF7F & EPREG_MASK))
+
+/*******************************************************************************
+* Macro Name : ToggleDTOG_RX / ToggleDTOG_TX .
+* Description : Toggles DTOG_RX / DTOG_TX bit in the endpoint register.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _ToggleDTOG_RX(bEpNum) (_SetENDPOINT(bEpNum, \
+ EP_DTOG_RX | _GetENDPOINT(bEpNum) & EPREG_MASK))
+#define _ToggleDTOG_TX(bEpNum) (_SetENDPOINT(bEpNum, \
+ EP_DTOG_TX | _GetENDPOINT(bEpNum) & EPREG_MASK))
+
+/*******************************************************************************
+* Macro Name : ClearDTOG_RX / ClearDTOG_TX.
+* Description : Clears DTOG_RX / DTOG_TX bit in the endpoint register.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _ClearDTOG_RX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_RX) != 0)\
+ _ToggleDTOG_RX(bEpNum)
+#define _ClearDTOG_TX(bEpNum) if((_GetENDPOINT(bEpNum) & EP_DTOG_TX) != 0)\
+ _ToggleDTOG_TX(bEpNum)
+/*******************************************************************************
+* Macro Name : SetEPAddress.
+* Description : Sets address in an endpoint register.
+* Input : bEpNum: Endpoint Number.
+* bAddr: Address.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPAddress(bEpNum,bAddr) _SetENDPOINT(bEpNum,\
+ _GetENDPOINT(bEpNum) & EPREG_MASK | bAddr)
+
+/*******************************************************************************
+* Macro Name : GetEPAddress.
+* Description : Gets address in an endpoint register.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _GetEPAddress(bEpNum) ((u8)(_GetENDPOINT(bEpNum) & EPADDR_FIELD))
+
+#define _pEPTxAddr(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8 )*2 + PMAAddr))
+#define _pEPTxCount(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8+2)*2 + PMAAddr))
+#define _pEPRxAddr(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8+4)*2 + PMAAddr))
+#define _pEPRxCount(bEpNum) ((u32 *)((_GetBTABLE()+bEpNum*8+6)*2 + PMAAddr))
+
+/*******************************************************************************
+* Macro Name : SetEPTxAddr / SetEPRxAddr.
+* Description : sets address of the tx/rx buffer.
+* Input : bEpNum: Endpoint Number.
+* wAddr: address to be set (must be word aligned).
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPTxAddr(bEpNum,wAddr) (*_pEPTxAddr(bEpNum) = ((wAddr >> 1) << 1))
+#define _SetEPRxAddr(bEpNum,wAddr) (*_pEPRxAddr(bEpNum) = ((wAddr >> 1) << 1))
+
+/*******************************************************************************
+* Macro Name : GetEPTxAddr / GetEPRxAddr.
+* Description : Gets address of the tx/rx buffer.
+* Input : bEpNum: Endpoint Number.
+* Output : None.
+* Return : address of the buffer.
+*******************************************************************************/
+#define _GetEPTxAddr(bEpNum) ((u16)*_pEPTxAddr(bEpNum))
+#define _GetEPRxAddr(bEpNum) ((u16)*_pEPRxAddr(bEpNum))
+
+/*******************************************************************************
+* Macro Name : SetEPCountRxReg.
+* Description : Sets counter of rx buffer with no. of blocks.
+* Input : pdwReg: pointer to counter.
+* wCount: Counter.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _BlocksOf32(dwReg,wCount,wNBlocks) {\
+ wNBlocks = wCount >> 5;\
+ if((wCount & 0x1f) == 0)\
+ wNBlocks--;\
+ *pdwReg = (u32)((wNBlocks << 10) | 0x8000);\
+ }/* _BlocksOf32 */
+
+#define _BlocksOf2(dwReg,wCount,wNBlocks) {\
+ wNBlocks = wCount >> 1;\
+ if((wCount & 0x1) != 0)\
+ wNBlocks++;\
+ *pdwReg = (u32)(wNBlocks << 10);\
+ }/* _BlocksOf2 */
+
+#define _SetEPCountRxReg(dwReg,wCount) {\
+ u16 wNBlocks;\
+ if(wCount > 62){_BlocksOf32(dwReg,wCount,wNBlocks);}\
+ else {_BlocksOf2(dwReg,wCount,wNBlocks);}\
+ }/* _SetEPCountRxReg */
+
+
+
+#define _SetEPRxDblBuf0Count(bEpNum,wCount) {\
+ u32 *pdwReg = _pEPTxCount(bEpNum); \
+ _SetEPCountRxReg(pdwReg, wCount);\
+ }
+/*******************************************************************************
+* Macro Name : SetEPTxCount / SetEPRxCount.
+* Description : sets counter for the tx/rx buffer.
+* Input : bEpNum: endpoint number.
+* wCount: Counter value.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPTxCount(bEpNum,wCount) (*_pEPTxCount(bEpNum) = wCount)
+#define _SetEPRxCount(bEpNum,wCount) {\
+ u32 *pdwReg = _pEPRxCount(bEpNum); \
+ _SetEPCountRxReg(pdwReg, wCount);\
+ }
+/*******************************************************************************
+* Macro Name : GetEPTxCount / GetEPRxCount.
+* Description : gets counter of the tx buffer.
+* Input : bEpNum: endpoint number.
+* Output : None.
+* Return : Counter value.
+*******************************************************************************/
+#define _GetEPTxCount(bEpNum)((u16)(*_pEPTxCount(bEpNum)) & 0x3ff)
+#define _GetEPRxCount(bEpNum)((u16)(*_pEPRxCount(bEpNum)) & 0x3ff)
+
+/*******************************************************************************
+* Macro Name : SetEPDblBuf0Addr / SetEPDblBuf1Addr.
+* Description : Sets buffer 0/1 address in a double buffer endpoint.
+* Input : bEpNum: endpoint number.
+* : wBuf0Addr: buffer 0 address.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPDblBuf0Addr(bEpNum,wBuf0Addr) {_SetEPTxAddr(bEpNum, wBuf0Addr);}
+#define _SetEPDblBuf1Addr(bEpNum,wBuf1Addr) {_SetEPRxAddr(bEpNum, wBuf1Addr);}
+
+/*******************************************************************************
+* Macro Name : SetEPDblBuffAddr.
+* Description : Sets addresses in a double buffer endpoint.
+* Input : bEpNum: endpoint number.
+* : wBuf0Addr: buffer 0 address.
+* : wBuf1Addr = buffer 1 address.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPDblBuffAddr(bEpNum,wBuf0Addr,wBuf1Addr) { \
+ _SetEPDblBuf0Addr(bEpNum, wBuf0Addr);\
+ _SetEPDblBuf1Addr(bEpNum, wBuf1Addr);\
+ } /* _SetEPDblBuffAddr */
+
+/*******************************************************************************
+* Macro Name : GetEPDblBuf0Addr / GetEPDblBuf1Addr.
+* Description : Gets buffer 0/1 address of a double buffer endpoint.
+* Input : bEpNum: endpoint number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _GetEPDblBuf0Addr(bEpNum) (_GetEPTxAddr(bEpNum))
+#define _GetEPDblBuf1Addr(bEpNum) (_GetEPRxAddr(bEpNum))
+
+/*******************************************************************************
+* Macro Name : SetEPDblBuffCount / SetEPDblBuf0Count / SetEPDblBuf1Count.
+* Description : Gets buffer 0/1 address of a double buffer endpoint.
+* Input : bEpNum: endpoint number.
+* : bDir: endpoint dir EP_DBUF_OUT = OUT
+* EP_DBUF_IN = IN
+* : wCount: Counter value
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _SetEPDblBuf0Count(bEpNum, bDir, wCount) { \
+ if(bDir == EP_DBUF_OUT)\
+ /* OUT endpoint */ \
+ {_SetEPRxDblBuf0Count(bEpNum,wCount);} \
+ else if(bDir == EP_DBUF_IN)\
+ /* IN endpoint */ \
+ *_pEPTxCount(bEpNum) = (u32)wCount; \
+ } /* SetEPDblBuf0Count*/
+
+#define _SetEPDblBuf1Count(bEpNum, bDir, wCount) { \
+ if(bDir == EP_DBUF_OUT)\
+ /* OUT endpoint */ \
+ {_SetEPRxCount(bEpNum,wCount);}\
+ else if(bDir == EP_DBUF_IN)\
+ /* IN endpoint */\
+ *_pEPRxCount(bEpNum) = (u32)wCount; \
+ } /* SetEPDblBuf1Count */
+
+#define _SetEPDblBuffCount(bEpNum, bDir, wCount) {\
+ _SetEPDblBuf0Count(bEpNum, bDir, wCount); \
+ _SetEPDblBuf1Count(bEpNum, bDir, wCount); \
+ } /* _SetEPDblBuffCount */
+
+/*******************************************************************************
+* Macro Name : GetEPDblBuf0Count / GetEPDblBuf1Count.
+* Description : Gets buffer 0/1 rx/tx counter for double buffering.
+* Input : bEpNum: endpoint number.
+* Output : None.
+* Return : None.
+*******************************************************************************/
+#define _GetEPDblBuf0Count(bEpNum) (_GetEPTxCount(bEpNum))
+#define _GetEPDblBuf1Count(bEpNum) (_GetEPRxCount(bEpNum))
+
+
+/* External variables --------------------------------------------------------*/
+extern volatile u16 wIstr; /* ISTR register last read value */
+
+/* Exported functions ------------------------------------------------------- */
+void SetCNTR(u16 /*wRegValue*/);
+void SetISTR(u16 /*wRegValue*/);
+void SetDADDR(u16 /*wRegValue*/);
+void SetBTABLE(u16 /*wRegValue*/);
+u16 GetCNTR(void);
+u16 GetISTR(void);
+u16 GetFNR(void);
+u16 GetDADDR(void);
+u16 GetBTABLE(void);
+void SetENDPOINT(u8 /*bEpNum*/, u16 /*wRegValue*/);
+u16 GetENDPOINT(u8 /*bEpNum*/);
+void SetEPType(u8 /*bEpNum*/, u16 /*wType*/);
+u16 GetEPType(u8 /*bEpNum*/);
+void SetEPTxStatus(u8 /*bEpNum*/, u16 /*wState*/);
+void SetEPRxStatus(u8 /*bEpNum*/, u16 /*wState*/);
+void SetDouBleBuffEPStall(u8 /*bEpNum*/, u8 bDir);
+u16 GetEPTxStatus(u8 /*bEpNum*/);
+u16 GetEPRxStatus(u8 /*bEpNum*/);
+void SetEPTxValid(u8 /*bEpNum*/);
+void SetEPRxValid(u8 /*bEpNum*/);
+u16 GetTxStallStatus(u8 /*bEpNum*/);
+u16 GetRxStallStatus(u8 /*bEpNum*/);
+void SetEP_KIND(u8 /*bEpNum*/);
+void ClearEP_KIND(u8 /*bEpNum*/);
+void Set_Status_Out(u8 /*bEpNum*/);
+void Clear_Status_Out(u8 /*bEpNum*/);
+void SetEPDoubleBuff(u8 /*bEpNum*/);
+void ClearEPDoubleBuff(u8 /*bEpNum*/);
+void ClearEP_CTR_RX(u8 /*bEpNum*/);
+void ClearEP_CTR_TX(u8 /*bEpNum*/);
+void ToggleDTOG_RX(u8 /*bEpNum*/);
+void ToggleDTOG_TX(u8 /*bEpNum*/);
+void ClearDTOG_RX(u8 /*bEpNum*/);
+void ClearDTOG_TX(u8 /*bEpNum*/);
+void SetEPAddress(u8 /*bEpNum*/, u8 /*bAddr*/);
+u8 GetEPAddress(u8 /*bEpNum*/);
+void SetEPTxAddr(u8 /*bEpNum*/, u16 /*wAddr*/);
+void SetEPRxAddr(u8 /*bEpNum*/, u16 /*wAddr*/);
+u16 GetEPTxAddr(u8 /*bEpNum*/);
+u16 GetEPRxAddr(u8 /*bEpNum*/);
+void SetEPCountRxReg(u32 * /*pdwReg*/, u16 /*wCount*/);
+void SetEPTxCount(u8 /*bEpNum*/, u16 /*wCount*/);
+void SetEPRxCount(u8 /*bEpNum*/, u16 /*wCount*/);
+u16 GetEPTxCount(u8 /*bEpNum*/);
+u16 GetEPRxCount(u8 /*bEpNum*/);
+void SetEPDblBuf0Addr(u8 /*bEpNum*/, u16 /*wBuf0Addr*/);
+void SetEPDblBuf1Addr(u8 /*bEpNum*/, u16 /*wBuf1Addr*/);
+void SetEPDblBuffAddr(u8 /*bEpNum*/, u16 /*wBuf0Addr*/, u16 /*wBuf1Addr*/);
+u16 GetEPDblBuf0Addr(u8 /*bEpNum*/);
+u16 GetEPDblBuf1Addr(u8 /*bEpNum*/);
+void SetEPDblBuffCount(u8 /*bEpNum*/, u8 /*bDir*/, u16 /*wCount*/);
+void SetEPDblBuf0Count(u8 /*bEpNum*/, u8 /*bDir*/, u16 /*wCount*/);
+void SetEPDblBuf1Count(u8 /*bEpNum*/, u8 /*bDir*/, u16 /*wCount*/);
+u16 GetEPDblBuf0Count(u8 /*bEpNum*/);
+u16 GetEPDblBuf1Count(u8 /*bEpNum*/);
+EP_DBUF_DIR GetEPDblBufDir(u8 /*bEpNum*/);
+void FreeUserBuffer(u8 bEpNum/*bEpNum*/, u8 bDir);
+u16 ToWord(u8, u8);
+u16 ByteSwap(u16);
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __USB_REGS_H */
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
diff --git a/libmaple/usb/usb_lib/usb_type.h b/libmaple/usb/usb_lib/usb_type.h
index 1106786..34b3bf5 100644
--- a/libmaple/usb/usb_lib/usb_type.h
+++ b/libmaple/usb/usb_lib/usb_type.h
@@ -1,77 +1,77 @@
-/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
-* File Name : usb_type.h
-* Author : MCD Application Team
-* Version : V2.2.1
-* Date : 09/22/2008
-* Description : Type definitions used by the USB Library
-********************************************************************************
-* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
-* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
-* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
-* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
-* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
-* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
-*******************************************************************************/
-
-/* Define to prevent recursive inclusion -------------------------------------*/
-#ifndef __USB_TYPE_H
-#define __USB_TYPE_H
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-/* Exported types ------------------------------------------------------------*/
-/* Exported constants --------------------------------------------------------*/
-#ifndef NULL
-#define NULL ((void *)0)
-#endif
-
-typedef signed long s32;
-typedef signed short s16;
-typedef signed char s8;
-
-typedef volatile signed long vs32;
-typedef volatile signed short vs16;
-typedef volatile signed char vs8;
-
-typedef unsigned long u32;
-typedef unsigned short u16;
-typedef unsigned char u8;
-
-typedef unsigned long const uc32; /* Read Only */
-typedef unsigned short const uc16; /* Read Only */
-typedef unsigned char const uc8; /* Read Only */
-
-typedef volatile unsigned long vu32;
-typedef volatile unsigned short vu16;
-typedef volatile unsigned char vu8;
-
-typedef volatile unsigned long const vuc32; /* Read Only */
-typedef volatile unsigned short const vuc16; /* Read Only */
-typedef volatile unsigned char const vuc8; /* Read Only */
-
-
-typedef enum
-{
- FALSE = 0, TRUE = !FALSE
-}
-USB_Bool;
-
-typedef enum { RESET = 0, SET = !RESET } FlagStatus, ITStatus;
-
-typedef enum { DISABLE = 0, ENABLE = !DISABLE} FunctionalState;
-
-typedef enum { ERROR = 0, SUCCESS = !ERROR} ErrorStatus;
-
-/* Exported macro ------------------------------------------------------------*/
-/* Exported functions ------------------------------------------------------- */
-/* External variables --------------------------------------------------------*/
-
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /* __USB_TYPE_H */
-
-/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
+/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
+* File Name : usb_type.h
+* Author : MCD Application Team
+* Version : V2.2.1
+* Date : 09/22/2008
+* Description : Type definitions used by the USB Library
+********************************************************************************
+* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
+* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
+* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
+* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
+* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
+* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
+*******************************************************************************/
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USB_TYPE_H
+#define __USB_TYPE_H
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+#ifndef NULL
+#define NULL ((void *)0)
+#endif
+
+typedef signed long s32;
+typedef signed short s16;
+typedef signed char s8;
+
+typedef volatile signed long vs32;
+typedef volatile signed short vs16;
+typedef volatile signed char vs8;
+
+typedef unsigned long u32;
+typedef unsigned short u16;
+typedef unsigned char u8;
+
+typedef unsigned long const uc32; /* Read Only */
+typedef unsigned short const uc16; /* Read Only */
+typedef unsigned char const uc8; /* Read Only */
+
+typedef volatile unsigned long vu32;
+typedef volatile unsigned short vu16;
+typedef volatile unsigned char vu8;
+
+typedef volatile unsigned long const vuc32; /* Read Only */
+typedef volatile unsigned short const vuc16; /* Read Only */
+typedef volatile unsigned char const vuc8; /* Read Only */
+
+
+typedef enum
+{
+ FALSE = 0, TRUE = !FALSE
+}
+USB_Bool;
+
+typedef enum { RESET = 0, SET = !RESET } FlagStatus, ITStatus;
+
+typedef enum { DISABLE = 0, ENABLE = !DISABLE} FunctionalState;
+
+typedef enum { ERROR = 0, SUCCESS = !ERROR} ErrorStatus;
+
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+/* External variables --------------------------------------------------------*/
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __USB_TYPE_H */
+
+/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/