@@ -78,13 +78,145 @@ STATIC mp_obj_t usb_midi_enable(void) {
78
78
}
79
79
MP_DEFINE_CONST_FUN_OBJ_0 (usb_midi_enable_obj , usb_midi_enable );
80
80
81
+ //| def set_streaming_interface_name(interface_name: str) -> None:
82
+ //| """Override the MIDI interface name in the USB Interface Descriptor.
83
+ //|
84
+ //| ``interface_name`` must be an ASCII string (or buffer) of at most 126 characters.
85
+ //|
86
+ //| This method must be called in boot.py to have any effect.
87
+ //|
88
+ //| Not available on boards without native USB support.
89
+ //| """
90
+ //| ...
91
+ //|
92
+ STATIC mp_obj_t usb_midi_set_streaming_interface_name (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
93
+ static const mp_arg_t allowed_args [] = {
94
+ { MP_QSTR_interface_name , MP_ARG_OBJ | MP_ARG_REQUIRED , {.u_rom_obj = mp_const_none } }
95
+ };
96
+ mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
97
+ mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , (mp_arg_val_t * )& args );
98
+
99
+ mp_buffer_info_t interface_name ;
100
+ mp_get_buffer_raise (args [0 ].u_obj , & interface_name , MP_BUFFER_READ );
101
+ mp_arg_validate_length_range (interface_name .len , 1 , 126 , MP_QSTR_interface_name );
102
+
103
+ if (custom_usb_midi_streaming_interface_name == NULL ) {
104
+ custom_usb_midi_streaming_interface_name = port_malloc (sizeof (char ) * 128 , false);
105
+ }
106
+ memcpy (custom_usb_midi_streaming_interface_name , interface_name .buf , interface_name .len );
107
+ custom_usb_midi_streaming_interface_name [interface_name .len ] = 0 ;
108
+
109
+ return mp_const_none ;
110
+ }
111
+ MP_DEFINE_CONST_FUN_OBJ_KW (usb_midi_set_streaming_interface_name_obj , 1 , usb_midi_set_streaming_interface_name );
112
+
113
+ //| def set_audio_control_interface_name(interface_name: str) -> None:
114
+ //| """Override the audio control interface name in the USB Interface Descriptor.
115
+ //|
116
+ //| ``interface_name`` must be an ASCII string (or buffer) of at most 126 characters.
117
+ //|
118
+ //| This method must be called in boot.py to have any effect.
119
+ //|
120
+ //| Not available on boards without native USB support.
121
+ //| """
122
+ //| ...
123
+ //|
124
+ STATIC mp_obj_t usb_midi_set_audio_control_interface_name (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
125
+ static const mp_arg_t allowed_args [] = {
126
+ { MP_QSTR_interface_name , MP_ARG_OBJ | MP_ARG_REQUIRED , {.u_rom_obj = mp_const_none } }
127
+ };
128
+ mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
129
+ mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , (mp_arg_val_t * )& args );
130
+
131
+ mp_buffer_info_t interface_name ;
132
+ mp_get_buffer_raise (args [0 ].u_obj , & interface_name , MP_BUFFER_READ );
133
+ mp_arg_validate_length_range (interface_name .len , 1 , 126 , MP_QSTR_interface_name );
134
+
135
+ if (custom_usb_midi_audio_control_interface_name == NULL ) {
136
+ custom_usb_midi_audio_control_interface_name = port_malloc (sizeof (char ) * 128 , false);
137
+ }
138
+ memcpy (custom_usb_midi_audio_control_interface_name , interface_name .buf , interface_name .len );
139
+ custom_usb_midi_audio_control_interface_name [interface_name .len ] = 0 ;
140
+
141
+ return mp_const_none ;
142
+ }
143
+ MP_DEFINE_CONST_FUN_OBJ_KW (usb_midi_set_audio_control_interface_name_obj , 1 , usb_midi_set_audio_control_interface_name );
144
+
145
+ //| def set_in_jack_name(jack_name: str) -> None:
146
+ //| """Override the MIDI IN jack name in the USB Interface Descriptor.
147
+ //|
148
+ //| ``jack_name`` must be an ASCII string (or buffer) of at most 126 characters.
149
+ //|
150
+ //| This method must be called in boot.py to have any effect.
151
+ //|
152
+ //| Not available on boards without native USB support.
153
+ //| """
154
+ //| ...
155
+ //|
156
+ STATIC mp_obj_t usb_midi_set_in_jack_name (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
157
+ static const mp_arg_t allowed_args [] = {
158
+ { MP_QSTR_jack_name , MP_ARG_OBJ | MP_ARG_REQUIRED , {.u_rom_obj = mp_const_none } }
159
+ };
160
+ mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
161
+ mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , (mp_arg_val_t * )& args );
162
+
163
+ mp_buffer_info_t jack_name ;
164
+ mp_get_buffer_raise (args [0 ].u_obj , & jack_name , MP_BUFFER_READ );
165
+ mp_arg_validate_length_range (jack_name .len , 1 , 126 , MP_QSTR_jack_name );
166
+
167
+ if (custom_usb_midi_in_jack_name == NULL ) {
168
+ custom_usb_midi_in_jack_name = port_malloc (sizeof (char ) * 128 , false);
169
+ }
170
+ memcpy (custom_usb_midi_in_jack_name , jack_name .buf , jack_name .len );
171
+ custom_usb_midi_in_jack_name [jack_name .len ] = 0 ;
172
+
173
+ return mp_const_none ;
174
+ }
175
+ MP_DEFINE_CONST_FUN_OBJ_KW (usb_midi_set_in_jack_name_obj , 1 , usb_midi_set_in_jack_name );
176
+
177
+ //| def set_out_jack_name(jack_name: str) -> None:
178
+ //| """Override the MIDI OUT jack name in the USB Interface Descriptor.
179
+ //|
180
+ //| ``jack_name`` must be an ASCII string (or buffer) of at most 126 characters.
181
+ //|
182
+ //| This method must be called in boot.py to have any effect.
183
+ //|
184
+ //| Not available on boards without native USB support.
185
+ //| """
186
+ //| ...
187
+ //|
188
+ STATIC mp_obj_t usb_midi_set_out_jack_name (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
189
+ static const mp_arg_t allowed_args [] = {
190
+ { MP_QSTR_jack_name , MP_ARG_OBJ | MP_ARG_REQUIRED , {.u_rom_obj = mp_const_none } }
191
+ };
192
+ mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
193
+ mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , (mp_arg_val_t * )& args );
194
+
195
+ mp_buffer_info_t jack_name ;
196
+ mp_get_buffer_raise (args [0 ].u_obj , & jack_name , MP_BUFFER_READ );
197
+ mp_arg_validate_length_range (jack_name .len , 1 , 126 , MP_QSTR_jack_name );
198
+
199
+ if (custom_usb_midi_out_jack_name == NULL ) {
200
+ custom_usb_midi_out_jack_name = port_malloc (sizeof (char ) * 128 , false);
201
+ }
202
+ memcpy (custom_usb_midi_out_jack_name , jack_name .buf , jack_name .len );
203
+ custom_usb_midi_out_jack_name [jack_name .len ] = 0 ;
204
+
205
+ return mp_const_none ;
206
+ }
207
+ MP_DEFINE_CONST_FUN_OBJ_KW (usb_midi_set_out_jack_name_obj , 1 , usb_midi_set_out_jack_name );
208
+
81
209
mp_map_elem_t usb_midi_module_globals_table [] = {
82
- { MP_ROM_QSTR (MP_QSTR___name__ ), MP_ROM_QSTR (MP_QSTR_usb_midi ) },
83
- { MP_ROM_QSTR (MP_QSTR_disable ), MP_OBJ_FROM_PTR (& usb_midi_disable_obj ) },
84
- { MP_ROM_QSTR (MP_QSTR_enable ), MP_OBJ_FROM_PTR (& usb_midi_enable_obj ) },
85
- { MP_ROM_QSTR (MP_QSTR_ports ), mp_const_empty_tuple },
86
- { MP_ROM_QSTR (MP_QSTR_PortIn ), MP_OBJ_FROM_PTR (& usb_midi_portin_type ) },
87
- { MP_ROM_QSTR (MP_QSTR_PortOut ), MP_OBJ_FROM_PTR (& usb_midi_portout_type ) },
210
+ { MP_ROM_QSTR (MP_QSTR___name__ ), MP_ROM_QSTR (MP_QSTR_usb_midi ) },
211
+ { MP_ROM_QSTR (MP_QSTR_disable ), MP_OBJ_FROM_PTR (& usb_midi_disable_obj ) },
212
+ { MP_ROM_QSTR (MP_QSTR_enable ), MP_OBJ_FROM_PTR (& usb_midi_enable_obj ) },
213
+ { MP_ROM_QSTR (MP_QSTR_ports ), mp_const_empty_tuple },
214
+ { MP_ROM_QSTR (MP_QSTR_PortIn ), MP_OBJ_FROM_PTR (& usb_midi_portin_type ) },
215
+ { MP_ROM_QSTR (MP_QSTR_PortOut ), MP_OBJ_FROM_PTR (& usb_midi_portout_type ) },
216
+ { MP_ROM_QSTR (MP_QSTR_set_streaming_interface_name ), MP_OBJ_FROM_PTR (& usb_midi_set_streaming_interface_name_obj ) },
217
+ { MP_ROM_QSTR (MP_QSTR_set_audio_control_interface_name ), MP_OBJ_FROM_PTR (& usb_midi_set_audio_control_interface_name_obj ) },
218
+ { MP_ROM_QSTR (MP_QSTR_set_in_jack_name ), MP_OBJ_FROM_PTR (& usb_midi_set_in_jack_name_obj ) },
219
+ { MP_ROM_QSTR (MP_QSTR_set_out_jack_name ), MP_OBJ_FROM_PTR (& usb_midi_set_out_jack_name_obj ) },
88
220
};
89
221
90
222
// This isn't const so we can set ports dynamically.
0 commit comments