Skip to content

Commit 8a1399d

Browse files
committed
字符串描述符现已支持简体中文
1 parent 294bc88 commit 8a1399d

File tree

5 files changed

+173
-11
lines changed

5 files changed

+173
-11
lines changed

src/usblib/config/usb_desc.c

+30-4
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,14 @@ const uint8_t USBD_ConfigDescriptor[USBD_SIZE_CONFIG_DESC] = {
249249
const uint8_t USBD_StringLangID[USBD_SIZE_STRING_LANGID] = {
250250
USBD_SIZE_STRING_LANGID,
251251
USB_STRING_DESCRIPTOR_TYPE,
252-
0x09,
253-
0x04};
252+
0x04, 0x08, // LangID = 0x0804: Chinese (Simplified, China Mainland)
253+
0x04, 0x10, // LangID = 0x1004: Chinese (Simplified, Singapore)
254+
0x04, 0x0C, // LangID = 0x0C04: Chinese (Traditional, HK)
255+
0x04, 0x04, // LangID = 0x0404: Chinese (Traditional, Taiwan)
256+
0x04, 0x14, // LangID = 0x1404: Chinese (Traditional, Macau)
257+
0x11, 0x04, // LangID = 0x0411: Japanese (Japan)
258+
// 0x09, 0x04, // LangID = 0x0409: English (United States)
259+
};
254260

255261
/* USB Device String Vendor */
256262
const uint8_t USBD_StringVendor[USBD_SIZE_STRING_VENDOR] = {
@@ -262,13 +268,18 @@ const uint8_t USBD_StringVendor[USBD_SIZE_STRING_VENDOR] = {
262268
const uint8_t USBD_StringProduct[USBD_SIZE_STRING_PRODUCT] = {
263269
USBD_SIZE_STRING_PRODUCT,
264270
USB_STRING_DESCRIPTOR_TYPE,
265-
'S', 0, 'i', 0, 'm', 0, 'G', 0, 'E', 0, 'K', 0, 'I', 0};
271+
0x53, 0x00, 0x69, 0x00, 0x6d, 0x00, 0x47, 0x00, 0x45, 0x00, 0x4b, 0x00, 0x49, 0x00, 0x20, 0x00, 0x43, 0x00, 0x6f, 0x00, 0x6e, 0x00, 0x74, 0x00, 0x72, 0x00, 0x6f, 0x00, 0x6c, 0x00, 0x6c, 0x00, 0x65, 0x00, 0x72, 0x00};
272+
273+
const uint8_t USBD_StringProduct_zh_hans[USBD_SIZE_STRING_PRODUCT_zh_hans] = {
274+
USBD_SIZE_STRING_PRODUCT_zh_hans,
275+
USB_STRING_DESCRIPTOR_TYPE,
276+
0x53, 0x00, 0x69, 0x00, 0x6d, 0x00, 0x47, 0x00, 0x45, 0x00, 0x4b, 0x00, 0x49, 0x00, 0x57, 0x88, 0x3a, 0x67, 0xce, 0x98, 0x3c, 0x68, 0xa7, 0x63, 0x36, 0x52, 0x68, 0x56};
266277

267278
/* USB Device String Serial */
268279
uint8_t USBD_StringSerial[USBD_SIZE_STRING_SERIAL] = {
269280
USBD_SIZE_STRING_SERIAL,
270281
USB_STRING_DESCRIPTOR_TYPE,
271-
'0', 0, '1', 0, '2', 0, '3', 0, '4', 0, '5', 0, '6', 0, '7', 0, '8', 0, '9', 0, '0', 0, '0', 0};
282+
'0', 0, '0', 0, '0', 0, '0', 0, '0', 0, '0', 0, '0', 0, '0', 0, '0', 0, '0', 0, '0', 0, '0', 0};
272283

273284
const uint8_t USBD_StringConfig[USBD_SIZE_STRING_CONFIG] = {
274285
USBD_SIZE_STRING_CONFIG,
@@ -285,16 +296,31 @@ const uint8_t USBD_StringLEDIO[USBD_SIZE_STRING_LEDIO] = {
285296
USB_STRING_DESCRIPTOR_TYPE,
286297
'L', 0, 'E', 0, 'D', 0, ' ', 0, 'B', 0, 'o', 0, 'a', 0, 'r', 0, 'd', 0, ' ', 0, 'C', 0, 'O', 0, 'M', 0, '3', 0};
287298

299+
const uint8_t USBD_StringLEDIO_zh_hans[USBD_SIZE_STRING_LEDIO_zh_hans] = {
300+
USBD_SIZE_STRING_LEDIO_zh_hans,
301+
USB_STRING_DESCRIPTOR_TYPE,
302+
0xbe, 0x8b, 0x07, 0x59, 0x6f, 0x70, 0x49, 0x51, 0x20, 0x00, 0x43, 0x00, 0x4f, 0x00, 0x4d, 0x00, 0x33, 0x00};
303+
288304
const uint8_t USBD_StringCardIO[USBD_SIZE_STRING_CARDIO] = {
289305
USBD_SIZE_STRING_CARDIO,
290306
USB_STRING_DESCRIPTOR_TYPE,
291307
'C', 0, 'a', 0, 'r', 0, 'd', 0, ' ', 0, 'R', 0, 'e', 0, 'a', 0, 'd', 0, 'e', 0, 'r', 0, ' ', 0, 'C', 0, 'O', 0, 'M', 0, '1', 0};
292308

309+
const uint8_t USBD_StringCardIO_zh_hans[USBD_SIZE_STRING_CARDIO_zh_hans] = {
310+
USBD_SIZE_STRING_CARDIO_zh_hans,
311+
USB_STRING_DESCRIPTOR_TYPE,
312+
0x4e, 0x00, 0x46, 0x00, 0x43, 0x00, 0xfb, 0x8b, 0x61, 0x53, 0x68, 0x56, 0x20, 0x00, 0x43, 0x00, 0x4f, 0x00, 0x4d, 0x00, 0x31, 0x00};
313+
293314
const uint8_t USBD_StringCustomHID[USBD_SIZE_STRING_CUSTOM_HID] = {
294315
USBD_SIZE_STRING_CUSTOM_HID,
295316
USB_STRING_DESCRIPTOR_TYPE,
296317
'S', 0, 'i', 0, 'm', 0, 'G', 0, 'E', 0, 'K', 0, 'I', 0, ' ', 0, 'C', 0, 'o', 0, 'n', 0, 'f', 0, 'i', 0, 'g', 0};
297318

319+
const uint8_t USBD_StringCustomHID_zh_hans[USBD_SIZE_STRING_CUSTOM_HID_zh_hans] = {
320+
USBD_SIZE_STRING_CUSTOM_HID_zh_hans,
321+
USB_STRING_DESCRIPTOR_TYPE,
322+
0x53, 0x00, 0x69, 0x00, 0x6d, 0x00, 0x47, 0x00, 0x45, 0x00, 0x4b, 0x00, 0x49, 0x00, 0xbe, 0x8b, 0x6e, 0x7f};
323+
298324
/* HID Report Descriptor */
299325
const uint8_t USBD_HidRepDesc[USBD_SIZE_REPORT_DESC] =
300326
{

src/usblib/config/usb_desc.h

+20-3
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,48 @@ extern "C" {
4848

4949
#define USBD_NUMOF_STRING_DESC 9
5050

51-
#define USBD_SIZE_STRING_LANGID 4
51+
#define USBD_SIZE_STRING_LANGID 14
5252
#define USBD_SIZE_STRING_VENDOR 10
53-
#define USBD_SIZE_STRING_PRODUCT 16
53+
#define USBD_SIZE_STRING_PRODUCT 38
5454
#define USBD_SIZE_STRING_SERIAL 26
5555
#define USBD_SIZE_STRING_CONFIG 22
5656
#define USBD_SIZE_STRING_HIDIO 188
5757
#define USBD_SIZE_STRING_LEDIO 30
5858
#define USBD_SIZE_STRING_CARDIO 34
5959
#define USBD_SIZE_STRING_CUSTOM_HID 30
6060

61+
#define USBD_SIZE_STRING_PRODUCT_zh_hans 30
62+
#define USBD_SIZE_STRING_LEDIO_zh_hans 20
63+
#define USBD_SIZE_STRING_CARDIO_zh_hans 24
64+
#define USBD_SIZE_STRING_CUSTOM_HID_zh_hans 20
65+
6166
extern const uint8_t USBD_DeviceDescriptor[USBD_SIZE_DEVICE_DESC];
6267
extern const uint8_t USBD_ConfigDescriptor[USBD_SIZE_CONFIG_DESC];
6368

6469
extern const uint8_t USBD_HidRepDesc[USBD_SIZE_REPORT_DESC];
6570
extern const uint8_t USBD_HidCustomDesc[USBD_SIZE_CUSTOM_REPORT_DESC];
6671

72+
// Not for muti-language
6773
extern const uint8_t USBD_StringLangID[USBD_SIZE_STRING_LANGID];
6874
extern const uint8_t USBD_StringVendor[USBD_SIZE_STRING_VENDOR];
69-
extern const uint8_t USBD_StringProduct[USBD_SIZE_STRING_PRODUCT];
7075
extern uint8_t USBD_StringSerial[USBD_SIZE_STRING_SERIAL];
76+
77+
// For muti-language
78+
extern const uint8_t USBD_StringProduct[USBD_SIZE_STRING_PRODUCT];
79+
extern const uint8_t USBD_StringProduct_zh_hans[USBD_SIZE_STRING_PRODUCT_zh_hans];
80+
7181
extern const uint8_t USBD_StringConfig[USBD_SIZE_STRING_CONFIG];
82+
7283
extern const uint8_t USBD_StringHIDIO[USBD_SIZE_STRING_HIDIO];
84+
7385
extern const uint8_t USBD_StringLEDIO[USBD_SIZE_STRING_LEDIO];
86+
extern const uint8_t USBD_StringLEDIO_zh_hans[USBD_SIZE_STRING_LEDIO_zh_hans];
87+
7488
extern const uint8_t USBD_StringCardIO[USBD_SIZE_STRING_CARDIO];
89+
extern const uint8_t USBD_StringCardIO_zh_hans[USBD_SIZE_STRING_CARDIO_zh_hans];
90+
7591
extern const uint8_t USBD_StringCustomHID[USBD_SIZE_STRING_CUSTOM_HID];
92+
extern const uint8_t USBD_StringCustomHID_zh_hans[USBD_SIZE_STRING_CUSTOM_HID_zh_hans];
7693

7794
void USBD_SerialNumUpdate();
7895

src/usblib/config/usb_prop.c

+113-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ DEVICE_PROP Device_Property =
3939
USBD_Get_Interface_Setting,
4040
USBD_GetDeviceDescriptor,
4141
USBD_GetConfigDescriptor,
42-
USBD_GetStringDescriptor,
42+
USBD_GetStringDescriptor_MutiLang,
4343
0,
4444
DEF_USBD_UEP0_SIZE};
4545

@@ -78,6 +78,64 @@ ONE_DESCRIPTOR String_Descriptor[USBD_NUMOF_STRING_DESC] =
7878
{(uint8_t *)USBD_StringCustomHID, USBD_SIZE_STRING_CUSTOM_HID},
7979
};
8080

81+
MUTI_LANG_DESCRIPTOR Muti_Lang_String_Descriptor[USBD_NUMOF_STRING_DESC] =
82+
{
83+
{
84+
{(uint8_t *)USBD_StringLangID, USBD_SIZE_STRING_LANGID},
85+
{(uint8_t *)USBD_StringLangID, USBD_SIZE_STRING_LANGID},
86+
{(uint8_t *)USBD_StringLangID, USBD_SIZE_STRING_LANGID},
87+
{(uint8_t *)USBD_StringLangID, USBD_SIZE_STRING_LANGID},
88+
},
89+
{
90+
{(uint8_t *)USBD_StringVendor, USBD_SIZE_STRING_VENDOR},
91+
{NULL, 0},
92+
{NULL, 0},
93+
{NULL, 0},
94+
},
95+
{
96+
{(uint8_t *)USBD_StringProduct, USBD_SIZE_STRING_PRODUCT},
97+
{(uint8_t *)USBD_StringProduct_zh_hans, USBD_SIZE_STRING_PRODUCT_zh_hans},
98+
{NULL, 0},
99+
{NULL, 0},
100+
},
101+
{
102+
{(uint8_t *)USBD_StringSerial, USBD_SIZE_STRING_SERIAL},
103+
{NULL, 0},
104+
{NULL, 0},
105+
{NULL, 0},
106+
},
107+
{
108+
{(uint8_t *)USBD_StringConfig, USBD_SIZE_STRING_CONFIG},
109+
{NULL, 0},
110+
{NULL, 0},
111+
{NULL, 0},
112+
},
113+
{
114+
{(uint8_t *)USBD_StringHIDIO, USBD_SIZE_STRING_HIDIO},
115+
{NULL, 0},
116+
{NULL, 0},
117+
{NULL, 0},
118+
},
119+
{
120+
{(uint8_t *)USBD_StringLEDIO, USBD_SIZE_STRING_LEDIO},
121+
{(uint8_t *)USBD_StringLEDIO_zh_hans, USBD_SIZE_STRING_LEDIO_zh_hans},
122+
{NULL, 0},
123+
{NULL, 0},
124+
},
125+
{
126+
{(uint8_t *)USBD_StringCardIO, USBD_SIZE_STRING_CARDIO},
127+
{(uint8_t *)USBD_StringCardIO_zh_hans, USBD_SIZE_STRING_CARDIO_zh_hans},
128+
{NULL, 0},
129+
{NULL, 0},
130+
},
131+
{
132+
{(uint8_t *)USBD_StringCustomHID, USBD_SIZE_STRING_CUSTOM_HID},
133+
{(uint8_t *)USBD_StringCustomHID_zh_hans, USBD_SIZE_STRING_CUSTOM_HID_zh_hans},
134+
{NULL, 0},
135+
{NULL, 0},
136+
},
137+
};
138+
81139
ONE_DESCRIPTOR Report_Descriptor[2] =
82140
{
83141
{(uint8_t *)USBD_HidRepDesc, USBD_SIZE_REPORT_DESC},
@@ -295,12 +353,63 @@ uint8_t *USBD_GetConfigDescriptor(uint16_t Length)
295353
*/
296354
uint8_t *USBD_GetStringDescriptor(uint16_t Length)
297355
{
298-
uint8_t wValue0 = pInformation->USBwValue0;
356+
uint8_t stringIndex = pInformation->USBwValue0;
357+
358+
if (stringIndex >= USBD_NUMOF_STRING_DESC) {
359+
return NULL;
360+
} else {
361+
return Standard_GetDescriptorData(Length, &String_Descriptor[stringIndex]);
362+
}
363+
}
364+
365+
/*********************************************************************
366+
* @fn USBD_GetStringDescriptor_MutiLang
367+
*
368+
* @brief Gets the string descriptors according to the needed index & lang id
369+
*
370+
* @param Length.
371+
*
372+
* @return The address of the string descriptors.
373+
*/
374+
uint8_t *USBD_GetStringDescriptor_MutiLang(uint16_t Length)
375+
{
376+
uint8_t stringIndex = pInformation->USBwValue0;
377+
uint16_t stringID = pInformation->USBwIndex;
299378

300-
if (wValue0 >= USBD_NUMOF_STRING_DESC) {
379+
if (stringIndex >= USBD_NUMOF_STRING_DESC) {
301380
return NULL;
302381
} else {
303-
return Standard_GetDescriptorData(Length, &String_Descriptor[wValue0]);
382+
switch (stringID) {
383+
case 0x0408:
384+
case 0x0410:
385+
// Chinese Simplified
386+
if (Muti_Lang_String_Descriptor[stringIndex].__zh_hans.Descriptor_Size == 0) {
387+
return Standard_GetDescriptorData(Length, &Muti_Lang_String_Descriptor[stringIndex].__en_us);
388+
}
389+
return Standard_GetDescriptorData(Length, &Muti_Lang_String_Descriptor[stringIndex].__zh_hans);
390+
break;
391+
case 0x0404:
392+
case 0x040c:
393+
case 0x0414:
394+
// Chinese Traditional
395+
if (Muti_Lang_String_Descriptor[stringIndex].__zh_hant.Descriptor_Size == 0) {
396+
return Standard_GetDescriptorData(Length, &Muti_Lang_String_Descriptor[stringIndex].__en_us);
397+
}
398+
return Standard_GetDescriptorData(Length, &Muti_Lang_String_Descriptor[stringIndex].__zh_hant);
399+
break;
400+
case 0x1104:
401+
// Japanese
402+
if (Muti_Lang_String_Descriptor[stringIndex].__ja_jp.Descriptor_Size == 0) {
403+
return Standard_GetDescriptorData(Length, &Muti_Lang_String_Descriptor[stringIndex].__en_us);
404+
}
405+
return Standard_GetDescriptorData(Length, &Muti_Lang_String_Descriptor[stringIndex].__ja_jp);
406+
break;
407+
case 0x0904:
408+
return Standard_GetDescriptorData(Length, &(Muti_Lang_String_Descriptor[stringIndex].__en_us));
409+
break;
410+
default:
411+
return Standard_GetDescriptorData(Length, &(Muti_Lang_String_Descriptor[stringIndex].__en_us));
412+
}
304413
}
305414
}
306415

src/usblib/config/usb_prop.h

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ RESULT USBD_Get_Interface_Setting(uint8_t Interface, uint8_t AlternateSetting);
6161
uint8_t *USBD_GetDeviceDescriptor(uint16_t );
6262
uint8_t *USBD_GetConfigDescriptor(uint16_t);
6363
uint8_t *USBD_GetStringDescriptor(uint16_t);
64+
uint8_t *USBD_GetStringDescriptor_MutiLang(uint16_t);
6465
uint8_t USBD_ENDPx_DataUp( uint8_t endp, uint8_t *pbuf, uint16_t len );
6566
#ifdef __cplusplus
6667
}

src/usblib/usb_driver/inc/usb_core.h

+9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ typedef struct OneDescriptor
4141
}
4242
ONE_DESCRIPTOR, *PONE_DESCRIPTOR;
4343

44+
typedef struct MutiLanguagesDescriptor
45+
{
46+
ONE_DESCRIPTOR __en_us; // English (United States)
47+
ONE_DESCRIPTOR __zh_hans; // Chinese (Simplified)
48+
ONE_DESCRIPTOR __zh_hant; // Chinese (Traditional)
49+
ONE_DESCRIPTOR __ja_jp; // Japanese (Japan)
50+
}
51+
MUTI_LANG_DESCRIPTOR;
52+
4453
typedef enum _RESULT
4554
{
4655
USB_SUCCESS = 0, /* Process successfully */

0 commit comments

Comments
 (0)