Skip to content

Commit 51bd500

Browse files
Add in_waiting property to busio.UART
Add the in_waiting property to match CircuitPython's busio.UART API. Returns the number of bytes available in the input buffer. - RP2040 UART: wraps MicroPython's uart.any() - busio.UART wrapper: checks for in_waiting first, falls back to any(), raises NotImplementedError if neither is available Fixes #1046
1 parent 23d84ee commit 51bd500

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/adafruit_blinka/microcontroller/rp2040/uart.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,8 @@ def readline(self):
5050
def write(self, buf):
5151
"""Write to the UART from a buffer"""
5252
return self._uart.write(buf)
53+
54+
@property
55+
def in_waiting(self):
56+
"""The number of bytes in the input buffer, available to be read"""
57+
return self._uart.any()

src/busio.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,3 +628,14 @@ def readline(self):
628628
def write(self, buf):
629629
"""Write to the UART from a buffer"""
630630
return self._uart.write(buf)
631+
632+
@property
633+
def in_waiting(self):
634+
"""The number of bytes in the input buffer, available to be read"""
635+
# Custom UART implementations (e.g. RP2040) that provide in_waiting directly
636+
if hasattr(self._uart, "in_waiting"):
637+
return self._uart.in_waiting
638+
# MicroPython's machine.UART uses any() for the same purpose
639+
if hasattr(self._uart, "any"):
640+
return self._uart.any()
641+
raise NotImplementedError("in_waiting not supported on this platform")

0 commit comments

Comments
 (0)