#include "bsp/spi.h"

/* Private variables ---------------------------------------------------------*/
#define SX1281_SPI_DMA 1
static volatile bool spi_done = false; 
/* -------------- 局部回调 -------------- */
static void txrx_cplt_cb(void) { spi_done = false; }
static void tx_cplt_cb (void) { spi_done = false; }

void SpiInit( void )
{
    BSP_SPI_RegisterCallback(BSP_SPI_SX1281, BSP_SPI_TX_RX_CPLT_CB, txrx_cplt_cb);
    BSP_SPI_RegisterCallback(BSP_SPI_SX1281, BSP_SPI_TX_CPLT_CB,    tx_cplt_cb);
}
static void wait_done(void)
{
    while(BSP_SPI_GetState(BSP_SPI_SX1281) != HAL_SPI_STATE_READY);
}
void SpiInOut( uint8_t *txBuffer, uint8_t *rxBuffer, uint16_t size )
{
    spi_done = true;
    BSP_SPI_TransmitReceive(BSP_SPI_SX1281, txBuffer, rxBuffer, size, SX1281_SPI_DMA); // true = DMA
    wait_done();
}

void SpiIn( uint8_t *txBuffer, uint16_t size )
{
    spi_done = true;
    BSP_SPI_Transmit(BSP_SPI_SX1281, txBuffer, size, SX1281_SPI_DMA);
	
    wait_done();
}


void SpiDeInit( void )
{
    
}

