libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
daisy::MultiSlaveSpiHandle Class Reference

Detailed Description

Handler for a serial peripheral interface that connects to multiple devices on one bus such that up to 4 devices can share the same MOSI, MISO and SCLK pins. Each device has its own NSS/CS pin which is software driven by the MultiSlaveSpiHandle.

#include <spiMultislave.h>

Classes

struct  Config
 

Public Member Functions

 MultiSlaveSpiHandle ()
 
 MultiSlaveSpiHandle (const MultiSlaveSpiHandle &other)=delete
 
SpiHandle::Result Init (const Config &config)
 
const ConfigGetConfig () const
 
SpiHandle::Result BlockingTransmit (size_t device_index, uint8_t *buff, size_t size, uint32_t timeout=100)
 
SpiHandle::Result BlockingReceive (size_t device_index, uint8_t *buff, uint16_t size, uint32_t timeout=100)
 
SpiHandle::Result BlockingTransmitAndReceive (size_t device_index, uint8_t *tx_buff, uint8_t *rx_buff, size_t size, uint32_t timeout=100)
 
SpiHandle::Result DmaTransmit (size_t device_index, uint8_t *buff, size_t size, SpiHandle::StartCallbackFunctionPtr start_callback, SpiHandle::EndCallbackFunctionPtr end_callback, void *callback_context)
 
SpiHandle::Result DmaReceive (size_t device_index, uint8_t *buff, size_t size, SpiHandle::StartCallbackFunctionPtr start_callback, SpiHandle::EndCallbackFunctionPtr end_callback, void *callback_context)
 
SpiHandle::Result DmaTransmitAndReceive (size_t device_index, uint8_t *tx_buff, uint8_t *rx_buff, size_t size, SpiHandle::StartCallbackFunctionPtr start_callback, SpiHandle::EndCallbackFunctionPtr end_callback, void *callback_context)
 
int CheckError ()
 

Static Public Attributes

static constexpr size_t max_num_devices_ = 4
 

Constructor & Destructor Documentation

◆ MultiSlaveSpiHandle() [1/2]

daisy::MultiSlaveSpiHandle::MultiSlaveSpiHandle ( )
inline

◆ MultiSlaveSpiHandle() [2/2]

daisy::MultiSlaveSpiHandle::MultiSlaveSpiHandle ( const MultiSlaveSpiHandle other)
delete

Member Function Documentation

◆ BlockingReceive()

SpiHandle::Result daisy::MultiSlaveSpiHandle::BlockingReceive ( size_t  device_index,
uint8_t buff,
uint16_t  size,
uint32_t  timeout = 100 
)

Polling Receive

Parameters
device_indexthe index of the device
buffinput buffer
sizebuffer size
timeouttimeout time in ms
Returns
Whether the receive was successful or not

◆ BlockingTransmit()

SpiHandle::Result daisy::MultiSlaveSpiHandle::BlockingTransmit ( size_t  device_index,
uint8_t buff,
size_t  size,
uint32_t  timeout = 100 
)

Blocking transmit

Parameters
device_indexthe index of the device
buffinput buffer
sizebuffer size
timeouttimeout time in ms

◆ BlockingTransmitAndReceive()

SpiHandle::Result daisy::MultiSlaveSpiHandle::BlockingTransmitAndReceive ( size_t  device_index,
uint8_t tx_buff,
uint8_t rx_buff,
size_t  size,
uint32_t  timeout = 100 
)

Blocking transmit and receive

Parameters
device_indexthe index of the device
tx_buffthe transmit buffer
rx_buffthe receive buffer
sizethe length of the transaction
timeouttimeout time in ms

◆ CheckError()

int daisy::MultiSlaveSpiHandle::CheckError ( )
Returns
the result of HAL_SPI_GetError() to the user.

◆ DmaReceive()

SpiHandle::Result daisy::MultiSlaveSpiHandle::DmaReceive ( size_t  device_index,
uint8_t buff,
size_t  size,
SpiHandle::StartCallbackFunctionPtr  start_callback,
SpiHandle::EndCallbackFunctionPtr  end_callback,
void callback_context 
)

DMA-based receive

Parameters
device_indexthe index of the device
buffreceive buffer
sizebuffer size
start_callbackA callback to execute when the transfer starts, or NULL.
end_callbackA callback to execute when the transfer finishes, or NULL.
callback_contextA pointer that will be passed back to you in the callbacks.
Returns
Whether the receive was successful or not

◆ DmaTransmit()

SpiHandle::Result daisy::MultiSlaveSpiHandle::DmaTransmit ( size_t  device_index,
uint8_t buff,
size_t  size,
SpiHandle::StartCallbackFunctionPtr  start_callback,
SpiHandle::EndCallbackFunctionPtr  end_callback,
void callback_context 
)

DMA-based transmit

Parameters
device_indexthe index of the device
bufftransmit buffer
sizebuffer size
start_callbackA callback to execute when the transfer starts, or NULL.
end_callbackA callback to execute when the transfer finishes, or NULL.
callback_contextA pointer that will be passed back to you in the callbacks.
Returns
Whether the transmit was successful or not

◆ DmaTransmitAndReceive()

SpiHandle::Result daisy::MultiSlaveSpiHandle::DmaTransmitAndReceive ( size_t  device_index,
uint8_t tx_buff,
uint8_t rx_buff,
size_t  size,
SpiHandle::StartCallbackFunctionPtr  start_callback,
SpiHandle::EndCallbackFunctionPtr  end_callback,
void callback_context 
)

DMA-based transmit and receive

Parameters
device_indexthe index of the device
tx_buffthe transmit buffer
rx_buffthe receive buffer
sizebuffer size
start_callbackA callback to execute when the transfer starts, or NULL.
end_callbackA callback to execute when the transfer finishes, or NULL.
callback_contextA pointer that will be passed back to you in the callbacks.
Returns
Whether the receive was successful or not

◆ GetConfig()

const Config & daisy::MultiSlaveSpiHandle::GetConfig ( ) const
inline

Returns the current config.

◆ Init()

SpiHandle::Result daisy::MultiSlaveSpiHandle::Init ( const Config config)

Initializes handler

Member Data Documentation

◆ max_num_devices_

constexpr size_t daisy::MultiSlaveSpiHandle::max_num_devices_ = 4
staticconstexpr

The documentation for this class was generated from the following file: