repair string descriptors
This commit is contained in:
parent
910516bd8a
commit
b4f5dd0670
4 changed files with 27 additions and 63 deletions
|
@ -295,37 +295,15 @@ void cdc_class::SetupTokenHandler() {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* get usb string descriptor */
|
/* get usb string descriptor */
|
||||||
case USB_DESCR_TYP_STRING:
|
case USB_DESCR_TYP_STRING: {
|
||||||
switch( (uint8_t)( USBFS_SetupReqValue & 0xFF ) ) {
|
const uint8_t order = USBFS_SetupReqValue & 0xFF;
|
||||||
/* Descriptor 0, Language descriptor */
|
if (order < DEF_MAX_STRINGS) {
|
||||||
case DEF_STRING_DESC_LANG:
|
pUSBFS_Descr = StringDescArray [order];
|
||||||
pUSBFS_Descr = MyLangDescr;
|
len = pUSBFS_Descr [0];
|
||||||
len = DEF_USBD_LANG_DESC_LEN;
|
} else {
|
||||||
break;
|
errflag = 0xFF;
|
||||||
|
|
||||||
/* Descriptor 1, Manufacturers String descriptor */
|
|
||||||
case DEF_STRING_DESC_MANU:
|
|
||||||
pUSBFS_Descr = MyManuInfo;
|
|
||||||
len = DEF_USBD_MANU_DESC_LEN;
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* Descriptor 2, Product String descriptor */
|
|
||||||
case DEF_STRING_DESC_PROD:
|
|
||||||
pUSBFS_Descr = MyProdInfo;
|
|
||||||
len = DEF_USBD_PROD_DESC_LEN;
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* Descriptor 3, Serial-number String descriptor */
|
|
||||||
case DEF_STRING_DESC_SERN:
|
|
||||||
pUSBFS_Descr = MySerNumInfo;
|
|
||||||
len = DEF_USBD_SN_DESC_LEN;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
errflag = 0xFF;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
break;
|
} break;
|
||||||
|
|
||||||
default :
|
default :
|
||||||
errflag = 0xFF;
|
errflag = 0xFF;
|
||||||
|
|
|
@ -60,11 +60,6 @@ extern "C" {
|
||||||
#define USB_SYNCH_FRAME 0x0C
|
#define USB_SYNCH_FRAME 0x0C
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DEF_STRING_DESC_LANG 0x00
|
|
||||||
#define DEF_STRING_DESC_MANU 0x01
|
|
||||||
#define DEF_STRING_DESC_PROD 0x02
|
|
||||||
#define DEF_STRING_DESC_SERN 0x03
|
|
||||||
|
|
||||||
/* USB hub class request code */
|
/* USB hub class request code */
|
||||||
#ifndef HUB_GET_DESCRIPTOR
|
#ifndef HUB_GET_DESCRIPTOR
|
||||||
#define HUB_GET_STATUS 0x00
|
#define HUB_GET_STATUS 0x00
|
||||||
|
|
|
@ -61,25 +61,23 @@ const uint8_t MyCfgDescr[] =
|
||||||
/* Endpoint descriptor */
|
/* Endpoint descriptor */
|
||||||
0x07, 0x05, 0x83, 0x02, (uint8_t)DEF_USBD_ENDP3_SIZE, (uint8_t)( DEF_USBD_ENDP3_SIZE >> 8 ), 0x00,
|
0x07, 0x05, 0x83, 0x02, (uint8_t)DEF_USBD_ENDP3_SIZE, (uint8_t)( DEF_USBD_ENDP3_SIZE >> 8 ), 0x00,
|
||||||
};
|
};
|
||||||
#define USB_DTYPE_STRING 3u
|
#define DEF_STRDESC(p,n) w_text<(sizeof(p)>>1)>n={sizeof(n)-2u,3u,{p}}
|
||||||
/* Language Descriptor */
|
|
||||||
const uint8_t MyLangDescr[] = {
|
|
||||||
0x04, 0x03, 0x09, 0x04
|
|
||||||
};
|
|
||||||
template<const unsigned N> struct w_text {
|
template<const unsigned N> struct w_text {
|
||||||
uint8_t len, typ;
|
uint8_t len, typ;
|
||||||
const char16_t str [N];
|
const char16_t str [N];
|
||||||
}__attribute__((packed));
|
};
|
||||||
|
static const DEF_STRDESC((u"Kizarm Labs."), str_1);
|
||||||
|
static const DEF_STRDESC((u"USB <=> USART"),str_2);
|
||||||
|
static const DEF_STRDESC((u"0001"), str_3);
|
||||||
|
/* Language Descriptor */
|
||||||
|
static const uint8_t LangDescr[] = {
|
||||||
|
0x04, 0x03, 0x09, 0x04
|
||||||
|
};
|
||||||
|
const uint8_t * StringDescArray [DEF_MAX_STRINGS] = {
|
||||||
|
LangDescr,
|
||||||
|
reinterpret_cast<const uint8_t*> (&str_1),
|
||||||
|
reinterpret_cast<const uint8_t*> (&str_2),
|
||||||
|
reinterpret_cast<const uint8_t*> (&str_3),
|
||||||
|
};
|
||||||
|
|
||||||
#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);
|
|
||||||
|
|
||||||
|
|
|
@ -50,23 +50,16 @@
|
||||||
#define DEF_USBD_DEVICE_DESC_LEN ((uint8_t)MyDevDescr[0])
|
#define DEF_USBD_DEVICE_DESC_LEN ((uint8_t)MyDevDescr[0])
|
||||||
#define DEF_USBD_CONFIG_DESC_LEN ((uint16_t)MyCfgDescr[2] + (uint16_t)(MyCfgDescr[3] << 8))
|
#define DEF_USBD_CONFIG_DESC_LEN ((uint16_t)MyCfgDescr[2] + (uint16_t)(MyCfgDescr[3] << 8))
|
||||||
#define DEF_USBD_REPORT_DESC_LEN 0
|
#define DEF_USBD_REPORT_DESC_LEN 0
|
||||||
#define DEF_USBD_LANG_DESC_LEN ((uint16_t)MyLangDescr[0])
|
|
||||||
#define DEF_USBD_MANU_DESC_LEN ((uint16_t)MyManuInfo[0])
|
|
||||||
#define DEF_USBD_PROD_DESC_LEN ((uint16_t)MyProdInfo[0])
|
|
||||||
#define DEF_USBD_SN_DESC_LEN ((uint16_t)MySerNumInfo[0])
|
|
||||||
|
|
||||||
|
#define DEF_MAX_STRINGS (4)
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* external variables */
|
/* external variables */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
extern const uint8_t MyDevDescr[ ];
|
extern const uint8_t MyDevDescr[ ];
|
||||||
extern const uint8_t MyCfgDescr[ ];
|
extern const uint8_t MyCfgDescr[ ];
|
||||||
extern const uint8_t MyLangDescr[ ];
|
extern const uint8_t * StringDescArray [DEF_MAX_STRINGS];
|
||||||
|
|
||||||
extern const uint8_t * MyManuInfo;
|
|
||||||
extern const uint8_t * MyProdInfo;
|
|
||||||
extern const uint8_t * MySerNumInfo;
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
};
|
};
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
Loading…
Reference in a new issue