Skip to content

daisy::SpiHandle

Module: LIBDAISY / PERIPHERAL / SERIAL

More...

#include <spi.h>

Public Classes

Name
struct Config

Public Types

Name
enum class Result
enum class DmaDirection
typedef void(*)(void *context) StartCallbackFunctionPtr
typedef void(*)(void *context, Result result) EndCallbackFunctionPtr

Public Functions

Name
SpiHandle()
SpiHandle(const SpiHandle & other) =default
SpiHandle & operator=(const SpiHandle & other) =default
Result Init(const Config & config)
const Config & GetConfig() 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()

Detailed Description

class daisy::SpiHandle;

Handler for serial peripheral interface

Public Types Documentation

enum Result

Enumerator Value Description
OK &
ERR &

Return values for Spi functions.

enum DmaDirection

Enumerator Value Description
RX &
TX &
RX_TX &

typedef StartCallbackFunctionPtr

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

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

typedef EndCallbackFunctionPtr

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

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

Public Functions Documentation

function SpiHandle

inline SpiHandle()

function SpiHandle

SpiHandle(
    const SpiHandle & other
) =default

function operator=

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

function Init

Result Init(
    const Config & config
)

Initializes handler


function GetConfig

const Config & GetConfig() const

Returns the current config.


function BlockingTransmit

Result BlockingTransmit(
    uint8_t * buff,
    size_t size,
    uint32_t timeout =100
)

Parameters:

  • buff input buffer
  • size buffer size
  • timeout how long in milliseconds the function will wait before returning without successful communication

Blocking transmit


function BlockingReceive

Result BlockingReceive(
    uint8_t * buffer,
    uint16_t size,
    uint32_t timeout
)

Parameters:

  • buffer input buffer
  • size buffer size
  • timeout How long to timeout for in milliseconds

Return: Whether the receive was successful or not

Polling Receive


function BlockingTransmitAndReceive

Result BlockingTransmitAndReceive(
    uint8_t * tx_buff,
    uint8_t * rx_buff,
    size_t size,
    uint32_t timeout =100
)

Parameters:

  • tx_buff the transmit buffer
  • rx_buff the receive buffer
  • size the length of the transaction
  • timeout how long in milliseconds the function will wait before returning without successful communication

Blocking transmit and receive


function DmaTransmit

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

Parameters:

  • ***buff** input buffer
  • size buffer size
  • start_callback A callback to execute when the transfer starts, or NULL. The callback is called from an interrupt, so keep it fast.
  • end_callback A callback to execute when the transfer finishes, or NULL. The callback is called from an interrupt, so keep it fast.
  • callback_context A pointer that will be passed back to you in the callbacks.

Return: Whether the transmit was successful or not

DMA-based transmit


function DmaReceive

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

Parameters:

  • ***buff** input buffer
  • size buffer size
  • start_callback A callback to execute when the transfer starts, or NULL. The callback is called from an interrupt, so keep it fast.
  • end_callback A callback to execute when the transfer finishes, or NULL. The callback is called from an interrupt, so keep it fast.
  • callback_context A pointer that will be passed back to you in the callbacks.

Return: Whether the receive was successful or not

DMA-based receive


function DmaTransmitAndReceive

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

Parameters:

  • tx_buff the transmit buffer
  • rx_buff the receive buffer
  • size buffer size
  • start_callback A callback to execute when the transfer starts, or NULL. The callback is called from an interrupt, so keep it fast.
  • end_callback A callback to execute when the transfer finishes, or NULL. The callback is called from an interrupt, so keep it fast.
  • callback_context A pointer that will be passed back to you in the callbacks.

Return: Whether the receive was successful or not

DMA-based transmit and receive


function CheckError

int CheckError()

Return: the result of HAL_SPI_GetError() to the user.

---

Updated on 2024-01-03 at 19:41:01 +0000