generated from Embedded_Projects/LPCXpresso55S69_Template
55 lines
1.4 KiB
C
55 lines
1.4 KiB
C
/* Board */
|
|
#include "pin_mux.h"
|
|
|
|
/* SDK drivers */
|
|
#include "fsl_spi.h"
|
|
|
|
/* Private */
|
|
#include "afe_impl.h"
|
|
|
|
#define AFE_SPI_BASE SPI8
|
|
#define AFE_SPI_CS kSPI_Ssel1
|
|
#define AFE_SPI_ID 8
|
|
#define AFE_SPI_FREQ 4000000UL
|
|
|
|
afe44x0_ret_t afe_impl_init(void) {
|
|
spi_master_config_t afe_spi_config = {
|
|
.enableMaster = true,
|
|
.polarity = kSPI_ClockPolarityActiveHigh,
|
|
.phase = kSPI_ClockPhaseFirstEdge,
|
|
.direction = kSPI_MsbFirst,
|
|
.baudRate_Bps = AFE_SPI_FREQ,
|
|
.dataWidth = kSPI_Data8Bits,
|
|
.sselNum = AFE_SPI_CS,
|
|
.sselPol = kSPI_SpolActiveAllLow,
|
|
.txWatermark = kSPI_TxFifo0,
|
|
.rxWatermark = kSPI_RxFifo1,
|
|
.delayConfig =
|
|
{
|
|
.frameDelay = 0U,
|
|
.preDelay = 0U,
|
|
.transferDelay = 0U,
|
|
.postDelay = 0U,
|
|
},
|
|
};
|
|
|
|
if (SPI_MasterInit(AFE_SPI_BASE, &afe_spi_config, CLOCK_GetFlexCommClkFreq(AFE_SPI_ID)) != kStatus_Success) {
|
|
return AFE44_RET_FAIL;
|
|
}
|
|
|
|
return AFE44_RET_SUCCESS;
|
|
}
|
|
|
|
afe44x0_ret_t afe_impl_transfer(void *handle, uint8_t *tx_data, uint8_t *rx_data, uint16_t len) {
|
|
spi_transfer_t xfer = {
|
|
.txData = tx_data,
|
|
.rxData = rx_data,
|
|
.dataSize = len,
|
|
};
|
|
|
|
if (SPI_MasterTransferBlocking(AFE_SPI_BASE, &xfer) != kStatus_Success) {
|
|
return AFE44_RET_FAIL;
|
|
}
|
|
|
|
return AFE44_RET_SUCCESS;
|
|
} |