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

Detailed Description

Handler for serial peripheral interface

#include <spi.h>

Classes

struct  Config
 

Public Types

enum class  Result { OK , ERR }
 
enum class  DmaDirection { RX , TX , RX_TX }
 
typedef void(* StartCallbackFunctionPtr) (void *context)
 
typedef void(* EndCallbackFunctionPtr) (void *context, Result result)
 

Public Member Functions

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

Member Typedef Documentation

◆ EndCallbackFunctionPtr

typedef void(* daisy::SpiHandle::EndCallbackFunctionPtr) (void *context, Result result)

A callback to be executed after a dma transfer is completed.

◆ StartCallbackFunctionPtr

typedef void(* daisy::SpiHandle::StartCallbackFunctionPtr) (void *context)

A callback to be executed right before a dma transfer is started.

Member Enumeration Documentation

◆ DmaDirection

Enumerator
RX 

&

TX 

&

RX_TX 

&

◆ Result

Return values for Spi functions.

Enumerator
OK 

&

ERR 

&

Constructor & Destructor Documentation

◆ SpiHandle() [1/2]

daisy::SpiHandle::SpiHandle ( )
inline

◆ SpiHandle() [2/2]

daisy::SpiHandle::SpiHandle ( const SpiHandle other)
default

Member Function Documentation

◆ BlockingReceive()

Result daisy::SpiHandle::BlockingReceive ( uint8_t buffer,
uint16_t  size,
uint32_t  timeout 
)

Polling Receive

Parameters
bufferinput buffer
sizebuffer size
timeoutHow long to timeout for in milliseconds
Returns
Whether the receive was successful or not

◆ BlockingTransmit()

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

Blocking transmit

Parameters
buffinput buffer
sizebuffer size
timeouthow long in milliseconds the function will wait before returning without successful communication

◆ BlockingTransmitAndReceive()

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

Blocking transmit and receive

Parameters
tx_buffthe transmit buffer
rx_buffthe receive buffer
sizethe length of the transaction
timeouthow long in milliseconds the function will wait before returning without successful communication

◆ CheckError()

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

◆ DmaReceive()

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

DMA-based receive

Parameters
*buffinput buffer
sizebuffer size
start_callbackA callback to execute when the transfer starts, or NULL. The callback is called from an interrupt, so keep it fast.
end_callbackA callback to execute when the transfer finishes, or NULL. The callback is called from an interrupt, so keep it fast.
callback_contextA pointer that will be passed back to you in the callbacks.
Returns
Whether the receive was successful or not

◆ DmaTransmit()

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

DMA-based transmit

Parameters
*buffinput buffer
sizebuffer size
start_callbackA callback to execute when the transfer starts, or NULL. The callback is called from an interrupt, so keep it fast.
end_callbackA callback to execute when the transfer finishes, or NULL. The callback is called from an interrupt, so keep it fast.
callback_contextA pointer that will be passed back to you in the callbacks.
Returns
Whether the transmit was successful or not

◆ DmaTransmitAndReceive()

Result daisy::SpiHandle::DmaTransmitAndReceive ( 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
tx_buffthe transmit buffer
rx_buffthe receive buffer
sizebuffer size
start_callbackA callback to execute when the transfer starts, or NULL. The callback is called from an interrupt, so keep it fast.
end_callbackA callback to execute when the transfer finishes, or NULL. The callback is called from an interrupt, so keep it fast.
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::SpiHandle::GetConfig ( ) const

Returns the current config.

◆ Init()

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

Initializes handler

◆ operator=()

SpiHandle & daisy::SpiHandle::operator= ( const SpiHandle other)
default

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