I am trying to port a function from python into upython. The function uses the spidev library in python which does not exist in upython.
here is the python function:
Code: Select all
def _spi_write(self, register, payload):
if type(payload) == int:
payload = [payload]
elif type(payload) == bytes:
payload = [p for p in payload]
elif type(payload) == str:
payload = [ord(s) for s in payload]
self.spi.xfer([register | 0x80] + payload)
xfer is described as
"Performs an SPI transaction. Chip-select should be released and reactivated between blocks. Delay specifies the delay in usec between blocks."
It is sending a list of two bytes in the function. In upython there is an spi.write method which sends a single byte. so can i simply loop over the list and use spi.write?
Thanks in advance,
Martyn