Skip to content

Commit 91f556a

Browse files
andrewleechclaude
andcommitted
usb-device-mtp: Fix uctypes struct definitions
- Update uctypes struct field definitions to use bitwise OR syntax - Change from (offset, type) tuples to offset | type notation - Use correct syntax for array fields: (offset | ARRAY, length | type) - Fix dynamically created object handles descriptor in get_object_handles 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 5ca3913 commit 91f556a

File tree

1 file changed

+19
-19
lines changed
  • micropython/usb/usb-device-mtp/usb/device

1 file changed

+19
-19
lines changed

micropython/usb/usb-device-mtp/usb/device/mtp.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -124,41 +124,41 @@
124124
# MTP struct definitions using uctypes
125125
# Container header struct
126126
_MTP_CONTAINER_HEADER_DESC = {
127-
"length": (0, uctypes.UINT32),
128-
"type": (4, uctypes.UINT16),
129-
"code": (6, uctypes.UINT16),
130-
"transaction_id": (8, uctypes.UINT32)
127+
"length": 0 | uctypes.UINT32,
128+
"type": 4 | uctypes.UINT16,
129+
"code": 6 | uctypes.UINT16,
130+
"transaction_id": 8 | uctypes.UINT32
131131
}
132132

133133
# Device Info struct
134134
_MTP_DEVICE_INFO_DESC = {
135-
"standard_version": (0, uctypes.UINT16),
136-
"vendor_extension_id": (2, uctypes.UINT32),
137-
"mtp_version": (6, uctypes.UINT16),
135+
"standard_version": 0 | uctypes.UINT16,
136+
"vendor_extension_id": 2 | uctypes.UINT32,
137+
"mtp_version": 6 | uctypes.UINT16,
138138
# Variable length data follows: extension string, operations, events, etc.
139139
}
140140

141141
# Storage IDs struct
142142
_MTP_STORAGE_IDS_DESC = {
143-
"count": (0, uctypes.UINT32),
144-
"storage_ids": (4, uctypes.ARRAY, 1, uctypes.UINT32) # Variable length array
143+
"count": 0 | uctypes.UINT32,
144+
"storage_ids": (4 | uctypes.ARRAY, 1 | uctypes.UINT32) # Variable length array
145145
}
146146

147147
# Storage Info struct
148148
_MTP_STORAGE_INFO_DESC = {
149-
"storage_type": (0, uctypes.UINT16),
150-
"filesystem_type": (2, uctypes.UINT16),
151-
"access_capability": (4, uctypes.UINT16),
152-
"max_capacity": (6, uctypes.UINT64),
153-
"free_space": (14, uctypes.UINT64),
154-
"free_space_objects": (22, uctypes.UINT32)
149+
"storage_type": 0 | uctypes.UINT16,
150+
"filesystem_type": 2 | uctypes.UINT16,
151+
"access_capability": 4 | uctypes.UINT16,
152+
"max_capacity": 6 | uctypes.UINT64,
153+
"free_space": 14 | uctypes.UINT64,
154+
"free_space_objects": 22 | uctypes.UINT32
155155
# Variable length data follows: storage_description, volume_identifier
156156
}
157157

158158
# Object Handles struct
159159
_MTP_OBJECT_HANDLES_DESC = {
160-
"count": (0, uctypes.UINT32),
161-
"handles": (4, uctypes.ARRAY, 1, uctypes.UINT32) # Variable length array
160+
"count": 0 | uctypes.UINT32,
161+
"handles": (4 | uctypes.ARRAY, 1 | uctypes.UINT32) # Variable length array
162162
}
163163

164164

@@ -783,8 +783,8 @@ def _cmd_get_object_handles(self, params):
783783
# For the _MTP_OBJECT_HANDLES_DESC, we need to dynamically adjust the array size
784784
# Create a custom descriptor with the actual array size
785785
obj_handles_desc = {
786-
"count": (0, uctypes.UINT32),
787-
"handles": (4, uctypes.ARRAY, len(handles), uctypes.UINT32)
786+
"count": 0 | uctypes.UINT32,
787+
"handles": (4 | uctypes.ARRAY, len(handles) | uctypes.UINT32)
788788
}
789789

790790
# Create the struct

0 commit comments

Comments
 (0)