GigaDevice_test/rf_switch_driver.c

66 lines
1.7 KiB
C

#include "rf_switch_driver.h"
#include "gd32f10x_gpio.h"
/**! \func void vRFSwitchInit(struct rf_switch_config *config)
* \brief Initialize RF Switch
*/
void vRFSwitchInit(struct rf_switch_config *config, uint32_t portA, uint32_t pinA, uint32_t portB, uint32_t pinB, uint32_t portC, uint32_t pinC)
{
config->enable = 0;
config->rfOutState = RF_OUT_01;
config->portA = portA;
config->portB = portB;
config->portC = portC;
config->pinA = pinA;
config->pinB = pinB;
config->pinC = pinC;
vSwitchRFOut(config, config->rfOutState);
}
/**! \func void vRFSwitchEnable(struct rf_switch_config *config)
* \brief Enable RF Switch
*/
void vRFSwitchEnable(struct rf_switch_config *config)
{
config->enable = 1;
}
/**! \func void vRFSwitchDisable(struct rf_switch_config *config)
* \brief Disable RF Switch
*/
void vRFSwitchDisable(struct rf_switch_config *config)
{
config->enable = 0;
}
/**! \func void vSwitchRFOut(struct rf_switch_config *config, RF_OUT_ENUM state)
* \brief Switch between RF out state
*/
void vSwitchRFOut(struct rf_switch_config *config, RF_OUT_ENUM state)
{
config->rfOutState = state;
if (state & 0x01)
gpio_bit_set(config->portA, config->pinA);
else
gpio_bit_reset(config->portA, config->pinA);
if (state & 0x02)
gpio_bit_set(config->portB, config->pinB);
else
gpio_bit_reset(config->portB, config->pinB);
if (state & 0x04)
gpio_bit_set(config->portC, config->pinC);
else
gpio_bit_reset(config->portC, config->pinC);
}
/**! \func RF_OUT_ENUM xGetRFSwitchState(struct rf_switch_config *config)
* \brief Get RF Switch State
*/
RF_OUT_ENUM xGetRFSwitchState(struct rf_switch_config *config)
{
return config->rfOutState;
}