Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f5b8489
usbd: Add USB device drivers implemented in Python.
projectgus Oct 26, 2022
e2a3e45
usbd: Add midi interface definition from @paulhamsh.
projectgus Feb 9, 2023
c8ad6ca
usbd: Major cleanup, refactor.
projectgus Feb 14, 2023
65762f6
Add basic keypad support
turmoni Jun 3, 2023
944e107
Fix report count, remove irrelevant comments
turmoni Jun 3, 2023
5b5871c
Add basic, read-only MSC support, and add LED status to keypad.
turmoni Jun 28, 2023
e8bd164
Actually add the changes methoned in the previous commit message, and…
turmoni Jun 28, 2023
eb47fa0
usbd: Bugfixes around data transfer, support using an AbstractBlockDe…
turmoni Jun 30, 2023
24f7422
usbd: Add USB device drivers implemented in Python.
projectgus Oct 26, 2022
581a662
usbd: Add midi interface definition from @paulhamsh.
projectgus Feb 9, 2023
7472ef5
Merge remote-tracking branch 'upstream/feature/usbd_python' into feat…
turmoni Jul 10, 2023
e24951a
usbd: Add copyright notices (+delete file that has gone from upstream…
turmoni Jul 10, 2023
e85b368
usbd: Run "black" with the right options for the style checker to be …
turmoni Jul 10, 2023
82f1e47
usbd: Use EP_IN_FLAG from utils for mass storage
turmoni Jul 10, 2023
5c51a9e
usbd: Re-run black to fix the missing comma
turmoni Jul 10, 2023
9d4d843
usbd: Add support for configuration open and reset callbacks.
projectgus Jul 25, 2023
29e9185
usbd: Add USB interface functions for endpoint STALL support.
projectgus Jul 25, 2023
9d7ce9f
usbd: Implement SET_REPORT support for OUT direction HID data.
projectgus Jul 26, 2023
92711ea
usbd: Rename ustruct->struct.
projectgus Jul 26, 2023
3765d04
usbd: Add hid keypad example from @turmoni .
projectgus Jul 26, 2023
756d761
usbd: Update hid_keypad example module.
projectgus Jul 26, 2023
bb389e3
usbd: Implement ruff, black linter & formatting fixes.
projectgus Jul 26, 2023
2baaf58
usbd: Add missing manifest file.
projectgus Jul 26, 2023
83364c0
Merge remote-tracking branch 'upstream/feature/usbd_python' into feat…
turmoni Aug 3, 2023
cd4f51c
usbd: Theoretically handle resets and bad CBWs better in msc
turmoni Sep 2, 2023
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