1 /******************************************************************************
2 * Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
3 * All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *****************************************************************************/
18 #if (1)
19
20 #include "myudb_usbdesc.h"
21 #include "drivers.h"
22 #include "myudb.h"
23
24 // request parameters
25 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
26 * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
27 * via the language ID table available at USB.org what languages the device supports for its string descriptors.
28 */
29 static const USB_Descriptor_String_t language_desc = {{sizeof(USB_Descriptor_Header_t) + 2, DTYPE_String},
30 {LANGUAGE_ID_ENG}};
31
32 /** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable
33 * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
34 * Descriptor.
35 */
36 static const USB_Descriptor_String_t vendor_desc = {
37 {sizeof(USB_Descriptor_Header_t) + sizeof(MYUDB_STRING_VENDOR) - 2, DTYPE_String}, // Header
38 MYUDB_STRING_VENDOR};
39
40 /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
41 * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
42 * Descriptor.
43 */
44 static const USB_Descriptor_String_t product_desc = {
45 {sizeof(USB_Descriptor_Header_t) + sizeof(MYUDB_STRING_PRODUCT) - 2, DTYPE_String}, // Header
46 MYUDB_STRING_PRODUCT};
47
48 /** Serial number string. This is a Unicode string containing the device's unique serial number, expressed as a
49 * series of uppercase hexadecimal digits.
50 */
51 static const USB_Descriptor_String_t serial_desc = {
52 {sizeof(USB_Descriptor_Header_t) + sizeof(MYUDB_STRING_SERIAL) - 2, DTYPE_String}, // Header
53 MYUDB_STRING_SERIAL};
54
55 static const USB_Descriptor_Device_t device_desc = {
56 {sizeof(USB_Descriptor_Device_t), DTYPE_Device}, // Header
57 0x0200, // USBSpecification, USB 2.0
58 USB_CSCP_NoDeviceClass, // Class
59 USB_CSCP_NoDeviceSubclass, // SubClass
60 USB_CSCP_NoDeviceProtocol, // Protocol
61 8, // Endpoint0Size, Maximum Packet Size for Zero Endpoint. Valid Sizes are 8, 16, 32, 64
62 MYUDB_ID_VENDOR, // VendorID
63 MYUDB_ID_PRODUCT, // ProductID
64 MYUDB_ID_VERSION /* 0x0100 */, // .ReleaseNumber
65 MYUDB_USB_STRING_VENDOR, // .ManufacturerStrIndex
66 MYUDB_USB_STRING_PRODUCT, // .ProductStrIndex
67 0, // .SerialNumStrIndex, iSerialNumber
68 1};
69
70 static const MYUDB_USB_Descriptor_Configuration_t configuration_desc = {
71 {
72 {sizeof(USB_Descriptor_Configuration_Header_t), DTYPE_Configuration}, // Length, type
73 sizeof(MYUDB_USB_Descriptor_Configuration_t), // TotalLength: variable
74 2, // NumInterfaces
75 1, // Configuration index
76 NO_DESCRIPTOR, // Configuration String
77 USB_CONFIG_ATTR_RESERVED, // Attributes
78 USB_CONFIG_POWER_MA(100) // MaxPower = 100mA
79 },
80 // printer_interface
81 {
82 {sizeof(USB_Descriptor_Interface_t), DTYPE_Interface},
83 0,
84 0, // AlternateSetting
85 2, // bNumEndpoints
86 PRNT_CSCP_PrinterClass, // bInterfaceclass ->Printer
87 PRNT_CSCP_PrinterSubclass, // bInterfaceSubClass -> Control
88 PRNT_CSCP_BidirectionalProtocol, // bInterfaceProtocol
89 NO_DESCRIPTOR // iInterface, same as iProduct in USB_Descriptor_Device_t, or else not working
90 },
91 // printer_in_endpoint
92 {
93 {sizeof(USB_Descriptor_Endpoint_t), DTYPE_Endpoint}, // length, bDescriptorType
94 ENDPOINT_DIR_IN | MYUDB_EDP_IN_HCI, // endpoint id
95 EP_TYPE_BULK, // endpoint type
96 0x0040, // wMaxPacketSize
97 0 // bInterval
98 },
99 // printer_out_endpoint
100 {
101 {sizeof(USB_Descriptor_Endpoint_t), DTYPE_Endpoint}, // length, bDescriptorType
102 MYUDB_EDP_OUT_HCI, // endpoint id
103 EP_TYPE_BULK, // endpoint type
104 0x0040, // wMaxPacketSize
105 0 // polling bInterval. valid for iso or interrupt type
106 },
107
108 // printer_interface
109 {
110 {sizeof(USB_Descriptor_Interface_t), DTYPE_Interface},
111 1,
112 0, // AlternateSetting
113 2, // bNumEndpoints
114 PRNT_CSCP_PrinterClass, // bInterfaceclass ->Printer
115 PRNT_CSCP_PrinterSubclass, // bInterfaceSubClass -> Control
116 PRNT_CSCP_BidirectionalProtocol, // bInterfaceProtocol
117 NO_DESCRIPTOR // iInterface, same as iProduct in USB_Descriptor_Device_t, or else not working
118 },
119 // printer_in_endpoint
120 {
121 {sizeof(USB_Descriptor_Endpoint_t), DTYPE_Endpoint}, // length, bDescriptorType
122 ENDPOINT_DIR_IN | MYUDB_EDP_IN_VCD, // endpoint id
123 EP_TYPE_BULK, // endpoint type
124 0x0040, // wMaxPacketSize
125 0 // bInterval
126 },
127 // printer_out_endpoint
128 {
129 {sizeof(USB_Descriptor_Endpoint_t), DTYPE_Endpoint}, // length, bDescriptorType
130 MYUDB_EDP_OUT_VCD, // endpoint id
131 EP_TYPE_BULK, // endpoint type
132 0x0040, // wMaxPacketSize
133 0 // polling bInterval. valid for iso or interrupt type
134 },
135 };
136
myudb_usbdesc_get_language(void)137 u8 *myudb_usbdesc_get_language(void)
138 {
139 return (u8 *)(&language_desc);
140 }
141
myudb_usbdesc_get_vendor(void)142 u8 *myudb_usbdesc_get_vendor(void)
143 {
144 return (u8 *)(&vendor_desc);
145 }
146
myudb_usbdesc_get_product(void)147 u8 *myudb_usbdesc_get_product(void)
148 {
149 return (u8 *)(&product_desc);
150 }
myudb_usbdesc_get_serial(void)151 u8 *myudb_usbdesc_get_serial(void)
152 {
153 return (u8 *)(&serial_desc);
154 }
155
myudb_usbdesc_get_device(void)156 u8 *myudb_usbdesc_get_device(void)
157 {
158 return (u8 *)(&device_desc);
159 }
160
myudb_usbdesc_get_configuration(void)161 u8 *myudb_usbdesc_get_configuration(void)
162 {
163 return (u8 *)(&configuration_desc);
164 }
165
166 #endif
167