Skip to content

Commit e85b368

Browse files
committed
usbd: Run "black" with the right options for the style checker to be happy
1 parent e24951a commit e85b368

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

micropython/usbd/keycodes.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
# Keypad keycodes for use with USB HID
22
# MIT license; Copyright (c) 2023 Dave Wickham
33
_KEYPAD_KEYS = [
4-
"<NumLock>", "/", "*", "-", "+", "<Enter>", "1", "2", "3", "4", "5", "6",
5-
"7", "8", "9", "0", "."
4+
"<NumLock>",
5+
"/",
6+
"*",
7+
"-",
8+
"+",
9+
"<Enter>",
10+
"1",
11+
"2",
12+
"3",
13+
"4",
14+
"5",
15+
"6",
16+
"7",
17+
"8",
18+
"9",
19+
"0",
20+
".",
621
]
722

823
KEYPAD_KEYCODES_TO_KEYS = {k + 0x53: v for k, v in enumerate(_KEYPAD_KEYS)}

micropython/usbd/msc.py

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ class CSW:
9494
STATUS_FAILED = const(1)
9595
STATUS_PHASE_ERROR = const(2)
9696

97-
def __init__(
98-
self, dCSWSignature=0x53425355, dCSWTag=None, dCSWDataResidue=0, bCSWStatus=0
99-
):
97+
def __init__(self, dCSWSignature=0x53425355, dCSWTag=None, dCSWDataResidue=0, bCSWStatus=0):
10098
self.dCSWSignature = dCSWSignature
10199
self.dCSWTag = dCSWTag
102100
self.dCSWDataResidue = dCSWDataResidue
@@ -199,9 +197,7 @@ def try_to_prepare_cbw(self, args=None):
199197
try:
200198
self.prepare_cbw()
201199
except KeyError:
202-
self.timer.init(
203-
mode=Timer.ONE_SHOT, period=2000, callback=self.try_to_prepare_cbw
204-
)
200+
self.timer.init(mode=Timer.ONE_SHOT, period=2000, callback=self.try_to_prepare_cbw)
205201

206202
def handle_interface_control_xfer(self, stage, request):
207203
"""Handle the interface control transfers; reset and get max lun"""
@@ -286,9 +282,7 @@ def prepare_cbw(self, args=None):
286282
def receive_cbw_callback(self, ep_addr, result, xferred_bytes):
287283
"""Callback stub to schedule actual CBW processing"""
288284
self.log("receive_cbw_callback")
289-
micropython.schedule(
290-
self.proc_receive_cbw_callback, (ep_addr, result, xferred_bytes)
291-
)
285+
micropython.schedule(self.proc_receive_cbw_callback, (ep_addr, result, xferred_bytes))
292286

293287
def proc_receive_cbw_callback(self, args):
294288
"""Invoke CBW processing"""
@@ -378,9 +372,7 @@ def proc_transfer_data(self, args):
378372
return micropython.schedule(self.send_csw, None)
379373

380374
# This is the last data we're sending, pad it out
381-
residue = self.cbw.dCBWDataTransferLength - (
382-
self.transferred_length + len(self.data)
383-
)
375+
residue = self.cbw.dCBWDataTransferLength - (self.transferred_length + len(self.data))
384376
if residue:
385377
self.log(f"Adding {residue} bytes of padding for residue")
386378
self.csw.dCSWDataResidue = residue
@@ -418,9 +410,7 @@ def validate_cbw(self) -> bool:
418410
# Check if this is a valid SCSI command
419411
try:
420412
# The storage layer doesn't know about USB, it'll return True for valid and False for invalid
421-
return not self.storage_device.validate_cmd(
422-
self.cbw.CBWCB[0 : self.cbw.bCBWCBLength]
423-
)
413+
return not self.storage_device.validate_cmd(self.cbw.CBWCB[0 : self.cbw.bCBWCBLength])
424414
except Exception as exc:
425415
self.log(str(exc))
426416
raise
@@ -442,13 +432,9 @@ def send_csw(self, args):
442432

443433
# If the host sent a command that was expecting more than just a CSW, we may have to send them some nothing in the absence of being able to STALL
444434
if self.transferred_length == 0 and self.csw.dCSWDataResidue != 0:
445-
self.log(
446-
f"Sending {self.csw.dCSWDataResidue} bytes of nothing to pad it out"
447-
)
435+
self.log(f"Sending {self.csw.dCSWDataResidue} bytes of nothing to pad it out")
448436
self.transferred_length = self.csw.dCSWDataResidue
449-
self.submit_xfer(
450-
self.ep_in, bytearray(self.csw.dCSWDataResidue), self.padding_sent
451-
)
437+
self.submit_xfer(self.ep_in, bytearray(self.csw.dCSWDataResidue), self.padding_sent)
452438
# The flow from sending the CSW happens in the callback, not in whatever called us, so we can just return and re-call from the padding callback
453439
return
454440

@@ -649,9 +635,7 @@ def handle_read10(self, cmd=None):
649635
length = self.long_operation["remaining_length"]
650636
lba = self.long_operation["current_lba"]
651637
else:
652-
(read10, flags, lba, group, length, control) = ustruct.unpack(
653-
">BBLBHB", cmd
654-
)
638+
(read10, flags, lba, group, length, control) = ustruct.unpack(">BBLBHB", cmd)
655639

656640
# Do we have an AbstractBlockDev?
657641
if getattr(self.filesystem, "readblocks", False):
@@ -719,6 +703,4 @@ def handle_inquiry(self, cmd):
719703
)
720704

721705
self.sense = type(self).INVALID_COMMAND
722-
raise StorageDevice.StorageError(
723-
"EVPD not implemented", status=CSW.STATUS_FAILED
724-
)
706+
raise StorageDevice.StorageError("EVPD not implemented", status=CSW.STATUS_FAILED)

0 commit comments

Comments
 (0)