Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sd = {
- "stringLanguage" : 0x0409,
- "stringVendor" : "STMicroelectronics",
- "stringDeviceDescriptor" : "ChibiOS/Custom Hardware",
- "stringSerialNumber" : "2.5.0"
- }
- def stringDescriptor(descriptor):
- for i in descriptor:
- print "static const uint8_t", i, "[] = {"
- if(type(descriptor[i])==type(1)):
- print " USB_DESC_BYTE(4)," + \
- " /* bLength. */"
- print " USB_DESC_BYTE(USB_DESCRIPTOR_STRING)," \
- + " /* bDescriptorType. */"
- print " USB_DESC_WORD(" + hex(descriptor[i]) + ")" \
- + " /* wLANGID (U.S. English). */"
- print "}\n"
- continue
- num=0
- s = descriptor[i].encode("utf-16")
- s = s[2:]
- print " USB_DESC_BYTE(" + str(len(s)+2) + ")" \
- + " /* bLength. */"
- print " USB_DESC_BYTE(USB_DESCRIPTOR_STRING)," \
- + "/* bDescriptorType. */"
- print " ",
- for j in s:
- if(j)=='\x00':
- print "0,",
- else:
- print "'" + j + "'" + ",",
- num+=1
- if(num==16):
- print "\n ",
- num =0
- print "\n}\n"
- stringDescriptor(sd)
Advertisement
Add Comment
Please, Sign In to add comment