pcan_cantact_another_one/Src/usbd_desc.c

95 lines
3.1 KiB
C
Raw Normal View History

2020-06-03 04:33:18 -07:00
#include "usbd_core.h"
#include "usbd_conf.h"
#define USBD_VID 0x0C72
#define USBD_PID_FS 0x000C
#define USBD_LANGID_STRING 1033
#define USBD_MAX_STR_DESC_SIZ 0x100U
uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
uint8_t * USBD_FS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
uint8_t * USBD_FS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
uint8_t * USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
__ALIGN_BEGIN uint8_t USBD_FS_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
{
0x12, /*bLength */
USB_DESC_TYPE_DEVICE, /*bDescriptorType*/
0x00, /*bcdUSB */
0x01,
0x00, /*bDeviceClass*/
0x00, /*bDeviceSubClass*/
0x00, /*bDeviceProtocol*/
USB_MAX_EP0_SIZE, /*bMaxPacketSize*/
LOBYTE(USBD_VID), /*idVendor*/
HIBYTE(USBD_VID), /*idVendor*/
LOBYTE(USBD_PID_FS), /*idProduct*/
HIBYTE(USBD_PID_FS), /*idProduct*/
0xff, /*bcdDevice*/
0x54,
10, /*Index of manufacturer string*/
4, /*Index of product string*/
0, /*Index of serial number string*/
USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/
};
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
{
USB_LEN_LANGID_STR_DESC,
USB_DESC_TYPE_STRING,
LOBYTE(USBD_LANGID_STRING),
HIBYTE(USBD_LANGID_STRING)
};
/* internal string descriptor */
__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
uint8_t * USBD_FS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
UNUSED(speed);
*length = sizeof(USBD_FS_DeviceDesc);
return USBD_FS_DeviceDesc;
}
uint8_t * USBD_FS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
UNUSED(speed);
*length = sizeof(USBD_LangIDDesc);
return USBD_LangIDDesc;
}
/* must be here: 1, 2 */
uint8_t * USBD_FS_HugeStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
UNUSED( speed );
memset( USBD_StrDesc, 0x00, 254 );
*length = 252+2;
USBD_StrDesc[0] = ( 252 + 2 );
USBD_StrDesc[1] = USB_DESC_TYPE_STRING;
return USBD_StrDesc;
}
uint8_t * USBD_FS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
UNUSED(speed);
USBD_GetString((uint8_t *)"PCAN-USB", USBD_StrDesc, length);
return USBD_StrDesc;
}
USBD_DescriptorsTypeDef FS_Desc =
{
.GetDeviceDescriptor = USBD_FS_DeviceDescriptor,
.GetLangIDStrDescriptor = USBD_FS_LangIDStrDescriptor,
.GetManufacturerStrDescriptor = USBD_FS_HugeStrDescriptor,
.GetProductStrDescriptor = USBD_FS_HugeStrDescriptor,
.GetSerialStrDescriptor = 0,
.GetConfigurationStrDescriptor = USBD_FS_ConfigStrDescriptor,
.GetInterfaceStrDescriptor = 0,
};