1 """UART Class for Binho Nova"""
3 from adafruit_blinka.microcontroller.nova import Connection
7 """Custom UART Class for Binho Nova"""
9 ESCAPE_SEQUENCE = "+++UART0"
11 # pylint: disable=too-many-arguments,unused-argument
23 self._nova = Connection.getInstance()
26 self._baudrate = baudrate
30 self._timeout = timeout
32 if flow is not None: # default 0
33 raise NotImplementedError(
34 "Parameter '{}' unsupported on Binho Nova".format("flow")
37 self._nova.setOperationMode(self._id, "UART")
38 self._nova.setBaudRateUART(self._id, baudrate)
39 self._nova.setDataBitsUART(self._id, bits)
40 self._nova.setParityUART(self._id, parity)
41 self._nova.setStopBitsUART(self._id, stop)
42 self._nova.setEscapeSequenceUART(self._id, UART.ESCAPE_SEQUENCE)
43 self._nova.beginBridgeUART(self._id)
45 # pylint: enable=too-many-arguments,unused-argument
49 self._nova.writeBridgeUART(UART.ESCAPE_SEQUENCE)
50 self._nova.stopBridgeUART(UART.ESCAPE_SEQUENCE)
52 def read(self, nbytes=None):
53 """Read data from UART and return it"""
57 for _ in range(nbytes):
58 data.append(ord(self._nova.readBridgeUART()))
61 def readinto(self, buf, nbytes=None):
62 """Read data from UART and into the buffer"""
65 for _ in range(nbytes):
66 buf.append(ord(self._nova.readBridgeUART()))
70 """Read a single line of data from UART"""
71 out = self._nova.readBridgeUART()
74 out = self._nova.readBridgeUART()
79 """Write data from the buffer to UART"""
80 return self._nova.writeBridgeUART(buf)