Skip to content

Commit

Permalink
Use char16_t for UTF-16 strings in the USB driver
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Collingbourne <[email protected]>
  • Loading branch information
pcc committed Feb 7, 2023
1 parent 038c2d3 commit 4be0eda
Show file tree
Hide file tree
Showing 15 changed files with 203 additions and 173 deletions.
32 changes: 32 additions & 0 deletions source/daplink/uchar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @file uchar.h
* @brief Compatibility for libcs without uchar.h
*
* DAPLink Interface Firmware
* Copyright (c) 2023 Google LLC, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef DAPLINK_UCHAR_H
#define DAPLINK_UCHAR_H

#if __has_include_next(<uchar.h>)
#include_next <uchar.h>
#else
#include <stdint.h>
typedef uint16_t char16_t;
#endif

#endif
26 changes: 13 additions & 13 deletions source/hic_hal/atmel/sam3u2c/usb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@
// </e>
// </h>
#define USBD_STRDESC_LANGID 0x0409
#define USBD_STRDESC_MAN L"Arm"
#define USBD_STRDESC_MAN u"Arm"
#ifndef USB_PROD_STR
#define USBD_STRDESC_PROD L"DAPLink CMSIS-DAP"
#define USBD_STRDESC_PROD u"DAPLink CMSIS-DAP"
#else
#define _TOWIDE(x) L ## #x
#define _TOWIDE(x) u ## #x
#define TOWIDE(x) _TOWIDE(x)
#define USBD_STRDESC_PROD TOWIDE(USB_PROD_STR)
#endif
#define USBD_STRDESC_SER_ENABLE 1
#define USBD_STRDESC_SER L"0001A0000000"
#define USBD_STRDESC_SER u"0001A0000000"

// <e0> Class Support
// <i> Enables USB Device Class specific Requests
Expand Down Expand Up @@ -169,8 +169,8 @@
#define USBD_HID_HS_ENABLE 1
#define USBD_HID_HS_WMAXPACKETSIZE 64
#define USBD_HID_HS_BINTERVAL 1
#define USBD_HID_STRDESC L"CMSIS-DAP v1"
#define USBD_WEBUSB_STRDESC L"WebUSB: CMSIS-DAP"
#define USBD_HID_STRDESC u"CMSIS-DAP v1"
#define USBD_WEBUSB_STRDESC u"WebUSB: CMSIS-DAP"
#define USBD_HID_INREPORT_NUM 1
#define USBD_HID_OUTREPORT_NUM 1
#define USBD_HID_INREPORT_MAX_SZ 64
Expand Down Expand Up @@ -221,7 +221,7 @@
#define USBD_MSC_HS_ENABLE 1
#define USBD_MSC_HS_WMAXPACKETSIZE 512
#define USBD_MSC_HS_BINTERVAL 0
#define USBD_MSC_STRDESC L"USB_MSC"
#define USBD_MSC_STRDESC u"USB_MSC"
// Make sure changes to USBD_MSC_INQUIRY_DATA are coordinated with mbed-ls
// since this is used to detect DAPLink drives
#define USBD_MSC_INQUIRY_DATA "MBED " \
Expand Down Expand Up @@ -266,9 +266,9 @@
#define USBD_ADC_BINTERVAL 1
#define USBD_ADC_HS_ENABLE 0
#define USBD_ADC_HS_WMAXPACKETSIZE 64
#define USBD_ADC_CIF_STRDESC L"USB_ADC"
#define USBD_ADC_SIF1_STRDESC L"USB_ADC1"
#define USBD_ADC_SIF2_STRDESC L"USB_ADC2"
#define USBD_ADC_CIF_STRDESC u"USB_ADC"
#define USBD_ADC_SIF1_STRDESC u"USB_ADC1"
#define USBD_ADC_SIF2_STRDESC u"USB_ADC2"
#define USBD_ADC_BSUBFRAMESIZE 2
#define USBD_ADC_BBITRESOLUTION 16
#define USBD_ADC_TSAMFREQ 32000
Expand Down Expand Up @@ -349,8 +349,8 @@
#define USBD_CDC_ACM_HS_ENABLE1 1
#define USBD_CDC_ACM_HS_WMAXPACKETSIZE1 512
#define USBD_CDC_ACM_HS_BINTERVAL1 1
#define USBD_CDC_ACM_CIF_STRDESC L"mbed Serial Port"
#define USBD_CDC_ACM_DIF_STRDESC L"mbed Serial Port"
#define USBD_CDC_ACM_CIF_STRDESC u"mbed Serial Port"
#define USBD_CDC_ACM_DIF_STRDESC u"mbed Serial Port"
#define USBD_CDC_ACM_SENDBUF_SIZE USBD_CDC_ACM_HS_WMAXPACKETSIZE1
#define USBD_CDC_ACM_RECEIVEBUF_SIZE USBD_CDC_ACM_HS_WMAXPACKETSIZE1
#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))
Expand Down Expand Up @@ -401,7 +401,7 @@
#define USBD_BULK_WMAXPACKETSIZE 64
#define USBD_BULK_HS_ENABLE 1
#define USBD_BULK_HS_WMAXPACKETSIZE 512
#define USBD_BULK_STRDESC L"CMSIS-DAP v2"
#define USBD_BULK_STRDESC u"CMSIS-DAP v2"


/* USB Device Calculations ---------------------------------------------------*/
Expand Down
26 changes: 13 additions & 13 deletions source/hic_hal/freescale/k20dx/usb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@
// </e>
// </h>
#define USBD_STRDESC_LANGID 0x0409
#define USBD_STRDESC_MAN L"Arm"
#define USBD_STRDESC_MAN u"Arm"
#ifndef USB_PROD_STR
#define USBD_STRDESC_PROD L"DAPLink CMSIS-DAP"
#define USBD_STRDESC_PROD u"DAPLink CMSIS-DAP"
#else
#define _TOWIDE(x) L ## #x
#define _TOWIDE(x) u ## #x
#define TOWIDE(x) _TOWIDE(x)
#define USBD_STRDESC_PROD TOWIDE(USB_PROD_STR)
#endif
#define USBD_STRDESC_SER_ENABLE 1
#define USBD_STRDESC_SER L"0001A0000000"
#define USBD_STRDESC_SER u"0001A0000000"

// <e0> Class Support
// <i> Enables USB Device Class specific Requests
Expand Down Expand Up @@ -169,8 +169,8 @@
#define USBD_HID_HS_ENABLE 0
#define USBD_HID_HS_WMAXPACKETSIZE 64
#define USBD_HID_HS_BINTERVAL 6
#define USBD_HID_STRDESC L"CMSIS-DAP v1"
#define USBD_WEBUSB_STRDESC L"WebUSB: CMSIS-DAP"
#define USBD_HID_STRDESC u"CMSIS-DAP v1"
#define USBD_WEBUSB_STRDESC u"WebUSB: CMSIS-DAP"
#define USBD_HID_INREPORT_NUM 1
#define USBD_HID_OUTREPORT_NUM 1
#define USBD_HID_INREPORT_MAX_SZ 64
Expand Down Expand Up @@ -220,7 +220,7 @@
#define USBD_MSC_HS_ENABLE 0
#define USBD_MSC_HS_WMAXPACKETSIZE 512
#define USBD_MSC_HS_BINTERVAL 0
#define USBD_MSC_STRDESC L"USB_MSC"
#define USBD_MSC_STRDESC u"USB_MSC"
// Make sure changes to USBD_MSC_INQUIRY_DATA are coordinated with mbed-ls
// since this is used to detect DAPLink drives
#define USBD_MSC_INQUIRY_DATA "MBED " \
Expand Down Expand Up @@ -265,9 +265,9 @@
#define USBD_ADC_BINTERVAL 1
#define USBD_ADC_HS_ENABLE 0
#define USBD_ADC_HS_WMAXPACKETSIZE 64
#define USBD_ADC_CIF_STRDESC L"USB_ADC"
#define USBD_ADC_SIF1_STRDESC L"USB_ADC1"
#define USBD_ADC_SIF2_STRDESC L"USB_ADC2"
#define USBD_ADC_CIF_STRDESC u"USB_ADC"
#define USBD_ADC_SIF1_STRDESC u"USB_ADC1"
#define USBD_ADC_SIF2_STRDESC u"USB_ADC2"
#define USBD_ADC_BSUBFRAMESIZE 2
#define USBD_ADC_BBITRESOLUTION 16
#define USBD_ADC_TSAMFREQ 32000
Expand Down Expand Up @@ -347,8 +347,8 @@
#define USBD_CDC_ACM_HS_ENABLE1 0
#define USBD_CDC_ACM_HS_WMAXPACKETSIZE1 64
#define USBD_CDC_ACM_HS_BINTERVAL1 0
#define USBD_CDC_ACM_CIF_STRDESC L"mbed Serial Port"
#define USBD_CDC_ACM_DIF_STRDESC L"mbed Serial Port"
#define USBD_CDC_ACM_CIF_STRDESC u"mbed Serial Port"
#define USBD_CDC_ACM_DIF_STRDESC u"mbed Serial Port"
#define USBD_CDC_ACM_SENDBUF_SIZE 64
#define USBD_CDC_ACM_RECEIVEBUF_SIZE 64
#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))
Expand Down Expand Up @@ -399,7 +399,7 @@
#define USBD_BULK_WMAXPACKETSIZE 64
#define USBD_BULK_HS_ENABLE 0
#define USBD_BULK_HS_WMAXPACKETSIZE 512
#define USBD_BULK_STRDESC L"CMSIS-DAP v2"
#define USBD_BULK_STRDESC u"CMSIS-DAP v2"


/* USB Device Calculations ---------------------------------------------------*/
Expand Down
26 changes: 13 additions & 13 deletions source/hic_hal/freescale/k26f/usb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,16 @@
// </e>
// </h>
#define USBD_STRDESC_LANGID 0x0409
#define USBD_STRDESC_MAN L"Arm"
#define USBD_STRDESC_MAN u"Arm"
#ifndef USB_PROD_STR
#define USBD_STRDESC_PROD L"DAPLink CMSIS-DAP"
#define USBD_STRDESC_PROD u"DAPLink CMSIS-DAP"
#else
#define _TOWIDE(x) L ## #x
#define _TOWIDE(x) u ## #x
#define TOWIDE(x) _TOWIDE(x)
#define USBD_STRDESC_PROD TOWIDE(USB_PROD_STR)
#endif
#define USBD_STRDESC_SER_ENABLE 1
#define USBD_STRDESC_SER L"0001A0000000"
#define USBD_STRDESC_SER u"0001A0000000"

// <e0> Class Support
// <i> Enables USB Device Class specific Requests
Expand Down Expand Up @@ -178,8 +178,8 @@
#define USBD_HID_HS_ENABLE 1
#define USBD_HID_HS_WMAXPACKETSIZE 64 //| (2<<11)
#define USBD_HID_HS_BINTERVAL 1
#define USBD_HID_STRDESC L"CMSIS-DAP v1"
#define USBD_WEBUSB_STRDESC L"WebUSB: CMSIS-DAP"
#define USBD_HID_STRDESC u"CMSIS-DAP v1"
#define USBD_WEBUSB_STRDESC u"WebUSB: CMSIS-DAP"
#define USBD_HID_INREPORT_NUM 1
#define USBD_HID_OUTREPORT_NUM 1
#define USBD_HID_INREPORT_MAX_SZ 64
Expand Down Expand Up @@ -229,7 +229,7 @@
#define USBD_MSC_HS_ENABLE 1
#define USBD_MSC_HS_WMAXPACKETSIZE 512
#define USBD_MSC_HS_BINTERVAL 0
#define USBD_MSC_STRDESC L"USB_MSC"
#define USBD_MSC_STRDESC u"USB_MSC"
// Make sure changes to USBD_MSC_INQUIRY_DATA are coordinated with mbed-ls
// since this is used to detect DAPLink drives
#define USBD_MSC_INQUIRY_DATA "MBED " \
Expand Down Expand Up @@ -274,9 +274,9 @@
#define USBD_ADC_BINTERVAL 1
#define USBD_ADC_HS_ENABLE 0
#define USBD_ADC_HS_WMAXPACKETSIZE 64
#define USBD_ADC_CIF_STRDESC L"USB_ADC"
#define USBD_ADC_SIF1_STRDESC L"USB_ADC1"
#define USBD_ADC_SIF2_STRDESC L"USB_ADC2"
#define USBD_ADC_CIF_STRDESC u"USB_ADC"
#define USBD_ADC_SIF1_STRDESC u"USB_ADC1"
#define USBD_ADC_SIF2_STRDESC u"USB_ADC2"
#define USBD_ADC_BSUBFRAMESIZE 2
#define USBD_ADC_BBITRESOLUTION 16
#define USBD_ADC_TSAMFREQ 32000
Expand Down Expand Up @@ -356,8 +356,8 @@
#define USBD_CDC_ACM_HS_ENABLE1 1
#define USBD_CDC_ACM_HS_WMAXPACKETSIZE1 512
#define USBD_CDC_ACM_HS_BINTERVAL1 1
#define USBD_CDC_ACM_CIF_STRDESC L"mbed Serial Port"
#define USBD_CDC_ACM_DIF_STRDESC L"mbed Serial Port"
#define USBD_CDC_ACM_CIF_STRDESC u"mbed Serial Port"
#define USBD_CDC_ACM_DIF_STRDESC u"mbed Serial Port"
#define USBD_CDC_ACM_SENDBUF_SIZE USBD_CDC_ACM_HS_WMAXPACKETSIZE1
#define USBD_CDC_ACM_RECEIVEBUF_SIZE USBD_CDC_ACM_HS_WMAXPACKETSIZE1
#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))
Expand Down Expand Up @@ -408,7 +408,7 @@
#define USBD_BULK_WMAXPACKETSIZE 64
#define USBD_BULK_HS_ENABLE 1
#define USBD_BULK_HS_WMAXPACKETSIZE 512
#define USBD_BULK_STRDESC L"CMSIS-DAP v2"
#define USBD_BULK_STRDESC u"CMSIS-DAP v2"


/* USB Device Calculations ---------------------------------------------------*/
Expand Down
26 changes: 13 additions & 13 deletions source/hic_hal/freescale/kl26z/usb_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@
// </e>
// </h>
#define USBD_STRDESC_LANGID 0x0409
#define USBD_STRDESC_MAN L"Arm"
#define USBD_STRDESC_MAN u"Arm"
#ifndef USB_PROD_STR
#define USBD_STRDESC_PROD L"DAPLink CMSIS-DAP"
#define USBD_STRDESC_PROD u"DAPLink CMSIS-DAP"
#else
#define _TOWIDE(x) L ## #x
#define _TOWIDE(x) u ## #x
#define TOWIDE(x) _TOWIDE(x)
#define USBD_STRDESC_PROD TOWIDE(USB_PROD_STR)
#endif
#define USBD_STRDESC_SER_ENABLE 1
#define USBD_STRDESC_SER L"0001A0000000"
#define USBD_STRDESC_SER u"0001A0000000"

// <e0> Class Support
// <i> Enables USB Device Class specific Requests
Expand Down Expand Up @@ -169,8 +169,8 @@
#define USBD_HID_HS_ENABLE 0
#define USBD_HID_HS_WMAXPACKETSIZE 64
#define USBD_HID_HS_BINTERVAL 6
#define USBD_HID_STRDESC L"CMSIS-DAP v1"
#define USBD_WEBUSB_STRDESC L"WebUSB: CMSIS-DAP"
#define USBD_HID_STRDESC u"CMSIS-DAP v1"
#define USBD_WEBUSB_STRDESC u"WebUSB: CMSIS-DAP"
#define USBD_HID_INREPORT_NUM 1
#define USBD_HID_OUTREPORT_NUM 1
#define USBD_HID_INREPORT_MAX_SZ 64
Expand Down Expand Up @@ -220,7 +220,7 @@
#define USBD_MSC_HS_ENABLE 0
#define USBD_MSC_HS_WMAXPACKETSIZE 512
#define USBD_MSC_HS_BINTERVAL 0
#define USBD_MSC_STRDESC L"USB_MSC"
#define USBD_MSC_STRDESC u"USB_MSC"
// Make sure changes to USBD_MSC_INQUIRY_DATA are coordinated with mbed-ls
// since this is used to detect DAPLink drives
#define USBD_MSC_INQUIRY_DATA "MBED " \
Expand Down Expand Up @@ -265,9 +265,9 @@
#define USBD_ADC_BINTERVAL 1
#define USBD_ADC_HS_ENABLE 0
#define USBD_ADC_HS_WMAXPACKETSIZE 64
#define USBD_ADC_CIF_STRDESC L"USB_ADC"
#define USBD_ADC_SIF1_STRDESC L"USB_ADC1"
#define USBD_ADC_SIF2_STRDESC L"USB_ADC2"
#define USBD_ADC_CIF_STRDESC u"USB_ADC"
#define USBD_ADC_SIF1_STRDESC u"USB_ADC1"
#define USBD_ADC_SIF2_STRDESC u"USB_ADC2"
#define USBD_ADC_BSUBFRAMESIZE 2
#define USBD_ADC_BBITRESOLUTION 16
#define USBD_ADC_TSAMFREQ 32000
Expand Down Expand Up @@ -347,8 +347,8 @@
#define USBD_CDC_ACM_HS_ENABLE1 0
#define USBD_CDC_ACM_HS_WMAXPACKETSIZE1 64
#define USBD_CDC_ACM_HS_BINTERVAL1 0
#define USBD_CDC_ACM_CIF_STRDESC L"mbed Serial Port"
#define USBD_CDC_ACM_DIF_STRDESC L"mbed Serial Port"
#define USBD_CDC_ACM_CIF_STRDESC u"mbed Serial Port"
#define USBD_CDC_ACM_DIF_STRDESC u"mbed Serial Port"
#define USBD_CDC_ACM_SENDBUF_SIZE 64
#define USBD_CDC_ACM_RECEIVEBUF_SIZE 64
#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))
Expand Down Expand Up @@ -399,7 +399,7 @@
#define USBD_BULK_WMAXPACKETSIZE 64
#define USBD_BULK_HS_ENABLE 0
#define USBD_BULK_HS_WMAXPACKETSIZE 512
#define USBD_BULK_STRDESC L"CMSIS-DAP v2"
#define USBD_BULK_STRDESC u"CMSIS-DAP v2"


/* USB Device Calculations ---------------------------------------------------*/
Expand Down
Loading

0 comments on commit 4be0eda

Please sign in to comment.