@@ -155,6 +155,37 @@ STATIC mp_obj_t usb_hid_get_boot_device(void) {
155
155
}
156
156
MP_DEFINE_CONST_FUN_OBJ_0 (usb_hid_get_boot_device_obj , usb_hid_get_boot_device );
157
157
158
+
159
+ //| def set_interface_name(
160
+ //| interface_name: str
161
+ //| ) -> None:
162
+ //| """Override HID interface name in the USB Interface Descriptor.
163
+ //|
164
+ //| `interface_name` must be ASCII string (or buffers) of at most 126.
165
+ //|
166
+ //| This method must be called in boot.py to have any effect.
167
+ //|
168
+ //| Not available on boards without native USB support.
169
+ //| """
170
+ //| ...
171
+ //|
172
+ STATIC mp_obj_t usb_hid_set_interface_name (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
173
+ static const mp_arg_t allowed_args [] = {
174
+ { MP_QSTR_interface_name , MP_ARG_OBJ | MP_ARG_REQUIRED , {.u_rom_obj = mp_const_none } }
175
+ };
176
+ mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
177
+ mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , (mp_arg_val_t * )& args );
178
+
179
+ mp_buffer_info_t interface_name ;
180
+ mp_get_buffer_raise (args [0 ].u_obj , & interface_name , MP_BUFFER_READ );
181
+ mp_arg_validate_length_range (interface_name .len , 1 , 126 , MP_QSTR_interface_name );
182
+ memcpy (usb_hid_interface_name_obj .interface_name , interface_name .buf , interface_name .len );
183
+ usb_hid_interface_name_obj .interface_name [interface_name .len ] = 0 ;
184
+
185
+ return mp_const_none ;
186
+ }
187
+ MP_DEFINE_CONST_FUN_OBJ_KW (usb_hid_set_interface_name_obj , 1 , usb_hid_set_interface_name );
188
+
158
189
// usb_hid.devices is set once the usb devices are determined, after boot.py runs.
159
190
STATIC mp_map_elem_t usb_hid_module_globals_table [] = {
160
191
{ MP_ROM_QSTR (MP_QSTR___name__ ), MP_OBJ_NEW_QSTR (MP_QSTR_usb_hid ) },
@@ -163,6 +194,7 @@ STATIC mp_map_elem_t usb_hid_module_globals_table[] = {
163
194
{ MP_ROM_QSTR (MP_QSTR_disable ), MP_OBJ_FROM_PTR (& usb_hid_disable_obj ) },
164
195
{ MP_ROM_QSTR (MP_QSTR_enable ), MP_OBJ_FROM_PTR (& usb_hid_enable_obj ) },
165
196
{ MP_ROM_QSTR (MP_QSTR_get_boot_device ), MP_OBJ_FROM_PTR (& usb_hid_get_boot_device_obj ) },
197
+ { MP_ROM_QSTR (MP_QSTR_set_interface_name ), MP_OBJ_FROM_PTR (& usb_hid_set_interface_name_obj ) },
166
198
};
167
199
168
200
STATIC MP_DEFINE_MUTABLE_DICT (usb_hid_module_globals , usb_hid_module_globals_table );
0 commit comments