Skip to content

Commit 20e349d

Browse files
committed
usbd: Rename ustruct->struct.
1 parent f24d615 commit 20e349d

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

micropython/usbd/device.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# MIT license; Copyright (c) 2022 Angus Gratton
33
from micropython import const
44
import machine
5-
import ustruct
5+
import struct
66

77
from .utils import split_bmRequestType, EP_IN_FLAG
88

@@ -119,7 +119,7 @@ def _descriptor_device_cb(self):
119119

120120
FMT = "<BBHBBBBHHHBBBB"
121121
# static descriptor fields
122-
f = ustruct.unpack(FMT, self._usbd.static.desc_device)
122+
f = struct.unpack(FMT, self._usbd.static.desc_device)
123123

124124
def maybe_set(value, idx):
125125
# Override a numeric descriptor value or keep static value f[idx] if 'value' is None
@@ -135,7 +135,7 @@ def maybe_set_str(s, idx):
135135

136136
# Either copy each descriptor field directly from the static device descriptor, or 'maybe'
137137
# override if a custom value has been set on this object
138-
return ustruct.pack(
138+
return struct.pack(
139139
FMT,
140140
f[0], # bLength
141141
f[1], # bDescriptorType
@@ -258,7 +258,7 @@ def _update_configuration_descriptor(self, desc):
258258
bNumInterfaces = self._usbd.static.itf_max if self.include_static else 0
259259
bNumInterfaces += len(self._itfs)
260260

261-
ustruct.pack_into(
261+
struct.pack_into(
262262
"<BBHBBBBB",
263263
desc,
264264
0,
@@ -451,7 +451,7 @@ def get_itf_descriptor(self, num_eps, itf_idx, str_idx):
451451
# (indexes in the descriptor data should start from 'str_idx'.)
452452
#
453453
# See USB 2.0 specification section 9.6.5 p267 for standard interface descriptors.
454-
desc = ustruct.pack(
454+
desc = struct.pack(
455455
"<" + "B" * _STD_DESC_INTERFACE_LEN,
456456
_STD_DESC_INTERFACE_LEN, # bLength
457457
_STD_DESC_INTERFACE_TYPE, # bDescriptorType

micropython/usbd/hid.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
REQ_TYPE_CLASS,
1414
)
1515
from micropython import const
16-
import ustruct
16+
import struct
1717

1818
_DESC_HID_TYPE = const(0x21)
1919
_DESC_REPORT_TYPE = const(0x22)
@@ -111,7 +111,7 @@ def get_hid_descriptor(self):
111111
# and optional additional descriptors.
112112
#
113113
# See HID Specification Version 1.1, Section 6.2.1 HID Descriptor p22
114-
result = ustruct.pack(
114+
result = struct.pack(
115115
"<BBHBBBH",
116116
9 + 3 * len(self.extra_descriptors), # bLength
117117
_DESC_HID_TYPE, # bDescriptorType
@@ -127,7 +127,7 @@ def get_hid_descriptor(self):
127127
# support in base class
128128
if self.extra_descriptors:
129129
result += b"".join(
130-
ustruct.pack("<BH", dt, len(dd)) for (dt, dd) in self.extra_descriptors
130+
struct.pack("<BH", dt, len(dd)) for (dt, dd) in self.extra_descriptors
131131
)
132132

133133
return result
@@ -280,7 +280,7 @@ def send_report(self, dx=0, dy=0):
280280
# transfer after it's submitted. So reusing a bytearray() creates a risk
281281
# of a race condition if a new report transfer is submitted using the
282282
# same buffer, before the previous one has completed.
283-
report = ustruct.pack("Bbb", b, dx, dy)
283+
report = struct.pack("Bbb", b, dx, dy)
284284

285285
super().send_report(report)
286286

micropython/usbd/midi.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# MicroPython USB MIDI module
22
# MIT license; Copyright (c) 2023 Angus Gratton, Paul Hamshere
33
from micropython import const
4-
import ustruct
4+
import struct
55

66
from .device import USBInterface
77
from .utils import endpoint_descriptor, EP_IN_FLAG
@@ -57,7 +57,7 @@ def get_itf_descriptor(self, num_eps, itf_idx, str_idx):
5757
desc, strs = super().get_itf_descriptor(num_eps, itf_idx, str_idx)
5858

5959
# Append the class-specific AudioControl interface descriptor
60-
desc += ustruct.pack(
60+
desc += struct.pack(
6161
"<BBBHHBB",
6262
9, # bLength
6363
0x24, # bDescriptorType CS_INTERFACE
@@ -124,7 +124,7 @@ def get_itf_descriptor(self, num_eps, itf_idx, str_idx):
124124
_JACK_OUT_DESC_LEN = const(9)
125125

126126
# Midi Streaming interface descriptor
127-
cs_ms_interface = ustruct.pack(
127+
cs_ms_interface = struct.pack(
128128
"<BBBHH",
129129
7, # bLength
130130
0x24, # bDescriptorType CS_INTERFACE
@@ -135,7 +135,7 @@ def get_itf_descriptor(self, num_eps, itf_idx, str_idx):
135135
)
136136

137137
def jack_in_desc(bJackType, bJackID):
138-
return ustruct.pack(
138+
return struct.pack(
139139
"<BBBBBB",
140140
_JACK_IN_DESC_LEN, # bLength
141141
0x24, # bDescriptorType CS_INTERFACE
@@ -146,7 +146,7 @@ def jack_in_desc(bJackType, bJackID):
146146
)
147147

148148
def jack_out_desc(bJackType, bJackID, bSourceId, bSourcePin):
149-
return ustruct.pack(
149+
return struct.pack(
150150
"<BBBBBBBBB",
151151
_JACK_OUT_DESC_LEN, # bLength
152152
0x24, # bDescriptorType CS_INTERFACE
@@ -250,7 +250,7 @@ def get_endpoint_descriptors(self, ep_addr, str_idx):
250250

251251
# rx side, USB "in" endpoint and embedded MIDI IN Jacks
252252
e_out = endpoint_descriptor(self.ep_in, "bulk", 64, 0)
253-
cs_out = ustruct.pack(
253+
cs_out = struct.pack(
254254
"<BBBB" + "B" * self._num_rx,
255255
4 + self._num_rx, # bLength
256256
0x25, # bDescriptorType CS_ENDPOINT
@@ -261,7 +261,7 @@ def get_endpoint_descriptors(self, ep_addr, str_idx):
261261

262262
# tx side, USB "out" endpoint and embedded MIDI OUT jacks
263263
e_in = endpoint_descriptor(self.ep_out, "bulk", 64, 0)
264-
cs_in = ustruct.pack(
264+
cs_in = struct.pack(
265265
"<BBBB" + "B" * self._num_tx,
266266
4 + self._num_tx, # bLength
267267
0x25, # bDescriptorType CS_ENDPOINT
@@ -282,11 +282,11 @@ def __init__(self):
282282
super().__init__()
283283

284284
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)
286286
super().send_data(obuf)
287287

288288
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)
290290
super().send_data(obuf)
291291

292292
def start(self):

0 commit comments

Comments
 (0)