102 lines
2.7 KiB
C
102 lines
2.7 KiB
C
#ifndef _USB_CONFIG_H
|
|
#define _USB_CONFIG_H
|
|
|
|
#define ENDPOINTS 2
|
|
|
|
#define USB_PORT D
|
|
#define USB_PIN_DP 3
|
|
#define USB_PIN_DM 4
|
|
// #define USB_PIN_DPU 2
|
|
|
|
#define RV003USB_OPTIMIZE_FLASH 1
|
|
#define RV003USB_DEBUG_TIMING 0
|
|
#define RV003USB_EVENT_DEBUGGING 0
|
|
#define RV003USB_HANDLE_IN_REQUEST 0
|
|
#define RV003USB_OTHER_CONTROL 1
|
|
#define RV003USB_HANDLE_USER_DATA 1
|
|
#define RV003USB_HID_FEATURES 0
|
|
#define RV003USB_USB_TERMINAL 0
|
|
#define RV003USB_USE_REBOOT_FEATURE_REPORT 0
|
|
|
|
#ifndef __ASSEMBLER__
|
|
|
|
#include <stdint.h>
|
|
|
|
#ifdef INSTANCE_DESCRIPTORS
|
|
|
|
static const uint8_t device_descriptor[] = {
|
|
18, 1,
|
|
0x10, 0x01, // USB 1.1
|
|
0x00, 0x00, 0x00,
|
|
0x08, // EP0 max packet
|
|
0xd0, 0xfa, // idVendor 0xfad0
|
|
0x00, 0x90, // idProduct 0x9000
|
|
0x02, 0x00,
|
|
1, 2, 3,
|
|
1,
|
|
};
|
|
|
|
static const uint8_t config_descriptor[] = {
|
|
9, 2,
|
|
0x20, 0x00, // wTotalLength = 9 + 9 + 7 + 7
|
|
0x01, // bNumInterfaces
|
|
0x01, // bConfigurationValue
|
|
0x00,
|
|
0x80,
|
|
0x64,
|
|
|
|
9, 4,
|
|
0, // bInterfaceNumber
|
|
0, // bAlternateSetting
|
|
2, // bNumEndpoints
|
|
0xff, // vendor specific class
|
|
0x00,
|
|
0x00,
|
|
0,
|
|
|
|
7, 0x05,
|
|
0x01, // EP1 OUT
|
|
0x03, // interrupt
|
|
0x08, 0x00, // max packet 8
|
|
10, // interval ms
|
|
|
|
7, 0x05,
|
|
0x81, // EP1 IN
|
|
0x03,
|
|
0x08, 0x00,
|
|
10,
|
|
};
|
|
|
|
#define STR_MANUFACTURER u"That real manufacturer"
|
|
#define STR_PRODUCT u"CH32V003 USB GPIO module"
|
|
#ifndef STR_SERIAL
|
|
#define STR_SERIAL u"deadbeef"
|
|
#endif
|
|
|
|
struct usb_string_descriptor_struct {
|
|
uint8_t bLength;
|
|
uint8_t bDescriptorType;
|
|
uint16_t wString[];
|
|
};
|
|
const static struct usb_string_descriptor_struct string0 __attribute__((section(".rodata"))) = { 4, 3, {0x0409} };
|
|
const static struct usb_string_descriptor_struct string1 __attribute__((section(".rodata"))) = { sizeof(STR_MANUFACTURER), 3, STR_MANUFACTURER };
|
|
const static struct usb_string_descriptor_struct string2 __attribute__((section(".rodata"))) = { sizeof(STR_PRODUCT), 3, STR_PRODUCT };
|
|
const static struct usb_string_descriptor_struct string3 __attribute__((section(".rodata"))) = { sizeof(STR_SERIAL), 3, STR_SERIAL };
|
|
|
|
const static struct descriptor_list_struct {
|
|
uint32_t lIndexValue;
|
|
const uint8_t *addr;
|
|
uint8_t length;
|
|
} descriptor_list[] = {
|
|
{0x00000100, device_descriptor, sizeof(device_descriptor)},
|
|
{0x00000200, config_descriptor, sizeof(config_descriptor)},
|
|
{0x00000300, (const uint8_t *)&string0, 4},
|
|
{0x04090301, (const uint8_t *)&string1, sizeof(STR_MANUFACTURER)},
|
|
{0x04090302, (const uint8_t *)&string2, sizeof(STR_PRODUCT)},
|
|
{0x04090303, (const uint8_t *)&string3, sizeof(STR_SERIAL)}
|
|
};
|
|
#define DESCRIPTOR_LIST_ENTRIES ((sizeof(descriptor_list))/(sizeof(struct descriptor_list_struct)))
|
|
|
|
#endif
|
|
#endif
|
|
#endif |