hal_spi.h File Reference

Header file containing functions prototypes of SPI HAL library. More...

#include "ll_spi.h"
#include "hal_def.h"
#include "hal_dma.h"
#include "hal_pwr_mgmt.h"

Go to the source code of this file.

Classes

struct  _spi_init
 SPI init Structure definition. More...
 
struct  _spi_handle
 SPI handle Structure definition. More...
 
struct  _hal_spi_callback
 HAL_SPI Callback function definition. More...
 

Macros

#define SPI_SOFT_CS_MAGIC_NUMBER   0xDEADBEAFU
 
#define CS_STA_STATE_POLL_TX   0x01U
 State from Software CS Assert. More...
 
#define CS_STA_STATE_POLL_RX   0x02U
 
#define CS_STA_STATE_POLL_TX_RX   0x03U
 
#define CS_STA_STATE_POLL_EEPREAD   0x04U
 
#define CS_STA_STATE_IT_TX   0x05U
 
#define CS_STA_STATE_IT_RX   0x06U
 
#define CS_STA_STATE_IT_TX_RX   0x07U
 
#define CS_STA_STATE_IT_EEPREAD   0x08U
 
#define CS_STA_STATE_DMA_TX   0x09U
 
#define CS_STA_STATE_DMA_RX   0x0AU
 
#define CS_STA_STATE_DMA_TX_RX   0x0BU
 
#define CS_STA_STATE_DMA_EEPREAD   0x0CU
 
#define CS_STA_STATE_DMA_LLP_TX   0x0DU
 
#define CS_STA_STATE_DMA_SCATTER_RX   0x0EU
 
#define CS_END_STATE_POLL_TX   0x81U
 State from Software CS De-Assert. More...
 
#define CS_END_STATE_POLL_RX   0x82U
 
#define CS_END_STATE_POLL_TX_RX   0x83U
 
#define CS_END_STATE_POLL_EEPREAD   0x84U
 
#define CS_END_STATE_TX_CPLT   0x90U
 
#define CS_END_STATE_RX_CPLT   0x91U
 
#define CS_END_STATE_TX_RX_CPLT   0x92U
 
#define CS_END_STATE_XFER_ERR   0x93U
 
#define CS_END_STATE_TX_ABORT_CPLT   0x94U
 
#define CS_END_STATE_RX_ABORT_CPLT   0x95U
 
#define CS_END_STATE_ABORT_CPLT   0x96U
 
#define SPI_DIRECTION_FULL_DUPLEX   LL_SPI_FULL_DUPLEX
 
#define SPI_DIRECTION_SIMPLEX_TX   LL_SPI_SIMPLEX_TX
 
#define SPI_DIRECTION_SIMPLEX_RX   LL_SPI_SIMPLEX_RX
 
#define SPI_DIRECTION_READ_EEPROM   LL_SPI_READ_EEPROM
 
#define HAL_SPI_ERROR_NONE   ((uint32_t)0x00000000)
 
#define HAL_SPI_ERROR_TIMEOUT   ((uint32_t)0x00000001)
 
#define HAL_SPI_ERROR_TRANSFER   ((uint32_t)0x00000002)
 
#define HAL_SPI_ERROR_DMA   ((uint32_t)0x00000004)
 
#define HAL_SPI_ERROR_INVALID_PARAM   ((uint32_t)0x00000008)
 
#define SPI_DATASIZE_4BIT   LL_SPI_DATASIZE_4BIT
 
#define SPI_DATASIZE_5BIT   LL_SPI_DATASIZE_5BIT
 
#define SPI_DATASIZE_6BIT   LL_SPI_DATASIZE_6BIT
 
#define SPI_DATASIZE_7BIT   LL_SPI_DATASIZE_7BIT
 
#define SPI_DATASIZE_8BIT   LL_SPI_DATASIZE_8BIT
 
#define SPI_DATASIZE_9BIT   LL_SPI_DATASIZE_9BIT
 
#define SPI_DATASIZE_10BIT   LL_SPI_DATASIZE_10BIT
 
#define SPI_DATASIZE_11BIT   LL_SPI_DATASIZE_11BIT
 
#define SPI_DATASIZE_12BIT   LL_SPI_DATASIZE_12BIT
 
#define SPI_DATASIZE_13BIT   LL_SPI_DATASIZE_13BIT
 
#define SPI_DATASIZE_14BIT   LL_SPI_DATASIZE_14BIT
 
#define SPI_DATASIZE_15BIT   LL_SPI_DATASIZE_15BIT
 
#define SPI_DATASIZE_16BIT   LL_SPI_DATASIZE_16BIT
 
#define SPI_DATASIZE_17BIT   LL_SPI_DATASIZE_17BIT
 
#define SPI_DATASIZE_18BIT   LL_SPI_DATASIZE_18BIT
 
#define SPI_DATASIZE_19BIT   LL_SPI_DATASIZE_19BIT
 
#define SPI_DATASIZE_20BIT   LL_SPI_DATASIZE_20BIT
 
#define SPI_DATASIZE_21BIT   LL_SPI_DATASIZE_21BIT
 
#define SPI_DATASIZE_22BIT   LL_SPI_DATASIZE_22BIT
 
#define SPI_DATASIZE_23BIT   LL_SPI_DATASIZE_23BIT
 
#define SPI_DATASIZE_24BIT   LL_SPI_DATASIZE_24BIT
 
#define SPI_DATASIZE_25BIT   LL_SPI_DATASIZE_25BIT
 
#define SPI_DATASIZE_26BIT   LL_SPI_DATASIZE_26BIT
 
#define SPI_DATASIZE_27BIT   LL_SPI_DATASIZE_27BIT
 
#define SPI_DATASIZE_28BIT   LL_SPI_DATASIZE_28BIT
 
#define SPI_DATASIZE_29BIT   LL_SPI_DATASIZE_29BIT
 
#define SPI_DATASIZE_30BIT   LL_SPI_DATASIZE_30BIT
 
#define SPI_DATASIZE_31BIT   LL_SPI_DATASIZE_31BIT
 
#define SPI_DATASIZE_32BIT   LL_SPI_DATASIZE_32BIT
 
#define SPI_POLARITY_LOW   LL_SPI_SCPOL_LOW
 
#define SPI_POLARITY_HIGH   LL_SPI_SCPOL_HIGH
 
#define SPI_PHASE_1EDGE   LL_SPI_SCPHA_1EDGE
 
#define SPI_PHASE_2EDGE   LL_SPI_SCPHA_2EDGE
 
#define SPI_TIMODE_DISABLE   ((uint32_t)0x00000000)
 
#define SPI_TIMODE_ENABLE   LL_SPI_PROTOCOL_TI
 
#define SPI_SLAVE_SELECT_0   LL_SPI_SLAVE0
 
#define SPI_SLAVE_SELECT_1   LL_SPI_SLAVE1
 
#define SPI_SLAVE_SELECT_ALL   (LL_SPI_SLAVE0 | LL_SPI_SLAVE1)
 
#define SPI_TX_FIFO_LEVEL_MAX   8U
 
#define SPI_RX_FIFO_LEVEL_MAX   8U
 
#define SPI_FLAG_DCOL   LL_SPI_SR_DCOL
 
#define SPI_FLAG_TXE   LL_SPI_SR_TXE
 
#define SPI_FLAG_RFF   LL_SPI_SR_RFF
 
#define SPI_FLAG_RFNE   LL_SPI_SR_RFNE
 
#define SPI_FLAG_TFE   LL_SPI_SR_TFE
 
#define SPI_FLAG_TFNF   LL_SPI_SR_TFNF
 
#define SPI_FLAG_BUSY   LL_SPI_SR_BUSY
 
#define SPI_IT_MST   LL_SPI_IS_MST
 
#define SPI_IT_RXF   LL_SPI_IS_RXF
 
#define SPI_IT_RXO   LL_SPI_IS_RXO
 
#define SPI_IT_RXU   LL_SPI_IS_RXU
 
#define SPI_IT_TXO   LL_SPI_IS_TXO
 
#define SPI_IT_TXE   LL_SPI_IS_TXE
 
#define HAL_SPI_TIMEOUT_DEFAULT_VALUE   ((uint32_t)5000)
 
#define __HAL_SPI_RESET_HANDLE_STATE(__HANDLE__)   ((__HANDLE__)->state = HAL_SPI_STATE_RESET)
 Reset SPI handle states. More...
 
#define __HAL_SPI_ENABLE(__HANDLE__)   SET_BITS((__HANDLE__)->p_instance->SSI_EN, SPI_SSI_EN)
 Enable the specified SPI peripheral. More...
 
#define __HAL_SPI_DISABLE(__HANDLE__)   CLEAR_BITS((__HANDLE__)->p_instance->SSI_EN, SPI_SSI_EN)
 Disable the specified SPI peripheral. More...
 
#define __HAL_SPI_ENABLE_DMATX(__HANDLE__)   SET_BITS((__HANDLE__)->p_instance->DMA_CTRL, SPI_DMA_CTRL_TX_DMA_EN)
 Enable the SPI DMA TX Request. More...
 
#define __HAL_SPI_ENABLE_DMARX(__HANDLE__)   SET_BITS((__HANDLE__)->p_instance->DMA_CTRL, SPI_DMA_CTRL_RX_DMA_EN)
 Enable the SPI DMA RX Request. More...
 
#define __HAL_SPI_DISABLE_DMATX(__HANDLE__)   CLEAR_BITS((__HANDLE__)->p_instance->DMA_CTRL, SPI_DMA_CTRL_TX_DMA_EN)
 Disable the SPI DMA TX Request. More...
 
#define __HAL_SPI_DISABLE_DMARX(__HANDLE__)   CLEAR_BITS((__HANDLE__)->p_instance->DMA_CTRL, SPI_DMA_CTRL_RX_DMA_EN)
 Disable the SPI DMA RX Request. More...
 
#define __HAL_SPI_ENABLE_IT(__HANDLE__, __INTERRUPT__)   SET_BITS((__HANDLE__)->p_instance->INT_MASK, (__INTERRUPT__))
 Enable the specified SPI interrupts. More...
 
#define __HAL_SPI_DISABLE_IT(__HANDLE__, __INTERRUPT__)   CLEAR_BITS((__HANDLE__)->p_instance->INT_MASK, (__INTERRUPT__))
 Disable the specified SPI interrupts. More...
 
#define __HAL_SPI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)   (READ_BITS((__HANDLE__)->p_instance->INT_STAT, (__INTERRUPT__)) == (__INTERRUPT__))
 Check whether the specified SPI interrupt source is enabled or not. More...
 
#define __HAL_SPI_GET_FLAG(__HANDLE__, __FLAG__)   ((READ_BITS((__HANDLE__)->p_instance->STAT, (__FLAG__)) != 0U) ? SET : RESET)
 Check whether the specified SPI flag is set or not. More...
 
#define __HAL_SPI_CLEAR_FLAG(__HANDLE__, __FLAG__)   READ_BITS((__HANDLE__)->p_instance->STAT, (__FLAG__))
 Clear the specified SPI flag. More...
 
#define IS_SPI_DIRECTION(__MODE__)
 Check if SPI Direction Mode is valid. More...
 
#define IS_SPI_DATASIZE(__DATASIZE__)
 Check if SPI Data Size is valid. More...
 
#define IS_SPI_CPOL(__CPOL__)
 Check if SPI Clock Polarity is valid. More...
 
#define IS_SPI_CPHA(__CPHA__)
 Check if SPI Clock Phase is valid. More...
 
#define IS_SPI_BAUDRATE_PRESCALER(__PRESCALER__)   ((__PRESCALER__) <= 0xFFFF)
 Check if SPI BaudRate Prescaler is valid. More...
 
#define IS_SPI_TIMODE(__MODE__)
 Check if SPI TI Mode is valid. More...
 
#define IS_SPI_SLAVE(__SLAVE__)
 Check if SPI Slave Select is valid. More...
 
#define IS_SPI_RX_SAMPLE_DLY(__DLY__)   (((__DLY__) >= 0) && ((__DLY__) <= 7))
 Check if SPI RX Sample Delay Value is valid. More...
 
#define IS_SPI_FIFO_THRESHOLD(__THR__)   (((__THR__) >= 0) && ((__THR__) <= (LL_SPI_M_FIFO_DEPTH - 1)))
 Check if SPI FIFO Threshold is valid. More...
 

Typedefs

typedef struct _spi_init spi_init_t
 SPI init Structure definition. More...
 
typedef struct _spi_handle spi_handle_t
 SPI handle Structure definition. More...
 
typedef struct _hal_spi_callback hal_spi_callback_t
 HAL_SPI Callback function definition. More...
 

Enumerations

enum  hal_spi_state_t {
  HAL_SPI_STATE_RESET = 0x00,
  HAL_SPI_STATE_READY = 0x01,
  HAL_SPI_STATE_BUSY = 0x02,
  HAL_SPI_STATE_BUSY_TX = 0x12,
  HAL_SPI_STATE_BUSY_RX = 0x22,
  HAL_SPI_STATE_BUSY_TX_RX = 0x32,
  HAL_SPI_STATE_ABORT = 0x08,
  HAL_SPI_STATE_ERROR = 0x04
}
 HAL SPI State Enumerations definition. More...
 

Functions

hal_status_t hal_spi_init (spi_handle_t *p_spi)
 Initialize the SPI according to the specified parameters in the spi_init_t and initialize the associated handle. More...
 
hal_status_t hal_spi_deinit (spi_handle_t *p_spi)
 De-initialize the SPI peripheral. More...
 
void hal_spi_msp_init (spi_handle_t *p_spi)
 Initialize the SPI MSP. More...
 
void hal_spi_msp_deinit (spi_handle_t *p_spi)
 De-initialize the SPI MSP. More...
 
hal_status_t hal_spi_transmit (spi_handle_t *p_spi, uint8_t *p_data, uint32_t length, uint32_t timeout)
 Transmit an amount of data in blocking mode. More...
 
hal_status_t hal_spi_receive (spi_handle_t *p_spi, uint8_t *p_data, uint32_t length, uint32_t timeout)
 Receive an amount of data in blocking mode. More...
 
hal_status_t hal_spi_transmit_receive (spi_handle_t *p_spi, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t length, uint32_t timeout)
 Transmit and Receive an amount of data in blocking mode. More...
 
hal_status_t hal_spi_read_eeprom (spi_handle_t *p_spi, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t tx_number_data, uint32_t rx_number_data, uint32_t timeout)
 Read an amount of data from EEPROM in blocking mode. More...
 
hal_status_t hal_spi_transmit_it (spi_handle_t *p_spi, uint8_t *p_data, uint32_t length)
 Transmit an amount of data in non-blocking mode with Interrupt. More...
 
hal_status_t hal_spi_receive_it (spi_handle_t *p_spi, uint8_t *p_data, uint32_t length)
 Receive an amount of data in non-blocking mode with Interrupt. More...
 
hal_status_t hal_spi_transmit_receive_it (spi_handle_t *p_spi, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t length)
 Transmit and Receive an amount of data in non-blocking mode with Interrupt. More...
 
hal_status_t hal_spi_read_eeprom_it (spi_handle_t *p_spi, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t tx_number_data, uint32_t rx_number_data)
 Read an amount of data from EEPROM in non-blocking mode with Interrupt. More...
 
hal_status_t hal_spi_transmit_dma (spi_handle_t *p_spi, uint8_t *p_data, uint32_t length)
 Transmit an amount of data in non-blocking mode with DMA. More...
 
hal_status_t hal_spi_receive_dma (spi_handle_t *p_spi, uint8_t *p_data, uint32_t length)
 Receive an amount of data in non-blocking mode with DMA. More...
 
hal_status_t hal_spi_transmit_receive_dma (spi_handle_t *p_spi, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t length)
 Transmit and Receive an amount of data in non-blocking mode with DMA. More...
 
hal_status_t hal_spi_read_eeprom_dma (spi_handle_t *p_spi, uint8_t *p_tx_data, uint8_t *p_rx_data, uint32_t tx_number_data, uint32_t rx_number_data)
 Read an amount of data from EEPROM in non-blocking mode with DMA. More...
 
hal_status_t hal_spi_transmit_with_ia (spi_handle_t *p_spi, uint8_t inst, uint32_t addr, uint8_t *p_data, uint32_t length, uint32_t timeout)
 Transmit an amount of data in non-blocking mode with polling. Support Setting C&A. More...
 
hal_status_t hal_spi_transmit_dma_with_ia (spi_handle_t *p_spi, uint8_t inst, uint32_t addr, uint8_t *p_data, uint32_t length)
 Transmit an amount of data in non-blocking mode with DMA. Support Setting C&A. More...
 
hal_status_t hal_spi_transmit_with_ia_32addr (spi_handle_t *p_spi, uint8_t inst, uint32_t addr, uint8_t *p_data, uint32_t length, uint32_t timeout)
 Transmit an amount of data in non-blocking mode with polling. Support Setting C&A. More...
 
hal_status_t hal_spi_transmit_dma_with_ia_32addr (spi_handle_t *p_spi, uint8_t inst, uint32_t addr, uint8_t *p_data, uint32_t length)
 Transmit an amount of data in non-blocking mode with DMA. Support Setting C&A. More...
 
hal_status_t hal_spi_abort (spi_handle_t *p_spi)
 Abort ongoing transfer (blocking mode). More...
 
hal_status_t hal_spi_abort_it (spi_handle_t *p_spi)
 Abort ongoing transfer (Interrupt mode). More...
 
void hal_spi_irq_handler (spi_handle_t *p_spi)
 Handle SPI interrupt request. More...
 
void hal_spi_tx_cplt_callback (spi_handle_t *p_spi)
 Tx Transfer completed callback. More...
 
void hal_spi_rx_cplt_callback (spi_handle_t *p_spi)
 Rx Transfer completed callback. More...
 
void hal_spi_tx_rx_cplt_callback (spi_handle_t *p_spi)
 Tx and Rx Transfer completed callback. More...
 
void hal_spi_error_callback (spi_handle_t *p_spi)
 SPI error callback. More...
 
void hal_spi_abort_cplt_callback (spi_handle_t *p_spi)
 SPI Abort Completed callback. More...
 
hal_spi_state_t hal_spi_get_state (spi_handle_t *p_spi)
 Return the SPI handle state. More...
 
uint32_t hal_spi_get_error (spi_handle_t *p_spi)
 Return the SPI error code. More...
 
void hal_spi_set_timeout (spi_handle_t *p_spi, uint32_t timeout)
 Set the SPI internal process timeout value. More...
 
hal_status_t hal_spi_set_tx_fifo_threshold (spi_handle_t *p_spi, uint32_t threshold)
 Set the TX FIFO threshold. More...
 
hal_status_t hal_spi_set_rx_fifo_threshold (spi_handle_t *p_spi, uint32_t threshold)
 Set the RX FIFO threshold. More...
 
uint32_t hal_spi_get_tx_fifo_threshold (spi_handle_t *p_spi)
 Get the TX FIFO threshold. More...
 
uint32_t hal_spi_get_rx_fifo_threshold (spi_handle_t *p_spi)
 Get the RX FIFO threshold. More...
 
void hal_spi_suspend_reg (spi_handle_t *p_spi)
 Suspend some registers related to SPI configuration before sleep. More...
 
void hal_spi_resume_reg (spi_handle_t *p_spi)
 Restore some registers related to SPI configuration after sleep. This function must be used in conjunction with the hal_spi_suspend_reg(). More...
 
hal_pm_status_t hal_pm_spi_suspend (spi_handle_t *p_spi)
 Suspend the specified SPI. More...
 
void hal_pm_spi_resume (spi_handle_t *p_spi)
 Resume the specified SPI. More...
 
void hal_spi_soft_cs_assert (spi_handle_t *p_spi, uint32_t state)
 Assert the CS Singal line by software (When activate the soft-cs mode) More...
 
void hal_spi_soft_cs_deassert (spi_handle_t *p_spi, uint32_t state)
 De-Assert the CS Singal line by software (When activate the soft-cs mode) More...
 

Detailed Description

Header file containing functions prototypes of SPI HAL library.

Author
BLE Driver Team
Attention
#####Copyright (c) 2019 GOODIX All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of GOODIX nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file hal_spi.h.