From 910516bd8ae604fd822e345cfa6ad1725119e339 Mon Sep 17 00:00:00 2001 From: Kizarm Date: Sun, 13 Oct 2024 11:25:54 +0200 Subject: [PATCH] remove string.py --- V203/usb/cdc/Makefile | 3 --- V203/usb/cdc/string.py | 24 ----------------------- V203/usb/cdc/{usb_desc.c => usb_desc.cpp} | 20 +++++++++++++++++-- V203/usb/cdc/usb_desc.h | 12 +++++++++--- 4 files changed, 27 insertions(+), 32 deletions(-) delete mode 100755 V203/usb/cdc/string.py rename V203/usb/cdc/{usb_desc.c => usb_desc.cpp} (74%) diff --git a/V203/usb/cdc/Makefile b/V203/usb/cdc/Makefile index 201205a..52ddce6 100644 --- a/V203/usb/cdc/Makefile +++ b/V203/usb/cdc/Makefile @@ -25,9 +25,6 @@ BOBJS = $(addprefix $(BLD),$(OBJS)) all: $(BLD) $(PRJ).elf # ... atd. -include $(BLD)*.d -mystrings.inc: string.py - ./string.py -usb_desc.c: mystrings.inc # linker $(PRJ).elf: $(BOBJS) -@echo [LD $(TOOL),$(TARGET)] $@ diff --git a/V203/usb/cdc/string.py b/V203/usb/cdc/string.py deleted file mode 100755 index b4f9624..0000000 --- a/V203/usb/cdc/string.py +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env python3 - -strings = [["MyManuInfo","Kizarm labs."],["MyProdInfo","USB <=> Serial"],["MySerNumInfo","0123456789"],] - -def print_string (s): - name = bytearray (s[1], 'utf-8') - r = 'const uint8_t {0:s} [] = {{\n '.format (s[0]) - r += '0x{0:02X},0x03,'.format (2 * (len (name) + 1)) - for e in name: - r += '\'{0:c}\',0,'.format (e) - r = r[:-1] - r += '\n};\n' - return r - -def print_strings (filename): - r = '' - for s in strings: r += print_string (s) - #print (r) - f = open (filename, 'w') - f.write (r) - f.close - -if __name__ == "__main__": - print_strings ('mystrings.inc') diff --git a/V203/usb/cdc/usb_desc.c b/V203/usb/cdc/usb_desc.cpp similarity index 74% rename from V203/usb/cdc/usb_desc.c rename to V203/usb/cdc/usb_desc.cpp index 3e1541b..42f8109 100644 --- a/V203/usb/cdc/usb_desc.c +++ b/V203/usb/cdc/usb_desc.cpp @@ -61,9 +61,25 @@ const uint8_t MyCfgDescr[] = /* Endpoint descriptor */ 0x07, 0x05, 0x83, 0x02, (uint8_t)DEF_USBD_ENDP3_SIZE, (uint8_t)( DEF_USBD_ENDP3_SIZE >> 8 ), 0x00, }; - +#define USB_DTYPE_STRING 3u /* Language Descriptor */ const uint8_t MyLangDescr[] = { 0x04, 0x03, 0x09, 0x04 }; -#include "mystrings.inc" +template struct w_text { + uint8_t len, typ; + const char16_t str [N]; +}__attribute__((packed)); + +#define WSTR1 (u"Kizarm Labs.") +#define WSTR2 (u"USB <=> USART") +#define WSTR3 (u"0001") + +static const w_text<(sizeof WSTR1 >> 1u)> str_1 = {sizeof (str_1) - 2u, USB_DTYPE_STRING, {WSTR1}}; +static const w_text<(sizeof WSTR2 >> 1u)> str_2 = {sizeof (str_2) - 2u, USB_DTYPE_STRING, {WSTR2}}; +static const w_text<(sizeof WSTR3 >> 1u)> str_3 = {sizeof (str_3) - 2u, USB_DTYPE_STRING, {WSTR3}}; + +const uint8_t * MyManuInfo = reinterpret_cast (&str_1); +const uint8_t * MyProdInfo = reinterpret_cast (&str_2); +const uint8_t * MySerNumInfo = reinterpret_cast (&str_3); + diff --git a/V203/usb/cdc/usb_desc.h b/V203/usb/cdc/usb_desc.h index f2360af..57d89f2 100644 --- a/V203/usb/cdc/usb_desc.h +++ b/V203/usb/cdc/usb_desc.h @@ -57,11 +57,17 @@ /******************************************************************************/ /* external variables */ +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus extern const uint8_t MyDevDescr[ ]; extern const uint8_t MyCfgDescr[ ]; extern const uint8_t MyLangDescr[ ]; -extern const uint8_t MyManuInfo[ ]; -extern const uint8_t MyProdInfo[ ]; -extern const uint8_t MySerNumInfo[ ]; +extern const uint8_t * MyManuInfo; +extern const uint8_t * MyProdInfo; +extern const uint8_t * MySerNumInfo; +#ifdef __cplusplus +}; +#endif // __cplusplus #endif /* USER_USB_DESC_H_ */