1
1
# MicroPython USB MIDI module
2
2
# MIT license; Copyright (c) 2023 Angus Gratton, Paul Hamshere
3
3
from micropython import const
4
- import ustruct
4
+ import struct
5
5
6
6
from .device import USBInterface
7
7
from .utils import endpoint_descriptor , EP_IN_FLAG
@@ -57,7 +57,7 @@ def get_itf_descriptor(self, num_eps, itf_idx, str_idx):
57
57
desc , strs = super ().get_itf_descriptor (num_eps , itf_idx , str_idx )
58
58
59
59
# Append the class-specific AudioControl interface descriptor
60
- desc += ustruct .pack (
60
+ desc += struct .pack (
61
61
"<BBBHHBB" ,
62
62
9 , # bLength
63
63
0x24 , # bDescriptorType CS_INTERFACE
@@ -124,7 +124,7 @@ def get_itf_descriptor(self, num_eps, itf_idx, str_idx):
124
124
_JACK_OUT_DESC_LEN = const (9 )
125
125
126
126
# Midi Streaming interface descriptor
127
- cs_ms_interface = ustruct .pack (
127
+ cs_ms_interface = struct .pack (
128
128
"<BBBHH" ,
129
129
7 , # bLength
130
130
0x24 , # bDescriptorType CS_INTERFACE
@@ -135,7 +135,7 @@ def get_itf_descriptor(self, num_eps, itf_idx, str_idx):
135
135
)
136
136
137
137
def jack_in_desc (bJackType , bJackID ):
138
- return ustruct .pack (
138
+ return struct .pack (
139
139
"<BBBBBB" ,
140
140
_JACK_IN_DESC_LEN , # bLength
141
141
0x24 , # bDescriptorType CS_INTERFACE
@@ -146,7 +146,7 @@ def jack_in_desc(bJackType, bJackID):
146
146
)
147
147
148
148
def jack_out_desc (bJackType , bJackID , bSourceId , bSourcePin ):
149
- return ustruct .pack (
149
+ return struct .pack (
150
150
"<BBBBBBBBB" ,
151
151
_JACK_OUT_DESC_LEN , # bLength
152
152
0x24 , # bDescriptorType CS_INTERFACE
@@ -250,7 +250,7 @@ def get_endpoint_descriptors(self, ep_addr, str_idx):
250
250
251
251
# rx side, USB "in" endpoint and embedded MIDI IN Jacks
252
252
e_out = endpoint_descriptor (self .ep_in , "bulk" , 64 , 0 )
253
- cs_out = ustruct .pack (
253
+ cs_out = struct .pack (
254
254
"<BBBB" + "B" * self ._num_rx ,
255
255
4 + self ._num_rx , # bLength
256
256
0x25 , # bDescriptorType CS_ENDPOINT
@@ -261,7 +261,7 @@ def get_endpoint_descriptors(self, ep_addr, str_idx):
261
261
262
262
# tx side, USB "out" endpoint and embedded MIDI OUT jacks
263
263
e_in = endpoint_descriptor (self .ep_out , "bulk" , 64 , 0 )
264
- cs_in = ustruct .pack (
264
+ cs_in = struct .pack (
265
265
"<BBBB" + "B" * self ._num_tx ,
266
266
4 + self ._num_tx , # bLength
267
267
0x25 , # bDescriptorType CS_ENDPOINT
@@ -282,11 +282,11 @@ def __init__(self):
282
282
super ().__init__ ()
283
283
284
284
def note_on (self , channel , pitch , vel ):
285
- obuf = ustruct .pack ("<BBBB" , 0x09 , 0x90 | channel , pitch , vel )
285
+ obuf = struct .pack ("<BBBB" , 0x09 , 0x90 | channel , pitch , vel )
286
286
super ().send_data (obuf )
287
287
288
288
def note_off (self , channel , pitch , vel ):
289
- obuf = ustruct .pack ("<BBBB" , 0x08 , 0x80 | channel , pitch , vel )
289
+ obuf = struct .pack ("<BBBB" , 0x08 , 0x80 | channel , pitch , vel )
290
290
super ().send_data (obuf )
291
291
292
292
def start (self ):
0 commit comments