@@ -62,6 +62,7 @@ bool common_hal_usb_core_device_construct(usb_core_device_obj_t *self, uint8_t d
6262 return false;
6363 }
6464 self -> device_number = device_number ;
65+ self -> first_langid = 0 ;
6566 _xfer_result = 0xff ;
6667 return true;
6768}
@@ -108,9 +109,23 @@ STATIC mp_obj_t _get_string(const uint16_t *temp_buf) {
108109 return utf16le_to_string (temp_buf + 1 , utf16_len );
109110}
110111
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+
111125mp_obj_t common_hal_usb_core_device_get_serial_number (usb_core_device_obj_t * self ) {
112126 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 ) ||
114129 !_wait_for_callback ()) {
115130 return mp_const_none ;
116131 }
@@ -119,7 +134,8 @@ mp_obj_t common_hal_usb_core_device_get_serial_number(usb_core_device_obj_t *sel
119134
120135mp_obj_t common_hal_usb_core_device_get_product (usb_core_device_obj_t * self ) {
121136 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 ) ||
123139 !_wait_for_callback ()) {
124140 return mp_const_none ;
125141 }
@@ -128,7 +144,8 @@ mp_obj_t common_hal_usb_core_device_get_product(usb_core_device_obj_t *self) {
128144
129145mp_obj_t common_hal_usb_core_device_get_manufacturer (usb_core_device_obj_t * self ) {
130146 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 ) ||
132149 !_wait_for_callback ()) {
133150 return mp_const_none ;
134151 }
0 commit comments