71 lines
2.4 KiB
C
71 lines
2.4 KiB
C
|
/*******************************************************************************
|
|||
|
* @note Copyright (C) 2017 Shanghai Panchip Microelectronics Co., Ltd.
|
|||
|
* All rights reserved.
|
|||
|
*
|
|||
|
* @file drv_spi.c
|
|||
|
* @brief SPI?y?<EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* @history - V1.0, 2017-03-06, xiaoguolin, first implementation.
|
|||
|
*******************************************************************************/
|
|||
|
#include "lib_driver_rfspi_pan159.h"
|
|||
|
|
|||
|
/*******************************************************************************
|
|||
|
* @brief SPI<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
|||
|
* @param[in] <EFBFBD><EFBFBD>
|
|||
|
* @param[out] <EFBFBD><EFBFBD>
|
|||
|
* @return <EFBFBD><EFBFBD>
|
|||
|
******************************************************************************/
|
|||
|
void rfspi_pan159_init(void)
|
|||
|
{
|
|||
|
SYS->P0_MFP |= SYS_MFP_P01_GPIO; // P01->RF_CSN
|
|||
|
SYS->P0_MFP |= SYS_MFP_P07_SPI0_CLK|SYS_MFP_P05_SPI0_MOSI|SYS_MFP_P06_SPI0_MISO ;
|
|||
|
SYS->P5_MFP |= SYS_MFP_P52_GPIO; //P20->RF_IRQ
|
|||
|
|
|||
|
CLK_EnableModuleClock(SPI0_MODULE);//ʹ<><CAB9>SPIʱ<49><CAB1>
|
|||
|
CLK_SetModuleClock(SPI0_MODULE,CLK_CLKSEL1_SPISEL_HCLK,1);//ʱ<><CAB1>1<EFBFBD><31>Ƶ
|
|||
|
|
|||
|
GPIO_SetMode(P0, BIT1, GPIO_MODE_OUTPUT); //RF_CSN
|
|||
|
GPIO_SetMode(P5, BIT2, GPIO_MODE_INPUT); //RF_IRQ
|
|||
|
|
|||
|
SYS->P0_MFP |= SYS_MFP_P05_SPI0_MOSI | SYS_MFP_P06_SPI0_MISO | SYS_MFP_P07_SPI0_CLK;//<2F><><EFBFBD><EFBFBD>IO<49><4F><EFBFBD>ù<EFBFBD><C3B9><EFBFBD>
|
|||
|
SPI_Open(SPI0, SPI_MASTER, SPI_MODE_0,8,2000000);//<2F><><EFBFBD>豸<EFBFBD><E8B1B8>ģʽ0,8λ<38><CEBB><EFBFBD>ȣ<EFBFBD>2M<32><4D><EFBFBD><EFBFBD>
|
|||
|
SPI_DisableAutoSS(SPI0);//<2F><>ֹӲ<D6B9><D3B2>SS<53><53>
|
|||
|
SPI_WRITE_TX(SPI0, 0);//<2F><><EFBFBD><EFBFBD>SPI<50><49><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
/*******************************************************************************
|
|||
|
* @brief SPI<EFBFBD>ֽڶ<EFBFBD>д
|
|||
|
* @param[in] dat - <EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @param[out] <EFBFBD><EFBFBD>
|
|||
|
* @return <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
|||
|
******************************************************************************/
|
|||
|
uint8_t rfspi_pan159_rwc(uint8_t dat)
|
|||
|
{
|
|||
|
SPI_WRITE_TX(SPI0, dat);
|
|||
|
SPI_TRIGGER(SPI0);
|
|||
|
while(SPI_IS_BUSY(SPI0));
|
|||
|
return SPI0->RX;
|
|||
|
}
|
|||
|
|
|||
|
/*******************************************************************************
|
|||
|
* @brief SPI<EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
|
|||
|
* @param[in] p_dat - <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
|
|||
|
* len - <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @param[out] <EFBFBD><EFBFBD>
|
|||
|
* @return <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ飬<EFBFBD><EFBFBD>p_dat<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @history - V1.0, 2017-03-06, xiaoguolin, first implementation.
|
|||
|
******************************************************************************/
|
|||
|
uint8_t* rfspi_pan159_rws(uint8_t* p_dat, uint16_t len)
|
|||
|
{
|
|||
|
uint8_t i = 0;
|
|||
|
while(i < len)
|
|||
|
{
|
|||
|
SPI_WRITE_TX(SPI0, p_dat[i]);
|
|||
|
SPI_TRIGGER(SPI0);
|
|||
|
while(SPI_IS_BUSY(SPI0));
|
|||
|
p_dat[i] = SPI0->RX;
|
|||
|
i++;
|
|||
|
}
|
|||
|
return p_dat;
|
|||
|
}
|