1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#!/usr/bin/env bash
# -*- Mode: C -*-
set -e
exec >"${0%.gen}"
cat <<'EOT'
/* tusb_helpers.h - Preprocessor macros that I think should be included in TinyUSB
*
* Copyright (c) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
#ifndef _USB_HELPERS_H_
#define _USB_HELPERS_H_
/* USB 2.0 §9.6.7 "String" says "The list of currently defined USB LANGIDs can be found at
* http://www.usb.org/developers/docs.html.", but that page 404s.
*
* Once upon a time the USB-IF (usb.org) published a "Language Identifiers (LANGIDs)" version 1.0,
* dated 2000-03-29. There is no longer any mention of this on usb.org, but I found a copy at
* http://www.baiheee.com/Documents/090518/090518112619/USB_LANGIDs.pdf
*
* So how does the USB-IF defined LANGIDs these days?
*
* https://www.usb.org/deprecated-links-and-tools says "To get the latest LANGID definitions go to
* https://docs.microsoft.com/en-us/windows/desktop/intl/language-identifier-constants-and-strings. This
* page will change as new LANGIDs are added." That page has no list of LANGIDs, but says "For the
* predefined primary language identifiers with their valid sublanguage identifiers, see
* [\[MS-LCID\]: Windows Language Code Identifier (LCID)
* Reference](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/70feba9f-294e-491e-b6eb-565326e84c37f)."
* That page at the time of this writing as a PDF marked as version 16.0, dated 2024-04-24:
* https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-LCID/%5bMS-LCID%5d.pdf
* [MS-LCID] defines an LCID as a 32-bit value consisting of a 16-bit a "Language ID", a 4-bit "Sort
* ID", and 12 reserved bits.
*
* That is to say: The USB-IF has said in essence "USB LANGIDs are defined to be the 'Language ID'
* portion of Microsoft Windows LCIDs (Language Code Identifiers); refer to Microsoft's published
* list of LCID Language IDs for a list of USB LANGIDs."
*
* The scheme for Language IDs is that the least-significant-byte is "primary" ID and the
* most-significant-byte is a "sublanguage" ID within that. With this in mind, Microsoft's choice
* to sort their list of by most-significant-byte was a poor editorial choice.
*/
EOT
[ -d 3rd-party ] || mkdir 3rd-party
[ -f 3rd-party/MS-LCID.pdf ] || wget -O 3rd-party/MS-LCID.pdf 'https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-LCID/%5bMS-LCID%5d.pdf'
[ -f 3rd-party/MS-LCID.txt ] || pdftotext -layout 3rd-party/MS-LCID.pdf
<3rd-party/MS-LCID.txt \
grep -E '^\s*0x[0-9A-F]{4}\s+[a-z]' | sed 's/,.*//' | grep -v reserved | # find the lines we're interested in
sed -E 's/^\s*0x(..)(..)\s+(\S.*)/\2 \1 \3/p' | tr '[:lower:]-' '[:upper:]_' | # format them as 'PRIhex SUBhex UPPER_STR'
sort |
sed -E 's/(..) (..) (.*)/#define LANGID_\3 0x\2\1/' | # format them as '#define LANGID_UPPER_STR 0xSUBPRI'
column --table --output-separator=' '
cat <<'EOT'
/* USB 2.0 §9.6.6 "Endpoint", field bEndpointAddress, bit 7 */
#define TUD_ENDPOINT_OUT 0x00
#define TUD_ENDPOINT_IN 0x80
#define TU_UTF16(str) u ## str
#endif /* _USB_HELPERS_H_ */
EOT
|