Files
CHJ/library/inc/lh32m0g3x_spi.h
2026-03-20 21:16:58 +08:00

248 lines
7.8 KiB
C
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/******************************************************************************
* 版权所有:苏州领慧立芯科技有限公司
* Copyright (c) 2020-2025 Suzhou Legendsemi Technology Co., Ltd.
******************************************************************************
* All rights reserved. Distributed under MIT license.
* The file is encoded in UTF-8 without signature.
* @file lh32m0g30x_spi.h
* @version 2025-09-15
******************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __LH32M0G3x_SPI_H
#define __LH32M0G3x_SPI_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "lh32m0xx_lhl.h"
/* Defines -------------------------------------------------------------------*/
/**
* @brief SPI_Private_Defines
*/
#define SPI_CR1_CLEAR_Msk ((uint16_t)0x3040)
/**
* @brief SPI Init structure definition
*/
typedef struct
{
uint16_t Direction; /*!< Specifies the SPI unidirectional or bidirectional data mode.
This parameter can be a value of @ref SPI_data_direction */
uint16_t Mode; /*!< Specifies the SPI operating mode.
This parameter can be a value of @ref SPI_mode */
uint16_t DataSize; /*!< 保留字不要设置2025-09-04
This parameter can be a value of @ref SPI_data_size */
uint16_t CPOL; /*!< Specifies the serial clock steady state.
This parameter can be a value of @ref SPI_Clock_Polarity */
uint16_t CPHA; /*!< Specifies the clock active edge for the bit capture.
This parameter can be a value of @ref SPI_Clock_Phase */
uint16_t NSS; /*!< Specifies whether the NSS signal is managed by
hardware (NSS pin) or by software using the SSI bit.
This parameter can be a value of @ref SPI_Slave_Select_management */
uint16_t BaudRatePrescaler; /*!< Specifies the Baud Rate prescaler value which will be
used to configure the transmit and receive SCK clock.
This parameter can be a value of @ref SPI_BaudRate_Prescaler.
@note The communication clock is derived from the master
clock. The slave clock does not need to be set. */
uint16_t FirstBit; /*!< Specifies whether data transfers start from MSB or LSB bit.
This parameter can be a value of @ref SPI_MSB_LSB_transmission */
uint16_t CRCPolynomial; /*!< Specifies the polynomial used for the CRC calculation. */
} SPI_InitTypeDef;
/**
* @}
*/
/** @defgroup SPI_data_direction
* @{
*/
#define SPI_Direction_2Lines_FullDuplex ((uint16_t)0x0000)
#define SPI_Direction_2Lines_RxOnly ((uint16_t)0x0400)
#define SPI_Direction_1Line_Rx ((uint16_t)0x8000)
#define SPI_Direction_1Line_Tx ((uint16_t)0xC000)
/**
* @}
*/
/** @defgroup SPI_mode
* @{
*/
#define SPI_Mode_Master ((uint16_t)0x0104)
#define SPI_Mode_Slave ((uint16_t)0x0000)
/**
* @}
*/
/** @defgroup SPI_data_size
* @{
*/
#define SPI_DataSize_16b ((uint16_t)0x0800)
#define SPI_DataSize_8b ((uint16_t)0x0000)
/**
* @}
*/
/** @defgroup SPI_Clock_Polarity
* @{
*/
#define SPI_CPOL_Low ((uint16_t)0x0000)
#define SPI_CPOL_High ((uint16_t)0x0002)
/**
* @}
*/
/** @defgroup SPI_Clock_Phase
* @{
*/
#define SPI_CPHA_1Edge ((uint16_t)0x0000)
#define SPI_CPHA_2Edge ((uint16_t)0x0001)
/**
* @}
*/
/** @defgroup SPI_Slave_Select_management
* @{
*/
#define SPI_NSS_Soft ((uint16_t)0x0200)
#define SPI_NSS_Hard ((uint16_t)0x0000)
/**
* @}
*/
/** @defgroup SPI_BaudRate_Prescaler
* @{
*/
#define SPI_BaudRatePrescaler_2 ((uint16_t)0x0000)
#define SPI_BaudRatePrescaler_4 ((uint16_t)0x0008)
#define SPI_BaudRatePrescaler_8 ((uint16_t)0x0010)
#define SPI_BaudRatePrescaler_16 ((uint16_t)0x0018)
#define SPI_BaudRatePrescaler_32 ((uint16_t)0x0020)
#define SPI_BaudRatePrescaler_64 ((uint16_t)0x0028)
#define SPI_BaudRatePrescaler_128 ((uint16_t)0x0030)
#define SPI_BaudRatePrescaler_256 ((uint16_t)0x0038)
/**
* @}
*/
/** @defgroup SPI_MSB_LSB_transmission
* @{
*/
#define SPI_FirstBit_MSB ((uint16_t)0x0000)
#define SPI_FirstBit_LSB ((uint16_t)0x0080)
/**
* @}
*/
/** @defgroup SPI_DMA_transfer_requests
* @{
*/
#define SPI_DMAReq_Tx ((uint16_t)0x0002)
#define SPI_DMAReq_Rx ((uint16_t)0x0001)
/**
* @}
*/
/** @defgroup SPI_NSS_internal_software_management
* @{
*/
#define SPI_NSSInternalSoft_Set ((uint16_t)0x0100)
#define SPI_NSSInternalSoft_Reset ((uint16_t)0xFEFF)
/**
* @}
*/
/** @defgroup SPI_CRC_Transmit_Receive
* @{
*/
#define SPI_CRC_Tx ((uint8_t)0x00)
#define SPI_CRC_Rx ((uint8_t)0x01)
/**
* @}
*/
/** @defgroup SPI_direction_transmit_receive
* @{
*/
#define SPI_Direction_Rx ((uint16_t)0xBFFF)
#define SPI_Direction_Tx ((uint16_t)0x4000)
/**
* @}
*/
/** @defgroup SPI_interrupts_definition
* @{
*/
#define SPI_IT_TXE ((uint8_t)0x71)
#define SPI_IT_RXNE ((uint8_t)0x60)
#define SPI_IT_ERR ((uint8_t)0x50)
#define SPI_IT_OVR ((uint8_t)0x56)
#define SPI_IT_MODF ((uint8_t)0x55)
#define SPI_IT_CRCERR ((uint8_t)0x54)
/**
* @}
*/
/** @defgroup SPI_flags_definition
* @{
*/
#define SPI_FLAG_RXNE ((uint16_t)0x0001)
#define SPI_FLAG_TXE ((uint16_t)0x0002)
#define SPI_FLAG_CRCERR ((uint16_t)0x0010)
#define SPI_FLAG_MODF ((uint16_t)0x0020)
#define SPI_FLAG_OVR ((uint16_t)0x0040)
#define SPI_FLAG_BSY ((uint16_t)0x0080)
/**
* @}
*/
/* Function Prototypes -------------------------------------------------------*/
/** @defgroup SPI_Exported_Functions
* @{
*/
void LHL_SPI_DeInit(SPI_TypeDef* pSPIx);
void LHL_SPI_Init(SPI_TypeDef* pSPIx, SPI_InitTypeDef* SPI_Init);
void LHL_SPI_Cmd(SPI_TypeDef* pSPIx, FunctionalState NewState);
void LHL_SPI_ITConfig(SPI_TypeDef* pSPIx, uint8_t SPI_IT, FunctionalState NewState);
ITStatus LHL_SPI_GetPending(SPI_TypeDef* SPIx, uint8_t SPI_IT);
void LHL_SPI_ClearPending(SPI_TypeDef* SPIx, uint8_t SPI_IT);
void LHL_SPI_SendData(SPI_TypeDef* SPIx, uint16_t Data);
uint16_t LHL_SPI_ReceiveData(SPI_TypeDef* SPIx);
LHL_StatusTypeDef LHL_SPI_Transmit(SPI_TypeDef *pSPIx, const uint8_t* pTxData, uint16_t size, uint32_t Timeout);
LHL_StatusTypeDef LHL_SPI_Receive(SPI_TypeDef *pSPIx, uint8_t* pRxData, uint16_t size, uint32_t Timeout);
LHL_StatusTypeDef LHL_SPI_TransmitReceive(SPI_TypeDef *pSPIx, const uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
FlagStatus LHL_SPI_GetFlag(SPI_TypeDef* pSPIx, uint16_t SPI_FLAG);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif
/*********************************End of File**********************************/