2022-03-26 20:51:40 +08:00

208 lines
4.9 KiB
C
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.

/********************************** (C) COPYRIGHT *******************************
* File Name : CH57x_SPI.h
* Author : WCH
* Version : V1.2
* Date : 2021/11/17
* Description
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/
#ifndef __CH58x_SPI_H__
#define __CH58x_SPI_H__
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief SPI0 interrupt bit define
*/
#define SPI0_IT_FST_BYTE RB_SPI_IE_FST_BYTE // <20>ӻ<EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>ģʽ<C4A3>£<EFBFBD><C2A3><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD>ж<EFBFBD>
#define SPI0_IT_FIFO_OV RB_SPI_IE_FIFO_OV // FIFO <20><><EFBFBD><EFBFBD>
#define SPI0_IT_DMA_END RB_SPI_IE_DMA_END // DMA <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define SPI0_IT_FIFO_HF RB_SPI_IE_FIFO_HF // FIFO ʹ<>ù<EFBFBD><C3B9><EFBFBD>
#define SPI0_IT_BYTE_END RB_SPI_IE_BYTE_END // <20><><EFBFBD>ֽڴ<D6BD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define SPI0_IT_CNT_END RB_SPI_IE_CNT_END // ȫ<><C8AB><EFBFBD>ֽڴ<D6BD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/**
* @brief Configuration data mode
*/
typedef enum
{
Mode0_LowBitINFront = 0, // ģʽ0<CABD><30><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>ǰ
Mode0_HighBitINFront, // ģʽ0<CABD><30><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>ǰ
Mode3_LowBitINFront, // ģʽ3<CABD><33><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>ǰ
Mode3_HighBitINFront, // ģʽ3<CABD><33><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>ǰ
} ModeBitOrderTypeDef;
/**
* @brief Configuration SPI0 slave mode
*/
typedef enum
{
Mode_DataStream = 0, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
Mose_FirstCmd, // <20><><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>ģʽ
} Slave_ModeTypeDef;
/**
* @brief <20><><EFBFBD><EFBFBD>ģʽĬ<CABD>ϳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ģʽ0+3<><33>ȫ˫<C8AB><CBAB>+8MHz
*/
void SPI0_MasterDefInit(void);
/**
* @brief SPI0 <20><>׼ʱ<D7BC><CAB1><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>= d*Tsys
*
* @param c - ʱ<>ӷ<EFBFBD>Ƶϵ<C6B5><CFB5>
*/
void SPI0_CLKCfg(uint8_t c);
/**
* @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
*
* @param m - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ refer to ModeBitOrderTypeDef
*/
void SPI0_DataMode(ModeBitOrderTypeDef m);
/**
* @brief <20><><EFBFBD>͵<EFBFBD><CDB5>ֽ<EFBFBD> (buffer)
*
* @param d - <20><><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
*/
void SPI0_MasterSendByte(uint8_t d);
/**
* @brief <20><><EFBFBD>յ<EFBFBD><D5B5>ֽ<EFBFBD> (buffer)
*
* @param none
*/
uint8_t SPI0_MasterRecvByte(void);
/**
* @brief ʹ<><CAB9>FIFO<46><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6>ֽ<EFBFBD>
*
* @param pbuf - <20><><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>׵<EFBFBD>ַ
* @param len - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3>ȣ<EFBFBD><C8A3><EFBFBD><EFBFBD><EFBFBD>4095
*/
void SPI0_MasterTrans(uint8_t *pbuf, uint16_t len);
/**
* @brief ʹ<><CAB9>FIFO<46><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ն<EFBFBD><D5B6>ֽ<EFBFBD>
*
* @param pbuf - <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>׵<EFBFBD>ַ
* @param len - <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3>ȣ<EFBFBD><C8A3><EFBFBD><EFBFBD><EFBFBD>4095
*/
void SPI0_MasterRecv(uint8_t *pbuf, uint16_t len);
/**
* @brief DMA<4D><41>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param pbuf - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ,<2C><>Ҫ<EFBFBD><D2AA><EFBFBD>ֽڶ<D6BD><DAB6><EFBFBD>
* @param len - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
*/
void SPI0_MasterDMATrans(uint8_t *pbuf, uint16_t len);
/**
* @brief DMA<4D><41>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param pbuf - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ,<2C><>Ҫ<EFBFBD><D2AA><EFBFBD>ֽڶ<D6BD><DAB6><EFBFBD>
* @param len - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
*/
void SPI0_MasterDMARecv(uint8_t *pbuf, uint16_t len);
void SPI1_MasterDefInit(void); /* <20><><EFBFBD><EFBFBD>ģʽĬ<CABD>ϳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ģʽ0+3<><33>ȫ˫<C8AB><CBAB>+8MHz */
void SPI1_CLKCfg(UINT8 c); /* SPI1 <20><>׼ʱ<D7BC><CAB1><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>= d*Tsys */
void SPI1_DataMode(ModeBitOrderTypeDef m); /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ */
void SPI1_MasterSendByte(UINT8 d); /* <20><><EFBFBD>͵<EFBFBD><CDB5>ֽ<EFBFBD> (buffer) */
UINT8 SPI1_MasterRecvByte(void); /* <20><><EFBFBD>յ<EFBFBD><D5B5>ֽ<EFBFBD> (buffer) */
void SPI1_MasterTrans(UINT8 *pbuf, UINT16 len); /* ʹ<><CAB9>FIFO<46><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6>ֽ<EFBFBD> */
void SPI1_MasterRecv(UINT8 *pbuf, UINT16 len); /* ʹ<><CAB9>FIFO<46><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ն<EFBFBD><D5B6>ֽ<EFBFBD> */
/**
* @brief <20>豸ģʽĬ<CABD>ϳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>MISO<53><4F>GPIO<49><4F>ӦΪ<D3A6><CEAA><EFBFBD><EFBFBD>ģʽ
*/
void SPI0_SlaveInit(void);
/**
* @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param d - <20><><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
#define SetFirstData(d) (R8_SPI0_SLAVE_PRE = d)
/**
* @brief <20>ӻ<EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
*
* @param d - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
void SPI0_SlaveSendByte(uint8_t d);
/**
* @brief <20>ӻ<EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
*
* @return <20><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>
*/
uint8_t SPI0_SlaveRecvByte(void);
/**
* @brief <20>ӻ<EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
*
* @param pbuf - <20><><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>׵<EFBFBD>ַ
* @param len - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3>ȣ<EFBFBD><C8A3><EFBFBD><EFBFBD><EFBFBD>4095
*/
void SPI0_SlaveTrans(uint8_t *pbuf, uint16_t len);
/**
* @brief <20>ӻ<EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD>ն<EFBFBD><D5B6>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
*
* @param pbuf - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ
* @param len - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
*/
void SPI0_SlaveRecv(uint8_t *pbuf, uint16_t len);
/**
* @brief DMA<4D><41>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param pbuf - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ,<2C><>Ҫ<EFBFBD><D2AA><EFBFBD>ֽڶ<D6BD><DAB6><EFBFBD>
* @param len - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
*/
void SPI0_SlaveDMATrans(uint8_t *pbuf, uint16_t len);
/**
* @brief DMA<4D><41>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @param pbuf - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ,<2C><>Ҫ<EFBFBD><D2AA><EFBFBD>ֽڶ<D6BD><DAB6><EFBFBD>
* @param len - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
*/
void SPI0_SlaveDMARecv(uint8_t *pbuf, uint16_t len);
/**
* @brief <20><><EFBFBD><EFBFBD>SPI0<49>ж<EFBFBD>
*
* @param s - ʹ<><CAB9>/<2F>ر<EFBFBD>
* @param f - refer to SPI0 interrupt bit define
*/
#define SPI0_ITCfg(s, f) ((s) ? (R8_SPI0_INTER_EN |= f) : (R8_SPI0_INTER_EN &= ~f))
/**
* @brief <20><>ȡ<EFBFBD>жϱ<D0B6>־״̬<D7B4><CCAC>0-δ<><CEB4>λ<EFBFBD><CEBB>(!0)-<2D><><EFBFBD><EFBFBD>
*
* @param f - refer to SPI0 interrupt bit define
*/
#define SPI0_GetITFlag(f) (R8_SPI0_INT_FLAG & f)
/**
* @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>жϱ<D0B6>־
*
* @param f - refer to SPI0 interrupt bit define
*/
#define SPI0_ClearITFlag(f) (R8_SPI0_INT_FLAG = f)
#ifdef __cplusplus
}
#endif
#endif // __CH58x_SPI_H__