/* USB String descriptors can contain at most 126 characters; input strings longer than that are truncated.  */
static unsigned ascii2desc(char const *s, u8 *buf, unsigned len)
/* USB String descriptors can contain at most 126 characters; input strings longer than that are truncated.  */
static unsigned ascii2desc(char const *s, u8 *buf, unsigned len)
{
	unsigned n, t = 2 + 2*strlen(s);
	if (t > 254)
		t = 254;
	if (len > t)
		len = t;
	t += USB_DT_STRING << 8;
	n = len;
	while (n--) {
		*buf++ = t;
		if (!n--)
			break;
		*buf++ = t >> 8;
		t = (unsigned char)*s++;
	}
	return len;
}