def transfer(tx_data):
"""Transfers data using the current SPI bus. Returns a list of bytes.
tx_data: A list of bytes to send.
Note: An exception is thrown if an error occurs during the transfer.
"""
length = len(tx_data)
tx_buffer = (ctypes.c_uint8 * length)(*tx_data)
rx_buffer = (ctypes.c_uint8 * length)()
ret = _LIB.spi_transfer(tx_buffer, rx_buffer, length)
if ret < 0:
raise Exception("spi transfer failed")
return [rx_buffer[i] for i in range(length)]
评论列表
文章目录