SPI master API 参考
SPI Master
-
enum WM_SPIM_TRANS_FLAG
Values:
-
enumerator SPI_TRANS_DUMMY_BITS
dummy bit valid bit
-
enumerator SPI_TRANS_CS_KEEP_ACTIVE
if set, CS will keep active after transceive done
-
enumerator SPI_TRANS_BIG_ENDIAN
if set, transmit high address byte first in a word
-
enumerator SPI_TRANS_VARIABLE_CMD
if set, cmd and cmd_len will valid in spim_transceive_ex_t
-
enumerator SPI_TRANS_VARIABLE_ADDR
if set, addr and addr_len will valid in spim_transceive_ex_t
-
enumerator SPI_TRANS_DUMMY_BITS
-
struct spim_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_SPIM_TRANS_FLAG
-
uint8_t *tx_buf
-
struct spim_transceive_ex_t
Public Members
-
spim_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
-
spim_transceive_t basic
-
typedef void (*wm_spim_callback_t)(int result, void *data)
-
int wm_drv_spim_transceive_sync(wm_device_t *dev, const wm_dt_hw_spim_dev_cfg_t *config, spim_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_spim_transceive_async(wm_device_t *dev, const wm_dt_hw_spim_dev_cfg_t *config, spim_transceive_t *desc, wm_spim_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_spim_init(const char *dev_name)
Initialize SPI master driver.
- 参数:
dev_name – [in] spi master device name
- 返回:
spi master device pointer: succeed
NULL : failed
-
int wm_drv_spim_deinit(wm_device_t *dev)
deinit SPI master driver
- 参数:
dev – [in] SPI master device pointer
- 返回:
WM_ERR_SUCCESS: succeed
others: failed