first commit

This commit is contained in:
2022-08-24 08:39:13 +02:00
commit e663300109
2491 changed files with 2231094 additions and 0 deletions
@@ -0,0 +1,555 @@
/**
******************************************************************************
* @file USBD_COMP.c
* @author DB4PLE
* @version V1.0.0
* @date 11-December-2015
* @brief This file provides the composite core functions.
*
*
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include <drivers/usb/device/class/composite/usbd_composite.h>
#include "usbd_desc.h"
#include "usbd_ctlreq.h"
#include "uhsdr_board.h"
/** @addtogroup STM32_USB_DEVICE_LIBRARY
* @{
*/
/** @defgroup USBD_COMP
* @brief usbd core module
* @{
*/
/** @defgroup USBD_COMP_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup USBD_COMP_Private_Defines
* @{
*/
/**
* @}
*/
/** @defgroup USBD_COMP_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USBD_COMP_Private_FunctionPrototypes
* @{
*/
static uint8_t USBD_COMP_Init (USBD_HandleTypeDef *pdev,
uint8_t cfgidx);
static uint8_t USBD_COMP_DeInit (USBD_HandleTypeDef *pdev,
uint8_t cfgidx);
static uint8_t USBD_COMP_Setup (USBD_HandleTypeDef *pdev,
USBD_SetupReqTypedef *req);
static uint8_t *USBD_COMP_GetCfgDesc (uint16_t *length);
static uint8_t *USBD_COMP_GetDeviceQualifierDesc (uint16_t *length);
static uint8_t USBD_COMP_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum);
static uint8_t USBD_COMP_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum);
static uint8_t USBD_COMP_EP0_RxReady (USBD_HandleTypeDef *pdev);
static uint8_t USBD_COMP_EP0_TxReady (USBD_HandleTypeDef *pdev);
static uint8_t USBD_COMP_SOF (USBD_HandleTypeDef *pdev);
static uint8_t USBD_COMP_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum);
static uint8_t USBD_COMP_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum);
/**
* @}
*/
/** @defgroup USBD_COMP_Private_Variables
* @{
*/
USBD_ClassTypeDef USBD_COMP =
{
USBD_COMP_Init,
USBD_COMP_DeInit,
USBD_COMP_Setup,
USBD_COMP_EP0_TxReady,
USBD_COMP_EP0_RxReady,
USBD_COMP_DataIn,
USBD_COMP_DataOut,
USBD_COMP_SOF,
USBD_COMP_IsoINIncomplete,
USBD_COMP_IsoOutIncomplete,
USBD_COMP_GetCfgDesc,
USBD_COMP_GetCfgDesc,
USBD_COMP_GetCfgDesc,
USBD_COMP_GetDeviceQualifierDesc,
};
USBD_COMP_ItfTypeDef USBD_COMP_fops_FS;
/* USB Standard Device Descriptor */
__ALIGN_BEGIN static uint8_t USBD_COMP_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END=
{
USB_LEN_DEV_QUALIFIER_DESC,
USB_DESC_TYPE_DEVICE_QUALIFIER,
0x00,
0x02,
0x00,
0x00,
0x00,
0x40,
0x01,
0x00,
};
/**
* @}
*/
/** @defgroup USBD_COMP_Private_Functions
* @{
*/
/**
* @brief USBD_COMP_Init
* Initialize the AUDIO interface
* @param pdev: device instance
* @param cfgidx: Configuration index
* @retval status
*/
static inline void switchToClass(USBD_HandleTypeDef *pdev,USBD_ClassCompInfo* class)
{
pdev->pClassData = class->classData;
pdev->pUserData = class->userData;
}
static inline void saveClass(USBD_HandleTypeDef *pdev,USBD_ClassCompInfo* class)
{
class->classData = pdev->pClassData;
class->userData = pdev->pUserData;
}
static uint8_t USBD_COMP_Init (USBD_HandleTypeDef *pdev,
uint8_t cfgidx)
{
uint8_t retval = USBD_OK;
for (int i = 0; i < CLASS_NUM && retval == USBD_OK; i++)
{
switchToClass(pdev,&dev_instance[i]);
retval = dev_instance[i].class->Init(pdev,cfgidx);
saveClass(pdev,&dev_instance[i]);
}
return retval;
}
/**
* @brief USBD_COMP_Init
* DeInitialize the AUDIO layer
* @param pdev: device instance
* @param cfgidx: Configuration index
* @retval status
*/
static uint8_t USBD_COMP_DeInit (USBD_HandleTypeDef *pdev,
uint8_t cfgidx)
{
uint8_t retval = USBD_OK;
for (int i = 0; i < CLASS_NUM && retval == USBD_OK; i++)
{
switchToClass(pdev,&dev_instance[i]);
retval = dev_instance[i].class->DeInit(pdev,cfgidx);
saveClass(pdev,&dev_instance[i]);
}
return retval;
}
/**
* @brief USBD_COMP_Setup
* Handle the AUDIO specific requests
* @param pdev: instance
* @param req: usb requests
* @retval status
*/
static uint8_t* USBD_COMP_FindDescriptor(uint8_t desc_type)
{
uint8_t* retval = NULL;
uint16_t desc_len;
uint8_t* desc_ptr = USBD_COMP_GetCfgDesc(&desc_len);
for (int32_t i = 0; i < desc_len; i += desc_ptr[i])
{
if (desc_ptr[i+1] == desc_type)
{
retval = &desc_ptr[i];
break;
}
}
return retval;
}
static uint8_t USBD_COMP_Setup (USBD_HandleTypeDef *pdev,
USBD_SetupReqTypedef *req)
{
uint16_t len;
uint8_t *pbuf;
uint8_t ret = USBD_OK;
uint8_t done = 0;
switch (req->bmRequest & USB_REQ_TYPE_MASK)
{
case USB_REQ_TYPE_CLASS :
switch(req->bmRequest & USB_REQ_RECIPIENT_MASK)
{
case USB_REQ_RECIPIENT_INTERFACE:
for (int i = 0; i < CLASS_NUM; i++)
{
uint8_t interface = req->wValue >> 8;
if (interface >= dev_instance[i].minIf && interface <= dev_instance[i].maxIf)
{
switchToClass(pdev,&dev_instance[i]);
ret = dev_instance[i].class->Setup(pdev,req);
done = 1;
break;
}
}
break;
default:
break;
}
if (done != 1)
{
USBD_CtlError (pdev, req);
ret = USBD_FAIL;
}
break;
case USB_REQ_TYPE_STANDARD:
switch (req->bRequest)
{
case USB_REQ_GET_DESCRIPTOR:
{
pbuf = USBD_COMP_FindDescriptor(req->wValue >> 8);
if(pbuf != NULL)
{
len = MIN(pbuf[0], req->wLength);
USBD_CtlSendData (pdev,
pbuf,
len);
}
}
break;
case USB_REQ_GET_INTERFACE :
case USB_REQ_SET_INTERFACE :
if ((uint8_t)(req->wIndex) <= USBD_MAX_NUM_INTERFACES)
{
for (int i = 0; i < CLASS_NUM; i++)
{
if (req->wIndex >= dev_instance[i].minIf && req->wIndex <= dev_instance[i].maxIf)
{
switchToClass(pdev,&dev_instance[i]);
ret = dev_instance[i].class->Setup(pdev,req);
done = 1;
break;
}
}
}
else
{
/* Call the error management function (command will be nacked */
USBD_CtlError (pdev, req);
}
break;
default:
USBD_CtlError (pdev, req);
ret = USBD_FAIL;
}
}
return ret;
}
/**
* @brief USBD_COMP_GetCfgDesc
* return configuration descriptor
* @param speed : current device speed
* @param length : pointer data length
* @retval pointer to descriptor buffer
*/
static uint8_t *USBD_COMP_GetCfgDesc (uint16_t *length)
{
*length = sizeof (USBD_COMP_CfgDesc);
return USBD_COMP_CfgDesc;
}
/**
* @brief USBD_COMP_DataIn
* handle data IN Stage
* @param pdev: device instance
* @param epnum: endpoint index
* @retval status
*/
static uint8_t USBD_COMP_DataIn (USBD_HandleTypeDef *pdev,
uint8_t epnum)
{
uint8_t retval = USBD_OK;
if (epnum <= USBD_MAX_EP)
{
uint8_t classIdx = usbdEpMap.in[epnum];
if (classIdx < CLASS_NUM)
{
if (dev_instance[classIdx].class->DataIn != NULL)
{
switchToClass(pdev,&dev_instance[classIdx]);
retval = dev_instance[classIdx].class->DataIn(pdev,epnum);
}
}
}
return retval;
}
/**
* @brief USBD_COMP_EP0_RxReady
* handle EP0 Rx Ready event
* @param pdev: device instance
* @retval status
*/
static uint8_t USBD_COMP_EP0_RxReady (USBD_HandleTypeDef *pdev)
{
uint8_t retval = USBD_OK;
for (int i = 0; i < CLASS_NUM; i++)
{
if (dev_instance[i].class->EP0_RxReady != NULL)
{
switchToClass(pdev,&dev_instance[i]);
retval = dev_instance[i].class->EP0_RxReady(pdev);
}
if (retval != USBD_OK)
{
break;
}
}
return retval;
}
/**
* @brief USBD_COMP_EP0_TxReady
* handle EP0 TRx Ready event
* @param pdev: device instance
* @retval status
*/
static uint8_t USBD_COMP_EP0_TxReady (USBD_HandleTypeDef *pdev)
{
uint8_t retval = USBD_OK;
for (int i = 0; i < CLASS_NUM; i++)
{
if (dev_instance[i].class->EP0_TxSent != NULL)
{
switchToClass(pdev,&dev_instance[i]);
retval = dev_instance[i].class->EP0_TxSent(pdev);
}
if (retval != USBD_OK)
{
break;
}
}
return retval;
}
/**
* @brief USBD_COMP_SOF
* handle SOF event
* @param pdev: device instance
* @retval status
*/
static uint8_t USBD_COMP_SOF (USBD_HandleTypeDef *pdev)
{
uint8_t retval = USBD_OK;
for (int i = 0; i < CLASS_NUM; i++)
{
if (dev_instance[i].class->SOF != NULL)
{
switchToClass(pdev,&dev_instance[i]);
retval = dev_instance[i].class->SOF(pdev);
if (retval != USBD_OK)
{
break;
}
}
}
return retval;
}
/**
* @brief USBD_COMP_IsoINIncomplete
* handle data ISO IN Incomplete event
* @param pdev: device instance
* @param epnum: endpoint index
* @retval status
*/
static uint8_t USBD_COMP_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum)
{
uint8_t retval = USBD_OK;
for (int i = 0; i < CLASS_NUM; i++)
{
if (dev_instance[i].class->IsoINIncomplete != NULL)
{
switchToClass(pdev,&dev_instance[i]);
retval = dev_instance[i].class->IsoINIncomplete(pdev, epnum);
if (retval != USBD_OK)
{
break;
}
}
}
return retval;
}
/**
* @brief USBD_COMP_IsoOutIncomplete
* handle data ISO OUT Incomplete event
* @param pdev: device instance
* @param epnum: endpoint index
* @retval status
*/
static uint8_t USBD_COMP_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum)
{
uint8_t retval = USBD_OK;
for (int i = 0; i < CLASS_NUM; i++)
{
if (dev_instance[i].class->IsoOUTIncomplete != NULL)
{
switchToClass(pdev,&dev_instance[i]);
retval = dev_instance[i].class->IsoOUTIncomplete(pdev, epnum);
if (retval != USBD_OK)
{
break;
}
}
}
return retval;
}
/**
* @brief USBD_COMP_DataOut
* handle data OUT Stage
* @param pdev: device instance
* @param epnum: endpoint index
* @retval status
*/
static uint8_t USBD_COMP_DataOut (USBD_HandleTypeDef *pdev,
uint8_t epnum)
{
uint8_t retval = USBD_OK;
if (epnum <= USBD_MAX_EP)
{
uint8_t classIdx = usbdEpMap.out[epnum];
if (classIdx < CLASS_NUM)
{
if (dev_instance[classIdx].class->DataOut != NULL)
{
switchToClass(pdev,&dev_instance[classIdx]);
retval = dev_instance[classIdx].class->DataOut(pdev,epnum);
}
}
}
return retval;
}
/**
* @brief DeviceQualifierDescriptor
* return Device Qualifier descriptor
* @param length : pointer data length
* @retval pointer to descriptor buffer
*/
static uint8_t *USBD_COMP_GetDeviceQualifierDesc (uint16_t *length)
{
*length = sizeof (USBD_COMP_DeviceQualifierDesc);
return USBD_COMP_DeviceQualifierDesc;
}
/**
* @brief USBD_COMP_RegisterInterface
* @param fops: Audio interface callback
* @retval status
*/
uint8_t USBD_COMP_RegisterInterface (USBD_HandleTypeDef *pdev,
USBD_COMP_ItfTypeDef *fops)
{
if(fops != NULL)
{
pdev->pUserData= fops;
}
return 0;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
@@ -0,0 +1,153 @@
/**
******************************************************************************
* @file USBD_COMP_cdc_comp.h
* @author MCD Application Team/ mcHF Devel
* @version V2.4.2
* @date 11-December-2015
* @brief header file for the USBD_COMP.c file.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USB_COMPOSITE_H
#define __USB_COMPOSITE_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "usbd_ioreq.h"
#include "usbd_desc.h"
/** @addtogroup STM32_USB_DEVICE_LIBRARY
* @{
*/
/** @defgroup USBD_COMP
* @brief This file is the Header file for USBD_COMP.c
* @{
*/
/** @defgroup USBD_COMP_Exported_Defines
* @{
*/
/**
* @}
*/
/** @defgroup USBD_CORE_Exported_TypesDefinitions
* @{
*/
typedef struct
{
USBD_ClassTypeDef* class;
void* classData;
void* userData;
uint16_t ctrlIf;
uint16_t minIf;
uint16_t maxIf;
} USBD_ClassCompInfo;
#define USBD_MAX_EP 3
typedef struct
{
uint8_t in[USBD_MAX_EP+1];
uint8_t out[USBD_MAX_EP+1];
} usbd_ep_map_t;
#define CLASS_AUDIO 0
#define CLASS_CDC 1
#define CLASS_NUM 2
#define CLASS_UNUSED 0xFF
extern const usbd_ep_map_t usbdEpMap;
extern USBD_ClassCompInfo dev_instance[CLASS_NUM];
#define USB_AUDIO_CONFIG_DESC_SIZ (9+101+73 + 8 + 66 + 9 +7)
extern uint8_t USBD_COMP_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ];
typedef struct
{
}
USBD_COMP_HandleTypeDef;
typedef struct
{
}USBD_COMP_ItfTypeDef;
extern USBD_COMP_ItfTypeDef USBD_COMP_fops_FS;
/**
* @}
*/
/** @defgroup USBD_CORE_Exported_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USBD_CORE_Exported_Variables
* @{
*/
extern USBD_ClassTypeDef USBD_COMP;
#define USBD_COMP_CLASS &USBD_COMP
/**
* @}
*/
/** @defgroup USB_CORE_Exported_Functions
* @{
*/
uint8_t USBD_COMP_RegisterInterface (USBD_HandleTypeDef *pdev,
USBD_COMP_ItfTypeDef *fops);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __USB_COMPOSITE_H */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
@@ -0,0 +1,523 @@
/**
******************************************************************************
* @file USBD_COMP.c
* @author MCD Application Team
* @version V2.4.2
* @date 11-December-2015
* @brief This file provides the Audio core functions.
*
* @verbatim
*
* ===================================================================
* AUDIO Class Description
* ===================================================================
* This driver manages the Audio Class 1.0 following the "USB Device Class Definition for
* Audio Devices V1.0 Mar 18, 98".
* This driver implements the following aspects of the specification:
* - Device descriptor management
* - Configuration descriptor management
* - Standard AC Interface Descriptor management
* - 1 Audio Streaming Interface (with single channel, PCM, Stereo mode)
* - 1 Audio Streaming Endpoint
* - 1 Audio Terminal Input (1 channel)
* - Audio Class-Specific AC Interfaces
* - Audio Class-Specific AS Interfaces
* - AudioControl Requests: only SET_CUR and GET_CUR requests are supported (for Mute)
* - Audio Feature Unit (limited to Mute control)
* - Audio Synchronization type: Asynchronous
* - Single fixed audio sampling rate (configurable in usbd_conf.h file)
* The current audio class version supports the following audio features:
* - Pulse Coded Modulation (PCM) format
* - sampling rate: 48KHz.
* - Bit resolution: 16
* - Number of channels: 2
* - No volume control
* - Mute/Unmute capability
* - Asynchronous Endpoints
*
* @note In HS mode and when the DMA is used, all variables and data structures
* dealing with the DMA during the transaction process should be 32-bit aligned.
*
*
* @endverbatim
*
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include <drivers/usb/device/class/composite/usbd_composite.h>
#include <drivers/usb/device/class/composite/usbd_composite_desc.h>
#include "usbd_desc.h"
#include "usbd_ctlreq.h"
#include "uhsdr_board.h"
#include "usbd_cdc.h"
#include "usbd_audio_cdc_comp.h"
#include "usbd_audio_if.h"
#include "usbd_cdc_if.h"
/** @addtogroup STM32_USB_DEVICE_LIBRARY
* @{
*/
/** @defgroup USBD_COMP
* @brief usbd core module
* @{
*/
/** @defgroup USBD_COMP_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup USBD_COMP_Private_Defines
* @{
*/
/**
* @}
*/
/** @defgroup USBD_COMP_Private_Macros
* @{
*/
#define AUDIO_SAMPLE_FREQ(frq) (uint8_t)(frq), (uint8_t)((frq >> 8)), (uint8_t)((frq >> 16))
/**
* @}
*/
/** @defgroup USBD_COMP_Private_FunctionPrototypes
* @{
*/
/* USB AUDIO device Configuration Descriptor */
__ALIGN_BEGIN uint8_t USBD_COMP_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ] __ALIGN_END =
{
/* Configuration 1 */
0x09, /* bLength */
USB_DESC_TYPE_CONFIGURATION, // USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType */
LOBYTE(USB_AUDIO_CONFIG_DESC_SIZ), /* wTotalLength 109 bytes*/
HIBYTE(USB_AUDIO_CONFIG_DESC_SIZ),
0x05, /* bNumInterfaces */
0x01, /* bConfigurationValue */
0x00, /* iConfiguration */
0xC0, /* bmAttributes BUS Powred*/
0x32, /* bMaxPower = 100 mA*/
/* 09 byte*/
/*---------------------------------------------------------------------------*/
USB_INTERFACE_ASSOCIATION_DESC_SIZE,
USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE,
CDC_CTRL_IF, /* first interface */
CDC_TOTAL_IF_NUM, /* bNumInterfaces */
0x02, /* bInterfaceClass */
0x02, /* bInterfaceSubClass */
0x01, /* bInterfaceProtocol */
0x00, /* String Index */
/*Interface Descriptor */
0x09, /* bLength: Interface Descriptor size */
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */
/* Interface descriptor type */
CDC_CTRL_IF, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: Alternate setting */
0x01, /* bNumEndpoints: One endpoints used */
0x02, /* bInterfaceClass: Communication Interface Class */
0x02, /* bInterfaceSubClass: Abstract Control Model */
0x01, /* bInterfaceProtocol: Common AT commands */
0x00, /* iInterface: */
/*Header Functional Descriptor*/
0x05, /* bLength: Endpoint Descriptor size */
0x24, /* bDescriptorType: CS_INTERFACE */
0x00, /* bDescriptorSubtype: Header Func Desc */
0x10, /* bcdCDC: spec release number */
0x01,
/*Call Management Functional Descriptor*/
0x05, /* bFunctionLength */
0x24, /* bDescriptorType: CS_INTERFACE */
0x01, /* bDescriptorSubtype: Call Management Func Desc */
0x00, /* bmCapabilities: D0+D1 */
0x01, /* bDataInterface: 1 */
/*ACM Functional Descriptor*/
0x04, /* bFunctionLength */
0x24, /* bDescriptorType: CS_INTERFACE */
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
0x02, /* bmCapabilities */
/*Union Functional Descriptor*/
0x05, /* bFunctionLength */
0x24, /* bDescriptorType: CS_INTERFACE */
0x06, /* bDescriptorSubtype: Union func desc */
CDC_CTRL_IF, /* bMasterInterface: Communication class interface */
CDC_DATA_IF, /* bSlaveInterface0: Data Class Interface */
/*Endpoint 2 Descriptor*/
0x07, /* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
CDC_CMD_EP, /* bEndpointAddress */
0x03, /* bmAttributes: Interrupt */
LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */
HIBYTE(CDC_CMD_PACKET_SIZE),
#ifdef USE_USB_OTG_HS
0x10, /* bInterval: */
#else
0xFF, /* bInterval: */
#endif /* USE_USB_OTG_HS */
/*---------------------------------------------------------------------------*/
/*Data class interface descriptor*/
0x09, /* bLength: Endpoint Descriptor size */
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
CDC_DATA_IF, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: Alternate setting */
0x02, /* bNumEndpoints: Two endpoints used */
0x0A, /* bInterfaceClass: CDC */
0x00, /* bInterfaceSubClass: */
0x00, /* bInterfaceProtocol: */
0x00, /* iInterface: */
/*Endpoint OUT Descriptor*/
0x07, /* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
CDC_OUT_EP, /* bEndpointAddress */
0x02, /* bmAttributes: Bulk */
LOBYTE(CDC_DATA_FS_OUT_PACKET_SIZE), /* wMaxPacketSize: */
HIBYTE(CDC_DATA_FS_OUT_PACKET_SIZE),
0x00, /* bInterval: ignore for Bulk transfer */
/*Endpoint IN Descriptor*/
0x07, /* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
CDC_IN_EP, /* bEndpointAddress */
0x02, /* bmAttributes: Bulk */
LOBYTE(CDC_DATA_FS_IN_PACKET_SIZE), /* wMaxPacketSize: */
HIBYTE(CDC_DATA_FS_IN_PACKET_SIZE),
0x00, /* bInterval: ignore for Bulk transfer */
USB_INTERFACE_ASSOCIATION_DESC_SIZE,
USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE,
AUDIO_CTRL_IF, /* first interface */
AUDIO_TOTAL_IF_NUM, /* bNumInterfaces */
USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */
AUDIO_SUBCLASS_AUDIOCONTROL, /* bInterfaceSubClass */
AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */
0x00, /* String Index */
/* USB Sound Standard interface descriptor */
AUDIO_INTERFACE_DESC_SIZE, /* bLength */
USB_DESC_TYPE_INTERFACE, /* bDescriptorType */
AUDIO_CTRL_IF, /* bInterfaceNumber */
0x00, /* bAlternateSetting */
0x00, /* bNumEndpoints */
USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */
AUDIO_SUBCLASS_AUDIOCONTROL, /* bInterfaceSubClass */
AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */
0x00, /* iInterface */
/* 09 byte*/
// Begin AudioControl Descriptors
/* USB Speaker Class-specific AC Interface Descriptor */
AUDIO_INTERFACE_DESC_SIZE + 1, /* bLength */
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
AUDIO_CONTROL_HEADER, /* bDescriptorSubtype */
0x00, /* 1.00 */ /* bcdADC */
0x01,
61 + 9 + 7,
0x00,
0x02, /* bInCollection */
AUDIO_OUT_IF, /* baInterfaceNr */
AUDIO_IN_IF, /* baInterfaceNr */
/* 09 byte*/
/* USB Speaker Input Terminal Descriptor */
AUDIO_INPUT_TERMINAL_DESC_SIZE, /* bLength */
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
AUDIO_CONTROL_INPUT_TERMINAL, /* bDescriptorSubtype */
0x01, /* bTerminalID */
0x01, /* wTerminalType AUDIO_TERMINAL_USB_STREAMING 0x0101 */
0x01,
0x00, /* bAssocTerminal */
/* bNrChannels conflict
* In the "Type III Format" (actually type I) descriptor, bNrChannels is set to 2
* But in the input terminal desc, bNrChannels is 1
* Also, wChannelConfig is wrong, even if it was mono */
0x02, /* bNrChannels */
0x03, /* wChannelConfig 0x0000 Mono; 0x03, 0x00 (L/R front) */
0x00,
0x00, /* iChannelNames */
0x00, /* iTerminal */
/* 12 byte*/
/* USB Speaker Audio Feature Unit Descriptor */
0x09, /* bLength */
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
AUDIO_CONTROL_FEATURE_UNIT, /* bDescriptorSubtype */
AUDIO_OUT_STREAMING_CTRL, /* bUnitID */
0x01, /* bSourceID */
0x01, /* bControlSize */
AUDIO_CONTROL_VOLUME, /* bmaControls(0) */
0x00, /* bmaControls(1) */
0x00, /* iTerminal */
/* 09 byte*/
/*USB Speaker Output Terminal Descriptor */
0x09, /* bLength */
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
AUDIO_CONTROL_OUTPUT_TERMINAL, /* bDescriptorSubtype */
0x03, /* bTerminalID */
0x01, /* wTerminalType 0x0301*/
0x03,
0x00, /* bAssocTerminal */
0x02, /* bSourceID */
0x00, /* iTerminal */
/* 09 byte*/
/*USB Microphone Input Terminal Descriptor */
0x0C, // Size of the descriptor, in bytes
AUDIO_INTERFACE_DESCRIPTOR_TYPE, // CS_INTERFACE Descriptor Type
AUDIO_CONTROL_INPUT_TERMINAL, // INPUT_TERMINAL descriptor subtype
0x04, // ID of this Terminal.
0x01,0x02, // Terminal is Microphone (0x01,0x02)
0x00, // No association
USBD_AUDIO_IN_CHANNELS, // One or two channel
0x03,0x00, /* wChannelConfig 0x0000 Mono; 0x03, 0x00 (L/R front) */
0x00, // Unused.
0x00, // Unused.
/* USB Microphone Output Terminal Descriptor */
0x09, // Size of the descriptor, in bytes (bLength)
AUDIO_INTERFACE_DESCRIPTOR_TYPE, // CS_INTERFACE Descriptor Type (bDescriptorType)
AUDIO_CONTROL_OUTPUT_TERMINAL, // OUTPUT_TERMINAL descriptor subtype (bDescriptorSubtype)
0x05, // ID of this Terminal. (bTerminalID)
0x01, 0x01, // USB Streaming. (wTerminalType
0x00, // unused (bAssocTerminal)
0x07, // From Input Terminal.(bSourceID)
0x00, // unused (iTerminal)
/* USB Speaker Audio Feature Unit Descriptor */
0x09, /* bLength */
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
AUDIO_CONTROL_FEATURE_UNIT, /* bDescriptorSubtype */
0x06, /* bUnitID */
0x04, /* bSourceID */
0x01, /* bControlSize */
AUDIO_CONTROL_VOLUME, /* bmaControls(0) */
0x00, /* bmaControls(1) */
0x00, /* iTerminal */
/* 09 byte*/
/* AC Selector Unit Descriptor */
0x07, // bLength
0x24, // bDescriptorType
0x05, // bDescriptorSubtype
0x07, // bUnitID
0x01, // bBrInPins
0x06, // baSourceID(1)
0x00, // iSelector
// ========================================== END AudioControl
/* USB Speaker Standard AS Interface Descriptor - Audio Streaming Zero Bandwith */
/* Interface 1, Alternate Setting 0 */
AUDIO_INTERFACE_DESC_SIZE, /* bLength */
USB_DESC_TYPE_INTERFACE, /* bDescriptorType */
AUDIO_OUT_IF, /* bInterfaceNumber */
0x00, /* bAlternateSetting */
0x00, /* bNumEndpoints */
USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubClass */
AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */
0x00, /* iInterface */
/* 09 byte*/
/* USB Speaker Standard AS Interface Descriptor - Audio Streaming Operational */
/* Interface 1, Alternate Setting 1 */
AUDIO_INTERFACE_DESC_SIZE, /* bLength */
USB_DESC_TYPE_INTERFACE, /* bDescriptorType */
AUDIO_OUT_IF, /* bInterfaceNumber */
0x01, /* bAlternateSetting */
0x01, /* bNumEndpoints */
USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */
AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubClass */
AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */
0x00, /* iInterface */
/* 09 byte*/
/* USB Speaker Audio Streaming Interface Descriptor */
AUDIO_STREAMING_INTERFACE_DESC_SIZE, /* bLength */
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
AUDIO_STREAMING_GENERAL, /* bDescriptorSubtype */
0x01, /* bTerminalLink */
0x01, /* bDelay */
0x01, /* wFormatTag AUDIO_FORMAT_PCM 0x0001*/
0x00,
/* 07 byte*/
/* USB Speaker Audio Type I Format Interface Descriptor */
0x0B, /* bLength */
AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */
AUDIO_STREAMING_FORMAT_TYPE, /* bDescriptorSubtype */
/* Type III" format descriptor is assigned, but wFormatTag on AS interface desc is set to PCM
* (type III is not PCM). As Type III is not a popular one, it should be of Type I */
AUDIO_FORMAT_TYPE_I, /* bFormatType */
0x02, /* bNrChannels */
0x02, /* bSubFrameSize : 2 Bytes per frame (16bits) */
16, /* bBitResolution (16-bits per sample) */
0x01, /* bSamFreqType only one frequency supported */
SAMPLE_FREQ(USBD_AUDIO_FREQ), /* Audio sampling frequency coded on 3 bytes */
/* 11 byte*/
/* Endpoint 1 - Standard Descriptor */
AUDIO_STANDARD_ENDPOINT_DESC_SIZE, /* bLength */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */
AUDIO_OUT_EP, /* bEndpointAddress 1 out endpoint*/
USB_ENDPOINT_TYPE_ISOCHRONOUS, /* bmAttributes */
AUDIO_PACKET_SZE(USBD_AUDIO_FREQ,USBD_AUDIO_OUT_CHANNELS), /* wMaxPacketSize in Bytes (Freq(Samples)*2(Stereo)*2(HalfWord)) */
0x01, /* bInterval */
0x00, /* bRefresh */
0x00, /* bSynchAddress */
/* 09 byte*/
/* Endpoint - Audio Streaming Descriptor*/
AUDIO_STREAMING_ENDPOINT_DESC_SIZE, /* bLength */
AUDIO_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */
AUDIO_ENDPOINT_GENERAL, /* bDescriptor */
0x00, /* bmAttributes */
0x00, /* bLockDelayUnits */
0x00, /* wLockDelay */
0x00,
/* 07 byte*/
/* From Here is the Microphone */
/* USB Microphone Standard AS Interface Descriptor (Alt. Set. 0) (CODE == 3)*/ //zero-bandwidth interface
/*
* Microphone Standard AS Interface Descriptor - Audio Streaming Zero Bandwith
* Interface 1, Alternate Setting 0
*/
AUDIO_INTERFACE_DESC_SIZE, // Size of the descriptor, in bytes (bLength)
USB_DESC_TYPE_INTERFACE, // INTERFACE descriptor type (bDescriptorType) 0x04
AUDIO_IN_IF, // Index of this interface. (bInterfaceNumber) ?????????? (3<) (1<<) (1<M)
0x00, // Index of this alternate setting. (bAlternateSetting)
0x00, // 0 endpoints. (bNumEndpoints)
USB_DEVICE_CLASS_AUDIO, // AUDIO (bInterfaceClass)
AUDIO_SUBCLASS_AUDIOSTREAMING, // AUDIO_STREAMING (bInterfaceSubclass)
AUDIO_PROTOCOL_UNDEFINED, // Unused. (bInterfaceProtocol)
0x00, // Unused. (iInterface)
/* USB Microphone Standard AS Interface Descriptor (Alt. Set. 1) (CODE == 4)*/
/*
* Microphone Standard AS Interface Descriptor - Audio Streaming Zero Bandwith
* Interface 1, Alternate Setting 1
*/
AUDIO_INTERFACE_DESC_SIZE, // Size of the descriptor, in bytes (bLength)
USB_DESC_TYPE_INTERFACE, // INTERFACE descriptor type (bDescriptorType)
AUDIO_IN_IF, // Index of this interface. (bInterfaceNumber)
0x01, // Index of this alternate setting. (bAlternateSetting)
0x01, // 1 endpoint (bNumEndpoints)
USB_DEVICE_CLASS_AUDIO, // AUDIO (bInterfaceClass)
AUDIO_SUBCLASS_AUDIOSTREAMING, // AUDIO_STREAMING (bInterfaceSubclass)
AUDIO_PROTOCOL_UNDEFINED, // Unused. (bInterfaceProtocol)
0x00, // Unused. (iInterface)
/* USB Microphone Class-specific AS General Interface Descriptor (CODE == 5)*/
AUDIO_STREAMING_INTERFACE_DESC_SIZE, // Size of the descriptor, in bytes (bLength)
AUDIO_INTERFACE_DESCRIPTOR_TYPE, // CS_INTERFACE Descriptor Type (bDescriptorType) 0x24
AUDIO_STREAMING_GENERAL, // GENERAL subtype (bDescriptorSubtype) 0x01
0x05, // Unit ID of the Output Terminal.(bTerminalLink)
0x01, // Interface delay. (bDelay)
0x01,0x00, // PCM Format (wFormatTag)
/* USB Microphone Type I Format Type Descriptor (CODE == 6)*/
/* Microphone Audio Type I Format Interface Descriptor */
0x0B, // Size of the descriptor, in bytes (bLength)
AUDIO_INTERFACE_DESCRIPTOR_TYPE,// CS_INTERFACE Descriptor Type (bDescriptorType) 0x24
AUDIO_STREAMING_FORMAT_TYPE, // FORMAT_TYPE subtype. (bDescriptorSubtype) 0x02
0x01, // FORMAT_TYPE_I. (bFormatType)
USBD_AUDIO_IN_CHANNELS, // One or two channel.(bNrChannels)
0x02, // Two bytes per audio subframe.(bSubFrameSize)
0x10, // 16 bits per sample.(bBitResolution)
0x01, // One frequency supported. (bSamFreqType)
(USBD_AUDIO_IN_FREQ&0xFF),((USBD_AUDIO_IN_FREQ>>8)&0xFF),0x00, // (tSamFreq) (NOT COMPLETE!!!)
/* USB Microphone Standard Endpoint Descriptor (CODE == 8)*/ //Standard AS Isochronous Audio Data Endpoint Descriptor
/* Endpoint 1 - Standard Descriptor */
AUDIO_STANDARD_ENDPOINT_DESC_SIZE, // Size of the descriptor, in bytes (bLength)
USB_DESC_TYPE_ENDPOINT, // ENDPOINT descriptor (bDescriptorType)
AUDIO_IN_EP, // IN Endpoint 1. (bEndpointAddress)
USB_ENDPOINT_TYPE_ISOCHRONOUS, // Isochronous, not shared. (bmAttributes)//USB_ENDPOINT_TYPE_asynchronous USB_ENDPOINT_TYPE_ISOCHRONOUS
(AUDIO_IN_PACKET&0xFF),((AUDIO_IN_PACKET>>8)&0xFF), //bytes per packet (wMaxPacketSize)
0x01, // One packet per frame.(bInterval)
0x00, // Unused. (bRefresh)
0x00, // Unused. (bSynchAddress)
/* USB Microphone Class-specific Isoc. Audio Data Endpoint Descriptor */
0x07, // Size of the descriptor, in bytes (bLength)
AUDIO_ENDPOINT_DESCRIPTOR_TYPE, // CS_ENDPOINT Descriptor Type (bDescriptorType) 0x25
AUDIO_ENDPOINT_GENERAL, // GENERAL subtype. (bDescriptorSubtype) 0x01
0x00, // No sampling frequency control, no pitch control, no packet padding.(bmAttributes)
0x00, // Unused. (bLockDelayUnits)
0x00,0x00, // Unused. (wLockDelay)
} ;
const usbd_ep_map_t usbdEpMap =
{
.in = { CLASS_UNUSED, CLASS_CDC, CLASS_CDC, CLASS_AUDIO },
.out = { CLASS_UNUSED, CLASS_CDC, CLASS_AUDIO, CLASS_UNUSED }
};
USBD_ClassCompInfo dev_instance[CLASS_NUM] =
{
{
.class = &USBD_AUDIO,
.userData = &USBD_AUDIO_fops_FS,
.ctrlIf = AUDIO_CTRL_IF,
.minIf = AUDIO_CTRL_IF,
.maxIf = AUDIO_IN_IF
},
{
.class = &USBD_CDC,
.userData = &USBD_Interface_fops_FS,
.ctrlIf = CDC_CTRL_IF,
.minIf = CDC_CTRL_IF,
.maxIf = CDC_DATA_IF
}
};
@@ -0,0 +1,172 @@
/**
******************************************************************************
* @file USBD_COMP_cdc_comp.h
* @author MCD Application Team/ mcHF Devel
* @version V2.4.2
* @date 11-December-2015
* @brief header file for the USBD_COMP.c file.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USB_COMPOSITE_H
#define __USB_COMPOSITE_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "usbd_ioreq.h"
/** @addtogroup STM32_USB_DEVICE_LIBRARY
* @{
*/
/** @defgroup USBD_COMP
* @brief This file is the Header file for USBD_COMP.c
* @{
*/
/** @defgroup USBD_COMP_Exported_Defines
* @{
*/
/**
* @}
*/
/** @defgroup USBD_CORE_Exported_TypesDefinitions
* @{
*/
typedef struct
{
USBD_ClassTypeDef* class;
void* classData;
void* userData;
uint16_t ctrlIf;
uint16_t minIf;
uint16_t maxIf;
} USBD_ClassCompInfo;
#define USBD_MAX_EP 3
typedef struct
{
uint8_t in[USBD_MAX_EP+1];
uint8_t out[USBD_MAX_EP+1];
} usbd_ep_map_t;
#define CLASS_AUDIO 0
#define CLASS_CDC 1
#define CLASS_NUM 2
#define CLASS_UNUSED 0xFF
extern usbd_ep_map_t usbdEpMap;
extern USBD_ClassCompInfo dev_instance[CLASS_NUM];
#define USB_AUDIO_CONFIG_DESC_SIZ (9+101+73 + 8 + 66 + 9 +7)
extern uint8_t USBD_COMP_CfgDesc[USB_AUDIO_CONFIG_DESC_SIZ];
typedef struct
{
}
USBD_COMP_HandleTypeDef;
typedef struct
{
}USBD_COMP_ItfTypeDef;
/**
* @}
*/
/** @defgroup USBD_CORE_Exported_Macros
* @{
*/
#define AUDIO_DESCRIPTOR_TYPE 0x21
#define USB_DEVICE_CLASS_AUDIO 0x01
#define AUDIO_SUBCLASS_AUDIOCONTROL 0x01
#define AUDIO_SUBCLASS_AUDIOSTREAMING 0x02
#define AUDIO_PROTOCOL_UNDEFINED 0x00
#define AUDIO_STREAMING_GENERAL 0x01
#define AUDIO_STREAMING_FORMAT_TYPE 0x02
/* Audio Descriptor Types */
#define AUDIO_INTERFACE_DESCRIPTOR_TYPE 0x24
#define AUDIO_ENDPOINT_DESCRIPTOR_TYPE 0x25
/* Audio Control Interface Descriptor Subtypes */
#define AUDIO_CONTROL_HEADER 0x01
#define AUDIO_CONTROL_INPUT_TERMINAL 0x02
#define AUDIO_CONTROL_OUTPUT_TERMINAL 0x03
#define AUDIO_CONTROL_FEATURE_UNIT 0x06
#define AUDIO_INTERFACE_DESC_SIZE 9
#define USB_AUDIO_DESC_SIZ 0x09
#define AUDIO_STANDARD_ENDPOINT_DESC_SIZE 0x09
#define AUDIO_STREAMING_ENDPOINT_DESC_SIZE 0x07
/**
* @}
*/
/** @defgroup USBD_CORE_Exported_Variables
* @{
*/
extern USBD_ClassTypeDef USBD_COMP;
#define USBD_COMP_CLASS &USBD_COMP
/**
* @}
*/
/** @defgroup USB_CORE_Exported_Functions
* @{
*/
uint8_t USBD_COMP_RegisterInterface (USBD_HandleTypeDef *pdev,
USBD_COMP_ItfTypeDef *fops);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* __USB_COMPOSITE_H */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/