Skip to content

Commit 4be0eda

Browse files
committed
Use char16_t for UTF-16 strings in the USB driver
Signed-off-by: Peter Collingbourne <[email protected]>
1 parent 038c2d3 commit 4be0eda

File tree

15 files changed

+203
-173
lines changed

15 files changed

+203
-173
lines changed

source/daplink/uchar.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @file uchar.h
3+
* @brief Compatibility for libcs without uchar.h
4+
*
5+
* DAPLink Interface Firmware
6+
* Copyright (c) 2023 Google LLC, All Rights Reserved
7+
* SPDX-License-Identifier: Apache-2.0
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
10+
* not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*/
21+
22+
#ifndef DAPLINK_UCHAR_H
23+
#define DAPLINK_UCHAR_H
24+
25+
#if __has_include_next(<uchar.h>)
26+
#include_next <uchar.h>
27+
#else
28+
#include <stdint.h>
29+
typedef uint16_t char16_t;
30+
#endif
31+
32+
#endif

source/hic_hal/atmel/sam3u2c/usb_config.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,16 @@
9090
// </e>
9191
// </h>
9292
#define USBD_STRDESC_LANGID 0x0409
93-
#define USBD_STRDESC_MAN L"Arm"
93+
#define USBD_STRDESC_MAN u"Arm"
9494
#ifndef USB_PROD_STR
95-
#define USBD_STRDESC_PROD L"DAPLink CMSIS-DAP"
95+
#define USBD_STRDESC_PROD u"DAPLink CMSIS-DAP"
9696
#else
97-
#define _TOWIDE(x) L ## #x
97+
#define _TOWIDE(x) u ## #x
9898
#define TOWIDE(x) _TOWIDE(x)
9999
#define USBD_STRDESC_PROD TOWIDE(USB_PROD_STR)
100100
#endif
101101
#define USBD_STRDESC_SER_ENABLE 1
102-
#define USBD_STRDESC_SER L"0001A0000000"
102+
#define USBD_STRDESC_SER u"0001A0000000"
103103

104104
// <e0> Class Support
105105
// <i> Enables USB Device Class specific Requests
@@ -169,8 +169,8 @@
169169
#define USBD_HID_HS_ENABLE 1
170170
#define USBD_HID_HS_WMAXPACKETSIZE 64
171171
#define USBD_HID_HS_BINTERVAL 1
172-
#define USBD_HID_STRDESC L"CMSIS-DAP v1"
173-
#define USBD_WEBUSB_STRDESC L"WebUSB: CMSIS-DAP"
172+
#define USBD_HID_STRDESC u"CMSIS-DAP v1"
173+
#define USBD_WEBUSB_STRDESC u"WebUSB: CMSIS-DAP"
174174
#define USBD_HID_INREPORT_NUM 1
175175
#define USBD_HID_OUTREPORT_NUM 1
176176
#define USBD_HID_INREPORT_MAX_SZ 64
@@ -221,7 +221,7 @@
221221
#define USBD_MSC_HS_ENABLE 1
222222
#define USBD_MSC_HS_WMAXPACKETSIZE 512
223223
#define USBD_MSC_HS_BINTERVAL 0
224-
#define USBD_MSC_STRDESC L"USB_MSC"
224+
#define USBD_MSC_STRDESC u"USB_MSC"
225225
// Make sure changes to USBD_MSC_INQUIRY_DATA are coordinated with mbed-ls
226226
// since this is used to detect DAPLink drives
227227
#define USBD_MSC_INQUIRY_DATA "MBED " \
@@ -266,9 +266,9 @@
266266
#define USBD_ADC_BINTERVAL 1
267267
#define USBD_ADC_HS_ENABLE 0
268268
#define USBD_ADC_HS_WMAXPACKETSIZE 64
269-
#define USBD_ADC_CIF_STRDESC L"USB_ADC"
270-
#define USBD_ADC_SIF1_STRDESC L"USB_ADC1"
271-
#define USBD_ADC_SIF2_STRDESC L"USB_ADC2"
269+
#define USBD_ADC_CIF_STRDESC u"USB_ADC"
270+
#define USBD_ADC_SIF1_STRDESC u"USB_ADC1"
271+
#define USBD_ADC_SIF2_STRDESC u"USB_ADC2"
272272
#define USBD_ADC_BSUBFRAMESIZE 2
273273
#define USBD_ADC_BBITRESOLUTION 16
274274
#define USBD_ADC_TSAMFREQ 32000
@@ -349,8 +349,8 @@
349349
#define USBD_CDC_ACM_HS_ENABLE1 1
350350
#define USBD_CDC_ACM_HS_WMAXPACKETSIZE1 512
351351
#define USBD_CDC_ACM_HS_BINTERVAL1 1
352-
#define USBD_CDC_ACM_CIF_STRDESC L"mbed Serial Port"
353-
#define USBD_CDC_ACM_DIF_STRDESC L"mbed Serial Port"
352+
#define USBD_CDC_ACM_CIF_STRDESC u"mbed Serial Port"
353+
#define USBD_CDC_ACM_DIF_STRDESC u"mbed Serial Port"
354354
#define USBD_CDC_ACM_SENDBUF_SIZE USBD_CDC_ACM_HS_WMAXPACKETSIZE1
355355
#define USBD_CDC_ACM_RECEIVEBUF_SIZE USBD_CDC_ACM_HS_WMAXPACKETSIZE1
356356
#if (((USBD_CDC_ACM_HS_ENABLE1) && (USBD_CDC_ACM_SENDBUF_SIZE < USBD_CDC_ACM_HS_WMAXPACKETSIZE1)) || (USBD_CDC_ACM_SENDBUF_SIZE < USBD_CDC_ACM_WMAXPACKETSIZE1))
@@ -401,7 +401,7 @@
401401
#define USBD_BULK_WMAXPACKETSIZE 64
402402
#define USBD_BULK_HS_ENABLE 1
403403
#define USBD_BULK_HS_WMAXPACKETSIZE 512
404-
#define USBD_BULK_STRDESC L"CMSIS-DAP v2"
404+
#define USBD_BULK_STRDESC u"CMSIS-DAP v2"
405405

406406

407407
/* USB Device Calculations ---------------------------------------------------*/

source/hic_hal/freescale/k20dx/usb_config.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,16 @@
9090
// </e>
9191
// </h>
9292
#define USBD_STRDESC_LANGID 0x0409
93-
#define USBD_STRDESC_MAN L"Arm"
93+
#define USBD_STRDESC_MAN u"Arm"
9494
#ifndef USB_PROD_STR
95-
#define USBD_STRDESC_PROD L"DAPLink CMSIS-DAP"
95+
#define USBD_STRDESC_PROD u"DAPLink CMSIS-DAP"
9696
#else
97-
#define _TOWIDE(x) L ## #x
97+
#define _TOWIDE(x) u ## #x
9898
#define TOWIDE(x) _TOWIDE(x)
9999
#define USBD_STRDESC_PROD TOWIDE(USB_PROD_STR)
100100
#endif
101101
#define USBD_STRDESC_SER_ENABLE 1
102-
#define USBD_STRDESC_SER L"0001A0000000"
102+
#define USBD_STRDESC_SER u"0001A0000000"
103103

104104
// <e0> Class Support
105105
// <i> Enables USB Device Class specific Requests
@@ -169,8 +169,8 @@
169169
#define USBD_HID_HS_ENABLE 0
170170
#define USBD_HID_HS_WMAXPACKETSIZE 64
171171
#define USBD_HID_HS_BINTERVAL 6
172-
#define USBD_HID_STRDESC L"CMSIS-DAP v1"
173-
#define USBD_WEBUSB_STRDESC L"WebUSB: CMSIS-DAP"
172+
#define USBD_HID_STRDESC u"CMSIS-DAP v1"
173+
#define USBD_WEBUSB_STRDESC u"WebUSB: CMSIS-DAP"
174174
#define USBD_HID_INREPORT_NUM 1
175175
#define USBD_HID_OUTREPORT_NUM 1
176176
#define USBD_HID_INREPORT_MAX_SZ 64
@@ -220,7 +220,7 @@
220220
#define USBD_MSC_HS_ENABLE 0
221221
#define USBD_MSC_HS_WMAXPACKETSIZE 512
222222
#define USBD_MSC_HS_BINTERVAL 0
223-
#define USBD_MSC_STRDESC L"USB_MSC"
223+
#define USBD_MSC_STRDESC u"USB_MSC"
224224
// Make sure changes to USBD_MSC_INQUIRY_DATA are coordinated with mbed-ls
225225
// since this is used to detect DAPLink drives
226226
#define USBD_MSC_INQUIRY_DATA "MBED " \
@@ -265,9 +265,9 @@
265265
#define USBD_ADC_BINTERVAL 1
266266
#define USBD_ADC_HS_ENABLE 0
267267
#define USBD_ADC_HS_WMAXPACKETSIZE 64
268-
#define USBD_ADC_CIF_STRDESC L"USB_ADC"
269-
#define USBD_ADC_SIF1_STRDESC L"USB_ADC1"
270-
#define USBD_ADC_SIF2_STRDESC L"USB_ADC2"
268+
#define USBD_ADC_CIF_STRDESC u"USB_ADC"
269+
#define USBD_ADC_SIF1_STRDESC u"USB_ADC1"
270+
#define USBD_ADC_SIF2_STRDESC u"USB_ADC2"
271271
#define USBD_ADC_BSUBFRAMESIZE 2
272272
#define USBD_ADC_BBITRESOLUTION 16
273273
#define USBD_ADC_TSAMFREQ 32000
@@ -347,8 +347,8 @@
347347
#define USBD_CDC_ACM_HS_ENABLE1 0
348348
#define USBD_CDC_ACM_HS_WMAXPACKETSIZE1 64
349349
#define USBD_CDC_ACM_HS_BINTERVAL1 0
350-
#define USBD_CDC_ACM_CIF_STRDESC L"mbed Serial Port"
351-
#define USBD_CDC_ACM_DIF_STRDESC L"mbed Serial Port"
350+
#define USBD_CDC_ACM_CIF_STRDESC u"mbed Serial Port"
351+
#define USBD_CDC_ACM_DIF_STRDESC u"mbed Serial Port"
352352
#define USBD_CDC_ACM_SENDBUF_SIZE 64
353353
#define USBD_CDC_ACM_RECEIVEBUF_SIZE 64
354354
#if (((USBD_CDC_ACM_HS_ENABLE1) && (USBD_CDC_ACM_SENDBUF_SIZE < USBD_CDC_ACM_HS_WMAXPACKETSIZE1)) || (USBD_CDC_ACM_SENDBUF_SIZE < USBD_CDC_ACM_WMAXPACKETSIZE1))
@@ -399,7 +399,7 @@
399399
#define USBD_BULK_WMAXPACKETSIZE 64
400400
#define USBD_BULK_HS_ENABLE 0
401401
#define USBD_BULK_HS_WMAXPACKETSIZE 512
402-
#define USBD_BULK_STRDESC L"CMSIS-DAP v2"
402+
#define USBD_BULK_STRDESC u"CMSIS-DAP v2"
403403

404404

405405
/* USB Device Calculations ---------------------------------------------------*/

source/hic_hal/freescale/k26f/usb_config.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,16 @@
9999
// </e>
100100
// </h>
101101
#define USBD_STRDESC_LANGID 0x0409
102-
#define USBD_STRDESC_MAN L"Arm"
102+
#define USBD_STRDESC_MAN u"Arm"
103103
#ifndef USB_PROD_STR
104-
#define USBD_STRDESC_PROD L"DAPLink CMSIS-DAP"
104+
#define USBD_STRDESC_PROD u"DAPLink CMSIS-DAP"
105105
#else
106-
#define _TOWIDE(x) L ## #x
106+
#define _TOWIDE(x) u ## #x
107107
#define TOWIDE(x) _TOWIDE(x)
108108
#define USBD_STRDESC_PROD TOWIDE(USB_PROD_STR)
109109
#endif
110110
#define USBD_STRDESC_SER_ENABLE 1
111-
#define USBD_STRDESC_SER L"0001A0000000"
111+
#define USBD_STRDESC_SER u"0001A0000000"
112112

113113
// <e0> Class Support
114114
// <i> Enables USB Device Class specific Requests
@@ -178,8 +178,8 @@
178178
#define USBD_HID_HS_ENABLE 1
179179
#define USBD_HID_HS_WMAXPACKETSIZE 64 //| (2<<11)
180180
#define USBD_HID_HS_BINTERVAL 1
181-
#define USBD_HID_STRDESC L"CMSIS-DAP v1"
182-
#define USBD_WEBUSB_STRDESC L"WebUSB: CMSIS-DAP"
181+
#define USBD_HID_STRDESC u"CMSIS-DAP v1"
182+
#define USBD_WEBUSB_STRDESC u"WebUSB: CMSIS-DAP"
183183
#define USBD_HID_INREPORT_NUM 1
184184
#define USBD_HID_OUTREPORT_NUM 1
185185
#define USBD_HID_INREPORT_MAX_SZ 64
@@ -229,7 +229,7 @@
229229
#define USBD_MSC_HS_ENABLE 1
230230
#define USBD_MSC_HS_WMAXPACKETSIZE 512
231231
#define USBD_MSC_HS_BINTERVAL 0
232-
#define USBD_MSC_STRDESC L"USB_MSC"
232+
#define USBD_MSC_STRDESC u"USB_MSC"
233233
// Make sure changes to USBD_MSC_INQUIRY_DATA are coordinated with mbed-ls
234234
// since this is used to detect DAPLink drives
235235
#define USBD_MSC_INQUIRY_DATA "MBED " \
@@ -274,9 +274,9 @@
274274
#define USBD_ADC_BINTERVAL 1
275275
#define USBD_ADC_HS_ENABLE 0
276276
#define USBD_ADC_HS_WMAXPACKETSIZE 64
277-
#define USBD_ADC_CIF_STRDESC L"USB_ADC"
278-
#define USBD_ADC_SIF1_STRDESC L"USB_ADC1"
279-
#define USBD_ADC_SIF2_STRDESC L"USB_ADC2"
277+
#define USBD_ADC_CIF_STRDESC u"USB_ADC"
278+
#define USBD_ADC_SIF1_STRDESC u"USB_ADC1"
279+
#define USBD_ADC_SIF2_STRDESC u"USB_ADC2"
280280
#define USBD_ADC_BSUBFRAMESIZE 2
281281
#define USBD_ADC_BBITRESOLUTION 16
282282
#define USBD_ADC_TSAMFREQ 32000
@@ -356,8 +356,8 @@
356356
#define USBD_CDC_ACM_HS_ENABLE1 1
357357
#define USBD_CDC_ACM_HS_WMAXPACKETSIZE1 512
358358
#define USBD_CDC_ACM_HS_BINTERVAL1 1
359-
#define USBD_CDC_ACM_CIF_STRDESC L"mbed Serial Port"
360-
#define USBD_CDC_ACM_DIF_STRDESC L"mbed Serial Port"
359+
#define USBD_CDC_ACM_CIF_STRDESC u"mbed Serial Port"
360+
#define USBD_CDC_ACM_DIF_STRDESC u"mbed Serial Port"
361361
#define USBD_CDC_ACM_SENDBUF_SIZE USBD_CDC_ACM_HS_WMAXPACKETSIZE1
362362
#define USBD_CDC_ACM_RECEIVEBUF_SIZE USBD_CDC_ACM_HS_WMAXPACKETSIZE1
363363
#if (((USBD_CDC_ACM_HS_ENABLE1) && (USBD_CDC_ACM_SENDBUF_SIZE < USBD_CDC_ACM_HS_WMAXPACKETSIZE1)) || (USBD_CDC_ACM_SENDBUF_SIZE < USBD_CDC_ACM_WMAXPACKETSIZE1))
@@ -408,7 +408,7 @@
408408
#define USBD_BULK_WMAXPACKETSIZE 64
409409
#define USBD_BULK_HS_ENABLE 1
410410
#define USBD_BULK_HS_WMAXPACKETSIZE 512
411-
#define USBD_BULK_STRDESC L"CMSIS-DAP v2"
411+
#define USBD_BULK_STRDESC u"CMSIS-DAP v2"
412412

413413

414414
/* USB Device Calculations ---------------------------------------------------*/

source/hic_hal/freescale/kl26z/usb_config.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,16 @@
9090
// </e>
9191
// </h>
9292
#define USBD_STRDESC_LANGID 0x0409
93-
#define USBD_STRDESC_MAN L"Arm"
93+
#define USBD_STRDESC_MAN u"Arm"
9494
#ifndef USB_PROD_STR
95-
#define USBD_STRDESC_PROD L"DAPLink CMSIS-DAP"
95+
#define USBD_STRDESC_PROD u"DAPLink CMSIS-DAP"
9696
#else
97-
#define _TOWIDE(x) L ## #x
97+
#define _TOWIDE(x) u ## #x
9898
#define TOWIDE(x) _TOWIDE(x)
9999
#define USBD_STRDESC_PROD TOWIDE(USB_PROD_STR)
100100
#endif
101101
#define USBD_STRDESC_SER_ENABLE 1
102-
#define USBD_STRDESC_SER L"0001A0000000"
102+
#define USBD_STRDESC_SER u"0001A0000000"
103103

104104
// <e0> Class Support
105105
// <i> Enables USB Device Class specific Requests
@@ -169,8 +169,8 @@
169169
#define USBD_HID_HS_ENABLE 0
170170
#define USBD_HID_HS_WMAXPACKETSIZE 64
171171
#define USBD_HID_HS_BINTERVAL 6
172-
#define USBD_HID_STRDESC L"CMSIS-DAP v1"
173-
#define USBD_WEBUSB_STRDESC L"WebUSB: CMSIS-DAP"
172+
#define USBD_HID_STRDESC u"CMSIS-DAP v1"
173+
#define USBD_WEBUSB_STRDESC u"WebUSB: CMSIS-DAP"
174174
#define USBD_HID_INREPORT_NUM 1
175175
#define USBD_HID_OUTREPORT_NUM 1
176176
#define USBD_HID_INREPORT_MAX_SZ 64
@@ -220,7 +220,7 @@
220220
#define USBD_MSC_HS_ENABLE 0
221221
#define USBD_MSC_HS_WMAXPACKETSIZE 512
222222
#define USBD_MSC_HS_BINTERVAL 0
223-
#define USBD_MSC_STRDESC L"USB_MSC"
223+
#define USBD_MSC_STRDESC u"USB_MSC"
224224
// Make sure changes to USBD_MSC_INQUIRY_DATA are coordinated with mbed-ls
225225
// since this is used to detect DAPLink drives
226226
#define USBD_MSC_INQUIRY_DATA "MBED " \
@@ -265,9 +265,9 @@
265265
#define USBD_ADC_BINTERVAL 1
266266
#define USBD_ADC_HS_ENABLE 0
267267
#define USBD_ADC_HS_WMAXPACKETSIZE 64
268-
#define USBD_ADC_CIF_STRDESC L"USB_ADC"
269-
#define USBD_ADC_SIF1_STRDESC L"USB_ADC1"
270-
#define USBD_ADC_SIF2_STRDESC L"USB_ADC2"
268+
#define USBD_ADC_CIF_STRDESC u"USB_ADC"
269+
#define USBD_ADC_SIF1_STRDESC u"USB_ADC1"
270+
#define USBD_ADC_SIF2_STRDESC u"USB_ADC2"
271271
#define USBD_ADC_BSUBFRAMESIZE 2
272272
#define USBD_ADC_BBITRESOLUTION 16
273273
#define USBD_ADC_TSAMFREQ 32000
@@ -347,8 +347,8 @@
347347
#define USBD_CDC_ACM_HS_ENABLE1 0
348348
#define USBD_CDC_ACM_HS_WMAXPACKETSIZE1 64
349349
#define USBD_CDC_ACM_HS_BINTERVAL1 0
350-
#define USBD_CDC_ACM_CIF_STRDESC L"mbed Serial Port"
351-
#define USBD_CDC_ACM_DIF_STRDESC L"mbed Serial Port"
350+
#define USBD_CDC_ACM_CIF_STRDESC u"mbed Serial Port"
351+
#define USBD_CDC_ACM_DIF_STRDESC u"mbed Serial Port"
352352
#define USBD_CDC_ACM_SENDBUF_SIZE 64
353353
#define USBD_CDC_ACM_RECEIVEBUF_SIZE 64
354354
#if (((USBD_CDC_ACM_HS_ENABLE1) && (USBD_CDC_ACM_SENDBUF_SIZE < USBD_CDC_ACM_HS_WMAXPACKETSIZE1)) || (USBD_CDC_ACM_SENDBUF_SIZE < USBD_CDC_ACM_WMAXPACKETSIZE1))
@@ -399,7 +399,7 @@
399399
#define USBD_BULK_WMAXPACKETSIZE 64
400400
#define USBD_BULK_HS_ENABLE 0
401401
#define USBD_BULK_HS_WMAXPACKETSIZE 512
402-
#define USBD_BULK_STRDESC L"CMSIS-DAP v2"
402+
#define USBD_BULK_STRDESC u"CMSIS-DAP v2"
403403

404404

405405
/* USB Device Calculations ---------------------------------------------------*/

0 commit comments

Comments
 (0)