RUI3 (RAK Unified Interface 3) - RAK4631
udrv_spimst.h File Reference

Provide a hardware independent SPI master driver layer for API layer to use. More...

Go to the source code of this file.

Data Structures

struct  udrv_spimst_api
 

Enumerations

enum  udrv_spimst_port {
  UDRV_SPIMST_0 = 0x0,
  UDRV_SPIMST_1 = 0x1,
  UDRV_SPIMST_2 = 0x2,
  UDRV_SPIMST_3 = 0x3,
  UDRV_SPIMST_MAX = 0x4
}
 
enum  ENUM_SPI_MST_CPHA_T {
  SPI_MST_CPHA_0 = 0,
  SPI_MST_CPHA_1 = 1
}
 
enum  ENUM_SPI_MST_CPOL_T {
  SPI_MST_CPOL_0 = 0,
  SPI_MST_CPOL_1 = 1
}
 

Functions

void udrv_spimst_init (udrv_spimst_port port)
 
void udrv_spimst_setup_mode (udrv_spimst_port port, ENUM_SPI_MST_CPHA_T CPHA, ENUM_SPI_MST_CPOL_T CPOL)
 
void udrv_spimst_setup_freq (udrv_spimst_port port, uint32_t clk_Hz)
 
void udrv_spimst_setup_byte_order (udrv_spimst_port port, bool msb_first)
 
void udrv_spimst_deinit (udrv_spimst_port port)
 
int8_t udrv_spimst_trx (udrv_spimst_port port, uint8_t *write_data, uint32_t write_length, uint8_t *read_data, uint32_t read_length, uint32_t csn)
 
void udrv_spimst_suspend ()
 Suspend SPI master hardware before entering sleep mode. More...
 
void udrv_spimst_resume ()
 Resume SPI master hardware after leaving sleep mode. More...
 

Detailed Description

Provide a hardware independent SPI master driver layer for API layer to use.

Author
Rakwireless
Version
0.0.0
Date
2021.2

Enumeration Type Documentation

◆ udrv_spimst_port

Enumerator
UDRV_SPIMST_0 
UDRV_SPIMST_1 
UDRV_SPIMST_2 
UDRV_SPIMST_3 
UDRV_SPIMST_MAX 

◆ ENUM_SPI_MST_CPHA_T

Enumerator
SPI_MST_CPHA_0 
SPI_MST_CPHA_1 

◆ ENUM_SPI_MST_CPOL_T

Enumerator
SPI_MST_CPOL_0 
SPI_MST_CPOL_1 

Function Documentation

◆ udrv_spimst_init()

void udrv_spimst_init ( udrv_spimst_port  port)

Initilize SPI bus to enable SPI operations.

Parameters
portthe specified serial port

◆ udrv_spimst_setup_mode()

void udrv_spimst_setup_mode ( udrv_spimst_port  port,
ENUM_SPI_MST_CPHA_T  CPHA,
ENUM_SPI_MST_CPOL_T  CPOL 
)

Setup SPI mode.

Parameters
portthe specified serial port
CPHASerial Clock Phase. 0x00 - Serial clock toggles in middle of first data bit 0x01 - Serial clock toggles at start of first data bit
CPOLSerial Clock Polarity. 0x00 - Inactive state of serial clock is low 0x01 - Inactive state of serial clock is high, need pull up in the clock pin.

◆ udrv_spimst_setup_freq()

void udrv_spimst_setup_freq ( udrv_spimst_port  port,
uint32_t  clk_Hz 
)

Setup SPI frequency.

Parameters
portthe specified serial port
clk_HzSPI Clock (BUS 40MHz : 610 - 20M, BUS 80MHz : 1221 - 40MHzM)

◆ udrv_spimst_setup_byte_order()

void udrv_spimst_setup_byte_order ( udrv_spimst_port  port,
bool  msb_first 
)

Setup SPI bit order.

Parameters
portthe specified serial port
msb_first(true : most significant byte first, false : least significatn byte first)

◆ udrv_spimst_deinit()

void udrv_spimst_deinit ( udrv_spimst_port  port)

Deinitialize SPI bus to disable SPI operations

Parameters
portthe specified serial port

◆ udrv_spimst_trx()

int8_t udrv_spimst_trx ( udrv_spimst_port  port,
uint8_t *  write_data,
uint32_t  write_length,
uint8_t *  read_data,
uint32_t  read_length,
uint32_t  csn 
)

Transmit and receive the spi data.

Parameters
portthe specified serial port
write_dataPointer to the data buffer to be written by the master.
write_lengthSize of the write data buffer exposed to the SPI master.
read_dataPointer to the data buffer to be read by the master.
read_lengthSize of the read data buffer exposed to the SPI master.
csnChip select pin.
Returns
-1 The operation error.
0 The operation completed successfully.

◆ udrv_spimst_suspend()

void udrv_spimst_suspend ( )

Suspend SPI master hardware before entering sleep mode.

◆ udrv_spimst_resume()

void udrv_spimst_resume ( )

Resume SPI master hardware after leaving sleep mode.