Esempio n. 1
0
    def transaction(self, dataToSend: Union[bytes, Sequence[int]]) -> bytes:
        """Perform a simultaneous read/write transaction with the device

        :param dataToSend: The data to be written out to the device

        :returns: data received from the device

        Usage::

            # send byte string
            data = spi.transaction(b'stuff')

            # send list of integers
            data = spi.transaction([0x01, 0x02])
        """
        return hal.transactionSPI(self.port, dataToSend)
Esempio n. 2
0
    def transaction(self, dataToSend: Union[bytes, Sequence[int]]) -> bytes:
        """Perform a simultaneous read/write transaction with the device

        :param dataToSend: The data to be written out to the device

        :returns: data received from the device

        Usage::

            # send byte string
            data = spi.transaction(b'stuff')

            # send list of integers
            data = spi.transaction([0x01, 0x02])
        """
        return hal.transactionSPI(self.port, dataToSend)
Esempio n. 3
0
    def read(self, initiate: bool, size: int) -> bytes:
        """Read a word from the receive FIFO.

        Waits for the current transfer to complete if the receive FIFO is
        empty.

        If the receive FIFO is empty, there is no active transfer, and
        initiate is False, errors.

        :param initiate: If True, this function pushes "0" into the
            transmit buffer and initiates a transfer.  If False, this function
            assumes that data is already in the receive FIFO from a previous
            write.
        :param size: Number of bytes to read.

        :returns: received data bytes
        """
        if initiate:
            return hal.transactionSPI(self.port, [0] * size)
        else:
            return hal.readSPI(self.port, size)
Esempio n. 4
0
    def read(self, initiate: bool, size: int) -> bytes:
        """Read a word from the receive FIFO.

        Waits for the current transfer to complete if the receive FIFO is
        empty.

        If the receive FIFO is empty, there is no active transfer, and
        initiate is False, errors.

        :param initiate: If True, this function pushes "0" into the
            transmit buffer and initiates a transfer.  If False, this function
            assumes that data is already in the receive FIFO from a previous
            write.
        :param size: Number of bytes to read.

        :returns: received data bytes
        """
        if initiate:
            return hal.transactionSPI(self.port, [0] * size)
        else:
            return hal.readSPI(self.port, size)