这是最新(主)开发分支的文档。如果您正在查找以前版本的文档,使用左侧的下拉菜单选择所需的版本。

SPI slave API 参考

头文件

  • wm_iot_sdk/components/driver/include/wm_drv_spi_slave.h

  • This header file can be included with:

#include "wm_drv_spi_slave.h"

宏定义

enum WM_SPIS_TRANS_FLAG

Values:

enumerator SPIS_TRANS_DUMMY_BITS

dummy bit valid bit

enumerator SPIS_TRANS_CS_KEEP_ACTIVE

if set, CS will keep active after transceive done

enumerator SPIS_TRANS_BIG_ENDIAN

if set, transmit high address byte first in a word

enumerator SPIS_TRANS_VARIABLE_CMD

if set, cmd and cmd_len will valid in spis_transceive_ex_t

enumerator SPIS_TRANS_VARIABLE_ADDR

if set, addr and addr_len will valid in spis_transceive_ex_t

结构体

struct spis_transceive_t

Public Members

uint8_t *tx_buf

[input]pointer to transmit buffer, or NULL no data to be transmit, if use DMA must 4 byte algin

uint8_t *rx_buf

[output]pointer to transmit buffer, or NULL no data receive, if use DMA must 4 byte algin

uint32_t tx_len

[input]total transmit length

uint32_t rx_len

[intput]total receive length

uint32_t flags

[input]transceive flag ref: WM_SPIS_TRANS_FLAG

struct spis_transceive_ex_t

Public Members

spis_transceive_t basic

it’s must be as the first member

uint16_t cmd

[input] tx command data, if you want to use this member must set “cmd_len” at the same time, if transmit low byte first, must set SPI_TRANS_CMD_SMALL_ENDIAN

uint32_t addr

[input] tx address data, if you want to use this member must set “addr_len” at the same time, if transmit low byte first, must set SPI_TRANS_ADDR_SMALL_ENDIAN

uint8_t cmd_len

[input] command length, unit is byte [0~2]

uint8_t addr_len

[input] address length, unit is byte [0~4]

uint8_t dummy_bits

[input] dummy length, unit is bit, must set SPI_TRANS_DUMMY_BITS flag if want to use this member

接口

typedef void (*wm_spis_callback_t)(int result, void *data)
int wm_drv_spis_transceive_sync(wm_device_t *dev, const wm_dt_hw_spis_dev_cfg_t *config, spis_transceive_t *desc, uint32_t ms_to_wait)

transceive data synchronously, the api return until synchronously done or timeout

参数:
  • dev[in] SPI device pointer

  • config[in] Pointer to a valid wm_hw_spi_device_config_t structure instance.

  • desc[in] transceive descrption about tx and rx

  • ms_to_wait[in] the max wait time for transeceive done, unit is millisecon

返回:

  • WM_ERR_SUCCESS: succeed

  • others: failed

int wm_drv_spis_transceive_async(wm_device_t *dev, const wm_dt_hw_spis_dev_cfg_t *config, spis_transceive_t *desc, wm_spis_callback_t callback, void *usr_data)

transceive data asynchronously, callback will be trigger after transceive done

参数:
  • dev[in] SPI device pointer

  • config[in] Pointer to a valid wm_hw_spi_device_config_t structure instance.

  • desc[in] transceive descrption about tx and rx

  • callback[in] the function will be trigger after transceive done

  • usr_data[in] the argument for callback function

返回:

  • WM_ERR_SUCCESS: succeed

  • others: failed

wm_device_t *wm_drv_spis_init(const char *dev_name)

Initialize SPI slave driver.

参数:

dev_name[in] spi slave device name

返回:

  • spi slave device pointer: succeed

  • NULL : failed

int wm_drv_spis_deinit(wm_device_t *dev)

deinit SPI slave driver

参数:

dev[in] SPI slave device pointer

返回:

  • WM_ERR_SUCCESS: succeed

  • others: failed