remove string.py

This commit is contained in:
Kizarm 2024-10-13 11:25:54 +02:00
parent 6770ef1f7e
commit 910516bd8a
4 changed files with 27 additions and 32 deletions

View file

@ -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)] $@

View file

@ -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')

View file

@ -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<const unsigned N> 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<const uint8_t*> (&str_1);
const uint8_t * MyProdInfo = reinterpret_cast<const uint8_t*> (&str_2);
const uint8_t * MySerNumInfo = reinterpret_cast<const uint8_t*> (&str_3);

View file

@ -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_ */