i2c controller to peripheral Hello World

This commit is contained in:
2022-10-26 20:34:57 -04:00
parent 074a3cf660
commit 6b2ef5f1dc
119 changed files with 134755 additions and 0 deletions

View File

@@ -0,0 +1,448 @@
/**
******************************************************************************
* @file usbh_cdc.h
* @author MCD Application Team
* @brief This file contains all the prototypes for the usbh_cdc.c
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2015 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Define to prevent recursive ----------------------------------------------*/
#ifndef __USBH_CDC_H
#define __USBH_CDC_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "usbh_core.h"
/** @addtogroup USBH_LIB
* @{
*/
/** @addtogroup USBH_CLASS
* @{
*/
/** @addtogroup USBH_CDC_CLASS
* @{
*/
/** @defgroup USBH_CDC_CORE
* @brief This file is the Header file for usbh_core.c
* @{
*/
/*Communication Class codes*/
#define USB_CDC_CLASS 0x02U
#define COMMUNICATION_INTERFACE_CLASS_CODE 0x02U
/*Data Interface Class Codes*/
#define DATA_INTERFACE_CLASS_CODE 0x0AU
/*Communication sub class codes*/
#define RESERVED 0x00U
#define DIRECT_LINE_CONTROL_MODEL 0x01U
#define ABSTRACT_CONTROL_MODEL 0x02U
#define TELEPHONE_CONTROL_MODEL 0x03U
#define MULTICHANNEL_CONTROL_MODEL 0x04U
#define CAPI_CONTROL_MODEL 0x05U
#define ETHERNET_NETWORKING_CONTROL_MODEL 0x06U
#define ATM_NETWORKING_CONTROL_MODEL 0x07U
/*Communication Interface Class Control Protocol Codes*/
#define NO_CLASS_SPECIFIC_PROTOCOL_CODE 0x00U
#define COMMON_AT_COMMAND 0x01U
#define VENDOR_SPECIFIC 0xFFU
#define CS_INTERFACE 0x24U
#define CDC_PAGE_SIZE_64 0x40U
/*Class-Specific Request Codes*/
#define CDC_SEND_ENCAPSULATED_COMMAND 0x00U
#define CDC_GET_ENCAPSULATED_RESPONSE 0x01U
#define CDC_SET_COMM_FEATURE 0x02U
#define CDC_GET_COMM_FEATURE 0x03U
#define CDC_CLEAR_COMM_FEATURE 0x04U
#define CDC_SET_AUX_LINE_STATE 0x10U
#define CDC_SET_HOOK_STATE 0x11U
#define CDC_PULSE_SETUP 0x12U
#define CDC_SEND_PULSE 0x13U
#define CDC_SET_PULSE_TIME 0x14U
#define CDC_RING_AUX_JACK 0x15U
#define CDC_SET_LINE_CODING 0x20U
#define CDC_GET_LINE_CODING 0x21U
#define CDC_SET_CONTROL_LINE_STATE 0x22U
#define CDC_SEND_BREAK 0x23U
#define CDC_SET_RINGER_PARMS 0x30U
#define CDC_GET_RINGER_PARMS 0x31U
#define CDC_SET_OPERATION_PARMS 0x32U
#define CDC_GET_OPERATION_PARMS 0x33U
#define CDC_SET_LINE_PARMS 0x34U
#define CDC_GET_LINE_PARMS 0x35U
#define CDC_DIAL_DIGITS 0x36U
#define CDC_SET_UNIT_PARAMETER 0x37U
#define CDC_GET_UNIT_PARAMETER 0x38U
#define CDC_CLEAR_UNIT_PARAMETER 0x39U
#define CDC_GET_PROFILE 0x3AU
#define CDC_SET_ETHERNET_MULTICAST_FILTERS 0x40U
#define CDC_SET_ETHERNET_POWER_MANAGEMENT_PATTERN FILTER 0x41U
#define CDC_GET_ETHERNET_POWER_MANAGEMENT_PATTERN FILTER 0x42U
#define CDC_SET_ETHERNET_PACKET_FILTER 0x43U
#define CDC_GET_ETHERNET_STATISTIC 0x44U
#define CDC_SET_ATM_DATA_FORMAT 0x50U
#define CDC_GET_ATM_DEVICE_STATISTICS 0x51U
#define CDC_SET_ATM_DEFAULT_VC 0x52U
#define CDC_GET_ATM_VC_STATISTICS 0x53U
/* wValue for SetControlLineState*/
#define CDC_ACTIVATE_CARRIER_SIGNAL_RTS 0x0002U
#define CDC_DEACTIVATE_CARRIER_SIGNAL_RTS 0x0000U
#define CDC_ACTIVATE_SIGNAL_DTR 0x0001U
#define CDC_DEACTIVATE_SIGNAL_DTR 0x0000U
#define LINE_CODING_STRUCTURE_SIZE 0x07U
/**
* @}
*/
/** @defgroup USBH_CDC_CORE_Exported_Types
* @{
*/
/* States for CDC State Machine */
typedef enum
{
CDC_IDLE = 0U,
CDC_SEND_DATA,
CDC_SEND_DATA_WAIT,
CDC_RECEIVE_DATA,
CDC_RECEIVE_DATA_WAIT,
}
CDC_DataStateTypeDef;
typedef enum
{
CDC_IDLE_STATE = 0U,
CDC_SET_LINE_CODING_STATE,
CDC_GET_LAST_LINE_CODING_STATE,
CDC_TRANSFER_DATA,
CDC_ERROR_STATE,
}
CDC_StateTypeDef;
/*Line coding structure*/
typedef union _CDC_LineCodingStructure
{
uint8_t Array[LINE_CODING_STRUCTURE_SIZE];
struct
{
uint32_t dwDTERate; /*Data terminal rate, in bits per second*/
uint8_t bCharFormat; /*Stop bits
0 - 1 Stop bit
1 - 1.5 Stop bits
2 - 2 Stop bits*/
uint8_t bParityType; /* Parity
0 - None
1 - Odd
2 - Even
3 - Mark
4 - Space*/
uint8_t bDataBits; /* Data bits (5, 6, 7, 8 or 16). */
} b;
}
CDC_LineCodingTypeDef;
/* Header Functional Descriptor
--------------------------------------------------------------------------------
Offset| field | Size | Value | Description
------|---------------------|-------|------------|------------------------------
0 | bFunctionLength | 1 | number | Size of this descriptor.
1 | bDescriptorType | 1 | Constant | CS_INTERFACE (0x24)
2 | bDescriptorSubtype | 1 | Constant | Identifier (ID) of functional
| | | | descriptor.
3 | bcdCDC | 2 | |
| | | Number | USB Class Definitions for
| | | | Communication Devices Specification
| | | | release number in binary-coded
| | | | decimal
------|---------------------|-------|------------|------------------------------
*/
typedef struct _FunctionalDescriptorHeader
{
uint8_t bLength; /*Size of this descriptor.*/
uint8_t bDescriptorType; /*CS_INTERFACE (0x24)*/
uint8_t bDescriptorSubType; /* Header functional descriptor subtype as*/
uint16_t bcdCDC; /* USB Class Definitions for Communication
Devices Specification release number in
binary-coded decimal. */
}
CDC_HeaderFuncDesc_TypeDef;
/* Call Management Functional Descriptor
--------------------------------------------------------------------------------
Offset| field | Size | Value | Description
------|---------------------|-------|------------|------------------------------
0 | bFunctionLength | 1 | number | Size of this descriptor.
1 | bDescriptorType | 1 | Constant | CS_INTERFACE (0x24)
2 | bDescriptorSubtype | 1 | Constant | Call Management functional
| | | | descriptor subtype.
3 | bmCapabilities | 1 | Bitmap | The capabilities that this configuration
| | | | supports:
| | | | D7..D2: RESERVED (Reset to zero)
| | | | D1: 0 - Device sends/receives call
| | | | management information only over
| | | | the Communication Class
| | | | interface.
| | | | 1 - Device can send/receive call
| \ | | management information over a
| | | | Data Class interface.
| | | | D0: 0 - Device does not handle call
| | | | management itself.
| | | | 1 - Device handles call
| | | | management itself.
| | | | The previous bits, in combination, identify
| | | | which call management scenario is used. If bit
| | | | D0 is reset to 0, then the value of bit D1 is
| | | | ignored. In this case, bit D1 is reset to zero for
| | | | future compatibility.
4 | bDataInterface | 1 | Number | Interface number of Data Class interface
| | | | optionally used for call management.
------|---------------------|-------|------------|------------------------------
*/
typedef struct _CallMgmtFunctionalDescriptor
{
uint8_t bLength; /*Size of this functional descriptor, in bytes.*/
uint8_t bDescriptorType; /*CS_INTERFACE (0x24)*/
uint8_t bDescriptorSubType; /* Call Management functional descriptor subtype*/
uint8_t bmCapabilities; /* bmCapabilities: D0+D1 */
uint8_t bDataInterface; /*bDataInterface: 1*/
}
CDC_CallMgmtFuncDesc_TypeDef;
/* Abstract Control Management Functional Descriptor
--------------------------------------------------------------------------------
Offset| field | Size | Value | Description
------|---------------------|-------|------------|------------------------------
0 | bFunctionLength | 1 | number | Size of functional descriptor, in bytes.
1 | bDescriptorType | 1 | Constant | CS_INTERFACE (0x24)
2 | bDescriptorSubtype | 1 | Constant | Abstract Control Management
| | | | functional descriptor subtype.
3 | bmCapabilities | 1 | Bitmap | The capabilities that this configuration
| | | | supports ((A bit value of zero means that the
| | | | request is not supported.) )
D7..D4: RESERVED (Reset to zero)
| | | | D3: 1 - Device supports the notification
| | | | Network_Connection.
| | | | D2: 1 - Device supports the request
| | | | Send_Break
| | | | D1: 1 - Device supports the request
| \ | | combination of Set_Line_Coding,
| | | | Set_Control_Line_State, Get_Line_Coding, and the
notification Serial_State.
| | | | D0: 1 - Device supports the request
| | | | combination of Set_Comm_Feature,
| | | | Clear_Comm_Feature, and Get_Comm_Feature.
| | | | The previous bits, in combination, identify
| | | | which requests/notifications are supported by
| | | | a Communication Class interface with the
| | | | SubClass code of Abstract Control Model.
------|---------------------|-------|------------|------------------------------
*/
typedef struct _AbstractCntrlMgmtFunctionalDescriptor
{
uint8_t bLength; /*Size of this functional descriptor, in bytes.*/
uint8_t bDescriptorType; /*CS_INTERFACE (0x24)*/
uint8_t bDescriptorSubType; /* Abstract Control Management functional
descriptor subtype*/
uint8_t bmCapabilities; /* The capabilities that this configuration supports */
}
CDC_AbstCntrlMgmtFuncDesc_TypeDef;
/* Union Functional Descriptor
--------------------------------------------------------------------------------
Offset| field | Size | Value | Description
------|---------------------|-------|------------|------------------------------
0 | bFunctionLength | 1 | number | Size of this descriptor.
1 | bDescriptorType | 1 | Constant | CS_INTERFACE (0x24)
2 | bDescriptorSubtype | 1 | Constant | Union functional
| | | | descriptor subtype.
3 | bMasterInterface | 1 | Constant | The interface number of the
| | | | Communication or Data Class interface
4 | bSlaveInterface0 | 1 | Number | nterface number of first slave or associated
| | | | interface in the union.
------|---------------------|-------|------------|------------------------------
*/
typedef struct _UnionFunctionalDescriptor
{
uint8_t bLength; /*Size of this functional descriptor, in bytes*/
uint8_t bDescriptorType; /*CS_INTERFACE (0x24)*/
uint8_t bDescriptorSubType; /* Union functional descriptor SubType*/
uint8_t bMasterInterface; /* The interface number of the Communication or
Data Class interface,*/
uint8_t bSlaveInterface0; /*Interface number of first slave*/
}
CDC_UnionFuncDesc_TypeDef;
typedef struct _USBH_CDCInterfaceDesc
{
CDC_HeaderFuncDesc_TypeDef CDC_HeaderFuncDesc;
CDC_CallMgmtFuncDesc_TypeDef CDC_CallMgmtFuncDesc;
CDC_AbstCntrlMgmtFuncDesc_TypeDef CDC_AbstCntrlMgmtFuncDesc;
CDC_UnionFuncDesc_TypeDef CDC_UnionFuncDesc;
}
CDC_InterfaceDesc_Typedef;
/* Structure for CDC process */
typedef struct
{
uint8_t NotifPipe;
uint8_t NotifEp;
uint8_t buff[8];
uint16_t NotifEpSize;
}
CDC_CommItfTypedef ;
typedef struct
{
uint8_t InPipe;
uint8_t OutPipe;
uint8_t OutEp;
uint8_t InEp;
uint8_t buff[8];
uint16_t OutEpSize;
uint16_t InEpSize;
}
CDC_DataItfTypedef ;
/* Structure for CDC process */
typedef struct _CDC_Process
{
CDC_CommItfTypedef CommItf;
CDC_DataItfTypedef DataItf;
uint8_t *pTxData;
uint8_t *pRxData;
uint32_t TxDataLength;
uint32_t RxDataLength;
CDC_InterfaceDesc_Typedef CDC_Desc;
CDC_LineCodingTypeDef LineCoding;
CDC_LineCodingTypeDef *pUserLineCoding;
CDC_StateTypeDef state;
CDC_DataStateTypeDef data_tx_state;
CDC_DataStateTypeDef data_rx_state;
uint8_t Rx_Poll;
}
CDC_HandleTypeDef;
/**
* @}
*/
/** @defgroup USBH_CDC_CORE_Exported_Defines
* @{
*/
/**
* @}
*/
/** @defgroup USBH_CDC_CORE_Exported_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USBH_CDC_CORE_Exported_Variables
* @{
*/
extern USBH_ClassTypeDef CDC_Class;
#define USBH_CDC_CLASS &CDC_Class
/**
* @}
*/
/** @defgroup USBH_CDC_CORE_Exported_FunctionsPrototype
* @{
*/
USBH_StatusTypeDef USBH_CDC_SetLineCoding(USBH_HandleTypeDef *phost,
CDC_LineCodingTypeDef *linecoding);
USBH_StatusTypeDef USBH_CDC_GetLineCoding(USBH_HandleTypeDef *phost,
CDC_LineCodingTypeDef *linecoding);
USBH_StatusTypeDef USBH_CDC_Transmit(USBH_HandleTypeDef *phost,
uint8_t *pbuff,
uint32_t length);
USBH_StatusTypeDef USBH_CDC_Receive(USBH_HandleTypeDef *phost,
uint8_t *pbuff,
uint32_t length);
uint16_t USBH_CDC_GetLastReceivedDataSize(USBH_HandleTypeDef *phost);
USBH_StatusTypeDef USBH_CDC_Stop(USBH_HandleTypeDef *phost);
void USBH_CDC_LineCodingChanged(USBH_HandleTypeDef *phost);
void USBH_CDC_TransmitCallback(USBH_HandleTypeDef *phost);
void USBH_CDC_ReceiveCallback(USBH_HandleTypeDef *phost);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __USBH_CDC_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,837 @@
/**
******************************************************************************
* @file usbh_cdc.c
* @author MCD Application Team
* @brief This file is the CDC Layer Handlers for USB Host CDC class.
*
* @verbatim
*
* ===================================================================
* CDC Class Driver Description
* ===================================================================
* This driver manages the "Universal Serial Bus Class Definitions for Communications Devices
* Revision 1.2 November 16, 2007" and the sub-protocol specification of "Universal Serial Bus
* Communications Class Subclass Specification for PSTN Devices Revision 1.2 February 9, 2007"
* This driver implements the following aspects of the specification:
* - Device descriptor management
* - Configuration descriptor management
* - Enumeration as CDC device with 2 data endpoints (IN and OUT) and 1 command endpoint (IN)
* - Requests management (as described in section 6.2 in specification)
* - Abstract Control Model compliant
* - Union Functional collection (using 1 IN endpoint for control)
* - Data interface class
*
* @endverbatim
*
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2015 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* BSPDependencies
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
- "stm32xxxxx_{eval}{discovery}_io.c"
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
- "stm32xxxxx_{eval}{discovery}{adafruit}_lcd.c"
- "stm32xxxxx_{eval}{discovery}_sdram.c"
EndBSPDependencies */
/* Includes ------------------------------------------------------------------*/
#include "usbh_cdc.h"
/** @addtogroup USBH_LIB
* @{
*/
/** @addtogroup USBH_CLASS
* @{
*/
/** @addtogroup USBH_CDC_CLASS
* @{
*/
/** @defgroup USBH_CDC_CORE
* @brief This file includes CDC Layer Handlers for USB Host CDC class.
* @{
*/
/** @defgroup USBH_CDC_CORE_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup USBH_CDC_CORE_Private_Defines
* @{
*/
#define USBH_CDC_BUFFER_SIZE 1024
/**
* @}
*/
/** @defgroup USBH_CDC_CORE_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USBH_CDC_CORE_Private_Variables
* @{
*/
/**
* @}
*/
/** @defgroup USBH_CDC_CORE_Private_FunctionPrototypes
* @{
*/
static USBH_StatusTypeDef USBH_CDC_InterfaceInit(USBH_HandleTypeDef *phost);
static USBH_StatusTypeDef USBH_CDC_InterfaceDeInit(USBH_HandleTypeDef *phost);
static USBH_StatusTypeDef USBH_CDC_Process(USBH_HandleTypeDef *phost);
static USBH_StatusTypeDef USBH_CDC_SOFProcess(USBH_HandleTypeDef *phost);
static USBH_StatusTypeDef USBH_CDC_ClassRequest(USBH_HandleTypeDef *phost);
static USBH_StatusTypeDef GetLineCoding(USBH_HandleTypeDef *phost,
CDC_LineCodingTypeDef *linecoding);
static USBH_StatusTypeDef SetLineCoding(USBH_HandleTypeDef *phost,
CDC_LineCodingTypeDef *linecoding);
static void CDC_ProcessTransmission(USBH_HandleTypeDef *phost);
static void CDC_ProcessReception(USBH_HandleTypeDef *phost);
USBH_ClassTypeDef CDC_Class =
{
"CDC",
USB_CDC_CLASS,
USBH_CDC_InterfaceInit,
USBH_CDC_InterfaceDeInit,
USBH_CDC_ClassRequest,
USBH_CDC_Process,
USBH_CDC_SOFProcess,
NULL,
};
/**
* @}
*/
/** @defgroup USBH_CDC_CORE_Private_Functions
* @{
*/
/**
* @brief USBH_CDC_InterfaceInit
* The function init the CDC class.
* @param phost: Host handle
* @retval USBH Status
*/
static USBH_StatusTypeDef USBH_CDC_InterfaceInit(USBH_HandleTypeDef *phost)
{
USBH_StatusTypeDef status;
uint8_t interface;
CDC_HandleTypeDef *CDC_Handle;
interface = USBH_FindInterface(phost, COMMUNICATION_INTERFACE_CLASS_CODE,
ABSTRACT_CONTROL_MODEL, COMMON_AT_COMMAND);
if ((interface == 0xFFU) || (interface >= USBH_MAX_NUM_INTERFACES)) /* No Valid Interface */
{
USBH_DbgLog("Cannot Find the interface for Communication Interface Class.", phost->pActiveClass->Name);
return USBH_FAIL;
}
status = USBH_SelectInterface(phost, interface);
if (status != USBH_OK)
{
return USBH_FAIL;
}
phost->pActiveClass->pData = (CDC_HandleTypeDef *)USBH_malloc(sizeof(CDC_HandleTypeDef));
CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData;
if (CDC_Handle == NULL)
{
USBH_DbgLog("Cannot allocate memory for CDC Handle");
return USBH_FAIL;
}
/* Initialize cdc handler */
(void)USBH_memset(CDC_Handle, 0, sizeof(CDC_HandleTypeDef));
/*Collect the notification endpoint address and length*/
if ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80U) != 0U)
{
CDC_Handle->CommItf.NotifEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress;
CDC_Handle->CommItf.NotifEpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize;
}
/*Allocate the length for host channel number in*/
CDC_Handle->CommItf.NotifPipe = USBH_AllocPipe(phost, CDC_Handle->CommItf.NotifEp);
/* Open pipe for Notification endpoint */
(void)USBH_OpenPipe(phost, CDC_Handle->CommItf.NotifPipe, CDC_Handle->CommItf.NotifEp,
phost->device.address, phost->device.speed, USB_EP_TYPE_INTR,
CDC_Handle->CommItf.NotifEpSize);
(void)USBH_LL_SetToggle(phost, CDC_Handle->CommItf.NotifPipe, 0U);
interface = USBH_FindInterface(phost, DATA_INTERFACE_CLASS_CODE,
RESERVED, NO_CLASS_SPECIFIC_PROTOCOL_CODE);
if ((interface == 0xFFU) || (interface >= USBH_MAX_NUM_INTERFACES)) /* No Valid Interface */
{
USBH_DbgLog("Cannot Find the interface for Data Interface Class.", phost->pActiveClass->Name);
return USBH_FAIL;
}
/*Collect the class specific endpoint address and length*/
if ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80U) != 0U)
{
CDC_Handle->DataItf.InEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress;
CDC_Handle->DataItf.InEpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize;
}
else
{
CDC_Handle->DataItf.OutEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress;
CDC_Handle->DataItf.OutEpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize;
}
if ((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].bEndpointAddress & 0x80U) != 0U)
{
CDC_Handle->DataItf.InEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].bEndpointAddress;
CDC_Handle->DataItf.InEpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].wMaxPacketSize;
}
else
{
CDC_Handle->DataItf.OutEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].bEndpointAddress;
CDC_Handle->DataItf.OutEpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].wMaxPacketSize;
}
/*Allocate the length for host channel number out*/
CDC_Handle->DataItf.OutPipe = USBH_AllocPipe(phost, CDC_Handle->DataItf.OutEp);
/*Allocate the length for host channel number in*/
CDC_Handle->DataItf.InPipe = USBH_AllocPipe(phost, CDC_Handle->DataItf.InEp);
/* Open channel for OUT endpoint */
(void)USBH_OpenPipe(phost, CDC_Handle->DataItf.OutPipe, CDC_Handle->DataItf.OutEp,
phost->device.address, phost->device.speed, USB_EP_TYPE_BULK,
CDC_Handle->DataItf.OutEpSize);
/* Open channel for IN endpoint */
(void)USBH_OpenPipe(phost, CDC_Handle->DataItf.InPipe, CDC_Handle->DataItf.InEp,
phost->device.address, phost->device.speed, USB_EP_TYPE_BULK,
CDC_Handle->DataItf.InEpSize);
CDC_Handle->state = CDC_IDLE_STATE;
(void)USBH_LL_SetToggle(phost, CDC_Handle->DataItf.OutPipe, 0U);
(void)USBH_LL_SetToggle(phost, CDC_Handle->DataItf.InPipe, 0U);
return USBH_OK;
}
/**
* @brief USBH_CDC_InterfaceDeInit
* The function DeInit the Pipes used for the CDC class.
* @param phost: Host handle
* @retval USBH Status
*/
static USBH_StatusTypeDef USBH_CDC_InterfaceDeInit(USBH_HandleTypeDef *phost)
{
CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData;
if ((CDC_Handle->CommItf.NotifPipe) != 0U)
{
(void)USBH_ClosePipe(phost, CDC_Handle->CommItf.NotifPipe);
(void)USBH_FreePipe(phost, CDC_Handle->CommItf.NotifPipe);
CDC_Handle->CommItf.NotifPipe = 0U; /* Reset the Channel as Free */
}
if ((CDC_Handle->DataItf.InPipe) != 0U)
{
(void)USBH_ClosePipe(phost, CDC_Handle->DataItf.InPipe);
(void)USBH_FreePipe(phost, CDC_Handle->DataItf.InPipe);
CDC_Handle->DataItf.InPipe = 0U; /* Reset the Channel as Free */
}
if ((CDC_Handle->DataItf.OutPipe) != 0U)
{
(void)USBH_ClosePipe(phost, CDC_Handle->DataItf.OutPipe);
(void)USBH_FreePipe(phost, CDC_Handle->DataItf.OutPipe);
CDC_Handle->DataItf.OutPipe = 0U; /* Reset the Channel as Free */
}
if ((phost->pActiveClass->pData) != NULL)
{
USBH_free(phost->pActiveClass->pData);
phost->pActiveClass->pData = 0U;
}
return USBH_OK;
}
/**
* @brief USBH_CDC_ClassRequest
* The function is responsible for handling Standard requests
* for CDC class.
* @param phost: Host handle
* @retval USBH Status
*/
static USBH_StatusTypeDef USBH_CDC_ClassRequest(USBH_HandleTypeDef *phost)
{
USBH_StatusTypeDef status;
CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData;
/* Issue the get line coding request */
status = GetLineCoding(phost, &CDC_Handle->LineCoding);
if (status == USBH_OK)
{
phost->pUser(phost, HOST_USER_CLASS_ACTIVE);
}
else if (status == USBH_NOT_SUPPORTED)
{
USBH_ErrLog("Control error: CDC: Device Get Line Coding configuration failed");
}
else
{
/* .. */
}
return status;
}
/**
* @brief USBH_CDC_Process
* The function is for managing state machine for CDC data transfers
* @param phost: Host handle
* @retval USBH Status
*/
static USBH_StatusTypeDef USBH_CDC_Process(USBH_HandleTypeDef *phost)
{
USBH_StatusTypeDef status = USBH_BUSY;
USBH_StatusTypeDef req_status = USBH_OK;
CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData;
switch (CDC_Handle->state)
{
case CDC_IDLE_STATE:
status = USBH_OK;
break;
case CDC_SET_LINE_CODING_STATE:
req_status = SetLineCoding(phost, CDC_Handle->pUserLineCoding);
if (req_status == USBH_OK)
{
CDC_Handle->state = CDC_GET_LAST_LINE_CODING_STATE;
}
else
{
if (req_status != USBH_BUSY)
{
CDC_Handle->state = CDC_ERROR_STATE;
}
}
break;
case CDC_GET_LAST_LINE_CODING_STATE:
req_status = GetLineCoding(phost, &(CDC_Handle->LineCoding));
if (req_status == USBH_OK)
{
CDC_Handle->state = CDC_IDLE_STATE;
if ((CDC_Handle->LineCoding.b.bCharFormat == CDC_Handle->pUserLineCoding->b.bCharFormat) &&
(CDC_Handle->LineCoding.b.bDataBits == CDC_Handle->pUserLineCoding->b.bDataBits) &&
(CDC_Handle->LineCoding.b.bParityType == CDC_Handle->pUserLineCoding->b.bParityType) &&
(CDC_Handle->LineCoding.b.dwDTERate == CDC_Handle->pUserLineCoding->b.dwDTERate))
{
USBH_CDC_LineCodingChanged(phost);
}
}
else
{
if (req_status != USBH_BUSY)
{
CDC_Handle->state = CDC_ERROR_STATE;
}
}
break;
case CDC_TRANSFER_DATA:
CDC_ProcessTransmission(phost);
CDC_ProcessReception(phost);
break;
case CDC_ERROR_STATE:
req_status = USBH_ClrFeature(phost, 0x00U);
if (req_status == USBH_OK)
{
/*Change the state to waiting*/
CDC_Handle->state = CDC_IDLE_STATE;
}
break;
default:
break;
}
return status;
}
/**
* @brief USBH_CDC_SOFProcess
* The function is for managing SOF callback
* @param phost: Host handle
* @retval USBH Status
*/
static USBH_StatusTypeDef USBH_CDC_SOFProcess(USBH_HandleTypeDef *phost)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(phost);
return USBH_OK;
}
/**
* @brief USBH_CDC_Stop
* Stop current CDC Transmission
* @param phost: Host handle
* @retval USBH Status
*/
USBH_StatusTypeDef USBH_CDC_Stop(USBH_HandleTypeDef *phost)
{
CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData;
if (phost->gState == HOST_CLASS)
{
CDC_Handle->state = CDC_IDLE_STATE;
(void)USBH_ClosePipe(phost, CDC_Handle->CommItf.NotifPipe);
(void)USBH_ClosePipe(phost, CDC_Handle->DataItf.InPipe);
(void)USBH_ClosePipe(phost, CDC_Handle->DataItf.OutPipe);
}
return USBH_OK;
}
/**
* @brief This request allows the host to find out the currently
* configured line coding.
* @param pdev: Selected device
* @retval USBH_StatusTypeDef : USB ctl xfer status
*/
static USBH_StatusTypeDef GetLineCoding(USBH_HandleTypeDef *phost, CDC_LineCodingTypeDef *linecoding)
{
phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_TYPE_CLASS | \
USB_REQ_RECIPIENT_INTERFACE;
phost->Control.setup.b.bRequest = CDC_GET_LINE_CODING;
phost->Control.setup.b.wValue.w = 0U;
phost->Control.setup.b.wIndex.w = 0U;
phost->Control.setup.b.wLength.w = LINE_CODING_STRUCTURE_SIZE;
return USBH_CtlReq(phost, linecoding->Array, LINE_CODING_STRUCTURE_SIZE);
}
/**
* @brief This request allows the host to specify typical asynchronous
* line-character formatting properties
* This request applies to asynchronous byte stream data class interfaces
* and endpoints
* @param pdev: Selected device
* @retval USBH_StatusTypeDef : USB ctl xfer status
*/
static USBH_StatusTypeDef SetLineCoding(USBH_HandleTypeDef *phost,
CDC_LineCodingTypeDef *linecoding)
{
phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_TYPE_CLASS |
USB_REQ_RECIPIENT_INTERFACE;
phost->Control.setup.b.bRequest = CDC_SET_LINE_CODING;
phost->Control.setup.b.wValue.w = 0U;
phost->Control.setup.b.wIndex.w = 0U;
phost->Control.setup.b.wLength.w = LINE_CODING_STRUCTURE_SIZE;
return USBH_CtlReq(phost, linecoding->Array, LINE_CODING_STRUCTURE_SIZE);
}
/**
* @brief This function prepares the state before issuing the class specific commands
* @param None
* @retval None
*/
USBH_StatusTypeDef USBH_CDC_SetLineCoding(USBH_HandleTypeDef *phost,
CDC_LineCodingTypeDef *linecoding)
{
CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData;
if (phost->gState == HOST_CLASS)
{
CDC_Handle->state = CDC_SET_LINE_CODING_STATE;
CDC_Handle->pUserLineCoding = linecoding;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_CLASS_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif
#endif
}
return USBH_OK;
}
/**
* @brief This function prepares the state before issuing the class specific commands
* @param None
* @retval None
*/
USBH_StatusTypeDef USBH_CDC_GetLineCoding(USBH_HandleTypeDef *phost,
CDC_LineCodingTypeDef *linecoding)
{
CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData;
if ((phost->gState == HOST_CLASS) || (phost->gState == HOST_CLASS_REQUEST))
{
*linecoding = CDC_Handle->LineCoding;
return USBH_OK;
}
else
{
return USBH_FAIL;
}
}
/**
* @brief This function return last received data size
* @param None
* @retval None
*/
uint16_t USBH_CDC_GetLastReceivedDataSize(USBH_HandleTypeDef *phost)
{
uint32_t dataSize;
CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData;
if (phost->gState == HOST_CLASS)
{
dataSize = USBH_LL_GetLastXferSize(phost, CDC_Handle->DataItf.InPipe);
}
else
{
dataSize = 0U;
}
return (uint16_t)dataSize;
}
/**
* @brief This function prepares the state before issuing the class specific commands
* @param None
* @retval None
*/
USBH_StatusTypeDef USBH_CDC_Transmit(USBH_HandleTypeDef *phost, uint8_t *pbuff, uint32_t length)
{
USBH_StatusTypeDef Status = USBH_BUSY;
CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData;
if ((CDC_Handle->state == CDC_IDLE_STATE) || (CDC_Handle->state == CDC_TRANSFER_DATA))
{
CDC_Handle->pTxData = pbuff;
CDC_Handle->TxDataLength = length;
CDC_Handle->state = CDC_TRANSFER_DATA;
CDC_Handle->data_tx_state = CDC_SEND_DATA;
Status = USBH_OK;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_CLASS_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif
#endif
}
return Status;
}
/**
* @brief This function prepares the state before issuing the class specific commands
* @param None
* @retval None
*/
USBH_StatusTypeDef USBH_CDC_Receive(USBH_HandleTypeDef *phost, uint8_t *pbuff, uint32_t length)
{
USBH_StatusTypeDef Status = USBH_BUSY;
CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData;
if ((CDC_Handle->state == CDC_IDLE_STATE) || (CDC_Handle->state == CDC_TRANSFER_DATA))
{
CDC_Handle->pRxData = pbuff;
CDC_Handle->RxDataLength = length;
CDC_Handle->state = CDC_TRANSFER_DATA;
CDC_Handle->data_rx_state = CDC_RECEIVE_DATA;
Status = USBH_OK;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_CLASS_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif
#endif
}
return Status;
}
/**
* @brief The function is responsible for sending data to the device
* @param pdev: Selected device
* @retval None
*/
static void CDC_ProcessTransmission(USBH_HandleTypeDef *phost)
{
CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData;
USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE;
switch (CDC_Handle->data_tx_state)
{
case CDC_SEND_DATA:
if (CDC_Handle->TxDataLength > CDC_Handle->DataItf.OutEpSize)
{
(void)USBH_BulkSendData(phost,
CDC_Handle->pTxData,
CDC_Handle->DataItf.OutEpSize,
CDC_Handle->DataItf.OutPipe,
1U);
}
else
{
(void)USBH_BulkSendData(phost,
CDC_Handle->pTxData,
(uint16_t)CDC_Handle->TxDataLength,
CDC_Handle->DataItf.OutPipe,
1U);
}
CDC_Handle->data_tx_state = CDC_SEND_DATA_WAIT;
break;
case CDC_SEND_DATA_WAIT:
URB_Status = USBH_LL_GetURBState(phost, CDC_Handle->DataItf.OutPipe);
/* Check the status done for transmission */
if (URB_Status == USBH_URB_DONE)
{
if (CDC_Handle->TxDataLength > CDC_Handle->DataItf.OutEpSize)
{
CDC_Handle->TxDataLength -= CDC_Handle->DataItf.OutEpSize;
CDC_Handle->pTxData += CDC_Handle->DataItf.OutEpSize;
}
else
{
CDC_Handle->TxDataLength = 0U;
}
if (CDC_Handle->TxDataLength > 0U)
{
CDC_Handle->data_tx_state = CDC_SEND_DATA;
}
else
{
CDC_Handle->data_tx_state = CDC_IDLE;
USBH_CDC_TransmitCallback(phost);
}
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_CLASS_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif
#endif
}
else
{
if (URB_Status == USBH_URB_NOTREADY)
{
CDC_Handle->data_tx_state = CDC_SEND_DATA;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_CLASS_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif
#endif
}
}
break;
default:
break;
}
}
/**
* @brief This function responsible for reception of data from the device
* @param pdev: Selected device
* @retval None
*/
static void CDC_ProcessReception(USBH_HandleTypeDef *phost)
{
CDC_HandleTypeDef *CDC_Handle = (CDC_HandleTypeDef *) phost->pActiveClass->pData;
USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE;
uint32_t length;
switch (CDC_Handle->data_rx_state)
{
case CDC_RECEIVE_DATA:
(void)USBH_BulkReceiveData(phost,
CDC_Handle->pRxData,
CDC_Handle->DataItf.InEpSize,
CDC_Handle->DataItf.InPipe);
CDC_Handle->data_rx_state = CDC_RECEIVE_DATA_WAIT;
break;
case CDC_RECEIVE_DATA_WAIT:
URB_Status = USBH_LL_GetURBState(phost, CDC_Handle->DataItf.InPipe);
/*Check the status done for reception*/
if (URB_Status == USBH_URB_DONE)
{
length = USBH_LL_GetLastXferSize(phost, CDC_Handle->DataItf.InPipe);
if (((CDC_Handle->RxDataLength - length) > 0U) && (length > CDC_Handle->DataItf.InEpSize))
{
CDC_Handle->RxDataLength -= length ;
CDC_Handle->pRxData += length;
CDC_Handle->data_rx_state = CDC_RECEIVE_DATA;
}
else
{
CDC_Handle->data_rx_state = CDC_IDLE;
USBH_CDC_ReceiveCallback(phost);
}
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_CLASS_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif
#endif
}
break;
default:
break;
}
}
/**
* @brief The function informs user that data have been received
* @param pdev: Selected device
* @retval None
*/
__weak void USBH_CDC_TransmitCallback(USBH_HandleTypeDef *phost)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(phost);
}
/**
* @brief The function informs user that data have been sent
* @param pdev: Selected device
* @retval None
*/
__weak void USBH_CDC_ReceiveCallback(USBH_HandleTypeDef *phost)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(phost);
}
/**
* @brief The function informs user that Settings have been changed
* @param pdev: Selected device
* @retval None
*/
__weak void USBH_CDC_LineCodingChanged(USBH_HandleTypeDef *phost)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(phost);
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,192 @@
/**
******************************************************************************
* @file usbh_core.h
* @author MCD Application Team
* @brief Header file for usbh_core.c
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2015 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Define to prevent recursive ----------------------------------------------*/
#ifndef __USBH_CORE_H
#define __USBH_CORE_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "usbh_conf.h"
#include "usbh_def.h"
#include "usbh_ioreq.h"
#include "usbh_pipes.h"
#include "usbh_ctlreq.h"
/** @addtogroup USBH_LIB
* @{
*/
/** @addtogroup USBH_LIB_CORE
* @{
*/
/** @defgroup USBH_CORE
* @brief This file is the Header file for usbh_core.c
* @{
*/
/** @defgroup USBH_CORE_Exported_Defines
* @{
*/
/**
* @}
*/
#define HOST_USER_SELECT_CONFIGURATION 0x01U
#define HOST_USER_CLASS_ACTIVE 0x02U
#define HOST_USER_CLASS_SELECTED 0x03U
#define HOST_USER_CONNECTION 0x04U
#define HOST_USER_DISCONNECTION 0x05U
#define HOST_USER_UNRECOVERED_ERROR 0x06U
/**
* @}
*/
/** @defgroup USBH_CORE_Exported_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USBH_CORE_Exported_Variables
* @{
*/
/**
* @}
*/
/** @defgroup USBH_CORE_Exported_FunctionsPrototype
* @{
*/
USBH_StatusTypeDef USBH_Init(USBH_HandleTypeDef *phost, void (*pUsrFunc)(USBH_HandleTypeDef *phost, uint8_t id), uint8_t id);
USBH_StatusTypeDef USBH_DeInit(USBH_HandleTypeDef *phost);
USBH_StatusTypeDef USBH_RegisterClass(USBH_HandleTypeDef *phost, USBH_ClassTypeDef *pclass);
USBH_StatusTypeDef USBH_SelectInterface(USBH_HandleTypeDef *phost, uint8_t interface);
uint8_t USBH_FindInterface(USBH_HandleTypeDef *phost,
uint8_t Class,
uint8_t SubClass,
uint8_t Protocol);
uint8_t USBH_GetActiveClass(USBH_HandleTypeDef *phost);
uint8_t USBH_FindInterfaceIndex(USBH_HandleTypeDef *phost,
uint8_t interface_number,
uint8_t alt_settings);
uint8_t USBH_IsPortEnabled(USBH_HandleTypeDef *phost);
USBH_StatusTypeDef USBH_Start(USBH_HandleTypeDef *phost);
USBH_StatusTypeDef USBH_Stop(USBH_HandleTypeDef *phost);
USBH_StatusTypeDef USBH_Process(USBH_HandleTypeDef *phost);
USBH_StatusTypeDef USBH_ReEnumerate(USBH_HandleTypeDef *phost);
/* USBH Low Level Driver */
USBH_StatusTypeDef USBH_LL_Init(USBH_HandleTypeDef *phost);
USBH_StatusTypeDef USBH_LL_DeInit(USBH_HandleTypeDef *phost);
USBH_StatusTypeDef USBH_LL_Start(USBH_HandleTypeDef *phost);
USBH_StatusTypeDef USBH_LL_Stop(USBH_HandleTypeDef *phost);
USBH_StatusTypeDef USBH_LL_Connect(USBH_HandleTypeDef *phost);
USBH_StatusTypeDef USBH_LL_Disconnect(USBH_HandleTypeDef *phost);
USBH_SpeedTypeDef USBH_LL_GetSpeed(USBH_HandleTypeDef *phost);
USBH_StatusTypeDef USBH_LL_ResetPort(USBH_HandleTypeDef *phost);
uint32_t USBH_LL_GetLastXferSize(USBH_HandleTypeDef *phost,
uint8_t pipe);
USBH_StatusTypeDef USBH_LL_DriverVBUS(USBH_HandleTypeDef *phost,
uint8_t state);
USBH_StatusTypeDef USBH_LL_OpenPipe(USBH_HandleTypeDef *phost,
uint8_t pipe,
uint8_t epnum,
uint8_t dev_address,
uint8_t speed,
uint8_t ep_type,
uint16_t mps);
USBH_StatusTypeDef USBH_LL_ClosePipe(USBH_HandleTypeDef *phost,
uint8_t pipe);
USBH_StatusTypeDef USBH_LL_SubmitURB(USBH_HandleTypeDef *phost,
uint8_t pipe,
uint8_t direction,
uint8_t ep_type,
uint8_t token,
uint8_t *pbuff,
uint16_t length,
uint8_t do_ping);
USBH_URBStateTypeDef USBH_LL_GetURBState(USBH_HandleTypeDef *phost,
uint8_t pipe);
#if (USBH_USE_OS == 1U)
USBH_StatusTypeDef USBH_LL_NotifyURBChange(USBH_HandleTypeDef *phost);
#endif
USBH_StatusTypeDef USBH_LL_SetToggle(USBH_HandleTypeDef *phost,
uint8_t pipe, uint8_t toggle);
uint8_t USBH_LL_GetToggle(USBH_HandleTypeDef *phost, uint8_t pipe);
void USBH_LL_PortDisabled(USBH_HandleTypeDef *phost);
void USBH_LL_PortEnabled(USBH_HandleTypeDef *phost);
/* USBH Time base */
void USBH_LL_SetTimer(USBH_HandleTypeDef *phost, uint32_t time);
void USBH_LL_IncTimer(USBH_HandleTypeDef *phost);
void USBH_Delay(uint32_t Delay);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __USBH_CORE_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,141 @@
/**
******************************************************************************
* @file usbh_ctlreq.h
* @author MCD Application Team
* @brief Header file for usbh_ctlreq.c
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2015 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Define to prevent recursive ----------------------------------------------*/
#ifndef __USBH_CTLREQ_H
#define __USBH_CTLREQ_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "usbh_core.h"
/** @addtogroup USBH_LIB
* @{
*/
/** @addtogroup USBH_LIB_CORE
* @{
*/
/** @defgroup USBH_CTLREQ
* @brief This file is the
* @{
*/
/** @defgroup USBH_CTLREQ_Exported_Defines
* @{
*/
/*Standard Feature Selector for clear feature command*/
#define FEATURE_SELECTOR_ENDPOINT 0x00U
#define FEATURE_SELECTOR_DEVICE 0x01U
#define FEATURE_SELECTOR_REMOTEWAKEUP 0X01U
#define INTERFACE_DESC_TYPE 0x04U
#define ENDPOINT_DESC_TYPE 0x05U
#define INTERFACE_DESC_SIZE 0x09U
/**
* @}
*/
/** @defgroup USBH_CTLREQ_Exported_Types
* @{
*/
/**
* @}
*/
/** @defgroup USBH_CTLREQ_Exported_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USBH_CTLREQ_Exported_Variables
* @{
*/
extern uint8_t USBH_CfgDesc[512];
/**
* @}
*/
/** @defgroup USBH_CTLREQ_Exported_FunctionsPrototype
* @{
*/
USBH_StatusTypeDef USBH_CtlReq(USBH_HandleTypeDef *phost, uint8_t *buff,
uint16_t length);
USBH_StatusTypeDef USBH_GetDescriptor(USBH_HandleTypeDef *phost,
uint8_t req_type, uint16_t value_idx,
uint8_t *buff, uint16_t length);
USBH_StatusTypeDef USBH_Get_DevDesc(USBH_HandleTypeDef *phost, uint8_t length);
USBH_StatusTypeDef USBH_Get_StringDesc(USBH_HandleTypeDef *phost,
uint8_t string_index, uint8_t *buff,
uint16_t length);
USBH_StatusTypeDef USBH_SetCfg(USBH_HandleTypeDef *phost, uint16_t cfg_idx);
USBH_StatusTypeDef USBH_Get_CfgDesc(USBH_HandleTypeDef *phost, uint16_t length);
USBH_StatusTypeDef USBH_SetAddress(USBH_HandleTypeDef *phost,
uint8_t DeviceAddress);
USBH_StatusTypeDef USBH_SetInterface(USBH_HandleTypeDef *phost, uint8_t ep_num,
uint8_t altSetting);
USBH_StatusTypeDef USBH_SetFeature(USBH_HandleTypeDef *phost, uint8_t wValue);
USBH_StatusTypeDef USBH_ClrFeature(USBH_HandleTypeDef *phost, uint8_t ep_num);
USBH_DescHeader_t *USBH_GetNextDesc(uint8_t *pbuf, uint16_t *ptr);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __USBH_CTLREQ_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,512 @@
/**
******************************************************************************
* @file usbh_def.h
* @author MCD Application Team
* @brief Definitions used in the USB host library
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2015 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Define to prevent recursive ----------------------------------------------*/
#ifndef USBH_DEF_H
#define USBH_DEF_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "usbh_conf.h"
/** @addtogroup USBH_LIB
* @{
*/
/** @addtogroup USBH_LIB_CORE
* @{
*/
/** @defgroup USBH_DEF
* @brief This file is includes USB descriptors
* @{
*/
#ifndef NULL
#define NULL 0U
#endif
#ifndef FALSE
#define FALSE 0U
#endif
#ifndef TRUE
#define TRUE 1U
#endif
#ifndef USBH_DEV_RESET_TIMEOUT
#define USBH_DEV_RESET_TIMEOUT 1000U
#endif
#define ValBit(VAR,POS) (VAR & (1 << POS))
#define SetBit(VAR,POS) (VAR |= (1 << POS))
#define ClrBit(VAR,POS) (VAR &= ((1 << POS)^255))
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
#define LE16(addr) (((uint16_t)(addr)[0]) | \
((uint16_t)(((uint32_t)(addr)[1]) << 8)))
#define LE24(addr) (((uint32_t)(addr)[0]) | \
(((uint32_t)(addr)[1]) << 8) | \
(((uint32_t)(addr)[2]) << 16))
#define LE32(addr) (((uint32_t)(addr)[0]) | \
(((uint32_t)(addr)[1]) << 8) | \
(((uint32_t)(addr)[2]) << 16) | \
(((uint32_t)(addr)[3]) << 24))
#define LE64(addr) (((uint64_t)(addr)[0]) | \
(((uint64_t)(addr)[1]) << 8) | \
(((uint64_t)(addr)[2]) << 16) | \
(((uint64_t)(addr)[3]) << 24) | \
(((uint64_t)(addr)[4]) << 32) | \
(((uint64_t)(addr)[5]) << 40) | \
(((uint64_t)(addr)[6]) << 48) | \
(((uint64_t)(addr)[7]) << 56))
#define LE16S(addr) ((int16_t)(LE16((addr))))
#define LE24S(addr) ((int32_t)(LE24((addr))))
#define LE32S(addr) ((int32_t)(LE32((addr))))
#define LE64S(addr) ((int64_t)(LE64((addr))))
#ifndef USBH_MAX_DATA_BUFFER
#define USBH_MAX_DATA_BUFFER 0x400U
#endif
#define USBH_MAX_EP_PACKET_SIZE 0x400U
#define USB_LEN_DESC_HDR 0x02U
#define USB_LEN_DEV_DESC 0x12U
#define USB_LEN_CFG_DESC 0x09U
#define USB_LEN_IF_DESC 0x09U
#define USB_LEN_EP_DESC 0x07U
#define USB_LEN_OTG_DESC 0x03U
#define USB_LEN_SETUP_PKT 0x08U
/* bmRequestType :D7 Data Phase Transfer Direction */
#define USB_REQ_DIR_MASK 0x80U
#define USB_H2D 0x00U
#define USB_D2H 0x80U
/* bmRequestType D6..5 Type */
#define USB_REQ_TYPE_STANDARD 0x00U
#define USB_REQ_TYPE_CLASS 0x20U
#define USB_REQ_TYPE_VENDOR 0x40U
#define USB_REQ_TYPE_RESERVED 0x60U
/* bmRequestType D4..0 Recipient */
#define USB_REQ_RECIPIENT_DEVICE 0x00U
#define USB_REQ_RECIPIENT_INTERFACE 0x01U
#define USB_REQ_RECIPIENT_ENDPOINT 0x02U
#define USB_REQ_RECIPIENT_OTHER 0x03U
/* Table 9-4. Standard Request Codes */
/* bRequest , Value */
#define USB_REQ_GET_STATUS 0x00U
#define USB_REQ_CLEAR_FEATURE 0x01U
#define USB_REQ_SET_FEATURE 0x03U
#define USB_REQ_SET_ADDRESS 0x05U
#define USB_REQ_GET_DESCRIPTOR 0x06U
#define USB_REQ_SET_DESCRIPTOR 0x07U
#define USB_REQ_GET_CONFIGURATION 0x08U
#define USB_REQ_SET_CONFIGURATION 0x09U
#define USB_REQ_GET_INTERFACE 0x0AU
#define USB_REQ_SET_INTERFACE 0x0BU
#define USB_REQ_SYNCH_FRAME 0x0CU
/* Table 9-5. Descriptor Types of USB Specifications */
#define USB_DESC_TYPE_DEVICE 0x01U
#define USB_DESC_TYPE_CONFIGURATION 0x02U
#define USB_DESC_TYPE_STRING 0x03U
#define USB_DESC_TYPE_INTERFACE 0x04U
#define USB_DESC_TYPE_ENDPOINT 0x05U
#define USB_DESC_TYPE_DEVICE_QUALIFIER 0x06U
#define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 0x07U
#define USB_DESC_TYPE_INTERFACE_POWER 0x08U
#define USB_DESC_TYPE_HID 0x21U
#define USB_DESC_TYPE_HID_REPORT 0x22U
#define USB_DEVICE_DESC_SIZE 0x12U
#define USB_CONFIGURATION_DESC_SIZE 0x09U
#define USB_HID_DESC_SIZE 0x09U
#define USB_INTERFACE_DESC_SIZE 0x09U
#define USB_ENDPOINT_DESC_SIZE 0x07U
/* Descriptor Type and Descriptor Index */
/* Use the following values when calling the function USBH_GetDescriptor */
#define USB_DESC_DEVICE ((USB_DESC_TYPE_DEVICE << 8) & 0xFF00U)
#define USB_DESC_CONFIGURATION ((USB_DESC_TYPE_CONFIGURATION << 8) & 0xFF00U)
#define USB_DESC_STRING ((USB_DESC_TYPE_STRING << 8) & 0xFF00U)
#define USB_DESC_INTERFACE ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00U)
#define USB_DESC_ENDPOINT ((USB_DESC_TYPE_INTERFACE << 8) & 0xFF00U)
#define USB_DESC_DEVICE_QUALIFIER ((USB_DESC_TYPE_DEVICE_QUALIFIER << 8) & 0xFF00U)
#define USB_DESC_OTHER_SPEED_CONFIGURATION ((USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION << 8) & 0xFF00U)
#define USB_DESC_INTERFACE_POWER ((USB_DESC_TYPE_INTERFACE_POWER << 8) & 0xFF00U)
#define USB_DESC_HID_REPORT ((USB_DESC_TYPE_HID_REPORT << 8) & 0xFF00U)
#define USB_DESC_HID ((USB_DESC_TYPE_HID << 8) & 0xFF00U)
#define USB_EP_TYPE_CTRL 0x00U
#define USB_EP_TYPE_ISOC 0x01U
#define USB_EP_TYPE_BULK 0x02U
#define USB_EP_TYPE_INTR 0x03U
#define USB_EP_DIR_OUT 0x00U
#define USB_EP_DIR_IN 0x80U
#define USB_EP_DIR_MSK 0x80U
#ifndef USBH_MAX_PIPES_NBR
#define USBH_MAX_PIPES_NBR 16U
#endif /* USBH_MAX_PIPES_NBR */
#define USBH_DEVICE_ADDRESS_DEFAULT 0x00U
#define USBH_DEVICE_ADDRESS 0x01U
#define USBH_MAX_ERROR_COUNT 0x02U
#if (USBH_USE_OS == 1U)
#define MSGQUEUE_OBJECTS 0x10U
#endif
/**
* @}
*/
#define USBH_CONFIGURATION_DESCRIPTOR_SIZE (USB_CONFIGURATION_DESC_SIZE \
+ USB_INTERFACE_DESC_SIZE\
+ (USBH_MAX_NUM_ENDPOINTS * USB_ENDPOINT_DESC_SIZE))
#define CONFIG_DESC_wTOTAL_LENGTH (ConfigurationDescriptorData.ConfigDescfield.\
ConfigurationDescriptor.wTotalLength)
typedef union
{
uint16_t w;
struct BW
{
uint8_t msb;
uint8_t lsb;
}
bw;
}
uint16_t_uint8_t;
typedef union _USB_Setup
{
uint32_t d8[2];
struct _SetupPkt_Struc
{
uint8_t bmRequestType;
uint8_t bRequest;
uint16_t_uint8_t wValue;
uint16_t_uint8_t wIndex;
uint16_t_uint8_t wLength;
} b;
}
USB_Setup_TypeDef;
typedef struct _DescHeader
{
uint8_t bLength;
uint8_t bDescriptorType;
}
USBH_DescHeader_t;
typedef struct _DeviceDescriptor
{
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t bcdUSB; /* USB Specification Number which device complies too */
uint8_t bDeviceClass;
uint8_t bDeviceSubClass;
uint8_t bDeviceProtocol;
/* If equal to Zero, each interface specifies its own class
code if equal to 0xFF, the class code is vendor specified.
Otherwise field is valid Class Code.*/
uint8_t bMaxPacketSize;
uint16_t idVendor; /* Vendor ID (Assigned by USB Org) */
uint16_t idProduct; /* Product ID (Assigned by Manufacturer) */
uint16_t bcdDevice; /* Device Release Number */
uint8_t iManufacturer; /* Index of Manufacturer String Descriptor */
uint8_t iProduct; /* Index of Product String Descriptor */
uint8_t iSerialNumber; /* Index of Serial Number String Descriptor */
uint8_t bNumConfigurations; /* Number of Possible Configurations */
}
USBH_DevDescTypeDef;
typedef struct _EndpointDescriptor
{
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bEndpointAddress; /* indicates what endpoint this descriptor is describing */
uint8_t bmAttributes; /* specifies the transfer type. */
uint16_t wMaxPacketSize; /* Maximum Packet Size this endpoint is capable of sending or receiving */
uint8_t bInterval; /* is used to specify the polling interval of certain transfers. */
}
USBH_EpDescTypeDef;
typedef struct _InterfaceDescriptor
{
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bInterfaceNumber;
uint8_t bAlternateSetting; /* Value used to select alternative setting */
uint8_t bNumEndpoints; /* Number of Endpoints used for this interface */
uint8_t bInterfaceClass; /* Class Code (Assigned by USB Org) */
uint8_t bInterfaceSubClass; /* Subclass Code (Assigned by USB Org) */
uint8_t bInterfaceProtocol; /* Protocol Code */
uint8_t iInterface; /* Index of String Descriptor Describing this interface */
USBH_EpDescTypeDef Ep_Desc[USBH_MAX_NUM_ENDPOINTS];
}
USBH_InterfaceDescTypeDef;
typedef struct _ConfigurationDescriptor
{
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t wTotalLength; /* Total Length of Data Returned */
uint8_t bNumInterfaces; /* Number of Interfaces */
uint8_t bConfigurationValue; /* Value to use as an argument to select this configuration*/
uint8_t iConfiguration; /*Index of String Descriptor Describing this configuration */
uint8_t bmAttributes; /* D7 Bus Powered , D6 Self Powered, D5 Remote Wakeup , D4..0 Reserved (0)*/
uint8_t bMaxPower; /*Maximum Power Consumption */
USBH_InterfaceDescTypeDef Itf_Desc[USBH_MAX_NUM_INTERFACES];
}
USBH_CfgDescTypeDef;
/* Following USB Host status */
typedef enum
{
USBH_OK = 0,
USBH_BUSY,
USBH_FAIL,
USBH_NOT_SUPPORTED,
USBH_UNRECOVERED_ERROR,
USBH_ERROR_SPEED_UNKNOWN,
} USBH_StatusTypeDef;
/** @defgroup USBH_CORE_Exported_Types
* @{
*/
typedef enum
{
USBH_SPEED_HIGH = 0U,
USBH_SPEED_FULL = 1U,
USBH_SPEED_LOW = 2U,
} USBH_SpeedTypeDef;
/* Following states are used for gState */
typedef enum
{
HOST_IDLE = 0U,
HOST_DEV_WAIT_FOR_ATTACHMENT,
HOST_DEV_ATTACHED,
HOST_DEV_DISCONNECTED,
HOST_DETECT_DEVICE_SPEED,
HOST_ENUMERATION,
HOST_CLASS_REQUEST,
HOST_INPUT,
HOST_SET_CONFIGURATION,
HOST_SET_WAKEUP_FEATURE,
HOST_CHECK_CLASS,
HOST_CLASS,
HOST_SUSPENDED,
HOST_ABORT_STATE,
} HOST_StateTypeDef;
/* Following states are used for EnumerationState */
typedef enum
{
ENUM_IDLE = 0U,
ENUM_GET_FULL_DEV_DESC,
ENUM_SET_ADDR,
ENUM_GET_CFG_DESC,
ENUM_GET_FULL_CFG_DESC,
ENUM_GET_MFC_STRING_DESC,
ENUM_GET_PRODUCT_STRING_DESC,
ENUM_GET_SERIALNUM_STRING_DESC,
} ENUM_StateTypeDef;
/* Following states are used for CtrlXferStateMachine */
typedef enum
{
CTRL_IDLE = 0U,
CTRL_SETUP,
CTRL_SETUP_WAIT,
CTRL_DATA_IN,
CTRL_DATA_IN_WAIT,
CTRL_DATA_OUT,
CTRL_DATA_OUT_WAIT,
CTRL_STATUS_IN,
CTRL_STATUS_IN_WAIT,
CTRL_STATUS_OUT,
CTRL_STATUS_OUT_WAIT,
CTRL_ERROR,
CTRL_STALLED,
CTRL_COMPLETE
} CTRL_StateTypeDef;
/* Following states are used for RequestState */
typedef enum
{
CMD_IDLE = 0U,
CMD_SEND,
CMD_WAIT
} CMD_StateTypeDef;
typedef enum
{
USBH_URB_IDLE = 0U,
USBH_URB_DONE,
USBH_URB_NOTREADY,
USBH_URB_NYET,
USBH_URB_ERROR,
USBH_URB_STALL
} USBH_URBStateTypeDef;
typedef enum
{
USBH_PORT_EVENT = 1U,
USBH_URB_EVENT,
USBH_CONTROL_EVENT,
USBH_CLASS_EVENT,
USBH_STATE_CHANGED_EVENT,
}
USBH_OSEventTypeDef;
/* Control request structure */
typedef struct
{
uint8_t pipe_in;
uint8_t pipe_out;
uint8_t pipe_size;
uint8_t *buff;
uint16_t length;
uint16_t timer;
USB_Setup_TypeDef setup;
CTRL_StateTypeDef state;
uint8_t errorcount;
} USBH_CtrlTypeDef;
/* Attached device structure */
typedef struct
{
uint8_t CfgDesc_Raw[USBH_MAX_SIZE_CONFIGURATION];
uint8_t Data[USBH_MAX_DATA_BUFFER];
uint8_t address;
uint8_t speed;
uint8_t EnumCnt;
uint8_t RstCnt;
__IO uint8_t is_connected;
__IO uint8_t is_disconnected;
__IO uint8_t is_ReEnumerated;
uint8_t PortEnabled;
uint8_t current_interface;
USBH_DevDescTypeDef DevDesc;
USBH_CfgDescTypeDef CfgDesc;
} USBH_DeviceTypeDef;
struct _USBH_HandleTypeDef;
/* USB Host Class structure */
typedef struct
{
const char *Name;
uint8_t ClassCode;
USBH_StatusTypeDef(*Init)(struct _USBH_HandleTypeDef *phost);
USBH_StatusTypeDef(*DeInit)(struct _USBH_HandleTypeDef *phost);
USBH_StatusTypeDef(*Requests)(struct _USBH_HandleTypeDef *phost);
USBH_StatusTypeDef(*BgndProcess)(struct _USBH_HandleTypeDef *phost);
USBH_StatusTypeDef(*SOFProcess)(struct _USBH_HandleTypeDef *phost);
void *pData;
} USBH_ClassTypeDef;
/* USB Host handle structure */
typedef struct _USBH_HandleTypeDef
{
__IO HOST_StateTypeDef gState; /* Host State Machine Value */
ENUM_StateTypeDef EnumState; /* Enumeration state Machine */
CMD_StateTypeDef RequestState;
USBH_CtrlTypeDef Control;
USBH_DeviceTypeDef device;
USBH_ClassTypeDef *pClass[USBH_MAX_NUM_SUPPORTED_CLASS];
USBH_ClassTypeDef *pActiveClass;
uint32_t ClassNumber;
uint32_t Pipes[16];
__IO uint32_t Timer;
uint32_t Timeout;
uint8_t id;
void *pData;
void (* pUser)(struct _USBH_HandleTypeDef *pHandle, uint8_t id);
#if (USBH_USE_OS == 1U)
#if osCMSIS < 0x20000
osMessageQId os_event;
osThreadId thread;
#else
osMessageQueueId_t os_event;
osThreadId_t thread;
#endif
uint32_t os_msg;
#endif
} USBH_HandleTypeDef;
#if defined ( __GNUC__ )
#ifndef __weak
#define __weak __attribute__((weak))
#endif /* __weak */
#ifndef __packed
#define __packed __attribute__((__packed__))
#endif /* __packed */
#endif /* __GNUC__ */
#ifdef __cplusplus
}
#endif
#endif /* USBH_DEF_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,160 @@
/**
******************************************************************************
* @file usbh_ioreq.h
* @author MCD Application Team
* @brief Header file for usbh_ioreq.c
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2015 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Define to prevent recursive ----------------------------------------------*/
#ifndef __USBH_IOREQ_H
#define __USBH_IOREQ_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "usbh_conf.h"
#include "usbh_core.h"
/** @addtogroup USBH_LIB
* @{
*/
/** @addtogroup USBH_LIB_CORE
* @{
*/
/** @defgroup USBH_IOREQ
* @brief This file is the header file for usbh_ioreq.c
* @{
*/
/** @defgroup USBH_IOREQ_Exported_Defines
* @{
*/
#define USBH_PID_SETUP 0U
#define USBH_PID_DATA 1U
#define USBH_EP_CONTROL 0U
#define USBH_EP_ISO 1U
#define USBH_EP_BULK 2U
#define USBH_EP_INTERRUPT 3U
#define USBH_SETUP_PKT_SIZE 8U
/**
* @}
*/
/** @defgroup USBH_IOREQ_Exported_Types
* @{
*/
/**
* @}
*/
/** @defgroup USBH_IOREQ_Exported_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USBH_IOREQ_Exported_Variables
* @{
*/
/**
* @}
*/
/** @defgroup USBH_IOREQ_Exported_FunctionsPrototype
* @{
*/
USBH_StatusTypeDef USBH_CtlSendSetup(USBH_HandleTypeDef *phost,
uint8_t *buff,
uint8_t pipe_num);
USBH_StatusTypeDef USBH_CtlSendData(USBH_HandleTypeDef *phost,
uint8_t *buff,
uint16_t length,
uint8_t pipe_num,
uint8_t do_ping);
USBH_StatusTypeDef USBH_CtlReceiveData(USBH_HandleTypeDef *phost,
uint8_t *buff,
uint16_t length,
uint8_t pipe_num);
USBH_StatusTypeDef USBH_BulkReceiveData(USBH_HandleTypeDef *phost,
uint8_t *buff,
uint16_t length,
uint8_t pipe_num);
USBH_StatusTypeDef USBH_BulkSendData(USBH_HandleTypeDef *phost,
uint8_t *buff,
uint16_t length,
uint8_t pipe_num,
uint8_t do_ping);
USBH_StatusTypeDef USBH_InterruptReceiveData(USBH_HandleTypeDef *phost,
uint8_t *buff,
uint8_t length,
uint8_t pipe_num);
USBH_StatusTypeDef USBH_InterruptSendData(USBH_HandleTypeDef *phost,
uint8_t *buff,
uint8_t length,
uint8_t pipe_num);
USBH_StatusTypeDef USBH_IsocReceiveData(USBH_HandleTypeDef *phost,
uint8_t *buff,
uint32_t length,
uint8_t pipe_num);
USBH_StatusTypeDef USBH_IsocSendData(USBH_HandleTypeDef *phost,
uint8_t *buff,
uint32_t length,
uint8_t pipe_num);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __USBH_IOREQ_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,123 @@
/**
******************************************************************************
* @file usbh_pipes.h
* @author MCD Application Team
* @brief Header file for usbh_pipes.c
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2015 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Define to prevent recursive ----------------------------------------------*/
#ifndef __USBH_PIPES_H
#define __USBH_PIPES_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "usbh_core.h"
/** @addtogroup USBH_LIB
* @{
*/
/** @addtogroup USBH_LIB_CORE
* @{
*/
/** @defgroup USBH_PIPES
* @brief This file is the header file for usbh_pipes.c
* @{
*/
/** @defgroup USBH_PIPES_Exported_Defines
* @{
*/
/**
* @}
*/
/** @defgroup USBH_PIPES_Exported_Types
* @{
*/
/**
* @}
*/
/** @defgroup USBH_PIPES_Exported_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USBH_PIPES_Exported_Variables
* @{
*/
/**
* @}
*/
/** @defgroup USBH_PIPES_Exported_FunctionsPrototype
* @{
*/
USBH_StatusTypeDef USBH_OpenPipe(USBH_HandleTypeDef *phost,
uint8_t pipe_num,
uint8_t epnum,
uint8_t dev_address,
uint8_t speed,
uint8_t ep_type,
uint16_t mps);
USBH_StatusTypeDef USBH_ClosePipe(USBH_HandleTypeDef *phost,
uint8_t pipe_num);
uint8_t USBH_AllocPipe(USBH_HandleTypeDef *phost,
uint8_t ep_addr);
USBH_StatusTypeDef USBH_FreePipe(USBH_HandleTypeDef *phost,
uint8_t idx);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __USBH_PIPES_H */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,350 @@
/**
******************************************************************************
* @file usbh_ioreq.c
* @author MCD Application Team
* @brief This file handles the issuing of the USB transactions
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2015 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "usbh_ioreq.h"
/** @addtogroup USBH_LIB
* @{
*/
/** @addtogroup USBH_LIB_CORE
* @{
*/
/** @defgroup USBH_IOREQ
* @brief This file handles the standard protocol processing (USB v2.0)
* @{
*/
/** @defgroup USBH_IOREQ_Private_Defines
* @{
*/
/**
* @}
*/
/** @defgroup USBH_IOREQ_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup USBH_IOREQ_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USBH_IOREQ_Private_Variables
* @{
*/
/**
* @}
*/
/** @defgroup USBH_IOREQ_Private_FunctionPrototypes
* @{
*/
/**
* @}
*/
/** @defgroup USBH_IOREQ_Private_Functions
* @{
*/
/**
* @brief USBH_CtlSendSetup
* Sends the Setup Packet to the Device
* @param phost: Host Handle
* @param buff: Buffer pointer from which the Data will be send to Device
* @param pipe_num: Pipe Number
* @retval USBH Status
*/
USBH_StatusTypeDef USBH_CtlSendSetup(USBH_HandleTypeDef *phost,
uint8_t *buff,
uint8_t pipe_num)
{
(void)USBH_LL_SubmitURB(phost, /* Driver handle */
pipe_num, /* Pipe index */
0U, /* Direction : OUT */
USBH_EP_CONTROL, /* EP type */
USBH_PID_SETUP, /* Type setup */
buff, /* data buffer */
USBH_SETUP_PKT_SIZE, /* data length */
0U);
return USBH_OK;
}
/**
* @brief USBH_CtlSendData
* Sends a data Packet to the Device
* @param phost: Host Handle
* @param buff: Buffer pointer from which the Data will be sent to Device
* @param length: Length of the data to be sent
* @param pipe_num: Pipe Number
* @retval USBH Status
*/
USBH_StatusTypeDef USBH_CtlSendData(USBH_HandleTypeDef *phost,
uint8_t *buff,
uint16_t length,
uint8_t pipe_num,
uint8_t do_ping)
{
if (phost->device.speed != USBH_SPEED_HIGH)
{
do_ping = 0U;
}
(void)USBH_LL_SubmitURB(phost, /* Driver handle */
pipe_num, /* Pipe index */
0U, /* Direction : OUT */
USBH_EP_CONTROL, /* EP type */
USBH_PID_DATA, /* Type Data */
buff, /* data buffer */
length, /* data length */
do_ping); /* do ping (HS Only)*/
return USBH_OK;
}
/**
* @brief USBH_CtlReceiveData
* Receives the Device Response to the Setup Packet
* @param phost: Host Handle
* @param buff: Buffer pointer in which the response needs to be copied
* @param length: Length of the data to be received
* @param pipe_num: Pipe Number
* @retval USBH Status.
*/
USBH_StatusTypeDef USBH_CtlReceiveData(USBH_HandleTypeDef *phost,
uint8_t *buff,
uint16_t length,
uint8_t pipe_num)
{
(void)USBH_LL_SubmitURB(phost, /* Driver handle */
pipe_num, /* Pipe index */
1U, /* Direction : IN */
USBH_EP_CONTROL, /* EP type */
USBH_PID_DATA, /* Type Data */
buff, /* data buffer */
length, /* data length */
0U);
return USBH_OK;
}
/**
* @brief USBH_BulkSendData
* Sends the Bulk Packet to the device
* @param phost: Host Handle
* @param buff: Buffer pointer from which the Data will be sent to Device
* @param length: Length of the data to be sent
* @param pipe_num: Pipe Number
* @retval USBH Status
*/
USBH_StatusTypeDef USBH_BulkSendData(USBH_HandleTypeDef *phost,
uint8_t *buff,
uint16_t length,
uint8_t pipe_num,
uint8_t do_ping)
{
if (phost->device.speed != USBH_SPEED_HIGH)
{
do_ping = 0U;
}
(void)USBH_LL_SubmitURB(phost, /* Driver handle */
pipe_num, /* Pipe index */
0U, /* Direction : IN */
USBH_EP_BULK, /* EP type */
USBH_PID_DATA, /* Type Data */
buff, /* data buffer */
length, /* data length */
do_ping); /* do ping (HS Only)*/
return USBH_OK;
}
/**
* @brief USBH_BulkReceiveData
* Receives IN bulk packet from device
* @param phost: Host Handle
* @param buff: Buffer pointer in which the received data packet to be copied
* @param length: Length of the data to be received
* @param pipe_num: Pipe Number
* @retval USBH Status.
*/
USBH_StatusTypeDef USBH_BulkReceiveData(USBH_HandleTypeDef *phost,
uint8_t *buff,
uint16_t length,
uint8_t pipe_num)
{
(void)USBH_LL_SubmitURB(phost, /* Driver handle */
pipe_num, /* Pipe index */
1U, /* Direction : IN */
USBH_EP_BULK, /* EP type */
USBH_PID_DATA, /* Type Data */
buff, /* data buffer */
length, /* data length */
0U);
return USBH_OK;
}
/**
* @brief USBH_InterruptReceiveData
* Receives the Device Response to the Interrupt IN token
* @param phost: Host Handle
* @param buff: Buffer pointer in which the response needs to be copied
* @param length: Length of the data to be received
* @param pipe_num: Pipe Number
* @retval USBH Status.
*/
USBH_StatusTypeDef USBH_InterruptReceiveData(USBH_HandleTypeDef *phost,
uint8_t *buff,
uint8_t length,
uint8_t pipe_num)
{
(void)USBH_LL_SubmitURB(phost, /* Driver handle */
pipe_num, /* Pipe index */
1U, /* Direction : IN */
USBH_EP_INTERRUPT, /* EP type */
USBH_PID_DATA, /* Type Data */
buff, /* data buffer */
(uint16_t)length, /* data length */
0U);
return USBH_OK;
}
/**
* @brief USBH_InterruptSendData
* Sends the data on Interrupt OUT Endpoint
* @param phost: Host Handle
* @param buff: Buffer pointer from where the data needs to be copied
* @param length: Length of the data to be sent
* @param pipe_num: Pipe Number
* @retval USBH Status.
*/
USBH_StatusTypeDef USBH_InterruptSendData(USBH_HandleTypeDef *phost,
uint8_t *buff,
uint8_t length,
uint8_t pipe_num)
{
(void)USBH_LL_SubmitURB(phost, /* Driver handle */
pipe_num, /* Pipe index */
0U, /* Direction : OUT */
USBH_EP_INTERRUPT, /* EP type */
USBH_PID_DATA, /* Type Data */
buff, /* data buffer */
(uint16_t)length, /* data length */
0U);
return USBH_OK;
}
/**
* @brief USBH_IsocReceiveData
* Receives the Device Response to the Isochronous IN token
* @param phost: Host Handle
* @param buff: Buffer pointer in which the response needs to be copied
* @param length: Length of the data to be received
* @param pipe_num: Pipe Number
* @retval USBH Status.
*/
USBH_StatusTypeDef USBH_IsocReceiveData(USBH_HandleTypeDef *phost,
uint8_t *buff,
uint32_t length,
uint8_t pipe_num)
{
(void)USBH_LL_SubmitURB(phost, /* Driver handle */
pipe_num, /* Pipe index */
1U, /* Direction : IN */
USBH_EP_ISO, /* EP type */
USBH_PID_DATA, /* Type Data */
buff, /* data buffer */
(uint16_t)length, /* data length */
0U);
return USBH_OK;
}
/**
* @brief USBH_IsocSendData
* Sends the data on Isochronous OUT Endpoint
* @param phost: Host Handle
* @param buff: Buffer pointer from where the data needs to be copied
* @param length: Length of the data to be sent
* @param pipe_num: Pipe Number
* @retval USBH Status.
*/
USBH_StatusTypeDef USBH_IsocSendData(USBH_HandleTypeDef *phost,
uint8_t *buff,
uint32_t length,
uint8_t pipe_num)
{
(void)USBH_LL_SubmitURB(phost, /* Driver handle */
pipe_num, /* Pipe index */
0U, /* Direction : OUT */
USBH_EP_ISO, /* EP type */
USBH_PID_DATA, /* Type Data */
buff, /* data buffer */
(uint16_t)length, /* data length */
0U);
return USBH_OK;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@@ -0,0 +1,188 @@
/**
******************************************************************************
* @file usbh_pipes.c
* @author MCD Application Team
* @brief This file implements functions for opening and closing Pipes
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2015 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "usbh_pipes.h"
/** @addtogroup USBH_LIB
* @{
*/
/** @addtogroup USBH_LIB_CORE
* @{
*/
/** @defgroup USBH_PIPES
* @brief This file includes opening and closing Pipes
* @{
*/
/** @defgroup USBH_PIPES_Private_Defines
* @{
*/
/**
* @}
*/
/** @defgroup USBH_PIPES_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup USBH_PIPES_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USBH_PIPES_Private_Variables
* @{
*/
/**
* @}
*/
/** @defgroup USBH_PIPES_Private_Functions
* @{
*/
static uint16_t USBH_GetFreePipe(USBH_HandleTypeDef *phost);
/**
* @brief USBH_Open_Pipe
* Open a pipe
* @param phost: Host Handle
* @param pipe_num: Pipe Number
* @param dev_address: USB Device address allocated to attached device
* @param speed : USB device speed (Full/Low)
* @param ep_type: end point type (Bulk/int/ctl)
* @param mps: max pkt size
* @retval USBH Status
*/
USBH_StatusTypeDef USBH_OpenPipe(USBH_HandleTypeDef *phost, uint8_t pipe_num,
uint8_t epnum, uint8_t dev_address,
uint8_t speed, uint8_t ep_type, uint16_t mps)
{
(void)USBH_LL_OpenPipe(phost, pipe_num, epnum, dev_address, speed, ep_type, mps);
return USBH_OK;
}
/**
* @brief USBH_ClosePipe
* Close a pipe
* @param phost: Host Handle
* @param pipe_num: Pipe Number
* @retval USBH Status
*/
USBH_StatusTypeDef USBH_ClosePipe(USBH_HandleTypeDef *phost, uint8_t pipe_num)
{
(void)USBH_LL_ClosePipe(phost, pipe_num);
return USBH_OK;
}
/**
* @brief USBH_Alloc_Pipe
* Allocate a new Pipe
* @param phost: Host Handle
* @param ep_addr: End point for which the Pipe to be allocated
* @retval Pipe number
*/
uint8_t USBH_AllocPipe(USBH_HandleTypeDef *phost, uint8_t ep_addr)
{
uint16_t pipe;
pipe = USBH_GetFreePipe(phost);
if (pipe != 0xFFFFU)
{
phost->Pipes[pipe & 0xFU] = (uint32_t)(0x8000U | ep_addr);
}
return (uint8_t)pipe;
}
/**
* @brief USBH_Free_Pipe
* Free the USB Pipe
* @param phost: Host Handle
* @param idx: Pipe number to be freed
* @retval USBH Status
*/
USBH_StatusTypeDef USBH_FreePipe(USBH_HandleTypeDef *phost, uint8_t idx)
{
if (idx < USBH_MAX_PIPES_NBR)
{
phost->Pipes[idx] &= 0x7FFFU;
}
return USBH_OK;
}
/**
* @brief USBH_GetFreePipe
* @param phost: Host Handle
* Get a free Pipe number for allocation to a device endpoint
* @retval idx: Free Pipe number
*/
static uint16_t USBH_GetFreePipe(USBH_HandleTypeDef *phost)
{
uint8_t idx = 0U;
for (idx = 0U ; idx < USBH_MAX_PIPES_NBR ; idx++)
{
if ((phost->Pipes[idx] & 0x8000U) == 0U)
{
return (uint16_t)idx;
}
}
return 0xFFFFU;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/