Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
usbd: Rename ustruct->struct.
  • Loading branch information
projectgus committed Jul 26, 2023
commit 92711eae134b37804c668e6fdf879ae53718a0a6
10 changes: 5 additions & 5 deletions micropython/usbd/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# MIT license; Copyright (c) 2022 Angus Gratton
from micropython import const
import machine
import ustruct
import struct

from .utils import split_bmRequestType, EP_IN_FLAG

Expand Down Expand Up @@ -119,7 +119,7 @@ def _descriptor_device_cb(self):

FMT = "<BBHBBBBHHHBBBB"
# static descriptor fields
f = ustruct.unpack(FMT, self._usbd.static.desc_device)
f = struct.unpack(FMT, self._usbd.static.desc_device)

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

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

ustruct.pack_into(
struct.pack_into(
"<BBHBBBBB",
desc,
0,
Expand Down Expand Up @@ -451,7 +451,7 @@ def get_itf_descriptor(self, num_eps, itf_idx, str_idx):
# (indexes in the descriptor data should start from 'str_idx'.)
#
# See USB 2.0 specification section 9.6.5 p267 for standard interface descriptors.
desc = ustruct.pack(
desc = struct.pack(
"<" + "B" * _STD_DESC_INTERFACE_LEN,
_STD_DESC_INTERFACE_LEN, # bLength
_STD_DESC_INTERFACE_TYPE, # bDescriptorType
Expand Down
8 changes: 4 additions & 4 deletions micropython/usbd/hid.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
REQ_TYPE_CLASS,
)
from micropython import const
import ustruct
import struct

_DESC_HID_TYPE = const(0x21)
_DESC_REPORT_TYPE = const(0x22)
Expand Down Expand Up @@ -111,7 +111,7 @@ def get_hid_descriptor(self):
# and optional additional descriptors.
#
# See HID Specification Version 1.1, Section 6.2.1 HID Descriptor p22
result = ustruct.pack(
result = struct.pack(
"<BBHBBBH",
9 + 3 * len(self.extra_descriptors), # bLength
_DESC_HID_TYPE, # bDescriptorType
Expand All @@ -127,7 +127,7 @@ def get_hid_descriptor(self):
# support in base class
if self.extra_descriptors:
result += b"".join(
ustruct.pack("<BH", dt, len(dd)) for (dt, dd) in self.extra_descriptors
struct.pack("<BH", dt, len(dd)) for (dt, dd) in self.extra_descriptors
)

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

super().send_report(report)

Expand Down
18 changes: 9 additions & 9 deletions micropython/usbd/midi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# MicroPython USB MIDI module
# MIT license; Copyright (c) 2023 Angus Gratton, Paul Hamshere
from micropython import const
import ustruct
import struct

from .device import USBInterface
from .utils import endpoint_descriptor, EP_IN_FLAG
Expand Down Expand Up @@ -57,7 +57,7 @@ def get_itf_descriptor(self, num_eps, itf_idx, str_idx):
desc, strs = super().get_itf_descriptor(num_eps, itf_idx, str_idx)

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

# Midi Streaming interface descriptor
cs_ms_interface = ustruct.pack(
cs_ms_interface = struct.pack(
"<BBBHH",
7, # bLength
0x24, # bDescriptorType CS_INTERFACE
Expand All @@ -135,7 +135,7 @@ def get_itf_descriptor(self, num_eps, itf_idx, str_idx):
)

def jack_in_desc(bJackType, bJackID):
return ustruct.pack(
return struct.pack(
"<BBBBBB",
_JACK_IN_DESC_LEN, # bLength
0x24, # bDescriptorType CS_INTERFACE
Expand All @@ -146,7 +146,7 @@ def jack_in_desc(bJackType, bJackID):
)

def jack_out_desc(bJackType, bJackID, bSourceId, bSourcePin):
return ustruct.pack(
return struct.pack(
"<BBBBBBBBB",
_JACK_OUT_DESC_LEN, # bLength
0x24, # bDescriptorType CS_INTERFACE
Expand Down Expand Up @@ -250,7 +250,7 @@ def get_endpoint_descriptors(self, ep_addr, str_idx):

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

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

def note_on(self, channel, pitch, vel):
obuf = ustruct.pack("<BBBB", 0x09, 0x90 | channel, pitch, vel)
obuf = struct.pack("<BBBB", 0x09, 0x90 | channel, pitch, vel)
super().send_data(obuf)

def note_off(self, channel, pitch, vel):
obuf = ustruct.pack("<BBBB", 0x08, 0x80 | channel, pitch, vel)
obuf = struct.pack("<BBBB", 0x08, 0x80 | channel, pitch, vel)
super().send_data(obuf)

def start(self):
Expand Down