SPI API

[English]

SPI (Serial Peripheral Interface) 串行外设接口API接口。

Header File

Functions

bk_err_t bk_spi_driver_init(void)

Init the SPI driver.

This API init the resoure common:

  • Init SPI driver control memory

Attention

1. This API should be called before any other SPI APIs.

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_spi_driver_deinit(void)

Deinit the SPI driver.

This API free all resource related to SPI and disable SPI.

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_spi_init(spi_id_t id, const spi_config_t *config)

Init the SPI id.

This API init the SPI id:

  • Power up the SPI id

  • Configure the SPI id clock

  • Map the SPI id to dedicated GPIO port

  • Set the SPI parameters

  • Start the SPI id

参数
  • id – SPI id

  • config – SPI parameter settings

返回

  • BK_OK: succeed

  • BK_ERR_NULL_PARAM: SPI config paramter is NULL

  • BK_ERR_SPI_NOT_INIT: SPI driver not init

  • BK_ERR_SPI_INVALID_ID: SPI id is invalid

  • others: other errors.

bk_err_t bk_spi_deinit(spi_id_t id)

Deinit the SPI id.

This API deinit the SPI id:

  • Stop the SPI id

  • Disable the SPI id interrupt

  • Power down the SPI id

参数

id – SPI id

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_spi_set_mode(spi_id_t id, spi_mode_t mode)

Set the SPI mode.

参数
  • id – SPI id

  • mode – SPI mode

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_spi_set_bit_width(spi_id_t id, spi_bit_width_t bit_width)

Set the SPI bit width.

参数
  • id – SPI id

  • bit_width – SPI bit width

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_spi_set_wire_mode(spi_id_t id, spi_wire_mode_t wire_mode)

Set the SPI wire mode.

参数
  • id – SPI id

  • wire_mode – SPI wire mode

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_spi_set_baud_rate(spi_id_t id, uint32_t baud_rate)

Set the SPI baud rate.

参数
  • id – SPI id

  • baud_rate – SPI baud rate

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_spi_set_bit_order(spi_id_t id, spi_bit_order_t bit_order)

Set the SPI bit order.

参数
  • id – SPI id

  • bit_order – SPI bit order

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_spi_register_rx_isr(spi_id_t id, spi_isr_t isr, void *param)

Register the RX interrupt service routine for SPI id.

参数
  • id – spi id

  • isr – SPI RX callback

  • param – SPI RX callback parameter

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_spi_register_tx_finish_isr(spi_id_t id, spi_isr_t isr, void *param)

Register the TX finish interrupt service routine for SPI id.

参数
  • id – SPi id

  • isr – SPI TX finish callback

  • param – SPi TX callback parameter

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_spi_write_bytes(spi_id_t id, const void *data, uint32_t size)

Send data to the SPI port from a given buffer and length.

参数
  • id – spi id

  • data – data buffer address

  • size – data length to send

返回

  • BK_OK: succeed

  • BK_ERR_SPI_NOT_INIT: SPI driver not init

  • BK_ERR_SPI_INVALID_ID: SPI id number is invalid

  • BK_ERR_SPI_ID_NOT_INIT: SPI id not init

  • others: other errors.

bk_err_t bk_spi_read_bytes(spi_id_t id, void *data, uint32_t size)

SPI read bytes from SPI buffer.

参数
  • id – SPI id

  • data – pointer to the buffer

  • size – data length to read

返回

  • BK_OK: succeed

  • BK_ERR_SPI_NOT_INIT: SPI driver not init

  • BK_ERR_SPI_INVALID_ID: SPI id number is invalid

  • BK_ERR_SPI_ID_NOT_INIT: SPI id not init

  • others: other errors.

bk_err_t bk_spi_transmit(spi_id_t id, const void *tx_data, uint32_t tx_size, void *rx_data, uint32_t rx_size)

SPI write and read bytes.

参数
  • id – SPI id

  • tx_data – write data buffer address

  • tx_size – data length to read

  • rx_data – pointer to the receive buffer

  • rx_size – data length to read

  • timeout_ms – timeout ms, if set BEKEN_WAIT_FOREVER, read will wait forever

返回

  • BK_OK: succeed

  • BK_ERR_SPI_NOT_INIT: SPI driver not init

  • BK_ERR_SPI_INVALID_ID: SPI id number is invalid

  • BK_ERR_SPI_ID_NOT_INIT: SPI id not init

  • others: other errors.

bk_err_t bk_spi_register_rx_finish_isr(spi_id_t id, spi_isr_t isr, void *param)

Register the RX finish interrupt service routine for SPI id.

参数
  • id – spi id

  • isr – SPI RX callback

  • param – SPI RX callback parameter

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_spi_unregister_rx_isr(spi_id_t id)

Unregister the RX interrupt service routine for SPI id.

参数

id – spi id

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_spi_unregister_rx_finish_isr(spi_id_t id)

Unregister the RX finish interrupt service routine for SPI id.

参数

id – spi id

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_spi_unregister_tx_finish_isr(spi_id_t id)

Unregister the TX finish interrupt service routine for SPI id.

参数

id – spi id

返回

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_spi_write_bytes_async(spi_id_t id, const void *data, uint32_t size)

Send data to the SPI port from a given buffer and length in async mode.

参数
  • id – spi id

  • data – data buffer address

  • size – data length to send

返回

  • BK_OK: succeed

  • BK_ERR_SPI_NOT_INIT: SPI driver not init

  • BK_ERR_SPI_INVALID_ID: SPI id number is invalid

  • BK_ERR_SPI_ID_NOT_INIT: SPI id not init

  • others: other errors.

bk_err_t bk_spi_read_bytes_async(spi_id_t id, void *data, uint32_t size)

SPI read bytes from SPI buffer in async mode.

参数
  • id – SPI id

  • data – pointer to the buffer

  • size – data length to read

返回

  • BK_OK: succeed

  • BK_ERR_SPI_NOT_INIT: SPI driver not init

  • BK_ERR_SPI_INVALID_ID: SPI id number is invalid

  • BK_ERR_SPI_ID_NOT_INIT: SPI id not init

  • others: other errors.