HT32SX Monarch Scan
Monarch Scan application for HT32SX
spi.c File Reference

: This file provides code for the configuration of the SPI instances. More...

#include "spi.h"

Macros

#define HEADER_WRITE_MASK   0x00
 
#define HEADER_READ_MASK   0x01
 
#define HEADER_ADDRESS_MASK   0x00
 
#define HEADER_COMMAND_MASK   0x80
 
#define LINEAR_FIFO_ADDRESS   0xFF
 
#define BUILT_HEADER(add_comm, w_r)   (add_comm | w_r)
 
#define WRITE_HEADER   BUILT_HEADER(HEADER_ADDRESS_MASK, HEADER_WRITE_MASK)
 
#define READ_HEADER   BUILT_HEADER(HEADER_ADDRESS_MASK, HEADER_READ_MASK)
 
#define COMMAND_HEADER   BUILT_HEADER(HEADER_COMMAND_MASK, HEADER_WRITE_MASK)
 
#define SPI_ENTER_CRITICAL()   __disable_irq()
 
#define SPI_EXIT_CRITICAL()   __enable_irq()
 
#define SdkEvalSPICSLow()   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET)
 
#define SdkEvalSPICSHigh()   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET)
 
#define WAIT_FOR_SPI_TC()
 

Functions

void MX_SPI1_Init (void)
 
void HAL_SPI_MspInit (SPI_HandleTypeDef *spiHandle)
 
void HAL_SPI_MspDeInit (SPI_HandleTypeDef *spiHandle)
 
uint16_t S2LPSpiReadRegisters (uint8_t address, uint8_t n_bytes, uint8_t *buffer)
 SPI function to read registers from a slave device. More...
 
uint16_t S2LPSpiWriteRegisters (uint8_t address, uint8_t n_bytes, uint8_t *buffer)
 SPI function to write registers of a slave device. More...
 
uint16_t S2LPSpiCommandStrobes (uint8_t command)
 
uint16_t S2LPSpiReadFifo (uint8_t n_bytes, uint8_t *buffer)
 
uint16_t S2LPSpiWriteFifo (uint8_t n_bytes, uint8_t *buffer)
 
__weak void SdkEvalSpiRawTC (void)
 
void S2LPSpiRaw (uint8_t n_bytes, uint8_t *in_buffer, uint8_t *out_buffer, uint8_t can_return_bef_tx)
 
void HAL_SPI_TxRxCpltCallback (SPI_HandleTypeDef *hspi)
 
void ST_MCU_API_SpiRaw (uint8_t n_bytes, uint8_t *in_buffer, uint8_t *out_buffer, uint8_t can_return_bef_tx)
 
void S2LPSetSpiInUse (uint8_t state)
 Set the S2LP in use flag. More...
 
uint8_t S2LPGetSpiInUse (void)
 Get the S2LP in use flag. More...
 

Variables

SPI_HandleTypeDef hspi1
 
DMA_HandleTypeDef hdma_spi1_tx
 
DMA_HandleTypeDef hdma_spi1_rx
 

Detailed Description

: This file provides code for the configuration of the SPI instances.

Attention

© Copyright (c) 2019 STMicroelectronics. All rights reserved.

This software component is licensed by ST under BSD 3-Clause license, the "License"; You may not use this file except in compliance with the License. You may obtain a copy of the License at: opensource.org/licenses/BSD-3-Clause

Macro Definition Documentation

◆ BUILT_HEADER

#define BUILT_HEADER (   add_comm,
  w_r 
)    (add_comm | w_r)

macro to build the header byte

◆ COMMAND_HEADER

#define COMMAND_HEADER   BUILT_HEADER(HEADER_COMMAND_MASK, HEADER_WRITE_MASK)

macro to build the command header byte

◆ HEADER_ADDRESS_MASK

#define HEADER_ADDRESS_MASK   0x00

Address mask for header byte

◆ HEADER_COMMAND_MASK

#define HEADER_COMMAND_MASK   0x80

Command mask for header byte

◆ HEADER_READ_MASK

#define HEADER_READ_MASK   0x01

Read mask for header byte

◆ HEADER_WRITE_MASK

#define HEADER_WRITE_MASK   0x00

Write mask for header byte

◆ LINEAR_FIFO_ADDRESS

#define LINEAR_FIFO_ADDRESS   0xFF

Linear FIFO address

◆ READ_HEADER

macro to build the read header byte

◆ WAIT_FOR_SPI_TC

#define WAIT_FOR_SPI_TC ( )
Value:
{while(!__HAL_DMA_GET_FLAG(hspi1.hdmarx, __HAL_DMA_GET_TC_FLAG_INDEX(hspi1.hdmarx)));\
do{HAL_DMA_IRQHandler(hspi1.hdmarx);\
HAL_DMA_IRQHandler(hspi1.hdmatx);\
}while(HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY);}

◆ WRITE_HEADER

#define WRITE_HEADER   BUILT_HEADER(HEADER_ADDRESS_MASK, HEADER_WRITE_MASK)

macro to build the write header byte

Function Documentation

◆ HAL_SPI_MspDeInit()

void HAL_SPI_MspDeInit ( SPI_HandleTypeDef *  spiHandle)

SPI1 GPIO Configuration
PB4 ---—> SPI1_MISO PB3 ---—> SPI1_SCK PA7 ---—> SPI1_MOSI

◆ HAL_SPI_MspInit()

void HAL_SPI_MspInit ( SPI_HandleTypeDef *  spiHandle)

SPI1 GPIO Configuration
PB4 ---—> SPI1_MISO PB3 ---—> SPI1_SCK PA7 ---—> SPI1_MOSI

◆ S2LPGetSpiInUse()

uint8_t S2LPGetSpiInUse ( void  )

Get the S2LP in use flag.


Parameters
[in]none
[out]none
Return values
spi_in_use1 if in use, else 0

◆ S2LPSetSpiInUse()

void S2LPSetSpiInUse ( uint8_t  state)

Set the S2LP in use flag.


Parameters
[in]state1 if in use, else 0
[out]none
Return values
none

◆ S2LPSpiReadRegisters()

uint16_t S2LPSpiReadRegisters ( uint8_t  RegisterAddr,
uint8_t  NumByteToRead,
uint8_t *  pBuffer 
)

SPI function to read registers from a slave device.

Parameters
RegisterAddrregister address
NumByteToReadnumber of byte to read
pBufferbuffer to retrieve data from a slave
Return values
ErrorStatuserror status ErrorStatus This parameter can be: SUCCESS or ERROR.

◆ S2LPSpiWriteRegisters()

uint16_t S2LPSpiWriteRegisters ( uint8_t  address,
uint8_t  n_bytes,
uint8_t *  buffer 
)

SPI function to write registers of a slave device.

Parameters
RegisterAddrregister address
NumByteToReadnumber of byte to write
pBufferbuffer contains data to write
Return values
ErrorStatuserror status ErrorStatus This parameter can be: SUCCESS or ERROR.