@@ -62,6 +62,7 @@ bool common_hal_usb_core_device_construct(usb_core_device_obj_t *self, uint8_t d
62
62
return false;
63
63
}
64
64
self -> device_number = device_number ;
65
+ self -> first_langid = 0 ;
65
66
_xfer_result = 0xff ;
66
67
return true;
67
68
}
@@ -108,9 +109,23 @@ STATIC mp_obj_t _get_string(const uint16_t *temp_buf) {
108
109
return utf16le_to_string (temp_buf + 1 , utf16_len );
109
110
}
110
111
112
+ STATIC void _get_langid (usb_core_device_obj_t * self ) {
113
+ if (self -> first_langid != 0 ) {
114
+ return ;
115
+ }
116
+ // Two control bytes and one uint16_t language code.
117
+ uint16_t temp_buf [2 ];
118
+ if (!tuh_descriptor_get_string (self -> device_number , 0 , 0 , temp_buf , sizeof (temp_buf ), _transfer_done_cb , 0 ) ||
119
+ !_wait_for_callback ()) {
120
+ return ;
121
+ }
122
+ self -> first_langid = temp_buf [1 ];
123
+ }
124
+
111
125
mp_obj_t common_hal_usb_core_device_get_serial_number (usb_core_device_obj_t * self ) {
112
126
uint16_t temp_buf [127 ];
113
- if (!tuh_descriptor_get_serial_string (self -> device_number , 0 , temp_buf , MP_ARRAY_SIZE (temp_buf ), _transfer_done_cb , 0 ) ||
127
+ _get_langid (self );
128
+ if (!tuh_descriptor_get_serial_string (self -> device_number , self -> first_langid , temp_buf , sizeof (temp_buf ), _transfer_done_cb , 0 ) ||
114
129
!_wait_for_callback ()) {
115
130
return mp_const_none ;
116
131
}
@@ -119,7 +134,8 @@ mp_obj_t common_hal_usb_core_device_get_serial_number(usb_core_device_obj_t *sel
119
134
120
135
mp_obj_t common_hal_usb_core_device_get_product (usb_core_device_obj_t * self ) {
121
136
uint16_t temp_buf [127 ];
122
- if (!tuh_descriptor_get_product_string (self -> device_number , 0 , temp_buf , MP_ARRAY_SIZE (temp_buf ), _transfer_done_cb , 0 ) ||
137
+ _get_langid (self );
138
+ if (!tuh_descriptor_get_product_string (self -> device_number , self -> first_langid , temp_buf , sizeof (temp_buf ), _transfer_done_cb , 0 ) ||
123
139
!_wait_for_callback ()) {
124
140
return mp_const_none ;
125
141
}
@@ -128,7 +144,8 @@ mp_obj_t common_hal_usb_core_device_get_product(usb_core_device_obj_t *self) {
128
144
129
145
mp_obj_t common_hal_usb_core_device_get_manufacturer (usb_core_device_obj_t * self ) {
130
146
uint16_t temp_buf [127 ];
131
- if (!tuh_descriptor_get_manufacturer_string (self -> device_number , 0 , temp_buf , MP_ARRAY_SIZE (temp_buf ), _transfer_done_cb , 0 ) ||
147
+ _get_langid (self );
148
+ if (!tuh_descriptor_get_manufacturer_string (self -> device_number , self -> first_langid , temp_buf , sizeof (temp_buf ), _transfer_done_cb , 0 ) ||
132
149
!_wait_for_callback ()) {
133
150
return mp_const_none ;
134
151
}
0 commit comments