kopia lustrzana https://github.com/micropython/micropython-lib
usb-device-cdc: Fix short delays when timeout is 0.
Previously even with timeout set to zero, a read could block for up to 1ms + machine.idle() timeout period. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
rodzic
163f8ea953
commit
a215fc47bb
|
@ -367,9 +367,11 @@ class CDCInterface(io.IOBase, Interface):
|
|||
mv = mv[nbytes:]
|
||||
|
||||
# check for timeout
|
||||
if time.ticks_diff(time.ticks_ms(), start) > self._timeout:
|
||||
if time.ticks_diff(time.ticks_ms(), start) >= self._timeout:
|
||||
return len(buf) - len(mv)
|
||||
|
||||
machine.idle()
|
||||
|
||||
def read(self, size):
|
||||
start = time.ticks_ms()
|
||||
|
||||
|
@ -404,7 +406,7 @@ class CDCInterface(io.IOBase, Interface):
|
|||
if n == len(b):
|
||||
break # Done, exit before we reach the sleep
|
||||
|
||||
if time.ticks_diff(time.ticks_ms(), start) > self._timeout:
|
||||
if time.ticks_diff(time.ticks_ms(), start) >= self._timeout:
|
||||
break # Timed out
|
||||
|
||||
machine.idle()
|
||||
|
|
Ładowanie…
Reference in New Issue