1 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
3 # SPDX-License-Identifier: MIT
4 """UART Class for Binho Nova"""
6 from adafruit_blinka.microcontroller.nova import Connection
10 """Custom UART Class for Binho Nova"""
12 ESCAPE_SEQUENCE = "+++UART0"
14 # pylint: disable=too-many-arguments,unused-argument
26 self._nova = Connection.getInstance()
29 self._baudrate = baudrate
33 self._timeout = timeout
35 if flow is not None: # default 0
36 raise NotImplementedError(
37 "Parameter '{}' unsupported on Binho Nova".format("flow")
40 self._nova.setOperationMode(self._id, "UART")
41 self._nova.setBaudRateUART(self._id, baudrate)
42 self._nova.setDataBitsUART(self._id, bits)
43 self._nova.setParityUART(self._id, parity)
44 self._nova.setStopBitsUART(self._id, stop)
45 self._nova.setEscapeSequenceUART(self._id, UART.ESCAPE_SEQUENCE)
46 self._nova.beginBridgeUART(self._id)
48 # pylint: enable=too-many-arguments,unused-argument
50 """Close Nova on delete"""
56 self._nova.writeBridgeUART(UART.ESCAPE_SEQUENCE)
57 self._nova.stopBridgeUART(UART.ESCAPE_SEQUENCE)
59 def read(self, nbytes=None):
60 """Read data from UART and return it"""
64 for _ in range(nbytes):
65 data.append(ord(self._nova.readBridgeUART()))
68 def readinto(self, buf, nbytes=None):
69 """Read data from UART and into the buffer"""
72 for _ in range(nbytes):
73 buf.append(ord(self._nova.readBridgeUART()))
77 """Read a single line of data from UART"""
78 out = self._nova.readBridgeUART()
81 out = self._nova.readBridgeUART()
86 """Write data from the buffer to UART"""
87 return self._nova.writeBridgeUART(buf)