mirror of
https://github.com/XIVN1987/DAPLink.git
synced 2026-09-26 22:16:11 +00:00
add CH32V203 WINUSB support
This commit is contained in:
@@ -653,6 +653,13 @@ void Data_Setup0(void)
|
||||
{
|
||||
CopyRoutine = pProperty->GetConfigDescriptor;
|
||||
}
|
||||
#ifndef DAP_FW_V1
|
||||
else if (wValue1 == DESC_BOS)
|
||||
{
|
||||
uint8_t *USBD_GetBOSDescriptor(uint16_t Length);
|
||||
CopyRoutine = USBD_GetBOSDescriptor;
|
||||
}
|
||||
#endif
|
||||
else if (wValue1 == STRING_DESCRIPTOR)
|
||||
{
|
||||
CopyRoutine = pProperty->GetStringDescriptor;
|
||||
@@ -717,6 +724,14 @@ void Data_Setup0(void)
|
||||
}
|
||||
|
||||
}
|
||||
#ifndef DAP_FW_V1
|
||||
else if((Type_Recipient & REQUEST_TYPE) == VENDOR_REQUEST)
|
||||
{
|
||||
uint8_t *USBD_MS_OS_20_DescriptorSet(uint16_t Length);
|
||||
if((Request_No == WINUSB_VENDOR_CODE) && (pInformation->USBwIndex0 == 7))
|
||||
CopyRoutine = USBD_MS_OS_20_DescriptorSet;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (CopyRoutine)
|
||||
{
|
||||
|
||||
@@ -69,6 +69,13 @@
|
||||
|
||||
|
||||
|
||||
#define DESC_BOS 0x0F
|
||||
#define DESC_CAPABILITY 0x10
|
||||
|
||||
#define WINUSB_VENDOR_CODE 0x34
|
||||
|
||||
|
||||
|
||||
#include "ch32v20x.h"
|
||||
|
||||
void Delay_Ms(uint32_t n);
|
||||
|
||||
@@ -57,7 +57,7 @@ const uint8_t USBD_ConfigDescriptor[] = {
|
||||
#endif
|
||||
0x00, // bInterfaceSubClass
|
||||
0x00, // bInterfaceProtocol
|
||||
0x00, // iInterface
|
||||
0x04, // iInterface
|
||||
|
||||
#ifdef DAP_FW_V1
|
||||
// HID Descriptor
|
||||
@@ -208,6 +208,13 @@ uint8_t USBD_StringSerial[] = {
|
||||
};
|
||||
|
||||
|
||||
const uint8_t USBD_StringInterface[] = {
|
||||
USBD_SIZE_STRING_PRODUCT,
|
||||
STRING_DESCRIPTOR,
|
||||
'X', 0, 'V', 0, '-', 0, 'L', 0, 'i', 0, 'n', 0, 'k', 0, ' ', 0, 'C', 0, 'M', 0, 'S', 0, 'I', 0, 'S', 0, '-', 0, 'D', 0, 'A', 0, 'P', 0
|
||||
};
|
||||
|
||||
|
||||
const uint8_t USBD_HidRepDesc[] =
|
||||
{
|
||||
0x06, 0x00, 0xFF, // Usage Page = 0xFF00 (Vendor Defined Page 1)
|
||||
@@ -226,3 +233,95 @@ const uint8_t USBD_HidRepDesc[] =
|
||||
0xC0 // End Collection
|
||||
};
|
||||
|
||||
|
||||
|
||||
uint8_t BOS_Descriptor[] =
|
||||
{
|
||||
5,
|
||||
DESC_BOS,
|
||||
5+20+8, 0, // wTotalLength
|
||||
1, // bNumDeviceCaps
|
||||
|
||||
/*** MS OS 2.0 descriptor platform capability descriptor ***/
|
||||
28,
|
||||
DESC_CAPABILITY,
|
||||
5, // bDevCapabilityType: PLATFORM (05H)
|
||||
0x00,
|
||||
0xDF, 0x60, 0xDD, 0xD8, // PlatformCapabilityUUID: MS_OS_20_Platform_Capability_ID (D8DD60DF-4589-4CC7-9CD2-659D9E648A9F)
|
||||
0x89, 0x45, 0xC7, 0x4C,
|
||||
0x9C, 0xD2, 0x65, 0x9D,
|
||||
0x9E, 0x64, 0x8A, 0x9F,
|
||||
|
||||
0x00, 0x00, 0x03, 0x06, // dwWindowsVersion: 0x06030000 for Windows 8.1
|
||||
10+8+20+128, 0x00, // wTotalLength: size of MS OS 2.0 descriptor set
|
||||
WINUSB_VENDOR_CODE, // bMS_VendorCode
|
||||
0x00, // bAltEnumCmd
|
||||
};
|
||||
|
||||
uint8_t *USBD_GetBOSDescriptor(uint16_t Length)
|
||||
{
|
||||
static ONE_DESCRIPTOR bos_descriptor =
|
||||
{
|
||||
(uint8_t*)BOS_Descriptor,
|
||||
sizeof(BOS_Descriptor)
|
||||
};
|
||||
|
||||
return Standard_GetDescriptorData(Length, &bos_descriptor);
|
||||
}
|
||||
|
||||
|
||||
#define MS_OS_20_SET_HEADER_DESCRIPTOR 0x00
|
||||
#define MS_OS_20_SUBSET_HEADER_CONFIGURATION 0x01
|
||||
#define MS_OS_20_SUBSET_HEADER_FUNCTION 0x02
|
||||
#define MS_OS_20_FEATURE_COMPATIBLE_ID 0x03
|
||||
#define MS_OS_20_FEATURE_REG_PROPERTY 0x04
|
||||
#define MS_OS_20_FEATURE_MIN_RESUME_TIME 0x05
|
||||
#define MS_OS_20_FEATURE_MODEL_ID 0x06
|
||||
#define MS_OS_20_FEATURE_CCGP_DEVICE 0x07
|
||||
#define MS_OS_20_FEATURE_VENDOR_REVISION 0x08
|
||||
|
||||
uint8_t MS_OS_20_DescriptorSet[] =
|
||||
{
|
||||
/*** Microsoft OS 2.0 Descriptor Set Header ***/
|
||||
10, 0,
|
||||
MS_OS_20_SET_HEADER_DESCRIPTOR, 0,
|
||||
0x00, 0x00, 0x03, 0x06, // dwWindowsVersion: 0x06030000 for Windows 8.1
|
||||
10+8+20+128, 0, // wTotalLength
|
||||
|
||||
/*** Microsoft OS 2.0 function subset header ***/
|
||||
8, 0,
|
||||
MS_OS_20_SUBSET_HEADER_FUNCTION, 0,
|
||||
0, // bFirstInterface, first interface to which this subset applies
|
||||
0,
|
||||
8+20+128, 0, // wSubsetLength
|
||||
|
||||
/*** Microsoft OS 2.0 compatible ID descriptor ***/
|
||||
20, 0,
|
||||
MS_OS_20_FEATURE_COMPATIBLE_ID, 0,
|
||||
'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, // CompatibleID
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // SubCompatibleID
|
||||
|
||||
/*** MS OS 2.0 registry property descriptor ***/
|
||||
128, 0,
|
||||
MS_OS_20_FEATURE_REG_PROPERTY, 0,
|
||||
1, 0, // wPropertyDataType: 1 = Unicode REG_SZ
|
||||
40, 0x00, // wPropertyNameLength
|
||||
'D', 0, 'e', 0, 'v', 0, 'i', 0, 'c', 0, 'e', 0, 'I', 0, 'n', 0, 't', 0, 'e', 0,
|
||||
'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0, 'G', 0, 'U', 0, 'I', 0, 'D', 0, 0, 0, // PropertyName: "DeviceInterfaceGUID"
|
||||
78, 0x00, // wPropertyDataLength
|
||||
'{', 0, 'C', 0, 'D', 0, 'B', 0, '3', 0, 'B', 0, '5', 0, 'A', 0, 'D', 0, '-', 0,
|
||||
'2', 0, '9', 0, '3', 0, 'B', 0, '-', 0, '4', 0, '6', 0, '6', 0, '3', 0, '-', 0,
|
||||
'A', 0, 'A', 0, '3', 0, '6', 0, '-', 0, '1', 0, 'A', 0, 'A', 0, 'E', 0, '4', 0,
|
||||
'6', 0, '4', 0, '6', 0, '3', 0, '7', 0, '7', 0, '6', 0, '}', 0, 0, 0, // PropertyData: "{CDB3B5AD-293B-4663-AA36-1AAE46463776}"
|
||||
};
|
||||
|
||||
uint8_t *USBD_MS_OS_20_DescriptorSet(uint16_t Length)
|
||||
{
|
||||
static ONE_DESCRIPTOR ms_os_20_descriptorSet =
|
||||
{
|
||||
(uint8_t*)MS_OS_20_DescriptorSet,
|
||||
sizeof(MS_OS_20_DescriptorSet)
|
||||
};
|
||||
|
||||
return Standard_GetDescriptorData(Length, &ms_os_20_descriptorSet);
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
#include "ch32v20x.h"
|
||||
|
||||
|
||||
#define USBD_VID 0x0416
|
||||
#define USBD_VID 0x1A86
|
||||
#ifdef DAP_FW_V1
|
||||
#define USBD_PID 0x5051
|
||||
#define USBD_PID 0x5021
|
||||
#else
|
||||
#define USBD_PID 0x7887
|
||||
#define USBD_PID 0x7021
|
||||
#endif
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ extern const uint8_t USBD_ConfigDescriptor[];
|
||||
extern const uint8_t USBD_StringLangID [];
|
||||
extern const uint8_t USBD_StringVendor [];
|
||||
extern const uint8_t USBD_StringProduct[];
|
||||
extern const uint8_t USBD_StringInterface[];
|
||||
extern const uint8_t USBD_HidRepDesc[];
|
||||
extern uint8_t USBD_StringSerial [];
|
||||
|
||||
|
||||
@@ -68,12 +68,13 @@ ONE_DESCRIPTOR Config_Descriptor =
|
||||
USBD_SIZE_CONFIG_TOTAL
|
||||
};
|
||||
|
||||
ONE_DESCRIPTOR String_Descriptor[4] =
|
||||
ONE_DESCRIPTOR String_Descriptor[5] =
|
||||
{
|
||||
{(uint8_t*)USBD_StringLangID, USBD_SIZE_STRING_LANGID},
|
||||
{(uint8_t*)USBD_StringVendor, USBD_SIZE_STRING_VENDOR},
|
||||
{(uint8_t*)USBD_StringProduct,USBD_SIZE_STRING_PRODUCT},
|
||||
{(uint8_t*)USBD_StringSerial, USBD_SIZE_STRING_SERIAL}
|
||||
{(uint8_t*)USBD_StringLangID, USBD_SIZE_STRING_LANGID},
|
||||
{(uint8_t*)USBD_StringVendor, USBD_SIZE_STRING_VENDOR},
|
||||
{(uint8_t*)USBD_StringProduct, USBD_SIZE_STRING_PRODUCT},
|
||||
{(uint8_t*)USBD_StringSerial, USBD_SIZE_STRING_SERIAL},
|
||||
{(uint8_t*)USBD_StringInterface,USBD_SIZE_STRING_PRODUCT}
|
||||
};
|
||||
|
||||
ONE_DESCRIPTOR Report_Descriptor[1] =
|
||||
|
||||
@@ -5,6 +5,13 @@
|
||||
#include "DAP.h"
|
||||
#include "vcom_serial.h"
|
||||
|
||||
|
||||
/* 在 Properties for DAPLink -> C/C++ Build -> Settings -> C Compiler -> Preprocessor 中:
|
||||
定义 DAP_FW_V1: 生成 CMSIS-DAP v1 固件,使用 HID 传输协议
|
||||
不定义 DAP_FW_V1: 生成 CMSIS-DAP v2 固件,使用 WINUSB 传输协议
|
||||
*/
|
||||
|
||||
|
||||
extern uint8_t usbd_hid_process(void);
|
||||
|
||||
volatile uint32_t SysTick_ms = 0;
|
||||
|
||||
Reference in New Issue
Block a user