From 438258fb3e31a1240f35148c9ce5f2f17f5390dc Mon Sep 17 00:00:00 2001 From: Phil Tokumaru Date: Fri, 23 Aug 2024 08:19:17 -0700 Subject: [PATCH] Consolidated USB driver files and specialized to only ACM --- common/AL94_USB_Composite/App/usb_device.c | 168 -- common/AL94_USB_Composite/App/usb_device.h | 105 - .../AL94_USB_Composite/App/usbd_cdc_acm_if.c | 541 ---- .../AL94_USB_Composite/App/usbd_cdc_acm_if.h | 131 - common/AL94_USB_Composite/App/usbd_desc.c | 415 ---- common/AL94_USB_Composite/App/usbd_desc.h | 146 -- .../Class/CDC_ACM/Inc/usbd_cdc_acm.h | 180 -- .../Class/CDC_ACM/Src/usbd_cdc_acm.c | 2175 ----------------- .../Class/COMPOSITE/Inc/usbd_composite.h | 151 -- .../Class/COMPOSITE/Src/usbd_composite.c | 1133 --------- .../AL94_USB_Composite/Core/Inc/usbd_core.h | 149 -- .../AL94_USB_Composite/Core/Inc/usbd_ctlreq.h | 99 - common/AL94_USB_Composite/Core/Inc/usbd_def.h | 429 ---- .../AL94_USB_Composite/Core/Inc/usbd_ioreq.h | 107 - .../AL94_USB_Composite/Core/Src/usbd_core.c | 673 ----- .../AL94_USB_Composite/Core/Src/usbd_ctlreq.c | 928 ------- common/AL94_USB_Composite/Target/usbd_conf.h | 176 -- .../AL94.I-CUBE-USBD-COMPOSITE_conf.h-ignore | 180 +- .../LICENSE.txt | 40 +- common/USB_AL94/usb_device.c | 58 + common/USB_AL94/usb_device.h | 41 + common/USB_AL94/usbd_cdc.c | 2052 ++++++++++++++++ common/USB_AL94/usbd_cdc.h | 151 ++ common/USB_AL94/usbd_cdc_if.c | 238 ++ common/USB_AL94/usbd_cdc_if.h | 39 + common/USB_AL94/usbd_composite.c | 366 +++ common/USB_AL94/usbd_composite.h | 58 + .../Target => USB_AL94}/usbd_conf.c | 1632 ++++++------- common/USB_AL94/usbd_conf.h | 106 + common/USB_AL94/usbd_core.c | 517 ++++ common/USB_AL94/usbd_core.h | 93 + common/USB_AL94/usbd_ctlreq.c | 801 ++++++ common/USB_AL94/usbd_ctlreq.h | 43 + common/USB_AL94/usbd_def.h | 385 +++ common/USB_AL94/usbd_desc.c | 270 ++ common/USB_AL94/usbd_desc.h | 47 + .../Core/Src => USB_AL94}/usbd_ioreq.c | 363 ++- common/USB_AL94/usbd_ioreq.h | 49 + 38 files changed, 6389 insertions(+), 8846 deletions(-) delete mode 100644 common/AL94_USB_Composite/App/usb_device.c delete mode 100644 common/AL94_USB_Composite/App/usb_device.h delete mode 100644 common/AL94_USB_Composite/App/usbd_cdc_acm_if.c delete mode 100644 common/AL94_USB_Composite/App/usbd_cdc_acm_if.h delete mode 100644 common/AL94_USB_Composite/App/usbd_desc.c delete mode 100644 common/AL94_USB_Composite/App/usbd_desc.h delete mode 100644 common/AL94_USB_Composite/Class/CDC_ACM/Inc/usbd_cdc_acm.h delete mode 100644 common/AL94_USB_Composite/Class/CDC_ACM/Src/usbd_cdc_acm.c delete mode 100644 common/AL94_USB_Composite/Class/COMPOSITE/Inc/usbd_composite.h delete mode 100644 common/AL94_USB_Composite/Class/COMPOSITE/Src/usbd_composite.c delete mode 100644 common/AL94_USB_Composite/Core/Inc/usbd_core.h delete mode 100644 common/AL94_USB_Composite/Core/Inc/usbd_ctlreq.h delete mode 100644 common/AL94_USB_Composite/Core/Inc/usbd_def.h delete mode 100644 common/AL94_USB_Composite/Core/Inc/usbd_ioreq.h delete mode 100644 common/AL94_USB_Composite/Core/Src/usbd_core.c delete mode 100644 common/AL94_USB_Composite/Core/Src/usbd_ctlreq.c delete mode 100644 common/AL94_USB_Composite/Target/usbd_conf.h rename common/{AL94_USB_Composite => USB_AL94}/AL94.I-CUBE-USBD-COMPOSITE_conf.h-ignore (96%) rename common/{AL94_USB_Composite => USB_AL94}/LICENSE.txt (98%) create mode 100644 common/USB_AL94/usb_device.c create mode 100644 common/USB_AL94/usb_device.h create mode 100644 common/USB_AL94/usbd_cdc.c create mode 100644 common/USB_AL94/usbd_cdc.h create mode 100644 common/USB_AL94/usbd_cdc_if.c create mode 100644 common/USB_AL94/usbd_cdc_if.h create mode 100644 common/USB_AL94/usbd_composite.c create mode 100644 common/USB_AL94/usbd_composite.h rename common/{AL94_USB_Composite/Target => USB_AL94}/usbd_conf.c (96%) create mode 100644 common/USB_AL94/usbd_conf.h create mode 100644 common/USB_AL94/usbd_core.c create mode 100644 common/USB_AL94/usbd_core.h create mode 100644 common/USB_AL94/usbd_ctlreq.c create mode 100644 common/USB_AL94/usbd_ctlreq.h create mode 100644 common/USB_AL94/usbd_def.h create mode 100644 common/USB_AL94/usbd_desc.c create mode 100644 common/USB_AL94/usbd_desc.h rename common/{AL94_USB_Composite/Core/Src => USB_AL94}/usbd_ioreq.c (50%) create mode 100644 common/USB_AL94/usbd_ioreq.h diff --git a/common/AL94_USB_Composite/App/usb_device.c b/common/AL94_USB_Composite/App/usb_device.c deleted file mode 100644 index e40d973..0000000 --- a/common/AL94_USB_Composite/App/usb_device.c +++ /dev/null @@ -1,168 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : usb_device.c - * @version : v1.0_Cube - * @brief : This file implements the USB Device - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * 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 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ - -#include "usb_device.h" -#include "usbd_desc.h" - -/* USER CODE BEGIN Includes */ -#include "usbd_composite.h" -/* USER CODE END Includes */ - -/* USER CODE BEGIN PV */ -/* Private variables ---------------------------------------------------------*/ - -/* USER CODE END PV */ - -/* USER CODE BEGIN PFP */ -/* Private function prototypes -----------------------------------------------*/ - -/* USER CODE END PFP */ - -/* USB Device Core handle declaration. */ -USBD_HandleTypeDef hUsbDevice; - -/* - * -- Insert your variables declaration here -- - */ -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* - * -- Insert your external function declaration here -- - */ -/* USER CODE BEGIN 1 */ - -/* USER CODE END 1 */ - -/** - * Init USB device Library, add supported class and start the library - * @retval None - */ -void MX_USB_DEVICE_Init (void) -{ - /* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */ - - /* USER CODE END USB_DEVICE_Init_PreTreatment */ - - /* Init Device Library, add supported class and start the library. */ - USBD_COMPOSITE_Mount_Class (); - -#if (USBD_USE_HS == 1) - if (USBD_Init(&hUsbDevice, &USBD_Desc, DEVICE_HS) != USBD_OK) - { - Error_Handler(); - } -#else - if (USBD_Init (&hUsbDevice, &USBD_Desc, DEVICE_FS) != USBD_OK) - { - Error_Handler (); - } -#endif - if (USBD_RegisterClass (&hUsbDevice, &USBD_COMPOSITE) != USBD_OK) - { - Error_Handler (); - } -#if (USBD_USE_CDC_ACM == 1) - if (USBD_CDC_ACM_RegisterInterface (&hUsbDevice, &USBD_CDC_ACM_fops) != USBD_OK) - { - Error_Handler (); - } -#endif -#if (USBD_USE_CDC_RNDIS == 1) - if (USBD_CDC_RNDIS_RegisterInterface(&hUsbDevice, &USBD_CDC_RNDIS_fops) != USBD_OK) - { - Error_Handler(); - } -#endif -#if (USBD_USE_CDC_ECM == 1) - if (USBD_CDC_ECM_RegisterInterface(&hUsbDevice, &USBD_CDC_ECM_fops) != USBD_OK) - { - Error_Handler(); - } -#endif -#if (USBD_USE_HID_MOUSE == 1) -#endif -#if (USBD_USE_HID_KEYBOARD == 1) -#endif -#if (USBD_USE_HID_CUSTOM == 1) - if (USBD_CUSTOM_HID_RegisterInterface(&hUsbDevice, &USBD_CustomHID_fops) != USBD_OK) - { - Error_Handler(); - } -#endif -#if (USBD_USE_UAC_MIC == 1) - if (USBD_AUDIO_MIC_RegisterInterface(&hUsbDevice, &USBD_AUDIO_MIC_fops_FS) != USBD_OK) - { - Error_Handler(); - } -#endif -#if (USBD_USE_UAC_SPKR == 1) - if (USBD_AUDIO_SPKR_RegisterInterface(&hUsbDevice, &USBD_AUDIO_SPKR_fops) != USBD_OK) - { - Error_Handler(); - } -#endif -#if (USBD_USE_UVC == 1) - if (USBD_VIDEO_RegisterInterface(&hUsbDevice, &USBD_VIDEO_fops_FS) != USBD_OK) - { - Error_Handler(); - } -#endif -#if (USBD_USE_MSC == 1) - if (USBD_MSC_RegisterStorage(&hUsbDevice, &USBD_Storage_Interface_fops) != USBD_OK) - { - Error_Handler(); - } -#endif -#if (USBD_USE_DFU == 1) - if (USBD_DFU_RegisterMedia(&hUsbDevice, &USBD_DFU_fops) != USBD_OK) - { - Error_Handler(); - } -#endif -#if (USBD_USE_PRNTR == 1) - if (USBD_PRNT_RegisterInterface(&hUsbDevice, &USBD_PRNT_fops) != USBD_OK) - { - Error_Handler(); - } -#endif - if (USBD_Start (&hUsbDevice) != USBD_OK) - { - Error_Handler (); - } - - /* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */ - - /* USER CODE END USB_DEVICE_Init_PostTreatment */ -} - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/AL94_USB_Composite/App/usb_device.h b/common/AL94_USB_Composite/App/usb_device.h deleted file mode 100644 index 065711d..0000000 --- a/common/AL94_USB_Composite/App/usb_device.h +++ /dev/null @@ -1,105 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : usb_device.h - * @version : v1.0_Cube - * @brief : Header for usb_device.c file. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * 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 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USB_DEVICE__H__ -#define __USB_DEVICE__H__ - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* Includes ------------------------------------------------------------------*/ -#include "main.h" -#include "usbd_def.h" - - /* USER CODE BEGIN INCLUDE */ - - /* USER CODE END INCLUDE */ - - /** @addtogroup USBD_OTG_DRIVER - * @{ - */ - - /** @defgroup USBD_DEVICE USBD_DEVICE - * @brief Device file for Usb otg low level driver. - * @{ - */ - - /** @defgroup USBD_DEVICE_Exported_Variables USBD_DEVICE_Exported_Variables - * @brief Public variables. - * @{ - */ - - /* Private variables ---------------------------------------------------------*/ - /* USER CODE BEGIN PV */ - - /* USER CODE END PV */ - - /* Private function prototypes -----------------------------------------------*/ - /* USER CODE BEGIN PFP */ - - /* USER CODE END PFP */ - - /* - * -- Insert your variables declaration here -- - */ - /* USER CODE BEGIN VARIABLES */ - - /* USER CODE END VARIABLES */ - /** - * @} - */ - - /** @defgroup USBD_DEVICE_Exported_FunctionsPrototype USBD_DEVICE_Exported_FunctionsPrototype - * @brief Declaration of public functions for Usb device. - * @{ - */ - - /** USB Device initialization function. */ - void MX_USB_DEVICE_Init (void); - -/* - * -- Insert functions declaration here -- - */ -/* USER CODE BEGIN FD */ - -/* USER CODE END FD */ -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USB_DEVICE__H__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/AL94_USB_Composite/App/usbd_cdc_acm_if.c b/common/AL94_USB_Composite/App/usbd_cdc_acm_if.c deleted file mode 100644 index 771779e..0000000 --- a/common/AL94_USB_Composite/App/usbd_cdc_acm_if.c +++ /dev/null @@ -1,541 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : usbd_cdc_if.c - * @version : v2.0_Cube - * @brief : Usb device for Virtual Com Port. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.

- * - * 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 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_cdc_acm_if.h" - -/* USER CODE BEGIN INCLUDE */ -//#include "usart.h" -//#include "tim.h" -#include -/* USER CODE END INCLUDE */ - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ - -/* USER CODE BEGIN PV */ -/* Private variables ---------------------------------------------------------*/ - -/* USER CODE END PV */ - -/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY - * @brief Usb device library. - * @{ - */ - -/** @addtogroup USBD_CDC_IF - * @{ - */ - -/** @defgroup USBD_CDC_IF_Private_TypesDefinitions USBD_CDC_IF_Private_TypesDefinitions - * @brief Private types. - * @{ - */ - -/* USER CODE BEGIN PRIVATE_TYPES */ - -/* USER CODE END PRIVATE_TYPES */ - -/** - * @} - */ - -/** @defgroup USBD_CDC_IF_Private_Defines USBD_CDC_IF_Private_Defines - * @brief Private defines. - * @{ - */ - -/* USER CODE BEGIN PRIVATE_DEFINES */ -/* USER CODE END PRIVATE_DEFINES */ - -/** - * @} - */ - -/** @defgroup USBD_CDC_IF_Private_Macros USBD_CDC_IF_Private_Macros - * @brief Private macros. - * @{ - */ - -/* USER CODE BEGIN PRIVATE_MACRO */ - -/* USER CODE END PRIVATE_MACRO */ - -/** - * @} - */ - -/** @defgroup USBD_CDC_IF_Private_Variables USBD_CDC_IF_Private_Variables - * @brief Private variables. - * @{ - */ - -/* USER CODE BEGIN PRIVATE_VARIABLES */ - -#define APP_RX_DATA_SIZE 128 -//#define APP_TX_DATA_SIZE 128 - -/** RX buffer for USB */ -uint8_t RX_Buffer[NUMBER_OF_CDC][APP_RX_DATA_SIZE]; - -/** TX buffer for USB, RX buffer for UART */ -//uint8_t TX_Buffer[NUMBER_OF_CDC][APP_TX_DATA_SIZE]; -USBD_CDC_ACM_LineCodingTypeDef Line_Coding[NUMBER_OF_CDC]; - -uint32_t Write_Index[NUMBER_OF_CDC]; /* keep track of received data over UART */ -uint32_t Read_Index[NUMBER_OF_CDC]; /* keep track of sent data to USB */ - -/* USER CODE END PRIVATE_VARIABLES */ - -/** - * @} - */ - -/** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables - * @brief Public variables. - * @{ - */ - -extern USBD_HandleTypeDef hUsbDevice; - -/* USER CODE BEGIN EXPORTED_VARIABLES */ - -/* USER CODE END EXPORTED_VARIABLES */ - -/** - * @} - */ - -/** @defgroup USBD_CDC_IF_Private_FunctionPrototypes USBD_CDC_IF_Private_FunctionPrototypes - * @brief Private functions declaration. - * @{ - */ - -static int8_t CDC_Init (uint8_t cdc_ch); -static int8_t CDC_DeInit (uint8_t cdc_ch); -static int8_t CDC_Control (uint8_t cdc_ch, uint8_t cmd, uint8_t *pbuf, uint16_t length); -static int8_t CDC_Receive (uint8_t cdc_ch, uint8_t *pbuf, uint32_t *Len); -static int8_t CDC_TransmitCplt (uint8_t cdc_ch, uint8_t *Buf, uint32_t *Len, uint8_t epnum); - -/* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */ -//UART_HandleTypeDef *CDC_CH_To_UART_Handle(uint8_t cdc_ch) -//{ -// UART_HandleTypeDef *handle = NULL; -// -// if (cdc_ch == 0) -// { -// handle = &huart1; -// } -//#if (0) -// else if (cdc_ch == 1) -// { -// handle = &huart2; -// } -// else if (cdc_ch == 2) -// { -// handle = &huart3; -// } -//#endif -// return handle; -//} -// -//uint8_t UART_Handle_TO_CDC_CH(UART_HandleTypeDef *handle) -//{ -// uint8_t cdc_ch = 0; -// -// if (handle == &huart1) -// { -// cdc_ch = 0; -// } -//#if (0) -// else if (handle == &huart2) -// { -// cdc_ch = 1; -// } -// else if (handle == &huart3) -// { -// cdc_ch = 2; -// } -//#endif -// return cdc_ch; -//} -// -//void Change_UART_Setting(uint8_t cdc_ch) -//{ -// UART_HandleTypeDef *handle = CDC_CH_To_UART_Handle(cdc_ch); -// -// if (HAL_UART_DeInit(handle) != HAL_OK) -// { -// /* Initialization Error */ -// Error_Handler(); -// } -// /* set the Stop bit */ -// switch (Line_Coding[cdc_ch].format) -// { -// case 0: -// handle->Init.StopBits = UART_STOPBITS_1; -// break; -// case 2: -// handle->Init.StopBits = UART_STOPBITS_2; -// break; -// default: -// handle->Init.StopBits = UART_STOPBITS_1; -// break; -// } -// -// /* set the parity bit*/ -// switch (Line_Coding[cdc_ch].paritytype) -// { -// case 0: -// handle->Init.Parity = UART_PARITY_NONE; -// break; -// case 1: -// handle->Init.Parity = UART_PARITY_ODD; -// break; -// case 2: -// handle->Init.Parity = UART_PARITY_EVEN; -// break; -// default: -// handle->Init.Parity = UART_PARITY_NONE; -// break; -// } -// -// /*set the data type : only 8bits and 9bits is supported */ -// switch (Line_Coding[cdc_ch].datatype) -// { -// case 0x07: -// /* With this configuration a parity (Even or Odd) must be set */ -// handle->Init.WordLength = UART_WORDLENGTH_8B; -// break; -// case 0x08: -// if (handle->Init.Parity == UART_PARITY_NONE) -// { -// handle->Init.WordLength = UART_WORDLENGTH_8B; -// } -// else -// { -// handle->Init.WordLength = UART_WORDLENGTH_9B; -// } -// -// break; -// default: -// handle->Init.WordLength = UART_WORDLENGTH_8B; -// break; -// } -// -// if (Line_Coding[cdc_ch].bitrate == 0) -// { -// Line_Coding[cdc_ch].bitrate = 115200; -// } -// -// handle->Init.BaudRate = Line_Coding[cdc_ch].bitrate; -// handle->Init.HwFlowCtl = UART_HWCONTROL_NONE; -// handle->Init.Mode = UART_MODE_TX_RX; -// handle->Init.OverSampling = UART_OVERSAMPLING_16; -// -// if (HAL_UART_Init(handle) != HAL_OK) -// { -// /* Initialization Error */ -// Error_Handler(); -// } -// -// /** rx for uart and tx buffer of usb */ -// if (HAL_UART_Receive_IT(handle, TX_Buffer[cdc_ch], 1) != HAL_OK) -// { -// /* Transfer error in reception process */ -// Error_Handler(); -// } -//} -/* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */ - -/** - * @} - */ - -USBD_CDC_ACM_ItfTypeDef USBD_CDC_ACM_fops = -{ CDC_Init, CDC_DeInit, CDC_Control, CDC_Receive, CDC_TransmitCplt }; - -/* Private functions ---------------------------------------------------------*/ -/** - * @brief Initializes the CDC media low layer over the FS USB IP - * @retval USBD_OK if all operations are OK else USBD_FAIL - */ -static int8_t CDC_Init (uint8_t cdc_ch) -{ - /* USER CODE BEGIN 3 */ - - /* ##-1- Set Application Buffers */ - USBD_CDC_SetRxBuffer (cdc_ch, &hUsbDevice, RX_Buffer[cdc_ch]); - - // /*##-2- Start the TIM Base generation in interrupt mode ####################*/ - // /* Start Channel1 */ - // if (HAL_TIM_Base_Start_IT(&htim4) != HAL_OK) - // { - // /* Starting Error */ - // Error_Handler(); - // } - - return (USBD_OK); - /* USER CODE END 3 */ -} - -/** - * @brief DeInitializes the CDC media low layer - * @retval USBD_OK if all operations are OK else USBD_FAIL - */ -static int8_t CDC_DeInit (uint8_t cdc_ch) -{ - /* USER CODE BEGIN 4 */ - /* DeInitialize the UART peripheral */ - // if (HAL_UART_DeInit(CDC_CH_To_UART_Handle(cdc_ch)) != HAL_OK) - // { - // /* Initialization Error */ - // Error_Handler(); - // } - return (USBD_OK); - /* USER CODE END 4 */ -} - -/** - * @brief Manage the CDC class requests - * @param cmd: Command code - * @param pbuf: Buffer containing command data (request parameters) - * @param length: Number of data to be sent (in bytes) - * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL - */ -static int8_t CDC_Control (uint8_t cdc_ch, uint8_t cmd, uint8_t *pbuf, uint16_t length) -{ - /* USER CODE BEGIN 5 */ - switch (cmd) - { - case CDC_SEND_ENCAPSULATED_COMMAND: - - break; - - case CDC_GET_ENCAPSULATED_RESPONSE: - - break; - - case CDC_SET_COMM_FEATURE: - - break; - - case CDC_GET_COMM_FEATURE: - - break; - - case CDC_CLEAR_COMM_FEATURE: - - break; - - /*******************************************************************************/ - /* Line Coding Structure */ - /*-----------------------------------------------------------------------------*/ - /* Offset | Field | Size | Value | Description */ - /* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/ - /* 4 | bCharFormat | 1 | Number | Stop bits */ - /* 0 - 1 Stop bit */ - /* 1 - 1.5 Stop bits */ - /* 2 - 2 Stop bits */ - /* 5 | bParityType | 1 | Number | Parity */ - /* 0 - None */ - /* 1 - Odd */ - /* 2 - Even */ - /* 3 - Mark */ - /* 4 - Space */ - /* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */ - /*******************************************************************************/ - case CDC_SET_LINE_CODING: - Line_Coding[cdc_ch].bitrate = (uint32_t) (pbuf[0] | (pbuf[1] << 8) | (pbuf[2] << 16) | (pbuf[3] << 24)); - Line_Coding[cdc_ch].format = pbuf[4]; - Line_Coding[cdc_ch].paritytype = pbuf[5]; - Line_Coding[cdc_ch].datatype = pbuf[6]; - - //Change_UART_Setting(cdc_ch); - break; - - case CDC_GET_LINE_CODING: - pbuf[0] = (uint8_t) (Line_Coding[cdc_ch].bitrate); - pbuf[1] = (uint8_t) (Line_Coding[cdc_ch].bitrate >> 8); - pbuf[2] = (uint8_t) (Line_Coding[cdc_ch].bitrate >> 16); - pbuf[3] = (uint8_t) (Line_Coding[cdc_ch].bitrate >> 24); - pbuf[4] = Line_Coding[cdc_ch].format; - pbuf[5] = Line_Coding[cdc_ch].paritytype; - pbuf[6] = Line_Coding[cdc_ch].datatype; - break; - - case CDC_SET_CONTROL_LINE_STATE: - - break; - - case CDC_SEND_BREAK: - - break; - - default: - break; - } - - return (USBD_OK); - /* USER CODE END 5 */ -} - -/** - * @brief Data received over USB OUT endpoint are sent over CDC interface - * through this function. - * - * @note - * This function will issue a NAK packet on any OUT packet received on - * USB endpoint until exiting this function. If you exit this function - * before transfer is complete on CDC interface (ie. using DMA controller) - * it will result in receiving more data while previous ones are still - * not sent. - * - * @param Buf: Buffer of data to be received - * @param Len: Number of data received (in bytes) - * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL - */ -static int8_t CDC_Receive (uint8_t cdc_ch, uint8_t *Buf, uint32_t *Len) -{ - /* USER CODE BEGIN 6 */ - //HAL_UART_Transmit_DMA(CDC_CH_To_UART_Handle(cdc_ch), Buf, *Len); -// CDC_Transmit(cdc_ch, Buf, *Len); // echo back on same channel - CDC_Receive_Callback (cdc_ch, Buf, *Len); //NOTE! AL94 USB CDC. We implement this. - - USBD_CDC_SetRxBuffer (cdc_ch, &hUsbDevice, &Buf[0]); - USBD_CDC_ReceivePacket (cdc_ch, &hUsbDevice); - return (USBD_OK); - /* USER CODE END 6 */ -} - -/** - * @brief CDC_TransmitCplt_FS - * Data transmited callback - * - * @note - * This function is IN transfer complete callback used to inform user that - * the submitted Data is successfully sent over USB. - * - * @param Buf: Buffer of data to be received - * @param Len: Number of data received (in bytes) - * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL - */ -static int8_t CDC_TransmitCplt (uint8_t cdc_ch, uint8_t *Buf, uint32_t *Len, uint8_t epnum) -{ - CDC_TransmitCplt_Callback (0, Buf, (uint16_t) (*Len)); //NOTE! AL94 USB CDC. We implement this. - - return (USBD_OK); -} - -/** - * @brief CDC_Transmit - * Data to send over USB IN endpoint are sent over CDC interface - * through this function. - * @note - * - * - * @param Buf: Buffer of data to be sent - * @param Len: Number of data to be sent (in bytes) - * @retval USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY - */ -uint8_t CDC_Transmit (uint8_t ch, uint8_t *Buf, uint16_t Len) -{ - uint8_t result = USBD_OK; - /* USER CODE BEGIN 7 */ - extern USBD_CDC_ACM_HandleTypeDef CDC_ACM_Class_Data[]; - USBD_CDC_ACM_HandleTypeDef *hcdc = NULL; - hcdc = &CDC_ACM_Class_Data[ch]; - if (hcdc->TxState != 0) - { - return USBD_BUSY; - } - USBD_CDC_SetTxBuffer (ch, &hUsbDevice, Buf, Len); - result = USBD_CDC_TransmitPacket (ch, &hUsbDevice); - /* USER CODE END 7 */ - return result; -} - -/* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */ -//void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) -//{ -// /* Initiate next USB packet transfer once UART completes transfer (transmitting data over Tx line) */ -// //USBD_CDC_ReceivePacket(UART_Handle_TO_CDC_CH(huart), &hUsbDevice); -//} -//void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) -//{ -// for (uint8_t i = 0; i < NUMBER_OF_CDC; i++) -// { -// uint32_t buffptr; -// uint32_t buffsize; -// -// if (Read_Index[i] != Write_Index[i]) -// { -// if (Read_Index[i] > Write_Index[i]) /* Rollback */ -// { -// buffsize = APP_TX_DATA_SIZE - Read_Index[i]; -// } -// else -// { -// buffsize = Write_Index[i] - Read_Index[i]; -// } -// -// buffptr = Read_Index[i]; -// -// USBD_CDC_SetTxBuffer(i, &hUsbDevice, &TX_Buffer[i][buffptr], buffsize); -// -// if (USBD_CDC_TransmitPacket(i, &hUsbDevice) == USBD_OK) -// { -// Read_Index[i] += buffsize; -// if (Read_Index[i] == APP_RX_DATA_SIZE) -// { -// Read_Index[i] = 0; -// } -// } -// } -// } -//} -//void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) -//{ -// uint8_t cdc_ch = UART_Handle_TO_CDC_CH(huart); -// /* Increment Index for buffer writing */ -// Write_Index[cdc_ch]++; -// -// /* To avoid buffer overflow */ -// if (Write_Index[cdc_ch] == APP_RX_DATA_SIZE) -// { -// Write_Index[cdc_ch] = 0; -// } -// -// /* Start another reception: provide the buffer pointer with offset and the buffer size */ -// HAL_UART_Receive_IT(huart, (TX_Buffer[cdc_ch] + Write_Index[cdc_ch]), 1); -//} -/* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */ - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/AL94_USB_Composite/App/usbd_cdc_acm_if.h b/common/AL94_USB_Composite/App/usbd_cdc_acm_if.h deleted file mode 100644 index 8a20ad2..0000000 --- a/common/AL94_USB_Composite/App/usbd_cdc_acm_if.h +++ /dev/null @@ -1,131 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : usbd_cdc_acm_if.h - * @version : v2.0_Cube - * @brief : Header for usbd_cdc_if.c file. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.

- * - * 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 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USBD_CDC_ACM_IF_H__ -#define __USBD_CDC_ACM_IF_H__ - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* Includes ------------------------------------------------------------------*/ -#include "usbd_cdc_acm.h" - - /* USER CODE BEGIN INCLUDE */ - - /* USER CODE END INCLUDE */ - - /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY - * @brief For Usb device. - * @{ - */ - - /** @defgroup USBD_CDC_IF USBD_CDC_IF - * @brief Usb VCP device module - * @{ - */ - - /** @defgroup USBD_CDC_IF_Exported_Defines USBD_CDC_IF_Exported_Defines - * @brief Defines. - * @{ - */ - /* USER CODE BEGIN EXPORTED_DEFINES */ - - /* USER CODE END EXPORTED_DEFINES */ - - /** - * @} - */ - - /** @defgroup USBD_CDC_IF_Exported_Types USBD_CDC_IF_Exported_Types - * @brief Types. - * @{ - */ - - /* USER CODE BEGIN EXPORTED_TYPES */ - - /* USER CODE END EXPORTED_TYPES */ - - /** - * @} - */ - - /** @defgroup USBD_CDC_IF_Exported_Macros USBD_CDC_IF_Exported_Macros - * @brief Aliases. - * @{ - */ - - /* USER CODE BEGIN EXPORTED_MACRO */ - - /* USER CODE END EXPORTED_MACRO */ - - /** - * @} - */ - - /** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables - * @brief Public variables. - * @{ - */ - - /** CDC Interface callback. */ - extern USBD_CDC_ACM_ItfTypeDef USBD_CDC_ACM_fops; - - /* USER CODE BEGIN EXPORTED_VARIABLES */ - - /* USER CODE END EXPORTED_VARIABLES */ - - /** - * @} - */ - - /** @defgroup USBD_CDC_IF_Exported_FunctionsPrototype USBD_CDC_IF_Exported_FunctionsPrototype - * @brief Public functions declaration. - * @{ - */ - - uint8_t CDC_Transmit (uint8_t ch, uint8_t *Buf, uint16_t Len); - -/* USER CODE BEGIN EXPORTED_FUNCTIONS */ - -/* USER CODE END EXPORTED_FUNCTIONS */ - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USBD_CDC_ACM_IF_TEMPLATE_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/AL94_USB_Composite/App/usbd_desc.c b/common/AL94_USB_Composite/App/usbd_desc.c deleted file mode 100644 index a66a9e7..0000000 --- a/common/AL94_USB_Composite/App/usbd_desc.c +++ /dev/null @@ -1,415 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : App/usbd_desc.c - * @version : v1.0_Cube - * @brief : This file implements the USB device descriptors. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * 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 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_core.h" -#include "usbd_desc.h" -#include "usbd_conf.h" - -/* USER CODE BEGIN INCLUDE */ -#include "usbd_composite.h" -/* USER CODE END INCLUDE */ - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ - -/* USER CODE BEGIN PV */ -/* Private variables ---------------------------------------------------------*/ - -/* USER CODE END PV */ - -/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY - * @{ - */ - -/** @addtogroup USBD_DESC - * @{ - */ - -/** @defgroup USBD_DESC_Private_TypesDefinitions USBD_DESC_Private_TypesDefinitions - * @brief Private types. - * @{ - */ - -/* USER CODE BEGIN PRIVATE_TYPES */ - -/* USER CODE END PRIVATE_TYPES */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Private_Defines USBD_DESC_Private_Defines - * @brief Private defines. - * @{ - */ - -#define USBD_VID 1155 -#define USBD_LANGID_STRING 1033 -#define USBD_MANUFACTURER_STRING "STMicroelectronics" -#if (USBD_USE_DFU == 1) -#define USBD_PID 57105 // for DFU PID must be 57105, ST proprietary modification -#else -#define USBD_PID 21156 -#endif -#define USBD_PRODUCT_STRING "STM32 COMPOSITE DEVICE" -#define USBD_CONFIGURATION_STRING "CONFIGURATION 0" -#define USBD_INTERFACE_STRING "COMPOSITE INTERFACE" - -/* USER CODE BEGIN PRIVATE_DEFINES */ - -//NOTE! USB Vendor and Product Information -#undef USBD_VID -#define USBD_VID 0x0000 // Vendor ID for Open Source Projects is "Generic" 0x1209 - -#undef USBD_MANUFACTURER_STRING -#define USBD_MANUFACTURER_STRING "VarmintWorks" - -#if (USBD_USE_DFU != 1) -#undef USBD_PID -#define USBD_PID 0x0001 // pid.codes Test PID for VID=0x1209 -#endif - -#undef USBD_PRODUCT_STRING -#define USBD_PRODUCT_STRING "rosflight controller" - -/* USER CODE END PRIVATE_DEFINES */ - -/** - * @} - */ - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/** @defgroup USBD_DESC_Private_Macros USBD_DESC_Private_Macros - * @brief Private macros. - * @{ - */ - -/* USER CODE BEGIN PRIVATE_MACRO */ - -/* USER CODE END PRIVATE_MACRO */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes - * @brief Private functions declaration. - * @{ - */ - -static void Get_SerialNum (void); -static void IntToUnicode (uint32_t value, uint8_t *pbuf, uint8_t len); - -/** - * @} - */ - -/** @defgroup USBD_DESC_Private_FunctionPrototypes USBD_DESC_Private_FunctionPrototypes - * @brief Private functions declaration for HS. - * @{ - */ - -uint8_t* USBD_DeviceDescriptor (USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t* USBD_LangIDStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t* USBD_ManufacturerStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t* USBD_ProductStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t* USBD_SerialStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t* USBD_ConfigStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length); -uint8_t* USBD_InterfaceStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length); - -/** - * @} - */ - -/** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables - * @brief Private variables. - * @{ - */ - -USBD_DescriptorsTypeDef USBD_Desc = -{ USBD_DeviceDescriptor, USBD_LangIDStrDescriptor, USBD_ManufacturerStrDescriptor, USBD_ProductStrDescriptor, USBD_SerialStrDescriptor, - USBD_ConfigStrDescriptor, USBD_InterfaceStrDescriptor }; - -#if defined ( __ICCARM__ ) /* IAR Compiler */ - #pragma data_alignment=4 -#endif /* defined ( __ICCARM__ ) */ -/** USB standard device descriptor. */ -__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = -{ 0x12, /*bLength */ -USB_DESC_TYPE_DEVICE, /*bDescriptorType*/ -0x00, /*bcdUSB */ -0x02, 0xEF, /*bDeviceClass*/ -0x02, /*bDeviceSubClass*/ -0x01, /*bDeviceProtocol*/ -USB_MAX_EP0_SIZE, /*bMaxPacketSize*/ -LOBYTE(USBD_VID), /*idVendor*/ -HIBYTE(USBD_VID), /*idVendor*/ -LOBYTE(USBD_PID), /*idProduct*/ -HIBYTE(USBD_PID), /*idProduct*/ -0x00, /*bcdDevice rel. 2.00*/ -0x02, -USBD_IDX_MFC_STR, /*Index of manufacturer string*/ -USBD_IDX_PRODUCT_STR, /*Index of product string*/ -USBD_IDX_SERIAL_STR, /*Index of serial number string*/ -USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/ -}; - -/** - * @} - */ - -/** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables - * @brief Private variables. - * @{ - */ - -#if defined ( __ICCARM__ ) /* IAR Compiler */ - #pragma data_alignment=4 -#endif /* defined ( __ICCARM__ ) */ - -/** USB lang indentifier descriptor. */ -__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = -{ -USB_LEN_LANGID_STR_DESC, -USB_DESC_TYPE_STRING, LOBYTE(USBD_LANGID_STRING), HIBYTE(USBD_LANGID_STRING) }; - -#if defined ( __ICCARM__ ) /* IAR Compiler */ - #pragma data_alignment=4 -#endif /* defined ( __ICCARM__ ) */ -/* Internal string descriptor. */ -__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; - -#if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 -#endif -__ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] __ALIGN_END = -{ -USB_SIZ_STRING_SERIAL, -USB_DESC_TYPE_STRING, }; - -/** - * @} - */ - -/** @defgroup USBD_DESC_Private_Functions USBD_DESC_Private_Functions - * @brief Private functions. - * @{ - */ - -/** - * @brief Return the device descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t* USBD_DeviceDescriptor (USBD_SpeedTypeDef speed, uint16_t *length) -{ - UNUSED(speed); - *length = sizeof(USBD_DeviceDesc); - return USBD_DeviceDesc; -} - -/** - * @brief Return the LangID string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t* USBD_LangIDStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length) -{ - UNUSED(speed); - *length = sizeof(USBD_LangIDDesc); - return USBD_LangIDDesc; -} - -/** - * @brief Return the product string descriptor - * @param speed : current device speed - * @param length : pointer to data length variable - * @retval pointer to descriptor buffer - */ -uint8_t* USBD_ProductStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length) -{ - if (speed == 0) - { - USBD_GetString ((uint8_t*) USBD_PRODUCT_STRING, USBD_StrDesc, length); - } - else - { - USBD_GetString ((uint8_t*) USBD_PRODUCT_STRING, USBD_StrDesc, length); - } - return USBD_StrDesc; -} - -/** - * @brief Return the manufacturer string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t* USBD_ManufacturerStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length) -{ - UNUSED(speed); - USBD_GetString ((uint8_t*) USBD_MANUFACTURER_STRING, USBD_StrDesc, length); - return USBD_StrDesc; -} - -/** - * @brief Return the serial number string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t* USBD_SerialStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length) -{ - UNUSED(speed); - *length = USB_SIZ_STRING_SERIAL; - - /* Update the serial number string descriptor with the data from the unique - * ID */ - Get_SerialNum (); - /* USER CODE BEGIN USBD_SerialStrDescriptor */ - - /* USER CODE END USBD_SerialStrDescriptor */ - - return (uint8_t*) USBD_StringSerial; -} - -/** - * @brief Return the configuration string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t* USBD_ConfigStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length) -{ - if (speed == USBD_SPEED_HIGH) - { - USBD_GetString ((uint8_t*) USBD_CONFIGURATION_STRING, USBD_StrDesc, length); - } - else - { - USBD_GetString ((uint8_t*) USBD_CONFIGURATION_STRING, USBD_StrDesc, length); - } - return USBD_StrDesc; -} - -/** - * @brief Return the interface string descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t* USBD_InterfaceStrDescriptor (USBD_SpeedTypeDef speed, uint16_t *length) -{ - if (speed == 0) - { - USBD_GetString ((uint8_t*) USBD_INTERFACE_STRING, USBD_StrDesc, length); - } - else - { - USBD_GetString ((uint8_t*) USBD_INTERFACE_STRING, USBD_StrDesc, length); - } - return USBD_StrDesc; -} - -#if (USBD_LPM_ENABLED == 1) -/** - * @brief Return the BOS descriptor - * @param speed : Current device speed - * @param length : Pointer to data length variable - * @retval Pointer to descriptor buffer - */ -uint8_t * USBD_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) -{ - UNUSED(speed); - *length = sizeof(USBD_BOSDesc); - return (uint8_t*)USBD_BOSDesc; -} -#endif /* (USBD_LPM_ENABLED == 1) */ - -/** - * @brief Create the serial number string descriptor - * @param None - * @retval None - */ -static void Get_SerialNum (void) -{ - uint32_t deviceserial0, deviceserial1, deviceserial2; - - deviceserial0 = *(uint32_t*) DEVICE_ID1; - deviceserial1 = *(uint32_t*) DEVICE_ID2; - deviceserial2 = *(uint32_t*) DEVICE_ID3; - - deviceserial0 += deviceserial2; - - if (deviceserial0 != 0) - { - IntToUnicode (deviceserial0, &USBD_StringSerial[2], 8); - IntToUnicode (deviceserial1, &USBD_StringSerial[18], 4); - } -} - -/** - * @brief Convert Hex 32Bits value into char - * @param value: value to convert - * @param pbuf: pointer to the buffer - * @param len: buffer length - * @retval None - */ -static void IntToUnicode (uint32_t value, uint8_t *pbuf, uint8_t len) -{ - uint8_t idx = 0; - - for (idx = 0; idx < len; idx++) - { - if (((value >> 28)) < 0xA) - { - pbuf[2 * idx] = (value >> 28) + '0'; - } - else - { - pbuf[2 * idx] = (value >> 28) + 'A' - 10; - } - - value = value << 4; - - pbuf[2 * idx + 1] = 0; - } -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/AL94_USB_Composite/App/usbd_desc.h b/common/AL94_USB_Composite/App/usbd_desc.h deleted file mode 100644 index 71b5248..0000000 --- a/common/AL94_USB_Composite/App/usbd_desc.h +++ /dev/null @@ -1,146 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : usbd_desc.c - * @version : v1.0_Cube - * @brief : Header for usbd_conf.c file. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * 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 - * - ****************************************************************************** - */ -/* USER CODE END Header */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USBD_DESC__C__ -#define __USBD_DESC__C__ - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* Includes ------------------------------------------------------------------*/ -#include "usbd_def.h" - - /* USER CODE BEGIN INCLUDE */ - - /* USER CODE END INCLUDE */ - - /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY - * @{ - */ - - /** @defgroup USBD_DESC USBD_DESC - * @brief Usb device descriptors module. - * @{ - */ - - /** @defgroup USBD_DESC_Exported_Constants USBD_DESC_Exported_Constants - * @brief Constants. - * @{ - */ -#define DEVICE_ID1 (UID_BASE) -#define DEVICE_ID2 (UID_BASE + 0x4) -#define DEVICE_ID3 (UID_BASE + 0x8) - -#define USB_SIZ_STRING_SERIAL 0x1A - - /* USER CODE BEGIN EXPORTED_CONSTANTS */ - - /* USER CODE END EXPORTED_CONSTANTS */ - - /** - * @} - */ - - /** @defgroup USBD_DESC_Exported_Defines USBD_DESC_Exported_Defines - * @brief Defines. - * @{ - */ - - /* USER CODE BEGIN EXPORTED_DEFINES */ - - /* USER CODE END EXPORTED_DEFINES */ - - /** - * @} - */ - - /** @defgroup USBD_DESC_Exported_TypesDefinitions USBD_DESC_Exported_TypesDefinitions - * @brief Types. - * @{ - */ - - /* USER CODE BEGIN EXPORTED_TYPES */ - - /* USER CODE END EXPORTED_TYPES */ - - /** - * @} - */ - - /** @defgroup USBD_DESC_Exported_Macros USBD_DESC_Exported_Macros - * @brief Aliases. - * @{ - */ - - /* USER CODE BEGIN EXPORTED_MACRO */ - - /* USER CODE END EXPORTED_MACRO */ - - /** - * @} - */ - - /** @defgroup USBD_DESC_Exported_Variables USBD_DESC_Exported_Variables - * @brief Public variables. - * @{ - */ - - /** Descriptor for the Usb device. */ - extern USBD_DescriptorsTypeDef USBD_Desc; - -/* USER CODE BEGIN EXPORTED_VARIABLES */ - -/* USER CODE END EXPORTED_VARIABLES */ - -/** - * @} - */ - -/** @defgroup USBD_DESC_Exported_FunctionsPrototype USBD_DESC_Exported_FunctionsPrototype - * @brief Public functions declaration. - * @{ - */ - -/* USER CODE BEGIN EXPORTED_FUNCTIONS */ - -/* USER CODE END EXPORTED_FUNCTIONS */ - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USBD_DESC__C__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/AL94_USB_Composite/Class/CDC_ACM/Inc/usbd_cdc_acm.h b/common/AL94_USB_Composite/Class/CDC_ACM/Inc/usbd_cdc_acm.h deleted file mode 100644 index a0784df..0000000 --- a/common/AL94_USB_Composite/Class/CDC_ACM/Inc/usbd_cdc_acm.h +++ /dev/null @@ -1,180 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_cdc.h - * @author MCD Application Team - * @brief header file for the usbd_cdc.c file. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

- * - * 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 inclusion -------------------------------------*/ -#ifndef __USB_CDC_H -#define __USB_CDC_H - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* Includes ------------------------------------------------------------------*/ -#include "usbd_ioreq.h" -#include // NOTE! replaced "AL94.I-CUBE-USBD-COMPOSITE_conf.h" - /** @addtogroup STM32_USB_DEVICE_LIBRARY - * @{ - */ - - /** @defgroup usbd_cdc - * @brief This file is the Header file for usbd_cdc.c - * @{ - */ - - /** @defgroup usbd_cdc_Exported_Defines - * @{ - */ - -#define CDC_ACM_STR_DESC "STM32 CDC ACM%d" - -#define NUMBER_OF_CDC _USBD_CDC_ACM_COUNT -#ifndef CDC_HS_BINTERVAL -#define CDC_HS_BINTERVAL 0x10U -#endif /* CDC_HS_BINTERVAL */ - -#ifndef CDC_FS_BINTERVAL -#define CDC_FS_BINTERVAL 0x10U -#endif /* CDC_FS_BINTERVAL */ - - /* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */ -#define CDC_DATA_HS_MAX_PACKET_SIZE 512U /* Endpoint IN & OUT Packet size */ -#define CDC_DATA_FS_MAX_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */ -#define CDC_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */ - -#define USB_CDC_CONFIG_DESC_SIZ (9 + 66 * NUMBER_OF_CDC) -#define CDC_DATA_HS_IN_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE -#define CDC_DATA_HS_OUT_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE - -#define CDC_DATA_FS_IN_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE -#define CDC_DATA_FS_OUT_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE - -#define CDC_REQ_MAX_DATA_SIZE 0x7U - /*---------------------------------------------------------------------*/ - /* CDC definitions */ - /*---------------------------------------------------------------------*/ -#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_LINE_CODING 0x20U -#define CDC_GET_LINE_CODING 0x21U -#define CDC_SET_CONTROL_LINE_STATE 0x22U -#define CDC_SEND_BREAK 0x23U - - /** - * @} - */ - - /** @defgroup USBD_CORE_Exported_TypesDefinitions - * @{ - */ - - /** - * @} - */ - typedef struct - { - uint32_t bitrate; - uint8_t format; - uint8_t paritytype; - uint8_t datatype; - } USBD_CDC_ACM_LineCodingTypeDef; - - typedef struct _USBD_CDC_Itf - { - int8_t (*Init) (uint8_t cdc_ch); - int8_t (*DeInit) (uint8_t cdc_ch); - int8_t (*Control) (uint8_t cdc_ch, uint8_t cmd, uint8_t *pbuf, uint16_t length); - int8_t (*Receive) (uint8_t cdc_ch, uint8_t *Buf, uint32_t *Len); - int8_t (*TransmitCplt) (uint8_t cdc_ch, uint8_t *Buf, uint32_t *Len, uint8_t epnum); - } USBD_CDC_ACM_ItfTypeDef; - - typedef struct - { - uint32_t data[NUMBER_OF_CDC][CDC_DATA_HS_MAX_PACKET_SIZE / 4U]; /* Force 32bits alignment */ - uint8_t CmdOpCode; - uint8_t CmdLength; - uint8_t *RxBuffer; - uint8_t *TxBuffer; - uint32_t RxLength; - uint32_t TxLength; - - __IO uint32_t TxState; - __IO uint32_t RxState; - } USBD_CDC_ACM_HandleTypeDef; - - /** @defgroup USBD_CORE_Exported_Macros - * @{ - */ - - /** - * @} - */ - - /** @defgroup USBD_CORE_Exported_Variables - * @{ - */ - - extern USBD_ClassTypeDef USBD_CDC_ACM; - - extern uint8_t CDC_IN_EP[NUMBER_OF_CDC]; /* EP1 for data IN */ - extern uint8_t CDC_OUT_EP[NUMBER_OF_CDC]; /* EP1 for data OUT */ - extern uint8_t CDC_CMD_EP[NUMBER_OF_CDC]; /* EP2 for CDC commands */ - - extern uint8_t CDC_CMD_ITF_NBR[NUMBER_OF_CDC]; /* Command Interface Number */ - extern uint8_t CDC_COM_ITF_NBR[NUMBER_OF_CDC]; /* Communication Interface Number */ - - extern uint8_t CDC_STR_DESC_IDX[NUMBER_OF_CDC]; - - /** - * @} - */ - - /** @defgroup USB_CORE_Exported_Functions - * @{ - */ - uint8_t USBD_CDC_ACM_RegisterInterface (USBD_HandleTypeDef *pdev, USBD_CDC_ACM_ItfTypeDef *fops); - - uint8_t USBD_CDC_SetTxBuffer (uint8_t ch, USBD_HandleTypeDef *pdev, uint8_t *pbuff, uint32_t length); - - uint8_t USBD_CDC_SetRxBuffer (uint8_t ch, USBD_HandleTypeDef *pdev, uint8_t *pbuff); - uint8_t USBD_CDC_ReceivePacket (uint8_t ch, USBD_HandleTypeDef *pdev); - uint8_t USBD_CDC_TransmitPacket (uint8_t ch, USBD_HandleTypeDef *pdev); - - void USBD_Update_CDC_ACM_DESC (uint8_t *desc, uint8_t cmd_itf, uint8_t com_itf, uint8_t in_ep, uint8_t cmd_ep, uint8_t out_ep, uint8_t str_idx); -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USB_CDC_H */ -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/AL94_USB_Composite/Class/CDC_ACM/Src/usbd_cdc_acm.c b/common/AL94_USB_Composite/Class/CDC_ACM/Src/usbd_cdc_acm.c deleted file mode 100644 index 2f83924..0000000 --- a/common/AL94_USB_Composite/Class/CDC_ACM/Src/usbd_cdc_acm.c +++ /dev/null @@ -1,2175 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_cdc.c - * @author MCD Application Team - * @brief This file provides the high layer firmware functions to manage the - * following functionalities of the USB CDC Class: - * - Initialization and Configuration of high and low layer - * - Enumeration as CDC Device (and enumeration for each implemented memory interface) - * - OUT/IN data transfer - * - Command IN transfer (class requests management) - * - Error management - * - * @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 - * - * These aspects may be enriched or modified for a specific user application. - * - * This driver doesn't implement the following aspects of the specification - * (but it is possible to manage these features with some modifications on this driver): - * - Any class-specific aspect relative to communication classes should be managed by user application. - * - All communication classes other than PSTN are not managed - * - * @endverbatim - * - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

- * - * 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" - EndBSPDependencies */ - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_cdc_acm.h" -#include "usbd_ctlreq.h" - -#define _CDC_IN_EP 0x81U /* EP1 for data IN */ -#define _CDC_OUT_EP 0x01U /* EP1 for data OUT */ -#define _CDC_CMD_EP 0x82U /* EP2 for CDC commands */ - -#define _CDC_CMD_ITF_NBR 0x00U /* Command Interface Number */ -#define _CDC_COM_ITF_NBR 0x01U /* Communication Interface Number */ - -#define _CDC_STR_DESC_IDX 0x00 - -uint8_t CDC_IN_EP[NUMBER_OF_CDC]; -uint8_t CDC_OUT_EP[NUMBER_OF_CDC]; -uint8_t CDC_CMD_EP[NUMBER_OF_CDC]; - -uint8_t CDC_CMD_ITF_NBR[NUMBER_OF_CDC]; -uint8_t CDC_COM_ITF_NBR[NUMBER_OF_CDC]; - -uint8_t CDC_STR_DESC_IDX[NUMBER_OF_CDC]; - -/** @addtogroup STM32_USB_DEVICE_LIBRARY - * @{ - */ - -/** @defgroup USBD_CDC - * @brief usbd core module - * @{ - */ - -/** @defgroup USBD_CDC_Private_TypesDefinitions - * @{ - */ -/** - * @} - */ - -/** @defgroup USBD_CDC_Private_Defines - * @{ - */ -/** - * @} - */ - -/** @defgroup USBD_CDC_Private_Macros - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_CDC_Private_FunctionPrototypes - * @{ - */ - -static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx); -static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx); -static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum); -static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum); -static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev); - -static uint8_t* USBD_CDC_GetFSCfgDesc (uint16_t *length); -static uint8_t* USBD_CDC_GetHSCfgDesc (uint16_t *length); -static uint8_t* USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length); -static uint8_t* USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length); -static uint8_t* USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length); - -USBD_CDC_ACM_HandleTypeDef CDC_ACM_Class_Data[NUMBER_OF_CDC]; - -/* USB Standard Device Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_CDC_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_CDC_Private_Variables - * @{ - */ - -/* CDC interface class callbacks structure */ -USBD_ClassTypeDef USBD_CDC_ACM = -{ USBD_CDC_Init, USBD_CDC_DeInit, USBD_CDC_Setup, -NULL, /* EP0_TxSent, */ -USBD_CDC_EP0_RxReady, USBD_CDC_DataIn, USBD_CDC_DataOut, -NULL, -NULL, -NULL, USBD_CDC_GetHSCfgDesc, USBD_CDC_GetFSCfgDesc, USBD_CDC_GetOtherSpeedCfgDesc, USBD_CDC_GetDeviceQualifierDescriptor, }; - -/* USB CDC device Configuration Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = -{ -/* Configuration Descriptor */ -0x09, /* bLength: Configuration Descriptor size */ -USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ -LOBYTE(USB_CDC_CONFIG_DESC_SIZ), /* wTotalLength:no of returned bytes */ -HIBYTE(USB_CDC_CONFIG_DESC_SIZ), (2 * NUMBER_OF_CDC), /* bNumInterfaces: 2 interface */ -0x01, /* bConfigurationValue: Configuration value */ -0x00, /* iConfiguration: Index of string descriptor describing the configuration */ -#if (USBD_SELF_POWERED == 1U) - 0xC0, /* bmAttributes: Bus Powered according to user configuration */ -#else - 0x80, /* bmAttributes: Bus Powered according to user configuration */ -#endif - USBD_MAX_POWER, /* MaxPower 100 mA */ - - /******************** CDC0 block ********************/ - /******** IAD to associate the two CDC interfaces */ - 0x08, /* bLength */ - 0x0B, /* bDescriptorType */ - _CDC_CMD_ITF_NBR, /* bFirstInterface */ - 0x02, /* bInterfaceCount */ - 0x02, /* bFunctionClass */ - 0x02, /* bFunctionSubClass */ - 0x01, /* bFunctionProtocol */ - 0x00, /* iFunction (Index of string descriptor describing this function) */ - - /* Interface Descriptor */ - 0x09, /* bLength: Interface Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ - _CDC_CMD_ITF_NBR, /* 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 */ - _CDC_STR_DESC_IDX, /* 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 */ - _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ - _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ - - /* Endpoint 2 Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_CMD_EP, /* bEndpointAddress */ - 0x03, /* bmAttributes: Interrupt */ - LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_CMD_PACKET_SIZE), - CDC_HS_BINTERVAL, /* bInterval: */ - /*---------------------------------------------------------------------------*/ - - /* Data class interface descriptor */ - 0x09, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ - _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_OUT_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ - - /* Endpoint IN Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_IN_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ - -#if (NUMBER_OF_CDC > 1) - /******************** CDC1 block ********************/ - /******** IAD to associate the two CDC interfaces */ - 0x08, /* bLength */ - 0x0B, /* bDescriptorType */ - _CDC_CMD_ITF_NBR, /* bFirstInterface */ - 0x02, /* bInterfaceCount */ - 0x02, /* bFunctionClass */ - 0x02, /* bFunctionSubClass */ - 0x01, /* bFunctionProtocol */ - 0x00, /* iFunction (Index of string descriptor describing this function) */ - - /* Interface Descriptor */ - 0x09, /* bLength: Interface Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ - _CDC_CMD_ITF_NBR, /* 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 */ - _CDC_STR_DESC_IDX, /* 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 */ - _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ - _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ - - /* Endpoint 2 Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_CMD_EP, /* bEndpointAddress */ - 0x03, /* bmAttributes: Interrupt */ - LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_CMD_PACKET_SIZE), - CDC_HS_BINTERVAL, /* bInterval: */ - /*---------------------------------------------------------------------------*/ - - /* Data class interface descriptor */ - 0x09, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ - _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_OUT_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ - - /* Endpoint IN Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_IN_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ -#endif - -#if (NUMBER_OF_CDC > 2) - /******************** CDC2 block ********************/ - /******** IAD to associate the two CDC interfaces */ - 0x08, /* bLength */ - 0x0B, /* bDescriptorType */ - _CDC_CMD_ITF_NBR, /* bFirstInterface */ - 0x02, /* bInterfaceCount */ - 0x02, /* bFunctionClass */ - 0x02, /* bFunctionSubClass */ - 0x01, /* bFunctionProtocol */ - 0x00, /* iFunction (Index of string descriptor describing this function) */ - - /* Interface Descriptor */ - 0x09, /* bLength: Interface Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ - _CDC_CMD_ITF_NBR, /* 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 */ - _CDC_STR_DESC_IDX, /* 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 */ - _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ - _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ - - /* Endpoint 2 Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_CMD_EP, /* bEndpointAddress */ - 0x03, /* bmAttributes: Interrupt */ - LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_CMD_PACKET_SIZE), - CDC_HS_BINTERVAL, /* bInterval: */ - /*---------------------------------------------------------------------------*/ - - /* Data class interface descriptor */ - 0x09, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ - _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_OUT_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ - - /* Endpoint IN Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_IN_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ -#endif - -#if (NUMBER_OF_CDC > 3) - /******************** CDC3 block ********************/ - /******** IAD to associate the two CDC interfaces */ - 0x08, /* bLength */ - 0x0B, /* bDescriptorType */ - _CDC_CMD_ITF_NBR, /* bFirstInterface */ - 0x02, /* bInterfaceCount */ - 0x02, /* bFunctionClass */ - 0x02, /* bFunctionSubClass */ - 0x01, /* bFunctionProtocol */ - 0x00, /* iFunction (Index of string descriptor describing this function) */ - - /* Interface Descriptor */ - 0x09, /* bLength: Interface Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ - _CDC_CMD_ITF_NBR, /* 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 */ - _CDC_STR_DESC_IDX, /* 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 */ - _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ - _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ - - /* Endpoint 2 Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_CMD_EP, /* bEndpointAddress */ - 0x03, /* bmAttributes: Interrupt */ - LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_CMD_PACKET_SIZE), - CDC_HS_BINTERVAL, /* bInterval: */ - /*---------------------------------------------------------------------------*/ - - /* Data class interface descriptor */ - 0x09, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ - _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_OUT_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ - - /* Endpoint IN Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_IN_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ -#endif - -#if (NUMBER_OF_CDC > 4) - /******************** CDC4 block ********************/ - /******** IAD to associate the two CDC interfaces */ - 0x08, /* bLength */ - 0x0B, /* bDescriptorType */ - _CDC_CMD_ITF_NBR, /* bFirstInterface */ - 0x02, /* bInterfaceCount */ - 0x02, /* bFunctionClass */ - 0x02, /* bFunctionSubClass */ - 0x01, /* bFunctionProtocol */ - 0x00, /* iFunction (Index of string descriptor describing this function) */ - - /* Interface Descriptor */ - 0x09, /* bLength: Interface Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ - _CDC_CMD_ITF_NBR, /* 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 */ - _CDC_STR_DESC_IDX, /* 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 */ - _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ - _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ - - /* Endpoint 2 Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_CMD_EP, /* bEndpointAddress */ - 0x03, /* bmAttributes: Interrupt */ - LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_CMD_PACKET_SIZE), - CDC_HS_BINTERVAL, /* bInterval: */ - /*---------------------------------------------------------------------------*/ - - /* Data class interface descriptor */ - 0x09, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ - _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_OUT_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ - - /* Endpoint IN Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_IN_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ -#endif - -#if (NUMBER_OF_CDC > 5) - /******************** CDC5 block ********************/ - /******** IAD to associate the two CDC interfaces */ - 0x08, /* bLength */ - 0x0B, /* bDescriptorType */ - _CDC_CMD_ITF_NBR, /* bFirstInterface */ - 0x02, /* bInterfaceCount */ - 0x02, /* bFunctionClass */ - 0x02, /* bFunctionSubClass */ - 0x01, /* bFunctionProtocol */ - 0x00, /* iFunction (Index of string descriptor describing this function) */ - - /* Interface Descriptor */ - 0x09, /* bLength: Interface Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ - _CDC_CMD_ITF_NBR, /* 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 */ - _CDC_STR_DESC_IDX, /* 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 */ - _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ - _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ - - /* Endpoint 2 Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_CMD_EP, /* bEndpointAddress */ - 0x03, /* bmAttributes: Interrupt */ - LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_CMD_PACKET_SIZE), - CDC_HS_BINTERVAL, /* bInterval: */ - /*---------------------------------------------------------------------------*/ - - /* Data class interface descriptor */ - 0x09, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ - _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_OUT_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ - - /* Endpoint IN Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_IN_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ -#endif - -#if (NUMBER_OF_CDC > 6) - /******************** CDC6 block ********************/ - /******** IAD to associate the two CDC interfaces */ - 0x08, /* bLength */ - 0x0B, /* bDescriptorType */ - _CDC_CMD_ITF_NBR, /* bFirstInterface */ - 0x02, /* bInterfaceCount */ - 0x02, /* bFunctionClass */ - 0x02, /* bFunctionSubClass */ - 0x01, /* bFunctionProtocol */ - 0x00, /* iFunction (Index of string descriptor describing this function) */ - - /* Interface Descriptor */ - 0x09, /* bLength: Interface Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ - _CDC_CMD_ITF_NBR, /* 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 */ - _CDC_STR_DESC_IDX, /* 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 */ - _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ - _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ - - /* Endpoint 2 Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_CMD_EP, /* bEndpointAddress */ - 0x03, /* bmAttributes: Interrupt */ - LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_CMD_PACKET_SIZE), - CDC_HS_BINTERVAL, /* bInterval: */ - /*---------------------------------------------------------------------------*/ - - /* Data class interface descriptor */ - 0x09, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ - _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_OUT_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ - - /* Endpoint IN Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_IN_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ -#endif - -#if (NUMBER_OF_CDC > 7) - /******************** CDC7 block ********************/ - /******** IAD to associate the two CDC interfaces */ - 0x08, /* bLength */ - 0x0B, /* bDescriptorType */ - _CDC_CMD_ITF_NBR, /* bFirstInterface */ - 0x02, /* bInterfaceCount */ - 0x02, /* bFunctionClass */ - 0x02, /* bFunctionSubClass */ - 0x01, /* bFunctionProtocol */ - 0x00, /* iFunction (Index of string descriptor describing this function) */ - - /* Interface Descriptor */ - 0x09, /* bLength: Interface Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ - _CDC_CMD_ITF_NBR, /* 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 */ - _CDC_STR_DESC_IDX, /* 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 */ - _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ - _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ - - /* Endpoint 2 Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_CMD_EP, /* bEndpointAddress */ - 0x03, /* bmAttributes: Interrupt */ - LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_CMD_PACKET_SIZE), - CDC_HS_BINTERVAL, /* bInterval: */ - /*---------------------------------------------------------------------------*/ - - /* Data class interface descriptor */ - 0x09, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ - _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_OUT_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ - - /* Endpoint IN Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_IN_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), - 0x00 /* bInterval: ignore for Bulk transfer */ -#endif - }; - -/* USB CDC device Configuration Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = -{ -/* Configuration Descriptor */ -0x09, /* bLength: Configuration Descriptor size */ -USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ -LOBYTE(USB_CDC_CONFIG_DESC_SIZ), /* wTotalLength:no of returned bytes */ -HIBYTE(USB_CDC_CONFIG_DESC_SIZ), 0x02, /* bNumInterfaces: 2 interface */ -0x01, /* bConfigurationValue: Configuration value */ -0x00, /* iConfiguration: Index of string descriptor describing the configuration */ -#if (USBD_SELF_POWERED == 1U) - 0xC0, /* bmAttributes: Bus Powered according to user configuration */ -#else - 0x80, /* bmAttributes: Bus Powered according to user configuration */ -#endif - USBD_MAX_POWER, /* MaxPower 100 mA */ - - /*---------------------------------------------------------------------------*/ - /******************** CDC0 block ********************/ - /******** IAD to associate the two CDC interfaces */ - 0x08, /* bLength */ - 0x0B, /* bDescriptorType */ - _CDC_CMD_ITF_NBR, /* bFirstInterface */ - 0x02, /* bInterfaceCount */ - 0x02, /* bFunctionClass */ - 0x02, /* bFunctionSubClass */ - 0x01, /* bFunctionProtocol */ - 0x00, /* iFunction (Index of string descriptor describing this function) */ - - /* Interface Descriptor */ - 0x09, /* bLength: Interface Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ - /* Interface descriptor type */ - _CDC_CMD_ITF_NBR, /* 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 */ - _CDC_STR_DESC_IDX,/* 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 */ - _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ - _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ - - /* Endpoint 2 Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_CMD_EP, /* bEndpointAddress */ - 0x03, /* bmAttributes: Interrupt */ - LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_CMD_PACKET_SIZE), - CDC_FS_BINTERVAL, /* bInterval: */ - /*---------------------------------------------------------------------------*/ - - /* Data class interface descriptor */ - 0x09, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ - _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_OUT_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ - - /* Endpoint IN Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_IN_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ - -#if (NUMBER_OF_CDC > 1) - /******************** CDC1 block ********************/ - /******** IAD to associate the two CDC interfaces */ - 0x08, /* bLength */ - 0x0B, /* bDescriptorType */ - _CDC_CMD_ITF_NBR, /* bFirstInterface */ - 0x02, /* bInterfaceCount */ - 0x02, /* bFunctionClass */ - 0x02, /* bFunctionSubClass */ - 0x01, /* bFunctionProtocol */ - 0x00, /* iFunction (Index of string descriptor describing this function) */ - - /* Interface Descriptor */ - 0x09, /* bLength: Interface Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ - /* Interface descriptor type */ - _CDC_CMD_ITF_NBR, /* 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 */ - _CDC_STR_DESC_IDX,/* 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 */ - _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ - _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ - - /* Endpoint 2 Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_CMD_EP, /* bEndpointAddress */ - 0x03, /* bmAttributes: Interrupt */ - LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_CMD_PACKET_SIZE), - CDC_FS_BINTERVAL, /* bInterval: */ - /*---------------------------------------------------------------------------*/ - - /* Data class interface descriptor */ - 0x09, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ - _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_OUT_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ - - /* Endpoint IN Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_IN_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ -#endif - -#if (NUMBER_OF_CDC > 2) - /******************** CDC2 block ********************/ - /******** IAD to associate the two CDC interfaces */ - 0x08, /* bLength */ - 0x0B, /* bDescriptorType */ - _CDC_CMD_ITF_NBR, /* bFirstInterface */ - 0x02, /* bInterfaceCount */ - 0x02, /* bFunctionClass */ - 0x02, /* bFunctionSubClass */ - 0x01, /* bFunctionProtocol */ - 0x00, /* iFunction (Index of string descriptor describing this function) */ - - /* Interface Descriptor */ - 0x09, /* bLength: Interface Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ - /* Interface descriptor type */ - _CDC_CMD_ITF_NBR, /* 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 */ - _CDC_STR_DESC_IDX,/* 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 */ - _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ - _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ - - /* Endpoint 2 Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_CMD_EP, /* bEndpointAddress */ - 0x03, /* bmAttributes: Interrupt */ - LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_CMD_PACKET_SIZE), - CDC_FS_BINTERVAL, /* bInterval: */ - /*---------------------------------------------------------------------------*/ - - /* Data class interface descriptor */ - 0x09, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ - _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_OUT_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ - - /* Endpoint IN Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_IN_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ -#endif - -#if (NUMBER_OF_CDC > 3) - /******************** CDC3 block ********************/ - /******** IAD to associate the two CDC interfaces */ - 0x08, /* bLength */ - 0x0B, /* bDescriptorType */ - _CDC_CMD_ITF_NBR, /* bFirstInterface */ - 0x02, /* bInterfaceCount */ - 0x02, /* bFunctionClass */ - 0x02, /* bFunctionSubClass */ - 0x01, /* bFunctionProtocol */ - 0x00, /* iFunction (Index of string descriptor describing this function) */ - - /* Interface Descriptor */ - 0x09, /* bLength: Interface Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ - /* Interface descriptor type */ - _CDC_CMD_ITF_NBR, /* 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 */ - _CDC_STR_DESC_IDX,/* 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 */ - _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ - _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ - - /* Endpoint 2 Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_CMD_EP, /* bEndpointAddress */ - 0x03, /* bmAttributes: Interrupt */ - LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_CMD_PACKET_SIZE), - CDC_FS_BINTERVAL, /* bInterval: */ - /*---------------------------------------------------------------------------*/ - - /* Data class interface descriptor */ - 0x09, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ - _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_OUT_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ - - /* Endpoint IN Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_IN_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ -#endif - -#if (NUMBER_OF_CDC > 4) - /******************** CDC4 block ********************/ - /******** IAD to associate the two CDC interfaces */ - 0x08, /* bLength */ - 0x0B, /* bDescriptorType */ - _CDC_CMD_ITF_NBR, /* bFirstInterface */ - 0x02, /* bInterfaceCount */ - 0x02, /* bFunctionClass */ - 0x02, /* bFunctionSubClass */ - 0x01, /* bFunctionProtocol */ - 0x00, /* iFunction (Index of string descriptor describing this function) */ - - /* Interface Descriptor */ - 0x09, /* bLength: Interface Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ - /* Interface descriptor type */ - _CDC_CMD_ITF_NBR, /* 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 */ - _CDC_STR_DESC_IDX,/* 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 */ - _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ - _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ - - /* Endpoint 2 Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_CMD_EP, /* bEndpointAddress */ - 0x03, /* bmAttributes: Interrupt */ - LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_CMD_PACKET_SIZE), - CDC_FS_BINTERVAL, /* bInterval: */ - /*---------------------------------------------------------------------------*/ - - /* Data class interface descriptor */ - 0x09, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ - _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_OUT_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ - - /* Endpoint IN Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_IN_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ -#endif - -#if (NUMBER_OF_CDC > 5) - /******************** CDC5 block ********************/ - /******** IAD to associate the two CDC interfaces */ - 0x08, /* bLength */ - 0x0B, /* bDescriptorType */ - _CDC_CMD_ITF_NBR, /* bFirstInterface */ - 0x02, /* bInterfaceCount */ - 0x02, /* bFunctionClass */ - 0x02, /* bFunctionSubClass */ - 0x01, /* bFunctionProtocol */ - 0x00, /* iFunction (Index of string descriptor describing this function) */ - - /* Interface Descriptor */ - 0x09, /* bLength: Interface Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ - /* Interface descriptor type */ - _CDC_CMD_ITF_NBR, /* 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 */ - _CDC_STR_DESC_IDX,/* 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 */ - _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ - _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ - - /* Endpoint 2 Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_CMD_EP, /* bEndpointAddress */ - 0x03, /* bmAttributes: Interrupt */ - LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_CMD_PACKET_SIZE), - CDC_FS_BINTERVAL, /* bInterval: */ - /*---------------------------------------------------------------------------*/ - - /* Data class interface descriptor */ - 0x09, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ - _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_OUT_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ - - /* Endpoint IN Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_IN_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ -#endif - -#if (NUMBER_OF_CDC > 6) - /******************** CDC6 block ********************/ - /******** IAD to associate the two CDC interfaces */ - 0x08, /* bLength */ - 0x0B, /* bDescriptorType */ - _CDC_CMD_ITF_NBR, /* bFirstInterface */ - 0x02, /* bInterfaceCount */ - 0x02, /* bFunctionClass */ - 0x02, /* bFunctionSubClass */ - 0x01, /* bFunctionProtocol */ - 0x00, /* iFunction (Index of string descriptor describing this function) */ - - /* Interface Descriptor */ - 0x09, /* bLength: Interface Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ - /* Interface descriptor type */ - _CDC_CMD_ITF_NBR, /* 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 */ - _CDC_STR_DESC_IDX,/* 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 */ - _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ - _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ - - /* Endpoint 2 Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_CMD_EP, /* bEndpointAddress */ - 0x03, /* bmAttributes: Interrupt */ - LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_CMD_PACKET_SIZE), - CDC_FS_BINTERVAL, /* bInterval: */ - /*---------------------------------------------------------------------------*/ - - /* Data class interface descriptor */ - 0x09, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ - _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_OUT_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ - - /* Endpoint IN Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_IN_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ -#endif - -#if (NUMBER_OF_CDC > 7) - /******************** CDC7 block ********************/ - /******** IAD to associate the two CDC interfaces */ - 0x08, /* bLength */ - 0x0B, /* bDescriptorType */ - _CDC_CMD_ITF_NBR, /* bFirstInterface */ - 0x02, /* bInterfaceCount */ - 0x02, /* bFunctionClass */ - 0x02, /* bFunctionSubClass */ - 0x01, /* bFunctionProtocol */ - 0x00, /* iFunction (Index of string descriptor describing this function) */ - - /* Interface Descriptor */ - 0x09, /* bLength: Interface Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ - /* Interface descriptor type */ - _CDC_CMD_ITF_NBR, /* 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 */ - _CDC_STR_DESC_IDX,/* 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 */ - _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ - _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ - - /* Endpoint 2 Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_CMD_EP, /* bEndpointAddress */ - 0x03, /* bmAttributes: Interrupt */ - LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_CMD_PACKET_SIZE), - CDC_FS_BINTERVAL, /* bInterval: */ - /*---------------------------------------------------------------------------*/ - - /* Data class interface descriptor */ - 0x09, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ - _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_OUT_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), - 0x00, /* bInterval: ignore for Bulk transfer */ - - /* Endpoint IN Descriptor */ - 0x07, /* bLength: Endpoint Descriptor size */ - USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ - _CDC_IN_EP, /* bEndpointAddress */ - 0x02, /* bmAttributes: Bulk */ - LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ - HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), - 0x00 /* bInterval: ignore for Bulk transfer */ -#endif - }; - -/** - * @} - */ - -/** @defgroup USBD_CDC_Private_Functions - * @{ - */ - -/** - * @brief USBD_CDC_Init - * Initialize the CDC interface - * @param pdev: device instance - * @param cfgidx: Configuration index - * @retval status - */ -static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) -{ - UNUSED(cfgidx); - USBD_CDC_ACM_HandleTypeDef *hcdc = NULL; - - for (uint8_t i = 0; i < NUMBER_OF_CDC; i++) - { - hcdc = &CDC_ACM_Class_Data[i]; - - if (pdev->dev_speed == USBD_SPEED_HIGH) - { - /* Open EP IN */ - (void) USBD_LL_OpenEP (pdev, CDC_IN_EP[i], USBD_EP_TYPE_BULK, - CDC_DATA_HS_IN_PACKET_SIZE); - - pdev->ep_in[CDC_IN_EP[i] & 0xFU].is_used = 1U; - - /* Open EP OUT */ - (void) USBD_LL_OpenEP (pdev, CDC_OUT_EP[i], USBD_EP_TYPE_BULK, - CDC_DATA_HS_OUT_PACKET_SIZE); - - pdev->ep_out[CDC_OUT_EP[i] & 0xFU].is_used = 1U; - - /* Set bInterval for CDC CMD Endpoint */ - pdev->ep_in[CDC_CMD_EP[i] & 0xFU].bInterval = CDC_HS_BINTERVAL; - } - else - { - /* Open EP IN */ - (void) USBD_LL_OpenEP (pdev, CDC_IN_EP[i], USBD_EP_TYPE_BULK, - CDC_DATA_FS_IN_PACKET_SIZE); - - pdev->ep_in[CDC_IN_EP[i] & 0xFU].is_used = 1U; - - /* Open EP OUT */ - (void) USBD_LL_OpenEP (pdev, CDC_OUT_EP[i], USBD_EP_TYPE_BULK, - CDC_DATA_FS_OUT_PACKET_SIZE); - - pdev->ep_out[CDC_OUT_EP[i] & 0xFU].is_used = 1U; - - /* Set bInterval for CMD Endpoint */ - pdev->ep_in[CDC_CMD_EP[i] & 0xFU].bInterval = CDC_FS_BINTERVAL; - } - - /* Open Command IN EP */ - (void) USBD_LL_OpenEP (pdev, CDC_CMD_EP[i], USBD_EP_TYPE_INTR, CDC_CMD_PACKET_SIZE); - pdev->ep_in[CDC_CMD_EP[i] & 0xFU].is_used = 1U; - - /* Init physical Interface components */ - ((USBD_CDC_ACM_ItfTypeDef*) pdev->pUserData_CDC_ACM)->Init (i); - - /* Init Xfer states */ - hcdc->TxState = 0U; - hcdc->RxState = 0U; - - if (pdev->dev_speed == USBD_SPEED_HIGH) - { - /* Prepare Out endpoint to receive next packet */ - (void) USBD_LL_PrepareReceive (pdev, CDC_OUT_EP[i], hcdc->RxBuffer, - CDC_DATA_HS_OUT_PACKET_SIZE); - } - else - { - /* Prepare Out endpoint to receive next packet */ - (void) USBD_LL_PrepareReceive (pdev, CDC_OUT_EP[i], hcdc->RxBuffer, - CDC_DATA_FS_OUT_PACKET_SIZE); - } - } - return (uint8_t) USBD_OK; -} - -/** - * @brief USBD_CDC_Init - * DeInitialize the CDC layer - * @param pdev: device instance - * @param cfgidx: Configuration index - * @retval status - */ -static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx) -{ - UNUSED(cfgidx); - for (uint8_t i = 0; i < NUMBER_OF_CDC; i++) - { - /* Close EP IN */ - (void) USBD_LL_CloseEP (pdev, CDC_IN_EP[i]); - pdev->ep_in[CDC_IN_EP[i] & 0xFU].is_used = 0U; - - /* Close EP OUT */ - (void) USBD_LL_CloseEP (pdev, CDC_OUT_EP[i]); - pdev->ep_out[CDC_OUT_EP[i] & 0xFU].is_used = 0U; - - /* Close Command IN EP */ - (void) USBD_LL_CloseEP (pdev, CDC_CMD_EP[i]); - pdev->ep_in[CDC_CMD_EP[i] & 0xFU].is_used = 0U; - pdev->ep_in[CDC_CMD_EP[i] & 0xFU].bInterval = 0U; - - /* DeInit physical Interface components */ - ((USBD_CDC_ACM_ItfTypeDef*) pdev->pUserData_CDC_ACM)->DeInit (i); - } - return (uint8_t) USBD_OK; -} - -/** - * @brief USBD_CDC_Setup - * Handle the CDC specific requests - * @param pdev: instance - * @param req: usb requests - * @retval status - */ -static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - USBD_CDC_ACM_HandleTypeDef *hcdc = NULL; - uint16_t len; - uint8_t ifalt = 0U; - uint16_t status_info = 0U; - USBD_StatusTypeDef ret = USBD_OK; - - uint8_t windex_to_ch = 0; - - for (uint8_t i = 0; i < NUMBER_OF_CDC; i++) - { - if (LOBYTE(req->wIndex) == CDC_CMD_ITF_NBR[i] || LOBYTE(req->wIndex) == CDC_COM_ITF_NBR[i]) - { - windex_to_ch = i; - break; - } - } - - hcdc = &CDC_ACM_Class_Data[windex_to_ch]; - - switch (req->bmRequest & USB_REQ_TYPE_MASK) - { - case USB_REQ_TYPE_CLASS: - if (req->wLength != 0U) - { - if ((req->bmRequest & 0x80U) != 0U) - { - ((USBD_CDC_ACM_ItfTypeDef*) pdev->pUserData_CDC_ACM)->Control (windex_to_ch, req->bRequest, (uint8_t*) hcdc->data[windex_to_ch], - req->wLength); - - len = MIN(CDC_REQ_MAX_DATA_SIZE, req->wLength); - (void) USBD_CtlSendData (pdev, (uint8_t*) hcdc->data[windex_to_ch], len); - } - else - { - hcdc->CmdOpCode = req->bRequest; - hcdc->CmdLength = (uint8_t) req->wLength; - - (void) USBD_CtlPrepareRx (pdev, (uint8_t*) hcdc->data[windex_to_ch], req->wLength); - } - } - else - { - ((USBD_CDC_ACM_ItfTypeDef*) pdev->pUserData_CDC_ACM)->Control (windex_to_ch, req->bRequest, (uint8_t*) req, 0U); - } - break; - - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - case USB_REQ_GET_STATUS: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - (void) USBD_CtlSendData (pdev, (uint8_t*) &status_info, 2U); - } - else - { - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - } - break; - - case USB_REQ_GET_INTERFACE: - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - (void) USBD_CtlSendData (pdev, &ifalt, 1U); - } - else - { - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - } - break; - - case USB_REQ_SET_INTERFACE: - if (pdev->dev_state != USBD_STATE_CONFIGURED) - { - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - } - break; - - case USB_REQ_CLEAR_FEATURE: - break; - - default: - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - break; - } - break; - - default: - USBD_CtlError (pdev, req); - ret = USBD_FAIL; - break; - } - - return (uint8_t) ret; -} - -/** - * @brief USBD_CDC_DataIn - * Data sent on non-control IN endpoint - * @param pdev: device instance - * @param epnum: endpoint number - * @retval status - */ -static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum) -{ - USBD_CDC_ACM_HandleTypeDef *hcdc = NULL; - PCD_HandleTypeDef *hpcd = pdev->pData; - uint8_t ep_to_ch = 0; - - for (uint8_t i = 0; i < NUMBER_OF_CDC; i++) - { - if (epnum == (CDC_IN_EP[i] & 0x0F)) - { - ep_to_ch = i; - break; - } - } - - hcdc = &CDC_ACM_Class_Data[ep_to_ch]; - - if ((pdev->ep_in[epnum].total_length > 0U) && ((pdev->ep_in[epnum].total_length % hpcd->IN_ep[epnum].maxpacket) == 0U)) - { - /* Update the packet total length */ - pdev->ep_in[epnum].total_length = 0U; - - /* Send ZLP */ - (void) USBD_LL_Transmit (pdev, epnum, NULL, 0U); - } - else - { - hcdc->TxState = 0U; - - if (((USBD_CDC_ACM_ItfTypeDef*) pdev->pUserData_CDC_ACM)->TransmitCplt != NULL) - { - ((USBD_CDC_ACM_ItfTypeDef*) pdev->pUserData_CDC_ACM)->TransmitCplt (ep_to_ch, hcdc->TxBuffer, &hcdc->TxLength, epnum); - } - } - - return (uint8_t) USBD_OK; -} - -/** - * @brief USBD_CDC_DataOut - * Data received on non-control Out endpoint - * @param pdev: device instance - * @param epnum: endpoint number - * @retval status - */ -static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum) -{ - USBD_CDC_ACM_HandleTypeDef *hcdc = NULL; - uint8_t ep_to_ch = 0; - - for (uint8_t i = 0; i < NUMBER_OF_CDC; i++) - { - if (epnum == CDC_OUT_EP[i]) - { - ep_to_ch = i; - break; - } - } - - hcdc = &CDC_ACM_Class_Data[ep_to_ch]; - - /* Get the received data length */ - hcdc->RxLength = USBD_LL_GetRxDataSize (pdev, epnum); - - /* USB data will be immediately processed, this allow next USB traffic being - NAKed till the end of the application Xfer */ - - ((USBD_CDC_ACM_ItfTypeDef*) pdev->pUserData_CDC_ACM)->Receive (ep_to_ch, hcdc->RxBuffer, &hcdc->RxLength); - - return (uint8_t) USBD_OK; -} - -/** - * @brief USBD_CDC_EP0_RxReady - * Handle EP0 Rx Ready event - * @param pdev: device instance - * @retval status - */ -static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev) -{ - USBD_CDC_ACM_HandleTypeDef *hcdc = NULL; - - for (uint8_t i = 0; i < NUMBER_OF_CDC; i++) - { - hcdc = &CDC_ACM_Class_Data[i]; - - if (hcdc == NULL) - { - return (uint8_t) USBD_FAIL; - } - - if ((pdev->pUserData_CDC_ACM != NULL) && (hcdc->CmdOpCode != 0xFFU)) - { - ((USBD_CDC_ACM_ItfTypeDef*) pdev->pUserData_CDC_ACM)->Control (i, hcdc->CmdOpCode, (uint8_t*) hcdc->data[i], (uint16_t) hcdc->CmdLength); - hcdc->CmdOpCode = 0xFFU; - } - } - - return (uint8_t) USBD_OK; -} - -/** - * @brief USBD_CDC_GetFSCfgDesc - * Return configuration descriptor - * @param speed : current device speed - * @param length : pointer data length - * @retval pointer to descriptor buffer - */ -static uint8_t* USBD_CDC_GetFSCfgDesc (uint16_t *length) -{ - *length = (uint16_t) sizeof(USBD_CDC_CfgFSDesc); - - return USBD_CDC_CfgFSDesc; -} - -/** - * @brief USBD_CDC_GetHSCfgDesc - * Return configuration descriptor - * @param speed : current device speed - * @param length : pointer data length - * @retval pointer to descriptor buffer - */ -static uint8_t* USBD_CDC_GetHSCfgDesc (uint16_t *length) -{ - *length = (uint16_t) sizeof(USBD_CDC_CfgHSDesc); - - return USBD_CDC_CfgHSDesc; -} - -/** - * @brief USBD_CDC_GetOtherSpeedCfgDesc - * Return configuration descriptor - * @param speed : current device speed - * @param length : pointer data length - * @retval pointer to descriptor buffer - */ -static uint8_t* USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length) -{ - *length = (uint16_t) sizeof(USBD_CDC_CfgFSDesc); - - return USBD_CDC_CfgFSDesc; -} - -/** - * @brief USBD_CDC_GetDeviceQualifierDescriptor - * return Device Qualifier descriptor - * @param length : pointer data length - * @retval pointer to descriptor buffer - */ -uint8_t* USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length) -{ - *length = (uint16_t) sizeof(USBD_CDC_DeviceQualifierDesc); - - return USBD_CDC_DeviceQualifierDesc; -} - -/** - * @brief USBD_CDC_RegisterInterface - * @param pdev: device instance - * @param fops: CD Interface callback - * @retval status - */ -uint8_t USBD_CDC_ACM_RegisterInterface (USBD_HandleTypeDef *pdev, USBD_CDC_ACM_ItfTypeDef *fops) -{ - if (fops == NULL) - { - return (uint8_t) USBD_FAIL; - } - - pdev->pUserData_CDC_ACM = fops; - - return (uint8_t) USBD_OK; -} - -/** - * @brief USBD_CDC_SetTxBuffer - * @param pdev: device instance - * @param pbuff: Tx Buffer - * @retval status - */ -uint8_t USBD_CDC_SetTxBuffer (uint8_t ch, USBD_HandleTypeDef *pdev, uint8_t *pbuff, uint32_t length) -{ - USBD_CDC_ACM_HandleTypeDef *hcdc = NULL; - - hcdc = &CDC_ACM_Class_Data[ch]; - - hcdc->TxBuffer = pbuff; - hcdc->TxLength = length; - - return (uint8_t) USBD_OK; -} - -/** - * @brief USBD_CDC_SetRxBuffer - * @param pdev: device instance - * @param pbuff: Rx Buffer - * @retval status - */ -uint8_t USBD_CDC_SetRxBuffer (uint8_t ch, USBD_HandleTypeDef *pdev, uint8_t *pbuff) -{ - USBD_CDC_ACM_HandleTypeDef *hcdc = NULL; - - hcdc = &CDC_ACM_Class_Data[ch]; - - hcdc->RxBuffer = pbuff; - - return (uint8_t) USBD_OK; -} - -/** - * @brief USBD_CDC_TransmitPacket - * Transmit packet on IN endpoint - * @param pdev: device instance - * @retval status - */ -uint8_t USBD_CDC_TransmitPacket (uint8_t ch, USBD_HandleTypeDef *pdev) -{ - USBD_CDC_ACM_HandleTypeDef *hcdc = NULL; - USBD_StatusTypeDef ret = USBD_BUSY; - - hcdc = &CDC_ACM_Class_Data[ch]; - - if (hcdc->TxState == 0U) - { - /* Tx Transfer in progress */ - hcdc->TxState = 1U; - - /* Update the packet total length */ - pdev->ep_in[CDC_IN_EP[ch] & 0xFU].total_length = hcdc->TxLength; - - /* Transmit next packet */ - (void) USBD_LL_Transmit (pdev, CDC_IN_EP[ch], hcdc->TxBuffer, hcdc->TxLength); - - ret = USBD_OK; - } - - return (uint8_t) ret; -} - -/** - * @brief USBD_CDC_ACM_ReceivePacket - * prepare OUT Endpoint for reception - * @param pdev: device instance - * @retval status - */ -uint8_t USBD_CDC_ReceivePacket (uint8_t ch, USBD_HandleTypeDef *pdev) -{ - USBD_CDC_ACM_HandleTypeDef *hcdc = NULL; - - hcdc = &CDC_ACM_Class_Data[ch]; - - if (pdev->dev_speed == USBD_SPEED_HIGH) - { - /* Prepare Out endpoint to receive next packet */ - (void) USBD_LL_PrepareReceive (pdev, CDC_OUT_EP[ch], hcdc->RxBuffer, - CDC_DATA_HS_OUT_PACKET_SIZE); - } - else - { - /* Prepare Out endpoint to receive next packet */ - (void) USBD_LL_PrepareReceive (pdev, CDC_OUT_EP[ch], hcdc->RxBuffer, - CDC_DATA_FS_OUT_PACKET_SIZE); - } - - return (uint8_t) USBD_OK; -} - -void USBD_Update_CDC_ACM_DESC (uint8_t *desc, uint8_t cmd_itf, uint8_t com_itf, uint8_t in_ep, uint8_t cmd_ep, uint8_t out_ep, uint8_t str_idx) -{ - desc += 9; - for (uint8_t i = 0; i < NUMBER_OF_CDC; i++) - { - desc[2] = cmd_itf; - desc[16] = str_idx; - desc[10] = cmd_itf; - desc[26] = com_itf; - desc[34] = cmd_itf; - desc[35] = com_itf; - desc[38] = cmd_ep; - desc[45] = com_itf; - desc[54] = out_ep; - desc[61] = in_ep; - - desc += 66; - CDC_IN_EP[i] = in_ep; - CDC_OUT_EP[i] = out_ep; - CDC_CMD_EP[i] = cmd_ep; - CDC_CMD_ITF_NBR[i] = cmd_itf; - CDC_COM_ITF_NBR[i] = com_itf; - CDC_STR_DESC_IDX[i] = str_idx; - - in_ep += 2; - cmd_ep = in_ep + 1; - out_ep++; - str_idx++; - - cmd_itf += 2; - com_itf = cmd_itf + 1; - } -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/AL94_USB_Composite/Class/COMPOSITE/Inc/usbd_composite.h b/common/AL94_USB_Composite/Class/COMPOSITE/Inc/usbd_composite.h deleted file mode 100644 index 8d57dfc..0000000 --- a/common/AL94_USB_Composite/Class/COMPOSITE/Inc/usbd_composite.h +++ /dev/null @@ -1,151 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_composite.h - * @author MCD Application Team - * @brief Header file for the usbd_composite.c file. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

- * - * 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 inclusion -------------------------------------*/ -#ifndef __USB_COMPOSITE_H -#define __USB_COMPOSITE_H - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* Includes ------------------------------------------------------------------*/ -#include "stdbool.h" -#include "usbd_ioreq.h" -#include // NOTE! replaced "AL94.I-CUBE-USBD-COMPOSITE_conf.h" - - /** @addtogroup STM32_USB_DEVICE_LIBRARY - * @{ - */ - - /** @defgroup USBD_COMPOSITE - * @brief This file is the header file for usbd_composite.c - * @{ - */ - - /** @defgroup USBD_COMPOSITE_Exported_Defines - * @{ - */ - -#define USBD_USE_HS _USBD_USE_HS -#define USBD_USE_CDC_ACM _USBD_USE_CDC_ACM -#define USBD_CDC_ACM_COUNT _USBD_CDC_ACM_COUNT -#define USBD_USE_CDC_RNDIS _USBD_USE_CDC_RNDIS -#define USBD_USE_CDC_ECM _USBD_USE_CDC_ECM -#define USBD_USE_HID_MOUSE _USBD_USE_HID_MOUSE -#define USBD_USE_HID_KEYBOARD _USBD_USE_HID_KEYBOARD -#define USBD_USE_HID_CUSTOM _USBD_USE_HID_CUSTOM -#define USBD_USE_UAC_MIC _USBD_USE_UAC_MIC -#define USBD_USE_UAC_SPKR _USBD_USE_UAC_SPKR -#define USBD_USE_UVC _USBD_USE_UVC -#define USBD_USE_MSC _USBD_USE_MSC -#define USBD_USE_DFU _USBD_USE_DFU -#define USBD_USE_PRNTR _USBD_USE_PRNTR - -#define STM32F1_DEVICE _STM32F1_DEVICE - -#if(USBD_USE_CDC_ACM == 1) -#include "usbd_cdc_acm_if.h" -#endif -#if(USBD_USE_CDC_RNDIS == 1) -#include "usbd_cdc_rndis_if.h" -#endif -#if(USBD_USE_CDC_ECM == 1) -#include "usbd_cdc_ecm_if.h" -#endif -#if(USBD_USE_HID_MOUSE == 1) -#include "usbd_hid_mouse.h" -#endif -#if(USBD_USE_HID_KEYBOARD == 1) -#include "usbd_hid_keyboard.h" -#endif -#if(USBD_USE_HID_CUSTOM == 1) -#include "usbd_hid_custom_if.h" -#endif -#if(USBD_USE_UAC_MIC == 1) -#include "usbd_audio_mic_if.h" -#endif -#if(USBD_USE_UAC_SPKR == 1) -#include "usbd_audio_spkr_if.h" -#endif -#if(USBD_USE_UVC == 1) -#include "usbd_video_if.h" -#endif -#if(USBD_USE_MSC == 1) -#include "usbd_msc_if.h" -#endif -#if(USBD_USE_DFU == 1) -#include "usbd_dfu_if.h" -#endif -#if(USBD_USE_PRNTR == 1) -#include "usbd_printer_if.h" -#endif - - /** - * @} - */ - - /** @defgroup USBD_COMPOSITE_Exported_TypesDefinitions - * @{ - */ - - /** - * @} - */ - - /** @defgroup USBD_COMPOSITE_Exported_Macros - * @{ - */ - - /** - * @} - */ - - /** @defgroup USBD_COMPOSITE_Exported_Variables - * @{ - */ - - extern USBD_ClassTypeDef USBD_COMPOSITE; - /** - * @} - */ - - /** @defgroup USB_CORE_Exported_Functions - * @{ - */ - void USBD_COMPOSITE_Mount_Class (void); -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USB_COMPOSITE_H */ -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/AL94_USB_Composite/Class/COMPOSITE/Src/usbd_composite.c b/common/AL94_USB_Composite/Class/COMPOSITE/Src/usbd_composite.c deleted file mode 100644 index 8008070..0000000 --- a/common/AL94_USB_Composite/Class/COMPOSITE/Src/usbd_composite.c +++ /dev/null @@ -1,1133 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_composite.c - * @author MCD Application Team - * @brief This file provides the HID core functions. - * - * @verbatim - * - * =================================================================== - * COMPOSITE Class Description - * =================================================================== - * - * - * - * - * - * - * @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 - * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

- * - * 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 "usbd_composite.h" -#include "usbd_ctlreq.h" - -/** @addtogroup STM32_USB_DEVICE_LIBRARY - * @{ - */ - -/** @defgroup USBD_COMPOSITE - * @brief usbd core module - * @{ - */ - -/** @defgroup USBD_COMPOSITE_Private_TypesDefinitions - * @{ - */ -/** - * @} - */ - -/** @defgroup USBD_COMPOSITE_Private_Defines - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_COMPOSITE_Private_Macros - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_COMPOSITE_Private_FunctionPrototypes - * @{ - */ - -static uint8_t USBD_COMPOSITE_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx); -static uint8_t USBD_COMPOSITE_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx); -static uint8_t USBD_COMPOSITE_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static uint8_t USBD_COMPOSITE_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum); -static uint8_t USBD_COMPOSITE_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum); -static uint8_t USBD_COMPOSITE_EP0_RxReady (USBD_HandleTypeDef *pdev); -static uint8_t USBD_COMPOSITE_EP0_TxReady (USBD_HandleTypeDef *pdev); -static uint8_t USBD_COMPOSITE_SOF (USBD_HandleTypeDef *pdev); -static uint8_t USBD_COMPOSITE_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum); -static uint8_t USBD_COMPOSITE_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum); - -static uint8_t* USBD_COMPOSITE_GetHSCfgDesc (uint16_t *length); -static uint8_t* USBD_COMPOSITE_GetFSCfgDesc (uint16_t *length); -static uint8_t* USBD_COMPOSITE_GetOtherSpeedCfgDesc (uint16_t *length); -static uint8_t* USBD_COMPOSITE_GetDeviceQualifierDesc (uint16_t *length); -static uint8_t* USBD_COMPOSITE_GetUsrStringDesc (USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length); - -/** - * @} - */ - -/** @defgroup USBD_COMPOSITE_Private_Variables - * @{ - */ - -USBD_ClassTypeDef USBD_COMPOSITE = -{ USBD_COMPOSITE_Init, USBD_COMPOSITE_DeInit, USBD_COMPOSITE_Setup, USBD_COMPOSITE_EP0_TxReady, USBD_COMPOSITE_EP0_RxReady, USBD_COMPOSITE_DataIn, - USBD_COMPOSITE_DataOut, USBD_COMPOSITE_SOF, USBD_COMPOSITE_IsoINIncomplete, USBD_COMPOSITE_IsoOutIncomplete, USBD_COMPOSITE_GetHSCfgDesc, - USBD_COMPOSITE_GetFSCfgDesc, USBD_COMPOSITE_GetOtherSpeedCfgDesc, USBD_COMPOSITE_GetDeviceQualifierDesc, USBD_COMPOSITE_GetUsrStringDesc }; - -typedef struct USBD_COMPOSITE_CFG_DESC_t -{ - uint8_t CONFIG_DESC[USB_CONF_DESC_SIZE]; -#if (USBD_USE_CDC_RNDIS == 1) - uint8_t USBD_CDC_RNDIS_DESC[CDC_RNDIS_CONFIG_DESC_SIZE - 0x09]; -#endif -#if (USBD_USE_CDC_ECM == 1) - uint8_t USBD_CDC_ECM_DESC[CDC_ECM_CONFIG_DESC_SIZE - 0x09]; -#endif -#if (USBD_USE_HID_MOUSE == 1) - uint8_t USBD_HID_MOUSE_DESC[USB_HID_CONFIG_DESC_SIZ - 0x09]; -#endif -#if (USBD_USE_HID_KEYBOARD == 1) - uint8_t USBD_HID_KEYBOARD_DESC[HID_KEYBOARD_CONFIG_DESC_SIZE - 0x09]; -#endif -#if (USBD_USE_HID_CUSTOM == 1) - uint8_t USBD_HID_CUSTOM_DESC[USB_CUSTOM_HID_CONFIG_DESC_SIZ - 0x09]; -#endif -#if (USBD_USE_UAC_MIC == 1) - uint8_t USBD_UAC_MIC_DESC[USBD_AUDIO_MIC_CONFIG_DESC_SIZE - 0x09]; -#endif -#if (USBD_USE_UAC_SPKR == 1) - uint8_t USBD_AUDIO_SPKR_DESC[USBD_AUDIO_SPKR_CONFIG_DESC_SIZE - 0x09]; -#endif -#if (USBD_USE_UVC == 1) - uint8_t USBD_UVC_DESC[UVC_CONFIG_DESC_SIZE - 0x09]; -#endif -#if (USBD_USE_MSC == 1) - uint8_t USBD_MSC_DESC[USB_MSC_CONFIG_DESC_SIZ - 0x09]; -#endif -#if (USBD_USE_DFU == 1) - uint8_t USBD_DFU_DESC[USB_DFU_CONFIG_DESC_SIZ - 0x09]; -#endif -#if (USBD_USE_PRNTR == 1) - uint8_t USBD_PRNTR_DESC[USB_PRNT_CONFIG_DESC_SIZE - 0x09]; -#endif -#if (USBD_USE_CDC_ACM == 1) - uint8_t USBD_CDC_ACM_DESC[USB_CDC_CONFIG_DESC_SIZ - 0x09]; -#endif - -}__PACKED USBD_COMPOSITE_CFG_DESC_t; - -#if defined(__ICCARM__) /*!< IAR Compiler */ -#pragma data_alignment = 4 -#endif -__ALIGN_BEGIN USBD_COMPOSITE_CFG_DESC_t USBD_COMPOSITE_FSCfgDesc, USBD_COMPOSITE_HSCfgDesc __ALIGN_END; -uint8_t USBD_Track_String_Index = (USBD_IDX_INTERFACE_STR + 1); - -#if defined(__ICCARM__) /*!< IAR Compiler */ -#pragma data_alignment = 4 -#endif -/* USB Standard Device Descriptor */ -__ALIGN_BEGIN static uint8_t USBD_COMPOSITE_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = -{ -USB_LEN_DEV_QUALIFIER_DESC, -USB_DESC_TYPE_DEVICE_QUALIFIER, 0x00, 0x02, 0xEF, 0x02, 0x01, 0x40, 0x01, 0x00, }; - -/** - * @} - */ - -/** @defgroup USBD_COMPOSITE_Private_Functions - * @{ - */ - -/** - * @brief USBD_COMPOSITE_Init - * Initialize the COMPOSITE interface - * @param pdev: device instance - * @param cfgidx: Configuration index - * @retval status - */ -static uint8_t USBD_COMPOSITE_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) -{ -#if (USBD_USE_CDC_ACM == 1) - USBD_CDC_ACM.Init (pdev, cfgidx); -#endif -#if (USBD_USE_CDC_ECM == 1) - USBD_CDC_ECM.Init(pdev, cfgidx); -#endif -#if (USBD_USE_CDC_RNDIS == 1) - USBD_CDC_RNDIS.Init(pdev, cfgidx); -#endif -#if (USBD_USE_HID_MOUSE == 1) - USBD_HID_MOUSE.Init(pdev, cfgidx); -#endif -#if (USBD_USE_HID_KEYBOARD == 1) - USBD_HID_KEYBOARD.Init(pdev, cfgidx); -#endif -#if (USBD_USE_HID_CUSTOM == 1) - USBD_HID_CUSTOM.Init(pdev, cfgidx); -#endif -#if (USBD_USE_UAC_MIC == 1) - USBD_AUDIO_MIC.Init(pdev, cfgidx); -#endif -#if (USBD_USE_UAC_SPKR == 1) - USBD_AUDIO_SPKR.Init(pdev, cfgidx); -#endif -#if (USBD_USE_UVC == 1) - USBD_VIDEO.Init(pdev, cfgidx); -#endif -#if (USBD_USE_MSC == 1) - USBD_MSC.Init(pdev, cfgidx); -#endif -#if (USBD_USE_DFU == 1) - USBD_DFU.Init(pdev, cfgidx); -#endif -#if (USBD_USE_PRNTR == 1) - USBD_PRNT.Init(pdev, cfgidx); -#endif - - return (uint8_t) USBD_OK; -} - -/** - * @brief USBD_COMPOSITE_Init - * DeInitialize the COMPOSITE layer - * @param pdev: device instance - * @param cfgidx: Configuration index - * @retval status - */ -static uint8_t USBD_COMPOSITE_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx) -{ -#if (USBD_USE_CDC_ACM == 1) - USBD_CDC_ACM.DeInit (pdev, cfgidx); -#endif -#if (USBD_USE_CDC_ECM == 1) - USBD_CDC_ECM.DeInit(pdev, cfgidx); -#endif -#if (USBD_USE_CDC_RNDIS == 1) - USBD_CDC_RNDIS.DeInit(pdev, cfgidx); -#endif -#if (USBD_USE_HID_MOUSE == 1) - USBD_HID_MOUSE.DeInit(pdev, cfgidx); -#endif -#if (USBD_USE_HID_KEYBOARD == 1) - USBD_HID_KEYBOARD.DeInit(pdev, cfgidx); -#endif -#if (USBD_USE_HID_CUSTOM == 1) - USBD_HID_CUSTOM.DeInit(pdev, cfgidx); -#endif -#if (USBD_USE_UAC_MIC == 1) - USBD_AUDIO_MIC.DeInit(pdev, cfgidx); -#endif -#if (USBD_USE_UAC_SPKR == 1) - USBD_AUDIO_SPKR.DeInit(pdev, cfgidx); -#endif -#if (USBD_USE_UVC == 1) - USBD_VIDEO.DeInit(pdev, cfgidx); -#endif -#if (USBD_USE_MSC == 1) - USBD_MSC.DeInit(pdev, cfgidx); -#endif -#if (USBD_USE_DFU == 1) - USBD_DFU.DeInit(pdev, cfgidx); -#endif -#if (USBD_USE_PRNTR == 1) - USBD_PRNT.DeInit(pdev, cfgidx); -#endif - - return (uint8_t) USBD_OK; -} - -/** - * @brief USBD_COMPOSITE_Setup - * Handle the COMPOSITE specific requests - * @param pdev: instance - * @param req: usb requests - * @retval status - */ -static uint8_t USBD_COMPOSITE_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ -#if (USBD_USE_CDC_ACM == 1) - for (uint8_t i = 0; i < USBD_CDC_ACM_COUNT; i++) - { - if (LOBYTE(req->wIndex) == CDC_CMD_ITF_NBR[i] || LOBYTE(req->wIndex) == CDC_COM_ITF_NBR[i]) - { - return USBD_CDC_ACM.Setup (pdev, req); - } - } -#endif -#if (USBD_USE_CDC_ECM == 1) - if (LOBYTE(req->wIndex) == CDC_ECM_CMD_ITF_NBR || LOBYTE(req->wIndex) == CDC_ECM_COM_ITF_NBR) - { - return USBD_CDC_ECM.Setup(pdev, req); - } -#endif -#if (USBD_USE_CDC_RNDIS == 1) - if (LOBYTE(req->wIndex) == CDC_RNDIS_CMD_ITF_NBR || LOBYTE(req->wIndex) == CDC_RNDIS_COM_ITF_NBR) - { - return USBD_CDC_RNDIS.Setup(pdev, req); - } -#endif -#if (USBD_USE_HID_MOUSE == 1) - if (LOBYTE(req->wIndex) == HID_MOUSE_ITF_NBR) - { - return USBD_HID_MOUSE.Setup(pdev, req); - } -#endif -#if (USBD_USE_HID_KEYBOARD == 1) - if (LOBYTE(req->wIndex) == HID_KEYBOARD_ITF_NBR) - { - return USBD_HID_KEYBOARD.Setup(pdev, req); - } -#endif -#if (USBD_USE_HID_CUSTOM == 1) - if (LOBYTE(req->wIndex) == CUSTOM_HID_ITF_NBR) - { - return USBD_HID_CUSTOM.Setup(pdev, req); - } -#endif -#if (USBD_USE_UAC_MIC == 1) - if (LOBYTE(req->wIndex) == AUDIO_MIC_AC_ITF_NBR || LOBYTE(req->wIndex) == AUDIO_MIC_AS_ITF_NBR) - { - return USBD_AUDIO_MIC.Setup(pdev, req); - } -#endif -#if (USBD_USE_UAC_SPKR == 1) - if (LOBYTE(req->wIndex) == AUDIO_SPKR_AC_ITF_NBR || LOBYTE(req->wIndex) == AUDIO_SPKR_AS_ITF_NBR) - { - return USBD_AUDIO_SPKR.Setup(pdev, req); - } -#endif -#if (USBD_USE_UVC == 1) - if (LOBYTE(req->wIndex) == UVC_VC_IF_NUM || LOBYTE(req->wIndex) == UVC_VS_IF_NUM) - { - return USBD_VIDEO.Setup(pdev, req); - } -#endif -#if (USBD_USE_MSC == 1) - if (LOBYTE(req->wIndex) == MSC_ITF_NBR) - { - return USBD_MSC.Setup(pdev, req); - } -#endif -#if (USBD_USE_DFU == 1) - if (LOBYTE(req->wIndex) == DFU_ITF_NBR) - { - return USBD_DFU.Setup(pdev, req); - } -#endif -#if (USBD_USE_PRNTR == 1) - if (LOBYTE(req->wIndex) == PRNT_ITF_NBR) - { - USBD_PRNT.Setup(pdev, req); - } -#endif - - return USBD_FAIL; -} - -/** - * @brief USBD_COMPOSITE_DataIn - * handle data IN Stage - * @param pdev: device instance - * @param epnum: endpoint index - * @retval status - */ -static uint8_t USBD_COMPOSITE_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum) -{ -#if (USBD_USE_CDC_ACM == 1) - for (uint8_t i = 0; i < USBD_CDC_ACM_COUNT; i++) - { - if (epnum == (CDC_IN_EP[i] & 0x7F) || epnum == (CDC_CMD_EP[i] & 0x7F)) - { - return USBD_CDC_ACM.DataIn (pdev, epnum); - } - } -#endif -#if (USBD_USE_CDC_ECM == 1) - if (epnum == (CDC_ECM_IN_EP & 0x7F) || epnum == (CDC_ECM_CMD_EP & 0x7F)) - { - return USBD_CDC_ECM.DataIn(pdev, epnum); - } -#endif -#if (USBD_USE_CDC_RNDIS == 1) - if (epnum == (CDC_RNDIS_IN_EP & 0x7F) || epnum == (CDC_RNDIS_CMD_EP & 0x7F)) - { - return USBD_CDC_RNDIS.DataIn(pdev, epnum); - } -#endif -#if (USBD_USE_HID_MOUSE == 1) - if (epnum == (HID_MOUSE_IN_EP & 0x7F)) - { - return USBD_HID_MOUSE.DataIn(pdev, epnum); - } -#endif -#if (USBD_USE_HID_KEYBOARD == 1) - if (epnum == (HID_KEYBOARD_IN_EP & 0x7F)) - { - return USBD_HID_KEYBOARD.DataIn(pdev, epnum); - } -#endif -#if (USBD_USE_HID_CUSTOM == 1) - if (epnum == (CUSTOM_HID_IN_EP & 0x7F)) - { - return USBD_HID_CUSTOM.DataIn(pdev, epnum); - } -#endif -#if (USBD_USE_UAC_MIC == 1) - if (epnum == (AUDIO_MIC_EP & 0x7F)) - { - return USBD_AUDIO_MIC.DataIn(pdev, epnum); - } -#endif -#if (USBD_USE_UAC_SPKR == 1) -#endif -#if (USBD_USE_UVC == 1) - if (epnum == (UVC_IN_EP & 0x7F)) - { - return USBD_VIDEO.DataIn(pdev, epnum); - } -#endif -#if (USBD_USE_MSC == 1) - if (epnum == (MSC_IN_EP & 0x7F)) - { - return USBD_MSC.DataIn(pdev, epnum); - } -#endif -#if (USBD_USE_DFU == 1) -#endif -#if (USBD_USE_PRNTR == 1) - if (epnum == (PRNT_IN_EP & 0x7F)) - { - USBD_PRNT.DataIn(pdev, epnum); - } -#endif - - return USBD_FAIL; -} - -/** - * @brief USBD_COMPOSITE_EP0_RxReady - * handle EP0 Rx Ready event - * @param pdev: device instance - * @retval status - */ -static uint8_t USBD_COMPOSITE_EP0_RxReady (USBD_HandleTypeDef *pdev) -{ -#if (USBD_USE_CDC_ACM == 1) - USBD_CDC_ACM.EP0_RxReady (pdev); -#endif -#if (USBD_USE_CDC_ECM == 1) - USBD_CDC_ECM.EP0_RxReady(pdev); -#endif -#if (USBD_USE_CDC_RNDIS == 1) - USBD_CDC_RNDIS.EP0_RxReady(pdev); -#endif -#if (USBD_USE_HID_MOUSE == 1) -#endif -#if (USBD_USE_HID_KEYBOARD == 1) -#endif -#if (USBD_USE_HID_CUSTOM == 1) - USBD_HID_CUSTOM.EP0_RxReady(pdev); -#endif -#if (USBD_USE_UAC_MIC == 1) - USBD_AUDIO_MIC.EP0_RxReady(pdev); -#endif -#if (USBD_USE_UAC_SPKR == 1) - USBD_AUDIO_SPKR.EP0_RxReady(pdev); -#endif -#if (USBD_USE_UVC == 1) -#endif -#if (USBD_USE_MSC == 1) -#endif -#if (USBD_USE_DFU == 1) - USBD_DFU.EP0_RxReady(pdev); -#endif -#if (USBD_USE_PRNTR == 1) -#endif - - return (uint8_t) USBD_OK; -} - -/** - * @brief USBD_COMPOSITE_EP0_TxReady - * handle EP0 TRx Ready event - * @param pdev: device instance - * @retval status - */ -static uint8_t USBD_COMPOSITE_EP0_TxReady (USBD_HandleTypeDef *pdev) -{ -#if (USBD_USE_CDC_ACM == 1) -#endif -#if (USBD_USE_CDC_ECM == 1) -#endif -#if (USBD_USE_CDC_RNDIS == 1) -#endif -#if (USBD_USE_HID_MOUSE == 1) -#endif -#if (USBD_USE_HID_KEYBOARD == 1) -#endif -#if (USBD_USE_HID_CUSTOM == 1) -#endif -#if (USBD_USE_UAC_MIC == 1) - USBD_AUDIO_MIC.EP0_TxSent(pdev); -#endif -#if (USBD_USE_UAC_SPKR == 1) - USBD_AUDIO_SPKR.EP0_TxSent(pdev); -#endif -#if (USBD_USE_UVC == 1) -#endif -#if (USBD_USE_MSC == 1) -#endif -#if (USBD_USE_DFU == 1) - USBD_DFU.EP0_TxSent(pdev); -#endif -#if (USBD_USE_PRNTR == 1) -#endif - - return (uint8_t) USBD_OK; -} - -/** - * @brief USBD_COMPOSITE_SOF - * handle SOF event - * @param pdev: device instance - * @retval status - */ -static uint8_t USBD_COMPOSITE_SOF (USBD_HandleTypeDef *pdev) -{ -#if (USBD_USE_CDC_ACM == 1) -#endif -#if (USBD_USE_CDC_ECM == 1) -#endif -#if (USBD_USE_CDC_RNDIS == 1) -#endif -#if (USBD_USE_HID_MOUSE == 1) -#endif -#if (USBD_USE_HID_KEYBOARD == 1) -#endif -#if (USBD_USE_HID_CUSTOM == 1) -#endif -#if (USBD_USE_UAC_MIC == 1) - USBD_AUDIO_MIC.SOF(pdev); -#endif -#if (USBD_USE_UAC_SPKR == 1) - USBD_AUDIO_SPKR.SOF(pdev); -#endif -#if (USBD_USE_UVC == 1) - USBD_VIDEO.SOF(pdev); -#endif -#if (USBD_USE_MSC == 1) -#endif -#if (USBD_USE_DFU == 1) - USBD_DFU.SOF(pdev); -#endif -#if (USBD_USE_PRNTR == 1) -#endif - - return (uint8_t) USBD_OK; -} - -/** - * @brief USBD_COMPOSITE_IsoINIncomplete - * handle data ISO IN Incomplete event - * @param pdev: device instance - * @param epnum: endpoint index - * @retval status - */ -static uint8_t USBD_COMPOSITE_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum) -{ -#if (USBD_USE_CDC_ACM == 1) -#endif -#if (USBD_USE_CDC_ECM == 1) -#endif -#if (USBD_USE_CDC_RNDIS == 1) -#endif -#if (USBD_USE_HID_MOUSE == 1) -#endif -#if (USBD_USE_HID_KEYBOARD == 1) -#endif -#if (USBD_USE_HID_CUSTOM == 1) -#endif -#if (USBD_USE_UAC_MIC == 1) - if (epnum == (AUDIO_MIC_EP & 0x7F)) - { - USBD_AUDIO_MIC.IsoINIncomplete(pdev, epnum); - } -#endif -#if (USBD_USE_UAC_SPKR == 1) -#endif -#if (USBD_USE_UVC == 1) - if (epnum == (UVC_IN_EP & 0x7F)) - { - USBD_VIDEO.IsoINIncomplete(pdev, epnum); - } -#endif -#if (USBD_USE_MSC == 1) -#endif -#if (USBD_USE_DFU == 1) -#endif -#if (USBD_USE_PRNTR == 1) -#endif - - return (uint8_t) USBD_OK; -} - -/** - * @brief USBD_COMPOSITE_IsoOutIncomplete - * handle data ISO OUT Incomplete event - * @param pdev: device instance - * @param epnum: endpoint index - * @retval status - */ -static uint8_t USBD_COMPOSITE_IsoOutIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum) -{ -#if (USBD_USE_CDC_ACM == 1) -#endif -#if (USBD_USE_CDC_ECM == 1) -#endif -#if (USBD_USE_CDC_RNDIS == 1) -#endif -#if (USBD_USE_HID_MOUSE == 1) -#endif -#if (USBD_USE_HID_KEYBOARD == 1) -#endif -#if (USBD_USE_HID_CUSTOM == 1) -#endif -#if (USBD_USE_UAC_MIC == 1) -#endif -#if (USBD_USE_UAC_SPKR == 1) - if (epnum == AUDIO_SPKR_EP) - { - USBD_AUDIO_SPKR.IsoOUTIncomplete(pdev, epnum); - } -#endif -#if (USBD_USE_UVC == 1) -#endif -#if (USBD_USE_MSC == 1) -#endif -#if (USBD_USE_DFU == 1) -#endif -#if (USBD_USE_PRNTR == 1) -#endif - - return (uint8_t) USBD_OK; -} -/** - * @brief USBD_COMPOSITE_DataOut - * handle data OUT Stage - * @param pdev: device instance - * @param epnum: endpoint index - * @retval status - */ -static uint8_t USBD_COMPOSITE_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum) -{ -#if (USBD_USE_CDC_ACM == 1) - for (uint8_t i = 0; i < USBD_CDC_ACM_COUNT; i++) - { - if (epnum == CDC_OUT_EP[i]) - { - return USBD_CDC_ACM.DataOut (pdev, epnum); - } - } -#endif -#if (USBD_USE_CDC_ECM == 1) - if (epnum == CDC_ECM_OUT_EP) - { - return USBD_CDC_ECM.DataOut(pdev, epnum); - } -#endif -#if (USBD_USE_CDC_RNDIS == 1) - if (epnum == CDC_RNDIS_OUT_EP) - { - return USBD_CDC_RNDIS.DataOut(pdev, epnum); - } -#endif -#if (USBD_USE_HID_MOUSE == 1) -#endif -#if (USBD_USE_HID_KEYBOARD == 1) -#endif -#if (USBD_USE_HID_CUSTOM == 1) - if (epnum == CUSTOM_HID_OUT_EP) - { - return USBD_HID_CUSTOM.DataOut(pdev, epnum); - } -#endif -#if (USBD_USE_UAC_MIC == 1) -#endif -#if (USBD_USE_UAC_SPKR == 1) - if (epnum == AUDIO_SPKR_EP) - { - return USBD_AUDIO_SPKR.DataOut(pdev, epnum); - } -#endif -#if (USBD_USE_UVC == 1) -#endif -#if (USBD_USE_MSC == 1) - if (epnum == MSC_OUT_EP) - { - return USBD_MSC.DataOut(pdev, epnum); - } -#endif -#if (USBD_USE_DFU == 1) -#endif -#if (USBD_USE_PRNTR == 1) - if (epnum == PRNT_OUT_EP) - { - USBD_PRNT.DataOut(pdev, epnum); - } -#endif - - return USBD_FAIL; -} - -/** - * @brief USBD_COMPOSITE_GetHSCfgDesc - * return configuration descriptor - * @param length : pointer data length - * @retval pointer to descriptor buffer - */ -static uint8_t* USBD_COMPOSITE_GetHSCfgDesc (uint16_t *length) -{ - *length = (uint16_t) sizeof(USBD_COMPOSITE_HSCfgDesc); - return (uint8_t*) &USBD_COMPOSITE_HSCfgDesc; -} - -/** - * @brief USBD_COMPOSITE_GetFSCfgDesc - * return configuration descriptor - * @param length : pointer data length - * @retval pointer to descriptor buffer - */ -static uint8_t* USBD_COMPOSITE_GetFSCfgDesc (uint16_t *length) -{ - *length = (uint16_t) sizeof(USBD_COMPOSITE_FSCfgDesc); - return (uint8_t*) &USBD_COMPOSITE_FSCfgDesc; -} - -/** - * @brief USBD_COMPOSITE_GetOtherSpeedCfgDesc - * return configuration descriptor - * @param length : pointer data length - * @retval pointer to descriptor buffer - */ -static uint8_t* USBD_COMPOSITE_GetOtherSpeedCfgDesc (uint16_t *length) -{ -#if (USBD_USE_HS == 1) - *length = (uint16_t)sizeof(USBD_COMPOSITE_FSCfgDesc); - return (uint8_t *)&USBD_COMPOSITE_FSCfgDesc; -#else - *length = (uint16_t) sizeof(USBD_COMPOSITE_HSCfgDesc); - return (uint8_t*) &USBD_COMPOSITE_HSCfgDesc; -#endif -} - -/** - * @brief DeviceQualifierDescriptor - * return Device Qualifier descriptor - * @param length : pointer data length - * @retval pointer to descriptor buffer - */ -uint8_t* USBD_COMPOSITE_GetDeviceQualifierDesc (uint16_t *length) -{ - *length = (uint16_t) sizeof(USBD_COMPOSITE_DeviceQualifierDesc); - return USBD_COMPOSITE_DeviceQualifierDesc; -} - -/** - * @brief USBD_COMPOSITE_GetUsrStringDesc - * Manages the transfer of memory interfaces string descriptors. - * @param speed : current device speed - * @param index: descriptor index - * @param length : pointer data length - * @retval pointer to the descriptor table or NULL if the descriptor is not supported. - */ -#if (USBD_SUPPORT_USER_STRING_DESC == 1U) -static uint8_t* USBD_COMPOSITE_GetUsrStringDesc (USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length) -{ - static uint8_t USBD_StrDesc[64]; - - /* Check if the requested string interface is supported */ - if (index <= USBD_Track_String_Index) - { -#if (USBD_USE_CDC_ACM == 1) - char str_buffer[16] = ""; - for (uint8_t i = 0; i < USBD_CDC_ACM_COUNT; i++) - { - if (index == CDC_STR_DESC_IDX[i]) - { - snprintf (str_buffer, sizeof(str_buffer), CDC_ACM_STR_DESC, i); - USBD_GetString ((uint8_t*) str_buffer, USBD_StrDesc, length); - } - } -#endif -#if (USBD_USE_CDC_ECM == 1) - if (index == CDC_ECM_STR_DESC_IDX) - { - USBD_GetString((uint8_t *)CDC_ECM_STR_DESC, USBD_StrDesc, length); - } -#endif -#if (USBD_USE_CDC_RNDIS == 1) - if (index == CDC_RNDIS_STR_DESC_IDX) - { - USBD_GetString((uint8_t *)CDC_RNDIS_STR_DESC, USBD_StrDesc, length); - } -#endif -#if (USBD_USE_HID_MOUSE == 1) - if (index == HID_MOUSE_STR_DESC_IDX) - { - USBD_GetString((uint8_t *)HID_MOUSE_STR_DESC, USBD_StrDesc, length); - } -#endif -#if (USBD_USE_HID_KEYBOARD == 1) - if (index == HID_KEYBOARD_STR_DESC_IDX) - { - USBD_GetString((uint8_t *)HID_KEYBOARD_STR_DESC, USBD_StrDesc, length); - } -#endif -#if (USBD_USE_HID_CUSTOM == 1) - if (index == CUSTOM_HID_STR_DESC_IDX) - { - USBD_GetString((uint8_t *)CUSTOM_HID_STR_DESC, USBD_StrDesc, length); - } -#endif -#if (USBD_USE_UAC_MIC == 1) - if (index == AUDIO_MIC_STR_DESC_IDX) - { - USBD_GetString((uint8_t *)AUDIO_MIC_STR_DESC, USBD_StrDesc, length); - } -#endif -#if (USBD_USE_UAC_SPKR == 1) - if (index == AUDIO_SPKR_STR_DESC_IDX) - { - USBD_GetString((uint8_t *)AUDIO_SPKR_STR_DESC, USBD_StrDesc, length); - } -#endif -#if (USBD_USE_UVC == 1) - if (index == UVC_STR_DESC_IDX) - { - USBD_GetString((uint8_t *)UVC_STR_DESC, USBD_StrDesc, length); - } -#endif -#if (USBD_USE_MSC == 1) - if (index == MSC_BOT_STR_DESC_IDX) - { - USBD_GetString((uint8_t *)MSC_BOT_STR_DESC, USBD_StrDesc, length); - } -#endif -#if (USBD_USE_DFU == 1) - if (index == DFU_STR_DESC_IDX) - { - USBD_GetString((uint8_t *)DFU_STR_DESC, USBD_StrDesc, length); - } -#endif -#if (USBD_USE_PRNTR == 1) - if (index == PRINTER_STR_DESC_IDX) - { - USBD_GetString((uint8_t *)PRNT_STR_DESC, USBD_StrDesc, length); - } -#endif - return USBD_StrDesc; - } - else - { - /* Not supported Interface Descriptor index */ - return NULL; - } -} -#endif - -void USBD_COMPOSITE_Mount_Class (void) -{ - uint16_t len = 0; - uint8_t *ptr = NULL; - - uint8_t in_ep_track = 0x81; - uint8_t out_ep_track = 0x01; - uint8_t interface_no_track = 0x00; - -#if (USBD_USE_CDC_RNDIS == 1) - ptr = USBD_CDC_RNDIS.GetFSConfigDescriptor(&len); - USBD_Update_CDC_RNDIS_DESC(ptr, - interface_no_track, - interface_no_track + 1, - in_ep_track, - in_ep_track + 1, - out_ep_track, - USBD_Track_String_Index); - memcpy(USBD_COMPOSITE_FSCfgDesc.USBD_CDC_RNDIS_DESC, ptr + 0x09, len - 0x09); - - ptr = USBD_CDC_RNDIS.GetHSConfigDescriptor(&len); - USBD_Update_CDC_RNDIS_DESC(ptr, - interface_no_track, - interface_no_track + 1, - in_ep_track, - in_ep_track + 1, - out_ep_track, - USBD_Track_String_Index); - memcpy(USBD_COMPOSITE_HSCfgDesc.USBD_CDC_RNDIS_DESC, ptr + 0x09, len - 0x09); - - in_ep_track += 2; - out_ep_track += 1; - interface_no_track += 2; - USBD_Track_String_Index += 1; -#endif - -#if (USBD_USE_CDC_ECM == 1) - ptr = USBD_CDC_ECM.GetFSConfigDescriptor(&len); - USBD_Update_CDC_ECM_DESC(ptr, - interface_no_track, - interface_no_track + 1, - in_ep_track, - in_ep_track + 1, - out_ep_track, - USBD_Track_String_Index); - memcpy(USBD_COMPOSITE_FSCfgDesc.USBD_CDC_ECM_DESC, ptr + 0x09, len - 0x09); - - ptr = USBD_CDC_ECM.GetHSConfigDescriptor(&len); - USBD_Update_CDC_ECM_DESC(ptr, - interface_no_track, - interface_no_track + 1, - in_ep_track, - in_ep_track + 1, - out_ep_track, - USBD_Track_String_Index); - memcpy(USBD_COMPOSITE_HSCfgDesc.USBD_CDC_ECM_DESC, ptr + 0x09, len - 0x09); - - in_ep_track += 2; - out_ep_track += 1; - interface_no_track += 2; - USBD_Track_String_Index += 1; -#endif - -#if (USBD_USE_HID_MOUSE == 1) - ptr = USBD_HID_MOUSE.GetFSConfigDescriptor(&len); - USBD_Update_HID_Mouse_DESC(ptr, interface_no_track, in_ep_track, USBD_Track_String_Index); - memcpy(USBD_COMPOSITE_FSCfgDesc.USBD_HID_MOUSE_DESC, ptr + 0x09, len - 0x09); - - ptr = USBD_HID_MOUSE.GetHSConfigDescriptor(&len); - USBD_Update_HID_Mouse_DESC(ptr, interface_no_track, in_ep_track, USBD_Track_String_Index); - memcpy(USBD_COMPOSITE_HSCfgDesc.USBD_HID_MOUSE_DESC, ptr + 0x09, len - 0x09); - - in_ep_track += 1; - interface_no_track += 1; - USBD_Track_String_Index += 1; -#endif - -#if (USBD_USE_HID_KEYBOARD == 1) - ptr = USBD_HID_KEYBOARD.GetFSConfigDescriptor(&len); - USBD_Update_HID_KBD_DESC(ptr, interface_no_track, in_ep_track, USBD_Track_String_Index); - memcpy(USBD_COMPOSITE_FSCfgDesc.USBD_HID_KEYBOARD_DESC, ptr + 0x09, len - 0x09); - - ptr = USBD_HID_KEYBOARD.GetHSConfigDescriptor(&len); - USBD_Update_HID_KBD_DESC(ptr, interface_no_track, in_ep_track, USBD_Track_String_Index); - memcpy(USBD_COMPOSITE_HSCfgDesc.USBD_HID_KEYBOARD_DESC, ptr + 0x09, len - 0x09); - - in_ep_track += 1; - interface_no_track += 1; - USBD_Track_String_Index += 1; -#endif - -#if (USBD_USE_HID_CUSTOM == 1) - ptr = USBD_HID_CUSTOM.GetFSConfigDescriptor(&len); - USBD_Update_HID_Custom_DESC(ptr, interface_no_track, in_ep_track, out_ep_track, USBD_Track_String_Index); - memcpy(USBD_COMPOSITE_FSCfgDesc.USBD_HID_CUSTOM_DESC, ptr + 0x09, len - 0x09); - - ptr = USBD_HID_CUSTOM.GetHSConfigDescriptor(&len); - USBD_Update_HID_Custom_DESC(ptr, interface_no_track, in_ep_track, out_ep_track, USBD_Track_String_Index); - memcpy(USBD_COMPOSITE_HSCfgDesc.USBD_HID_CUSTOM_DESC, ptr + 0x09, len - 0x09); - - in_ep_track += 1; - out_ep_track += 1; - interface_no_track += 1; - USBD_Track_String_Index += 1; -#endif - -#if (USBD_USE_UAC_MIC == 1) - ptr = USBD_AUDIO_MIC.GetFSConfigDescriptor(&len); - USBD_Update_Audio_MIC_DESC(ptr, - interface_no_track, - interface_no_track + 1, - in_ep_track, - USBD_Track_String_Index); - memcpy(USBD_COMPOSITE_FSCfgDesc.USBD_UAC_MIC_DESC, ptr + 0x09, len - 0x09); - - ptr = USBD_AUDIO_MIC.GetHSConfigDescriptor(&len); - USBD_Update_Audio_MIC_DESC(ptr, - interface_no_track, - interface_no_track + 1, - in_ep_track, - USBD_Track_String_Index); - - memcpy(USBD_COMPOSITE_HSCfgDesc.USBD_UAC_MIC_DESC, ptr + 0x09, len - 0x09); - in_ep_track += 1; - interface_no_track += 2; - USBD_Track_String_Index += 1; -#endif - -#if (USBD_USE_UAC_SPKR == 1) - ptr = USBD_AUDIO_SPKR.GetFSConfigDescriptor(&len); - USBD_Update_Audio_SPKR_DESC(ptr, interface_no_track, interface_no_track + 1, out_ep_track, USBD_Track_String_Index); - memcpy(USBD_COMPOSITE_FSCfgDesc.USBD_AUDIO_SPKR_DESC, ptr + 0x09, len - 0x09); - - ptr = USBD_AUDIO_SPKR.GetHSConfigDescriptor(&len); - USBD_Update_Audio_SPKR_DESC(ptr, interface_no_track, interface_no_track + 1, out_ep_track, USBD_Track_String_Index); - memcpy(USBD_COMPOSITE_HSCfgDesc.USBD_AUDIO_SPKR_DESC, ptr + 0x09, len - 0x09); - - out_ep_track += 1; - interface_no_track += 2; - USBD_Track_String_Index += 1; -#endif - -#if (USBD_USE_UVC == 1) - ptr = USBD_VIDEO.GetFSConfigDescriptor(&len); - USBD_Update_UVC_DESC(ptr, interface_no_track, interface_no_track + 1, in_ep_track, USBD_Track_String_Index); - memcpy(USBD_COMPOSITE_FSCfgDesc.USBD_UVC_DESC, ptr + 0x09, len - 0x09); - - ptr = USBD_VIDEO.GetHSConfigDescriptor(&len); - USBD_Update_UVC_DESC(ptr, interface_no_track, interface_no_track + 1, in_ep_track, USBD_Track_String_Index); - memcpy(USBD_COMPOSITE_HSCfgDesc.USBD_UVC_DESC, ptr + 0x09, len - 0x09); - - in_ep_track += 1; - interface_no_track += 2; - USBD_Track_String_Index += 1; -#endif - -#if (USBD_USE_MSC == 1) - ptr = USBD_MSC.GetFSConfigDescriptor(&len); - USBD_Update_MSC_DESC(ptr, interface_no_track, in_ep_track, out_ep_track, USBD_Track_String_Index); - memcpy(USBD_COMPOSITE_FSCfgDesc.USBD_MSC_DESC, ptr + 0x09, len - 0x09); - - ptr = USBD_MSC.GetHSConfigDescriptor(&len); - USBD_Update_MSC_DESC(ptr, interface_no_track, in_ep_track, out_ep_track, USBD_Track_String_Index); - memcpy(USBD_COMPOSITE_HSCfgDesc.USBD_MSC_DESC, ptr + 0x09, len - 0x09); - - in_ep_track += 1; - out_ep_track += 1; - interface_no_track += 1; - USBD_Track_String_Index += 1; -#endif - -#if (USBD_USE_DFU == 1) - ptr = USBD_DFU.GetFSConfigDescriptor(&len); - USBD_Update_DFU_DESC(ptr, interface_no_track, USBD_Track_String_Index); - memcpy(USBD_COMPOSITE_FSCfgDesc.USBD_DFU_DESC, ptr + 0x09, len - 0x09); - - ptr = USBD_DFU.GetHSConfigDescriptor(&len); - USBD_Update_DFU_DESC(ptr, interface_no_track, USBD_Track_String_Index); - memcpy(USBD_COMPOSITE_HSCfgDesc.USBD_DFU_DESC, ptr + 0x09, len - 0x09); - - interface_no_track += USBD_DFU_MAX_ITF_NUM; - USBD_Track_String_Index += USBD_DFU_MAX_ITF_NUM; -#endif - -#if (USBD_USE_PRNTR == 1) - ptr = USBD_PRNT.GetFSConfigDescriptor(&len); - USBD_Update_PRNT_DESC(ptr, interface_no_track, in_ep_track, out_ep_track, USBD_Track_String_Index); - memcpy(USBD_COMPOSITE_FSCfgDesc.USBD_PRNTR_DESC, ptr + 0x09, len - 0x09); - - ptr = USBD_PRNT.GetHSConfigDescriptor(&len); - USBD_Update_PRNT_DESC(ptr, interface_no_track, in_ep_track, out_ep_track, USBD_Track_String_Index); - memcpy(USBD_COMPOSITE_HSCfgDesc.USBD_PRNTR_DESC, ptr + 0x09, len - 0x09); - - in_ep_track += 1; - out_ep_track += 1; - interface_no_track += 1; - USBD_Track_String_Index += 1; -#endif - -#if (USBD_USE_CDC_ACM == 1) - ptr = USBD_CDC_ACM.GetFSConfigDescriptor (&len); - USBD_Update_CDC_ACM_DESC (ptr, interface_no_track, interface_no_track + 1, in_ep_track, in_ep_track + 1, out_ep_track, USBD_Track_String_Index); - memcpy (USBD_COMPOSITE_FSCfgDesc.USBD_CDC_ACM_DESC, ptr + 0x09, len - 0x09); - - ptr = USBD_CDC_ACM.GetHSConfigDescriptor (&len); - USBD_Update_CDC_ACM_DESC (ptr, interface_no_track, interface_no_track + 1, in_ep_track, in_ep_track + 1, out_ep_track, USBD_Track_String_Index); - memcpy (USBD_COMPOSITE_HSCfgDesc.USBD_CDC_ACM_DESC, ptr + 0x09, len - 0x09); - - in_ep_track += 2 * USBD_CDC_ACM_COUNT; - out_ep_track += 1 * USBD_CDC_ACM_COUNT; - interface_no_track += 2 * USBD_CDC_ACM_COUNT; - USBD_Track_String_Index += USBD_CDC_ACM_COUNT; -#endif - - uint16_t CFG_SIZE = sizeof(USBD_COMPOSITE_CFG_DESC_t); - ptr = USBD_COMPOSITE_HSCfgDesc.CONFIG_DESC; - /* Configuration Descriptor */ - ptr[0] = 0x09; /* bLength: Configuration Descriptor size */ - ptr[1] = USB_DESC_TYPE_CONFIGURATION; /* bDescriptorType: Configuration */ - ptr[2] = LOBYTE(CFG_SIZE); /* wTotalLength:no of returned bytes */ - ptr[3] = HIBYTE(CFG_SIZE); - ptr[4] = interface_no_track; /* bNumInterfaces: 2 interface */ - ptr[5] = 0x01; /* bConfigurationValue: Configuration value */ - ptr[6] = 0x00; /* iConfiguration: Index of string descriptor describing the configuration */ -#if (USBD_SELF_POWERED == 1U) - ptr[7] = 0xC0; /* bmAttributes: Bus Powered according to user configuration */ -#else - ptr[7] = 0x80; /* bmAttributes: Bus Powered according to user configuration */ -#endif - ptr[8] = USBD_MAX_POWER; /* MaxPower 100 mA */ - - ptr = USBD_COMPOSITE_FSCfgDesc.CONFIG_DESC; - /* Configuration Descriptor */ - ptr[0] = 0x09; /* bLength: Configuration Descriptor size */ - ptr[1] = USB_DESC_TYPE_CONFIGURATION; /* bDescriptorType: Configuration */ - ptr[2] = LOBYTE(CFG_SIZE); /* wTotalLength:no of returned bytes */ - ptr[3] = HIBYTE(CFG_SIZE); - ptr[4] = interface_no_track; /* bNumInterfaces: 2 interface */ - ptr[5] = 0x01; /* bConfigurationValue: Configuration value */ - ptr[6] = 0x00; /* iConfiguration: Index of string descriptor describing the configuration */ -#if (USBD_SELF_POWERED == 1U) - ptr[7] = 0xC0; /* bmAttributes: Bus Powered according to user configuration */ -#else - ptr[7] = 0x80; /* bmAttributes: Bus Powered according to user configuration */ -#endif - ptr[8] = USBD_MAX_POWER; /* MaxPower 100 mA */ - - (void) out_ep_track; - (void) in_ep_track; -} - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/AL94_USB_Composite/Core/Inc/usbd_core.h b/common/AL94_USB_Composite/Core/Inc/usbd_core.h deleted file mode 100644 index c7426ad..0000000 --- a/common/AL94_USB_Composite/Core/Inc/usbd_core.h +++ /dev/null @@ -1,149 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_core.h - * @author MCD Application Team - * @brief Header file for usbd_core.c file - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

- * - * 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 inclusion -------------------------------------*/ -#ifndef __USBD_CORE_H -#define __USBD_CORE_H - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* Includes ------------------------------------------------------------------*/ -#include "usbd_conf.h" -#include "usbd_def.h" -#include "usbd_ioreq.h" -#include "usbd_ctlreq.h" - - /** @addtogroup STM32_USB_DEVICE_LIBRARY - * @{ - */ - - /** @defgroup USBD_CORE - * @brief This file is the Header file for usbd_core.c file - * @{ - */ - - /** @defgroup USBD_CORE_Exported_Defines - * @{ - */ -#ifndef USBD_DEBUG_LEVEL -#define USBD_DEBUG_LEVEL 0U -#endif /* USBD_DEBUG_LEVEL */ - /** - * @} - */ - - /** @defgroup USBD_CORE_Exported_TypesDefinitions - * @{ - */ - - /** - * @} - */ - - /** @defgroup USBD_CORE_Exported_Macros - * @{ - */ - - /** - * @} - */ - - /** @defgroup USBD_CORE_Exported_Variables - * @{ - */ -#define USBD_SOF USBD_LL_SOF - /** - * @} - */ - - /** @defgroup USBD_CORE_Exported_FunctionsPrototype - * @{ - */ - USBD_StatusTypeDef USBD_Init (USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id); - USBD_StatusTypeDef USBD_DeInit (USBD_HandleTypeDef *pdev); - USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev); - USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev); - USBD_StatusTypeDef USBD_RegisterClass (USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass); - - USBD_StatusTypeDef USBD_RunTestMode (USBD_HandleTypeDef *pdev); - USBD_StatusTypeDef USBD_SetClassConfig (USBD_HandleTypeDef *pdev, uint8_t cfgidx); - USBD_StatusTypeDef USBD_ClrClassConfig (USBD_HandleTypeDef *pdev, uint8_t cfgidx); - - USBD_StatusTypeDef USBD_LL_SetupStage (USBD_HandleTypeDef *pdev, uint8_t *psetup); - USBD_StatusTypeDef USBD_LL_DataOutStage (USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata); - USBD_StatusTypeDef USBD_LL_DataInStage (USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata); - - USBD_StatusTypeDef USBD_LL_Reset (USBD_HandleTypeDef *pdev); - USBD_StatusTypeDef USBD_LL_SetSpeed (USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed); - USBD_StatusTypeDef USBD_LL_Suspend (USBD_HandleTypeDef *pdev); - USBD_StatusTypeDef USBD_LL_Resume (USBD_HandleTypeDef *pdev); - - USBD_StatusTypeDef USBD_LL_SOF (USBD_HandleTypeDef *pdev); - USBD_StatusTypeDef USBD_LL_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum); - USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum); - - USBD_StatusTypeDef USBD_LL_DevConnected (USBD_HandleTypeDef *pdev); - USBD_StatusTypeDef USBD_LL_DevDisconnected (USBD_HandleTypeDef *pdev); - - /* USBD Low Level Driver */ - USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev); - USBD_StatusTypeDef USBD_LL_DeInit (USBD_HandleTypeDef *pdev); - USBD_StatusTypeDef USBD_LL_Start (USBD_HandleTypeDef *pdev); - USBD_StatusTypeDef USBD_LL_Stop (USBD_HandleTypeDef *pdev); - - USBD_StatusTypeDef USBD_LL_OpenEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps); - - USBD_StatusTypeDef USBD_LL_CloseEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); - USBD_StatusTypeDef USBD_LL_FlushEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); - USBD_StatusTypeDef USBD_LL_StallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); - USBD_StatusTypeDef USBD_LL_ClearStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); - USBD_StatusTypeDef USBD_LL_SetUSBAddress (USBD_HandleTypeDef *pdev, uint8_t dev_addr); - - USBD_StatusTypeDef USBD_LL_Transmit (USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size); - - USBD_StatusTypeDef USBD_LL_PrepareReceive (USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size); - - uint8_t USBD_LL_IsStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); - uint32_t USBD_LL_GetRxDataSize (USBD_HandleTypeDef *pdev, uint8_t ep_addr); - - void USBD_LL_Delay (uint32_t Delay); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USBD_CORE_H */ - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - diff --git a/common/AL94_USB_Composite/Core/Inc/usbd_ctlreq.h b/common/AL94_USB_Composite/Core/Inc/usbd_ctlreq.h deleted file mode 100644 index 0eeb2ff..0000000 --- a/common/AL94_USB_Composite/Core/Inc/usbd_ctlreq.h +++ /dev/null @@ -1,99 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_req.h - * @author MCD Application Team - * @brief Header file for the usbd_req.c file - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

- * - * 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 inclusion -------------------------------------*/ -#ifndef __USB_REQUEST_H -#define __USB_REQUEST_H - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* Includes ------------------------------------------------------------------*/ -#include "usbd_def.h" - - /** @addtogroup STM32_USB_DEVICE_LIBRARY - * @{ - */ - - /** @defgroup USBD_REQ - * @brief header file for the usbd_req.c file - * @{ - */ - - /** @defgroup USBD_REQ_Exported_Defines - * @{ - */ - /** - * @} - */ - - /** @defgroup USBD_REQ_Exported_Types - * @{ - */ - /** - * @} - */ - - /** @defgroup USBD_REQ_Exported_Macros - * @{ - */ - /** - * @} - */ - - /** @defgroup USBD_REQ_Exported_Variables - * @{ - */ - /** - * @} - */ - - /** @defgroup USBD_REQ_Exported_FunctionsPrototype - * @{ - */ - - USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); - USBD_StatusTypeDef USBD_StdItfReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); - USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); - - void USBD_CtlError (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); - void USBD_ParseSetupRequest (USBD_SetupReqTypedef *req, uint8_t *pdata); - void USBD_GetString (uint8_t *desc, uint8_t *unicode, uint16_t *len); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USB_REQUEST_H */ - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/AL94_USB_Composite/Core/Inc/usbd_def.h b/common/AL94_USB_Composite/Core/Inc/usbd_def.h deleted file mode 100644 index 3002c36..0000000 --- a/common/AL94_USB_Composite/Core/Inc/usbd_def.h +++ /dev/null @@ -1,429 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_def.h - * @author MCD Application Team - * @brief General defines for the usb device library - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

- * - * 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 inclusion -------------------------------------*/ -#ifndef __USBD_DEF_H -#define __USBD_DEF_H - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* Includes ------------------------------------------------------------------*/ -#include "usbd_conf.h" - - /** @addtogroup STM32_USBD_DEVICE_LIBRARY - * @{ - */ - - /** @defgroup USB_DEF - * @brief general defines for the usb device library file - * @{ - */ - - /** @defgroup USB_DEF_Exported_Defines - * @{ - */ - -#ifndef NULL -#define NULL 0U -#endif /* NULL */ - -#ifndef USBD_MAX_NUM_INTERFACES -#define USBD_MAX_NUM_INTERFACES 1U -#endif /* USBD_MAX_NUM_CONFIGURATION */ - -#ifndef USBD_MAX_NUM_CONFIGURATION -#define USBD_MAX_NUM_CONFIGURATION 1U -#endif /* USBD_MAX_NUM_CONFIGURATION */ - -#ifndef USBD_LPM_ENABLED -#define USBD_LPM_ENABLED 0U -#endif /* USBD_LPM_ENABLED */ - -#ifndef USBD_SELF_POWERED -#define USBD_SELF_POWERED 1U -#endif /*USBD_SELF_POWERED */ - -#ifndef USBD_MAX_POWER -#define USBD_MAX_POWER 0x32U /* 100 mA */ -#endif /* USBD_MAX_POWER */ - -#ifndef USBD_SUPPORT_USER_STRING_DESC -#define USBD_SUPPORT_USER_STRING_DESC 0U -#endif /* USBD_SUPPORT_USER_STRING_DESC */ - -#ifndef USBD_CLASS_USER_STRING_DESC -#define USBD_CLASS_USER_STRING_DESC 0U -#endif /* USBD_CLASS_USER_STRING_DESC */ - -#define USB_LEN_DEV_QUALIFIER_DESC 0x0AU -#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_LANGID_STR_DESC 0x04U -#define USB_LEN_OTHER_SPEED_DESC_SIZ 0x09U - -#define USBD_IDX_LANGID_STR 0x00U -#define USBD_IDX_MFC_STR 0x01U -#define USBD_IDX_PRODUCT_STR 0x02U -#define USBD_IDX_SERIAL_STR 0x03U -#define USBD_IDX_CONFIG_STR 0x04U -#define USBD_IDX_INTERFACE_STR 0x05U - -#define USB_REQ_TYPE_STANDARD 0x00U -#define USB_REQ_TYPE_CLASS 0x20U -#define USB_REQ_TYPE_VENDOR 0x40U -#define USB_REQ_TYPE_MASK 0x60U - -#define USB_REQ_RECIPIENT_DEVICE 0x00U -#define USB_REQ_RECIPIENT_INTERFACE 0x01U -#define USB_REQ_RECIPIENT_ENDPOINT 0x02U -#define USB_REQ_RECIPIENT_MASK 0x03U - -#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 - -#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_IAD 0x0BU -#define USB_DESC_TYPE_BOS 0x0FU - -#define USB_CONFIG_REMOTE_WAKEUP 0x02U -#define USB_CONFIG_SELF_POWERED 0x01U - -#define USB_FEATURE_EP_HALT 0x00U -#define USB_FEATURE_REMOTE_WAKEUP 0x01U -#define USB_FEATURE_TEST_MODE 0x02U - -#define USB_DEVICE_CAPABITY_TYPE 0x10U - -#define USB_CONF_DESC_SIZE 0x09U -#define USB_IF_DESC_SIZE 0x09U -#define USB_EP_DESC_SIZE 0x07U -#define USB_IAD_DESC_SIZE 0x08U - -#define USB_HS_MAX_PACKET_SIZE 512U -#define USB_FS_MAX_PACKET_SIZE 64U -#define USB_MAX_EP0_SIZE 64U - - /* Device Status */ -#define USBD_STATE_DEFAULT 0x01U -#define USBD_STATE_ADDRESSED 0x02U -#define USBD_STATE_CONFIGURED 0x03U -#define USBD_STATE_SUSPENDED 0x04U - - /* EP0 State */ -#define USBD_EP0_IDLE 0x00U -#define USBD_EP0_SETUP 0x01U -#define USBD_EP0_DATA_IN 0x02U -#define USBD_EP0_DATA_OUT 0x03U -#define USBD_EP0_STATUS_IN 0x04U -#define USBD_EP0_STATUS_OUT 0x05U -#define USBD_EP0_STALL 0x06U - -#define USBD_EP_TYPE_CTRL 0x00U -#define USBD_EP_TYPE_ISOC 0x01U -#define USBD_EP_TYPE_BULK 0x02U -#define USBD_EP_TYPE_INTR 0x03U - - /** - * @} - */ - - /** @defgroup USBD_DEF_Exported_TypesDefinitions - * @{ - */ - - typedef struct usb_setup_req - { - uint8_t bmRequest; - uint8_t bRequest; - uint16_t wValue; - uint16_t wIndex; - uint16_t wLength; - } USBD_SetupReqTypedef; - - typedef struct - { - uint8_t bLength; - uint8_t bDescriptorType; - uint16_t wTotalLength; - uint8_t bNumInterfaces; - uint8_t bConfigurationValue; - uint8_t iConfiguration; - uint8_t bmAttributes; - uint8_t bMaxPower; - } USBD_ConfigDescTypedef; - - typedef struct - { - uint8_t bLength; - uint8_t bDescriptorType; - uint16_t wTotalLength; - uint8_t bNumDeviceCaps; - } USBD_BosDescTypedef; - - typedef struct - { - uint8_t bLength; - uint8_t bDescriptorType; - uint8_t bEndpointAddress; - uint8_t bmAttributes; - uint16_t wMaxPacketSize; - uint8_t bInterval; - } USBD_EpDescTypedef; - - struct _USBD_HandleTypeDef; - - typedef struct _Device_cb - { - uint8_t (*Init) (struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx); - uint8_t (*DeInit) (struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx); - /* Control Endpoints*/ - uint8_t (*Setup) (struct _USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); - uint8_t (*EP0_TxSent) (struct _USBD_HandleTypeDef *pdev); - uint8_t (*EP0_RxReady) (struct _USBD_HandleTypeDef *pdev); - /* Class Specific Endpoints*/ - uint8_t (*DataIn) (struct _USBD_HandleTypeDef *pdev, uint8_t epnum); - uint8_t (*DataOut) (struct _USBD_HandleTypeDef *pdev, uint8_t epnum); - uint8_t (*SOF) (struct _USBD_HandleTypeDef *pdev); - uint8_t (*IsoINIncomplete) (struct _USBD_HandleTypeDef *pdev, uint8_t epnum); - uint8_t (*IsoOUTIncomplete) (struct _USBD_HandleTypeDef *pdev, uint8_t epnum); - - uint8_t* (*GetHSConfigDescriptor) (uint16_t *length); - uint8_t* (*GetFSConfigDescriptor) (uint16_t *length); - uint8_t* (*GetOtherSpeedConfigDescriptor) (uint16_t *length); - uint8_t* (*GetDeviceQualifierDescriptor) (uint16_t *length); -#if (USBD_SUPPORT_USER_STRING_DESC == 1U) - uint8_t* (*GetUsrStrDescriptor) (struct _USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length); -#endif - - } USBD_ClassTypeDef; - - /* Following USB Device Speed */ - typedef enum - { - USBD_SPEED_HIGH = 0U, USBD_SPEED_FULL = 1U, USBD_SPEED_LOW = 2U, - } USBD_SpeedTypeDef; - - /* Following USB Device status */ - typedef enum - { - USBD_OK = 0U, USBD_BUSY, USBD_EMEM, USBD_FAIL, - } USBD_StatusTypeDef; - - /* USB Device descriptors structure */ - typedef struct - { - uint8_t* (*GetDeviceDescriptor) (USBD_SpeedTypeDef speed, uint16_t *length); - uint8_t* (*GetLangIDStrDescriptor) (USBD_SpeedTypeDef speed, uint16_t *length); - uint8_t* (*GetManufacturerStrDescriptor) (USBD_SpeedTypeDef speed, uint16_t *length); - uint8_t* (*GetProductStrDescriptor) (USBD_SpeedTypeDef speed, uint16_t *length); - uint8_t* (*GetSerialStrDescriptor) (USBD_SpeedTypeDef speed, uint16_t *length); - uint8_t* (*GetConfigurationStrDescriptor) (USBD_SpeedTypeDef speed, uint16_t *length); - uint8_t* (*GetInterfaceStrDescriptor) (USBD_SpeedTypeDef speed, uint16_t *length); -#if (USBD_CLASS_USER_STRING_DESC == 1) - uint8_t *(*GetUserStrDescriptor)(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length); -#endif -#if ((USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1)) - uint8_t *(*GetBOSDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length); -#endif - } USBD_DescriptorsTypeDef; - - /* USB Device handle structure */ - typedef struct - { - uint32_t status; - uint32_t total_length; - uint32_t rem_length; - uint32_t maxpacket; - uint16_t is_used; - uint16_t bInterval; - } USBD_EndpointTypeDef; - - /* USB Device handle structure */ - typedef struct _USBD_HandleTypeDef - { - uint8_t id; - uint32_t dev_config; - uint32_t dev_default_config; - uint32_t dev_config_status; - USBD_SpeedTypeDef dev_speed; - USBD_EndpointTypeDef ep_in[16]; - USBD_EndpointTypeDef ep_out[16]; - __IO uint32_t ep0_state; - uint32_t ep0_data_len; - __IO uint8_t dev_state; - __IO uint8_t dev_old_state; - uint8_t dev_address; - uint8_t dev_connection_status; - uint8_t dev_test_mode; - uint32_t dev_remote_wakeup; - uint8_t ConfIdx; - - USBD_SetupReqTypedef request; - USBD_DescriptorsTypeDef *pDesc; - USBD_ClassTypeDef *pClass; - void *pUserData_CDC_ACM; - void *pClassData_CDC_RNDIS; - void *pUserData_CDC_RNDIS; - void *pClassData_CDC_ECM; - void *pUserData_CDC_ECM; - void *pClassData_HID_Mouse; - void *pClassData_HID_Keyboard; - void *pClassData_HID_Custom; - void *pUserData_HID_Custom; - void *pClassData_UAC_MIC; - void *pUserData_UAC_MIC; - void *pClassData_UAC_SPKR; - void *pUserData_UAC_SPKR; - void *pClassData_UVC; - void *pUserData_UVC; - void *pClassData_MSC; - void *pUserData_MSC; - void *pClassData_DFU; - void *pUserData_DFU; - void *pClassData_PRNTR; - void *pUserData_PRNTR; - void *pData; - void *pBosDesc; - void *pConfDesc; - } USBD_HandleTypeDef; - - /** - * @} - */ - - /** @defgroup USBD_DEF_Exported_Macros - * @{ - */ - __STATIC_INLINE uint16_t SWAPBYTE (uint8_t *addr) - { - uint16_t _SwapVal, _Byte1, _Byte2; - uint8_t *_pbuff = addr; - - _Byte1 = *(uint8_t*) _pbuff; - _pbuff++; - _Byte2 = *(uint8_t*) _pbuff; - - _SwapVal = (_Byte2 << 8) | _Byte1; - - return _SwapVal; - } - -#ifndef LOBYTE -#define LOBYTE(x) ((uint8_t)((x) & 0x00FFU)) -#endif - -#ifndef HIBYTE -#define HIBYTE(x) ((uint8_t)(((x) & 0xFF00U) >> 8U)) -#endif - -#ifndef MIN -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) -#endif - -#ifndef MAX -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#endif - -#if defined ( __GNUC__ ) -#ifndef __weak -#define __weak __attribute__((weak)) -#endif /* __weak */ -#ifndef __packed -#define __packed __attribute__((__packed__)) -#endif /* __packed */ -#endif /* __GNUC__ */ - -/* In HS mode and when the DMA is used, all variables and data structures dealing - with the DMA during the transaction process should be 4-bytes aligned */ - -#if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */ -#ifndef __ALIGN_END -#define __ALIGN_END __attribute__ ((aligned (4U))) -#endif /* __ALIGN_END */ -#ifndef __ALIGN_BEGIN -#define __ALIGN_BEGIN -#endif /* __ALIGN_BEGIN */ -#else -#ifndef __ALIGN_END -#define __ALIGN_END -#endif /* __ALIGN_END */ -#ifndef __ALIGN_BEGIN -#if defined (__CC_ARM) /* ARM Compiler */ -#define __ALIGN_BEGIN __align(4U) -#elif defined (__ICCARM__) /* IAR Compiler */ -#define __ALIGN_BEGIN -#endif /* __CC_ARM */ -#endif /* __ALIGN_BEGIN */ -#endif /* __GNUC__ */ - -/** - * @} - */ - -/** @defgroup USBD_DEF_Exported_Variables - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_DEF_Exported_FunctionsPrototype - * @{ - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USBD_DEF_H */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/AL94_USB_Composite/Core/Inc/usbd_ioreq.h b/common/AL94_USB_Composite/Core/Inc/usbd_ioreq.h deleted file mode 100644 index 8d56fc2..0000000 --- a/common/AL94_USB_Composite/Core/Inc/usbd_ioreq.h +++ /dev/null @@ -1,107 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_ioreq.h - * @author MCD Application Team - * @brief Header file for the usbd_ioreq.c file - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

- * - * 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 inclusion -------------------------------------*/ -#ifndef __USBD_IOREQ_H -#define __USBD_IOREQ_H - -#ifdef __cplusplus -extern "C" -{ -#endif - - /* Includes ------------------------------------------------------------------*/ -#include "usbd_def.h" -#include "usbd_core.h" - - /** @addtogroup STM32_USB_DEVICE_LIBRARY - * @{ - */ - - /** @defgroup USBD_IOREQ - * @brief header file for the usbd_ioreq.c file - * @{ - */ - - /** @defgroup USBD_IOREQ_Exported_Defines - * @{ - */ - /** - * @} - */ - - /** @defgroup USBD_IOREQ_Exported_Types - * @{ - */ - - /** - * @} - */ - - /** @defgroup USBD_IOREQ_Exported_Macros - * @{ - */ - - /** - * @} - */ - - /** @defgroup USBD_IOREQ_Exported_Variables - * @{ - */ - - /** - * @} - */ - - /** @defgroup USBD_IOREQ_Exported_FunctionsPrototype - * @{ - */ - - USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t len); - - USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t len); - - USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t len); - - USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t len); - - USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev); - USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev); - - uint32_t USBD_GetRxCount (USBD_HandleTypeDef *pdev, uint8_t ep_addr); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USBD_IOREQ_H */ - -/** - * @} - */ - -/** - * @} - */ -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/AL94_USB_Composite/Core/Src/usbd_core.c b/common/AL94_USB_Composite/Core/Src/usbd_core.c deleted file mode 100644 index ad7bf28..0000000 --- a/common/AL94_USB_Composite/Core/Src/usbd_core.c +++ /dev/null @@ -1,673 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_core.c - * @author MCD Application Team - * @brief This file provides all the USBD core functions. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

- * - * 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 "usbd_core.h" - -/** @addtogroup STM32_USBD_DEVICE_LIBRARY - * @{ - */ - -/** @defgroup USBD_CORE - * @brief usbd core module - * @{ - */ - -/** @defgroup USBD_CORE_Private_TypesDefinitions - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_CORE_Private_Defines - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_CORE_Private_Macros - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_CORE_Private_FunctionPrototypes - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_CORE_Private_Variables - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_CORE_Private_Functions - * @{ - */ - -/** - * @brief USBD_Init - * Initializes the device stack and load the class driver - * @param pdev: device instance - * @param pdesc: Descriptor structure address - * @param id: Low level core index - * @retval None - */ -USBD_StatusTypeDef USBD_Init (USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id) -{ - USBD_StatusTypeDef ret; - - /* Check whether the USB Host handle is valid */ - if (pdev == NULL) - { -#if (USBD_DEBUG_LEVEL > 1U) - USBD_ErrLog("Invalid Device handle"); -#endif - return USBD_FAIL; - } - - /* Unlink previous class resources */ - pdev->pClass = NULL; - pdev->pConfDesc = NULL; - - /* Assign USBD Descriptors */ - if (pdesc != NULL) - { - pdev->pDesc = pdesc; - } - - /* Set Device initial State */ - pdev->dev_state = USBD_STATE_DEFAULT; - pdev->id = id; - - /* Initialize low level driver */ - ret = USBD_LL_Init (pdev); - - return ret; -} - -/** - * @brief USBD_DeInit - * Re-Initialize the device library - * @param pdev: device instance - * @retval status: status - */ -USBD_StatusTypeDef USBD_DeInit (USBD_HandleTypeDef *pdev) -{ - USBD_StatusTypeDef ret; - - /* Disconnect the USB Device */ - (void) USBD_LL_Stop (pdev); - - /* Set Default State */ - pdev->dev_state = USBD_STATE_DEFAULT; - - /* Free Class Resources */ - if (pdev->pClass != NULL) - { - pdev->pClass->DeInit (pdev, (uint8_t) pdev->dev_config); - pdev->pClass = NULL; - } - - /* Free Device descriptors resources */ - pdev->pDesc = NULL; - pdev->pConfDesc = NULL; - - /* DeInitialize low level driver */ - ret = USBD_LL_DeInit (pdev); - - return ret; -} - -/** - * @brief USBD_RegisterClass - * Link class driver to Device Core. - * @param pDevice : Device Handle - * @param pclass: Class handle - * @retval USBD Status - */ -USBD_StatusTypeDef USBD_RegisterClass (USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass) -{ - uint16_t len = 0U; - - if (pclass == NULL) - { -#if (USBD_DEBUG_LEVEL > 1U) - USBD_ErrLog("Invalid Class handle"); -#endif - return USBD_FAIL; - } - - /* link the class to the USB Device handle */ - pdev->pClass = pclass; - - /* Get Device Configuration Descriptor */ - if (pdev->dev_speed == USBD_SPEED_HIGH) - { - if (pdev->pClass->GetHSConfigDescriptor != NULL) - { - pdev->pConfDesc = (void*) pdev->pClass->GetHSConfigDescriptor (&len); - } - } - else if (pdev->pClass->GetFSConfigDescriptor != NULL) - { - pdev->pConfDesc = (void*) pdev->pClass->GetFSConfigDescriptor (&len); - } - - return USBD_OK; -} - -/** - * @brief USBD_Start - * Start the USB Device Core. - * @param pdev: Device Handle - * @retval USBD Status - */ -USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev) -{ - /* Start the low level driver */ - return USBD_LL_Start (pdev); -} - -/** - * @brief USBD_Stop - * Stop the USB Device Core. - * @param pdev: Device Handle - * @retval USBD Status - */ -USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev) -{ - /* Disconnect USB Device */ - (void) USBD_LL_Stop (pdev); - - /* Free Class Resources */ - if (pdev->pClass != NULL) - { - (void) pdev->pClass->DeInit (pdev, (uint8_t) pdev->dev_config); - } - - return USBD_OK; -} - -/** - * @brief USBD_RunTestMode - * Launch test mode process - * @param pdev: device instance - * @retval status - */ -USBD_StatusTypeDef USBD_RunTestMode (USBD_HandleTypeDef *pdev) -{ - /* Prevent unused argument compilation warning */ - UNUSED(pdev); - - return USBD_OK; -} - -/** - * @brief USBD_SetClassConfig - * Configure device and start the interface - * @param pdev: device instance - * @param cfgidx: configuration index - * @retval status - */ - -USBD_StatusTypeDef USBD_SetClassConfig (USBD_HandleTypeDef *pdev, uint8_t cfgidx) -{ - USBD_StatusTypeDef ret = USBD_FAIL; - - if (pdev->pClass != NULL) - { - /* Set configuration and Start the Class */ - ret = (USBD_StatusTypeDef) pdev->pClass->Init (pdev, cfgidx); - } - - return ret; -} - -/** - * @brief USBD_ClrClassConfig - * Clear current configuration - * @param pdev: device instance - * @param cfgidx: configuration index - * @retval status: USBD_StatusTypeDef - */ -USBD_StatusTypeDef USBD_ClrClassConfig (USBD_HandleTypeDef *pdev, uint8_t cfgidx) -{ - /* Clear configuration and De-initialize the Class process */ - if (pdev->pClass != NULL) - { - pdev->pClass->DeInit (pdev, cfgidx); - } - - return USBD_OK; -} - -/** - * @brief USBD_LL_SetupStage - * Handle the setup stage - * @param pdev: device instance - * @retval status - */ -USBD_StatusTypeDef USBD_LL_SetupStage (USBD_HandleTypeDef *pdev, uint8_t *psetup) -{ - USBD_StatusTypeDef ret; - - USBD_ParseSetupRequest (&pdev->request, psetup); - - pdev->ep0_state = USBD_EP0_SETUP; - - pdev->ep0_data_len = pdev->request.wLength; - - switch (pdev->request.bmRequest & 0x1FU) - { - case USB_REQ_RECIPIENT_DEVICE: - ret = USBD_StdDevReq (pdev, &pdev->request); - break; - - case USB_REQ_RECIPIENT_INTERFACE: - ret = USBD_StdItfReq (pdev, &pdev->request); - break; - - case USB_REQ_RECIPIENT_ENDPOINT: - ret = USBD_StdEPReq (pdev, &pdev->request); - break; - - default: - ret = USBD_LL_StallEP (pdev, (pdev->request.bmRequest & 0x80U)); - break; - } - - return ret; -} - -/** - * @brief USBD_LL_DataOutStage - * Handle data OUT stage - * @param pdev: device instance - * @param epnum: endpoint index - * @param pdata: data pointer - * @retval status - */ -USBD_StatusTypeDef USBD_LL_DataOutStage (USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata) -{ - USBD_EndpointTypeDef *pep; - USBD_StatusTypeDef ret; - - if (epnum == 0U) - { - pep = &pdev->ep_out[0]; - - if (pdev->ep0_state == USBD_EP0_DATA_OUT) - { - if (pep->rem_length > pep->maxpacket) - { - pep->rem_length -= pep->maxpacket; - - (void) USBD_CtlContinueRx (pdev, pdata, MIN(pep->rem_length, pep->maxpacket)); - } - else - { - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - if (pdev->pClass->EP0_RxReady != NULL) - { - pdev->pClass->EP0_RxReady (pdev); - } - } - - (void) USBD_CtlSendStatus (pdev); - } - } - else - { -#if 0 - if (pdev->ep0_state == USBD_EP0_STATUS_OUT) - { - /* - * STATUS PHASE completed, update ep0_state to idle - */ - pdev->ep0_state = USBD_EP0_IDLE; - (void)USBD_LL_StallEP(pdev, 0U); - } -#endif - } - } - else - { - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - if (pdev->pClass->DataOut != NULL) - { - ret = (USBD_StatusTypeDef) pdev->pClass->DataOut (pdev, epnum); - - if (ret != USBD_OK) - { - return ret; - } - } - } - } - - return USBD_OK; -} - -/** - * @brief USBD_LL_DataInStage - * Handle data in stage - * @param pdev: device instance - * @param epnum: endpoint index - * @retval status - */ -USBD_StatusTypeDef USBD_LL_DataInStage (USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata) -{ - USBD_EndpointTypeDef *pep; - USBD_StatusTypeDef ret; - - if (epnum == 0U) - { - pep = &pdev->ep_in[0]; - - if (pdev->ep0_state == USBD_EP0_DATA_IN) - { - if (pep->rem_length > pep->maxpacket) - { - pep->rem_length -= pep->maxpacket; - - (void) USBD_CtlContinueSendData (pdev, pdata, pep->rem_length); - - /* Prepare endpoint for premature end of transfer */ - (void) USBD_LL_PrepareReceive (pdev, 0U, NULL, 0U); - } - else - { - /* last packet is MPS multiple, so send ZLP packet */ - if ((pep->maxpacket == pep->rem_length) && (pep->total_length >= pep->maxpacket) && (pep->total_length < pdev->ep0_data_len)) - { - (void) USBD_CtlContinueSendData (pdev, NULL, 0U); - pdev->ep0_data_len = 0U; - - /* Prepare endpoint for premature end of transfer */ - (void) USBD_LL_PrepareReceive (pdev, 0U, NULL, 0U); - } - else - { - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - if (pdev->pClass->EP0_TxSent != NULL) - { - pdev->pClass->EP0_TxSent (pdev); - } - } - (void) USBD_LL_StallEP (pdev, 0x80U); - (void) USBD_CtlReceiveStatus (pdev); - } - } - } - else - { -#if 0 - if ((pdev->ep0_state == USBD_EP0_STATUS_IN) || - (pdev->ep0_state == USBD_EP0_IDLE)) - { - (void)USBD_LL_StallEP(pdev, 0x80U); - } -#endif - } - - if (pdev->dev_test_mode == 1U) - { - (void) USBD_RunTestMode (pdev); - pdev->dev_test_mode = 0U; - } - } - else - { - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - if (pdev->pClass->DataIn != NULL) - { - ret = (USBD_StatusTypeDef) pdev->pClass->DataIn (pdev, epnum); - - if (ret != USBD_OK) - { - return ret; - } - } - } - } - - return USBD_OK; -} - -/** - * @brief USBD_LL_Reset - * Handle Reset event - * @param pdev: device instance - * @retval status - */ - -USBD_StatusTypeDef USBD_LL_Reset (USBD_HandleTypeDef *pdev) -{ - /* Upon Reset call user call back */ - pdev->dev_state = USBD_STATE_DEFAULT; - pdev->ep0_state = USBD_EP0_IDLE; - pdev->dev_config = 0U; - pdev->dev_remote_wakeup = 0U; - - if (pdev->pClass == NULL) - { - return USBD_FAIL; - } - - if (pdev->pClass->DeInit != NULL) - { - (void) pdev->pClass->DeInit (pdev, (uint8_t) pdev->dev_config); - } - - /* Open EP0 OUT */ - (void) USBD_LL_OpenEP (pdev, 0x00U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE); - pdev->ep_out[0x00U & 0xFU].is_used = 1U; - - pdev->ep_out[0].maxpacket = USB_MAX_EP0_SIZE; - - /* Open EP0 IN */ - (void) USBD_LL_OpenEP (pdev, 0x80U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE); - pdev->ep_in[0x80U & 0xFU].is_used = 1U; - - pdev->ep_in[0].maxpacket = USB_MAX_EP0_SIZE; - - return USBD_OK; -} - -/** - * @brief USBD_LL_SetSpeed - * Handle Reset event - * @param pdev: device instance - * @retval status - */ -USBD_StatusTypeDef USBD_LL_SetSpeed (USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed) -{ - pdev->dev_speed = speed; - - return USBD_OK; -} - -/** - * @brief USBD_LL_Suspend - * Handle Suspend event - * @param pdev: device instance - * @retval status - */ - -USBD_StatusTypeDef USBD_LL_Suspend (USBD_HandleTypeDef *pdev) -{ - pdev->dev_old_state = pdev->dev_state; - pdev->dev_state = USBD_STATE_SUSPENDED; - - return USBD_OK; -} - -/** - * @brief USBD_LL_Resume - * Handle Resume event - * @param pdev: device instance - * @retval status - */ - -USBD_StatusTypeDef USBD_LL_Resume (USBD_HandleTypeDef *pdev) -{ - if (pdev->dev_state == USBD_STATE_SUSPENDED) - { - pdev->dev_state = pdev->dev_old_state; - } - - return USBD_OK; -} - -/** - * @brief USBD_LL_SOF - * Handle SOF event - * @param pdev: device instance - * @retval status - */ - -USBD_StatusTypeDef USBD_LL_SOF (USBD_HandleTypeDef *pdev) -{ - if (pdev->pClass == NULL) - { - return USBD_FAIL; - } - - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - if (pdev->pClass->SOF != NULL) - { - (void) pdev->pClass->SOF (pdev); - } - } - - return USBD_OK; -} - -/** - * @brief USBD_LL_IsoINIncomplete - * Handle iso in incomplete event - * @param pdev: device instance - * @retval status - */ -USBD_StatusTypeDef USBD_LL_IsoINIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum) -{ - if (pdev->pClass == NULL) - { - return USBD_FAIL; - } - - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - if (pdev->pClass->IsoINIncomplete != NULL) - { - (void) pdev->pClass->IsoINIncomplete (pdev, epnum); - } - } - - return USBD_OK; -} - -/** - * @brief USBD_LL_IsoOUTIncomplete - * Handle iso out incomplete event - * @param pdev: device instance - * @retval status - */ -USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete (USBD_HandleTypeDef *pdev, uint8_t epnum) -{ - if (pdev->pClass == NULL) - { - return USBD_FAIL; - } - - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - if (pdev->pClass->IsoOUTIncomplete != NULL) - { - (void) pdev->pClass->IsoOUTIncomplete (pdev, epnum); - } - } - - return USBD_OK; -} - -/** - * @brief USBD_LL_DevConnected - * Handle device connection event - * @param pdev: device instance - * @retval status - */ -USBD_StatusTypeDef USBD_LL_DevConnected (USBD_HandleTypeDef *pdev) -{ - /* Prevent unused argument compilation warning */ - UNUSED(pdev); - - return USBD_OK; -} - -/** - * @brief USBD_LL_DevDisconnected - * Handle device disconnection event - * @param pdev: device instance - * @retval status - */ -USBD_StatusTypeDef USBD_LL_DevDisconnected (USBD_HandleTypeDef *pdev) -{ - /* Free Class Resources */ - pdev->dev_state = USBD_STATE_DEFAULT; - - if (pdev->pClass != NULL) - { - (void) pdev->pClass->DeInit (pdev, (uint8_t) pdev->dev_config); - } - - return USBD_OK; -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - diff --git a/common/AL94_USB_Composite/Core/Src/usbd_ctlreq.c b/common/AL94_USB_Composite/Core/Src/usbd_ctlreq.c deleted file mode 100644 index 36ae460..0000000 --- a/common/AL94_USB_Composite/Core/Src/usbd_ctlreq.c +++ /dev/null @@ -1,928 +0,0 @@ -/** - ****************************************************************************** - * @file usbd_req.c - * @author MCD Application Team - * @brief This file provides the standard USB requests following chapter 9. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

- * - * 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 "usbd_ctlreq.h" -#include "usbd_ioreq.h" - -/** @addtogroup STM32_USBD_STATE_DEVICE_LIBRARY - * @{ - */ - -/** @defgroup USBD_REQ - * @brief USB standard requests module - * @{ - */ - -/** @defgroup USBD_REQ_Private_TypesDefinitions - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_REQ_Private_Defines - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_REQ_Private_Macros - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_REQ_Private_Variables - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_REQ_Private_FunctionPrototypes - * @{ - */ -static void USBD_GetDescriptor (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static void USBD_SetAddress (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static USBD_StatusTypeDef USBD_SetConfig (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static void USBD_GetConfig (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static void USBD_GetStatus (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static void USBD_SetFeature (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static void USBD_ClrFeature (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); -static uint8_t USBD_GetLen (uint8_t *buf); - -/** - * @} - */ - -/** @defgroup USBD_REQ_Private_Functions - * @{ - */ - -/** - * @brief USBD_StdDevReq - * Handle standard usb device requests - * @param pdev: device instance - * @param req: usb request - * @retval status - */ -USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - USBD_StatusTypeDef ret = USBD_OK; - - switch (req->bmRequest & USB_REQ_TYPE_MASK) - { - case USB_REQ_TYPE_CLASS: - case USB_REQ_TYPE_VENDOR: - ret = (USBD_StatusTypeDef) pdev->pClass->Setup (pdev, req); - break; - - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - case USB_REQ_GET_DESCRIPTOR: - USBD_GetDescriptor (pdev, req); - break; - - case USB_REQ_SET_ADDRESS: - USBD_SetAddress (pdev, req); - break; - - case USB_REQ_SET_CONFIGURATION: - ret = USBD_SetConfig (pdev, req); - break; - - case USB_REQ_GET_CONFIGURATION: - USBD_GetConfig (pdev, req); - break; - - case USB_REQ_GET_STATUS: - USBD_GetStatus (pdev, req); - break; - - case USB_REQ_SET_FEATURE: - USBD_SetFeature (pdev, req); - break; - - case USB_REQ_CLEAR_FEATURE: - USBD_ClrFeature (pdev, req); - break; - - default: - USBD_CtlError (pdev, req); - break; - } - break; - - default: - USBD_CtlError (pdev, req); - break; - } - - return ret; -} - -/** - * @brief USBD_StdItfReq - * Handle standard usb interface requests - * @param pdev: device instance - * @param req: usb request - * @retval status - */ -USBD_StatusTypeDef USBD_StdItfReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - USBD_StatusTypeDef ret = USBD_OK; - - switch (req->bmRequest & USB_REQ_TYPE_MASK) - { - case USB_REQ_TYPE_CLASS: - case USB_REQ_TYPE_VENDOR: - case USB_REQ_TYPE_STANDARD: - switch (pdev->dev_state) - { - case USBD_STATE_DEFAULT: - case USBD_STATE_ADDRESSED: - case USBD_STATE_CONFIGURED: - - if (LOBYTE(req->wIndex) <= USBD_MAX_NUM_INTERFACES) - { - ret = (USBD_StatusTypeDef) pdev->pClass->Setup (pdev, req); - - if ((req->wLength == 0U) && (ret == USBD_OK)) - { - (void) USBD_CtlSendStatus (pdev); - } - } - else - { - USBD_CtlError (pdev, req); - } - break; - - default: - USBD_CtlError (pdev, req); - break; - } - break; - - default: - USBD_CtlError (pdev, req); - break; - } - - return ret; -} - -/** - * @brief USBD_StdEPReq - * Handle standard usb endpoint requests - * @param pdev: device instance - * @param req: usb request - * @retval status - */ -USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - USBD_EndpointTypeDef *pep; - uint8_t ep_addr; - USBD_StatusTypeDef ret = USBD_OK; - ep_addr = LOBYTE(req->wIndex); - - switch (req->bmRequest & USB_REQ_TYPE_MASK) - { - case USB_REQ_TYPE_CLASS: - case USB_REQ_TYPE_VENDOR: - ret = (USBD_StatusTypeDef) pdev->pClass->Setup (pdev, req); - break; - - case USB_REQ_TYPE_STANDARD: - switch (req->bRequest) - { - case USB_REQ_SET_FEATURE: - switch (pdev->dev_state) - { - case USBD_STATE_ADDRESSED: - if ((ep_addr != 0x00U) && (ep_addr != 0x80U)) - { - (void) USBD_LL_StallEP (pdev, ep_addr); - (void) USBD_LL_StallEP (pdev, 0x80U); - } - else - { - USBD_CtlError (pdev, req); - } - break; - - case USBD_STATE_CONFIGURED: - if (req->wValue == USB_FEATURE_EP_HALT) - { - if ((ep_addr != 0x00U) && (ep_addr != 0x80U) && (req->wLength == 0x00U)) - { - (void) USBD_LL_StallEP (pdev, ep_addr); - } - } - (void) USBD_CtlSendStatus (pdev); - - break; - - default: - USBD_CtlError (pdev, req); - break; - } - break; - - case USB_REQ_CLEAR_FEATURE: - - switch (pdev->dev_state) - { - case USBD_STATE_ADDRESSED: - if ((ep_addr != 0x00U) && (ep_addr != 0x80U)) - { - (void) USBD_LL_StallEP (pdev, ep_addr); - (void) USBD_LL_StallEP (pdev, 0x80U); - } - else - { - USBD_CtlError (pdev, req); - } - break; - - case USBD_STATE_CONFIGURED: - if (req->wValue == USB_FEATURE_EP_HALT) - { - if ((ep_addr & 0x7FU) != 0x00U) - { - (void) USBD_LL_ClearStallEP (pdev, ep_addr); - } - (void) USBD_CtlSendStatus (pdev); - ret = (USBD_StatusTypeDef) pdev->pClass->Setup (pdev, req); - } - break; - - default: - USBD_CtlError (pdev, req); - break; - } - break; - - case USB_REQ_GET_STATUS: - switch (pdev->dev_state) - { - case USBD_STATE_ADDRESSED: - if ((ep_addr != 0x00U) && (ep_addr != 0x80U)) - { - USBD_CtlError (pdev, req); - break; - } - pep = ((ep_addr & 0x80U) == 0x80U) ? &pdev->ep_in[ep_addr & 0x7FU] : &pdev->ep_out[ep_addr & 0x7FU]; - - pep->status = 0x0000U; - - (void) USBD_CtlSendData (pdev, (uint8_t*) &pep->status, 2U); - break; - - case USBD_STATE_CONFIGURED: - if ((ep_addr & 0x80U) == 0x80U) - { - if (pdev->ep_in[ep_addr & 0xFU].is_used == 0U) - { - USBD_CtlError (pdev, req); - break; - } - } - else - { - if (pdev->ep_out[ep_addr & 0xFU].is_used == 0U) - { - USBD_CtlError (pdev, req); - break; - } - } - - pep = ((ep_addr & 0x80U) == 0x80U) ? &pdev->ep_in[ep_addr & 0x7FU] : &pdev->ep_out[ep_addr & 0x7FU]; - - if ((ep_addr == 0x00U) || (ep_addr == 0x80U)) - { - pep->status = 0x0000U; - } - else if (USBD_LL_IsStallEP (pdev, ep_addr) != 0U) - { - pep->status = 0x0001U; - } - else - { - pep->status = 0x0000U; - } - - (void) USBD_CtlSendData (pdev, (uint8_t*) &pep->status, 2U); - break; - - default: - USBD_CtlError (pdev, req); - break; - } - break; - - default: - USBD_CtlError (pdev, req); - break; - } - break; - - default: - USBD_CtlError (pdev, req); - break; - } - - return ret; -} - -/** - * @brief USBD_GetDescriptor - * Handle Get Descriptor requests - * @param pdev: device instance - * @param req: usb request - * @retval status - */ -static void USBD_GetDescriptor (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - uint16_t len = 0U; - uint8_t *pbuf = NULL; - uint8_t err = 0U; - - switch (req->wValue >> 8) - { -#if ((USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1U)) - case USB_DESC_TYPE_BOS: - if (pdev->pDesc->GetBOSDescriptor != NULL) - { - pbuf = pdev->pDesc->GetBOSDescriptor(pdev->dev_speed, &len); - } - else - { - USBD_CtlError(pdev, req); - err++; - } - break; -#endif - case USB_DESC_TYPE_DEVICE: - pbuf = pdev->pDesc->GetDeviceDescriptor (pdev->dev_speed, &len); - break; - - case USB_DESC_TYPE_CONFIGURATION: - if (pdev->dev_speed == USBD_SPEED_HIGH) - { - pbuf = pdev->pClass->GetHSConfigDescriptor (&len); - pbuf[1] = USB_DESC_TYPE_CONFIGURATION; - } - else - { - pbuf = pdev->pClass->GetFSConfigDescriptor (&len); - pbuf[1] = USB_DESC_TYPE_CONFIGURATION; - } - break; - - case USB_DESC_TYPE_STRING: - switch ((uint8_t) (req->wValue)) - { - case USBD_IDX_LANGID_STR: - if (pdev->pDesc->GetLangIDStrDescriptor != NULL) - { - pbuf = pdev->pDesc->GetLangIDStrDescriptor (pdev->dev_speed, &len); - } - else - { - USBD_CtlError (pdev, req); - err++; - } - break; - - case USBD_IDX_MFC_STR: - if (pdev->pDesc->GetManufacturerStrDescriptor != NULL) - { - pbuf = pdev->pDesc->GetManufacturerStrDescriptor (pdev->dev_speed, &len); - } - else - { - USBD_CtlError (pdev, req); - err++; - } - break; - - case USBD_IDX_PRODUCT_STR: - if (pdev->pDesc->GetProductStrDescriptor != NULL) - { - pbuf = pdev->pDesc->GetProductStrDescriptor (pdev->dev_speed, &len); - } - else - { - USBD_CtlError (pdev, req); - err++; - } - break; - - case USBD_IDX_SERIAL_STR: - if (pdev->pDesc->GetSerialStrDescriptor != NULL) - { - pbuf = pdev->pDesc->GetSerialStrDescriptor (pdev->dev_speed, &len); - } - else - { - USBD_CtlError (pdev, req); - err++; - } - break; - - case USBD_IDX_CONFIG_STR: - if (pdev->pDesc->GetConfigurationStrDescriptor != NULL) - { - pbuf = pdev->pDesc->GetConfigurationStrDescriptor (pdev->dev_speed, &len); - } - else - { - USBD_CtlError (pdev, req); - err++; - } - break; - - case USBD_IDX_INTERFACE_STR: - if (pdev->pDesc->GetInterfaceStrDescriptor != NULL) - { - pbuf = pdev->pDesc->GetInterfaceStrDescriptor (pdev->dev_speed, &len); - } - else - { - USBD_CtlError (pdev, req); - err++; - } - break; - - default: -#if (USBD_SUPPORT_USER_STRING_DESC == 1U) - if (pdev->pClass->GetUsrStrDescriptor != NULL) - { - pbuf = pdev->pClass->GetUsrStrDescriptor (pdev, (req->wValue), &len); - } - else - { - USBD_CtlError (pdev, req); - err++; - } -#endif - -#if (USBD_CLASS_USER_STRING_DESC == 1U) - if (pdev->pDesc->GetUserStrDescriptor != NULL) - { - pbuf = pdev->pDesc->GetUserStrDescriptor(pdev->dev_speed, (req->wValue), &len); - } - else - { - USBD_CtlError(pdev, req); - err++; - } -#endif - -#if ((USBD_CLASS_USER_STRING_DESC == 0U) && (USBD_SUPPORT_USER_STRING_DESC == 0U)) - USBD_CtlError(pdev, req); - err++; -#endif - break; - } - break; - - case USB_DESC_TYPE_DEVICE_QUALIFIER: - if (pdev->dev_speed == USBD_SPEED_HIGH) - { - pbuf = pdev->pClass->GetDeviceQualifierDescriptor (&len); - } - else - { - USBD_CtlError (pdev, req); - err++; - } - break; - - case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION: - if (pdev->dev_speed == USBD_SPEED_HIGH) - { - pbuf = pdev->pClass->GetOtherSpeedConfigDescriptor (&len); - pbuf[1] = USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION; - } - else - { - USBD_CtlError (pdev, req); - err++; - } - break; - - default: - USBD_CtlError (pdev, req); - err++; - break; - } - - if (err != 0U) - { - return; - } - - if (req->wLength != 0U) - { - if (len != 0U) - { - len = MIN(len, req->wLength); - (void) USBD_CtlSendData (pdev, pbuf, len); - } - else - { - USBD_CtlError (pdev, req); - } - } - else - { - (void) USBD_CtlSendStatus (pdev); - } -} - -/** - * @brief USBD_SetAddress - * Set device address - * @param pdev: device instance - * @param req: usb request - * @retval status - */ -static void USBD_SetAddress (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - uint8_t dev_addr; - - if ((req->wIndex == 0U) && (req->wLength == 0U) && (req->wValue < 128U)) - { - dev_addr = (uint8_t) (req->wValue) & 0x7FU; - - if (pdev->dev_state == USBD_STATE_CONFIGURED) - { - USBD_CtlError (pdev, req); - } - else - { - pdev->dev_address = dev_addr; - (void) USBD_LL_SetUSBAddress (pdev, dev_addr); - (void) USBD_CtlSendStatus (pdev); - - if (dev_addr != 0U) - { - pdev->dev_state = USBD_STATE_ADDRESSED; - } - else - { - pdev->dev_state = USBD_STATE_DEFAULT; - } - } - } - else - { - USBD_CtlError (pdev, req); - } -} - -/** - * @brief USBD_SetConfig - * Handle Set device configuration request - * @param pdev: device instance - * @param req: usb request - * @retval status - */ -static USBD_StatusTypeDef USBD_SetConfig (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - USBD_StatusTypeDef ret = USBD_OK; - static uint8_t cfgidx; - - cfgidx = (uint8_t) (req->wValue); - - if (cfgidx > USBD_MAX_NUM_CONFIGURATION) - { - USBD_CtlError (pdev, req); - return USBD_FAIL; - } - - switch (pdev->dev_state) - { - case USBD_STATE_ADDRESSED: - if (cfgidx != 0U) - { - pdev->dev_config = cfgidx; - - ret = USBD_SetClassConfig (pdev, cfgidx); - - if (ret != USBD_OK) - { - USBD_CtlError (pdev, req); - } - else - { - (void) USBD_CtlSendStatus (pdev); - pdev->dev_state = USBD_STATE_CONFIGURED; - } - } - else - { - (void) USBD_CtlSendStatus (pdev); - } - break; - - case USBD_STATE_CONFIGURED: - if (cfgidx == 0U) - { - pdev->dev_state = USBD_STATE_ADDRESSED; - pdev->dev_config = cfgidx; - (void) USBD_ClrClassConfig (pdev, cfgidx); - (void) USBD_CtlSendStatus (pdev); - } - else if (cfgidx != pdev->dev_config) - { - /* Clear old configuration */ - (void) USBD_ClrClassConfig (pdev, (uint8_t) pdev->dev_config); - - /* set new configuration */ - pdev->dev_config = cfgidx; - - ret = USBD_SetClassConfig (pdev, cfgidx); - - if (ret != USBD_OK) - { - USBD_CtlError (pdev, req); - (void) USBD_ClrClassConfig (pdev, (uint8_t) pdev->dev_config); - pdev->dev_state = USBD_STATE_ADDRESSED; - } - else - { - (void) USBD_CtlSendStatus (pdev); - } - } - else - { - (void) USBD_CtlSendStatus (pdev); - } - break; - - default: - USBD_CtlError (pdev, req); - (void) USBD_ClrClassConfig (pdev, cfgidx); - ret = USBD_FAIL; - break; - } - - return ret; -} - -/** - * @brief USBD_GetConfig - * Handle Get device configuration request - * @param pdev: device instance - * @param req: usb request - * @retval status - */ -static void USBD_GetConfig (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - if (req->wLength != 1U) - { - USBD_CtlError (pdev, req); - } - else - { - switch (pdev->dev_state) - { - case USBD_STATE_DEFAULT: - case USBD_STATE_ADDRESSED: - pdev->dev_default_config = 0U; - (void) USBD_CtlSendData (pdev, (uint8_t*) &pdev->dev_default_config, 1U); - break; - - case USBD_STATE_CONFIGURED: - (void) USBD_CtlSendData (pdev, (uint8_t*) &pdev->dev_config, 1U); - break; - - default: - USBD_CtlError (pdev, req); - break; - } - } -} - -/** - * @brief USBD_GetStatus - * Handle Get Status request - * @param pdev: device instance - * @param req: usb request - * @retval status - */ -static void USBD_GetStatus (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - switch (pdev->dev_state) - { - case USBD_STATE_DEFAULT: - case USBD_STATE_ADDRESSED: - case USBD_STATE_CONFIGURED: - if (req->wLength != 0x2U) - { - USBD_CtlError (pdev, req); - break; - } - -#if (USBD_SELF_POWERED == 1U) - pdev->dev_config_status = USB_CONFIG_SELF_POWERED; -#else - pdev->dev_config_status = 0U; -#endif - - if (pdev->dev_remote_wakeup != 0U) - { - pdev->dev_config_status |= USB_CONFIG_REMOTE_WAKEUP; - } - - (void) USBD_CtlSendData (pdev, (uint8_t*) &pdev->dev_config_status, 2U); - break; - - default: - USBD_CtlError (pdev, req); - break; - } -} - -/** - * @brief USBD_SetFeature - * Handle Set device feature request - * @param pdev: device instance - * @param req: usb request - * @retval status - */ -static void USBD_SetFeature (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) - { - pdev->dev_remote_wakeup = 1U; - (void) USBD_CtlSendStatus (pdev); - } -} - -/** - * @brief USBD_ClrFeature - * Handle clear device feature request - * @param pdev: device instance - * @param req: usb request - * @retval status - */ -static void USBD_ClrFeature (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - switch (pdev->dev_state) - { - case USBD_STATE_DEFAULT: - case USBD_STATE_ADDRESSED: - case USBD_STATE_CONFIGURED: - if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) - { - pdev->dev_remote_wakeup = 0U; - (void) USBD_CtlSendStatus (pdev); - } - break; - - default: - USBD_CtlError (pdev, req); - break; - } -} - -/** - * @brief USBD_ParseSetupRequest - * Copy buffer into setup structure - * @param pdev: device instance - * @param req: usb request - * @retval None - */ -void USBD_ParseSetupRequest (USBD_SetupReqTypedef *req, uint8_t *pdata) -{ - uint8_t *pbuff = pdata; - - req->bmRequest = *(uint8_t*) (pbuff); - - pbuff++; - req->bRequest = *(uint8_t*) (pbuff); - - pbuff++; - req->wValue = SWAPBYTE (pbuff); - - pbuff++; - pbuff++; - req->wIndex = SWAPBYTE (pbuff); - - pbuff++; - pbuff++; - req->wLength = SWAPBYTE (pbuff); -} - -/** - * @brief USBD_CtlError - * Handle USB low level Error - * @param pdev: device instance - * @param req: usb request - * @retval None - */ -void USBD_CtlError (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) -{ - UNUSED(req); - - (void) USBD_LL_StallEP (pdev, 0x80U); - (void) USBD_LL_StallEP (pdev, 0U); -} - -/** - * @brief USBD_GetString - * Convert Ascii string into unicode one - * @param desc : descriptor buffer - * @param unicode : Formatted string buffer (unicode) - * @param len : descriptor length - * @retval None - */ -void USBD_GetString (uint8_t *desc, uint8_t *unicode, uint16_t *len) -{ - uint8_t idx = 0U; - uint8_t *pdesc; - - if (desc == NULL) - { - return; - } - - pdesc = desc; - *len = ((uint16_t) USBD_GetLen (pdesc) * 2U) + 2U; - - unicode[idx] = *(uint8_t*) len; - idx++; - unicode[idx] = USB_DESC_TYPE_STRING; - idx++; - - while (*pdesc != (uint8_t) '\0') - { - unicode[idx] = *pdesc; - pdesc++; - idx++; - - unicode[idx] = 0U; - idx++; - } -} - -/** - * @brief USBD_GetLen - * return the string length - * @param buf : pointer to the ascii string buffer - * @retval string length - */ -static uint8_t USBD_GetLen (uint8_t *buf) -{ - uint8_t len = 0U; - uint8_t *pbuff = buf; - - while (*pbuff != (uint8_t) '\0') - { - len++; - pbuff++; - } - - return len; -} -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/AL94_USB_Composite/Target/usbd_conf.h b/common/AL94_USB_Composite/Target/usbd_conf.h deleted file mode 100644 index 53df2f0..0000000 --- a/common/AL94_USB_Composite/Target/usbd_conf.h +++ /dev/null @@ -1,176 +0,0 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : usbd_conf.h - * @version : v1.0_Cube - * @brief : Header for usbd_conf.c file. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * 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 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __USBD_CONF__H__ -#define __USBD_CONF__H__ - -#ifdef __cplusplus -extern "C" -{ -#endif - -/* Includes ------------------------------------------------------------------*/ -#include -#include -#include -#include "main.h" - -/* USER CODE BEGIN INCLUDE */ - -/* USER CODE END INCLUDE */ - -/** @addtogroup USBD_OTG_DRIVER - * @brief Driver for Usb device. - * @{ - */ - -/** @defgroup USBD_CONF USBD_CONF - * @brief Configuration file for Usb otg low level driver. - * @{ - */ - -/** @defgroup USBD_CONF_Exported_Variables USBD_CONF_Exported_Variables - * @brief Public variables. - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_CONF_Exported_Defines USBD_CONF_Exported_Defines - * @brief Defines for configuration of the Usb device. - * @{ - */ - -/*---------- -----------*/ -#define USBD_MAX_NUM_INTERFACES 15U -/*---------- -----------*/ -#define USBD_MAX_NUM_CONFIGURATION 1U -/*---------- -----------*/ -#define USBD_MAX_STR_DESC_SIZ 512U -/*---------- -----------*/ -#define USBD_SUPPORT_USER_STRING_DESC 1U -/*---------- -----------*/ -#define USBD_DEBUG_LEVEL 0U -/*---------- -----------*/ -#define USBD_LPM_ENABLED 0U -/*---------- -----------*/ -#define USBD_SELF_POWERED 1U -/*---------- -----------*/ - -/****************************************/ -/* #define for FS and HS identification */ -#define DEVICE_FS 0 -#define DEVICE_HS 1 - -/** - * @} - */ - -/** @defgroup USBD_CONF_Exported_Macros USBD_CONF_Exported_Macros - * @brief Aliases. - * @{ - */ - -/* Memory management macros */ - -/** Alias for memory allocation. */ -#define USBD_malloc malloc - -/** Alias for memory release. */ -#define USBD_free free - -/** Alias for memory set. */ -#define USBD_memset memset - -/** Alias for memory copy. */ -#define USBD_memcpy memcpy - -/** Alias for delay. */ -#define USBD_Delay HAL_Delay - -/* DEBUG macros */ - -#if (USBD_DEBUG_LEVEL > 0) -#define USBD_UsrLog(...) printf(__VA_ARGS__);\ - printf("\n"); -#else -#define USBD_UsrLog(...) -#endif - -#if (USBD_DEBUG_LEVEL > 1) - -#define USBD_ErrLog(...) printf("ERROR: ") ;\ - printf(__VA_ARGS__);\ - printf("\n"); -#else -#define USBD_ErrLog(...) -#endif - -#if (USBD_DEBUG_LEVEL > 2) -#define USBD_DbgLog(...) printf("DEBUG : ") ;\ - printf(__VA_ARGS__);\ - printf("\n"); -#else -#define USBD_DbgLog(...) -#endif - -/** - * @} - */ - -/** @defgroup USBD_CONF_Exported_Types USBD_CONF_Exported_Types - * @brief Types. - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_CONF_Exported_FunctionsPrototype USBD_CONF_Exported_FunctionsPrototype - * @brief Declaration of public functions for Usb device. - * @{ - */ - -/* Exported functions -------------------------------------------------------*/ - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __USBD_CONF__H__ */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/AL94_USB_Composite/AL94.I-CUBE-USBD-COMPOSITE_conf.h-ignore b/common/USB_AL94/AL94.I-CUBE-USBD-COMPOSITE_conf.h-ignore similarity index 96% rename from common/AL94_USB_Composite/AL94.I-CUBE-USBD-COMPOSITE_conf.h-ignore rename to common/USB_AL94/AL94.I-CUBE-USBD-COMPOSITE_conf.h-ignore index a29b74a..da5c436 100644 --- a/common/AL94_USB_Composite/AL94.I-CUBE-USBD-COMPOSITE_conf.h-ignore +++ b/common/USB_AL94/AL94.I-CUBE-USBD-COMPOSITE_conf.h-ignore @@ -1,90 +1,90 @@ -/** - ****************************************************************************** - * File Name : AL94.I-CUBE-USBD-COMPOSITE_conf.h - * Description : This file provides code for the configuration - * of the AL94.I-CUBE-USBD-COMPOSITE_conf.h instances. - ****************************************************************************** - * @attention - * - * Copyright (c) 2024 STMicroelectronics. - * All rights reserved. - * - * This software is licensed under terms that can be found in the LICENSE file - * in the root directory of this software component. - * If no LICENSE file comes with this software, it is provided AS-IS. - * - ****************************************************************************** - */ -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef __AL94__I_CUBE_USBD_COMPOSITE_CONF__H__ -#define __AL94__I_CUBE_USBD_COMPOSITE_CONF__H__ - -#ifdef __cplusplus -extern "C" -{ -#endif - -/* Includes ------------------------------------------------------------------*/ - -/** - MiddleWare name : AL94.I-CUBE-USBD-COMPOSITE.1.0.3 - MiddleWare fileName : AL94.I-CUBE-USBD-COMPOSITE_conf.h - MiddleWare version : - */ -/*---------- _USBD_USE_HS -----------*/ - -#define _USBD_USE_HS false - - -/*---------- _USBD_USE_CDC_ACM -----------*/ -#define _USBD_USE_CDC_ACM true - -/*---------- _USBD_CDC_ACM_COUNT -----------*/ -#define _USBD_CDC_ACM_COUNT 1 - -/*---------- _USBD_USE_CDC_RNDIS -----------*/ -#define _USBD_USE_CDC_RNDIS false - -/*---------- _USBD_USE_CDC_ECM -----------*/ -#define _USBD_USE_CDC_ECM false - -/*---------- _USBD_USE_HID_MOUSE -----------*/ -#define _USBD_USE_HID_MOUSE false - -/*---------- _USBD_USE_HID_KEYBOARD -----------*/ -#define _USBD_USE_HID_KEYBOARD false - -/*---------- _USBD_USE_HID_CUSTOM -----------*/ -#define _USBD_USE_HID_CUSTOM false - -/*---------- _USBD_USE_UAC_MIC -----------*/ -#define _USBD_USE_UAC_MIC false - -/*---------- _USBD_USE_UAC_SPKR -----------*/ -#define _USBD_USE_UAC_SPKR false - -/*---------- _USBD_USE_UVC -----------*/ -#define _USBD_USE_UVC false - -/*---------- _USBD_USE_MSC -----------*/ -#define _USBD_USE_MSC false - -/*---------- _USBD_USE_DFU -----------*/ -#define _USBD_USE_DFU false - -/*---------- _USBD_USE_PRNTR -----------*/ -#define _USBD_USE_PRNTR false - -/*---------- _STM32F1_DEVICE -----------*/ -#define _STM32F1_DEVICE false - -#ifdef __cplusplus -} -#endif -#endif /*__ AL94__I_CUBE_USBD_COMPOSITE_CONF__H_H */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ +/** + ****************************************************************************** + * File Name : AL94.I-CUBE-USBD-COMPOSITE_conf.h + * Description : This file provides code for the configuration + * of the AL94.I-CUBE-USBD-COMPOSITE_conf.h instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2024 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __AL94__I_CUBE_USBD_COMPOSITE_CONF__H__ +#define __AL94__I_CUBE_USBD_COMPOSITE_CONF__H__ + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* Includes ------------------------------------------------------------------*/ + +/** + MiddleWare name : AL94.I-CUBE-USBD-COMPOSITE.1.0.3 + MiddleWare fileName : AL94.I-CUBE-USBD-COMPOSITE_conf.h + MiddleWare version : + */ +/*---------- _USBD_USE_HS -----------*/ + +#define _USBD_USE_HS false + + +/*---------- _USBD_USE_CDC_ACM -----------*/ +#define _USBD_USE_CDC_ACM true + +/*---------- _USBD_CDC_ACM_COUNT -----------*/ +#define _USBD_CDC_ACM_COUNT 1 + +/*---------- _USBD_USE_CDC_RNDIS -----------*/ +#define _USBD_USE_CDC_RNDIS false + +/*---------- _USBD_USE_CDC_ECM -----------*/ +#define _USBD_USE_CDC_ECM false + +/*---------- _USBD_USE_HID_MOUSE -----------*/ +#define _USBD_USE_HID_MOUSE false + +/*---------- _USBD_USE_HID_KEYBOARD -----------*/ +#define _USBD_USE_HID_KEYBOARD false + +/*---------- _USBD_USE_HID_CUSTOM -----------*/ +#define _USBD_USE_HID_CUSTOM false + +/*---------- _USBD_USE_UAC_MIC -----------*/ +#define _USBD_USE_UAC_MIC false + +/*---------- _USBD_USE_UAC_SPKR -----------*/ +#define _USBD_USE_UAC_SPKR false + +/*---------- _USBD_USE_UVC -----------*/ +#define _USBD_USE_UVC false + +/*---------- _USBD_USE_MSC -----------*/ +#define _USBD_USE_MSC false + +/*---------- _USBD_USE_DFU -----------*/ +#define _USBD_USE_DFU false + +/*---------- _USBD_USE_PRNTR -----------*/ +#define _USBD_USE_PRNTR false + +/*---------- _STM32F1_DEVICE -----------*/ +#define _STM32F1_DEVICE false + +#ifdef __cplusplus +} +#endif +#endif /*__ AL94__I_CUBE_USBD_COMPOSITE_CONF__H_H */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/AL94_USB_Composite/LICENSE.txt b/common/USB_AL94/LICENSE.txt similarity index 98% rename from common/AL94_USB_Composite/LICENSE.txt rename to common/USB_AL94/LICENSE.txt index 059b65d..4bf2beb 100644 --- a/common/AL94_USB_Composite/LICENSE.txt +++ b/common/USB_AL94/LICENSE.txt @@ -1,21 +1,21 @@ -MIT License - -Copyright (c) 2021 alambe94 - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +MIT License + +Copyright (c) 2021 alambe94 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/common/USB_AL94/usb_device.c b/common/USB_AL94/usb_device.c new file mode 100644 index 0000000..19db251 --- /dev/null +++ b/common/USB_AL94/usb_device.c @@ -0,0 +1,58 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : usb_device.c + * @version : v1.0_Cube + * @brief : This file implements the USB Device + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2021 STMicroelectronics. + * All rights reserved.

+ * + * 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 + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ + +#include "usb_device.h" +#include "usbd_desc.h" + +#include "usbd_composite.h" + +/* USB Device Core handle declaration. */ +USBD_HandleTypeDef hUsbDevice; + +/** + * Init USB device Library, add supported class and start the library + * @retval None + */ +void MX_USB_DEVICE_Init(void) +{ + /* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */ + + /* USER CODE END USB_DEVICE_Init_PreTreatment */ + + /* Init Device Library, add supported class and start the library. */ + USBD_COMPOSITE_Mount_Class(); + +#if (USBD_USE_HS == 1) + if (USBD_Init(&hUsbDevice, &USBD_Desc, DEVICE_HS) != USBD_OK) { Error_Handler(); } +#else + if (USBD_Init(&hUsbDevice, &USBD_Desc, DEVICE_FS) != USBD_OK) { Error_Handler(); } +#endif + + if (USBD_RegisterClass(&hUsbDevice, &USBD_COMPOSITE) != USBD_OK) { Error_Handler(); } + + if (USBD_CDC_ACM_RegisterInterface(&hUsbDevice, &USBD_CDC_ACM_fops) != USBD_OK) { Error_Handler(); } + + if (USBD_Start(&hUsbDevice) != USBD_OK) { Error_Handler(); } +} + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/USB_AL94/usb_device.h b/common/USB_AL94/usb_device.h new file mode 100644 index 0000000..47258a4 --- /dev/null +++ b/common/USB_AL94/usb_device.h @@ -0,0 +1,41 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : usb_device.h + * @version : v1.0_Cube + * @brief : Header for usb_device.c file. + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2021 STMicroelectronics. + * All rights reserved.

+ * + * 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 + * + ****************************************************************************** + */ + +#ifndef __USB_DEVICE__H__ +#define __USB_DEVICE__H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" +#include "usbd_def.h" + +/** USB Device initialization function. */ +void MX_USB_DEVICE_Init(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __USB_DEVICE__H__ */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/USB_AL94/usbd_cdc.c b/common/USB_AL94/usbd_cdc.c new file mode 100644 index 0000000..b6902f7 --- /dev/null +++ b/common/USB_AL94/usbd_cdc.c @@ -0,0 +1,2052 @@ +/** + ****************************************************************************** + * @file usbd_cdc.c + * @author MCD Application Team + * @brief This file provides the high layer firmware functions to manage the + * following functionalities of the USB CDC Class: + * - Initialization and Configuration of high and low layer + * - Enumeration as CDC Device (and enumeration for each implemented memory interface) + * - OUT/IN data transfer + * - Command IN transfer (class requests management) + * - Error management + * + * @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 + * + * These aspects may be enriched or modified for a specific user application. + * + * This driver doesn't implement the following aspects of the specification + * (but it is possible to manage these features with some modifications on this driver): + * - Any class-specific aspect relative to communication classes should be managed by user application. + * - All communication classes other than PSTN are not managed + * + * @endverbatim + * + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2015 STMicroelectronics. + * All rights reserved.

+ * + * 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 + * + ****************************************************************************** + */ + +#include "usbd_cdc.h" +#include "usbd_ctlreq.h" + +#define _CDC_IN_EP 0x81U /* EP1 for data IN */ +#define _CDC_OUT_EP 0x01U /* EP1 for data OUT */ +#define _CDC_CMD_EP 0x82U /* EP2 for CDC commands */ + +#define _CDC_CMD_ITF_NBR 0x00U /* Command Interface Number */ +#define _CDC_COM_ITF_NBR 0x01U /* Communication Interface Number */ + +#define _CDC_STR_DESC_IDX 0x00 + +uint8_t CDC_IN_EP[NUMBER_OF_CDC]; +uint8_t CDC_OUT_EP[NUMBER_OF_CDC]; +uint8_t CDC_CMD_EP[NUMBER_OF_CDC]; + +uint8_t CDC_CMD_ITF_NBR[NUMBER_OF_CDC]; +uint8_t CDC_COM_ITF_NBR[NUMBER_OF_CDC]; + +uint8_t CDC_STR_DESC_IDX[NUMBER_OF_CDC]; + +/** @defgroup USBD_CDC_Private_FunctionPrototypes + * @{ + */ + +static uint8_t USBD_CDC_Init(USBD_HandleTypeDef * pdev, uint8_t cfgidx); +static uint8_t USBD_CDC_DeInit(USBD_HandleTypeDef * pdev, uint8_t cfgidx); +static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req); +static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef * pdev, uint8_t epnum); +static uint8_t USBD_CDC_DataOut(USBD_HandleTypeDef * pdev, uint8_t epnum); +static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef * pdev); + +static uint8_t * USBD_CDC_GetFSCfgDesc(uint16_t * length); +static uint8_t * USBD_CDC_GetHSCfgDesc(uint16_t * length); +static uint8_t * USBD_CDC_GetOtherSpeedCfgDesc(uint16_t * length); +static uint8_t * USBD_CDC_GetOtherSpeedCfgDesc(uint16_t * length); +static uint8_t * USBD_CDC_GetDeviceQualifierDescriptor(uint16_t * length); + +USBD_CDC_ACM_HandleTypeDef CDC_ACM_Class_Data[NUMBER_OF_CDC]; + +/* USB Standard Device Descriptor */ +__ALIGN_BEGIN static uint8_t USBD_CDC_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_CDC_Private_Variables + * @{ + */ + +/* CDC interface class callbacks structure */ +USBD_ClassTypeDef USBD_CDC_ACM = { + USBD_CDC_Init, + USBD_CDC_DeInit, + USBD_CDC_Setup, + NULL, /* EP0_TxSent, */ + USBD_CDC_EP0_RxReady, + USBD_CDC_DataIn, + USBD_CDC_DataOut, + NULL, + NULL, + NULL, + USBD_CDC_GetHSCfgDesc, + USBD_CDC_GetFSCfgDesc, + USBD_CDC_GetOtherSpeedCfgDesc, + USBD_CDC_GetDeviceQualifierDescriptor, +}; + +/* USB CDC device Configuration Descriptor */ +__ALIGN_BEGIN static uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = { + /* Configuration Descriptor */ + 0x09, /* bLength: Configuration Descriptor size */ + USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ + LOBYTE(USB_CDC_CONFIG_DESC_SIZ), /* wTotalLength:no of returned bytes */ + HIBYTE(USB_CDC_CONFIG_DESC_SIZ), (2 * NUMBER_OF_CDC), /* bNumInterfaces: 2 interface */ + 0x01, /* bConfigurationValue: Configuration value */ + 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ +#if (USBD_SELF_POWERED == 1U) + 0xC0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0x80, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA */ + + /******************** CDC0 block ********************/ + /******** IAD to associate the two CDC interfaces */ + 0x08, /* bLength */ + 0x0B, /* bDescriptorType */ + _CDC_CMD_ITF_NBR, /* bFirstInterface */ + 0x02, /* bInterfaceCount */ + 0x02, /* bFunctionClass */ + 0x02, /* bFunctionSubClass */ + 0x01, /* bFunctionProtocol */ + 0x00, /* iFunction (Index of string descriptor describing this function) */ + + /* Interface Descriptor */ + 0x09, /* bLength: Interface Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ + _CDC_CMD_ITF_NBR, /* 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 */ + _CDC_STR_DESC_IDX, /* 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 */ + _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ + _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ + + /* Endpoint 2 Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_CMD_EP, /* bEndpointAddress */ + 0x03, /* bmAttributes: Interrupt */ + LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_CMD_PACKET_SIZE), CDC_HS_BINTERVAL, /* bInterval: */ + /*---------------------------------------------------------------------------*/ + + /* Data class interface descriptor */ + 0x09, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ + _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_OUT_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ + + /* Endpoint IN Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_IN_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ + +#if (NUMBER_OF_CDC > 1) + /******************** CDC1 block ********************/ + /******** IAD to associate the two CDC interfaces */ + 0x08, /* bLength */ + 0x0B, /* bDescriptorType */ + _CDC_CMD_ITF_NBR, /* bFirstInterface */ + 0x02, /* bInterfaceCount */ + 0x02, /* bFunctionClass */ + 0x02, /* bFunctionSubClass */ + 0x01, /* bFunctionProtocol */ + 0x00, /* iFunction (Index of string descriptor describing this function) */ + + /* Interface Descriptor */ + 0x09, /* bLength: Interface Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ + _CDC_CMD_ITF_NBR, /* 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 */ + _CDC_STR_DESC_IDX, /* 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 */ + _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ + _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ + + /* Endpoint 2 Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_CMD_EP, /* bEndpointAddress */ + 0x03, /* bmAttributes: Interrupt */ + LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_CMD_PACKET_SIZE), CDC_HS_BINTERVAL, /* bInterval: */ + /*---------------------------------------------------------------------------*/ + + /* Data class interface descriptor */ + 0x09, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ + _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_OUT_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ + + /* Endpoint IN Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_IN_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ +#endif + +#if (NUMBER_OF_CDC > 2) + /******************** CDC2 block ********************/ + /******** IAD to associate the two CDC interfaces */ + 0x08, /* bLength */ + 0x0B, /* bDescriptorType */ + _CDC_CMD_ITF_NBR, /* bFirstInterface */ + 0x02, /* bInterfaceCount */ + 0x02, /* bFunctionClass */ + 0x02, /* bFunctionSubClass */ + 0x01, /* bFunctionProtocol */ + 0x00, /* iFunction (Index of string descriptor describing this function) */ + + /* Interface Descriptor */ + 0x09, /* bLength: Interface Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ + _CDC_CMD_ITF_NBR, /* 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 */ + _CDC_STR_DESC_IDX, /* 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 */ + _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ + _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ + + /* Endpoint 2 Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_CMD_EP, /* bEndpointAddress */ + 0x03, /* bmAttributes: Interrupt */ + LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_CMD_PACKET_SIZE), CDC_HS_BINTERVAL, /* bInterval: */ + /*---------------------------------------------------------------------------*/ + + /* Data class interface descriptor */ + 0x09, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ + _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_OUT_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ + + /* Endpoint IN Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_IN_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ +#endif + +#if (NUMBER_OF_CDC > 3) + /******************** CDC3 block ********************/ + /******** IAD to associate the two CDC interfaces */ + 0x08, /* bLength */ + 0x0B, /* bDescriptorType */ + _CDC_CMD_ITF_NBR, /* bFirstInterface */ + 0x02, /* bInterfaceCount */ + 0x02, /* bFunctionClass */ + 0x02, /* bFunctionSubClass */ + 0x01, /* bFunctionProtocol */ + 0x00, /* iFunction (Index of string descriptor describing this function) */ + + /* Interface Descriptor */ + 0x09, /* bLength: Interface Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ + _CDC_CMD_ITF_NBR, /* 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 */ + _CDC_STR_DESC_IDX, /* 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 */ + _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ + _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ + + /* Endpoint 2 Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_CMD_EP, /* bEndpointAddress */ + 0x03, /* bmAttributes: Interrupt */ + LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_CMD_PACKET_SIZE), CDC_HS_BINTERVAL, /* bInterval: */ + /*---------------------------------------------------------------------------*/ + + /* Data class interface descriptor */ + 0x09, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ + _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_OUT_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ + + /* Endpoint IN Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_IN_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ +#endif + +#if (NUMBER_OF_CDC > 4) + /******************** CDC4 block ********************/ + /******** IAD to associate the two CDC interfaces */ + 0x08, /* bLength */ + 0x0B, /* bDescriptorType */ + _CDC_CMD_ITF_NBR, /* bFirstInterface */ + 0x02, /* bInterfaceCount */ + 0x02, /* bFunctionClass */ + 0x02, /* bFunctionSubClass */ + 0x01, /* bFunctionProtocol */ + 0x00, /* iFunction (Index of string descriptor describing this function) */ + + /* Interface Descriptor */ + 0x09, /* bLength: Interface Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ + _CDC_CMD_ITF_NBR, /* 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 */ + _CDC_STR_DESC_IDX, /* 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 */ + _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ + _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ + + /* Endpoint 2 Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_CMD_EP, /* bEndpointAddress */ + 0x03, /* bmAttributes: Interrupt */ + LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_CMD_PACKET_SIZE), CDC_HS_BINTERVAL, /* bInterval: */ + /*---------------------------------------------------------------------------*/ + + /* Data class interface descriptor */ + 0x09, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ + _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_OUT_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ + + /* Endpoint IN Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_IN_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ +#endif + +#if (NUMBER_OF_CDC > 5) + /******************** CDC5 block ********************/ + /******** IAD to associate the two CDC interfaces */ + 0x08, /* bLength */ + 0x0B, /* bDescriptorType */ + _CDC_CMD_ITF_NBR, /* bFirstInterface */ + 0x02, /* bInterfaceCount */ + 0x02, /* bFunctionClass */ + 0x02, /* bFunctionSubClass */ + 0x01, /* bFunctionProtocol */ + 0x00, /* iFunction (Index of string descriptor describing this function) */ + + /* Interface Descriptor */ + 0x09, /* bLength: Interface Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ + _CDC_CMD_ITF_NBR, /* 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 */ + _CDC_STR_DESC_IDX, /* 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 */ + _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ + _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ + + /* Endpoint 2 Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_CMD_EP, /* bEndpointAddress */ + 0x03, /* bmAttributes: Interrupt */ + LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_CMD_PACKET_SIZE), CDC_HS_BINTERVAL, /* bInterval: */ + /*---------------------------------------------------------------------------*/ + + /* Data class interface descriptor */ + 0x09, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ + _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_OUT_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ + + /* Endpoint IN Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_IN_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ +#endif + +#if (NUMBER_OF_CDC > 6) + /******************** CDC6 block ********************/ + /******** IAD to associate the two CDC interfaces */ + 0x08, /* bLength */ + 0x0B, /* bDescriptorType */ + _CDC_CMD_ITF_NBR, /* bFirstInterface */ + 0x02, /* bInterfaceCount */ + 0x02, /* bFunctionClass */ + 0x02, /* bFunctionSubClass */ + 0x01, /* bFunctionProtocol */ + 0x00, /* iFunction (Index of string descriptor describing this function) */ + + /* Interface Descriptor */ + 0x09, /* bLength: Interface Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ + _CDC_CMD_ITF_NBR, /* 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 */ + _CDC_STR_DESC_IDX, /* 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 */ + _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ + _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ + + /* Endpoint 2 Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_CMD_EP, /* bEndpointAddress */ + 0x03, /* bmAttributes: Interrupt */ + LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_CMD_PACKET_SIZE), CDC_HS_BINTERVAL, /* bInterval: */ + /*---------------------------------------------------------------------------*/ + + /* Data class interface descriptor */ + 0x09, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ + _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_OUT_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ + + /* Endpoint IN Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_IN_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ +#endif + +#if (NUMBER_OF_CDC > 7) + /******************** CDC7 block ********************/ + /******** IAD to associate the two CDC interfaces */ + 0x08, /* bLength */ + 0x0B, /* bDescriptorType */ + _CDC_CMD_ITF_NBR, /* bFirstInterface */ + 0x02, /* bInterfaceCount */ + 0x02, /* bFunctionClass */ + 0x02, /* bFunctionSubClass */ + 0x01, /* bFunctionProtocol */ + 0x00, /* iFunction (Index of string descriptor describing this function) */ + + /* Interface Descriptor */ + 0x09, /* bLength: Interface Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ + _CDC_CMD_ITF_NBR, /* 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 */ + _CDC_STR_DESC_IDX, /* 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 */ + _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ + _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ + + /* Endpoint 2 Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_CMD_EP, /* bEndpointAddress */ + 0x03, /* bmAttributes: Interrupt */ + LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_CMD_PACKET_SIZE), CDC_HS_BINTERVAL, /* bInterval: */ + /*---------------------------------------------------------------------------*/ + + /* Data class interface descriptor */ + 0x09, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ + _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_OUT_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ + + /* Endpoint IN Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_IN_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), 0x00 /* bInterval: ignore for Bulk transfer */ +#endif +}; + +/* USB CDC device Configuration Descriptor */ +__ALIGN_BEGIN static uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = { + /* Configuration Descriptor */ + 0x09, /* bLength: Configuration Descriptor size */ + USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ + LOBYTE(USB_CDC_CONFIG_DESC_SIZ), /* wTotalLength:no of returned bytes */ + HIBYTE(USB_CDC_CONFIG_DESC_SIZ), 0x02, /* bNumInterfaces: 2 interface */ + 0x01, /* bConfigurationValue: Configuration value */ + 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ +#if (USBD_SELF_POWERED == 1U) + 0xC0, /* bmAttributes: Bus Powered according to user configuration */ +#else + 0x80, /* bmAttributes: Bus Powered according to user configuration */ +#endif + USBD_MAX_POWER, /* MaxPower 100 mA */ + + /*---------------------------------------------------------------------------*/ + /******************** CDC0 block ********************/ + /******** IAD to associate the two CDC interfaces */ + 0x08, /* bLength */ + 0x0B, /* bDescriptorType */ + _CDC_CMD_ITF_NBR, /* bFirstInterface */ + 0x02, /* bInterfaceCount */ + 0x02, /* bFunctionClass */ + 0x02, /* bFunctionSubClass */ + 0x01, /* bFunctionProtocol */ + 0x00, /* iFunction (Index of string descriptor describing this function) */ + + /* Interface Descriptor */ + 0x09, /* bLength: Interface Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ + /* Interface descriptor type */ + _CDC_CMD_ITF_NBR, /* 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 */ + _CDC_STR_DESC_IDX, /* 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 */ + _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ + _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ + + /* Endpoint 2 Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_CMD_EP, /* bEndpointAddress */ + 0x03, /* bmAttributes: Interrupt */ + LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_CMD_PACKET_SIZE), CDC_FS_BINTERVAL, /* bInterval: */ + /*---------------------------------------------------------------------------*/ + + /* Data class interface descriptor */ + 0x09, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ + _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_OUT_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ + + /* Endpoint IN Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_IN_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ + +#if (NUMBER_OF_CDC > 1) + /******************** CDC1 block ********************/ + /******** IAD to associate the two CDC interfaces */ + 0x08, /* bLength */ + 0x0B, /* bDescriptorType */ + _CDC_CMD_ITF_NBR, /* bFirstInterface */ + 0x02, /* bInterfaceCount */ + 0x02, /* bFunctionClass */ + 0x02, /* bFunctionSubClass */ + 0x01, /* bFunctionProtocol */ + 0x00, /* iFunction (Index of string descriptor describing this function) */ + + /* Interface Descriptor */ + 0x09, /* bLength: Interface Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ + /* Interface descriptor type */ + _CDC_CMD_ITF_NBR, /* 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 */ + _CDC_STR_DESC_IDX, /* 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 */ + _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ + _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ + + /* Endpoint 2 Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_CMD_EP, /* bEndpointAddress */ + 0x03, /* bmAttributes: Interrupt */ + LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_CMD_PACKET_SIZE), CDC_FS_BINTERVAL, /* bInterval: */ + /*---------------------------------------------------------------------------*/ + + /* Data class interface descriptor */ + 0x09, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ + _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_OUT_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ + + /* Endpoint IN Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_IN_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ +#endif + +#if (NUMBER_OF_CDC > 2) + /******************** CDC2 block ********************/ + /******** IAD to associate the two CDC interfaces */ + 0x08, /* bLength */ + 0x0B, /* bDescriptorType */ + _CDC_CMD_ITF_NBR, /* bFirstInterface */ + 0x02, /* bInterfaceCount */ + 0x02, /* bFunctionClass */ + 0x02, /* bFunctionSubClass */ + 0x01, /* bFunctionProtocol */ + 0x00, /* iFunction (Index of string descriptor describing this function) */ + + /* Interface Descriptor */ + 0x09, /* bLength: Interface Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ + /* Interface descriptor type */ + _CDC_CMD_ITF_NBR, /* 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 */ + _CDC_STR_DESC_IDX, /* 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 */ + _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ + _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ + + /* Endpoint 2 Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_CMD_EP, /* bEndpointAddress */ + 0x03, /* bmAttributes: Interrupt */ + LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_CMD_PACKET_SIZE), CDC_FS_BINTERVAL, /* bInterval: */ + /*---------------------------------------------------------------------------*/ + + /* Data class interface descriptor */ + 0x09, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ + _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_OUT_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ + + /* Endpoint IN Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_IN_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ +#endif + +#if (NUMBER_OF_CDC > 3) + /******************** CDC3 block ********************/ + /******** IAD to associate the two CDC interfaces */ + 0x08, /* bLength */ + 0x0B, /* bDescriptorType */ + _CDC_CMD_ITF_NBR, /* bFirstInterface */ + 0x02, /* bInterfaceCount */ + 0x02, /* bFunctionClass */ + 0x02, /* bFunctionSubClass */ + 0x01, /* bFunctionProtocol */ + 0x00, /* iFunction (Index of string descriptor describing this function) */ + + /* Interface Descriptor */ + 0x09, /* bLength: Interface Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ + /* Interface descriptor type */ + _CDC_CMD_ITF_NBR, /* 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 */ + _CDC_STR_DESC_IDX, /* 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 */ + _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ + _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ + + /* Endpoint 2 Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_CMD_EP, /* bEndpointAddress */ + 0x03, /* bmAttributes: Interrupt */ + LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_CMD_PACKET_SIZE), CDC_FS_BINTERVAL, /* bInterval: */ + /*---------------------------------------------------------------------------*/ + + /* Data class interface descriptor */ + 0x09, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ + _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_OUT_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ + + /* Endpoint IN Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_IN_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ +#endif + +#if (NUMBER_OF_CDC > 4) + /******************** CDC4 block ********************/ + /******** IAD to associate the two CDC interfaces */ + 0x08, /* bLength */ + 0x0B, /* bDescriptorType */ + _CDC_CMD_ITF_NBR, /* bFirstInterface */ + 0x02, /* bInterfaceCount */ + 0x02, /* bFunctionClass */ + 0x02, /* bFunctionSubClass */ + 0x01, /* bFunctionProtocol */ + 0x00, /* iFunction (Index of string descriptor describing this function) */ + + /* Interface Descriptor */ + 0x09, /* bLength: Interface Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ + /* Interface descriptor type */ + _CDC_CMD_ITF_NBR, /* 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 */ + _CDC_STR_DESC_IDX, /* 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 */ + _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ + _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ + + /* Endpoint 2 Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_CMD_EP, /* bEndpointAddress */ + 0x03, /* bmAttributes: Interrupt */ + LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_CMD_PACKET_SIZE), CDC_FS_BINTERVAL, /* bInterval: */ + /*---------------------------------------------------------------------------*/ + + /* Data class interface descriptor */ + 0x09, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ + _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_OUT_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ + + /* Endpoint IN Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_IN_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ +#endif + +#if (NUMBER_OF_CDC > 5) + /******************** CDC5 block ********************/ + /******** IAD to associate the two CDC interfaces */ + 0x08, /* bLength */ + 0x0B, /* bDescriptorType */ + _CDC_CMD_ITF_NBR, /* bFirstInterface */ + 0x02, /* bInterfaceCount */ + 0x02, /* bFunctionClass */ + 0x02, /* bFunctionSubClass */ + 0x01, /* bFunctionProtocol */ + 0x00, /* iFunction (Index of string descriptor describing this function) */ + + /* Interface Descriptor */ + 0x09, /* bLength: Interface Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ + /* Interface descriptor type */ + _CDC_CMD_ITF_NBR, /* 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 */ + _CDC_STR_DESC_IDX, /* 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 */ + _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ + _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ + + /* Endpoint 2 Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_CMD_EP, /* bEndpointAddress */ + 0x03, /* bmAttributes: Interrupt */ + LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_CMD_PACKET_SIZE), CDC_FS_BINTERVAL, /* bInterval: */ + /*---------------------------------------------------------------------------*/ + + /* Data class interface descriptor */ + 0x09, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ + _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_OUT_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ + + /* Endpoint IN Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_IN_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ +#endif + +#if (NUMBER_OF_CDC > 6) + /******************** CDC6 block ********************/ + /******** IAD to associate the two CDC interfaces */ + 0x08, /* bLength */ + 0x0B, /* bDescriptorType */ + _CDC_CMD_ITF_NBR, /* bFirstInterface */ + 0x02, /* bInterfaceCount */ + 0x02, /* bFunctionClass */ + 0x02, /* bFunctionSubClass */ + 0x01, /* bFunctionProtocol */ + 0x00, /* iFunction (Index of string descriptor describing this function) */ + + /* Interface Descriptor */ + 0x09, /* bLength: Interface Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ + /* Interface descriptor type */ + _CDC_CMD_ITF_NBR, /* 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 */ + _CDC_STR_DESC_IDX, /* 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 */ + _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ + _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ + + /* Endpoint 2 Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_CMD_EP, /* bEndpointAddress */ + 0x03, /* bmAttributes: Interrupt */ + LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_CMD_PACKET_SIZE), CDC_FS_BINTERVAL, /* bInterval: */ + /*---------------------------------------------------------------------------*/ + + /* Data class interface descriptor */ + 0x09, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ + _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_OUT_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ + + /* Endpoint IN Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_IN_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ +#endif + +#if (NUMBER_OF_CDC > 7) + /******************** CDC7 block ********************/ + /******** IAD to associate the two CDC interfaces */ + 0x08, /* bLength */ + 0x0B, /* bDescriptorType */ + _CDC_CMD_ITF_NBR, /* bFirstInterface */ + 0x02, /* bInterfaceCount */ + 0x02, /* bFunctionClass */ + 0x02, /* bFunctionSubClass */ + 0x01, /* bFunctionProtocol */ + 0x00, /* iFunction (Index of string descriptor describing this function) */ + + /* Interface Descriptor */ + 0x09, /* bLength: Interface Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ + /* Interface descriptor type */ + _CDC_CMD_ITF_NBR, /* 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 */ + _CDC_STR_DESC_IDX, /* 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 */ + _CDC_COM_ITF_NBR, /* 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_CMD_ITF_NBR, /* bMasterInterface: Communication class interface */ + _CDC_COM_ITF_NBR, /* bSlaveInterface0: Data Class Interface */ + + /* Endpoint 2 Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_CMD_EP, /* bEndpointAddress */ + 0x03, /* bmAttributes: Interrupt */ + LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_CMD_PACKET_SIZE), CDC_FS_BINTERVAL, /* bInterval: */ + /*---------------------------------------------------------------------------*/ + + /* Data class interface descriptor */ + 0x09, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ + _CDC_COM_ITF_NBR, /* 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_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_OUT_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00, /* bInterval: ignore for Bulk transfer */ + + /* Endpoint IN Descriptor */ + 0x07, /* bLength: Endpoint Descriptor size */ + USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ + _CDC_IN_EP, /* bEndpointAddress */ + 0x02, /* bmAttributes: Bulk */ + LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ + HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00 /* bInterval: ignore for Bulk transfer */ +#endif +}; + +/** + * @} + */ + +/** @defgroup USBD_CDC_Private_Functions + * @{ + */ + +/** + * @brief USBD_CDC_Init + * Initialize the CDC interface + * @param pdev: device instance + * @param cfgidx: Configuration index + * @retval status + */ +static uint8_t USBD_CDC_Init(USBD_HandleTypeDef * pdev, uint8_t cfgidx) +{ + UNUSED(cfgidx); + USBD_CDC_ACM_HandleTypeDef * hcdc = NULL; + + for (uint8_t i = 0; i < NUMBER_OF_CDC; i++) { + hcdc = &CDC_ACM_Class_Data[i]; + + if (pdev->dev_speed == USBD_SPEED_HIGH) { + /* Open EP IN */ + (void) USBD_LL_OpenEP(pdev, CDC_IN_EP[i], USBD_EP_TYPE_BULK, CDC_DATA_HS_IN_PACKET_SIZE); + + pdev->ep_in[CDC_IN_EP[i] & 0xFU].is_used = 1U; + + /* Open EP OUT */ + (void) USBD_LL_OpenEP(pdev, CDC_OUT_EP[i], USBD_EP_TYPE_BULK, CDC_DATA_HS_OUT_PACKET_SIZE); + + pdev->ep_out[CDC_OUT_EP[i] & 0xFU].is_used = 1U; + + /* Set bInterval for CDC CMD Endpoint */ + pdev->ep_in[CDC_CMD_EP[i] & 0xFU].bInterval = CDC_HS_BINTERVAL; + } else { + /* Open EP IN */ + (void) USBD_LL_OpenEP(pdev, CDC_IN_EP[i], USBD_EP_TYPE_BULK, CDC_DATA_FS_IN_PACKET_SIZE); + + pdev->ep_in[CDC_IN_EP[i] & 0xFU].is_used = 1U; + + /* Open EP OUT */ + (void) USBD_LL_OpenEP(pdev, CDC_OUT_EP[i], USBD_EP_TYPE_BULK, CDC_DATA_FS_OUT_PACKET_SIZE); + + pdev->ep_out[CDC_OUT_EP[i] & 0xFU].is_used = 1U; + + /* Set bInterval for CMD Endpoint */ + pdev->ep_in[CDC_CMD_EP[i] & 0xFU].bInterval = CDC_FS_BINTERVAL; + } + + /* Open Command IN EP */ + (void) USBD_LL_OpenEP(pdev, CDC_CMD_EP[i], USBD_EP_TYPE_INTR, CDC_CMD_PACKET_SIZE); + pdev->ep_in[CDC_CMD_EP[i] & 0xFU].is_used = 1U; + + /* Init physical Interface components */ + ((USBD_CDC_ACM_ItfTypeDef *) pdev->pUserData_CDC_ACM)->Init(i); + + /* Init Xfer states */ + hcdc->TxState = 0U; + hcdc->RxState = 0U; + + if (pdev->dev_speed == USBD_SPEED_HIGH) { + /* Prepare Out endpoint to receive next packet */ + (void) USBD_LL_PrepareReceive(pdev, CDC_OUT_EP[i], hcdc->RxBuffer, CDC_DATA_HS_OUT_PACKET_SIZE); + } else { + /* Prepare Out endpoint to receive next packet */ + (void) USBD_LL_PrepareReceive(pdev, CDC_OUT_EP[i], hcdc->RxBuffer, CDC_DATA_FS_OUT_PACKET_SIZE); + } + } + return (uint8_t) USBD_OK; +} + +/** + * @brief USBD_CDC_Init + * DeInitialize the CDC layer + * @param pdev: device instance + * @param cfgidx: Configuration index + * @retval status + */ +static uint8_t USBD_CDC_DeInit(USBD_HandleTypeDef * pdev, uint8_t cfgidx) +{ + UNUSED(cfgidx); + for (uint8_t i = 0; i < NUMBER_OF_CDC; i++) { + /* Close EP IN */ + (void) USBD_LL_CloseEP(pdev, CDC_IN_EP[i]); + pdev->ep_in[CDC_IN_EP[i] & 0xFU].is_used = 0U; + + /* Close EP OUT */ + (void) USBD_LL_CloseEP(pdev, CDC_OUT_EP[i]); + pdev->ep_out[CDC_OUT_EP[i] & 0xFU].is_used = 0U; + + /* Close Command IN EP */ + (void) USBD_LL_CloseEP(pdev, CDC_CMD_EP[i]); + pdev->ep_in[CDC_CMD_EP[i] & 0xFU].is_used = 0U; + pdev->ep_in[CDC_CMD_EP[i] & 0xFU].bInterval = 0U; + + /* DeInit physical Interface components */ + ((USBD_CDC_ACM_ItfTypeDef *) pdev->pUserData_CDC_ACM)->DeInit(i); + } + return (uint8_t) USBD_OK; +} + +/** + * @brief USBD_CDC_Setup + * Handle the CDC specific requests + * @param pdev: instance + * @param req: usb requests + * @retval status + */ +static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req) +{ + USBD_CDC_ACM_HandleTypeDef * hcdc = NULL; + uint16_t len; + uint8_t ifalt = 0U; + uint16_t status_info = 0U; + USBD_StatusTypeDef ret = USBD_OK; + + uint8_t windex_to_ch = 0; + + for (uint8_t i = 0; i < NUMBER_OF_CDC; i++) { + if (LOBYTE(req->wIndex) == CDC_CMD_ITF_NBR[i] || LOBYTE(req->wIndex) == CDC_COM_ITF_NBR[i]) { + windex_to_ch = i; + break; + } + } + + hcdc = &CDC_ACM_Class_Data[windex_to_ch]; + + switch (req->bmRequest & USB_REQ_TYPE_MASK) { + case USB_REQ_TYPE_CLASS: + if (req->wLength != 0U) { + if ((req->bmRequest & 0x80U) != 0U) { + ((USBD_CDC_ACM_ItfTypeDef *) pdev->pUserData_CDC_ACM) + ->Control(windex_to_ch, req->bRequest, (uint8_t *) hcdc->data[windex_to_ch], req->wLength); + + len = MIN(CDC_REQ_MAX_DATA_SIZE, req->wLength); + (void) USBD_CtlSendData(pdev, (uint8_t *) hcdc->data[windex_to_ch], len); + } else { + hcdc->CmdOpCode = req->bRequest; + hcdc->CmdLength = (uint8_t) req->wLength; + + (void) USBD_CtlPrepareRx(pdev, (uint8_t *) hcdc->data[windex_to_ch], req->wLength); + } + } else { + ((USBD_CDC_ACM_ItfTypeDef *) pdev->pUserData_CDC_ACM) + ->Control(windex_to_ch, req->bRequest, (uint8_t *) req, 0U); + } + break; + + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) { + case USB_REQ_GET_STATUS: + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + (void) USBD_CtlSendData(pdev, (uint8_t *) &status_info, 2U); + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_GET_INTERFACE: + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + (void) USBD_CtlSendData(pdev, &ifalt, 1U); + } else { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_SET_INTERFACE: + if (pdev->dev_state != USBD_STATE_CONFIGURED) { + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + } + break; + + case USB_REQ_CLEAR_FEATURE: + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; + } + break; + + default: + USBD_CtlError(pdev, req); + ret = USBD_FAIL; + break; + } + + return (uint8_t) ret; +} + +/** + * @brief USBD_CDC_DataIn + * Data sent on non-control IN endpoint + * @param pdev: device instance + * @param epnum: endpoint number + * @retval status + */ +static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef * pdev, uint8_t epnum) +{ + USBD_CDC_ACM_HandleTypeDef * hcdc = NULL; + PCD_HandleTypeDef * hpcd = pdev->pData; + uint8_t ep_to_ch = 0; + + for (uint8_t i = 0; i < NUMBER_OF_CDC; i++) { + if (epnum == (CDC_IN_EP[i] & 0x0F)) { + ep_to_ch = i; + break; + } + } + + hcdc = &CDC_ACM_Class_Data[ep_to_ch]; + + if ((pdev->ep_in[epnum].total_length > 0U) + && ((pdev->ep_in[epnum].total_length % hpcd->IN_ep[epnum].maxpacket) == 0U)) { + /* Update the packet total length */ + pdev->ep_in[epnum].total_length = 0U; + + /* Send ZLP */ + (void) USBD_LL_Transmit(pdev, epnum, NULL, 0U); + } else { + hcdc->TxState = 0U; + + if (((USBD_CDC_ACM_ItfTypeDef *) pdev->pUserData_CDC_ACM)->TransmitCplt != NULL) { + ((USBD_CDC_ACM_ItfTypeDef *) pdev->pUserData_CDC_ACM) + ->TransmitCplt(ep_to_ch, hcdc->TxBuffer, &hcdc->TxLength, epnum); + } + } + + return (uint8_t) USBD_OK; +} + +/** + * @brief USBD_CDC_DataOut + * Data received on non-control Out endpoint + * @param pdev: device instance + * @param epnum: endpoint number + * @retval status + */ + +static uint8_t USBD_CDC_DataOut(USBD_HandleTypeDef * pdev, uint8_t epnum) +{ + USBD_CDC_ACM_HandleTypeDef * hcdc = NULL; + uint8_t ep_to_ch = 0; + + for (uint8_t i = 0; i < NUMBER_OF_CDC; i++) { + if (epnum == CDC_OUT_EP[i]) { + ep_to_ch = i; + break; + } + } + + hcdc = &CDC_ACM_Class_Data[ep_to_ch]; + + /* Get the received data length */ + hcdc->RxLength = USBD_LL_GetRxDataSize(pdev, epnum); + + /* USB data will be immediately processed, this allow next USB traffic being + NAKed till the end of the application Xfer */ + + ((USBD_CDC_ACM_ItfTypeDef *) pdev->pUserData_CDC_ACM)->Receive(ep_to_ch, hcdc->RxBuffer, &hcdc->RxLength); + + return (uint8_t) USBD_OK; +} + +/** + * @brief USBD_CDC_EP0_RxReady + * Handle EP0 Rx Ready event + * @param pdev: device instance + * @retval status + */ +static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef * pdev) +{ + USBD_CDC_ACM_HandleTypeDef * hcdc = NULL; + + for (uint8_t i = 0; i < NUMBER_OF_CDC; i++) { + hcdc = &CDC_ACM_Class_Data[i]; + + if (hcdc == NULL) { return (uint8_t) USBD_FAIL; } + + if ((pdev->pUserData_CDC_ACM != NULL) && (hcdc->CmdOpCode != 0xFFU)) { + ((USBD_CDC_ACM_ItfTypeDef *) pdev->pUserData_CDC_ACM) + ->Control(i, hcdc->CmdOpCode, (uint8_t *) hcdc->data[i], (uint16_t) hcdc->CmdLength); + hcdc->CmdOpCode = 0xFFU; + } + } + + return (uint8_t) USBD_OK; +} + +/** + * @brief USBD_CDC_GetFSCfgDesc + * Return configuration descriptor + * @param speed : current device speed + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ +static uint8_t * USBD_CDC_GetFSCfgDesc(uint16_t * length) +{ + *length = (uint16_t) sizeof(USBD_CDC_CfgFSDesc); + + return USBD_CDC_CfgFSDesc; +} + +/** + * @brief USBD_CDC_GetHSCfgDesc + * Return configuration descriptor + * @param speed : current device speed + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ +static uint8_t * USBD_CDC_GetHSCfgDesc(uint16_t * length) +{ + *length = (uint16_t) sizeof(USBD_CDC_CfgHSDesc); + + return USBD_CDC_CfgHSDesc; +} + +/** + * @brief USBD_CDC_GetOtherSpeedCfgDesc + * Return configuration descriptor + * @param speed : current device speed + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ +static uint8_t * USBD_CDC_GetOtherSpeedCfgDesc(uint16_t * length) +{ + *length = (uint16_t) sizeof(USBD_CDC_CfgFSDesc); + + return USBD_CDC_CfgFSDesc; +} + +/** + * @brief USBD_CDC_GetDeviceQualifierDescriptor + * return Device Qualifier descriptor + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ +uint8_t * USBD_CDC_GetDeviceQualifierDescriptor(uint16_t * length) +{ + *length = (uint16_t) sizeof(USBD_CDC_DeviceQualifierDesc); + + return USBD_CDC_DeviceQualifierDesc; +} + +/** + * @brief USBD_CDC_RegisterInterface + * @param pdev: device instance + * @param fops: CD Interface callback + * @retval status + */ +uint8_t USBD_CDC_ACM_RegisterInterface(USBD_HandleTypeDef * pdev, USBD_CDC_ACM_ItfTypeDef * fops) +{ + if (fops == NULL) { return (uint8_t) USBD_FAIL; } + + pdev->pUserData_CDC_ACM = fops; + + return (uint8_t) USBD_OK; +} + +/** + * @brief USBD_CDC_SetTxBuffer + * @param pdev: device instance + * @param pbuff: Tx Buffer + * @retval status + */ +uint8_t USBD_CDC_SetTxBuffer(uint8_t ch, USBD_HandleTypeDef * pdev, uint8_t * pbuff, uint32_t length) +{ + USBD_CDC_ACM_HandleTypeDef * hcdc = NULL; + + hcdc = &CDC_ACM_Class_Data[ch]; + + hcdc->TxBuffer = pbuff; + hcdc->TxLength = length; + + return (uint8_t) USBD_OK; +} + +/** + * @brief USBD_CDC_SetRxBuffer + * @param pdev: device instance + * @param pbuff: Rx Buffer + * @retval status + */ +uint8_t USBD_CDC_SetRxBuffer(uint8_t ch, USBD_HandleTypeDef * pdev, uint8_t * pbuff) +{ + USBD_CDC_ACM_HandleTypeDef * hcdc = NULL; + + hcdc = &CDC_ACM_Class_Data[ch]; + + hcdc->RxBuffer = pbuff; + + return (uint8_t) USBD_OK; +} + +/** + * @brief USBD_CDC_TransmitPacket + * Transmit packet on IN endpoint + * @param pdev: device instance + * @retval status + */ +uint8_t USBD_CDC_TransmitPacket(uint8_t ch, USBD_HandleTypeDef * pdev) +{ + USBD_CDC_ACM_HandleTypeDef * hcdc = NULL; + USBD_StatusTypeDef ret = USBD_BUSY; + + hcdc = &CDC_ACM_Class_Data[ch]; + + if (hcdc->TxState == 0U) { + /* Tx Transfer in progress */ + hcdc->TxState = 1U; + + /* Update the packet total length */ + pdev->ep_in[CDC_IN_EP[ch] & 0xFU].total_length = hcdc->TxLength; + + /* Transmit next packet */ + (void) USBD_LL_Transmit(pdev, CDC_IN_EP[ch], hcdc->TxBuffer, hcdc->TxLength); + + ret = USBD_OK; + } + + return (uint8_t) ret; +} + +/** + * @brief USBD_CDC_ACM_ReceivePacket + * prepare OUT Endpoint for reception + * @param pdev: device instance + * @retval status + */ +uint8_t USBD_CDC_ReceivePacket(uint8_t ch, USBD_HandleTypeDef * pdev) +{ + USBD_CDC_ACM_HandleTypeDef * hcdc = NULL; + + hcdc = &CDC_ACM_Class_Data[ch]; + + if (pdev->dev_speed == USBD_SPEED_HIGH) { + /* Prepare Out endpoint to receive next packet */ + (void) USBD_LL_PrepareReceive(pdev, CDC_OUT_EP[ch], hcdc->RxBuffer, CDC_DATA_HS_OUT_PACKET_SIZE); + } else { + /* Prepare Out endpoint to receive next packet */ + (void) USBD_LL_PrepareReceive(pdev, CDC_OUT_EP[ch], hcdc->RxBuffer, CDC_DATA_FS_OUT_PACKET_SIZE); + } + + return (uint8_t) USBD_OK; +} + +void USBD_Update_CDC_ACM_DESC(uint8_t * desc, uint8_t cmd_itf, uint8_t com_itf, uint8_t in_ep, uint8_t cmd_ep, + uint8_t out_ep, uint8_t str_idx) +{ + desc += 9; + for (uint8_t i = 0; i < NUMBER_OF_CDC; i++) { + desc[2] = cmd_itf; + desc[16] = str_idx; + desc[10] = cmd_itf; + desc[26] = com_itf; + desc[34] = cmd_itf; + desc[35] = com_itf; + desc[38] = cmd_ep; + desc[45] = com_itf; + desc[54] = out_ep; + desc[61] = in_ep; + + desc += 66; + CDC_IN_EP[i] = in_ep; + CDC_OUT_EP[i] = out_ep; + CDC_CMD_EP[i] = cmd_ep; + CDC_CMD_ITF_NBR[i] = cmd_itf; + CDC_COM_ITF_NBR[i] = com_itf; + CDC_STR_DESC_IDX[i] = str_idx; + + in_ep += 2; + cmd_ep = in_ep + 1; + out_ep++; + str_idx++; + + cmd_itf += 2; + com_itf = cmd_itf + 1; + } +} +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/USB_AL94/usbd_cdc.h b/common/USB_AL94/usbd_cdc.h new file mode 100644 index 0000000..7ecfee1 --- /dev/null +++ b/common/USB_AL94/usbd_cdc.h @@ -0,0 +1,151 @@ +/** + ****************************************************************************** + * @file usbd_cdc.h + * @author MCD Application Team + * @brief header file for the usbd_cdc.c file. + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2015 STMicroelectronics. + * All rights reserved.

+ * + * 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 + * + ****************************************************************************** + */ + +#ifndef __USB_CDC_H +#define __USB_CDC_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "usbd_ioreq.h" +#include + +#define CDC_ACM_STR_DESC "STM32 CDC ACM%d" + +#define NUMBER_OF_CDC _USBD_CDC_ACM_COUNT +#ifndef CDC_HS_BINTERVAL +#define CDC_HS_BINTERVAL 0x10U +#endif /* CDC_HS_BINTERVAL */ + +#ifndef CDC_FS_BINTERVAL +#define CDC_FS_BINTERVAL 0x10U +#endif /* CDC_FS_BINTERVAL */ + +/* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */ +#define CDC_DATA_HS_MAX_PACKET_SIZE 512U /* Endpoint IN & OUT Packet size */ +#define CDC_DATA_FS_MAX_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */ +#define CDC_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */ + +#define USB_CDC_CONFIG_DESC_SIZ (9 + 66 * NUMBER_OF_CDC) +#define CDC_DATA_HS_IN_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE +#define CDC_DATA_HS_OUT_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE + +#define CDC_DATA_FS_IN_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE +#define CDC_DATA_FS_OUT_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE + +#define CDC_REQ_MAX_DATA_SIZE 0x7U +/*---------------------------------------------------------------------*/ +/* CDC definitions */ +/*---------------------------------------------------------------------*/ +#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_LINE_CODING 0x20U +#define CDC_GET_LINE_CODING 0x21U +#define CDC_SET_CONTROL_LINE_STATE 0x22U +#define CDC_SEND_BREAK 0x23U + +/** @defgroup USBD_CORE_Exported_TypesDefinitions + * @{ + */ + +typedef struct +{ + uint32_t bitrate; + uint8_t format; + uint8_t paritytype; + uint8_t datatype; +} USBD_CDC_ACM_LineCodingTypeDef; + +typedef struct _USBD_CDC_Itf +{ + int8_t (*Init)(uint8_t cdc_ch); + int8_t (*DeInit)(uint8_t cdc_ch); + int8_t (*Control)(uint8_t cdc_ch, uint8_t cmd, uint8_t * pbuf, uint16_t length); + int8_t (*Receive)(uint8_t cdc_ch, uint8_t * Buf, uint32_t * Len); + int8_t (*TransmitCplt)(uint8_t cdc_ch, uint8_t * Buf, uint32_t * Len, uint8_t epnum); +} USBD_CDC_ACM_ItfTypeDef; + +typedef struct +{ + uint32_t data[NUMBER_OF_CDC][CDC_DATA_HS_MAX_PACKET_SIZE / 4U]; /* Force 32bits alignment */ + uint8_t CmdOpCode; + uint8_t CmdLength; + uint8_t * RxBuffer; + uint8_t * TxBuffer; + uint32_t RxLength; + uint32_t TxLength; + + __IO uint32_t TxState; + __IO uint32_t RxState; +} USBD_CDC_ACM_HandleTypeDef; + +/** @defgroup USBD_CORE_Exported_Variables + * @{ + */ + +extern USBD_ClassTypeDef USBD_CDC_ACM; + +extern uint8_t CDC_IN_EP[NUMBER_OF_CDC]; /* EP1 for data IN */ +extern uint8_t CDC_OUT_EP[NUMBER_OF_CDC]; /* EP1 for data OUT */ +extern uint8_t CDC_CMD_EP[NUMBER_OF_CDC]; /* EP2 for CDC commands */ + +extern uint8_t CDC_CMD_ITF_NBR[NUMBER_OF_CDC]; /* Command Interface Number */ +extern uint8_t CDC_COM_ITF_NBR[NUMBER_OF_CDC]; /* Communication Interface Number */ + +extern uint8_t CDC_STR_DESC_IDX[NUMBER_OF_CDC]; + +/** + * @} + */ + +/** @defgroup USB_CORE_Exported_Functions + * @{ + */ +uint8_t USBD_CDC_ACM_RegisterInterface(USBD_HandleTypeDef * pdev, USBD_CDC_ACM_ItfTypeDef * fops); + +uint8_t USBD_CDC_SetTxBuffer(uint8_t ch, USBD_HandleTypeDef * pdev, uint8_t * pbuff, uint32_t length); + +uint8_t USBD_CDC_SetRxBuffer(uint8_t ch, USBD_HandleTypeDef * pdev, uint8_t * pbuff); +uint8_t USBD_CDC_ReceivePacket(uint8_t ch, USBD_HandleTypeDef * pdev); +uint8_t USBD_CDC_TransmitPacket(uint8_t ch, USBD_HandleTypeDef * pdev); + +void USBD_Update_CDC_ACM_DESC(uint8_t * desc, uint8_t cmd_itf, uint8_t com_itf, uint8_t in_ep, uint8_t cmd_ep, + uint8_t out_ep, uint8_t str_idx); +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USB_CDC_H */ +/** + * @} + */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/USB_AL94/usbd_cdc_if.c b/common/USB_AL94/usbd_cdc_if.c new file mode 100644 index 0000000..f5ee6d4 --- /dev/null +++ b/common/USB_AL94/usbd_cdc_if.c @@ -0,0 +1,238 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : usbd_cdc_if.c + * @version : v2.0_Cube + * @brief : Usb device for Virtual Com Port. + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.

+ * + * 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 "usbd_cdc_if.h" + +#include + +#define APP_RX_DATA_SIZE 128 +//#define APP_TX_DATA_SIZE 128 + +/** RX buffer for USB */ +uint8_t RX_Buffer[NUMBER_OF_CDC][APP_RX_DATA_SIZE]; + +/** TX buffer for USB, RX buffer for UART */ +//uint8_t TX_Buffer[NUMBER_OF_CDC][APP_TX_DATA_SIZE]; +USBD_CDC_ACM_LineCodingTypeDef Line_Coding[NUMBER_OF_CDC]; + +uint32_t Write_Index[NUMBER_OF_CDC]; /* keep track of received data over UART */ +uint32_t Read_Index[NUMBER_OF_CDC]; /* keep track of sent data to USB */ + +extern USBD_HandleTypeDef hUsbDevice; + +static int8_t CDC_Init(uint8_t cdc_ch); +static int8_t CDC_DeInit(uint8_t cdc_ch); +static int8_t CDC_Control(uint8_t cdc_ch, uint8_t cmd, uint8_t * pbuf, uint16_t length); +static int8_t CDC_Receive(uint8_t cdc_ch, uint8_t * pbuf, uint32_t * Len); +static int8_t CDC_TransmitCplt(uint8_t cdc_ch, uint8_t * Buf, uint32_t * Len, uint8_t epnum); + +USBD_CDC_ACM_ItfTypeDef USBD_CDC_ACM_fops = {CDC_Init, CDC_DeInit, CDC_Control, CDC_Receive, CDC_TransmitCplt}; + +static int8_t CDC_Init(uint8_t cdc_ch) +{ + /* USER CODE BEGIN 3 */ + + /* ##-1- Set Application Buffers */ + USBD_CDC_SetRxBuffer(cdc_ch, &hUsbDevice, RX_Buffer[cdc_ch]); + + // /*##-2- Start the TIM Base generation in interrupt mode ####################*/ + // /* Start Channel1 */ + // if (HAL_TIM_Base_Start_IT(&htim4) != HAL_OK) + // { + // /* Starting Error */ + // Error_Handler(); + // } + + return (USBD_OK); + /* USER CODE END 3 */ +} + +/** + * @brief DeInitializes the CDC media low layer + * @retval USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_DeInit(uint8_t cdc_ch) +{ + /* USER CODE BEGIN 4 */ + /* DeInitialize the UART peripheral */ + // if (HAL_UART_DeInit(CDC_CH_To_UART_Handle(cdc_ch)) != HAL_OK) + // { + // /* Initialization Error */ + // Error_Handler(); + // } + return (USBD_OK); + /* USER CODE END 4 */ +} + +/** + * @brief Manage the CDC class requests + * @param cmd: Command code + * @param pbuf: Buffer containing command data (request parameters) + * @param length: Number of data to be sent (in bytes) + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_Control(uint8_t cdc_ch, uint8_t cmd, uint8_t * pbuf, uint16_t length) +{ + /* USER CODE BEGIN 5 */ + switch (cmd) { + case CDC_SEND_ENCAPSULATED_COMMAND: + + break; + + case CDC_GET_ENCAPSULATED_RESPONSE: + + break; + + case CDC_SET_COMM_FEATURE: + + break; + + case CDC_GET_COMM_FEATURE: + + break; + + case CDC_CLEAR_COMM_FEATURE: + + break; + + /*******************************************************************************/ + /* Line Coding Structure */ + /*-----------------------------------------------------------------------------*/ + /* Offset | Field | Size | Value | Description */ + /* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/ + /* 4 | bCharFormat | 1 | Number | Stop bits */ + /* 0 - 1 Stop bit */ + /* 1 - 1.5 Stop bits */ + /* 2 - 2 Stop bits */ + /* 5 | bParityType | 1 | Number | Parity */ + /* 0 - None */ + /* 1 - Odd */ + /* 2 - Even */ + /* 3 - Mark */ + /* 4 - Space */ + /* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */ + /*******************************************************************************/ + case CDC_SET_LINE_CODING: + Line_Coding[cdc_ch].bitrate = (uint32_t) (pbuf[0] | (pbuf[1] << 8) | (pbuf[2] << 16) | (pbuf[3] << 24)); + Line_Coding[cdc_ch].format = pbuf[4]; + Line_Coding[cdc_ch].paritytype = pbuf[5]; + Line_Coding[cdc_ch].datatype = pbuf[6]; + + //Change_UART_Setting(cdc_ch); + break; + + case CDC_GET_LINE_CODING: + pbuf[0] = (uint8_t) (Line_Coding[cdc_ch].bitrate); + pbuf[1] = (uint8_t) (Line_Coding[cdc_ch].bitrate >> 8); + pbuf[2] = (uint8_t) (Line_Coding[cdc_ch].bitrate >> 16); + pbuf[3] = (uint8_t) (Line_Coding[cdc_ch].bitrate >> 24); + pbuf[4] = Line_Coding[cdc_ch].format; + pbuf[5] = Line_Coding[cdc_ch].paritytype; + pbuf[6] = Line_Coding[cdc_ch].datatype; + break; + + case CDC_SET_CONTROL_LINE_STATE: + + break; + + case CDC_SEND_BREAK: + + break; + + default: + break; + } + + return (USBD_OK); + /* USER CODE END 5 */ +} + +/** + * @brief Data received over USB OUT endpoint are sent over CDC interface + * through this function. + * + * @note + * This function will issue a NAK packet on any OUT packet received on + * USB endpoint until exiting this function. If you exit this function + * before transfer is complete on CDC interface (ie. using DMA controller) + * it will result in receiving more data while previous ones are still + * not sent. + * + * @param Buf: Buffer of data to be received + * @param Len: Number of data received (in bytes) + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_Receive(uint8_t cdc_ch, uint8_t * Buf, uint32_t * Len) +{ + /* USER CODE BEGIN 6 */ + CDC_Receive_Callback(cdc_ch, Buf, *Len); //NOTE! AL94 USB CDC. We implement this. + + USBD_CDC_SetRxBuffer(cdc_ch, &hUsbDevice, &Buf[0]); + USBD_CDC_ReceivePacket(cdc_ch, &hUsbDevice); + return (USBD_OK); + /* USER CODE END 6 */ +} + +/** + * @brief CDC_TransmitCplt_FS + * Data transmited callback + * + * @note + * This function is IN transfer complete callback used to inform user that + * the submitted Data is successfully sent over USB. + * + * @param Buf: Buffer of data to be received + * @param Len: Number of data received (in bytes) + * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL + */ +static int8_t CDC_TransmitCplt(uint8_t cdc_ch, uint8_t * Buf, uint32_t * Len, uint8_t epnum) +{ + CDC_TransmitCplt_Callback(cdc_ch, Buf, (uint16_t) (*Len)); //NOTE! AL94 USB CDC. We implement this. + + return (USBD_OK); +} + +/** + * @brief CDC_Transmit + * Data to send over USB IN endpoint are sent over CDC interface + * through this function. + * @note + * + * + * @param Buf: Buffer of data to be sent + * @param Len: Number of data to be sent (in bytes) + * @retval USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY + */ +uint8_t CDC_Transmit(uint8_t ch, uint8_t * Buf, uint16_t Len) +{ + uint8_t result = USBD_OK; + /* USER CODE BEGIN 7 */ + extern USBD_CDC_ACM_HandleTypeDef CDC_ACM_Class_Data[]; + USBD_CDC_ACM_HandleTypeDef * hcdc = NULL; + hcdc = &CDC_ACM_Class_Data[ch]; + if (hcdc->TxState != 0) { return USBD_BUSY; } + USBD_CDC_SetTxBuffer(ch, &hUsbDevice, Buf, Len); + result = USBD_CDC_TransmitPacket(ch, &hUsbDevice); + /* USER CODE END 7 */ + return result; +} + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/USB_AL94/usbd_cdc_if.h b/common/USB_AL94/usbd_cdc_if.h new file mode 100644 index 0000000..92fa2b7 --- /dev/null +++ b/common/USB_AL94/usbd_cdc_if.h @@ -0,0 +1,39 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : usbd_cdc_acm_if.h + * @version : v2.0_Cube + * @brief : Header for usbd_cdc_if.c file. + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.

+ * + * 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 + * + ****************************************************************************** + */ + +#ifndef __USBD_CDC_ACM_IF_H__ +#define __USBD_CDC_ACM_IF_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "usbd_cdc.h" + +extern USBD_CDC_ACM_ItfTypeDef USBD_CDC_ACM_fops; +uint8_t CDC_Transmit(uint8_t ch, uint8_t * Buf, uint16_t Len); + +#ifdef __cplusplus +} +#endif + +#endif /* __USBD_CDC_ACM_IF_TEMPLATE_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/USB_AL94/usbd_composite.c b/common/USB_AL94/usbd_composite.c new file mode 100644 index 0000000..28e608b --- /dev/null +++ b/common/USB_AL94/usbd_composite.c @@ -0,0 +1,366 @@ +/** + ****************************************************************************** + * @file usbd_composite.c + * @author MCD Application Team + * @brief This file provides the HID core functions. + * + * @verbatim + * + * =================================================================== + * COMPOSITE Class Description + * =================================================================== + * + * + * + * + * + * + * @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 + * + *

© Copyright (c) 2015 STMicroelectronics. + * All rights reserved.

+ * + * 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 + * + ****************************************************************************** + */ + +#include "usbd_composite.h" +#include "usbd_ctlreq.h" + +static uint8_t USBD_COMPOSITE_Init(USBD_HandleTypeDef * pdev, uint8_t cfgidx); +static uint8_t USBD_COMPOSITE_DeInit(USBD_HandleTypeDef * pdev, uint8_t cfgidx); +static uint8_t USBD_COMPOSITE_Setup(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req); +static uint8_t USBD_COMPOSITE_DataIn(USBD_HandleTypeDef * pdev, uint8_t epnum); +static uint8_t USBD_COMPOSITE_DataOut(USBD_HandleTypeDef * pdev, uint8_t epnum); +static uint8_t USBD_COMPOSITE_EP0_RxReady(USBD_HandleTypeDef * pdev); +static uint8_t USBD_COMPOSITE_EP0_TxReady(USBD_HandleTypeDef * pdev); +static uint8_t USBD_COMPOSITE_SOF(USBD_HandleTypeDef * pdev); +static uint8_t USBD_COMPOSITE_IsoINIncomplete(USBD_HandleTypeDef * pdev, uint8_t epnum); +static uint8_t USBD_COMPOSITE_IsoOutIncomplete(USBD_HandleTypeDef * pdev, uint8_t epnum); + +static uint8_t * USBD_COMPOSITE_GetHSCfgDesc(uint16_t * length); +static uint8_t * USBD_COMPOSITE_GetFSCfgDesc(uint16_t * length); +static uint8_t * USBD_COMPOSITE_GetOtherSpeedCfgDesc(uint16_t * length); +static uint8_t * USBD_COMPOSITE_GetDeviceQualifierDesc(uint16_t * length); +static uint8_t * USBD_COMPOSITE_GetUsrStringDesc(USBD_HandleTypeDef * pdev, uint8_t index, uint16_t * length); + +USBD_ClassTypeDef USBD_COMPOSITE = {USBD_COMPOSITE_Init, + USBD_COMPOSITE_DeInit, + USBD_COMPOSITE_Setup, + USBD_COMPOSITE_EP0_TxReady, + USBD_COMPOSITE_EP0_RxReady, + USBD_COMPOSITE_DataIn, + USBD_COMPOSITE_DataOut, + USBD_COMPOSITE_SOF, + USBD_COMPOSITE_IsoINIncomplete, + USBD_COMPOSITE_IsoOutIncomplete, + USBD_COMPOSITE_GetHSCfgDesc, + USBD_COMPOSITE_GetFSCfgDesc, + USBD_COMPOSITE_GetOtherSpeedCfgDesc, + USBD_COMPOSITE_GetDeviceQualifierDesc, + USBD_COMPOSITE_GetUsrStringDesc}; + +typedef struct USBD_COMPOSITE_CFG_DESC_t +{ + uint8_t CONFIG_DESC[USB_CONF_DESC_SIZE]; + + uint8_t USBD_CDC_ACM_DESC[USB_CDC_CONFIG_DESC_SIZ - 0x09]; + +} __PACKED USBD_COMPOSITE_CFG_DESC_t; + +__ALIGN_BEGIN USBD_COMPOSITE_CFG_DESC_t USBD_COMPOSITE_FSCfgDesc, USBD_COMPOSITE_HSCfgDesc __ALIGN_END; +uint8_t USBD_Track_String_Index = (USBD_IDX_INTERFACE_STR + 1); + +/* USB Standard Device Descriptor */ +__ALIGN_BEGIN static uint8_t USBD_COMPOSITE_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = { + USB_LEN_DEV_QUALIFIER_DESC, USB_DESC_TYPE_DEVICE_QUALIFIER, 0x00, 0x02, 0xEF, 0x02, 0x01, 0x40, 0x01, 0x00, +}; + +/** + * @brief USBD_COMPOSITE_Init + * Initialize the COMPOSITE interface + * @param pdev: device instance + * @param cfgidx: Configuration index + * @retval status + */ +static uint8_t USBD_COMPOSITE_Init(USBD_HandleTypeDef * pdev, uint8_t cfgidx) +{ + USBD_CDC_ACM.Init(pdev, cfgidx); + return (uint8_t) USBD_OK; +} + +/** + * @brief USBD_COMPOSITE_Init + * DeInitialize the COMPOSITE layer + * @param pdev: device instance + * @param cfgidx: Configuration index + * @retval status + */ +static uint8_t USBD_COMPOSITE_DeInit(USBD_HandleTypeDef * pdev, uint8_t cfgidx) +{ + USBD_CDC_ACM.DeInit(pdev, cfgidx); + + return (uint8_t) USBD_OK; +} + +/** + * @brief USBD_COMPOSITE_Setup + * Handle the COMPOSITE specific requests + * @param pdev: instance + * @param req: usb requests + * @retval status + */ +static uint8_t USBD_COMPOSITE_Setup(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req) +{ + for (uint8_t i = 0; i < USBD_CDC_ACM_COUNT; i++) { + if (LOBYTE(req->wIndex) == CDC_CMD_ITF_NBR[i] || LOBYTE(req->wIndex) == CDC_COM_ITF_NBR[i]) { + return USBD_CDC_ACM.Setup(pdev, req); + } + } + + return USBD_FAIL; +} + +/** + * @brief USBD_COMPOSITE_DataIn + * handle data IN Stage + * @param pdev: device instance + * @param epnum: endpoint index + * @retval status + */ +static uint8_t USBD_COMPOSITE_DataIn(USBD_HandleTypeDef * pdev, uint8_t epnum) +{ + for (uint8_t i = 0; i < USBD_CDC_ACM_COUNT; i++) { + if (epnum == (CDC_IN_EP[i] & 0x7F) || epnum == (CDC_CMD_EP[i] & 0x7F)) { return USBD_CDC_ACM.DataIn(pdev, epnum); } + } + return USBD_FAIL; +} + +/** + * @brief USBD_COMPOSITE_EP0_RxReady + * handle EP0 Rx Ready event + * @param pdev: device instance + * @retval status + */ +static uint8_t USBD_COMPOSITE_EP0_RxReady(USBD_HandleTypeDef * pdev) +{ + USBD_CDC_ACM.EP0_RxReady(pdev); + return (uint8_t) USBD_OK; +} + +/** + * @brief USBD_COMPOSITE_EP0_TxReady + * handle EP0 TRx Ready event + * @param pdev: device instance + * @retval status + */ +static uint8_t USBD_COMPOSITE_EP0_TxReady(USBD_HandleTypeDef * pdev) { return (uint8_t) USBD_OK; } + +/** + * @brief USBD_COMPOSITE_SOF + * handle SOF event + * @param pdev: device instance + * @retval status + */ +static uint8_t USBD_COMPOSITE_SOF(USBD_HandleTypeDef * pdev) { return (uint8_t) USBD_OK; } + +/** + * @brief USBD_COMPOSITE_IsoINIncomplete + * handle data ISO IN Incomplete event + * @param pdev: device instance + * @param epnum: endpoint index + * @retval status + */ +static uint8_t USBD_COMPOSITE_IsoINIncomplete(USBD_HandleTypeDef * pdev, uint8_t epnum) { return (uint8_t) USBD_OK; } + +/** + * @brief USBD_COMPOSITE_IsoOutIncomplete + * handle data ISO OUT Incomplete event + * @param pdev: device instance + * @param epnum: endpoint index + * @retval status + */ +static uint8_t USBD_COMPOSITE_IsoOutIncomplete(USBD_HandleTypeDef * pdev, uint8_t epnum) { return (uint8_t) USBD_OK; } +/** + * @brief USBD_COMPOSITE_DataOut + * handle data OUT Stage + * @param pdev: device instance + * @param epnum: endpoint index + * @retval status + */ +static uint8_t USBD_COMPOSITE_DataOut(USBD_HandleTypeDef * pdev, uint8_t epnum) +{ + for (uint8_t i = 0; i < USBD_CDC_ACM_COUNT; i++) { + if (epnum == CDC_OUT_EP[i]) { return USBD_CDC_ACM.DataOut(pdev, epnum); } + } + return USBD_FAIL; +} + +/** + * @brief USBD_COMPOSITE_GetHSCfgDesc + * return configuration descriptor + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ +static uint8_t * USBD_COMPOSITE_GetHSCfgDesc(uint16_t * length) +{ + *length = (uint16_t) sizeof(USBD_COMPOSITE_HSCfgDesc); + return (uint8_t *) &USBD_COMPOSITE_HSCfgDesc; +} + +/** + * @brief USBD_COMPOSITE_GetFSCfgDesc + * return configuration descriptor + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ +static uint8_t * USBD_COMPOSITE_GetFSCfgDesc(uint16_t * length) +{ + *length = (uint16_t) sizeof(USBD_COMPOSITE_FSCfgDesc); + return (uint8_t *) &USBD_COMPOSITE_FSCfgDesc; +} + +/** + * @brief USBD_COMPOSITE_GetOtherSpeedCfgDesc + * return configuration descriptor + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ +static uint8_t * USBD_COMPOSITE_GetOtherSpeedCfgDesc(uint16_t * length) +{ +#if (USBD_USE_HS == 1) + *length = (uint16_t) sizeof(USBD_COMPOSITE_FSCfgDesc); + return (uint8_t *) &USBD_COMPOSITE_FSCfgDesc; +#else + *length = (uint16_t) sizeof(USBD_COMPOSITE_HSCfgDesc); + return (uint8_t *) &USBD_COMPOSITE_HSCfgDesc; +#endif +} + +/** + * @brief DeviceQualifierDescriptor + * return Device Qualifier descriptor + * @param length : pointer data length + * @retval pointer to descriptor buffer + */ +uint8_t * USBD_COMPOSITE_GetDeviceQualifierDesc(uint16_t * length) +{ + *length = (uint16_t) sizeof(USBD_COMPOSITE_DeviceQualifierDesc); + return USBD_COMPOSITE_DeviceQualifierDesc; +} + +/** + * @brief USBD_COMPOSITE_GetUsrStringDesc + * Manages the transfer of memory interfaces string descriptors. + * @param speed : current device speed + * @param index: descriptor index + * @param length : pointer data length + * @retval pointer to the descriptor table or NULL if the descriptor is not supported. + */ +#if (USBD_SUPPORT_USER_STRING_DESC == 1U) +static uint8_t * USBD_COMPOSITE_GetUsrStringDesc(USBD_HandleTypeDef * pdev, uint8_t index, uint16_t * length) +{ + static uint8_t USBD_StrDesc[64]; + + /* Check if the requested string interface is supported */ + if (index <= USBD_Track_String_Index) { + char str_buffer[16] = ""; + for (uint8_t i = 0; i < USBD_CDC_ACM_COUNT; i++) { + if (index == CDC_STR_DESC_IDX[i]) { + snprintf(str_buffer, sizeof(str_buffer), CDC_ACM_STR_DESC, i); + USBD_GetString((uint8_t *) str_buffer, USBD_StrDesc, length); + } + } + return USBD_StrDesc; + } else { + /* Not supported Interface Descriptor index */ + return NULL; + } +} +#endif + +void USBD_COMPOSITE_Mount_Class(void) +{ + uint16_t len = 0; + uint8_t * ptr = NULL; + + uint8_t in_ep_track = 0x81; + uint8_t out_ep_track = 0x01; + uint8_t interface_no_track = 0x00; + + ptr = USBD_CDC_ACM.GetFSConfigDescriptor(&len); + USBD_Update_CDC_ACM_DESC(ptr, interface_no_track, interface_no_track + 1, in_ep_track, in_ep_track + 1, out_ep_track, + USBD_Track_String_Index); + memcpy(USBD_COMPOSITE_FSCfgDesc.USBD_CDC_ACM_DESC, ptr + 0x09, len - 0x09); + + ptr = USBD_CDC_ACM.GetHSConfigDescriptor(&len); + USBD_Update_CDC_ACM_DESC(ptr, interface_no_track, interface_no_track + 1, in_ep_track, in_ep_track + 1, out_ep_track, + USBD_Track_String_Index); + memcpy(USBD_COMPOSITE_HSCfgDesc.USBD_CDC_ACM_DESC, ptr + 0x09, len - 0x09); + + in_ep_track += 2 * USBD_CDC_ACM_COUNT; + out_ep_track += 1 * USBD_CDC_ACM_COUNT; + interface_no_track += 2 * USBD_CDC_ACM_COUNT; + USBD_Track_String_Index += USBD_CDC_ACM_COUNT; + + uint16_t CFG_SIZE = sizeof(USBD_COMPOSITE_CFG_DESC_t); + ptr = USBD_COMPOSITE_HSCfgDesc.CONFIG_DESC; + /* Configuration Descriptor */ + ptr[0] = 0x09; /* bLength: Configuration Descriptor size */ + ptr[1] = USB_DESC_TYPE_CONFIGURATION; /* bDescriptorType: Configuration */ + ptr[2] = LOBYTE(CFG_SIZE); /* wTotalLength:no of returned bytes */ + ptr[3] = HIBYTE(CFG_SIZE); + ptr[4] = interface_no_track; /* bNumInterfaces: 2 interface */ + ptr[5] = 0x01; /* bConfigurationValue: Configuration value */ + ptr[6] = 0x00; /* iConfiguration: Index of string descriptor describing the configuration */ +#if (USBD_SELF_POWERED == 1U) + ptr[7] = 0xC0; /* bmAttributes: Bus Powered according to user configuration */ +#else + ptr[7] = 0x80; /* bmAttributes: Bus Powered according to user configuration */ +#endif + ptr[8] = USBD_MAX_POWER; /* MaxPower 100 mA */ + + ptr = USBD_COMPOSITE_FSCfgDesc.CONFIG_DESC; + /* Configuration Descriptor */ + ptr[0] = 0x09; /* bLength: Configuration Descriptor size */ + ptr[1] = USB_DESC_TYPE_CONFIGURATION; /* bDescriptorType: Configuration */ + ptr[2] = LOBYTE(CFG_SIZE); /* wTotalLength:no of returned bytes */ + ptr[3] = HIBYTE(CFG_SIZE); + ptr[4] = interface_no_track; /* bNumInterfaces: 2 interface */ + ptr[5] = 0x01; /* bConfigurationValue: Configuration value */ + ptr[6] = 0x00; /* iConfiguration: Index of string descriptor describing the configuration */ +#if (USBD_SELF_POWERED == 1U) + ptr[7] = 0xC0; /* bmAttributes: Bus Powered according to user configuration */ +#else + ptr[7] = 0x80; /* bmAttributes: Bus Powered according to user configuration */ +#endif + ptr[8] = USBD_MAX_POWER; /* MaxPower 100 mA */ + + (void) out_ep_track; + (void) in_ep_track; +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/USB_AL94/usbd_composite.h b/common/USB_AL94/usbd_composite.h new file mode 100644 index 0000000..ba26ad4 --- /dev/null +++ b/common/USB_AL94/usbd_composite.h @@ -0,0 +1,58 @@ +/** + ****************************************************************************** + * @file usbd_composite.h + * @author MCD Application Team + * @brief Header file for the usbd_composite.c file. + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2015 STMicroelectronics. + * All rights reserved.

+ * + * 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 + * + ****************************************************************************** + */ + +#ifndef __USB_COMPOSITE_H +#define __USB_COMPOSITE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "stdbool.h" +#include "usbd_ioreq.h" +#include // NOTE! replaced "AL94.I-CUBE-USBD-COMPOSITE_conf.h" + +#define USBD_USE_HS _USBD_USE_HS +#define USBD_USE_CDC_ACM _USBD_USE_CDC_ACM +#define USBD_CDC_ACM_COUNT _USBD_CDC_ACM_COUNT +//#define USBD_USE_CDC_RNDIS _USBD_USE_CDC_RNDIS +//#define USBD_USE_CDC_ECM _USBD_USE_CDC_ECM +//#define USBD_USE_HID_MOUSE _USBD_USE_HID_MOUSE +//#define USBD_USE_HID_KEYBOARD _USBD_USE_HID_KEYBOARD +//#define USBD_USE_HID_CUSTOM _USBD_USE_HID_CUSTOM +//#define USBD_USE_UAC_MIC _USBD_USE_UAC_MIC +//#define USBD_USE_UAC_SPKR _USBD_USE_UAC_SPKR +//#define USBD_USE_UVC _USBD_USE_UVC +//#define USBD_USE_MSC _USBD_USE_MSC +//#define USBD_USE_DFU _USBD_USE_DFU +//#define USBD_USE_PRNTR _USBD_USE_PRNTR + +#include "usbd_cdc_if.h" + +extern USBD_ClassTypeDef USBD_COMPOSITE; + +void USBD_COMPOSITE_Mount_Class(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __USB_COMPOSITE_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/AL94_USB_Composite/Target/usbd_conf.c b/common/USB_AL94/usbd_conf.c similarity index 96% rename from common/AL94_USB_Composite/Target/usbd_conf.c rename to common/USB_AL94/usbd_conf.c index c05b09f..03a96ac 100644 --- a/common/AL94_USB_Composite/Target/usbd_conf.c +++ b/common/USB_AL94/usbd_conf.c @@ -1,816 +1,816 @@ -/* USER CODE BEGIN Header */ -/** - ****************************************************************************** - * @file : Target/usbd_conf.c - * @version : v1.0_Cube - * @brief : This file implements the board support package for the USB device library - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2021 STMicroelectronics. - * All rights reserved.

- * - * 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 - * - ****************************************************************************** - */ -/* USER CODE END Header */ - -/* Includes ------------------------------------------------------------------*/ -#include "usbd_def.h" -#include "usbd_core.h" - -/* USER CODE BEGIN Includes */ -#include "usbd_composite.h" -#if (STM32F1_DEVICE) /** for STM32F1 or similar */ -#include "usb.h" -#else -// #include "usb_otg.h" -#include -#endif -/* USER CODE END Includes */ - -/* Private typedef -----------------------------------------------------------*/ -/* Private define ------------------------------------------------------------*/ -/* Private macro -------------------------------------------------------------*/ - -/* USER CODE BEGIN PV */ -/* Private variables ---------------------------------------------------------*/ - -/* USER CODE END PV */ -PCD_HandleTypeDef *hpcd_USB_OTG_PTR; -void Error_Handler (void); - -/* External functions --------------------------------------------------------*/ - -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ - -/* USER CODE BEGIN PFP */ -/* Private function prototypes -----------------------------------------------*/ -USBD_StatusTypeDef USBD_Get_USB_Status (HAL_StatusTypeDef hal_status); -HAL_StatusTypeDef HAL_PCDEx_SetTxFiFoInBytes (PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size); -HAL_StatusTypeDef HAL_PCDEx_SetRxFiFoInBytes (PCD_HandleTypeDef *hpcd, uint16_t size); -/* USER CODE END PFP */ - -/* Private functions ---------------------------------------------------------*/ - -/* USER CODE BEGIN 1 */ -#if(!STM32F1_DEVICE) -HAL_StatusTypeDef HAL_PCDEx_SetTxFiFoInBytes (PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size) -{ - return HAL_PCDEx_SetTxFiFo (hpcd, fifo, (size / 4)); -} - -HAL_StatusTypeDef HAL_PCDEx_SetRxFiFoInBytes (PCD_HandleTypeDef *hpcd, uint16_t size) -{ - return HAL_PCDEx_SetRxFiFo (hpcd, (size / 4)); -} -#endif -/* USER CODE END 1 */ - -/******************************************************************************* - LL Driver Callbacks (PCD -> USB Device Library) - *******************************************************************************/ -/* MSP Init */ - -__weak void HAL_PCD_MspInit (PCD_HandleTypeDef *pcdHandle) -{ - /* @see usb_otg.c or usb.c for (STM32F1 or similar) generated by cube **/ -} - -__weak void HAL_PCD_MspDeInit (PCD_HandleTypeDef *pcdHandle) -{ - /* @see usb_otg.c or usb.c for (STM32F1 or similar) generated by cube **/ -} - -/** - * @brief Setup stage callback - * @param hpcd: PCD handle - * @retval None - */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) -#else -void HAL_PCD_SetupStageCallback (PCD_HandleTypeDef *hpcd) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - USBD_LL_SetupStage ((USBD_HandleTypeDef*) hpcd->pData, (uint8_t*) hpcd->Setup); -} - -/** - * @brief Data Out stage callback. - * @param hpcd: PCD handle - * @param epnum: Endpoint number - * @retval None - */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) -#else -void HAL_PCD_DataOutStageCallback (PCD_HandleTypeDef *hpcd, uint8_t epnum) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - USBD_LL_DataOutStage ((USBD_HandleTypeDef*) hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff); -} - -/** - * @brief Data In stage callback. - * @param hpcd: PCD handle - * @param epnum: Endpoint number - * @retval None - */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) -#else -void HAL_PCD_DataInStageCallback (PCD_HandleTypeDef *hpcd, uint8_t epnum) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - USBD_LL_DataInStage ((USBD_HandleTypeDef*) hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff); -} - -/** - * @brief SOF callback. - * @param hpcd: PCD handle - * @retval None - */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_SOFCallback(PCD_HandleTypeDef *hpcd) -#else -void HAL_PCD_SOFCallback (PCD_HandleTypeDef *hpcd) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - USBD_LL_SOF ((USBD_HandleTypeDef*) hpcd->pData); -} - -/** - * @brief Reset callback. - * @param hpcd: PCD handle - * @retval None - */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ResetCallback(PCD_HandleTypeDef *hpcd) -#else -void HAL_PCD_ResetCallback (PCD_HandleTypeDef *hpcd) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - USBD_SpeedTypeDef speed = USBD_SPEED_FULL; - - if (hpcd->Init.speed == PCD_SPEED_FULL) - { - speed = USBD_SPEED_FULL; - } -#if(!STM32F1_DEVICE) - else if (hpcd->Init.speed == PCD_SPEED_HIGH) - { - speed = USBD_SPEED_HIGH; - } -#endif - else - { - Error_Handler (); - } - /* Set Speed. */ - USBD_LL_SetSpeed ((USBD_HandleTypeDef*) hpcd->pData, speed); - - /* Reset Device. */ - USBD_LL_Reset ((USBD_HandleTypeDef*) hpcd->pData); -} - -/** - * @brief Suspend callback. - * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) - * @param hpcd: PCD handle - * @retval None - */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) -#else -void HAL_PCD_SuspendCallback (PCD_HandleTypeDef *hpcd) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - /* Inform USB library that core enters in suspend Mode. */ - USBD_LL_Suspend ((USBD_HandleTypeDef*) hpcd->pData); -#if (!STM32F1_DEVICE) - __HAL_PCD_GATE_PHYCLOCK(hpcd); - /* Enter in STOP mode. */ - /* USER CODE BEGIN 2 */ - if (hpcd->Init.low_power_enable) - { - /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */ - SCB->SCR |= (uint32_t) ((uint32_t) (SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); - } -#endif - /* USER CODE END 2 */ -} - -/** - * @brief Resume callback. - * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) - * @param hpcd: PCD handle - * @retval None - */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) -#else -void HAL_PCD_ResumeCallback (PCD_HandleTypeDef *hpcd) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - /* USER CODE BEGIN 3 */ - - /* USER CODE END 3 */ - USBD_LL_Resume ((USBD_HandleTypeDef*) hpcd->pData); -} - -/** - * @brief ISOOUTIncomplete callback. - * @param hpcd: PCD handle - * @param epnum: Endpoint number - * @retval None - */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) -#else -void HAL_PCD_ISOOUTIncompleteCallback (PCD_HandleTypeDef *hpcd, uint8_t epnum) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - USBD_LL_IsoOUTIncomplete ((USBD_HandleTypeDef*) hpcd->pData, epnum); -} - -/** - * @brief ISOINIncomplete callback. - * @param hpcd: PCD handle - * @param epnum: Endpoint number - * @retval None - */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) -#else -void HAL_PCD_ISOINIncompleteCallback (PCD_HandleTypeDef *hpcd, uint8_t epnum) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - USBD_LL_IsoINIncomplete ((USBD_HandleTypeDef*) hpcd->pData, epnum); -} - -/** - * @brief Connect callback. - * @param hpcd: PCD handle - * @retval None - */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) -#else -void HAL_PCD_ConnectCallback (PCD_HandleTypeDef *hpcd) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - USBD_LL_DevConnected ((USBD_HandleTypeDef*) hpcd->pData); -} - -/** - * @brief Disconnect callback. - * @param hpcd: PCD handle - * @retval None - */ -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) -static void PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) -#else -void HAL_PCD_DisconnectCallback (PCD_HandleTypeDef *hpcd) -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ -{ - USBD_LL_DevDisconnected ((USBD_HandleTypeDef*) hpcd->pData); -} - -/******************************************************************************* - LL Driver Interface (USB Device Library --> PCD) - *******************************************************************************/ - -/** - * @brief Initializes the low level portion of the device driver. - * @param pdev: Device handle - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev) -{ -#if (USBD_USE_HS == 1) - /** HIGH SPEED USB */ - hpcd_USB_OTG_PTR = &hpcd_USB_OTG_HS; - - if (pdev->id == DEVICE_HS) - { - /* Link the driver to the stack. */ - hpcd_USB_OTG_PTR->pData = pdev; - pdev->pData = hpcd_USB_OTG_PTR; - - /* @see HAL_PCD_Init() usb_otg.c generated by cube **/ - - HAL_PCDEx_SetRxFiFoInBytes(hpcd_USB_OTG_PTR, 1024); - - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, 0, 64); // EP0 IN - -#if (USBD_USE_CDC_RNDIS == 1) - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CDC_RNDIS_IN_EP & 0x7F), 128); - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CDC_RNDIS_CMD_EP & 0x7F), 64); -#endif -#if (USBD_USE_CDC_ECM == 1) - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CDC_ECM_IN_EP & 0x7F), 128); - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CDC_ECM_CMD_EP & 0x7F), 64); -#endif -#if (USBD_USE_HID_MOUSE == 1) - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (HID_MOUSE_IN_EP & 0x7F), 64); -#endif -#if (USBD_USE_HID_KEYBOARD == 1) - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (HID_KEYBOARD_IN_EP & 0x7F), 64); -#endif -#if (USBD_USE_HID_CUSTOM == 1) - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CUSTOM_HID_IN_EP & 0x7F), 64); -#endif -#if (USBD_USE_UAC_MIC == 1) - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (AUDIO_MIC_EP & 0x7F), 128); -#endif -#if (USBD_USE_UAC_SPKR == 1) -#endif -#if (USBD_USE_UVC == 1) - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (UVC_IN_EP & 0x7F), 128); -#endif -#if (USBD_USE_MSC == 1) - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (MSC_IN_EP & 0x7F), 128); -#endif -#if (USBD_USE_DFU == 1) -#endif -#if (USBD_USE_PRNTR == 1) - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (PRNT_IN_EP & 0x7F), 128); -#endif -#if (USBD_USE_CDC_ACM == 1) - for (uint8_t i = 0; i < USBD_CDC_ACM_COUNT; i++) - { - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CDC_IN_EP[i] & 0x7F), 128); - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CDC_CMD_EP[i] & 0x7F), 64); - } -#endif - } -#else - /**FULL SPEED USB */ -#if (STM32F1_DEVICE) /** for STM32F1 or similar */ - hpcd_USB_OTG_PTR = &hpcd_USB_FS; /** hpcd_USB_FS or hpcd_USB_OTG_FS*/ -#else - hpcd_USB_OTG_PTR = &hpcd_USB_OTG_FS; /** hpcd_USB_FS or hpcd_USB_OTG_FS*/ -#endif - - if (pdev->id == DEVICE_FS) - { - /* Link the driver to the stack. */ - hpcd_USB_OTG_PTR->pData = pdev; - pdev->pData = hpcd_USB_OTG_PTR; - - /* @see HAL_PCD_Init() usb_otg.c generated by cube **/ - -#if (STM32F1_DEVICE) - /** Device is F1 or similar or if HAL_PCDEx_PMAConfig() is used by HAL driver */ - uint16_t pma_track = 0x40; /** PMA offset*/ - - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, 0x00, PCD_SNG_BUF, pma_track); - pma_track += 0x40; - - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, 0x80, PCD_SNG_BUF, pma_track); - pma_track += 0x40; - -#if (USBD_USE_CDC_RNDIS == 1) - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CDC_RNDIS_IN_EP, PCD_SNG_BUF, pma_track); - pma_track += 128; - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CDC_RNDIS_OUT_EP, PCD_SNG_BUF, pma_track); - pma_track += 128; - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CDC_RNDIS_CMD_EP, PCD_SNG_BUF, pma_track); - pma_track += 8; -#endif -#if (USBD_USE_CDC_ECM == 1) - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CDC_ECM_IN_EP, PCD_SNG_BUF, pma_track); - pma_track += 48; - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CDC_ECM_OUT_EP, PCD_SNG_BUF, pma_track); - pma_track += 48; - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CDC_ECM_CMD_EP, PCD_SNG_BUF, pma_track); - pma_track += 8; -#endif -#if (USBD_USE_HID_MOUSE == 1) - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, HID_MOUSE_IN_EP, PCD_SNG_BUF, pma_track); - pma_track += 8; -#endif -#if (USBD_USE_HID_KEYBOARD == 1) - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, HID_KEYBOARD_IN_EP, PCD_SNG_BUF, pma_track); - pma_track += 8; -#endif -#if (USBD_USE_HID_CUSTOM == 1) - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CUSTOM_HID_IN_EP, PCD_SNG_BUF, pma_track); - pma_track += 8; - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CUSTOM_HID_OUT_EP, PCD_SNG_BUF, pma_track); - pma_track += 8; -#endif -#if (USBD_USE_UAC_MIC == 1) - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, AUDIO_MIC_EP, PCD_SNG_BUF, pma_track); - pma_track += 128; -#endif -#if (USBD_USE_UAC_SPKR == 1) - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, AUDIO_SPKR_EP, PCD_SNG_BUF, pma_track); - pma_track += 128; -#endif -#if (USBD_USE_UVC == 1) - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, UVC_IN_EP, PCD_SNG_BUF, pma_track); - pma_track += 128; -#endif -#if (USBD_USE_MSC == 1) - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, MSC_IN_EP, PCD_SNG_BUF, pma_track); - pma_track += 128; - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, MSC_OUT_EP, PCD_SNG_BUF, pma_track); - pma_track += 128; -#endif -#if (USBD_USE_DFU == 1) -#endif -#if (USBD_USE_PRNTR == 1) - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, PRNT_IN_EP, PCD_SNG_BUF, pma_track); - pma_track += 128; - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, PRNT_OUT_EP, PCD_SNG_BUF, pma_track); - pma_track += 128; -#endif -#if (USBD_USE_CDC_ACM == 1) - for (uint8_t i = 0; i < USBD_CDC_ACM_COUNT; i++) - { - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CDC_IN_EP[i], PCD_SNG_BUF, pma_track); - pma_track += 48; - - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CDC_OUT_EP[i], PCD_SNG_BUF, pma_track); - pma_track += 48; - - HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CDC_CMD_EP[i], PCD_SNG_BUF, pma_track); - pma_track += 8; - } -#endif -#else /** if HAL_PCDEx_SetRxFiFo() is used by HAL driver */ - - HAL_PCDEx_SetRxFiFoInBytes (hpcd_USB_OTG_PTR, 512); // ALL OUT EP Buffer - - HAL_PCDEx_SetTxFiFoInBytes (hpcd_USB_OTG_PTR, 0, 64); // EP0 IN - -#if (USBD_USE_CDC_RNDIS == 1) - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CDC_RNDIS_IN_EP & 0x7F), 128); - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CDC_RNDIS_CMD_EP & 0x7F), 64); -#endif - -#if (USBD_USE_CDC_ECM == 1) - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CDC_ECM_IN_EP & 0x7F), 128); - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CDC_ECM_CMD_EP & 0x7F), 64); -#endif -#if (USBD_USE_HID_MOUSE == 1) - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (HID_MOUSE_IN_EP & 0x7F), 64); -#endif -#if (USBD_USE_HID_KEYBOARD == 1) - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (HID_KEYBOARD_IN_EP & 0x7F), 64); -#endif -#if (USBD_USE_HID_CUSTOM == 1) - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CUSTOM_HID_IN_EP & 0x7F), 64); -#endif -#if (USBD_USE_UAC_MIC == 1) - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (AUDIO_MIC_EP & 0x7F), 128); -#endif -#if (USBD_USE_UAC_SPKR == 1) -#endif -#if (USBD_USE_UVC == 1) - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (UVC_IN_EP & 0x7F), 128); -#endif -#if (USBD_USE_MSC == 1) - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (MSC_IN_EP & 0x7F), 128); -#endif -#if (USBD_USE_DFU == 1) -#endif -#if (USBD_USE_PRNTR == 1) - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (PRNT_IN_EP & 0x7F), 128); -#endif -#if (USBD_USE_CDC_ACM == 1) - for (uint8_t i = 0; i < USBD_CDC_ACM_COUNT; i++) - { - HAL_PCDEx_SetTxFiFoInBytes (hpcd_USB_OTG_PTR, (CDC_IN_EP[i] & 0x7F), 128); - HAL_PCDEx_SetTxFiFoInBytes (hpcd_USB_OTG_PTR, (CDC_CMD_EP[i] & 0x7F), 64); - } -#endif -#endif - } -#endif - -#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) - /* Register USB PCD CallBacks */ - HAL_PCD_RegisterCallback(hpcd_USB_OTG_PTR, HAL_PCD_SOF_CB_ID, PCD_SOFCallback); - HAL_PCD_RegisterCallback(hpcd_USB_OTG_PTR, HAL_PCD_SETUPSTAGE_CB_ID, PCD_SetupStageCallback); - HAL_PCD_RegisterCallback(hpcd_USB_OTG_PTR, HAL_PCD_RESET_CB_ID, PCD_ResetCallback); - HAL_PCD_RegisterCallback(hpcd_USB_OTG_PTR, HAL_PCD_SUSPEND_CB_ID, PCD_SuspendCallback); - HAL_PCD_RegisterCallback(hpcd_USB_OTG_PTR, HAL_PCD_RESUME_CB_ID, PCD_ResumeCallback); - HAL_PCD_RegisterCallback(hpcd_USB_OTG_PTR, HAL_PCD_CONNECT_CB_ID, PCD_ConnectCallback); - HAL_PCD_RegisterCallback(hpcd_USB_OTG_PTR, HAL_PCD_DISCONNECT_CB_ID, PCD_DisconnectCallback); - - HAL_PCD_RegisterDataOutStageCallback(hpcd_USB_OTG_PTR, PCD_DataOutStageCallback); - HAL_PCD_RegisterDataInStageCallback(hpcd_USB_OTG_PTR, PCD_DataInStageCallback); - HAL_PCD_RegisterIsoOutIncpltCallback(hpcd_USB_OTG_PTR, PCD_ISOOUTIncompleteCallback); - HAL_PCD_RegisterIsoInIncpltCallback(hpcd_USB_OTG_PTR, PCD_ISOINIncompleteCallback); -#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ - return USBD_OK; -} - -/** - * @brief De-Initializes the low level portion of the device driver. - * @param pdev: Device handle - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_DeInit (USBD_HandleTypeDef *pdev) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_DeInit (pdev->pData); - - usb_status = USBD_Get_USB_Status (hal_status); - - return usb_status; -} - -/** - * @brief Starts the low level portion of the device driver. - * @param pdev: Device handle - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_Start (USBD_HandleTypeDef *pdev) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_Start (pdev->pData); - - usb_status = USBD_Get_USB_Status (hal_status); - - return usb_status; -} - -/** - * @brief Stops the low level portion of the device driver. - * @param pdev: Device handle - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_Stop (USBD_HandleTypeDef *pdev) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_Stop (pdev->pData); - - usb_status = USBD_Get_USB_Status (hal_status); - - return usb_status; -} - -/** - * @brief Opens an endpoint of the low level driver. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @param ep_type: Endpoint type - * @param ep_mps: Endpoint max packet size - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_OpenEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_Open (pdev->pData, ep_addr, ep_mps, ep_type); - - usb_status = USBD_Get_USB_Status (hal_status); - - return usb_status; -} - -/** - * @brief Closes an endpoint of the low level driver. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_CloseEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_Close (pdev->pData, ep_addr); - - usb_status = USBD_Get_USB_Status (hal_status); - - return usb_status; -} - -/** - * @brief Flushes an endpoint of the Low Level Driver. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_FlushEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_Flush (pdev->pData, ep_addr); - - usb_status = USBD_Get_USB_Status (hal_status); - - return usb_status; -} - -/** - * @brief Sets a Stall condition on an endpoint of the Low Level Driver. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_StallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_SetStall (pdev->pData, ep_addr); - - usb_status = USBD_Get_USB_Status (hal_status); - - return usb_status; -} - -/** - * @brief Clears a Stall condition on an endpoint of the Low Level Driver. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_ClearStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_ClrStall (pdev->pData, ep_addr); - - usb_status = USBD_Get_USB_Status (hal_status); - - return usb_status; -} - -/** - * @brief Returns Stall condition. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval Stall (1: Yes, 0: No) - */ -uint8_t USBD_LL_IsStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) -{ - PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData; - - if ((ep_addr & 0x80) == 0x80) - { - return hpcd->IN_ep[ep_addr & 0x7F].is_stall; - } - else - { - return hpcd->OUT_ep[ep_addr & 0x7F].is_stall; - } -} - -/** - * @brief Assigns a USB address to the device. - * @param pdev: Device handle - * @param dev_addr: Device address - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_SetUSBAddress (USBD_HandleTypeDef *pdev, uint8_t dev_addr) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_SetAddress (pdev->pData, dev_addr); - - usb_status = USBD_Get_USB_Status (hal_status); - - return usb_status; -} - -// NOTE! is used instead of the Cube generated ST file that does not check maxpacket -HAL_StatusTypeDef Faux_HAL_PCD_EP_Transmit (PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len) -{ - PCD_EPTypeDef *ep; - - ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK]; - - /*setup and start the Xfer */ - ep->xfer_buff = pBuf; - ep->xfer_len = len; - ep->xfer_count = 0U; - ep->is_in = 1U; - ep->num = ep_addr & EP_ADDR_MSK; - if (ep->maxpacket == 0) - return HAL_ERROR; // NOTE This prevents transmitting if buffers aren't initialized. - - if (hpcd->Init.dma_enable == 1U) - { - ep->dma_addr = (uint32_t) pBuf; - } - - (void) USB_EPStartXfer (hpcd->Instance, ep, (uint8_t) hpcd->Init.dma_enable); - - return HAL_OK; -} - -/** - * @brief Transmits data over an endpoint. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @param pbuf: Pointer to data to be sent - * @param size: Data size - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_Transmit (USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = Faux_HAL_PCD_EP_Transmit (pdev->pData, ep_addr, pbuf, size); - - usb_status = USBD_Get_USB_Status (hal_status); - - return usb_status; -} - -/** - * @brief Prepares an endpoint for reception. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @param pbuf: Pointer to data to be received - * @param size: Data size - * @retval USBD status - */ -USBD_StatusTypeDef USBD_LL_PrepareReceive (USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size) -{ - HAL_StatusTypeDef hal_status = HAL_OK; - USBD_StatusTypeDef usb_status = USBD_OK; - - hal_status = HAL_PCD_EP_Receive (pdev->pData, ep_addr, pbuf, size); - - usb_status = USBD_Get_USB_Status (hal_status); - - return usb_status; -} - -/** - * @brief Returns the last transfered packet size. - * @param pdev: Device handle - * @param ep_addr: Endpoint number - * @retval Recived Data Size - */ -uint32_t USBD_LL_GetRxDataSize (USBD_HandleTypeDef *pdev, uint8_t ep_addr) -{ - return HAL_PCD_EP_GetRxCount ((PCD_HandleTypeDef*) pdev->pData, ep_addr); -} - -/** - * @brief Delays routine for the USB device library. - * @param Delay: Delay in ms - * @retval None - */ -void USBD_LL_Delay (uint32_t Delay) -{ - HAL_Delay (Delay); -} - -/** - * @brief Retuns the USB status depending on the HAL status: - * @param hal_status: HAL status - * @retval USB status - */ -USBD_StatusTypeDef USBD_Get_USB_Status (HAL_StatusTypeDef hal_status) -{ - USBD_StatusTypeDef usb_status = USBD_OK; - - switch (hal_status) - { - case HAL_OK: - usb_status = USBD_OK; - break; - case HAL_ERROR: - usb_status = USBD_FAIL; - break; - case HAL_BUSY: - usb_status = USBD_BUSY; - break; - case HAL_TIMEOUT: - usb_status = USBD_FAIL; - break; - default: - usb_status = USBD_FAIL; - break; - } - return usb_status; -} - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : Target/usbd_conf.c + * @version : v1.0_Cube + * @brief : This file implements the board support package for the USB device library + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2021 STMicroelectronics. + * All rights reserved.

+ * + * 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 + * + ****************************************************************************** + */ +/* USER CODE END Header */ + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_def.h" +#include "usbd_core.h" + +/* USER CODE BEGIN Includes */ +#include "usbd_composite.h" +#if (STM32F1_DEVICE) /** for STM32F1 or similar */ +#include "usb.h" +#else +// #include "usb_otg.h" +#include +#endif +/* USER CODE END Includes */ + +/* Private typedef -----------------------------------------------------------*/ +/* Private define ------------------------------------------------------------*/ +/* Private macro -------------------------------------------------------------*/ + +/* USER CODE BEGIN PV */ +/* Private variables ---------------------------------------------------------*/ + +/* USER CODE END PV */ +PCD_HandleTypeDef *hpcd_USB_OTG_PTR; +void Error_Handler (void); + +/* External functions --------------------------------------------------------*/ + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +/* USER CODE BEGIN PFP */ +/* Private function prototypes -----------------------------------------------*/ +USBD_StatusTypeDef USBD_Get_USB_Status (HAL_StatusTypeDef hal_status); +HAL_StatusTypeDef HAL_PCDEx_SetTxFiFoInBytes (PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size); +HAL_StatusTypeDef HAL_PCDEx_SetRxFiFoInBytes (PCD_HandleTypeDef *hpcd, uint16_t size); +/* USER CODE END PFP */ + +/* Private functions ---------------------------------------------------------*/ + +/* USER CODE BEGIN 1 */ +#if(!STM32F1_DEVICE) +HAL_StatusTypeDef HAL_PCDEx_SetTxFiFoInBytes (PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size) +{ + return HAL_PCDEx_SetTxFiFo (hpcd, fifo, (size / 4)); +} + +HAL_StatusTypeDef HAL_PCDEx_SetRxFiFoInBytes (PCD_HandleTypeDef *hpcd, uint16_t size) +{ + return HAL_PCDEx_SetRxFiFo (hpcd, (size / 4)); +} +#endif +/* USER CODE END 1 */ + +/******************************************************************************* + LL Driver Callbacks (PCD -> USB Device Library) + *******************************************************************************/ +/* MSP Init */ + +__weak void HAL_PCD_MspInit (PCD_HandleTypeDef *pcdHandle) +{ + /* @see usb_otg.c or usb.c for (STM32F1 or similar) generated by cube **/ +} + +__weak void HAL_PCD_MspDeInit (PCD_HandleTypeDef *pcdHandle) +{ + /* @see usb_otg.c or usb.c for (STM32F1 or similar) generated by cube **/ +} + +/** + * @brief Setup stage callback + * @param hpcd: PCD handle + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) +#else +void HAL_PCD_SetupStageCallback (PCD_HandleTypeDef *hpcd) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + USBD_LL_SetupStage ((USBD_HandleTypeDef*) hpcd->pData, (uint8_t*) hpcd->Setup); +} + +/** + * @brief Data Out stage callback. + * @param hpcd: PCD handle + * @param epnum: Endpoint number + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +#else +void HAL_PCD_DataOutStageCallback (PCD_HandleTypeDef *hpcd, uint8_t epnum) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + USBD_LL_DataOutStage ((USBD_HandleTypeDef*) hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff); +} + +/** + * @brief Data In stage callback. + * @param hpcd: PCD handle + * @param epnum: Endpoint number + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +#else +void HAL_PCD_DataInStageCallback (PCD_HandleTypeDef *hpcd, uint8_t epnum) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + USBD_LL_DataInStage ((USBD_HandleTypeDef*) hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff); +} + +/** + * @brief SOF callback. + * @param hpcd: PCD handle + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_SOFCallback(PCD_HandleTypeDef *hpcd) +#else +void HAL_PCD_SOFCallback (PCD_HandleTypeDef *hpcd) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + USBD_LL_SOF ((USBD_HandleTypeDef*) hpcd->pData); +} + +/** + * @brief Reset callback. + * @param hpcd: PCD handle + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_ResetCallback(PCD_HandleTypeDef *hpcd) +#else +void HAL_PCD_ResetCallback (PCD_HandleTypeDef *hpcd) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + USBD_SpeedTypeDef speed = USBD_SPEED_FULL; + + if (hpcd->Init.speed == PCD_SPEED_FULL) + { + speed = USBD_SPEED_FULL; + } +#if(!STM32F1_DEVICE) + else if (hpcd->Init.speed == PCD_SPEED_HIGH) + { + speed = USBD_SPEED_HIGH; + } +#endif + else + { + Error_Handler (); + } + /* Set Speed. */ + USBD_LL_SetSpeed ((USBD_HandleTypeDef*) hpcd->pData, speed); + + /* Reset Device. */ + USBD_LL_Reset ((USBD_HandleTypeDef*) hpcd->pData); +} + +/** + * @brief Suspend callback. + * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) + * @param hpcd: PCD handle + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) +#else +void HAL_PCD_SuspendCallback (PCD_HandleTypeDef *hpcd) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + /* Inform USB library that core enters in suspend Mode. */ + USBD_LL_Suspend ((USBD_HandleTypeDef*) hpcd->pData); +#if (!STM32F1_DEVICE) + __HAL_PCD_GATE_PHYCLOCK(hpcd); + /* Enter in STOP mode. */ + /* USER CODE BEGIN 2 */ + if (hpcd->Init.low_power_enable) + { + /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */ + SCB->SCR |= (uint32_t) ((uint32_t) (SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); + } +#endif + /* USER CODE END 2 */ +} + +/** + * @brief Resume callback. + * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it) + * @param hpcd: PCD handle + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) +#else +void HAL_PCD_ResumeCallback (PCD_HandleTypeDef *hpcd) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + /* USER CODE BEGIN 3 */ + + /* USER CODE END 3 */ + USBD_LL_Resume ((USBD_HandleTypeDef*) hpcd->pData); +} + +/** + * @brief ISOOUTIncomplete callback. + * @param hpcd: PCD handle + * @param epnum: Endpoint number + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +#else +void HAL_PCD_ISOOUTIncompleteCallback (PCD_HandleTypeDef *hpcd, uint8_t epnum) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + USBD_LL_IsoOUTIncomplete ((USBD_HandleTypeDef*) hpcd->pData, epnum); +} + +/** + * @brief ISOINIncomplete callback. + * @param hpcd: PCD handle + * @param epnum: Endpoint number + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) +#else +void HAL_PCD_ISOINIncompleteCallback (PCD_HandleTypeDef *hpcd, uint8_t epnum) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + USBD_LL_IsoINIncomplete ((USBD_HandleTypeDef*) hpcd->pData, epnum); +} + +/** + * @brief Connect callback. + * @param hpcd: PCD handle + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) +#else +void HAL_PCD_ConnectCallback (PCD_HandleTypeDef *hpcd) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + USBD_LL_DevConnected ((USBD_HandleTypeDef*) hpcd->pData); +} + +/** + * @brief Disconnect callback. + * @param hpcd: PCD handle + * @retval None + */ +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) +static void PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) +#else +void HAL_PCD_DisconnectCallback (PCD_HandleTypeDef *hpcd) +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ +{ + USBD_LL_DevDisconnected ((USBD_HandleTypeDef*) hpcd->pData); +} + +/******************************************************************************* + LL Driver Interface (USB Device Library --> PCD) + *******************************************************************************/ + +/** + * @brief Initializes the low level portion of the device driver. + * @param pdev: Device handle + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev) +{ +#if (USBD_USE_HS == 1) + /** HIGH SPEED USB */ + hpcd_USB_OTG_PTR = &hpcd_USB_OTG_HS; + + if (pdev->id == DEVICE_HS) + { + /* Link the driver to the stack. */ + hpcd_USB_OTG_PTR->pData = pdev; + pdev->pData = hpcd_USB_OTG_PTR; + + /* @see HAL_PCD_Init() usb_otg.c generated by cube **/ + + HAL_PCDEx_SetRxFiFoInBytes(hpcd_USB_OTG_PTR, 1024); + + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, 0, 64); // EP0 IN + +#if (USBD_USE_CDC_RNDIS == 1) + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CDC_RNDIS_IN_EP & 0x7F), 128); + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CDC_RNDIS_CMD_EP & 0x7F), 64); +#endif +#if (USBD_USE_CDC_ECM == 1) + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CDC_ECM_IN_EP & 0x7F), 128); + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CDC_ECM_CMD_EP & 0x7F), 64); +#endif +#if (USBD_USE_HID_MOUSE == 1) + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (HID_MOUSE_IN_EP & 0x7F), 64); +#endif +#if (USBD_USE_HID_KEYBOARD == 1) + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (HID_KEYBOARD_IN_EP & 0x7F), 64); +#endif +#if (USBD_USE_HID_CUSTOM == 1) + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CUSTOM_HID_IN_EP & 0x7F), 64); +#endif +#if (USBD_USE_UAC_MIC == 1) + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (AUDIO_MIC_EP & 0x7F), 128); +#endif +#if (USBD_USE_UAC_SPKR == 1) +#endif +#if (USBD_USE_UVC == 1) + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (UVC_IN_EP & 0x7F), 128); +#endif +#if (USBD_USE_MSC == 1) + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (MSC_IN_EP & 0x7F), 128); +#endif +#if (USBD_USE_DFU == 1) +#endif +#if (USBD_USE_PRNTR == 1) + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (PRNT_IN_EP & 0x7F), 128); +#endif +#if (USBD_USE_CDC_ACM == 1) + for (uint8_t i = 0; i < USBD_CDC_ACM_COUNT; i++) + { + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CDC_IN_EP[i] & 0x7F), 128); + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CDC_CMD_EP[i] & 0x7F), 64); + } +#endif + } +#else + /**FULL SPEED USB */ +#if (STM32F1_DEVICE) /** for STM32F1 or similar */ + hpcd_USB_OTG_PTR = &hpcd_USB_FS; /** hpcd_USB_FS or hpcd_USB_OTG_FS*/ +#else + hpcd_USB_OTG_PTR = &hpcd_USB_OTG_FS; /** hpcd_USB_FS or hpcd_USB_OTG_FS*/ +#endif + + if (pdev->id == DEVICE_FS) + { + /* Link the driver to the stack. */ + hpcd_USB_OTG_PTR->pData = pdev; + pdev->pData = hpcd_USB_OTG_PTR; + + /* @see HAL_PCD_Init() usb_otg.c generated by cube **/ + +#if (STM32F1_DEVICE) + /** Device is F1 or similar or if HAL_PCDEx_PMAConfig() is used by HAL driver */ + uint16_t pma_track = 0x40; /** PMA offset*/ + + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, 0x00, PCD_SNG_BUF, pma_track); + pma_track += 0x40; + + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, 0x80, PCD_SNG_BUF, pma_track); + pma_track += 0x40; + +#if (USBD_USE_CDC_RNDIS == 1) + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CDC_RNDIS_IN_EP, PCD_SNG_BUF, pma_track); + pma_track += 128; + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CDC_RNDIS_OUT_EP, PCD_SNG_BUF, pma_track); + pma_track += 128; + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CDC_RNDIS_CMD_EP, PCD_SNG_BUF, pma_track); + pma_track += 8; +#endif +#if (USBD_USE_CDC_ECM == 1) + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CDC_ECM_IN_EP, PCD_SNG_BUF, pma_track); + pma_track += 48; + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CDC_ECM_OUT_EP, PCD_SNG_BUF, pma_track); + pma_track += 48; + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CDC_ECM_CMD_EP, PCD_SNG_BUF, pma_track); + pma_track += 8; +#endif +#if (USBD_USE_HID_MOUSE == 1) + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, HID_MOUSE_IN_EP, PCD_SNG_BUF, pma_track); + pma_track += 8; +#endif +#if (USBD_USE_HID_KEYBOARD == 1) + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, HID_KEYBOARD_IN_EP, PCD_SNG_BUF, pma_track); + pma_track += 8; +#endif +#if (USBD_USE_HID_CUSTOM == 1) + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CUSTOM_HID_IN_EP, PCD_SNG_BUF, pma_track); + pma_track += 8; + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CUSTOM_HID_OUT_EP, PCD_SNG_BUF, pma_track); + pma_track += 8; +#endif +#if (USBD_USE_UAC_MIC == 1) + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, AUDIO_MIC_EP, PCD_SNG_BUF, pma_track); + pma_track += 128; +#endif +#if (USBD_USE_UAC_SPKR == 1) + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, AUDIO_SPKR_EP, PCD_SNG_BUF, pma_track); + pma_track += 128; +#endif +#if (USBD_USE_UVC == 1) + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, UVC_IN_EP, PCD_SNG_BUF, pma_track); + pma_track += 128; +#endif +#if (USBD_USE_MSC == 1) + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, MSC_IN_EP, PCD_SNG_BUF, pma_track); + pma_track += 128; + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, MSC_OUT_EP, PCD_SNG_BUF, pma_track); + pma_track += 128; +#endif +#if (USBD_USE_DFU == 1) +#endif +#if (USBD_USE_PRNTR == 1) + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, PRNT_IN_EP, PCD_SNG_BUF, pma_track); + pma_track += 128; + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, PRNT_OUT_EP, PCD_SNG_BUF, pma_track); + pma_track += 128; +#endif +#if (USBD_USE_CDC_ACM == 1) + for (uint8_t i = 0; i < USBD_CDC_ACM_COUNT; i++) + { + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CDC_IN_EP[i], PCD_SNG_BUF, pma_track); + pma_track += 48; + + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CDC_OUT_EP[i], PCD_SNG_BUF, pma_track); + pma_track += 48; + + HAL_PCDEx_PMAConfig((PCD_HandleTypeDef *)pdev->pData, CDC_CMD_EP[i], PCD_SNG_BUF, pma_track); + pma_track += 8; + } +#endif +#else /** if HAL_PCDEx_SetRxFiFo() is used by HAL driver */ + + HAL_PCDEx_SetRxFiFoInBytes (hpcd_USB_OTG_PTR, 512); // ALL OUT EP Buffer + + HAL_PCDEx_SetTxFiFoInBytes (hpcd_USB_OTG_PTR, 0, 64); // EP0 IN + +#if (USBD_USE_CDC_RNDIS == 1) + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CDC_RNDIS_IN_EP & 0x7F), 128); + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CDC_RNDIS_CMD_EP & 0x7F), 64); +#endif + +#if (USBD_USE_CDC_ECM == 1) + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CDC_ECM_IN_EP & 0x7F), 128); + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CDC_ECM_CMD_EP & 0x7F), 64); +#endif +#if (USBD_USE_HID_MOUSE == 1) + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (HID_MOUSE_IN_EP & 0x7F), 64); +#endif +#if (USBD_USE_HID_KEYBOARD == 1) + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (HID_KEYBOARD_IN_EP & 0x7F), 64); +#endif +#if (USBD_USE_HID_CUSTOM == 1) + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (CUSTOM_HID_IN_EP & 0x7F), 64); +#endif +#if (USBD_USE_UAC_MIC == 1) + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (AUDIO_MIC_EP & 0x7F), 128); +#endif +#if (USBD_USE_UAC_SPKR == 1) +#endif +#if (USBD_USE_UVC == 1) + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (UVC_IN_EP & 0x7F), 128); +#endif +#if (USBD_USE_MSC == 1) + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (MSC_IN_EP & 0x7F), 128); +#endif +#if (USBD_USE_DFU == 1) +#endif +#if (USBD_USE_PRNTR == 1) + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (PRNT_IN_EP & 0x7F), 128); +#endif +#if (USBD_USE_CDC_ACM == 1) + for (uint8_t i = 0; i < USBD_CDC_ACM_COUNT; i++) + { + HAL_PCDEx_SetTxFiFoInBytes (hpcd_USB_OTG_PTR, (CDC_IN_EP[i] & 0x7F), 128); + HAL_PCDEx_SetTxFiFoInBytes (hpcd_USB_OTG_PTR, (CDC_CMD_EP[i] & 0x7F), 64); + } +#endif +#endif + } +#endif + +#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) + /* Register USB PCD CallBacks */ + HAL_PCD_RegisterCallback(hpcd_USB_OTG_PTR, HAL_PCD_SOF_CB_ID, PCD_SOFCallback); + HAL_PCD_RegisterCallback(hpcd_USB_OTG_PTR, HAL_PCD_SETUPSTAGE_CB_ID, PCD_SetupStageCallback); + HAL_PCD_RegisterCallback(hpcd_USB_OTG_PTR, HAL_PCD_RESET_CB_ID, PCD_ResetCallback); + HAL_PCD_RegisterCallback(hpcd_USB_OTG_PTR, HAL_PCD_SUSPEND_CB_ID, PCD_SuspendCallback); + HAL_PCD_RegisterCallback(hpcd_USB_OTG_PTR, HAL_PCD_RESUME_CB_ID, PCD_ResumeCallback); + HAL_PCD_RegisterCallback(hpcd_USB_OTG_PTR, HAL_PCD_CONNECT_CB_ID, PCD_ConnectCallback); + HAL_PCD_RegisterCallback(hpcd_USB_OTG_PTR, HAL_PCD_DISCONNECT_CB_ID, PCD_DisconnectCallback); + + HAL_PCD_RegisterDataOutStageCallback(hpcd_USB_OTG_PTR, PCD_DataOutStageCallback); + HAL_PCD_RegisterDataInStageCallback(hpcd_USB_OTG_PTR, PCD_DataInStageCallback); + HAL_PCD_RegisterIsoOutIncpltCallback(hpcd_USB_OTG_PTR, PCD_ISOOUTIncompleteCallback); + HAL_PCD_RegisterIsoInIncpltCallback(hpcd_USB_OTG_PTR, PCD_ISOINIncompleteCallback); +#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ + return USBD_OK; +} + +/** + * @brief De-Initializes the low level portion of the device driver. + * @param pdev: Device handle + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_DeInit (USBD_HandleTypeDef *pdev) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_DeInit (pdev->pData); + + usb_status = USBD_Get_USB_Status (hal_status); + + return usb_status; +} + +/** + * @brief Starts the low level portion of the device driver. + * @param pdev: Device handle + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_Start (USBD_HandleTypeDef *pdev) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_Start (pdev->pData); + + usb_status = USBD_Get_USB_Status (hal_status); + + return usb_status; +} + +/** + * @brief Stops the low level portion of the device driver. + * @param pdev: Device handle + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_Stop (USBD_HandleTypeDef *pdev) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_Stop (pdev->pData); + + usb_status = USBD_Get_USB_Status (hal_status); + + return usb_status; +} + +/** + * @brief Opens an endpoint of the low level driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @param ep_type: Endpoint type + * @param ep_mps: Endpoint max packet size + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_OpenEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_EP_Open (pdev->pData, ep_addr, ep_mps, ep_type); + + usb_status = USBD_Get_USB_Status (hal_status); + + return usb_status; +} + +/** + * @brief Closes an endpoint of the low level driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_CloseEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_EP_Close (pdev->pData, ep_addr); + + usb_status = USBD_Get_USB_Status (hal_status); + + return usb_status; +} + +/** + * @brief Flushes an endpoint of the Low Level Driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_FlushEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_EP_Flush (pdev->pData, ep_addr); + + usb_status = USBD_Get_USB_Status (hal_status); + + return usb_status; +} + +/** + * @brief Sets a Stall condition on an endpoint of the Low Level Driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_StallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_EP_SetStall (pdev->pData, ep_addr); + + usb_status = USBD_Get_USB_Status (hal_status); + + return usb_status; +} + +/** + * @brief Clears a Stall condition on an endpoint of the Low Level Driver. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_ClearStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_EP_ClrStall (pdev->pData, ep_addr); + + usb_status = USBD_Get_USB_Status (hal_status); + + return usb_status; +} + +/** + * @brief Returns Stall condition. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @retval Stall (1: Yes, 0: No) + */ +uint8_t USBD_LL_IsStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData; + + if ((ep_addr & 0x80) == 0x80) + { + return hpcd->IN_ep[ep_addr & 0x7F].is_stall; + } + else + { + return hpcd->OUT_ep[ep_addr & 0x7F].is_stall; + } +} + +/** + * @brief Assigns a USB address to the device. + * @param pdev: Device handle + * @param dev_addr: Device address + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_SetUSBAddress (USBD_HandleTypeDef *pdev, uint8_t dev_addr) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_SetAddress (pdev->pData, dev_addr); + + usb_status = USBD_Get_USB_Status (hal_status); + + return usb_status; +} + +// NOTE! is used instead of the Cube generated ST file that does not check maxpacket +HAL_StatusTypeDef Faux_HAL_PCD_EP_Transmit (PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len) +{ + PCD_EPTypeDef *ep; + + ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK]; + + /*setup and start the Xfer */ + ep->xfer_buff = pBuf; + ep->xfer_len = len; + ep->xfer_count = 0U; + ep->is_in = 1U; + ep->num = ep_addr & EP_ADDR_MSK; + if (ep->maxpacket == 0) + return HAL_ERROR; // NOTE This prevents transmitting if buffers aren't initialized. + + if (hpcd->Init.dma_enable == 1U) + { + ep->dma_addr = (uint32_t) pBuf; + } + + (void) USB_EPStartXfer (hpcd->Instance, ep, (uint8_t) hpcd->Init.dma_enable); + + return HAL_OK; +} + +/** + * @brief Transmits data over an endpoint. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @param pbuf: Pointer to data to be sent + * @param size: Data size + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_Transmit (USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = Faux_HAL_PCD_EP_Transmit (pdev->pData, ep_addr, pbuf, size); + + usb_status = USBD_Get_USB_Status (hal_status); + + return usb_status; +} + +/** + * @brief Prepares an endpoint for reception. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @param pbuf: Pointer to data to be received + * @param size: Data size + * @retval USBD status + */ +USBD_StatusTypeDef USBD_LL_PrepareReceive (USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size) +{ + HAL_StatusTypeDef hal_status = HAL_OK; + USBD_StatusTypeDef usb_status = USBD_OK; + + hal_status = HAL_PCD_EP_Receive (pdev->pData, ep_addr, pbuf, size); + + usb_status = USBD_Get_USB_Status (hal_status); + + return usb_status; +} + +/** + * @brief Returns the last transfered packet size. + * @param pdev: Device handle + * @param ep_addr: Endpoint number + * @retval Recived Data Size + */ +uint32_t USBD_LL_GetRxDataSize (USBD_HandleTypeDef *pdev, uint8_t ep_addr) +{ + return HAL_PCD_EP_GetRxCount ((PCD_HandleTypeDef*) pdev->pData, ep_addr); +} + +/** + * @brief Delays routine for the USB device library. + * @param Delay: Delay in ms + * @retval None + */ +void USBD_LL_Delay (uint32_t Delay) +{ + HAL_Delay (Delay); +} + +/** + * @brief Retuns the USB status depending on the HAL status: + * @param hal_status: HAL status + * @retval USB status + */ +USBD_StatusTypeDef USBD_Get_USB_Status (HAL_StatusTypeDef hal_status) +{ + USBD_StatusTypeDef usb_status = USBD_OK; + + switch (hal_status) + { + case HAL_OK: + usb_status = USBD_OK; + break; + case HAL_ERROR: + usb_status = USBD_FAIL; + break; + case HAL_BUSY: + usb_status = USBD_BUSY; + break; + case HAL_TIMEOUT: + usb_status = USBD_FAIL; + break; + default: + usb_status = USBD_FAIL; + break; + } + return usb_status; +} + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/USB_AL94/usbd_conf.h b/common/USB_AL94/usbd_conf.h new file mode 100644 index 0000000..4cacbf7 --- /dev/null +++ b/common/USB_AL94/usbd_conf.h @@ -0,0 +1,106 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : usbd_conf.h + * @version : v1.0_Cube + * @brief : Header for usbd_conf.c file. + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2021 STMicroelectronics. + * All rights reserved.

+ * + * 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 + * + ****************************************************************************** + */ + +#ifndef __USBD_CONF__H__ +#define __USBD_CONF__H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "main.h" +#include +#include +#include + +/*---------- -----------*/ +#define USBD_MAX_NUM_INTERFACES 15U +/*---------- -----------*/ +#define USBD_MAX_NUM_CONFIGURATION 1U +/*---------- -----------*/ +#define USBD_MAX_STR_DESC_SIZ 512U +/*---------- -----------*/ +#define USBD_SUPPORT_USER_STRING_DESC 1U +/*---------- -----------*/ +#define USBD_DEBUG_LEVEL 0U +/*---------- -----------*/ +#define USBD_LPM_ENABLED 0U +/*---------- -----------*/ +#define USBD_SELF_POWERED 1U +/*---------- -----------*/ + +/****************************************/ +/* #define for FS and HS identification */ +#define DEVICE_FS 0 +#define DEVICE_HS 1 + +/* Memory management macros */ + +/** Alias for memory allocation. */ +#define USBD_malloc malloc + +/** Alias for memory release. */ +#define USBD_free free + +/** Alias for memory set. */ +#define USBD_memset memset + +/** Alias for memory copy. */ +#define USBD_memcpy memcpy + +/** Alias for delay. */ +#define USBD_Delay HAL_Delay + +/* DEBUG macros */ + +#if (USBD_DEBUG_LEVEL > 0) +#define USBD_UsrLog(...) \ + printf(__VA_ARGS__); \ + printf("\n"); +#else +#define USBD_UsrLog(...) +#endif + +#if (USBD_DEBUG_LEVEL > 1) + +#define USBD_ErrLog(...) \ + printf("ERROR: "); \ + printf(__VA_ARGS__); \ + printf("\n"); +#else +#define USBD_ErrLog(...) +#endif + +#if (USBD_DEBUG_LEVEL > 2) +#define USBD_DbgLog(...) \ + printf("DEBUG : "); \ + printf(__VA_ARGS__); \ + printf("\n"); +#else +#define USBD_DbgLog(...) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* __USBD_CONF__H__ */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/USB_AL94/usbd_core.c b/common/USB_AL94/usbd_core.c new file mode 100644 index 0000000..c3defa9 --- /dev/null +++ b/common/USB_AL94/usbd_core.c @@ -0,0 +1,517 @@ +/** + ****************************************************************************** + * @file usbd_core.c + * @author MCD Application Team + * @brief This file provides all the USBD core functions. + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2015 STMicroelectronics. + * All rights reserved.

+ * + * 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 + * + ****************************************************************************** + */ + +#include "usbd_core.h" + +/** + * @brief USBD_Init + * Initializes the device stack and load the class driver + * @param pdev: device instance + * @param pdesc: Descriptor structure address + * @param id: Low level core index + * @retval None + */ +USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef * pdev, USBD_DescriptorsTypeDef * pdesc, uint8_t id) +{ + USBD_StatusTypeDef ret; + + /* Check whether the USB Host handle is valid */ + if (pdev == NULL) { +#if (USBD_DEBUG_LEVEL > 1U) + USBD_ErrLog("Invalid Device handle"); +#endif + return USBD_FAIL; + } + + /* Unlink previous class resources */ + pdev->pClass = NULL; + pdev->pConfDesc = NULL; + + /* Assign USBD Descriptors */ + if (pdesc != NULL) { pdev->pDesc = pdesc; } + + /* Set Device initial State */ + pdev->dev_state = USBD_STATE_DEFAULT; + pdev->id = id; + + /* Initialize low level driver */ + ret = USBD_LL_Init(pdev); + + return ret; +} + +/** + * @brief USBD_DeInit + * Re-Initialize the device library + * @param pdev: device instance + * @retval status: status + */ +USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef * pdev) +{ + USBD_StatusTypeDef ret; + + /* Disconnect the USB Device */ + (void) USBD_LL_Stop(pdev); + + /* Set Default State */ + pdev->dev_state = USBD_STATE_DEFAULT; + + /* Free Class Resources */ + if (pdev->pClass != NULL) { + pdev->pClass->DeInit(pdev, (uint8_t) pdev->dev_config); + pdev->pClass = NULL; + } + + /* Free Device descriptors resources */ + pdev->pDesc = NULL; + pdev->pConfDesc = NULL; + + /* DeInitialize low level driver */ + ret = USBD_LL_DeInit(pdev); + + return ret; +} + +/** + * @brief USBD_RegisterClass + * Link class driver to Device Core. + * @param pDevice : Device Handle + * @param pclass: Class handle + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef * pdev, USBD_ClassTypeDef * pclass) +{ + uint16_t len = 0U; + + if (pclass == NULL) { +#if (USBD_DEBUG_LEVEL > 1U) + USBD_ErrLog("Invalid Class handle"); +#endif + return USBD_FAIL; + } + + /* link the class to the USB Device handle */ + pdev->pClass = pclass; + + /* Get Device Configuration Descriptor */ + if (pdev->dev_speed == USBD_SPEED_HIGH) { + if (pdev->pClass->GetHSConfigDescriptor != NULL) { + pdev->pConfDesc = (void *) pdev->pClass->GetHSConfigDescriptor(&len); + } + } else if (pdev->pClass->GetFSConfigDescriptor != NULL) { + pdev->pConfDesc = (void *) pdev->pClass->GetFSConfigDescriptor(&len); + } + + return USBD_OK; +} + +/** + * @brief USBD_Start + * Start the USB Device Core. + * @param pdev: Device Handle + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef * pdev) +{ + /* Start the low level driver */ + return USBD_LL_Start(pdev); +} + +/** + * @brief USBD_Stop + * Stop the USB Device Core. + * @param pdev: Device Handle + * @retval USBD Status + */ +USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef * pdev) +{ + /* Disconnect USB Device */ + (void) USBD_LL_Stop(pdev); + + /* Free Class Resources */ + if (pdev->pClass != NULL) { (void) pdev->pClass->DeInit(pdev, (uint8_t) pdev->dev_config); } + + return USBD_OK; +} + +/** + * @brief USBD_RunTestMode + * Launch test mode process + * @param pdev: device instance + * @retval status + */ +USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef * pdev) +{ + /* Prevent unused argument compilation warning */ + UNUSED(pdev); + + return USBD_OK; +} + +/** + * @brief USBD_SetClassConfig + * Configure device and start the interface + * @param pdev: device instance + * @param cfgidx: configuration index + * @retval status + */ + +USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef * pdev, uint8_t cfgidx) +{ + USBD_StatusTypeDef ret = USBD_FAIL; + + if (pdev->pClass != NULL) { + /* Set configuration and Start the Class */ + ret = (USBD_StatusTypeDef) pdev->pClass->Init(pdev, cfgidx); + } + + return ret; +} + +/** + * @brief USBD_ClrClassConfig + * Clear current configuration + * @param pdev: device instance + * @param cfgidx: configuration index + * @retval status: USBD_StatusTypeDef + */ +USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef * pdev, uint8_t cfgidx) +{ + /* Clear configuration and De-initialize the Class process */ + if (pdev->pClass != NULL) { pdev->pClass->DeInit(pdev, cfgidx); } + + return USBD_OK; +} + +/** + * @brief USBD_LL_SetupStage + * Handle the setup stage + * @param pdev: device instance + * @retval status + */ +USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef * pdev, uint8_t * psetup) +{ + USBD_StatusTypeDef ret; + + USBD_ParseSetupRequest(&pdev->request, psetup); + + pdev->ep0_state = USBD_EP0_SETUP; + + pdev->ep0_data_len = pdev->request.wLength; + + switch (pdev->request.bmRequest & 0x1FU) { + case USB_REQ_RECIPIENT_DEVICE: + ret = USBD_StdDevReq(pdev, &pdev->request); + break; + + case USB_REQ_RECIPIENT_INTERFACE: + ret = USBD_StdItfReq(pdev, &pdev->request); + break; + + case USB_REQ_RECIPIENT_ENDPOINT: + ret = USBD_StdEPReq(pdev, &pdev->request); + break; + + default: + ret = USBD_LL_StallEP(pdev, (pdev->request.bmRequest & 0x80U)); + break; + } + + return ret; +} + +/** + * @brief USBD_LL_DataOutStage + * Handle data OUT stage + * @param pdev: device instance + * @param epnum: endpoint index + * @param pdata: data pointer + * @retval status + */ +USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef * pdev, uint8_t epnum, uint8_t * pdata) +{ + USBD_EndpointTypeDef * pep; + USBD_StatusTypeDef ret; + + if (epnum == 0U) { + pep = &pdev->ep_out[0]; + + if (pdev->ep0_state == USBD_EP0_DATA_OUT) { + if (pep->rem_length > pep->maxpacket) { + pep->rem_length -= pep->maxpacket; + + (void) USBD_CtlContinueRx(pdev, pdata, MIN(pep->rem_length, pep->maxpacket)); + } else { + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + if (pdev->pClass->EP0_RxReady != NULL) { pdev->pClass->EP0_RxReady(pdev); } + } + + (void) USBD_CtlSendStatus(pdev); + } + } else { +#if 0 + if (pdev->ep0_state == USBD_EP0_STATUS_OUT) + { + /* + * STATUS PHASE completed, update ep0_state to idle + */ + pdev->ep0_state = USBD_EP0_IDLE; + (void)USBD_LL_StallEP(pdev, 0U); + } +#endif + } + } else { + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + if (pdev->pClass->DataOut != NULL) { + ret = (USBD_StatusTypeDef) pdev->pClass->DataOut(pdev, epnum); + + if (ret != USBD_OK) { return ret; } + } + } + } + + return USBD_OK; +} + +/** + * @brief USBD_LL_DataInStage + * Handle data in stage + * @param pdev: device instance + * @param epnum: endpoint index + * @retval status + */ +USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef * pdev, uint8_t epnum, uint8_t * pdata) +{ + USBD_EndpointTypeDef * pep; + USBD_StatusTypeDef ret; + + if (epnum == 0U) { + pep = &pdev->ep_in[0]; + + if (pdev->ep0_state == USBD_EP0_DATA_IN) { + if (pep->rem_length > pep->maxpacket) { + pep->rem_length -= pep->maxpacket; + + (void) USBD_CtlContinueSendData(pdev, pdata, pep->rem_length); + + /* Prepare endpoint for premature end of transfer */ + (void) USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U); + } else { + /* last packet is MPS multiple, so send ZLP packet */ + if ((pep->maxpacket == pep->rem_length) && (pep->total_length >= pep->maxpacket) + && (pep->total_length < pdev->ep0_data_len)) { + (void) USBD_CtlContinueSendData(pdev, NULL, 0U); + pdev->ep0_data_len = 0U; + + /* Prepare endpoint for premature end of transfer */ + (void) USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U); + } else { + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + if (pdev->pClass->EP0_TxSent != NULL) { pdev->pClass->EP0_TxSent(pdev); } + } + (void) USBD_LL_StallEP(pdev, 0x80U); + (void) USBD_CtlReceiveStatus(pdev); + } + } + } else { +#if 0 + if ((pdev->ep0_state == USBD_EP0_STATUS_IN) || + (pdev->ep0_state == USBD_EP0_IDLE)) + { + (void)USBD_LL_StallEP(pdev, 0x80U); + } +#endif + } + + if (pdev->dev_test_mode == 1U) { + (void) USBD_RunTestMode(pdev); + pdev->dev_test_mode = 0U; + } + } else { + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + if (pdev->pClass->DataIn != NULL) { + ret = (USBD_StatusTypeDef) pdev->pClass->DataIn(pdev, epnum); + + if (ret != USBD_OK) { return ret; } + } + } + } + + return USBD_OK; +} + +/** + * @brief USBD_LL_Reset + * Handle Reset event + * @param pdev: device instance + * @retval status + */ + +USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef * pdev) +{ + /* Upon Reset call user call back */ + pdev->dev_state = USBD_STATE_DEFAULT; + pdev->ep0_state = USBD_EP0_IDLE; + pdev->dev_config = 0U; + pdev->dev_remote_wakeup = 0U; + + if (pdev->pClass == NULL) { return USBD_FAIL; } + + if (pdev->pClass->DeInit != NULL) { (void) pdev->pClass->DeInit(pdev, (uint8_t) pdev->dev_config); } + + /* Open EP0 OUT */ + (void) USBD_LL_OpenEP(pdev, 0x00U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE); + pdev->ep_out[0x00U & 0xFU].is_used = 1U; + + pdev->ep_out[0].maxpacket = USB_MAX_EP0_SIZE; + + /* Open EP0 IN */ + (void) USBD_LL_OpenEP(pdev, 0x80U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE); + pdev->ep_in[0x80U & 0xFU].is_used = 1U; + + pdev->ep_in[0].maxpacket = USB_MAX_EP0_SIZE; + + return USBD_OK; +} + +/** + * @brief USBD_LL_SetSpeed + * Handle Reset event + * @param pdev: device instance + * @retval status + */ +USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef * pdev, USBD_SpeedTypeDef speed) +{ + pdev->dev_speed = speed; + + return USBD_OK; +} + +/** + * @brief USBD_LL_Suspend + * Handle Suspend event + * @param pdev: device instance + * @retval status + */ + +USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef * pdev) +{ + pdev->dev_old_state = pdev->dev_state; + pdev->dev_state = USBD_STATE_SUSPENDED; + + return USBD_OK; +} + +/** + * @brief USBD_LL_Resume + * Handle Resume event + * @param pdev: device instance + * @retval status + */ + +USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef * pdev) +{ + if (pdev->dev_state == USBD_STATE_SUSPENDED) { pdev->dev_state = pdev->dev_old_state; } + + return USBD_OK; +} + +/** + * @brief USBD_LL_SOF + * Handle SOF event + * @param pdev: device instance + * @retval status + */ + +USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef * pdev) +{ + if (pdev->pClass == NULL) { return USBD_FAIL; } + + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + if (pdev->pClass->SOF != NULL) { (void) pdev->pClass->SOF(pdev); } + } + + return USBD_OK; +} + +/** + * @brief USBD_LL_IsoINIncomplete + * Handle iso in incomplete event + * @param pdev: device instance + * @retval status + */ +USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef * pdev, uint8_t epnum) +{ + if (pdev->pClass == NULL) { return USBD_FAIL; } + + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + if (pdev->pClass->IsoINIncomplete != NULL) { (void) pdev->pClass->IsoINIncomplete(pdev, epnum); } + } + + return USBD_OK; +} + +/** + * @brief USBD_LL_IsoOUTIncomplete + * Handle iso out incomplete event + * @param pdev: device instance + * @retval status + */ +USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef * pdev, uint8_t epnum) +{ + if (pdev->pClass == NULL) { return USBD_FAIL; } + + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + if (pdev->pClass->IsoOUTIncomplete != NULL) { (void) pdev->pClass->IsoOUTIncomplete(pdev, epnum); } + } + + return USBD_OK; +} + +/** + * @brief USBD_LL_DevConnected + * Handle device connection event + * @param pdev: device instance + * @retval status + */ +USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef * pdev) +{ + /* Prevent unused argument compilation warning */ + UNUSED(pdev); + + return USBD_OK; +} + +/** + * @brief USBD_LL_DevDisconnected + * Handle device disconnection event + * @param pdev: device instance + * @retval status + */ +USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef * pdev) +{ + /* Free Class Resources */ + pdev->dev_state = USBD_STATE_DEFAULT; + + if (pdev->pClass != NULL) { (void) pdev->pClass->DeInit(pdev, (uint8_t) pdev->dev_config); } + + return USBD_OK; +} + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/USB_AL94/usbd_core.h b/common/USB_AL94/usbd_core.h new file mode 100644 index 0000000..e46d6ed --- /dev/null +++ b/common/USB_AL94/usbd_core.h @@ -0,0 +1,93 @@ +/** + ****************************************************************************** + * @file usbd_core.h + * @author MCD Application Team + * @brief Header file for usbd_core.c file + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2015 STMicroelectronics. + * All rights reserved.

+ * + * 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 + * + ****************************************************************************** + */ + +#ifndef __USBD_CORE_H +#define __USBD_CORE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "usbd_conf.h" +#include "usbd_ctlreq.h" +#include "usbd_def.h" +#include "usbd_ioreq.h" + +#ifndef USBD_DEBUG_LEVEL +#define USBD_DEBUG_LEVEL 0U +#endif /* USBD_DEBUG_LEVEL */ + +#define USBD_SOF USBD_LL_SOF + +USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef * pdev, USBD_DescriptorsTypeDef * pdesc, uint8_t id); +USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef * pdev); +USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef * pdev); +USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef * pdev); +USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef * pdev, USBD_ClassTypeDef * pclass); + +USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef * pdev); +USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef * pdev, uint8_t cfgidx); +USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef * pdev, uint8_t cfgidx); + +USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef * pdev, uint8_t * psetup); +USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef * pdev, uint8_t epnum, uint8_t * pdata); +USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef * pdev, uint8_t epnum, uint8_t * pdata); + +USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef * pdev); +USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef * pdev, USBD_SpeedTypeDef speed); +USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef * pdev); +USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef * pdev); + +USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef * pdev); +USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef * pdev, uint8_t epnum); +USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef * pdev, uint8_t epnum); + +USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef * pdev); +USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef * pdev); + +/* USBD Low Level Driver */ +USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef * pdev); +USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef * pdev); +USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef * pdev); +USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef * pdev); + +USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef * pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps); + +USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef * pdev, uint8_t ep_addr); +USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef * pdev, uint8_t ep_addr); +USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef * pdev, uint8_t ep_addr); +USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef * pdev, uint8_t ep_addr); +USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef * pdev, uint8_t dev_addr); + +USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef * pdev, uint8_t ep_addr, uint8_t * pbuf, uint32_t size); + +USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef * pdev, uint8_t ep_addr, uint8_t * pbuf, uint32_t size); + +uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef * pdev, uint8_t ep_addr); +uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef * pdev, uint8_t ep_addr); + +void USBD_LL_Delay(uint32_t Delay); + +#ifdef __cplusplus +} +#endif + +#endif /* __USBD_CORE_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/USB_AL94/usbd_ctlreq.c b/common/USB_AL94/usbd_ctlreq.c new file mode 100644 index 0000000..ead1742 --- /dev/null +++ b/common/USB_AL94/usbd_ctlreq.c @@ -0,0 +1,801 @@ +/** + ****************************************************************************** + * @file usbd_req.c + * @author MCD Application Team + * @brief This file provides the standard USB requests following chapter 9. + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2015 STMicroelectronics. + * All rights reserved.

+ * + * 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 "usbd_ctlreq.h" +#include "usbd_ioreq.h" + +/** @addtogroup STM32_USBD_STATE_DEVICE_LIBRARY + * @{ + */ + +/** @defgroup USBD_REQ + * @brief USB standard requests module + * @{ + */ + +/** @defgroup USBD_REQ_Private_TypesDefinitions + * @{ + */ + +/** + * @} + */ + +/** @defgroup USBD_REQ_Private_Defines + * @{ + */ + +/** + * @} + */ + +/** @defgroup USBD_REQ_Private_Macros + * @{ + */ + +/** + * @} + */ + +/** @defgroup USBD_REQ_Private_Variables + * @{ + */ + +/** + * @} + */ + +/** @defgroup USBD_REQ_Private_FunctionPrototypes + * @{ + */ +static void USBD_GetDescriptor(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req); +static void USBD_SetAddress(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req); +static USBD_StatusTypeDef USBD_SetConfig(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req); +static void USBD_GetConfig(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req); +static void USBD_GetStatus(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req); +static void USBD_SetFeature(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req); +static void USBD_ClrFeature(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req); +static uint8_t USBD_GetLen(uint8_t * buf); + +/** + * @} + */ + +/** @defgroup USBD_REQ_Private_Functions + * @{ + */ + +/** + * @brief USBD_StdDevReq + * Handle standard usb device requests + * @param pdev: device instance + * @param req: usb request + * @retval status + */ +USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req) +{ + USBD_StatusTypeDef ret = USBD_OK; + + switch (req->bmRequest & USB_REQ_TYPE_MASK) { + case USB_REQ_TYPE_CLASS: + case USB_REQ_TYPE_VENDOR: + ret = (USBD_StatusTypeDef) pdev->pClass->Setup(pdev, req); + break; + + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) { + case USB_REQ_GET_DESCRIPTOR: + USBD_GetDescriptor(pdev, req); + break; + + case USB_REQ_SET_ADDRESS: + USBD_SetAddress(pdev, req); + break; + + case USB_REQ_SET_CONFIGURATION: + ret = USBD_SetConfig(pdev, req); + break; + + case USB_REQ_GET_CONFIGURATION: + USBD_GetConfig(pdev, req); + break; + + case USB_REQ_GET_STATUS: + USBD_GetStatus(pdev, req); + break; + + case USB_REQ_SET_FEATURE: + USBD_SetFeature(pdev, req); + break; + + case USB_REQ_CLEAR_FEATURE: + USBD_ClrFeature(pdev, req); + break; + + default: + USBD_CtlError(pdev, req); + break; + } + break; + + default: + USBD_CtlError(pdev, req); + break; + } + + return ret; +} + +/** + * @brief USBD_StdItfReq + * Handle standard usb interface requests + * @param pdev: device instance + * @param req: usb request + * @retval status + */ +USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req) +{ + USBD_StatusTypeDef ret = USBD_OK; + + switch (req->bmRequest & USB_REQ_TYPE_MASK) { + case USB_REQ_TYPE_CLASS: + case USB_REQ_TYPE_VENDOR: + case USB_REQ_TYPE_STANDARD: + switch (pdev->dev_state) { + case USBD_STATE_DEFAULT: + case USBD_STATE_ADDRESSED: + case USBD_STATE_CONFIGURED: + + if (LOBYTE(req->wIndex) <= USBD_MAX_NUM_INTERFACES) { + ret = (USBD_StatusTypeDef) pdev->pClass->Setup(pdev, req); + + if ((req->wLength == 0U) && (ret == USBD_OK)) { (void) USBD_CtlSendStatus(pdev); } + } else { + USBD_CtlError(pdev, req); + } + break; + + default: + USBD_CtlError(pdev, req); + break; + } + break; + + default: + USBD_CtlError(pdev, req); + break; + } + + return ret; +} + +/** + * @brief USBD_StdEPReq + * Handle standard usb endpoint requests + * @param pdev: device instance + * @param req: usb request + * @retval status + */ +USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req) +{ + USBD_EndpointTypeDef * pep; + uint8_t ep_addr; + USBD_StatusTypeDef ret = USBD_OK; + ep_addr = LOBYTE(req->wIndex); + + switch (req->bmRequest & USB_REQ_TYPE_MASK) { + case USB_REQ_TYPE_CLASS: + case USB_REQ_TYPE_VENDOR: + ret = (USBD_StatusTypeDef) pdev->pClass->Setup(pdev, req); + break; + + case USB_REQ_TYPE_STANDARD: + switch (req->bRequest) { + case USB_REQ_SET_FEATURE: + switch (pdev->dev_state) { + case USBD_STATE_ADDRESSED: + if ((ep_addr != 0x00U) && (ep_addr != 0x80U)) { + (void) USBD_LL_StallEP(pdev, ep_addr); + (void) USBD_LL_StallEP(pdev, 0x80U); + } else { + USBD_CtlError(pdev, req); + } + break; + + case USBD_STATE_CONFIGURED: + if (req->wValue == USB_FEATURE_EP_HALT) { + if ((ep_addr != 0x00U) && (ep_addr != 0x80U) && (req->wLength == 0x00U)) { + (void) USBD_LL_StallEP(pdev, ep_addr); + } + } + (void) USBD_CtlSendStatus(pdev); + + break; + + default: + USBD_CtlError(pdev, req); + break; + } + break; + + case USB_REQ_CLEAR_FEATURE: + + switch (pdev->dev_state) { + case USBD_STATE_ADDRESSED: + if ((ep_addr != 0x00U) && (ep_addr != 0x80U)) { + (void) USBD_LL_StallEP(pdev, ep_addr); + (void) USBD_LL_StallEP(pdev, 0x80U); + } else { + USBD_CtlError(pdev, req); + } + break; + + case USBD_STATE_CONFIGURED: + if (req->wValue == USB_FEATURE_EP_HALT) { + if ((ep_addr & 0x7FU) != 0x00U) { (void) USBD_LL_ClearStallEP(pdev, ep_addr); } + (void) USBD_CtlSendStatus(pdev); + ret = (USBD_StatusTypeDef) pdev->pClass->Setup(pdev, req); + } + break; + + default: + USBD_CtlError(pdev, req); + break; + } + break; + + case USB_REQ_GET_STATUS: + switch (pdev->dev_state) { + case USBD_STATE_ADDRESSED: + if ((ep_addr != 0x00U) && (ep_addr != 0x80U)) { + USBD_CtlError(pdev, req); + break; + } + pep = ((ep_addr & 0x80U) == 0x80U) ? &pdev->ep_in[ep_addr & 0x7FU] : &pdev->ep_out[ep_addr & 0x7FU]; + + pep->status = 0x0000U; + + (void) USBD_CtlSendData(pdev, (uint8_t *) &pep->status, 2U); + break; + + case USBD_STATE_CONFIGURED: + if ((ep_addr & 0x80U) == 0x80U) { + if (pdev->ep_in[ep_addr & 0xFU].is_used == 0U) { + USBD_CtlError(pdev, req); + break; + } + } else { + if (pdev->ep_out[ep_addr & 0xFU].is_used == 0U) { + USBD_CtlError(pdev, req); + break; + } + } + + pep = ((ep_addr & 0x80U) == 0x80U) ? &pdev->ep_in[ep_addr & 0x7FU] : &pdev->ep_out[ep_addr & 0x7FU]; + + if ((ep_addr == 0x00U) || (ep_addr == 0x80U)) { + pep->status = 0x0000U; + } else if (USBD_LL_IsStallEP(pdev, ep_addr) != 0U) { + pep->status = 0x0001U; + } else { + pep->status = 0x0000U; + } + + (void) USBD_CtlSendData(pdev, (uint8_t *) &pep->status, 2U); + break; + + default: + USBD_CtlError(pdev, req); + break; + } + break; + + default: + USBD_CtlError(pdev, req); + break; + } + break; + + default: + USBD_CtlError(pdev, req); + break; + } + + return ret; +} + +/** + * @brief USBD_GetDescriptor + * Handle Get Descriptor requests + * @param pdev: device instance + * @param req: usb request + * @retval status + */ +static void USBD_GetDescriptor(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req) +{ + uint16_t len = 0U; + uint8_t * pbuf = NULL; + uint8_t err = 0U; + + switch (req->wValue >> 8) { +#if ((USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1U)) + case USB_DESC_TYPE_BOS: + if (pdev->pDesc->GetBOSDescriptor != NULL) { + pbuf = pdev->pDesc->GetBOSDescriptor(pdev->dev_speed, &len); + } else { + USBD_CtlError(pdev, req); + err++; + } + break; +#endif + case USB_DESC_TYPE_DEVICE: + pbuf = pdev->pDesc->GetDeviceDescriptor(pdev->dev_speed, &len); + break; + + case USB_DESC_TYPE_CONFIGURATION: + if (pdev->dev_speed == USBD_SPEED_HIGH) { + pbuf = pdev->pClass->GetHSConfigDescriptor(&len); + pbuf[1] = USB_DESC_TYPE_CONFIGURATION; + } else { + pbuf = pdev->pClass->GetFSConfigDescriptor(&len); + pbuf[1] = USB_DESC_TYPE_CONFIGURATION; + } + break; + + case USB_DESC_TYPE_STRING: + switch ((uint8_t) (req->wValue)) { + case USBD_IDX_LANGID_STR: + if (pdev->pDesc->GetLangIDStrDescriptor != NULL) { + pbuf = pdev->pDesc->GetLangIDStrDescriptor(pdev->dev_speed, &len); + } else { + USBD_CtlError(pdev, req); + err++; + } + break; + + case USBD_IDX_MFC_STR: + if (pdev->pDesc->GetManufacturerStrDescriptor != NULL) { + pbuf = pdev->pDesc->GetManufacturerStrDescriptor(pdev->dev_speed, &len); + } else { + USBD_CtlError(pdev, req); + err++; + } + break; + + case USBD_IDX_PRODUCT_STR: + if (pdev->pDesc->GetProductStrDescriptor != NULL) { + pbuf = pdev->pDesc->GetProductStrDescriptor(pdev->dev_speed, &len); + } else { + USBD_CtlError(pdev, req); + err++; + } + break; + + case USBD_IDX_SERIAL_STR: + if (pdev->pDesc->GetSerialStrDescriptor != NULL) { + pbuf = pdev->pDesc->GetSerialStrDescriptor(pdev->dev_speed, &len); + } else { + USBD_CtlError(pdev, req); + err++; + } + break; + + case USBD_IDX_CONFIG_STR: + if (pdev->pDesc->GetConfigurationStrDescriptor != NULL) { + pbuf = pdev->pDesc->GetConfigurationStrDescriptor(pdev->dev_speed, &len); + } else { + USBD_CtlError(pdev, req); + err++; + } + break; + + case USBD_IDX_INTERFACE_STR: + if (pdev->pDesc->GetInterfaceStrDescriptor != NULL) { + pbuf = pdev->pDesc->GetInterfaceStrDescriptor(pdev->dev_speed, &len); + } else { + USBD_CtlError(pdev, req); + err++; + } + break; + + default: +#if (USBD_SUPPORT_USER_STRING_DESC == 1U) + if (pdev->pClass->GetUsrStrDescriptor != NULL) { + pbuf = pdev->pClass->GetUsrStrDescriptor(pdev, (req->wValue), &len); + } else { + USBD_CtlError(pdev, req); + err++; + } +#endif + +#if (USBD_CLASS_USER_STRING_DESC == 1U) + if (pdev->pDesc->GetUserStrDescriptor != NULL) { + pbuf = pdev->pDesc->GetUserStrDescriptor(pdev->dev_speed, (req->wValue), &len); + } else { + USBD_CtlError(pdev, req); + err++; + } +#endif + +#if ((USBD_CLASS_USER_STRING_DESC == 0U) && (USBD_SUPPORT_USER_STRING_DESC == 0U)) + USBD_CtlError(pdev, req); + err++; +#endif + break; + } + break; + + case USB_DESC_TYPE_DEVICE_QUALIFIER: + if (pdev->dev_speed == USBD_SPEED_HIGH) { + pbuf = pdev->pClass->GetDeviceQualifierDescriptor(&len); + } else { + USBD_CtlError(pdev, req); + err++; + } + break; + + case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION: + if (pdev->dev_speed == USBD_SPEED_HIGH) { + pbuf = pdev->pClass->GetOtherSpeedConfigDescriptor(&len); + pbuf[1] = USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION; + } else { + USBD_CtlError(pdev, req); + err++; + } + break; + + default: + USBD_CtlError(pdev, req); + err++; + break; + } + + if (err != 0U) { return; } + + if (req->wLength != 0U) { + if (len != 0U) { + len = MIN(len, req->wLength); + (void) USBD_CtlSendData(pdev, pbuf, len); + } else { + USBD_CtlError(pdev, req); + } + } else { + (void) USBD_CtlSendStatus(pdev); + } +} + +/** + * @brief USBD_SetAddress + * Set device address + * @param pdev: device instance + * @param req: usb request + * @retval status + */ +static void USBD_SetAddress(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req) +{ + uint8_t dev_addr; + + if ((req->wIndex == 0U) && (req->wLength == 0U) && (req->wValue < 128U)) { + dev_addr = (uint8_t) (req->wValue) & 0x7FU; + + if (pdev->dev_state == USBD_STATE_CONFIGURED) { + USBD_CtlError(pdev, req); + } else { + pdev->dev_address = dev_addr; + (void) USBD_LL_SetUSBAddress(pdev, dev_addr); + (void) USBD_CtlSendStatus(pdev); + + if (dev_addr != 0U) { + pdev->dev_state = USBD_STATE_ADDRESSED; + } else { + pdev->dev_state = USBD_STATE_DEFAULT; + } + } + } else { + USBD_CtlError(pdev, req); + } +} + +/** + * @brief USBD_SetConfig + * Handle Set device configuration request + * @param pdev: device instance + * @param req: usb request + * @retval status + */ +static USBD_StatusTypeDef USBD_SetConfig(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req) +{ + USBD_StatusTypeDef ret = USBD_OK; + static uint8_t cfgidx; + + cfgidx = (uint8_t) (req->wValue); + + if (cfgidx > USBD_MAX_NUM_CONFIGURATION) { + USBD_CtlError(pdev, req); + return USBD_FAIL; + } + + switch (pdev->dev_state) { + case USBD_STATE_ADDRESSED: + if (cfgidx != 0U) { + pdev->dev_config = cfgidx; + + ret = USBD_SetClassConfig(pdev, cfgidx); + + if (ret != USBD_OK) { + USBD_CtlError(pdev, req); + } else { + (void) USBD_CtlSendStatus(pdev); + pdev->dev_state = USBD_STATE_CONFIGURED; + } + } else { + (void) USBD_CtlSendStatus(pdev); + } + break; + + case USBD_STATE_CONFIGURED: + if (cfgidx == 0U) { + pdev->dev_state = USBD_STATE_ADDRESSED; + pdev->dev_config = cfgidx; + (void) USBD_ClrClassConfig(pdev, cfgidx); + (void) USBD_CtlSendStatus(pdev); + } else if (cfgidx != pdev->dev_config) { + /* Clear old configuration */ + (void) USBD_ClrClassConfig(pdev, (uint8_t) pdev->dev_config); + + /* set new configuration */ + pdev->dev_config = cfgidx; + + ret = USBD_SetClassConfig(pdev, cfgidx); + + if (ret != USBD_OK) { + USBD_CtlError(pdev, req); + (void) USBD_ClrClassConfig(pdev, (uint8_t) pdev->dev_config); + pdev->dev_state = USBD_STATE_ADDRESSED; + } else { + (void) USBD_CtlSendStatus(pdev); + } + } else { + (void) USBD_CtlSendStatus(pdev); + } + break; + + default: + USBD_CtlError(pdev, req); + (void) USBD_ClrClassConfig(pdev, cfgidx); + ret = USBD_FAIL; + break; + } + + return ret; +} + +/** + * @brief USBD_GetConfig + * Handle Get device configuration request + * @param pdev: device instance + * @param req: usb request + * @retval status + */ +static void USBD_GetConfig(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req) +{ + if (req->wLength != 1U) { + USBD_CtlError(pdev, req); + } else { + switch (pdev->dev_state) { + case USBD_STATE_DEFAULT: + case USBD_STATE_ADDRESSED: + pdev->dev_default_config = 0U; + (void) USBD_CtlSendData(pdev, (uint8_t *) &pdev->dev_default_config, 1U); + break; + + case USBD_STATE_CONFIGURED: + (void) USBD_CtlSendData(pdev, (uint8_t *) &pdev->dev_config, 1U); + break; + + default: + USBD_CtlError(pdev, req); + break; + } + } +} + +/** + * @brief USBD_GetStatus + * Handle Get Status request + * @param pdev: device instance + * @param req: usb request + * @retval status + */ +static void USBD_GetStatus(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req) +{ + switch (pdev->dev_state) { + case USBD_STATE_DEFAULT: + case USBD_STATE_ADDRESSED: + case USBD_STATE_CONFIGURED: + if (req->wLength != 0x2U) { + USBD_CtlError(pdev, req); + break; + } + +#if (USBD_SELF_POWERED == 1U) + pdev->dev_config_status = USB_CONFIG_SELF_POWERED; +#else + pdev->dev_config_status = 0U; +#endif + + if (pdev->dev_remote_wakeup != 0U) { pdev->dev_config_status |= USB_CONFIG_REMOTE_WAKEUP; } + + (void) USBD_CtlSendData(pdev, (uint8_t *) &pdev->dev_config_status, 2U); + break; + + default: + USBD_CtlError(pdev, req); + break; + } +} + +/** + * @brief USBD_SetFeature + * Handle Set device feature request + * @param pdev: device instance + * @param req: usb request + * @retval status + */ +static void USBD_SetFeature(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req) +{ + if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) { + pdev->dev_remote_wakeup = 1U; + (void) USBD_CtlSendStatus(pdev); + } +} + +/** + * @brief USBD_ClrFeature + * Handle clear device feature request + * @param pdev: device instance + * @param req: usb request + * @retval status + */ +static void USBD_ClrFeature(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req) +{ + switch (pdev->dev_state) { + case USBD_STATE_DEFAULT: + case USBD_STATE_ADDRESSED: + case USBD_STATE_CONFIGURED: + if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) { + pdev->dev_remote_wakeup = 0U; + (void) USBD_CtlSendStatus(pdev); + } + break; + + default: + USBD_CtlError(pdev, req); + break; + } +} + +/** + * @brief USBD_ParseSetupRequest + * Copy buffer into setup structure + * @param pdev: device instance + * @param req: usb request + * @retval None + */ +void USBD_ParseSetupRequest(USBD_SetupReqTypedef * req, uint8_t * pdata) +{ + uint8_t * pbuff = pdata; + + req->bmRequest = *(uint8_t *) (pbuff); + + pbuff++; + req->bRequest = *(uint8_t *) (pbuff); + + pbuff++; + req->wValue = SWAPBYTE(pbuff); + + pbuff++; + pbuff++; + req->wIndex = SWAPBYTE(pbuff); + + pbuff++; + pbuff++; + req->wLength = SWAPBYTE(pbuff); +} + +/** + * @brief USBD_CtlError + * Handle USB low level Error + * @param pdev: device instance + * @param req: usb request + * @retval None + */ +void USBD_CtlError(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req) +{ + UNUSED(req); + + (void) USBD_LL_StallEP(pdev, 0x80U); + (void) USBD_LL_StallEP(pdev, 0U); +} + +/** + * @brief USBD_GetString + * Convert Ascii string into unicode one + * @param desc : descriptor buffer + * @param unicode : Formatted string buffer (unicode) + * @param len : descriptor length + * @retval None + */ +void USBD_GetString(uint8_t * desc, uint8_t * unicode, uint16_t * len) +{ + uint8_t idx = 0U; + uint8_t * pdesc; + + if (desc == NULL) { return; } + + pdesc = desc; + *len = ((uint16_t) USBD_GetLen(pdesc) * 2U) + 2U; + + unicode[idx] = *(uint8_t *) len; + idx++; + unicode[idx] = USB_DESC_TYPE_STRING; + idx++; + + while (*pdesc != (uint8_t) '\0') { + unicode[idx] = *pdesc; + pdesc++; + idx++; + + unicode[idx] = 0U; + idx++; + } +} + +/** + * @brief USBD_GetLen + * return the string length + * @param buf : pointer to the ascii string buffer + * @retval string length + */ +static uint8_t USBD_GetLen(uint8_t * buf) +{ + uint8_t len = 0U; + uint8_t * pbuff = buf; + + while (*pbuff != (uint8_t) '\0') { + len++; + pbuff++; + } + + return len; +} +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/USB_AL94/usbd_ctlreq.h b/common/USB_AL94/usbd_ctlreq.h new file mode 100644 index 0000000..0f37743 --- /dev/null +++ b/common/USB_AL94/usbd_ctlreq.h @@ -0,0 +1,43 @@ +/** + ****************************************************************************** + * @file usbd_req.h + * @author MCD Application Team + * @brief Header file for the usbd_req.c file + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2015 STMicroelectronics. + * All rights reserved.

+ * + * 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 + * + ****************************************************************************** + */ + +#ifndef __USB_REQUEST_H +#define __USB_REQUEST_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "usbd_def.h" + +USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req); +USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req); +USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req); + +void USBD_CtlError(USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req); +void USBD_ParseSetupRequest(USBD_SetupReqTypedef * req, uint8_t * pdata); +void USBD_GetString(uint8_t * desc, uint8_t * unicode, uint16_t * len); + +#ifdef __cplusplus +} +#endif + +#endif /* __USB_REQUEST_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/USB_AL94/usbd_def.h b/common/USB_AL94/usbd_def.h new file mode 100644 index 0000000..d95f827 --- /dev/null +++ b/common/USB_AL94/usbd_def.h @@ -0,0 +1,385 @@ +/** + ****************************************************************************** + * @file usbd_def.h + * @author MCD Application Team + * @brief General defines for the usb device library + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2015 STMicroelectronics. + * All rights reserved.

+ * + * 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 inclusion -------------------------------------*/ +#ifndef __USBD_DEF_H +#define __USBD_DEF_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "usbd_conf.h" + +#ifndef NULL +#define NULL 0U +#endif /* NULL */ + +#ifndef USBD_MAX_NUM_INTERFACES +#define USBD_MAX_NUM_INTERFACES 1U +#endif /* USBD_MAX_NUM_CONFIGURATION */ + +#ifndef USBD_MAX_NUM_CONFIGURATION +#define USBD_MAX_NUM_CONFIGURATION 1U +#endif /* USBD_MAX_NUM_CONFIGURATION */ + +#ifndef USBD_LPM_ENABLED +#define USBD_LPM_ENABLED 0U +#endif /* USBD_LPM_ENABLED */ + +#ifndef USBD_SELF_POWERED +#define USBD_SELF_POWERED 1U +#endif /*USBD_SELF_POWERED */ + +#ifndef USBD_MAX_POWER +#define USBD_MAX_POWER 0x32U /* 100 mA */ +#endif /* USBD_MAX_POWER */ + +#ifndef USBD_SUPPORT_USER_STRING_DESC +#define USBD_SUPPORT_USER_STRING_DESC 0U +#endif /* USBD_SUPPORT_USER_STRING_DESC */ + +#ifndef USBD_CLASS_USER_STRING_DESC +#define USBD_CLASS_USER_STRING_DESC 0U +#endif /* USBD_CLASS_USER_STRING_DESC */ + +#define USB_LEN_DEV_QUALIFIER_DESC 0x0AU +#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_LANGID_STR_DESC 0x04U +#define USB_LEN_OTHER_SPEED_DESC_SIZ 0x09U + +#define USBD_IDX_LANGID_STR 0x00U +#define USBD_IDX_MFC_STR 0x01U +#define USBD_IDX_PRODUCT_STR 0x02U +#define USBD_IDX_SERIAL_STR 0x03U +#define USBD_IDX_CONFIG_STR 0x04U +#define USBD_IDX_INTERFACE_STR 0x05U + +#define USB_REQ_TYPE_STANDARD 0x00U +#define USB_REQ_TYPE_CLASS 0x20U +#define USB_REQ_TYPE_VENDOR 0x40U +#define USB_REQ_TYPE_MASK 0x60U + +#define USB_REQ_RECIPIENT_DEVICE 0x00U +#define USB_REQ_RECIPIENT_INTERFACE 0x01U +#define USB_REQ_RECIPIENT_ENDPOINT 0x02U +#define USB_REQ_RECIPIENT_MASK 0x03U + +#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 + +#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_IAD 0x0BU +#define USB_DESC_TYPE_BOS 0x0FU + +#define USB_CONFIG_REMOTE_WAKEUP 0x02U +#define USB_CONFIG_SELF_POWERED 0x01U + +#define USB_FEATURE_EP_HALT 0x00U +#define USB_FEATURE_REMOTE_WAKEUP 0x01U +#define USB_FEATURE_TEST_MODE 0x02U + +#define USB_DEVICE_CAPABITY_TYPE 0x10U + +#define USB_CONF_DESC_SIZE 0x09U +#define USB_IF_DESC_SIZE 0x09U +#define USB_EP_DESC_SIZE 0x07U +#define USB_IAD_DESC_SIZE 0x08U + +#define USB_HS_MAX_PACKET_SIZE 512U +#define USB_FS_MAX_PACKET_SIZE 64U +#define USB_MAX_EP0_SIZE 64U + +/* Device Status */ +#define USBD_STATE_DEFAULT 0x01U +#define USBD_STATE_ADDRESSED 0x02U +#define USBD_STATE_CONFIGURED 0x03U +#define USBD_STATE_SUSPENDED 0x04U + +/* EP0 State */ +#define USBD_EP0_IDLE 0x00U +#define USBD_EP0_SETUP 0x01U +#define USBD_EP0_DATA_IN 0x02U +#define USBD_EP0_DATA_OUT 0x03U +#define USBD_EP0_STATUS_IN 0x04U +#define USBD_EP0_STATUS_OUT 0x05U +#define USBD_EP0_STALL 0x06U + +#define USBD_EP_TYPE_CTRL 0x00U +#define USBD_EP_TYPE_ISOC 0x01U +#define USBD_EP_TYPE_BULK 0x02U +#define USBD_EP_TYPE_INTR 0x03U + +typedef struct usb_setup_req +{ + uint8_t bmRequest; + uint8_t bRequest; + uint16_t wValue; + uint16_t wIndex; + uint16_t wLength; +} USBD_SetupReqTypedef; + +typedef struct +{ + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t wTotalLength; + uint8_t bNumInterfaces; + uint8_t bConfigurationValue; + uint8_t iConfiguration; + uint8_t bmAttributes; + uint8_t bMaxPower; +} USBD_ConfigDescTypedef; + +typedef struct +{ + uint8_t bLength; + uint8_t bDescriptorType; + uint16_t wTotalLength; + uint8_t bNumDeviceCaps; +} USBD_BosDescTypedef; + +typedef struct +{ + uint8_t bLength; + uint8_t bDescriptorType; + uint8_t bEndpointAddress; + uint8_t bmAttributes; + uint16_t wMaxPacketSize; + uint8_t bInterval; +} USBD_EpDescTypedef; + +struct _USBD_HandleTypeDef; + +typedef struct _Device_cb +{ + uint8_t (*Init)(struct _USBD_HandleTypeDef * pdev, uint8_t cfgidx); + uint8_t (*DeInit)(struct _USBD_HandleTypeDef * pdev, uint8_t cfgidx); + /* Control Endpoints*/ + uint8_t (*Setup)(struct _USBD_HandleTypeDef * pdev, USBD_SetupReqTypedef * req); + uint8_t (*EP0_TxSent)(struct _USBD_HandleTypeDef * pdev); + uint8_t (*EP0_RxReady)(struct _USBD_HandleTypeDef * pdev); + /* Class Specific Endpoints*/ + uint8_t (*DataIn)(struct _USBD_HandleTypeDef * pdev, uint8_t epnum); + uint8_t (*DataOut)(struct _USBD_HandleTypeDef * pdev, uint8_t epnum); + uint8_t (*SOF)(struct _USBD_HandleTypeDef * pdev); + uint8_t (*IsoINIncomplete)(struct _USBD_HandleTypeDef * pdev, uint8_t epnum); + uint8_t (*IsoOUTIncomplete)(struct _USBD_HandleTypeDef * pdev, uint8_t epnum); + + uint8_t * (*GetHSConfigDescriptor)(uint16_t * length); + uint8_t * (*GetFSConfigDescriptor)(uint16_t * length); + uint8_t * (*GetOtherSpeedConfigDescriptor)(uint16_t * length); + uint8_t * (*GetDeviceQualifierDescriptor)(uint16_t * length); +#if (USBD_SUPPORT_USER_STRING_DESC == 1U) + uint8_t * (*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef * pdev, uint8_t index, uint16_t * length); +#endif + +} USBD_ClassTypeDef; + +/* Following USB Device Speed */ +typedef enum +{ + USBD_SPEED_HIGH = 0U, + USBD_SPEED_FULL = 1U, + USBD_SPEED_LOW = 2U, +} USBD_SpeedTypeDef; + +/* Following USB Device status */ +typedef enum +{ + USBD_OK = 0U, + USBD_BUSY, + USBD_EMEM, + USBD_FAIL, +} USBD_StatusTypeDef; + +/* USB Device descriptors structure */ +typedef struct +{ + uint8_t * (*GetDeviceDescriptor)(USBD_SpeedTypeDef speed, uint16_t * length); + uint8_t * (*GetLangIDStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t * length); + uint8_t * (*GetManufacturerStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t * length); + uint8_t * (*GetProductStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t * length); + uint8_t * (*GetSerialStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t * length); + uint8_t * (*GetConfigurationStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t * length); + uint8_t * (*GetInterfaceStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t * length); +#if (USBD_CLASS_USER_STRING_DESC == 1) + uint8_t * (*GetUserStrDescriptor)(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t * length); +#endif +#if ((USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1)) + uint8_t * (*GetBOSDescriptor)(USBD_SpeedTypeDef speed, uint16_t * length); +#endif +} USBD_DescriptorsTypeDef; + +/* USB Device handle structure */ +typedef struct +{ + uint32_t status; + uint32_t total_length; + uint32_t rem_length; + uint32_t maxpacket; + uint16_t is_used; + uint16_t bInterval; +} USBD_EndpointTypeDef; + +/* USB Device handle structure */ +typedef struct _USBD_HandleTypeDef +{ + uint8_t id; + uint32_t dev_config; + uint32_t dev_default_config; + uint32_t dev_config_status; + USBD_SpeedTypeDef dev_speed; + USBD_EndpointTypeDef ep_in[16]; + USBD_EndpointTypeDef ep_out[16]; + __IO uint32_t ep0_state; + uint32_t ep0_data_len; + __IO uint8_t dev_state; + __IO uint8_t dev_old_state; + uint8_t dev_address; + uint8_t dev_connection_status; + uint8_t dev_test_mode; + uint32_t dev_remote_wakeup; + uint8_t ConfIdx; + + USBD_SetupReqTypedef request; + USBD_DescriptorsTypeDef * pDesc; + USBD_ClassTypeDef * pClass; + void * pUserData_CDC_ACM; + void * pClassData_CDC_RNDIS; + void * pUserData_CDC_RNDIS; + void * pClassData_CDC_ECM; + void * pUserData_CDC_ECM; + void * pClassData_HID_Mouse; + void * pClassData_HID_Keyboard; + void * pClassData_HID_Custom; + void * pUserData_HID_Custom; + void * pClassData_UAC_MIC; + void * pUserData_UAC_MIC; + void * pClassData_UAC_SPKR; + void * pUserData_UAC_SPKR; + void * pClassData_UVC; + void * pUserData_UVC; + void * pClassData_MSC; + void * pUserData_MSC; + void * pClassData_DFU; + void * pUserData_DFU; + void * pClassData_PRNTR; + void * pUserData_PRNTR; + void * pData; + void * pBosDesc; + void * pConfDesc; +} USBD_HandleTypeDef; + +/** + * @} + */ + +/** @defgroup USBD_DEF_Exported_Macros + * @{ + */ +__STATIC_INLINE uint16_t SWAPBYTE(uint8_t * addr) +{ + uint16_t _SwapVal, _Byte1, _Byte2; + uint8_t * _pbuff = addr; + + _Byte1 = *(uint8_t *) _pbuff; + _pbuff++; + _Byte2 = *(uint8_t *) _pbuff; + + _SwapVal = (_Byte2 << 8) | _Byte1; + + return _SwapVal; +} + +#ifndef LOBYTE +#define LOBYTE(x) ((uint8_t) ((x) &0x00FFU)) +#endif + +#ifndef HIBYTE +#define HIBYTE(x) ((uint8_t) (((x) &0xFF00U) >> 8U)) +#endif + +#ifndef MIN +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#endif + +#ifndef MAX +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#endif + +#if defined(__GNUC__) +#ifndef __weak +#define __weak __attribute__((weak)) +#endif /* __weak */ +#ifndef __packed +#define __packed __attribute__((__packed__)) +#endif /* __packed */ +#endif /* __GNUC__ */ + +/* In HS mode and when the DMA is used, all variables and data structures dealing + with the DMA during the transaction process should be 4-bytes aligned */ + +#if defined(__GNUC__) && !defined(__CC_ARM) /* GNU Compiler */ +#ifndef __ALIGN_END +#define __ALIGN_END __attribute__((aligned(4U))) +#endif /* __ALIGN_END */ +#ifndef __ALIGN_BEGIN +#define __ALIGN_BEGIN +#endif /* __ALIGN_BEGIN */ +#else +#ifndef __ALIGN_END +#define __ALIGN_END +#endif /* __ALIGN_END */ +#ifndef __ALIGN_BEGIN +#if defined(__CC_ARM) /* ARM Compiler */ +#define __ALIGN_BEGIN __align(4U) +#elif defined(__ICCARM__) /* IAR Compiler */ +#define __ALIGN_BEGIN +#endif /* __CC_ARM */ +#endif /* __ALIGN_BEGIN */ +#endif /* __GNUC__ */ + +#ifdef __cplusplus +} +#endif + +#endif /* __USBD_DEF_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/USB_AL94/usbd_desc.c b/common/USB_AL94/usbd_desc.c new file mode 100644 index 0000000..221bac0 --- /dev/null +++ b/common/USB_AL94/usbd_desc.c @@ -0,0 +1,270 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : App/usbd_desc.c + * @version : v1.0_Cube + * @brief : This file implements the USB device descriptors. + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2021 STMicroelectronics. + * All rights reserved.

+ * + * 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 "usbd_desc.h" +#include "usbd_conf.h" +#include "usbd_core.h" + +#include "usbd_composite.h" + +#define USBD_LANGID_STRING 1033 +#define USBD_CONFIGURATION_STRING "CONFIGURATION 0" +#define USBD_INTERFACE_STRING "COMPOSITE INTERFACE" + +//#define USBD_VID 1155 +//#define USBD_MANUFACTURER_STRING "STMicroelectronics" +//#define USBD_PID 21156 +//#define USBD_PRODUCT_STRING "STM32 COMPOSITE DEVICE" + +#define USBD_VID 0x0000 // Vendor ID for Open Source Projects is "Generic" 0x1209 +#define USBD_MANUFACTURER_STRING "VarmintWorks" +#define USBD_PID 0x0001 // pid.codes Test PID for VID=0x1209 +#define USBD_PRODUCT_STRING "rosflight controller" + +static void Get_SerialNum(void); +static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len); + +uint8_t * USBD_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t * length); +uint8_t * USBD_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t * length); +uint8_t * USBD_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t * length); +uint8_t * USBD_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t * length); +uint8_t * USBD_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t * length); +uint8_t * USBD_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t * length); +uint8_t * USBD_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t * length); + +USBD_DescriptorsTypeDef USBD_Desc = { + USBD_DeviceDescriptor, USBD_LangIDStrDescriptor, USBD_ManufacturerStrDescriptor, USBD_ProductStrDescriptor, + USBD_SerialStrDescriptor, USBD_ConfigStrDescriptor, USBD_InterfaceStrDescriptor}; + +/** USB standard device descriptor. */ +__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = { + 0x12, /*bLength */ + USB_DESC_TYPE_DEVICE, /*bDescriptorType*/ + 0x00, /*bcdUSB */ + 0x02, + 0xEF, /*bDeviceClass*/ + 0x02, /*bDeviceSubClass*/ + 0x01, /*bDeviceProtocol*/ + USB_MAX_EP0_SIZE, /*bMaxPacketSize*/ + LOBYTE(USBD_VID), /*idVendor*/ + HIBYTE(USBD_VID), /*idVendor*/ + LOBYTE(USBD_PID), /*idProduct*/ + HIBYTE(USBD_PID), /*idProduct*/ + 0x00, /*bcdDevice rel. 2.00*/ + 0x02, + USBD_IDX_MFC_STR, /*Index of manufacturer string*/ + USBD_IDX_PRODUCT_STR, /*Index of product string*/ + USBD_IDX_SERIAL_STR, /*Index of serial number string*/ + USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/ +}; + +/** USB lang indentifier descriptor. */ +__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END = { + USB_LEN_LANGID_STR_DESC, USB_DESC_TYPE_STRING, LOBYTE(USBD_LANGID_STRING), HIBYTE(USBD_LANGID_STRING)}; + +/* Internal string descriptor. */ +__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; + +__ALIGN_BEGIN uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] __ALIGN_END = { + USB_SIZ_STRING_SERIAL, + USB_DESC_TYPE_STRING, +}; + +/** + * @brief Return the device descriptor + * @param speed : Current device speed + * @param length : Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t * USBD_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t * length) +{ + UNUSED(speed); + *length = sizeof(USBD_DeviceDesc); + return USBD_DeviceDesc; +} + +/** + * @brief Return the LangID string descriptor + * @param speed : Current device speed + * @param length : Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t * USBD_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t * length) +{ + UNUSED(speed); + *length = sizeof(USBD_LangIDDesc); + return USBD_LangIDDesc; +} + +/** + * @brief Return the product string descriptor + * @param speed : current device speed + * @param length : pointer to data length variable + * @retval pointer to descriptor buffer + */ +uint8_t * USBD_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t * length) +{ + if (speed == 0) { + USBD_GetString((uint8_t *) USBD_PRODUCT_STRING, USBD_StrDesc, length); + } else { + USBD_GetString((uint8_t *) USBD_PRODUCT_STRING, USBD_StrDesc, length); + } + return USBD_StrDesc; +} + +/** + * @brief Return the manufacturer string descriptor + * @param speed : Current device speed + * @param length : Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t * USBD_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t * length) +{ + UNUSED(speed); + USBD_GetString((uint8_t *) USBD_MANUFACTURER_STRING, USBD_StrDesc, length); + return USBD_StrDesc; +} + +/** + * @brief Return the serial number string descriptor + * @param speed : Current device speed + * @param length : Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t * USBD_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t * length) +{ + UNUSED(speed); + *length = USB_SIZ_STRING_SERIAL; + + /* Update the serial number string descriptor with the data from the unique + * ID */ + Get_SerialNum(); + /* USER CODE BEGIN USBD_SerialStrDescriptor */ + + /* USER CODE END USBD_SerialStrDescriptor */ + + return (uint8_t *) USBD_StringSerial; +} + +/** + * @brief Return the configuration string descriptor + * @param speed : Current device speed + * @param length : Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t * USBD_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t * length) +{ + if (speed == USBD_SPEED_HIGH) { + USBD_GetString((uint8_t *) USBD_CONFIGURATION_STRING, USBD_StrDesc, length); + } else { + USBD_GetString((uint8_t *) USBD_CONFIGURATION_STRING, USBD_StrDesc, length); + } + return USBD_StrDesc; +} + +/** + * @brief Return the interface string descriptor + * @param speed : Current device speed + * @param length : Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t * USBD_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t * length) +{ + if (speed == 0) { + USBD_GetString((uint8_t *) USBD_INTERFACE_STRING, USBD_StrDesc, length); + } else { + USBD_GetString((uint8_t *) USBD_INTERFACE_STRING, USBD_StrDesc, length); + } + return USBD_StrDesc; +} + +#if (USBD_LPM_ENABLED == 1) +/** + * @brief Return the BOS descriptor + * @param speed : Current device speed + * @param length : Pointer to data length variable + * @retval Pointer to descriptor buffer + */ +uint8_t * USBD_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t * length) +{ + UNUSED(speed); + *length = sizeof(USBD_BOSDesc); + return (uint8_t *) USBD_BOSDesc; +} +#endif /* (USBD_LPM_ENABLED == 1) */ + +/** + * @brief Create the serial number string descriptor + * @param None + * @retval None + */ +static void Get_SerialNum(void) +{ + uint32_t deviceserial0, deviceserial1, deviceserial2; + + deviceserial0 = *(uint32_t *) DEVICE_ID1; + deviceserial1 = *(uint32_t *) DEVICE_ID2; + deviceserial2 = *(uint32_t *) DEVICE_ID3; + + deviceserial0 += deviceserial2; + + if (deviceserial0 != 0) { + IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8); + IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4); + } +} + +/** + * @brief Convert Hex 32Bits value into char + * @param value: value to convert + * @param pbuf: pointer to the buffer + * @param len: buffer length + * @retval None + */ +static void IntToUnicode(uint32_t value, uint8_t * pbuf, uint8_t len) +{ + uint8_t idx = 0; + + for (idx = 0; idx < len; idx++) { + if (((value >> 28)) < 0xA) { + pbuf[2 * idx] = (value >> 28) + '0'; + } else { + pbuf[2 * idx] = (value >> 28) + 'A' - 10; + } + + value = value << 4; + + pbuf[2 * idx + 1] = 0; + } +} +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/USB_AL94/usbd_desc.h b/common/USB_AL94/usbd_desc.h new file mode 100644 index 0000000..4806e5b --- /dev/null +++ b/common/USB_AL94/usbd_desc.h @@ -0,0 +1,47 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file : usbd_desc.c + * @version : v1.0_Cube + * @brief : Header for usbd_conf.c file. + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2021 STMicroelectronics. + * All rights reserved.

+ * + * 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 + * + ****************************************************************************** + */ + +#ifndef __USBD_DESC__C__ +#define __USBD_DESC__C__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "usbd_def.h" +/** @defgroup USBD_DESC_Exported_Constants USBD_DESC_Exported_Constants + * @brief Constants. + * @{ + */ +#define DEVICE_ID1 (UID_BASE) +#define DEVICE_ID2 (UID_BASE + 0x4) +#define DEVICE_ID3 (UID_BASE + 0x8) + +#define USB_SIZ_STRING_SERIAL 0x1A + +extern USBD_DescriptorsTypeDef USBD_Desc; + +#ifdef __cplusplus +} +#endif + +#endif /* __USBD_DESC__C__ */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/AL94_USB_Composite/Core/Src/usbd_ioreq.c b/common/USB_AL94/usbd_ioreq.c similarity index 50% rename from common/AL94_USB_Composite/Core/Src/usbd_ioreq.c rename to common/USB_AL94/usbd_ioreq.c index 2cb3995..a850996 100644 --- a/common/AL94_USB_Composite/Core/Src/usbd_ioreq.c +++ b/common/USB_AL94/usbd_ioreq.c @@ -1,214 +1,149 @@ -/** - ****************************************************************************** - * @file usbd_ioreq.c - * @author MCD Application Team - * @brief This file provides the IO requests APIs for control endpoints. - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2015 STMicroelectronics. - * All rights reserved.

- * - * 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 "usbd_ioreq.h" - -/** @addtogroup STM32_USB_DEVICE_LIBRARY - * @{ - */ - -/** @defgroup USBD_IOREQ - * @brief control I/O requests module - * @{ - */ - -/** @defgroup USBD_IOREQ_Private_TypesDefinitions - * @{ - */ -/** - * @} - */ - -/** @defgroup USBD_IOREQ_Private_Defines - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_IOREQ_Private_Macros - * @{ - */ -/** - * @} - */ - -/** @defgroup USBD_IOREQ_Private_Variables - * @{ - */ - -/** - * @} - */ - -/** @defgroup USBD_IOREQ_Private_FunctionPrototypes - * @{ - */ -/** - * @} - */ - -/** @defgroup USBD_IOREQ_Private_Functions - * @{ - */ - -/** - * @brief USBD_CtlSendData - * send data on the ctl pipe - * @param pdev: device instance - * @param buff: pointer to data buffer - * @param len: length of data to be sent - * @retval status - */ -USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t len) -{ - /* Set EP0 State */ - pdev->ep0_state = USBD_EP0_DATA_IN; - pdev->ep_in[0].total_length = len; - -#ifdef USBD_AVOID_PACKET_SPLIT_MPS - pdev->ep_in[0].rem_length = 0U; -#else - pdev->ep_in[0].rem_length = len; -#endif - - /* Start the transfer */ - (void) USBD_LL_Transmit (pdev, 0x00U, pbuf, len); - - return USBD_OK; -} - -/** - * @brief USBD_CtlContinueSendData - * continue sending data on the ctl pipe - * @param pdev: device instance - * @param buff: pointer to data buffer - * @param len: length of data to be sent - * @retval status - */ -USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t len) -{ - /* Start the next transfer */ - (void) USBD_LL_Transmit (pdev, 0x00U, pbuf, len); - - return USBD_OK; -} - -/** - * @brief USBD_CtlPrepareRx - * receive data on the ctl pipe - * @param pdev: device instance - * @param buff: pointer to data buffer - * @param len: length of data to be received - * @retval status - */ -USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t len) -{ - /* Set EP0 State */ - pdev->ep0_state = USBD_EP0_DATA_OUT; - pdev->ep_out[0].total_length = len; - -#ifdef USBD_AVOID_PACKET_SPLIT_MPS - pdev->ep_out[0].rem_length = 0U; -#else - pdev->ep_out[0].rem_length = len; -#endif - - /* Start the transfer */ - (void) USBD_LL_PrepareReceive (pdev, 0U, pbuf, len); - - return USBD_OK; -} - -/** - * @brief USBD_CtlContinueRx - * continue receive data on the ctl pipe - * @param pdev: device instance - * @param buff: pointer to data buffer - * @param len: length of data to be received - * @retval status - */ -USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint32_t len) -{ - (void) USBD_LL_PrepareReceive (pdev, 0U, pbuf, len); - - return USBD_OK; -} - -/** - * @brief USBD_CtlSendStatus - * send zero lzngth packet on the ctl pipe - * @param pdev: device instance - * @retval status - */ -USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev) -{ - /* Set EP0 State */ - pdev->ep0_state = USBD_EP0_STATUS_IN; - - /* Start the transfer */ - (void) USBD_LL_Transmit (pdev, 0x00U, NULL, 0U); - - return USBD_OK; -} - -/** - * @brief USBD_CtlReceiveStatus - * receive zero lzngth packet on the ctl pipe - * @param pdev: device instance - * @retval status - */ -USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev) -{ - /* Set EP0 State */ - pdev->ep0_state = USBD_EP0_STATUS_OUT; - - /* Start the transfer */ - (void) USBD_LL_PrepareReceive (pdev, 0U, NULL, 0U); - - return USBD_OK; -} - -/** - * @brief USBD_GetRxCount - * returns the received data length - * @param pdev: device instance - * @param ep_addr: endpoint address - * @retval Rx Data blength - */ -uint32_t USBD_GetRxCount (USBD_HandleTypeDef *pdev, uint8_t ep_addr) -{ - return USBD_LL_GetRxDataSize (pdev, ep_addr); -} - -/** - * @} - */ - -/** - * @} - */ - -/** - * @} - */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ +/** + ****************************************************************************** + * @file usbd_ioreq.c + * @author MCD Application Team + * @brief This file provides the IO requests APIs for control endpoints. + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2015 STMicroelectronics. + * All rights reserved.

+ * + * 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 "usbd_ioreq.h" + +/** + * @brief USBD_CtlSendData + * send data on the ctl pipe + * @param pdev: device instance + * @param buff: pointer to data buffer + * @param len: length of data to be sent + * @retval status + */ +USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef * pdev, uint8_t * pbuf, uint32_t len) +{ + /* Set EP0 State */ + pdev->ep0_state = USBD_EP0_DATA_IN; + pdev->ep_in[0].total_length = len; + +#ifdef USBD_AVOID_PACKET_SPLIT_MPS + pdev->ep_in[0].rem_length = 0U; +#else + pdev->ep_in[0].rem_length = len; +#endif + + /* Start the transfer */ + (void) USBD_LL_Transmit(pdev, 0x00U, pbuf, len); + + return USBD_OK; +} + +/** + * @brief USBD_CtlContinueSendData + * continue sending data on the ctl pipe + * @param pdev: device instance + * @param buff: pointer to data buffer + * @param len: length of data to be sent + * @retval status + */ +USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef * pdev, uint8_t * pbuf, uint32_t len) +{ + /* Start the next transfer */ + (void) USBD_LL_Transmit(pdev, 0x00U, pbuf, len); + + return USBD_OK; +} + +/** + * @brief USBD_CtlPrepareRx + * receive data on the ctl pipe + * @param pdev: device instance + * @param buff: pointer to data buffer + * @param len: length of data to be received + * @retval status + */ +USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef * pdev, uint8_t * pbuf, uint32_t len) +{ + /* Set EP0 State */ + pdev->ep0_state = USBD_EP0_DATA_OUT; + pdev->ep_out[0].total_length = len; + +#ifdef USBD_AVOID_PACKET_SPLIT_MPS + pdev->ep_out[0].rem_length = 0U; +#else + pdev->ep_out[0].rem_length = len; +#endif + + /* Start the transfer */ + (void) USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); + + return USBD_OK; +} + +/** + * @brief USBD_CtlContinueRx + * continue receive data on the ctl pipe + * @param pdev: device instance + * @param buff: pointer to data buffer + * @param len: length of data to be received + * @retval status + */ +USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef * pdev, uint8_t * pbuf, uint32_t len) +{ + (void) USBD_LL_PrepareReceive(pdev, 0U, pbuf, len); + + return USBD_OK; +} + +/** + * @brief USBD_CtlSendStatus + * send zero lzngth packet on the ctl pipe + * @param pdev: device instance + * @retval status + */ +USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef * pdev) +{ + /* Set EP0 State */ + pdev->ep0_state = USBD_EP0_STATUS_IN; + + /* Start the transfer */ + (void) USBD_LL_Transmit(pdev, 0x00U, NULL, 0U); + + return USBD_OK; +} + +/** + * @brief USBD_CtlReceiveStatus + * receive zero lzngth packet on the ctl pipe + * @param pdev: device instance + * @retval status + */ +USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef * pdev) +{ + /* Set EP0 State */ + pdev->ep0_state = USBD_EP0_STATUS_OUT; + + /* Start the transfer */ + (void) USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U); + + return USBD_OK; +} + +/** + * @brief USBD_GetRxCount + * returns the received data length + * @param pdev: device instance + * @param ep_addr: endpoint address + * @retval Rx Data blength + */ +uint32_t USBD_GetRxCount(USBD_HandleTypeDef * pdev, uint8_t ep_addr) { return USBD_LL_GetRxDataSize(pdev, ep_addr); } + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/common/USB_AL94/usbd_ioreq.h b/common/USB_AL94/usbd_ioreq.h new file mode 100644 index 0000000..cb25d22 --- /dev/null +++ b/common/USB_AL94/usbd_ioreq.h @@ -0,0 +1,49 @@ +/** + ****************************************************************************** + * @file usbd_ioreq.h + * @author MCD Application Team + * @brief Header file for the usbd_ioreq.c file + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2015 STMicroelectronics. + * All rights reserved.

+ * + * 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 + * + ****************************************************************************** + */ + +#ifndef __USBD_IOREQ_H +#define __USBD_IOREQ_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "usbd_core.h" +#include "usbd_def.h" + +USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef * pdev, uint8_t * pbuf, uint32_t len); + +USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef * pdev, uint8_t * pbuf, uint32_t len); + +USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef * pdev, uint8_t * pbuf, uint32_t len); + +USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef * pdev, uint8_t * pbuf, uint32_t len); + +USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef * pdev); +USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef * pdev); + +uint32_t USBD_GetRxCount(USBD_HandleTypeDef * pdev, uint8_t ep_addr); + +#ifdef __cplusplus +} +#endif + +#endif /* __USBD_IOREQ_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/