monorepo
This commit is contained in:
@@ -0,0 +1,198 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_customhid.h
|
||||
* @author MCD Application Team
|
||||
* @brief header file for the usbd_customhid.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2015 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 __USB_CUSTOMHID_H
|
||||
#define __USB_CUSTOMHID_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ioreq.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CUSTOM_HID
|
||||
* @brief This file is the Header file for USBD_customhid.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CUSTOM_HID_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
#ifndef CUSTOM_HID_EPIN_ADDR
|
||||
#define CUSTOM_HID_EPIN_ADDR 0x81U
|
||||
#endif /* CUSTOM_HID_EPIN_ADDR */
|
||||
|
||||
#ifndef CUSTOM_HID_EPIN_SIZE
|
||||
#define CUSTOM_HID_EPIN_SIZE 0x02U
|
||||
#endif /* CUSTOM_HID_EPIN_SIZE */
|
||||
|
||||
#ifndef CUSTOM_HID_EPOUT_ADDR
|
||||
#define CUSTOM_HID_EPOUT_ADDR 0x01U
|
||||
#endif /* CUSTOM_HID_EPOUT_ADDR */
|
||||
|
||||
#ifndef CUSTOM_HID_EPOUT_SIZE
|
||||
#define CUSTOM_HID_EPOUT_SIZE 0x02U
|
||||
#endif /* CUSTOM_HID_EPOUT_SIZE*/
|
||||
|
||||
#define USB_CUSTOM_HID_CONFIG_DESC_SIZ 41U
|
||||
#define USB_CUSTOM_HID_DESC_SIZ 9U
|
||||
|
||||
#ifndef CUSTOM_HID_HS_BINTERVAL
|
||||
#define CUSTOM_HID_HS_BINTERVAL 0x05U
|
||||
#endif /* CUSTOM_HID_HS_BINTERVAL */
|
||||
|
||||
#ifndef CUSTOM_HID_FS_BINTERVAL
|
||||
#define CUSTOM_HID_FS_BINTERVAL 0x05U
|
||||
#endif /* CUSTOM_HID_FS_BINTERVAL */
|
||||
|
||||
#ifndef USBD_CUSTOMHID_OUTREPORT_BUF_SIZE
|
||||
#define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 0x02U
|
||||
#endif /* USBD_CUSTOMHID_OUTREPORT_BUF_SIZE */
|
||||
|
||||
#ifndef USBD_CUSTOM_HID_REPORT_DESC_SIZE
|
||||
#define USBD_CUSTOM_HID_REPORT_DESC_SIZE 163U
|
||||
#endif /* USBD_CUSTOM_HID_REPORT_DESC_SIZE */
|
||||
|
||||
#define CUSTOM_HID_DESCRIPTOR_TYPE 0x21U
|
||||
#define CUSTOM_HID_REPORT_DESC 0x22U
|
||||
|
||||
#define CUSTOM_HID_REQ_SET_PROTOCOL 0x0BU
|
||||
#define CUSTOM_HID_REQ_GET_PROTOCOL 0x03U
|
||||
|
||||
#define CUSTOM_HID_REQ_SET_IDLE 0x0AU
|
||||
#define CUSTOM_HID_REQ_GET_IDLE 0x02U
|
||||
|
||||
#define CUSTOM_HID_REQ_SET_REPORT 0x09U
|
||||
#define CUSTOM_HID_REQ_GET_REPORT 0x01U
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
CUSTOM_HID_IDLE = 0U,
|
||||
CUSTOM_HID_BUSY,
|
||||
} CUSTOM_HID_StateTypeDef;
|
||||
|
||||
typedef struct _USBD_CUSTOM_HID_Itf
|
||||
{
|
||||
uint8_t *pReport;
|
||||
int8_t (* Init)(void);
|
||||
int8_t (* DeInit)(void);
|
||||
int8_t (* OutEvent)(uint8_t event_idx, uint8_t state);
|
||||
#ifdef USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED
|
||||
int8_t (* CtrlReqComplete)(uint8_t request, uint16_t wLength);
|
||||
#endif /* USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED */
|
||||
#ifdef USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED
|
||||
uint8_t *(* GetReport)(uint16_t *ReportLength);
|
||||
#endif /* USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED */
|
||||
} USBD_CUSTOM_HID_ItfTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Report_buf[USBD_CUSTOMHID_OUTREPORT_BUF_SIZE];
|
||||
uint32_t Protocol;
|
||||
uint32_t IdleState;
|
||||
uint32_t AltSetting;
|
||||
uint32_t IsReportAvailable;
|
||||
CUSTOM_HID_StateTypeDef state;
|
||||
} USBD_CUSTOM_HID_HandleTypeDef;
|
||||
|
||||
/*
|
||||
* HID Class specification version 1.1
|
||||
* 6.2.1 HID Descriptor
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorTypeCHID;
|
||||
uint16_t bcdCUSTOM_HID;
|
||||
uint8_t bCountryCode;
|
||||
uint8_t bNumDescriptors;
|
||||
uint8_t bDescriptorType;
|
||||
uint16_t wItemLength;
|
||||
} __PACKED USBD_DescTypeDef;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_CUSTOM_HID;
|
||||
#define USBD_CUSTOM_HID_CLASS &USBD_CUSTOM_HID
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *report, uint16_t len, uint8_t ClassId);
|
||||
#else
|
||||
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *report, uint16_t len);
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
uint8_t USBD_CUSTOM_HID_ReceivePacket(USBD_HandleTypeDef *pdev);
|
||||
|
||||
uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_CUSTOM_HID_ItfTypeDef *fops);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_CUSTOMHID_H */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,811 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_customhid.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides the CUSTOM_HID core functions.
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2015 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.
|
||||
*
|
||||
******************************************************************************
|
||||
* @verbatim
|
||||
*
|
||||
* ===================================================================
|
||||
* CUSTOM_HID Class Description
|
||||
* ===================================================================
|
||||
* This module manages the CUSTOM_HID class V1.11 following the "Device Class Definition
|
||||
* for Human Interface Devices (CUSTOM_HID) Version 1.11 Jun 27, 2001".
|
||||
* This driver implements the following aspects of the specification:
|
||||
* - The Boot Interface Subclass
|
||||
* - Usage Page : Generic Desktop
|
||||
* - Usage : Vendor
|
||||
* - Collection : Application
|
||||
*
|
||||
* @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
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
EndBSPDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_customhid.h"
|
||||
#include "usbd_ctlreq.h"
|
||||
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CUSTOM_HID
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CUSTOM_HID_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CUSTOM_HID_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CUSTOM_HID_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/** @defgroup USBD_CUSTOM_HID_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
static uint8_t USBD_CUSTOM_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
static uint8_t USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
|
||||
static uint8_t USBD_CUSTOM_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_CUSTOM_HID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||
#ifndef USE_USBD_COMPOSITE
|
||||
static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc(uint16_t *length);
|
||||
static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc(uint16_t *length);
|
||||
static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||
static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc(uint16_t *length);
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CUSTOM_HID_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
USBD_ClassTypeDef USBD_CUSTOM_HID =
|
||||
{
|
||||
USBD_CUSTOM_HID_Init,
|
||||
USBD_CUSTOM_HID_DeInit,
|
||||
USBD_CUSTOM_HID_Setup,
|
||||
NULL, /*EP0_TxSent*/
|
||||
USBD_CUSTOM_HID_EP0_RxReady, /*EP0_RxReady*/ /* STATUS STAGE IN */
|
||||
USBD_CUSTOM_HID_DataIn, /*DataIn*/
|
||||
USBD_CUSTOM_HID_DataOut,
|
||||
NULL, /*SOF */
|
||||
NULL,
|
||||
NULL,
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
#else
|
||||
USBD_CUSTOM_HID_GetHSCfgDesc,
|
||||
USBD_CUSTOM_HID_GetFSCfgDesc,
|
||||
USBD_CUSTOM_HID_GetOtherSpeedCfgDesc,
|
||||
USBD_CUSTOM_HID_GetDeviceQualifierDesc,
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
};
|
||||
|
||||
#ifndef USE_USBD_COMPOSITE
|
||||
/* USB CUSTOM_HID device FS Configuration Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgDesc[USB_CUSTOM_HID_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
0x09, /* bLength: Configuration Descriptor size */
|
||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||
LOBYTE(USB_CUSTOM_HID_CONFIG_DESC_SIZ), /* wTotalLength: Bytes returned */
|
||||
HIBYTE(USB_CUSTOM_HID_CONFIG_DESC_SIZ),
|
||||
0x01, /* bNumInterfaces: 1 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_SELF_POWERED */
|
||||
USBD_MAX_POWER, /* MaxPower (mA) */
|
||||
|
||||
/************** Descriptor of CUSTOM HID interface ****************/
|
||||
/* 09 */
|
||||
0x09, /* bLength: Interface Descriptor size*/
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */
|
||||
0x00, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x02, /* bNumEndpoints*/
|
||||
0x03, /* bInterfaceClass: CUSTOM_HID */
|
||||
0x00, /* bInterfaceSubClass : 1=BOOT, 0=no boot */
|
||||
0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
|
||||
0x00, /* iInterface: Index of string descriptor */
|
||||
/******************** Descriptor of CUSTOM_HID *************************/
|
||||
/* 18 */
|
||||
0x09, /* bLength: CUSTOM_HID Descriptor size */
|
||||
CUSTOM_HID_DESCRIPTOR_TYPE, /* bDescriptorType: CUSTOM_HID */
|
||||
0x11, /* bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number */
|
||||
0x01,
|
||||
0x00, /* bCountryCode: Hardware target country */
|
||||
0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors
|
||||
to follow */
|
||||
0x22, /* bDescriptorType */
|
||||
LOBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), /* wItemLength: Total length of Report descriptor */
|
||||
HIBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE),
|
||||
/******************** Descriptor of Custom HID endpoints ********************/
|
||||
/* 27 */
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||
|
||||
CUSTOM_HID_EPIN_ADDR, /* bEndpointAddress: Endpoint Address (IN) */
|
||||
0x03, /* bmAttributes: Interrupt endpoint */
|
||||
LOBYTE(CUSTOM_HID_EPIN_SIZE), /* wMaxPacketSize: 2 Bytes max */
|
||||
HIBYTE(CUSTOM_HID_EPIN_SIZE),
|
||||
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
||||
/* 34 */
|
||||
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: */
|
||||
CUSTOM_HID_EPOUT_ADDR, /* bEndpointAddress: Endpoint Address (OUT) */
|
||||
0x03, /* bmAttributes: Interrupt endpoint */
|
||||
LOBYTE(CUSTOM_HID_EPOUT_SIZE), /* wMaxPacketSize: 2 Bytes max */
|
||||
HIBYTE(CUSTOM_HID_EPOUT_SIZE),
|
||||
CUSTOM_HID_FS_BINTERVAL, /* bInterval: Polling Interval */
|
||||
/* 41 */
|
||||
};
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
/* USB CUSTOM_HID device Configuration Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_Desc[USB_CUSTOM_HID_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
/* 18 */
|
||||
0x09, /* bLength: CUSTOM_HID Descriptor size */
|
||||
CUSTOM_HID_DESCRIPTOR_TYPE, /* bDescriptorType: CUSTOM_HID */
|
||||
0x11, /* bCUSTOM_HIDUSTOM_HID: CUSTOM_HID Class Spec release number */
|
||||
0x01,
|
||||
0x00, /* bCountryCode: Hardware target country */
|
||||
0x01, /* bNumDescriptors: Number of CUSTOM_HID class descriptors
|
||||
to follow */
|
||||
0x22, /* bDescriptorType */
|
||||
LOBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), /* wItemLength: Total length of Report descriptor */
|
||||
HIBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE),
|
||||
};
|
||||
|
||||
#ifndef USE_USBD_COMPOSITE
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_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,
|
||||
};
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
static uint8_t CUSTOMHIDInEpAdd = CUSTOM_HID_EPIN_ADDR;
|
||||
static uint8_t CUSTOMHIDOutEpAdd = CUSTOM_HID_EPOUT_ADDR;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CUSTOM_HID_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_CUSTOM_HID_Init
|
||||
* Initialize the CUSTOM_HID interface
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CUSTOM_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
UNUSED(cfgidx);
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid;
|
||||
|
||||
hhid = (USBD_CUSTOM_HID_HandleTypeDef *)USBD_malloc(sizeof(USBD_CUSTOM_HID_HandleTypeDef));
|
||||
|
||||
if (hhid == NULL)
|
||||
{
|
||||
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||
return (uint8_t)USBD_EMEM;
|
||||
}
|
||||
|
||||
pdev->pClassDataCmsit[pdev->classId] = (void *)hhid;
|
||||
pdev->pClassData = pdev->pClassDataCmsit[pdev->classId];
|
||||
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
/* Get the Endpoints addresses allocated for this class instance */
|
||||
CUSTOMHIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||
CUSTOMHIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
pdev->ep_in[CUSTOMHIDInEpAdd & 0xFU].bInterval = CUSTOM_HID_HS_BINTERVAL;
|
||||
pdev->ep_out[CUSTOMHIDOutEpAdd & 0xFU].bInterval = CUSTOM_HID_HS_BINTERVAL;
|
||||
}
|
||||
else /* LOW and FULL-speed endpoints */
|
||||
{
|
||||
pdev->ep_in[CUSTOMHIDInEpAdd & 0xFU].bInterval = CUSTOM_HID_FS_BINTERVAL;
|
||||
pdev->ep_out[CUSTOMHIDOutEpAdd & 0xFU].bInterval = CUSTOM_HID_FS_BINTERVAL;
|
||||
}
|
||||
|
||||
/* Open EP IN */
|
||||
(void)USBD_LL_OpenEP(pdev, CUSTOMHIDInEpAdd, USBD_EP_TYPE_INTR,
|
||||
CUSTOM_HID_EPIN_SIZE);
|
||||
|
||||
pdev->ep_in[CUSTOMHIDInEpAdd & 0xFU].is_used = 1U;
|
||||
|
||||
/* Open EP OUT */
|
||||
(void)USBD_LL_OpenEP(pdev, CUSTOMHIDOutEpAdd, USBD_EP_TYPE_INTR,
|
||||
CUSTOM_HID_EPOUT_SIZE);
|
||||
|
||||
pdev->ep_out[CUSTOMHIDOutEpAdd & 0xFU].is_used = 1U;
|
||||
|
||||
hhid->state = CUSTOM_HID_IDLE;
|
||||
|
||||
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->Init();
|
||||
|
||||
#ifndef USBD_CUSTOMHID_OUT_PREPARE_RECEIVE_DISABLED
|
||||
/* Prepare Out endpoint to receive 1st packet */
|
||||
(void)USBD_LL_PrepareReceive(pdev, CUSTOMHIDOutEpAdd, hhid->Report_buf,
|
||||
USBD_CUSTOMHID_OUTREPORT_BUF_SIZE);
|
||||
#endif /* USBD_CUSTOMHID_OUT_PREPARE_RECEIVE_DISABLED */
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CUSTOM_HID_Init
|
||||
* DeInitialize the CUSTOM_HID layer
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CUSTOM_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
UNUSED(cfgidx);
|
||||
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
/* Get the Endpoints addresses allocated for this class instance */
|
||||
CUSTOMHIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||
CUSTOMHIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
/* Close CUSTOM_HID EP IN */
|
||||
(void)USBD_LL_CloseEP(pdev, CUSTOMHIDInEpAdd);
|
||||
pdev->ep_in[CUSTOMHIDInEpAdd & 0xFU].is_used = 0U;
|
||||
pdev->ep_in[CUSTOMHIDInEpAdd & 0xFU].bInterval = 0U;
|
||||
|
||||
/* Close CUSTOM_HID EP OUT */
|
||||
(void)USBD_LL_CloseEP(pdev, CUSTOMHIDOutEpAdd);
|
||||
pdev->ep_out[CUSTOMHIDOutEpAdd & 0xFU].is_used = 0U;
|
||||
pdev->ep_out[CUSTOMHIDOutEpAdd & 0xFU].bInterval = 0U;
|
||||
|
||||
/* Free allocated memory */
|
||||
if (pdev->pClassDataCmsit[pdev->classId] != NULL)
|
||||
{
|
||||
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->DeInit();
|
||||
USBD_free(pdev->pClassDataCmsit[pdev->classId]);
|
||||
pdev->pClassDataCmsit[pdev->classId] = NULL;
|
||||
pdev->pClassData = NULL;
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CUSTOM_HID_Setup
|
||||
* Handle the CUSTOM_HID specific requests
|
||||
* @param pdev: instance
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CUSTOM_HID_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint16_t len = 0U;
|
||||
#ifdef USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED
|
||||
uint16_t ReportLength = 0U;
|
||||
#endif /* USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED */
|
||||
uint8_t *pbuf = NULL;
|
||||
uint16_t status_info = 0U;
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
|
||||
if (hhid == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case CUSTOM_HID_REQ_SET_PROTOCOL:
|
||||
hhid->Protocol = (uint8_t)(req->wValue);
|
||||
break;
|
||||
|
||||
case CUSTOM_HID_REQ_GET_PROTOCOL:
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->Protocol, 1U);
|
||||
break;
|
||||
|
||||
case CUSTOM_HID_REQ_SET_IDLE:
|
||||
hhid->IdleState = (uint8_t)(req->wValue >> 8);
|
||||
break;
|
||||
|
||||
case CUSTOM_HID_REQ_GET_IDLE:
|
||||
(void)USBD_CtlSendData(pdev, (uint8_t *)&hhid->IdleState, 1U);
|
||||
break;
|
||||
|
||||
case CUSTOM_HID_REQ_SET_REPORT:
|
||||
#ifdef USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED
|
||||
if (((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->CtrlReqComplete != NULL)
|
||||
{
|
||||
/* Let the application decide when to enable EP0 to receive the next report */
|
||||
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->CtrlReqComplete(req->bRequest,
|
||||
req->wLength);
|
||||
}
|
||||
#endif /* USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED */
|
||||
#ifndef USBD_CUSTOMHID_EP0_OUT_PREPARE_RECEIVE_DISABLED
|
||||
hhid->IsReportAvailable = 1U;
|
||||
(void)USBD_CtlPrepareRx(pdev, hhid->Report_buf,
|
||||
MIN(req->wLength, USBD_CUSTOMHID_OUTREPORT_BUF_SIZE));
|
||||
#endif /* USBD_CUSTOMHID_EP0_OUT_PREPARE_RECEIVE_DISABLED */
|
||||
break;
|
||||
#ifdef USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED
|
||||
case CUSTOM_HID_REQ_GET_REPORT:
|
||||
if (((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->GetReport != NULL)
|
||||
{
|
||||
ReportLength = req->wLength;
|
||||
|
||||
/* Get report data buffer */
|
||||
pbuf = ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->GetReport(&ReportLength);
|
||||
}
|
||||
|
||||
if ((pbuf != NULL) && (ReportLength != 0U))
|
||||
{
|
||||
len = MIN(ReportLength, req->wLength);
|
||||
|
||||
/* Send the report data over EP0 */
|
||||
(void)USBD_CtlSendData(pdev, pbuf, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED
|
||||
if (((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->CtrlReqComplete != NULL)
|
||||
{
|
||||
/* Let the application decide what to do, keep EP0 data phase in NAK state and
|
||||
use USBD_CtlSendData() when data become available or stall the EP0 data phase */
|
||||
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->CtrlReqComplete(req->bRequest,
|
||||
req->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Stall EP0 if no data available */
|
||||
USBD_CtlError(pdev, req);
|
||||
}
|
||||
#else
|
||||
/* Stall EP0 if no data available */
|
||||
USBD_CtlError(pdev, req);
|
||||
#endif /* USBD_CUSTOMHID_CTRL_REQ_COMPLETE_CALLBACK_ENABLED */
|
||||
}
|
||||
break;
|
||||
#endif /* USBD_CUSTOMHID_CTRL_REQ_GET_REPORT_ENABLED */
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
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_DESCRIPTOR:
|
||||
if ((req->wValue >> 8) == CUSTOM_HID_REPORT_DESC)
|
||||
{
|
||||
len = MIN(USBD_CUSTOM_HID_REPORT_DESC_SIZE, req->wLength);
|
||||
pbuf = ((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->pReport;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((req->wValue >> 8) == CUSTOM_HID_DESCRIPTOR_TYPE)
|
||||
{
|
||||
pbuf = USBD_CUSTOM_HID_Desc;
|
||||
len = MIN(USB_CUSTOM_HID_DESC_SIZ, req->wLength);
|
||||
}
|
||||
}
|
||||
|
||||
if (pbuf != NULL)
|
||||
{
|
||||
(void)USBD_CtlSendData(pdev, pbuf, len);
|
||||
}
|
||||
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, (uint8_t *)&hhid->AltSetting, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
hhid->AltSetting = (uint8_t)(req->wValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
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_CUSTOM_HID_SendReport
|
||||
* Send CUSTOM_HID Report
|
||||
* @param pdev: device instance
|
||||
* @param buff: pointer to report
|
||||
* @param ClassId: The Class ID
|
||||
* @retval status
|
||||
*/
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *report, uint16_t len, uint8_t ClassId)
|
||||
{
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[ClassId];
|
||||
#else
|
||||
uint8_t USBD_CUSTOM_HID_SendReport(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *report, uint16_t len)
|
||||
{
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
if (hhid == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
/* Get Endpoint IN address allocated for this class instance */
|
||||
CUSTOMHIDInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_INTR, ClassId);
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
if (hhid->state == CUSTOM_HID_IDLE)
|
||||
{
|
||||
hhid->state = CUSTOM_HID_BUSY;
|
||||
(void)USBD_LL_Transmit(pdev, CUSTOMHIDInEpAdd, report, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (uint8_t)USBD_BUSY;
|
||||
}
|
||||
}
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
#ifndef USE_USBD_COMPOSITE
|
||||
/**
|
||||
* @brief USBD_CUSTOM_HID_GetFSCfgDesc
|
||||
* return FS configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CUSTOM_HID_GetFSCfgDesc(uint16_t *length)
|
||||
{
|
||||
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CUSTOM_HID_CfgDesc, CUSTOM_HID_EPIN_ADDR);
|
||||
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CUSTOM_HID_CfgDesc, CUSTOM_HID_EPOUT_ADDR);
|
||||
|
||||
if (pEpInDesc != NULL)
|
||||
{
|
||||
pEpInDesc->wMaxPacketSize = CUSTOM_HID_EPIN_SIZE;
|
||||
pEpInDesc->bInterval = CUSTOM_HID_FS_BINTERVAL;
|
||||
}
|
||||
|
||||
if (pEpOutDesc != NULL)
|
||||
{
|
||||
pEpOutDesc->wMaxPacketSize = CUSTOM_HID_EPOUT_SIZE;
|
||||
pEpOutDesc->bInterval = CUSTOM_HID_FS_BINTERVAL;
|
||||
}
|
||||
|
||||
*length = (uint16_t)sizeof(USBD_CUSTOM_HID_CfgDesc);
|
||||
return USBD_CUSTOM_HID_CfgDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CUSTOM_HID_GetHSCfgDesc
|
||||
* return HS configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CUSTOM_HID_GetHSCfgDesc(uint16_t *length)
|
||||
{
|
||||
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CUSTOM_HID_CfgDesc, CUSTOM_HID_EPIN_ADDR);
|
||||
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CUSTOM_HID_CfgDesc, CUSTOM_HID_EPOUT_ADDR);
|
||||
|
||||
if (pEpInDesc != NULL)
|
||||
{
|
||||
pEpInDesc->wMaxPacketSize = CUSTOM_HID_EPIN_SIZE;
|
||||
pEpInDesc->bInterval = CUSTOM_HID_HS_BINTERVAL;
|
||||
}
|
||||
|
||||
if (pEpOutDesc != NULL)
|
||||
{
|
||||
pEpOutDesc->wMaxPacketSize = CUSTOM_HID_EPOUT_SIZE;
|
||||
pEpOutDesc->bInterval = CUSTOM_HID_HS_BINTERVAL;
|
||||
}
|
||||
|
||||
*length = (uint16_t)sizeof(USBD_CUSTOM_HID_CfgDesc);
|
||||
return USBD_CUSTOM_HID_CfgDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CUSTOM_HID_GetOtherSpeedCfgDesc
|
||||
* return other speed configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CUSTOM_HID_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||
{
|
||||
USBD_EpDescTypeDef *pEpInDesc = USBD_GetEpDesc(USBD_CUSTOM_HID_CfgDesc, CUSTOM_HID_EPIN_ADDR);
|
||||
USBD_EpDescTypeDef *pEpOutDesc = USBD_GetEpDesc(USBD_CUSTOM_HID_CfgDesc, CUSTOM_HID_EPOUT_ADDR);
|
||||
|
||||
if (pEpInDesc != NULL)
|
||||
{
|
||||
pEpInDesc->wMaxPacketSize = CUSTOM_HID_EPIN_SIZE;
|
||||
pEpInDesc->bInterval = CUSTOM_HID_FS_BINTERVAL;
|
||||
}
|
||||
|
||||
if (pEpOutDesc != NULL)
|
||||
{
|
||||
pEpOutDesc->wMaxPacketSize = CUSTOM_HID_EPOUT_SIZE;
|
||||
pEpOutDesc->bInterval = CUSTOM_HID_FS_BINTERVAL;
|
||||
}
|
||||
|
||||
*length = (uint16_t)sizeof(USBD_CUSTOM_HID_CfgDesc);
|
||||
return USBD_CUSTOM_HID_CfgDesc;
|
||||
}
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
/**
|
||||
* @brief USBD_CUSTOM_HID_DataIn
|
||||
* handle data IN Stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CUSTOM_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
UNUSED(epnum);
|
||||
|
||||
/* Ensure that the FIFO is empty before a new transfer, this condition could
|
||||
be caused by a new transfer before the end of the previous transfer */
|
||||
((USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId])->state = CUSTOM_HID_IDLE;
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CUSTOM_HID_DataOut
|
||||
* handle data OUT Stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CUSTOM_HID_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
UNUSED(epnum);
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid;
|
||||
|
||||
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
|
||||
/* USB data will be immediately processed, this allow next USB traffic being
|
||||
NAKed till the end of the application processing */
|
||||
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->OutEvent(hhid->Report_buf[0],
|
||||
hhid->Report_buf[1]);
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_CUSTOM_HID_ReceivePacket
|
||||
* prepare OUT Endpoint for reception
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CUSTOM_HID_ReceivePacket(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid;
|
||||
|
||||
if (pdev->pClassDataCmsit[pdev->classId] == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
/* Get OUT Endpoint address allocated for this class instance */
|
||||
CUSTOMHIDOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_INTR, (uint8_t)pdev->classId);
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
|
||||
/* Resume USB Out process */
|
||||
(void)USBD_LL_PrepareReceive(pdev, CUSTOMHIDOutEpAdd, hhid->Report_buf,
|
||||
USBD_CUSTOMHID_OUTREPORT_BUF_SIZE);
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_CUSTOM_HID_EP0_RxReady
|
||||
* Handles control request data.
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CUSTOM_HID_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CUSTOM_HID_HandleTypeDef *hhid = (USBD_CUSTOM_HID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
|
||||
if (hhid == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
if (hhid->IsReportAvailable == 1U)
|
||||
{
|
||||
((USBD_CUSTOM_HID_ItfTypeDef *)pdev->pUserData[pdev->classId])->OutEvent(hhid->Report_buf[0],
|
||||
hhid->Report_buf[1]);
|
||||
hhid->IsReportAvailable = 0U;
|
||||
}
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
|
||||
#ifndef USE_USBD_COMPOSITE
|
||||
/**
|
||||
* @brief DeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CUSTOM_HID_GetDeviceQualifierDesc(uint16_t *length)
|
||||
{
|
||||
*length = (uint16_t)sizeof(USBD_CUSTOM_HID_DeviceQualifierDesc);
|
||||
|
||||
return USBD_CUSTOM_HID_DeviceQualifierDesc;
|
||||
}
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
/**
|
||||
* @brief USBD_CUSTOM_HID_RegisterInterface
|
||||
* @param pdev: device instance
|
||||
* @param fops: CUSTOMHID Interface callback
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CUSTOM_HID_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_CUSTOM_HID_ItfTypeDef *fops)
|
||||
{
|
||||
if (fops == NULL)
|
||||
{
|
||||
return (uint8_t)USBD_FAIL;
|
||||
}
|
||||
|
||||
pdev->pUserData[pdev->classId] = fops;
|
||||
|
||||
return (uint8_t)USBD_OK;
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
166
P7_SETR1/Middlewares/ST/STM32_USB_Device_Library/Class/MIDI/Inc/usbd_midi.h
Executable file
166
P7_SETR1/Middlewares/ST/STM32_USB_Device_Library/Class/MIDI/Inc/usbd_midi.h
Executable file
@@ -0,0 +1,166 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_midi.h
|
||||
* @author MCD Application Team
|
||||
* @brief header file for the usbd_midi.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2022 Illia Pikin</center></h2>
|
||||
* <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#ifndef __USB_MIDI_H
|
||||
#define __USB_MIDI_H
|
||||
|
||||
#include "usbd_ioreq.h"
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MIDI_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
#define MIDI_EPIN_ADDR 0x81
|
||||
#define MIDI_EPIN_SIZE 0x40
|
||||
|
||||
#define MIDI_EPOUT_ADDR 0x01
|
||||
#define MIDI_EPOUT_SIZE 0x40
|
||||
|
||||
#define USB_MIDI_CLASS_DESC_SHIFT 18
|
||||
#define USB_MIDI_DESC_SIZE 7
|
||||
#define USB_MIDI_REPORT_DESC_SIZE (MIDI_IN_PORTS_NUM * 16 + MIDI_OUT_PORTS_NUM * 16 + 33)
|
||||
#define USB_MIDI_CONFIG_DESC_SIZE (USB_MIDI_REPORT_DESC_SIZE + USB_MIDI_CLASS_DESC_SHIFT)
|
||||
|
||||
#define MIDI_DESCRIPTOR_TYPE 0x21
|
||||
|
||||
#define MIDI_REQ_SET_PROTOCOL 0x0B
|
||||
#define MIDI_REQ_GET_PROTOCOL 0x03
|
||||
|
||||
#define MIDI_REQ_SET_IDLE 0x0A
|
||||
#define MIDI_REQ_GET_IDLE 0x02
|
||||
|
||||
#define MIDI_REQ_SET_REPORT 0x09
|
||||
#define MIDI_REQ_GET_REPORT 0x01
|
||||
|
||||
#define MIDI_JACK_1 0x01
|
||||
#define MIDI_JACK_2 0x02
|
||||
#define MIDI_JACK_3 0x03
|
||||
#define MIDI_JACK_4 0x04
|
||||
#define MIDI_JACK_5 0x05
|
||||
#define MIDI_JACK_6 0x06
|
||||
#define MIDI_JACK_7 0x07
|
||||
#define MIDI_JACK_8 0x08
|
||||
#define MIDI_JACK_9 0x09
|
||||
#define MIDI_JACK_10 0x0a
|
||||
#define MIDI_JACK_11 0x0b
|
||||
#define MIDI_JACK_12 0x0c
|
||||
#define MIDI_JACK_13 0x0d
|
||||
#define MIDI_JACK_14 0x0e
|
||||
#define MIDI_JACK_15 0x0f
|
||||
#define MIDI_JACK_16 0x10
|
||||
#define MIDI_JACK_17 (MIDI_IN_PORTS_NUM * 2 + 0x01)
|
||||
#define MIDI_JACK_18 (MIDI_IN_PORTS_NUM * 2 + 0x02)
|
||||
#define MIDI_JACK_19 (MIDI_IN_PORTS_NUM * 2 + 0x03)
|
||||
#define MIDI_JACK_20 (MIDI_IN_PORTS_NUM * 2 + 0x04)
|
||||
#define MIDI_JACK_21 (MIDI_IN_PORTS_NUM * 2 + 0x05)
|
||||
#define MIDI_JACK_22 (MIDI_IN_PORTS_NUM * 2 + 0x06)
|
||||
#define MIDI_JACK_23 (MIDI_IN_PORTS_NUM * 2 + 0x07)
|
||||
#define MIDI_JACK_24 (MIDI_IN_PORTS_NUM * 2 + 0x08)
|
||||
#define MIDI_JACK_25 (MIDI_IN_PORTS_NUM * 2 + 0x09)
|
||||
#define MIDI_JACK_26 (MIDI_IN_PORTS_NUM * 2 + 0x0a)
|
||||
#define MIDI_JACK_27 (MIDI_IN_PORTS_NUM * 2 + 0x0b)
|
||||
#define MIDI_JACK_28 (MIDI_IN_PORTS_NUM * 2 + 0x0c)
|
||||
#define MIDI_JACK_29 (MIDI_IN_PORTS_NUM * 2 + 0x0d)
|
||||
#define MIDI_JACK_30 (MIDI_IN_PORTS_NUM * 2 + 0x0e)
|
||||
#define MIDI_JACK_31 (MIDI_IN_PORTS_NUM * 2 + 0x0f)
|
||||
#define MIDI_JACK_32 (MIDI_IN_PORTS_NUM * 2 + 0x10)
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
MIDI_IDLE = 0,
|
||||
MIDI_BUSY,
|
||||
}
|
||||
MIDI_StateTypeDef;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t Protocol;
|
||||
uint32_t IdleState;
|
||||
uint32_t AltSetting;
|
||||
MIDI_StateTypeDef state;
|
||||
}
|
||||
USBD_MIDI_HandleTypeDef;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_MIDI;
|
||||
extern void USBD_MIDI_DataInHandler(uint8_t * usb_rx_buffer, uint8_t usb_rx_buffer_length);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_MIDI_SendReport (USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len);
|
||||
uint8_t *USBD_MIDI_DeviceQualifierDescriptor (uint16_t *length);
|
||||
uint8_t USBD_MIDI_GetState(USBD_HandleTypeDef *pdev);
|
||||
uint8_t USBD_MIDI_GetDeviceState(USBD_HandleTypeDef *pdev);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif // __USB_MIDI_H
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
883
P7_SETR1/Middlewares/ST/STM32_USB_Device_Library/Class/MIDI/Src/usbd_midi.c
Executable file
883
P7_SETR1/Middlewares/ST/STM32_USB_Device_Library/Class/MIDI/Src/usbd_midi.c
Executable file
@@ -0,0 +1,883 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_midi.c
|
||||
* @author Illia Pikin; MCD Application Team
|
||||
* @brief This file provides the MIDI core functions.
|
||||
*
|
||||
* @verbatim
|
||||
*
|
||||
* ===================================================================
|
||||
* MIDI Class Description
|
||||
* ===================================================================
|
||||
* This module manages the MIDI class V1.0 following the "Universal Serial Bus
|
||||
* Device Class Definition for MIDI Devices. Release 1.0 Nov 1, 1999".
|
||||
*
|
||||
* @note In HS mode and when the DMA is used, all variables and data structures
|
||||
* dealing with the DMA during the transaction process should be 32-bit aligned.
|
||||
*
|
||||
*
|
||||
* @endverbatim
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2022 Illia Pikin</center></h2>
|
||||
* <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||
* You may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_midi.h"
|
||||
#include "usbd_desc.h"
|
||||
#include "usbd_ctlreq.h"
|
||||
|
||||
|
||||
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MIDI
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MIDI_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MIDI_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_MIDI_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_MIDI_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
static uint8_t USBD_MIDI_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
static uint8_t USBD_MIDI_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
static uint8_t USBD_MIDI_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
static uint8_t *USBD_MIDI_GetCfgDesc (uint16_t *length);
|
||||
static uint8_t *USBD_MIDI_GetDeviceQualifierDesc (uint16_t *length);
|
||||
static uint8_t USBD_MIDI_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
static uint8_t USBD_MIDI_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_MIDI_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
static uint8_t usb_rx_buffer[MIDI_EPOUT_SIZE] = {0};
|
||||
|
||||
|
||||
/* USB MIDI class type definition */
|
||||
USBD_ClassTypeDef USBD_MIDI =
|
||||
{
|
||||
USBD_MIDI_Init,
|
||||
USBD_MIDI_DeInit,
|
||||
USBD_MIDI_Setup,
|
||||
NULL, /*EP0_TxSent*/
|
||||
NULL, /*EP0_RxReady*/
|
||||
USBD_MIDI_DataIn, /*DataIn*/
|
||||
USBD_MIDI_DataOut, /*DataOut*/
|
||||
NULL, /*SOF */
|
||||
NULL,
|
||||
NULL,
|
||||
USBD_MIDI_GetCfgDesc,
|
||||
USBD_MIDI_GetCfgDesc,
|
||||
USBD_MIDI_GetCfgDesc,
|
||||
USBD_MIDI_GetDeviceQualifierDesc,
|
||||
};
|
||||
|
||||
/* USB MIDI device Configuration Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_MIDI_CfgDesc[USB_MIDI_CONFIG_DESC_SIZE] __ALIGN_END =
|
||||
{
|
||||
0x09, /* bLength: Configuration Descriptor size */
|
||||
USB_DESC_TYPE_CONFIGURATION,/* bDescriptorType: Configuration */
|
||||
USB_MIDI_CONFIG_DESC_SIZE,
|
||||
0x00, /*Length of the total configuration block, including this descriptor, in bytes.*/
|
||||
0x01, /*bNumInterfaces: 1 interface*/
|
||||
0x01, /*bConfigurationValue: ID of this configuration. */
|
||||
0x00, /*iConfiguration: Index of string descriptor describing the configuration (Unused.)*/
|
||||
0x80, /*bmAttributes: Bus Powered device, not Self Powered, no Remote wakeup capability. */
|
||||
0xFA, /*MaxPower 500 mA: this current is used for detecting Vbus*/
|
||||
|
||||
/************** MIDI Adapter Standard MS Interface Descriptor ****************/
|
||||
0x09, /*bLength: Interface Descriptor size*/
|
||||
USB_DESC_TYPE_INTERFACE,/*bDescriptorType: Interface descriptor type*/
|
||||
0x00, /*bInterfaceNumber: Index of this interface.*/
|
||||
0x00, /*bAlternateSetting: Alternate setting*/
|
||||
0x02, /*bNumEndpoints*/
|
||||
0x01, /*bInterfaceClass: AUDIO*/
|
||||
0x03, /*bInterfaceSubClass : MIDISTREAMING*/
|
||||
0x00, /*nInterfaceProtocol : Unused*/
|
||||
0x00, /*iInterface: Unused*/
|
||||
|
||||
/******************** MIDI Adapter Class-specific MS Interface Descriptor ********************/
|
||||
/* USB_MIDI_CLASS_DESC_SHIFT */
|
||||
0x07, /*bLength: Descriptor size*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor*/
|
||||
0x01, /*bDescriptorSubtype: MS_HEADER subtype*/
|
||||
0x00,
|
||||
0x01, /*BcdADC: Revision of this class specification*/
|
||||
USB_MIDI_REPORT_DESC_SIZE,
|
||||
0x00, /*wTotalLength: Total size of class-specific descriptors*/
|
||||
|
||||
#if MIDI_IN_PORTS_NUM >= 1
|
||||
/******************** MIDI Adapter MIDI IN Jack Descriptor (External) ********************/
|
||||
0x06, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x02, /*bDescriptorSubtype: MIDI_IN_JACK subtype*/
|
||||
0x02, /*bJackType: EXTERNAL.*/
|
||||
MIDI_JACK_1, /*bJackID: ID of this Jack.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
|
||||
/******************** MIDI Adapter MIDI OUT Jack Descriptor (Embedded) ********************/
|
||||
0x09, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x03, /*bDescriptorSubtype: MIDI_OUT_JACK subtype*/
|
||||
0x01, /*bJackType: EMBEDDED*/
|
||||
MIDI_JACK_2, /*bJackID: ID of this Jack.*/
|
||||
0x01, /*bNrInputPins: Number of Input Pins of this Jack.*/
|
||||
MIDI_JACK_1, /*BaSourceID(1): ID of the Entity to which this Pin is connected.*/
|
||||
0x01, /*BaSourcePin(1): Output Pin number of the Entity to which this Input Pin is connected.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
#endif
|
||||
|
||||
#if MIDI_IN_PORTS_NUM >= 2
|
||||
/******************** MIDI Adapter MIDI IN Jack Descriptor (External) ********************/
|
||||
0x06, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x02, /*bDescriptorSubtype: MIDI_IN_JACK subtype*/
|
||||
0x02, /*bJackType: EXTERNAL.*/
|
||||
MIDI_JACK_3, /*bJackID: ID of this Jack.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
|
||||
/******************** MIDI Adapter MIDI OUT Jack Descriptor (Embedded) ********************/
|
||||
0x09, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x03, /*bDescriptorSubtype: MIDI_OUT_JACK subtype*/
|
||||
0x01, /*bJackType: EMBEDDED*/
|
||||
MIDI_JACK_4, /*bJackID: ID of this Jack.*/
|
||||
0x01, /*bNrInputPins: Number of Input Pins of this Jack.*/
|
||||
MIDI_JACK_3, /*BaSourceID(1): ID of the Entity to which this Pin is connected.*/
|
||||
0x01, /*BaSourcePin(1): Output Pin number of the Entity to which this Input Pin is connected.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
#endif
|
||||
|
||||
#if MIDI_IN_PORTS_NUM >= 3
|
||||
/******************** MIDI Adapter MIDI IN Jack Descriptor (External) ********************/
|
||||
0x06, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x02, /*bDescriptorSubtype: MIDI_IN_JACK subtype*/
|
||||
0x02, /*bJackType: EXTERNAL.*/
|
||||
MIDI_JACK_5, /*bJackID: ID of this Jack.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
|
||||
/******************** MIDI Adapter MIDI OUT Jack Descriptor (Embedded) ********************/
|
||||
0x09, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x03, /*bDescriptorSubtype: MIDI_OUT_JACK subtype*/
|
||||
0x01, /*bJackType: EMBEDDED*/
|
||||
MIDI_JACK_6, /*bJackID: ID of this Jack.*/
|
||||
0x01, /*bNrInputPins: Number of Input Pins of this Jack.*/
|
||||
MIDI_JACK_5, /*BaSourceID(1): ID of the Entity to which this Pin is connected.*/
|
||||
0x01, /*BaSourcePin(1): Output Pin number of the Entity to which this Input Pin is connected.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
#endif
|
||||
|
||||
#if MIDI_IN_PORTS_NUM >= 4
|
||||
/******************** MIDI Adapter MIDI IN Jack Descriptor (External) ********************/
|
||||
0x06, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x02, /*bDescriptorSubtype: MIDI_IN_JACK subtype*/
|
||||
0x02, /*bJackType: EXTERNAL.*/
|
||||
MIDI_JACK_7, /*bJackID: ID of this Jack.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
|
||||
/******************** MIDI Adapter MIDI OUT Jack Descriptor (Embedded) ********************/
|
||||
0x09, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x03, /*bDescriptorSubtype: MIDI_OUT_JACK subtype*/
|
||||
0x01, /*bJackType: EMBEDDED*/
|
||||
MIDI_JACK_8, /*bJackID: ID of this Jack.*/
|
||||
0x01, /*bNrInputPins: Number of Input Pins of this Jack.*/
|
||||
MIDI_JACK_7, /*BaSourceID(1): ID of the Entity to which this Pin is connected.*/
|
||||
0x01, /*BaSourcePin(1): Output Pin number of the Entity to which this Input Pin is connected.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
#endif
|
||||
|
||||
#if MIDI_IN_PORTS_NUM >= 5
|
||||
/******************** MIDI Adapter MIDI IN Jack Descriptor (External) ********************/
|
||||
0x06, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x02, /*bDescriptorSubtype: MIDI_IN_JACK subtype*/
|
||||
0x02, /*bJackType: EXTERNAL.*/
|
||||
MIDI_JACK_9, /*bJackID: ID of this Jack.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
|
||||
/******************** MIDI Adapter MIDI OUT Jack Descriptor (Embedded) ********************/
|
||||
0x09, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x03, /*bDescriptorSubtype: MIDI_OUT_JACK subtype*/
|
||||
0x01, /*bJackType: EMBEDDED*/
|
||||
MIDI_JACK_10, /*bJackID: ID of this Jack.*/
|
||||
0x01, /*bNrInputPins: Number of Input Pins of this Jack.*/
|
||||
MIDI_JACK_9, /*BaSourceID(1): ID of the Entity to which this Pin is connected.*/
|
||||
0x01, /*BaSourcePin(1): Output Pin number of the Entity to which this Input Pin is connected.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
#endif
|
||||
|
||||
#if MIDI_IN_PORTS_NUM >= 6
|
||||
/******************** MIDI Adapter MIDI IN Jack Descriptor (External) ********************/
|
||||
0x06, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x02, /*bDescriptorSubtype: MIDI_IN_JACK subtype*/
|
||||
0x02, /*bJackType: EXTERNAL.*/
|
||||
MIDI_JACK_11, /*bJackID: ID of this Jack.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
|
||||
/******************** MIDI Adapter MIDI OUT Jack Descriptor (Embedded) ********************/
|
||||
0x09, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x03, /*bDescriptorSubtype: MIDI_OUT_JACK subtype*/
|
||||
0x01, /*bJackType: EMBEDDED*/
|
||||
MIDI_JACK_12, /*bJackID: ID of this Jack.*/
|
||||
0x01, /*bNrInputPins: Number of Input Pins of this Jack.*/
|
||||
MIDI_JACK_11, /*BaSourceID(1): ID of the Entity to which this Pin is connected.*/
|
||||
0x01, /*BaSourcePin(1): Output Pin number of the Entity to which this Input Pin is connected.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
#endif
|
||||
|
||||
#if MIDI_IN_PORTS_NUM >= 7
|
||||
/******************** MIDI Adapter MIDI IN Jack Descriptor (External) ********************/
|
||||
0x06, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x02, /*bDescriptorSubtype: MIDI_IN_JACK subtype*/
|
||||
0x02, /*bJackType: EXTERNAL.*/
|
||||
MIDI_JACK_13, /*bJackID: ID of this Jack.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
|
||||
/******************** MIDI Adapter MIDI OUT Jack Descriptor (Embedded) ********************/
|
||||
0x09, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x03, /*bDescriptorSubtype: MIDI_OUT_JACK subtype*/
|
||||
0x01, /*bJackType: EMBEDDED*/
|
||||
MIDI_JACK_14, /*bJackID: ID of this Jack.*/
|
||||
0x01, /*bNrInputPins: Number of Input Pins of this Jack.*/
|
||||
MIDI_JACK_13, /*BaSourceID(1): ID of the Entity to which this Pin is connected.*/
|
||||
0x01, /*BaSourcePin(1): Output Pin number of the Entity to which this Input Pin is connected.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
#endif
|
||||
|
||||
#if MIDI_IN_PORTS_NUM >= 8
|
||||
/******************** MIDI Adapter MIDI IN Jack Descriptor (External) ********************/
|
||||
0x06, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x02, /*bDescriptorSubtype: MIDI_IN_JACK subtype*/
|
||||
0x02, /*bJackType: EXTERNAL.*/
|
||||
MIDI_JACK_15, /*bJackID: ID of this Jack.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
|
||||
/******************** MIDI Adapter MIDI OUT Jack Descriptor (Embedded) ********************/
|
||||
0x09, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x03, /*bDescriptorSubtype: MIDI_OUT_JACK subtype*/
|
||||
0x01, /*bJackType: EMBEDDED*/
|
||||
MIDI_JACK_16, /*bJackID: ID of this Jack.*/
|
||||
0x01, /*bNrInputPins: Number of Input Pins of this Jack.*/
|
||||
MIDI_JACK_15, /*BaSourceID(1): ID of the Entity to which this Pin is connected.*/
|
||||
0x01, /*BaSourcePin(1): Output Pin number of the Entity to which this Input Pin is connected.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
#endif
|
||||
|
||||
#if MIDI_OUT_PORTS_NUM >= 1
|
||||
/******************** MIDI Adapter MIDI IN Jack Descriptor (Embedded) ********************/
|
||||
0x06, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x02, /*bDescriptorSubtype: MIDI_IN_JACK subtype*/
|
||||
0x01, /*bJackType: EMBEDDED*/
|
||||
MIDI_JACK_17, /*bJackID: ID of this Jack.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
|
||||
/******************** MIDI Adapter MIDI OUT Jack Descriptor (External) ********************/
|
||||
0x09, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x03, /*bDescriptorSubtype: MIDI_OUT_JACK subtype*/
|
||||
0x02, /*bJackType: EXTERNAL.*/
|
||||
MIDI_JACK_18, /*bJackID: ID of this Jack.*/
|
||||
0x01, /*bNrInputPins: Number of Input Pins of this Jack.*/
|
||||
MIDI_JACK_17, /*BaSourceID(1): ID of the Entity to which this Pin is connected.*/
|
||||
0x01, /*BaSourcePin(1): Output Pin number of the Entity to which this Input Pin is connected.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
#endif
|
||||
|
||||
#if MIDI_OUT_PORTS_NUM >= 2
|
||||
/******************** MIDI Adapter MIDI IN Jack Descriptor (Embedded) ********************/
|
||||
0x06, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x02, /*bDescriptorSubtype: MIDI_IN_JACK subtype*/
|
||||
0x01, /*bJackType: EMBEDDED*/
|
||||
MIDI_JACK_19, /*bJackID: ID of this Jack.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
|
||||
/******************** MIDI Adapter MIDI OUT Jack Descriptor (External) ********************/
|
||||
0x09, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x03, /*bDescriptorSubtype: MIDI_OUT_JACK subtype*/
|
||||
0x02, /*bJackType: EXTERNAL.*/
|
||||
MIDI_JACK_20, /*bJackID: ID of this Jack.*/
|
||||
0x01, /*bNrInputPins: Number of Input Pins of this Jack.*/
|
||||
MIDI_JACK_19, /*BaSourceID(1): ID of the Entity to which this Pin is connected.*/
|
||||
0x01, /*BaSourcePin(1): Output Pin number of the Entity to which this Input Pin is connected.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
#endif
|
||||
|
||||
#if MIDI_OUT_PORTS_NUM >= 3
|
||||
/******************** MIDI Adapter MIDI IN Jack Descriptor (Embedded) ********************/
|
||||
0x06, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x02, /*bDescriptorSubtype: MIDI_IN_JACK subtype*/
|
||||
0x01, /*bJackType: EMBEDDED*/
|
||||
MIDI_JACK_21, /*bJackID: ID of this Jack.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
|
||||
/******************** MIDI Adapter MIDI OUT Jack Descriptor (External) ********************/
|
||||
0x09, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x03, /*bDescriptorSubtype: MIDI_OUT_JACK subtype*/
|
||||
0x02, /*bJackType: EXTERNAL.*/
|
||||
MIDI_JACK_22, /*bJackID: ID of this Jack.*/
|
||||
0x01, /*bNrInputPins: Number of Input Pins of this Jack.*/
|
||||
MIDI_JACK_21, /*BaSourceID(1): ID of the Entity to which this Pin is connected.*/
|
||||
0x01, /*BaSourcePin(1): Output Pin number of the Entity to which this Input Pin is connected.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
#endif
|
||||
|
||||
#if MIDI_OUT_PORTS_NUM >= 4
|
||||
/******************** MIDI Adapter MIDI IN Jack Descriptor (Embedded) ********************/
|
||||
0x06, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x02, /*bDescriptorSubtype: MIDI_IN_JACK subtype*/
|
||||
0x01, /*bJackType: EMBEDDED*/
|
||||
MIDI_JACK_23, /*bJackID: ID of this Jack.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
|
||||
/******************** MIDI Adapter MIDI OUT Jack Descriptor (External) ********************/
|
||||
0x09, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x03, /*bDescriptorSubtype: MIDI_OUT_JACK subtype*/
|
||||
0x02, /*bJackType: EXTERNAL.*/
|
||||
MIDI_JACK_24, /*bJackID: ID of this Jack.*/
|
||||
0x01, /*bNrInputPins: Number of Input Pins of this Jack.*/
|
||||
MIDI_JACK_23, /*BaSourceID(1): ID of the Entity to which this Pin is connected.*/
|
||||
0x01, /*BaSourcePin(1): Output Pin number of the Entity to which this Input Pin is connected.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
#endif
|
||||
|
||||
#if MIDI_OUT_PORTS_NUM >= 5
|
||||
/******************** MIDI Adapter MIDI IN Jack Descriptor (Embedded) ********************/
|
||||
0x06, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x02, /*bDescriptorSubtype: MIDI_IN_JACK subtype*/
|
||||
0x01, /*bJackType: EMBEDDED*/
|
||||
MIDI_JACK_25, /*bJackID: ID of this Jack.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
|
||||
/******************** MIDI Adapter MIDI OUT Jack Descriptor (External) ********************/
|
||||
0x09, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x03, /*bDescriptorSubtype: MIDI_OUT_JACK subtype*/
|
||||
0x02, /*bJackType: EXTERNAL.*/
|
||||
MIDI_JACK_26, /*bJackID: ID of this Jack.*/
|
||||
0x01, /*bNrInputPins: Number of Input Pins of this Jack.*/
|
||||
MIDI_JACK_25, /*BaSourceID(1): ID of the Entity to which this Pin is connected.*/
|
||||
0x01, /*BaSourcePin(1): Output Pin number of the Entity to which this Input Pin is connected.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
#endif
|
||||
|
||||
#if MIDI_OUT_PORTS_NUM >= 6
|
||||
/******************** MIDI Adapter MIDI IN Jack Descriptor (Embedded) ********************/
|
||||
0x06, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x02, /*bDescriptorSubtype: MIDI_IN_JACK subtype*/
|
||||
0x01, /*bJackType: EMBEDDED*/
|
||||
MIDI_JACK_27, /*bJackID: ID of this Jack.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
|
||||
/******************** MIDI Adapter MIDI OUT Jack Descriptor (External) ********************/
|
||||
0x09, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x03, /*bDescriptorSubtype: MIDI_OUT_JACK subtype*/
|
||||
0x02, /*bJackType: EXTERNAL.*/
|
||||
MIDI_JACK_28, /*bJackID: ID of this Jack.*/
|
||||
0x01, /*bNrInputPins: Number of Input Pins of this Jack.*/
|
||||
MIDI_JACK_27, /*BaSourceID(1): ID of the Entity to which this Pin is connected.*/
|
||||
0x01, /*BaSourcePin(1): Output Pin number of the Entity to which this Input Pin is connected.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
#endif
|
||||
|
||||
#if MIDI_OUT_PORTS_NUM >= 7
|
||||
/******************** MIDI Adapter MIDI IN Jack Descriptor (Embedded) ********************/
|
||||
0x06, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x02, /*bDescriptorSubtype: MIDI_IN_JACK subtype*/
|
||||
0x01, /*bJackType: EMBEDDED*/
|
||||
MIDI_JACK_29, /*bJackID: ID of this Jack.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
|
||||
/******************** MIDI Adapter MIDI OUT Jack Descriptor (External) ********************/
|
||||
0x09, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x03, /*bDescriptorSubtype: MIDI_OUT_JACK subtype*/
|
||||
0x02, /*bJackType: EXTERNAL.*/
|
||||
MIDI_JACK_30, /*bJackID: ID of this Jack.*/
|
||||
0x01, /*bNrInputPins: Number of Input Pins of this Jack.*/
|
||||
MIDI_JACK_29, /*BaSourceID(1): ID of the Entity to which this Pin is connected.*/
|
||||
0x01, /*BaSourcePin(1): Output Pin number of the Entity to which this Input Pin is connected.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
#endif
|
||||
|
||||
#if MIDI_OUT_PORTS_NUM >= 8
|
||||
/******************** MIDI Adapter MIDI IN Jack Descriptor (Embedded) ********************/
|
||||
0x06, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x02, /*bDescriptorSubtype: MIDI_IN_JACK subtype*/
|
||||
0x01, /*bJackType: EMBEDDED*/
|
||||
MIDI_JACK_31, /*bJackID: ID of this Jack.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
|
||||
/******************** MIDI Adapter MIDI OUT Jack Descriptor (External) ********************/
|
||||
0x09, /*bLength: Size of this descriptor, in bytes*/
|
||||
0x24, /*bDescriptorType: CS_INTERFACE descriptor.*/
|
||||
0x03, /*bDescriptorSubtype: MIDI_OUT_JACK subtype*/
|
||||
0x02, /*bJackType: EXTERNAL.*/
|
||||
MIDI_JACK_32, /*bJackID: ID of this Jack.*/
|
||||
0x01, /*bNrInputPins: Number of Input Pins of this Jack.*/
|
||||
MIDI_JACK_31, /*BaSourceID(1): ID of the Entity to which this Pin is connected.*/
|
||||
0x01, /*BaSourcePin(1): Output Pin number of the Entity to which this Input Pin is connected.*/
|
||||
0x00, /*iJack: Unused.*/
|
||||
#endif
|
||||
|
||||
/******************** MIDI Adapter Standard Bulk OUT Endpoint Descriptor ********************/
|
||||
0x09, /*bLength: Size of this descriptor, in bytes*/
|
||||
USB_DESC_TYPE_ENDPOINT, /*bDescriptorType: ENDPOINT descriptor.*/
|
||||
MIDI_EPOUT_ADDR, /*bEndpointAddress: OUT Endpoint 1.*/
|
||||
0x02, /*bmAttributes: Bulk, not shared.*/
|
||||
MIDI_EPOUT_SIZE,
|
||||
0x00, /*wMaxPacketSize*/
|
||||
0x00, /*bInterval: Ignored for Bulk. Set to zero.*/
|
||||
0x00, /*bRefresh: Unused.*/
|
||||
0x00, /*bSynchAddress: Unused.*/
|
||||
|
||||
/******************** MIDI Adapter Class-specific Bulk OUT Endpoint Descriptor ********************/
|
||||
(4 + MIDI_OUT_PORTS_NUM), /*bLength: Size of this descriptor, in bytes*/
|
||||
0x25, /*bDescriptorType: CS_ENDPOINT descriptor*/
|
||||
0x01, /*bDescriptorSubtype: MS_GENERAL subtype.*/
|
||||
MIDI_OUT_PORTS_NUM, /*bNumEmbMIDIJack: Number of embedded MIDI IN Jacks.*/
|
||||
#if MIDI_OUT_PORTS_NUM >= 1
|
||||
MIDI_JACK_17, /*BaAssocJackID(1): ID of the Embedded MIDI IN Jack.*/
|
||||
#endif
|
||||
#if MIDI_OUT_PORTS_NUM >= 2
|
||||
MIDI_JACK_19, /*BaAssocJackID(2): ID of the Embedded MIDI IN Jack.*/
|
||||
#endif
|
||||
#if MIDI_OUT_PORTS_NUM >= 3
|
||||
MIDI_JACK_21, /*BaAssocJackID(3): ID of the Embedded MIDI IN Jack.*/
|
||||
#endif
|
||||
#if MIDI_OUT_PORTS_NUM >= 4
|
||||
MIDI_JACK_23, /*BaAssocJackID(4): ID of the Embedded MIDI IN Jack.*/
|
||||
#endif
|
||||
#if MIDI_OUT_PORTS_NUM >= 5
|
||||
MIDI_JACK_25, /*BaAssocJackID(5): ID of the Embedded MIDI IN Jack.*/
|
||||
#endif
|
||||
#if MIDI_OUT_PORTS_NUM >= 6
|
||||
MIDI_JACK_27, /*BaAssocJackID(6): ID of the Embedded MIDI IN Jack.*/
|
||||
#endif
|
||||
#if MIDI_OUT_PORTS_NUM >= 7
|
||||
MIDI_JACK_29, /*BaAssocJackID(7): ID of the Embedded MIDI IN Jack.*/
|
||||
#endif
|
||||
#if MIDI_OUT_PORTS_NUM >= 8
|
||||
MIDI_JACK_31, /*BaAssocJackID(8): ID of the Embedded MIDI IN Jack.*/
|
||||
#endif
|
||||
|
||||
/******************** MIDI Adapter Standard Bulk IN Endpoint Descriptor ********************/
|
||||
0x09, /*bLength: Size of this descriptor, in bytes*/
|
||||
USB_DESC_TYPE_ENDPOINT, /*bDescriptorType: ENDPOINT descriptor.*/
|
||||
MIDI_EPIN_ADDR, /*bEndpointAddress: IN Endpoint 1.*/
|
||||
0x02, /*bmAttributes: Bulk, not shared.*/
|
||||
MIDI_EPIN_SIZE,
|
||||
0x00, /*wMaxPacketSize*/
|
||||
0x00, /*bInterval: Ignored for Bulk. Set to zero.*/
|
||||
0x00, /*bRefresh: Unused.*/
|
||||
0x00, /*bSynchAddress: Unused.*/
|
||||
|
||||
/******************** MIDI Adapter Class-specific Bulk IN Endpoint Descriptor ********************/
|
||||
(4 + MIDI_IN_PORTS_NUM), /*bLength: Size of this descriptor, in bytes*/
|
||||
0x25, /*bDescriptorType: CS_ENDPOINT descriptor*/
|
||||
0x01, /*bDescriptorSubtype: MS_GENERAL subtype.*/
|
||||
MIDI_IN_PORTS_NUM, /*bNumEmbMIDIJack: Number of embedded MIDI OUT Jacks.*/
|
||||
#if MIDI_IN_PORTS_NUM >= 1
|
||||
MIDI_JACK_2, /*BaAssocJackID(1): ID of the Embedded MIDI OUT Jack.*/
|
||||
#endif
|
||||
#if MIDI_IN_PORTS_NUM >= 2
|
||||
MIDI_JACK_4, /*BaAssocJackID(2): ID of the Embedded MIDI OUT Jack.*/
|
||||
#endif
|
||||
#if MIDI_IN_PORTS_NUM >= 3
|
||||
MIDI_JACK_6, /*BaAssocJackID(3): ID of the Embedded MIDI OUT Jack.*/
|
||||
#endif
|
||||
#if MIDI_IN_PORTS_NUM >= 4
|
||||
MIDI_JACK_8, /*BaAssocJackID(4): ID of the Embedded MIDI OUT Jack.*/
|
||||
#endif
|
||||
#if MIDI_IN_PORTS_NUM >= 5
|
||||
MIDI_JACK_10, /*BaAssocJackID(5): ID of the Embedded MIDI OUT Jack.*/
|
||||
#endif
|
||||
#if MIDI_IN_PORTS_NUM >= 6
|
||||
MIDI_JACK_12, /*BaAssocJackID(6): ID of the Embedded MIDI OUT Jack.*/
|
||||
#endif
|
||||
#if MIDI_IN_PORTS_NUM >= 7
|
||||
MIDI_JACK_14, /*BaAssocJackID(7): ID of the Embedded MIDI OUT Jack.*/
|
||||
#endif
|
||||
#if MIDI_IN_PORTS_NUM >= 8
|
||||
MIDI_JACK_16, /*BaAssocJackID(8): ID of the Embedded MIDI OUT Jack.*/
|
||||
#endif
|
||||
};
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_MIDI_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_MIDI_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_MIDI_Init
|
||||
* Initialize the MIDI interface
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_MIDI_Init (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
|
||||
USBD_LL_OpenEP(pdev,
|
||||
MIDI_EPIN_ADDR,
|
||||
USBD_EP_TYPE_BULK,
|
||||
MIDI_EPIN_SIZE);
|
||||
|
||||
USBD_LL_OpenEP(pdev,
|
||||
MIDI_EPOUT_ADDR,
|
||||
USBD_EP_TYPE_BULK,
|
||||
MIDI_EPOUT_SIZE);
|
||||
|
||||
USBD_LL_PrepareReceive(pdev,
|
||||
MIDI_EPOUT_ADDR,
|
||||
usb_rx_buffer,
|
||||
MIDI_EPOUT_SIZE);
|
||||
|
||||
pdev->pClassData = USBD_malloc(sizeof (USBD_MIDI_HandleTypeDef));
|
||||
|
||||
if(pdev->pClassData == NULL)
|
||||
{
|
||||
ret = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
((USBD_MIDI_HandleTypeDef *)pdev->pClassData)->state = MIDI_IDLE;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MIDI_Init
|
||||
* DeInitialize the MIDI layer
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_MIDI_DeInit (USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx)
|
||||
{
|
||||
/* Close MIDI EPs */
|
||||
USBD_LL_CloseEP(pdev, MIDI_EPIN_SIZE);
|
||||
|
||||
/* FRee allocated memory */
|
||||
if(pdev->pClassData != NULL)
|
||||
{
|
||||
USBD_free(pdev->pClassData);
|
||||
pdev->pClassData = NULL;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MIDI_Setup
|
||||
* Handle the MIDI specific requests
|
||||
* @param pdev: instance
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_MIDI_Setup (USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
uint16_t len = 0;
|
||||
uint8_t *pbuf = NULL;
|
||||
USBD_MIDI_HandleTypeDef *hmidi = pdev->pClassData;
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case MIDI_REQ_SET_PROTOCOL:
|
||||
hmidi->Protocol = (uint8_t)(req->wValue);
|
||||
break;
|
||||
|
||||
case MIDI_REQ_GET_PROTOCOL:
|
||||
USBD_CtlSendData (pdev,
|
||||
(uint8_t *)&hmidi->Protocol,
|
||||
1);
|
||||
break;
|
||||
|
||||
case MIDI_REQ_SET_IDLE:
|
||||
hmidi->IdleState = (uint8_t)(req->wValue >> 8);
|
||||
break;
|
||||
|
||||
case MIDI_REQ_GET_IDLE:
|
||||
USBD_CtlSendData (pdev,
|
||||
(uint8_t *)&hmidi->IdleState,
|
||||
1);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError (pdev, req);
|
||||
return USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_DESCRIPTOR:
|
||||
if( req->wValue >> 8 == MIDI_DESCRIPTOR_TYPE)
|
||||
{
|
||||
pbuf = USBD_MIDI_CfgDesc + USB_MIDI_CLASS_DESC_SHIFT;
|
||||
len = MIN(USB_MIDI_DESC_SIZE , req->wLength);
|
||||
}
|
||||
|
||||
USBD_CtlSendData (pdev, pbuf, len);
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE :
|
||||
USBD_CtlSendData (pdev,
|
||||
(uint8_t *)&hmidi->AltSetting,
|
||||
1);
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE :
|
||||
hmidi->AltSetting = (uint8_t)(req->wValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MIDI_GetDeviceState
|
||||
* Get MIDI State
|
||||
* @param pdev: device instance
|
||||
* @retval usb device state (USBD_STATE_DEFAULT, USBD_STATE_ADDRESSED, USBD_STATE_CONFIGURED, USBD_STATE_SUSPENDED)
|
||||
*/
|
||||
uint8_t USBD_MIDI_GetDeviceState(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
return pdev->dev_state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MIDI_GetState
|
||||
* Get MIDI State
|
||||
* @param pdev: device instance
|
||||
* @retval usb state (MIDI_IDLE, MIDI_BUSY)
|
||||
*/
|
||||
uint8_t USBD_MIDI_GetState(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
return ((USBD_MIDI_HandleTypeDef *)pdev->pClassData)->state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MIDI_SendReport
|
||||
* Send MIDI Report
|
||||
* @param pdev: device instance
|
||||
* @param report: pointer to report
|
||||
* @param len: size of report
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_MIDI_SendReport (USBD_HandleTypeDef *pdev,
|
||||
uint8_t *report,
|
||||
uint16_t len)
|
||||
{
|
||||
USBD_MIDI_HandleTypeDef *hmidi = pdev->pClassData;
|
||||
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
if(hmidi->state == MIDI_IDLE)
|
||||
{
|
||||
hmidi->state = MIDI_BUSY;
|
||||
USBD_LL_Transmit (pdev, MIDI_EPIN_ADDR, report, len);
|
||||
}
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MIDI_GetCfgDesc
|
||||
* return configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_MIDI_GetCfgDesc (uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_MIDI_CfgDesc);
|
||||
return USBD_MIDI_CfgDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_MIDI_DeviceQualifierDescriptor (uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_MIDI_DeviceQualifierDesc);
|
||||
return USBD_MIDI_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_MIDI_DataIn
|
||||
* handle data IN Stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_MIDI_DataIn (USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
{
|
||||
|
||||
/* Ensure that the FIFO is empty before a new transfer, this condition could
|
||||
be caused by a new transfer before the end of the previous transfer */
|
||||
((USBD_MIDI_HandleTypeDef *)pdev->pClassData)->state = MIDI_IDLE;
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MIDI_DataOut
|
||||
* handle data OUT Stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_MIDI_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
if (epnum != (MIDI_EPOUT_ADDR & 0x0F)) return USBD_FAIL;
|
||||
|
||||
USBD_MIDI_DataInHandler(usb_rx_buffer, MIDI_EPOUT_SIZE);
|
||||
|
||||
memset(usb_rx_buffer, 0, MIDI_EPOUT_SIZE);
|
||||
|
||||
USBD_LL_PrepareReceive(pdev, MIDI_EPOUT_ADDR, usb_rx_buffer, MIDI_EPOUT_SIZE);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_MIDI_DataInHandler
|
||||
* @param usb_rx_buffer: midi messages buffer
|
||||
* @param usb_rx_buffer_length: midi messages buffer length
|
||||
*/
|
||||
__weak extern void USBD_MIDI_DataInHandler(uint8_t * usb_rx_buffer, uint8_t usb_rx_buffer_length)
|
||||
{
|
||||
// For user implementation.
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_MIDI_GetDeviceQualifierDesc (uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_MIDI_DeviceQualifierDesc);
|
||||
return USBD_MIDI_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
175
P7_SETR1/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h
Executable file
175
P7_SETR1/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h
Executable file
@@ -0,0 +1,175 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @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 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 __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);
|
||||
#if (USBD_USER_REGISTER_CALLBACK == 1U)
|
||||
USBD_StatusTypeDef USBD_RegisterDevStateCallback(USBD_HandleTypeDef *pdev, USBD_DevStateCallbackTypeDef pUserCallback);
|
||||
#endif /* USBD_USER_REGISTER_CALLBACK */
|
||||
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
USBD_StatusTypeDef USBD_RegisterClassComposite(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass,
|
||||
USBD_CompositeClassTypeDef classtype, uint8_t *EpAddr);
|
||||
|
||||
USBD_StatusTypeDef USBD_UnRegisterClassComposite(USBD_HandleTypeDef *pdev);
|
||||
uint8_t USBD_CoreGetEPAdd(USBD_HandleTypeDef *pdev, uint8_t ep_dir, uint8_t ep_type, uint8_t ClassId);
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
uint8_t USBD_CoreFindIF(USBD_HandleTypeDef *pdev, uint8_t index);
|
||||
uint8_t USBD_CoreFindEP(USBD_HandleTypeDef *pdev, uint8_t index);
|
||||
|
||||
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);
|
||||
|
||||
#ifdef USBD_HS_TESTMODE_ENABLE
|
||||
USBD_StatusTypeDef USBD_LL_SetTestMode(USBD_HandleTypeDef *pdev, uint8_t testmode);
|
||||
#endif /* USBD_HS_TESTMODE_ENABLE */
|
||||
|
||||
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);
|
||||
|
||||
void *USBD_GetEpDesc(uint8_t *pConfDesc, uint8_t EpAddr);
|
||||
USBD_DescHeaderTypeDef *USBD_GetNextDesc(uint8_t *pbuf, uint16_t *ptr);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_CORE_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
101
P7_SETR1/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h
Executable file
101
P7_SETR1/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h
Executable file
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @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 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 __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 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
523
P7_SETR1/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h
Executable file
523
P7_SETR1/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h
Executable file
@@ -0,0 +1,523 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @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 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 __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 */
|
||||
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
#ifndef USBD_MAX_SUPPORTED_CLASS
|
||||
#define USBD_MAX_SUPPORTED_CLASS 4U
|
||||
#endif /* USBD_MAX_SUPPORTED_CLASS */
|
||||
#else
|
||||
#ifndef USBD_MAX_SUPPORTED_CLASS
|
||||
#define USBD_MAX_SUPPORTED_CLASS 1U
|
||||
#endif /* USBD_MAX_SUPPORTED_CLASS */
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
#ifndef USBD_MAX_CLASS_ENDPOINTS
|
||||
#define USBD_MAX_CLASS_ENDPOINTS 5U
|
||||
#endif /* USBD_MAX_CLASS_ENDPOINTS */
|
||||
|
||||
#ifndef USBD_MAX_CLASS_INTERFACES
|
||||
#define USBD_MAX_CLASS_INTERFACES 5U
|
||||
#endif /* USBD_MAX_CLASS_INTERFACES */
|
||||
|
||||
#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
|
||||
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
#define USBD_EP_IN 0x80U
|
||||
#define USBD_EP_OUT 0x00U
|
||||
#define USBD_FUNC_DESCRIPTOR_TYPE 0x24U
|
||||
#define USBD_DESC_SUBTYPE_ACM 0x0FU
|
||||
#define USBD_DESC_ECM_BCD_LOW 0x00U
|
||||
#define USBD_DESC_ECM_BCD_HIGH 0x10U
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @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;
|
||||
} __PACKED 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;
|
||||
} __PACKED USBD_EpDescTypeDef;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bDescriptorSubType;
|
||||
} USBD_DescHeaderTypeDef;
|
||||
|
||||
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_SUPPORT_USER_STRING_DESC */
|
||||
|
||||
} 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 /* USBD_CLASS_USER_STRING_DESC */
|
||||
#if ((USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1))
|
||||
uint8_t *(*GetBOSDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
#endif /* (USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1) */
|
||||
} 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;
|
||||
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
typedef enum
|
||||
{
|
||||
CLASS_TYPE_NONE = 0,
|
||||
CLASS_TYPE_HID = 1,
|
||||
CLASS_TYPE_CDC = 2,
|
||||
CLASS_TYPE_MSC = 3,
|
||||
CLASS_TYPE_DFU = 4,
|
||||
CLASS_TYPE_CHID = 5,
|
||||
CLASS_TYPE_AUDIO = 6,
|
||||
CLASS_TYPE_ECM = 7,
|
||||
CLASS_TYPE_RNDIS = 8,
|
||||
CLASS_TYPE_MTP = 9,
|
||||
CLASS_TYPE_VIDEO = 10,
|
||||
CLASS_TYPE_PRINTER = 11,
|
||||
CLASS_TYPE_CCID = 12,
|
||||
} USBD_CompositeClassTypeDef;
|
||||
|
||||
|
||||
/* USB Device handle structure */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t add;
|
||||
uint8_t type;
|
||||
uint8_t size;
|
||||
uint8_t is_used;
|
||||
} USBD_EPTypeDef;
|
||||
|
||||
/* USB Device handle structure */
|
||||
typedef struct
|
||||
{
|
||||
USBD_CompositeClassTypeDef ClassType;
|
||||
uint32_t ClassId;
|
||||
uint32_t Active;
|
||||
uint32_t NumEps;
|
||||
USBD_EPTypeDef Eps[USBD_MAX_CLASS_ENDPOINTS];
|
||||
uint8_t *EpAdd;
|
||||
uint32_t NumIf;
|
||||
uint8_t Ifs[USBD_MAX_CLASS_INTERFACES];
|
||||
uint32_t CurrPcktSze;
|
||||
} USBD_CompositeElementTypeDef;
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
|
||||
/* 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[USBD_MAX_SUPPORTED_CLASS];
|
||||
void *pClassData;
|
||||
void *pClassDataCmsit[USBD_MAX_SUPPORTED_CLASS];
|
||||
void *pUserData[USBD_MAX_SUPPORTED_CLASS];
|
||||
void *pData;
|
||||
void *pBosDesc;
|
||||
void *pConfDesc;
|
||||
uint32_t classId;
|
||||
uint32_t NumClasses;
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
USBD_CompositeElementTypeDef tclasslist[USBD_MAX_SUPPORTED_CLASS];
|
||||
#endif /* USE_USBD_COMPOSITE */
|
||||
#if (USBD_USER_REGISTER_CALLBACK == 1U)
|
||||
void (* DevStateCallback)(uint8_t dev_state, uint8_t cfgidx); /*!< User Notification callback */
|
||||
#endif /* USBD_USER_REGISTER_CALLBACK */
|
||||
} USBD_HandleTypeDef;
|
||||
|
||||
#if (USBD_USER_REGISTER_CALLBACK == 1U)
|
||||
typedef void (*USBD_DevStateCallbackTypeDef)(uint8_t dev_state, uint8_t cfgidx); /*!< pointer to User callback function */
|
||||
#endif /* USBD_USER_REGISTER_CALLBACK */
|
||||
|
||||
/* USB Device endpoint direction */
|
||||
typedef enum
|
||||
{
|
||||
OUT = 0x00,
|
||||
IN = 0x80,
|
||||
} USBD_EPDirectionTypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
NETWORK_CONNECTION = 0x00,
|
||||
RESPONSE_AVAILABLE = 0x01,
|
||||
CONNECTION_SPEED_CHANGE = 0x2A
|
||||
} USBD_CDC_NotifCodeTypeDef;
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_DEF_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
__STATIC_INLINE uint16_t SWAPBYTE(uint8_t *addr)
|
||||
{
|
||||
uint16_t _SwapVal;
|
||||
uint16_t _Byte1;
|
||||
uint16_t _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 /* LOBYTE */
|
||||
|
||||
#ifndef HIBYTE
|
||||
#define HIBYTE(x) ((uint8_t)(((x) & 0xFF00U) >> 8U))
|
||||
#endif /* HIBYTE */
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif /* MIN */
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#endif /* MAX */
|
||||
|
||||
#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 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
113
P7_SETR1/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h
Executable file
113
P7_SETR1/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h
Executable file
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @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 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 __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 */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
1215
P7_SETR1/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c
Executable file
1215
P7_SETR1/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c
Executable file
File diff suppressed because it is too large
Load Diff
1058
P7_SETR1/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c
Executable file
1058
P7_SETR1/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c
Executable file
File diff suppressed because it is too large
Load Diff
224
P7_SETR1/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c
Executable file
224
P7_SETR1/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c
Executable file
@@ -0,0 +1,224 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @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 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* 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 /* USBD_AVOID_PACKET_SPLIT_MPS */
|
||||
|
||||
/* 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 /* USBD_AVOID_PACKET_SPLIT_MPS */
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
86
P7_SETR1/Middlewares/ST/STM32_USB_Device_Library/LICENSE.txt
Executable file
86
P7_SETR1/Middlewares/ST/STM32_USB_Device_Library/LICENSE.txt
Executable file
@@ -0,0 +1,86 @@
|
||||
This software component is provided to you as part of a software package and
|
||||
applicable license terms are in the Package_license file. If you received this
|
||||
software component outside of a package or without applicable license terms,
|
||||
the terms of the SLA0044 license shall apply and are fully reproduced below:
|
||||
|
||||
SLA0044 Rev5/February 2018
|
||||
|
||||
Software license agreement
|
||||
|
||||
ULTIMATE LIBERTY SOFTWARE LICENSE AGREEMENT
|
||||
|
||||
BY INSTALLING, COPYING, DOWNLOADING, ACCESSING OR OTHERWISE USING THIS SOFTWARE
|
||||
OR ANY PART THEREOF (AND THE RELATED DOCUMENTATION) FROM STMICROELECTRONICS
|
||||
INTERNATIONAL N.V, SWISS BRANCH AND/OR ITS AFFILIATED COMPANIES
|
||||
(STMICROELECTRONICS), THE RECIPIENT, ON BEHALF OF HIMSELF OR HERSELF, OR ON
|
||||
BEHALF OF ANY ENTITY BY WHICH SUCH RECIPIENT IS EMPLOYED AND/OR ENGAGED AGREES
|
||||
TO BE BOUND BY THIS SOFTWARE LICENSE AGREEMENT.
|
||||
|
||||
Under STMicroelectronics’ intellectual property rights, the redistribution,
|
||||
reproduction and use in source and binary forms of the software or any part
|
||||
thereof, with or without modification, are permitted provided that the following
|
||||
conditions are met:
|
||||
|
||||
1. Redistribution of source code (modified or not) must retain any copyright
|
||||
notice, this list of conditions and the disclaimer set forth below as items 10
|
||||
and 11.
|
||||
|
||||
2. Redistributions in binary form, except as embedded into microcontroller or
|
||||
microprocessor device manufactured by or for STMicroelectronics or a software
|
||||
update for such device, must reproduce any copyright notice provided with the
|
||||
binary code, this list of conditions, and the disclaimer set forth below as
|
||||
items 10 and 11, in documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
3. Neither the name of STMicroelectronics nor the names of other contributors to
|
||||
this software may be used to endorse or promote products derived from this
|
||||
software or part thereof without specific written permission.
|
||||
|
||||
4. This software or any part thereof, including modifications and/or derivative
|
||||
works of this software, must be used and execute solely and exclusively on or in
|
||||
combination with a microcontroller or microprocessor device manufactured by or
|
||||
for STMicroelectronics.
|
||||
|
||||
5. No use, reproduction or redistribution of this software partially or totally
|
||||
may be done in any manner that would subject this software to any Open Source
|
||||
Terms. “Open Source Terms” shall mean any open source license which requires as
|
||||
part of distribution of software that the source code of such software is
|
||||
distributed therewith or otherwise made available, or open source license that
|
||||
substantially complies with the Open Source definition specified at
|
||||
www.opensource.org and any other comparable open source license such as for
|
||||
example GNU General Public License (GPL), Eclipse Public License (EPL), Apache
|
||||
Software License, BSD license or MIT license.
|
||||
|
||||
6. STMicroelectronics has no obligation to provide any maintenance, support or
|
||||
updates for the software.
|
||||
|
||||
7. The software is and will remain the exclusive property of STMicroelectronics
|
||||
and its licensors. The recipient will not take any action that jeopardizes
|
||||
STMicroelectronics and its licensors' proprietary rights or acquire any rights
|
||||
in the software, except the limited rights specified hereunder.
|
||||
|
||||
8. The recipient shall comply with all applicable laws and regulations affecting
|
||||
the use of the software or any part thereof including any applicable export
|
||||
control law or regulation.
|
||||
|
||||
9. Redistribution and use of this software or any part thereof other than as
|
||||
permitted under this license is void and will automatically terminate your
|
||||
rights under this license.
|
||||
|
||||
10. THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY RIGHTS, WHICH ARE
|
||||
DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT SHALL
|
||||
STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
11. EXCEPT AS EXPRESSLY PERMITTED HEREUNDER, NO LICENSE OR OTHER RIGHTS, WHETHER
|
||||
EXPRESS OR IMPLIED, ARE GRANTED UNDER ANY PATENT OR OTHER INTELLECTUAL PROPERTY
|
||||
RIGHTS OF STMICROELECTRONICS OR ANY THIRD PARTY.
|
||||
|
||||
Reference in New Issue
Block a user