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
47 """Close Nova on delete"""
53 self._nova.writeBridgeUART(UART.ESCAPE_SEQUENCE)
54 self._nova.stopBridgeUART(UART.ESCAPE_SEQUENCE)
56 def read(self, nbytes=None):
57 """Read data from UART and return it"""
61 for _ in range(nbytes):
62 data.append(ord(self._nova.readBridgeUART()))
65 def readinto(self, buf, nbytes=None):
66 """Read data from UART and into the buffer"""
69 for _ in range(nbytes):
70 buf.append(ord(self._nova.readBridgeUART()))
74 """Read a single line of data from UART"""
75 out = self._nova.readBridgeUART()
78 out = self._nova.readBridgeUART()
83 """Write data from the buffer to UART"""
84 return self._nova.writeBridgeUART(buf)