
#ifndef __MYRADIO_GPIO_H_
#define __MYRADIO_GPIO_H_

#include <stdint.h>

#include "stm32f10x.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_spi.h"
#include "board.h"

#ifndef SPI_HARD
#define SPI_HARD
#endif
typedef void (*RADIO_GPIO_CALLBACK)(uint8_t index);

//-------------射频模块引脚映射到转接板排针---------------
//IO1用于射频中断响应
#define RF_24x1_IRQ_PIN           BOARD_PIN_SPI_GPIOC  //
#define RF_24x1_IRQ_PORT          BOARD_PORT_SPI_GPIOC
#define RF_24x1_IRQ               RF_24x1_IRQ_PORT, RF_24x1_IRQ_PIN          //
//
#define RF_24x1_CE_PIN           BOARD_PIN_SPI_GPIOA  //
#define RF_24x1_CE_PORT          BOARD_PORT_SPI_GPIOA
#define RF_24x1_CE               RF_24x1_CE_PORT, RF_24x1_CE_PIN          //

//外部PA和LNA控制脚
#define RF_EXTPA_RE_PIN      BOARD_PIN_SPI_GPIOG  //
#define RF_EXTPA_RE_PORT     BOARD_PORT_SPI_GPIOG
#define RF_EXTPA_RE          RF_EXTPA_RE_PORT, RF_EXTPA_RE_PIN          //
#define RF_EXTPA_TE_PIN      BOARD_PIN_SPI_GPIOF  //
#define RF_EXTPA_TE_PORT     BOARD_PORT_SPI_GPIOF
#define RF_EXTPA_TE          RF_EXTPA_TE_PORT, RF_EXTPA_TE_PIN          //
//-------------射频模块引脚映射到转接板排针---------------END

uint8_t READ_24x1_IRQ_IRQ(void);
void RF_24x1_CE_H(void);
void RF_24x1_CE_L(void);

void RF_EXT_PA_RE_H(void);
void RF_EXT_PA_RE_L(void);
void RF_EXT_PA_TE_H(void);
void RF_EXT_PA_TE_L(void);

#define RF_EXT_PA_TO_TX() RF_EXT_PA_TE_H();RF_EXT_PA_RE_L()
#define RF_EXT_PA_TO_RX() RF_EXT_PA_TE_L();RF_EXT_PA_RE_H()
#define RF_EXT_PA_TO_IDLE() RF_EXT_PA_TE_L();RF_EXT_PA_RE_L()

void BOARD_SPI_NSS_H(void);
void BOARD_SPI_NSS_L(void);

//-------------将封装的API映射到射频模块硬件层---------------
void myRadio_gpio_init(RADIO_GPIO_CALLBACK cb);
uint8_t myRadioSpi_rwByte(uint8_t byteToWrite);
void myRadioSpi_wBuffer(uint8_t* pData, uint8_t len);
void myRadioSpi_rBuffer(uint8_t* pData, uint8_t len);

#define SpiReadWrite(p) myRadioSpi_rwByte(p)
#define SpiWriteData(p1, p2) myRadioSpi_wBuffer(p1, p2)
#define SpiReadData(p1, p2) myRadioSpi_rBuffer(p1, p2)
#define RF_SPI_NSS_H() BOARD_SPI_NSS_H()
#define RF_SPI_NSS_L() BOARD_SPI_NSS_L()
#define RF_NRF_CE_H() RF_24x1_CE_H()
#define RF_NRF_CE_L() RF_24x1_CE_L()
//-------------将封装的API映射到射频模块硬件层---------------END
#endif
