1 """UART Class for RP2040"""
 
   2 from machine import UART as _UART
 
   3 from machine import Pin
 
   4 from microcontroller.pin import uartPorts
 
   6 # pylint: disable=protected-access, no-self-use
 
   8     """Custom UART Class for RP2040"""
 
  10     # pylint: disable=too-many-arguments
 
  11     def __init__(self, tx, rx, baudrate=9600, bits=8, parity=None, stop=1):
 
  12         # check tx and rx have hardware support
 
  13         for portId, txPin, rxPin in uartPorts:
 
  14             if txPin == tx and rxPin == rx:
 
  27                 "No Hardware UART on (tx,rx)={}\nValid UART ports: {}".format(
 
  28                     (tx.id, rx.id), uartPorts
 
  32     # pylint: enable=too-many-arguments
 
  34     def read(self, nbytes=None):
 
  35         """Read from the UART"""
 
  36         return self._uart.read(nbytes)
 
  38     def readinto(self, buf, nbytes=None):
 
  39         """Read from the UART into a buffer"""
 
  40         return self._uart.readinto(buf, nbytes)
 
  43         """Read a line of characters up to a newline charater from the UART"""
 
  44         return self._uart.readline()
 
  47         """Write to the UART from a buffer"""
 
  48         return self._uart.write(buf)