HPM SDK
HPMicro Software Development Kit
hpm_spi_drv.h File Reference
#include "hpm_spi_regs.h"
#include "hpm_soc_feature.h"

Go to the source code of this file.

Data Structures

struct  spi_master_timing_config_t
 spi master interface timing config structure More...
 
struct  spi_timing_config_t
 spi interface timing config structure More...
 
struct  spi_master_format_config_t
 spi master transfer format config structure More...
 
struct  spi_common_format_config_t
 spi common format config structure More...
 
struct  spi_format_config_t
 spi format config structure More...
 
struct  spi_master_control_config_t
 spi master transfer control config structure More...
 
struct  spi_slave_control_config_t
 spi slave transfer control config structure More...
 
struct  spi_common_control_config_t
 spi common transfer control config structure More...
 
struct  spi_control_config_t
 spi control config structure More...
 

Enumerations

enum  spi_dma_enable_t { spi_tx_dma_enable = SPI_CTRL_TXDMAEN_MASK , spi_rx_dma_enable = SPI_CTRL_RXDMAEN_MASK }
 spi dma enable More...
 
enum  spi_interrupt_t {
  spi_rx_fifo_overflow_int = SPI_INTREN_RXFIFOORINTEN_MASK , spi_tx_fifo_underflow_int = SPI_INTREN_TXFIFOURINTEN_MASK , spi_rx_fifo_threshold_int = SPI_INTREN_RXFIFOINTEN_MASK , spi_tx_fifo_threshold_int = SPI_INTREN_TXFIFOINTEN_MASK ,
  spi_end_int = SPI_INTREN_ENDINTEN_MASK , spi_slave_cmd_int = SPI_INTREN_SLVCMDEN_MASK
}
 spi interrupt mask More...
 
enum  spi_mode_selection_t { spi_master_mode = 0 , spi_slave_mode }
 spi mode selection More...
 
enum  spi_sclk_idle_state_t { spi_sclk_low_idle = 0 , spi_sclk_high_idle }
 spi clock polarity More...
 
enum  spi_sclk_sampling_clk_edges_t { spi_sclk_sampling_odd_clk_edges = 0 , spi_sclk_sampling_even_clk_edges }
 spi clock phase More...
 
enum  spi_cs2sclk_duration_t { spi_cs2sclk_half_sclk_1 = 0 , spi_cs2sclk_half_sclk_2 , spi_cs2sclk_half_sclk_3 , spi_cs2sclk_half_sclk_4 }
 spi cs to sclk edge duration More...
 
enum  spi_csht_duration_t {
  spi_csht_half_sclk_1 = 0 , spi_csht_half_sclk_2 , spi_csht_half_sclk_3 , spi_csht_half_sclk_4 ,
  spi_csht_half_sclk_5 , spi_csht_half_sclk_6 , spi_csht_half_sclk_7 , spi_csht_half_sclk_8 ,
  spi_csht_half_sclk_9 , spi_csht_half_sclk_10 , spi_csht_half_sclk_11 , spi_csht_half_sclk_12 ,
  spi_csht_half_sclk_13 , spi_csht_half_sclk_14 , spi_csht_half_sclk_15 , spi_csht_half_sclk_16
}
 spi cs high level duration More...
 
enum  spi_addr_phase_format_t { spi_address_phase_format_single_io_mode = 0 , spi_address_phase_format_dualquad_io_mode }
 spi address phase format More...
 
enum  spi_trans_mode_t {
  spi_trans_write_read_together = 0 , spi_trans_write_only , spi_trans_read_only , spi_trans_write_read ,
  spi_trans_read_write , spi_trans_write_dummy_read , spi_trans_read_dummy_write , spi_trans_no_data ,
  spi_trans_dummy_write , spi_trans_dummy_read
}
 spi transfer mode More...
 
enum  spi_data_phase_format_t { spi_single_io_mode = 0 , spi_dual_io_mode , spi_quad_io_mode }
 spi data phase format More...
 
enum  spi_token_value_t { spi_token_value_0x00 = 0 , spi_token_value_0x69 }
 spi token value More...
 
enum  spi_dummy_count_t { spi_dummy_count_1 = 0 , spi_dummy_count_2 , spi_dummy_count_3 , spi_dummy_count_4 }
 spi dummy count More...
 
enum  spi_shift_direction_t { spi_msb_first = 0 , spi_lsb_first }
 
enum  spi_cs_index_t { spi_cs_0 = 1 , spi_cs_1 = 2 , spi_cs_2 = 4 , spi_cs_3 = 8 }
 
enum  spi_address_len_t { addrlen_8bit = 0 , addrlen_16bit , addrlen_24bit , addrlen_32bit }
 
enum  spi_directio_pin_t {
  hold_pin = 0 , wp_pin , miso_pin , mosi_pin ,
  sclk_pin , cs_pin
}
 
enum  { status_spi_master_busy = MAKE_STATUS(status_group_spi, 1) }
 SPI status. More...
 

Functions

void spi_master_get_default_timing_config (spi_timing_config_t *config)
 spi master get default timing config More...
 
void spi_master_get_default_format_config (spi_format_config_t *config)
 spi master get default format config More...
 
void spi_master_get_default_control_config (spi_control_config_t *config)
 spi master get default control config More...
 
void spi_slave_get_default_format_config (spi_format_config_t *config)
 spi slave get default format config More...
 
void spi_slave_get_default_control_config (spi_control_config_t *config)
 spi slave get default control config More...
 
hpm_stat_t spi_master_timing_init (SPI_Type *ptr, spi_timing_config_t *config)
 spi master timing initialization More...
 
void spi_format_init (SPI_Type *ptr, spi_format_config_t *config)
 spi format initialization More...
 
hpm_stat_t spi_transfer (SPI_Type *ptr, spi_control_config_t *config, uint8_t *cmd, uint32_t *addr, uint8_t *wbuff, uint32_t wcount, uint8_t *rbuff, uint32_t rcount)
 spi transfer More...
 
hpm_stat_t spi_setup_dma_transfer (SPI_Type *ptr, spi_control_config_t *config, uint8_t *cmd, uint32_t *addr, uint32_t wcount, uint32_t rcount)
 spi setup dma transfer More...
 
hpm_stat_t spi_wait_for_idle_status (SPI_Type *ptr)
 spi wait for idle status More...
 
hpm_stat_t spi_wait_for_busy_status (SPI_Type *ptr)
 spi wait for busy status More...
 
static void spi_set_tx_fifo_threshold (SPI_Type *ptr, uint32_t threshold)
 SPI set TX FIFO threshold. More...
 
static void spi_set_rx_fifo_threshold (SPI_Type *ptr, uint32_t threshold)
 SPI set RX FIFO threshold. More...
 
static void spi_enable_dma (SPI_Type *ptr, uint32_t mask)
 Enables the SPI DMA request. More...
 
static void spi_disable_dma (SPI_Type *ptr, uint32_t mask)
 Disables the SPI DMA request. More...
 
static uint32_t spi_get_interrupt_status (SPI_Type *ptr)
 Get the SPI interrupt status. More...
 
static void spi_clear_interrupt_status (SPI_Type *ptr, uint32_t mask)
 Clear the SPI interrupt status. More...
 
static void spi_enable_interrupt (SPI_Type *ptr, uint32_t mask)
 Enables the SPI interrupt. More...
 
static void spi_disable_interrupt (SPI_Type *ptr, uint32_t mask)
 Disables the SPI interrupt. More...
 
hpm_stat_t spi_write_read_data (SPI_Type *ptr, uint8_t data_len_in_bytes, uint8_t *wbuff, uint32_t wcount, uint8_t *rbuff, uint32_t rcount)
 spi write and read data More...
 
hpm_stat_t spi_read_data (SPI_Type *ptr, uint8_t data_len_in_bytes, uint8_t *buff, uint32_t count)
 spi read data More...
 
hpm_stat_t spi_write_data (SPI_Type *ptr, uint8_t data_len_in_bytes, uint8_t *buff, uint32_t count)
 spi write data More...
 
hpm_stat_t spi_write_command (SPI_Type *ptr, spi_mode_selection_t mode, spi_control_config_t *config, uint8_t *cmd)
 spi write command More...
 
hpm_stat_t spi_read_command (SPI_Type *ptr, spi_mode_selection_t mode, spi_control_config_t *config, uint8_t *cmd)
 spi read command More...
 
hpm_stat_t spi_write_address (SPI_Type *ptr, spi_mode_selection_t mode, spi_control_config_t *config, uint32_t *addr)
 spi write address More...
 
hpm_stat_t spi_control_init (SPI_Type *ptr, spi_control_config_t *config, uint32_t wcount, uint32_t rcount)
 spi control initialization More...
 
static uint8_t spi_get_data_length_in_bits (SPI_Type *ptr)
 Get the SPI data length in bits. More...
 
static uint8_t spi_get_data_length_in_bytes (SPI_Type *ptr)
 Get the SPI data length in bytes. More...
 
static bool spi_is_active (SPI_Type *ptr)
 SPI get active status. More...
 
static void spi_enable_tx_dma (SPI_Type *ptr)
 SPI enable tx dma. More...
 
static void spi_disable_tx_dma (SPI_Type *ptr)
 SPI disable tx dma. More...
 
static void spi_enable_rx_dma (SPI_Type *ptr)
 SPI enable rx dma. More...
 
static void spi_disable_rx_dma (SPI_Type *ptr)
 SPI disable rx dma. More...
 
static uint32_t spi_slave_get_sent_data_count (SPI_Type *ptr)
 SPI slave get sent data count. More...
 
static uint32_t spi_slave_get_received_data_count (SPI_Type *ptr)
 SPI slave get received data count. More...
 
static void spi_set_clock_phase (SPI_Type *ptr, spi_sclk_sampling_clk_edges_t clock_phase)
 set spi clock phase More...
 
static spi_sclk_sampling_clk_edges_t spi_get_clock_phase (SPI_Type *ptr)
 get spi clock phase More...
 
static void spi_set_clock_polarity (SPI_Type *ptr, spi_sclk_idle_state_t clock_polarity)
 set spi clock polarity More...
 
static spi_sclk_idle_state_t spi_get_clock_polarity (SPI_Type *ptr)
 get spi clock phase More...
 
static hpm_stat_t spi_set_data_bits (SPI_Type *ptr, uint8_t nbits)
 set spi the length of each data unit in bits More...
 
static void spi_transmit_fifo_reset (SPI_Type *ptr)
 SPI transmit fifo reset. More...
 
static void spi_receive_fifo_reset (SPI_Type *ptr)
 SPI receive fifo reset. More...
 
static void spi_reset (SPI_Type *ptr)
 SPI reset. More...
 
static void spi_set_address_len (SPI_Type *ptr, spi_address_len_t addrlen)
 set spi the length of address More...
 
static void spi_enable_data_merge (SPI_Type *ptr)
 Enable SPI data merge. More...
 
static void spi_disable_data_merge (SPI_Type *ptr)
 Disable SPI data merge. More...
 
hpm_stat_t spi_directio_enable_output (SPI_Type *ptr, spi_directio_pin_t pin)
 enable specific pin output for spi directio More...
 
hpm_stat_t spi_directio_disable_output (SPI_Type *ptr, spi_directio_pin_t pin)
 disable specific pin output for spi directio More...
 
hpm_stat_t spi_directio_write (SPI_Type *ptr, spi_directio_pin_t pin, bool high)
 write specified pin level for spi directio More...
 
uint8_t spi_directio_read (SPI_Type *ptr, spi_directio_pin_t pin)
 Read specified pin level for spi directio. More...
 
static void spi_enable_directio (SPI_Type *ptr)
 Enable SPI directIO control function. More...
 
static void spi_disable_directio (SPI_Type *ptr)
 Disable SPI directIO control function. More...
 
static uint8_t spi_get_directio_enable_status (SPI_Type *ptr)
 get whether spi directio function is enabled More...
 
static uint8_t spi_get_rx_fifo_valid_data_size (SPI_Type *ptr)
 Get valid data size in receive FIFO. More...
 
static uint8_t spi_get_tx_fifo_valid_data_size (SPI_Type *ptr)
 Get valid data size in transmit FIFO. More...
 
static uint8_t spi_get_rx_fifo_size (SPI_Type *ptr)
 Get SPI RXFIFO size. More...
 
static uint8_t spi_get_tx_fifo_size (SPI_Type *ptr)
 Get SPI TXFIFO size. More...
 
static void spi_slave_enable_data_only (SPI_Type *ptr)
 SPI slave enable only date mode. More...
 
static void spi_slave_disable_data_only (SPI_Type *ptr)
 SPI slave disable only date mode. More...
 
static void spi_master_enable_command_phase (SPI_Type *ptr)
 SPI master enable command phase. More...
 
static void spi_master_disable_command_phase (SPI_Type *ptr)
 SPI master disable command phase. More...
 
static void spi_master_enable_address_phase (SPI_Type *ptr)
 SPI master enable address phase. More...
 
static void spi_master_disable_address_phase (SPI_Type *ptr)
 SPI master disable address phase. More...
 
static void spi_master_set_address_phase_format (SPI_Type *ptr, spi_addr_phase_format_t format)
 SPI master set address phase format. More...
 
static void spi_set_transfer_mode (SPI_Type *ptr, spi_trans_mode_t mode)
 SPI master set transfer mode. More...
 
static void spi_master_enable_token_transfer (SPI_Type *ptr)
 SPI master enable token transfer. More...
 
static void spi_master_disable_token_transfer (SPI_Type *ptr)
 SPI master disable token transfer. More...
 
static void spi_set_write_data_count (SPI_Type *ptr, uint32_t count)
 SPI master set transfer count for write data. More...
 
static void spi_set_read_data_count (SPI_Type *ptr, uint32_t count)
 SPI master set transfer count for read data. More...
 
static void spi_master_set_token_value (SPI_Type *ptr, spi_token_value_t value)
 SPI master set the value of the one-byte special token following the address phase for SPI read transfers. More...
 
static void spi_set_dummy_count (SPI_Type *ptr, spi_dummy_count_t count)
 SPI master set dummy data count. More...
 
static void spi_master_set_cs2sclk_timing (SPI_Type *ptr, spi_cs2sclk_duration_t duration)
 SPI master set the minimum time between the edges of SPI CS and the edges of SCLK. More...
 
static spi_cs2sclk_duration_t spi_master_get_cs2sclk_timing (SPI_Type *ptr)
 SPI master get the minimum time between the edges of SPI CS and the edges of SCLK. More...
 
static void spi_master_set_csht_timing (SPI_Type *ptr, spi_csht_duration_t duration)
 SPI master set the minimum time that SPI CS should stay HIGH. More...
 
static spi_csht_duration_t spi_master_get_csht_timing (SPI_Type *ptr)
 SPI master get the minimum time that SPI CS should stay HIGH. More...
 
static void spi_master_set_sclk_div (SPI_Type *ptr, uint8_t div)
 SPI master set the clock frequency ratio between the clock source and SPI SCLK. More...
 
static uint8_t spi_master_get_sclk_div (SPI_Type *ptr)
 SPI master get the clock frequency ratio between the clock source and SPI SCLK. More...
 
static void spi_slave_set_user_status (SPI_Type *ptr, uint16_t user_status)
 SPI slave set the user defined status flags. More...
 
static void spi_master_set_data_phase_format (SPI_Type *ptr, spi_data_phase_format_t format)
 SPI master set data phase format. More...
 
static spi_data_phase_format_t spi_master_get_data_phase_format (SPI_Type *ptr)
 SPI master get data phase format. More...
 
static void spi_set_shift_direction (SPI_Type *ptr, spi_shift_direction_t shift_direction)
 set spi shift direction More...
 
static spi_shift_direction_t spi_get_shift_direction (SPI_Type *ptr)
 get spi shift direction More...