EFM32 Gecko Software Documentation  efm32g-doc-5.1.2
ezradio_hal.c
Go to the documentation of this file.
1 /**************************************************************************/
33 #include <stdlib.h>
34 #include <stdint.h>
35 
36 #include "em_gpio.h"
37 #include "em_prs.h"
38 
39 #include "spidrv.h"
40 #include "gpiointerrupt.h"
41 
42 #include "ezradiodrv_config.h"
43 #include "ezradio_hal.h"
44 
46 
47 static SPIDRV_HandleData_t ezradioSpiHandle;
48 static SPIDRV_Handle_t ezradioSpiHandlePtr = &ezradioSpiHandle;
49 
50 #if defined(_EZR32_HAPPY_FAMILY)
51 static SPIDRV_Init_t ezradioSpiInitData = SPIDRV_MASTER_USARTRF1;
52 #elif (defined(_EZR32_LEOPARD_FAMILY) || defined(_EZR32_WONDER_FAMILY))
53 static SPIDRV_Init_t ezradioSpiInitData = SPIDRV_MASTER_USARTRF0;
54 #else
55 static SPIDRV_Init_t ezradioSpiInitData = SPIDRV_MASTER_USART1;
56 #endif
57 
59 
66 void ezradio_hal_GpioInit( GPIOINT_IrqCallbackPtr_t ezradioIrqCallback, bool enablePTI )
67 {
68 #if defined(_EZR32_HAPPY_FAMILY)
69  (void)enablePTI;
70 #endif
71 
72 #if !defined(EZRADIODRV_SPI_4WIRE_MODE)
73  GPIO_PinModeSet( (GPIO_Port_TypeDef) RF_USARTRF_CS_PORT, RF_USARTRF_CS_PIN, gpioModePushPull, 1 );
74 #endif
75 
76  /* Setup enable and interrupt pins to radio */
77  GPIO_PinModeSet( (GPIO_Port_TypeDef) RF_SDN_PORT, RF_SDN_PIN, gpioModePushPull, 0 );
78  GPIO_PinModeSet( (GPIO_Port_TypeDef) RF_INT_PORT, RF_INT_PIN, gpioModeInputPull, 1 );
79 
80  /* EZR32HG family uses hard wired PTI interface from the radio to the board controller */
81 #if ( !defined(_EZR32_HAPPY_FAMILY) && !defined(EZRADIODRV_DISABLE_PTI) )
82  if (enablePTI)
83  {
84  /* Setup PRS for PTI pins */
86 
87  /* Configure RF_GPIO0 and RF_GPIO1 to inputs. */
88  GPIO_PinModeSet((GPIO_Port_TypeDef)RF_GPIO0_PORT, RF_GPIO0_PIN, gpioModeInput, 0);
89  GPIO_PinModeSet((GPIO_Port_TypeDef)RF_GPIO1_PORT, RF_GPIO1_PIN, gpioModeInput, 0);
90 
91  /* Pin PA0 and PA1 output the GPIO0 and GPIO1 via PRS to PTI */
92  GPIO_PinModeSet(gpioPortA, 0, gpioModePushPull, 0);
93  GPIO_PinModeSet(gpioPortA, 1, gpioModePushPull, 0);
94 
95  /* Disable INT for PRS channels */
96  GPIO_IntConfig((GPIO_Port_TypeDef)RF_GPIO0_PORT, RF_GPIO0_PIN, false, false, false);
97  GPIO_IntConfig((GPIO_Port_TypeDef)RF_GPIO1_PORT, RF_GPIO1_PIN, false, false, false);
98 
99  /* Setup PRS for RF GPIO pins */
100  PRS_SourceAsyncSignalSet(0, PRS_CH_CTRL_SOURCESEL_GPIOH, PRS_CH_CTRL_SIGSEL_GPIOPIN15);
101  PRS_SourceAsyncSignalSet(1, PRS_CH_CTRL_SOURCESEL_GPIOH, PRS_CH_CTRL_SIGSEL_GPIOPIN14);
102  PRS->ROUTE = (PRS_ROUTE_CH0PEN | PRS_ROUTE_CH1PEN);
103 
104  /* Make sure PRS sensing is enabled (should be by default) */
106  }
107 #endif //#if !defined(_EZR32_HAPPY_FAMILY)
108 
109 #if defined(EZRADIODRV_DISABLE_PTI) && defined(EZRADIODRV_COMM_USE_GPIO1_FOR_CTS)
110  //Enable GPIO1 for CTS input
111  GPIO_PinModeSet((GPIO_Port_TypeDef)RF_GPIO1_PORT, RF_GPIO1_PIN, gpioModeInput, 0);
112 #endif
113 
114  if (NULL != ezradioIrqCallback)
115  {
116  /* Register callback and enable interrupt */
117  GPIOINT_CallbackRegister( RF_INT_PIN, ezradioIrqCallback );
118  GPIO_IntConfig( (GPIO_Port_TypeDef) RF_INT_PORT, RF_INT_PIN, false, true, true );
119  }
120 
121 }
122 
127 {
128  ezradioSpiInitData.bitRate = 8E6;
129 
130 #if !defined(EZRADIODRV_SPI_4WIRE_MODE)
131  ezradioSpiInitData.csControl = spidrvCsControlApplication;
132 #endif
133 
134  SPIDRV_Init( ezradioSpiHandlePtr, &ezradioSpiInitData );
135 
136 }
137 
142 {
143  GPIO_PinOutSet( (GPIO_Port_TypeDef) RF_SDN_PORT, RF_SDN_PIN);
144 }
145 
150 {
151  GPIO_PinOutClear( (GPIO_Port_TypeDef) RF_SDN_PORT, RF_SDN_PIN);
152 }
153 
158 {
159  GPIO_PinOutClear( (GPIO_Port_TypeDef) RF_USARTRF_CS_PORT, RF_USARTRF_CS_PIN);
160 }
161 
166 {
167  GPIO_PinOutSet( (GPIO_Port_TypeDef) RF_USARTRF_CS_PORT, RF_USARTRF_CS_PIN);
168 }
169 
176 {
177  return GPIO_PinInGet( (GPIO_Port_TypeDef) RF_INT_PORT, RF_INT_PIN);
178 }
179 
180 #if defined(EZRADIODRV_DISABLE_PTI) && defined(EZRADIODRV_COMM_USE_GPIO1_FOR_CTS)
181 
186 uint8_t ezradio_hal_Gpio1Level(void)
187 {
188  return GPIO_PinInGet( (GPIO_Port_TypeDef) RF_GPIO1_PORT, RF_GPIO1_PIN);
189 }
190 #endif
191 
197 void ezradio_hal_SpiWriteByte(uint8_t byteToWrite)
198 {
199  SPIDRV_MTransmitB(ezradioSpiHandlePtr, &byteToWrite, 1);
200 }
201 
207 void ezradio_hal_SpiReadByte(uint8_t* readByte)
208 {
209  SPIDRV_MReceiveB(ezradioSpiHandlePtr, readByte, 1);
210 }
211 
218 void ezradio_hal_SpiWriteData(uint8_t byteCount, uint8_t* pData)
219 {
220  SPIDRV_MTransmitB(ezradioSpiHandlePtr, pData, byteCount);
221 }
222 
229 void ezradio_hal_SpiReadData(uint8_t byteCount, uint8_t* pData)
230 {
231 
232  SPIDRV_MReceiveB(ezradioSpiHandlePtr, pData, byteCount);
233 }
234 
241 void ezradio_hal_SpiWriteReadData(uint8_t byteCount, uint8_t* txData, uint8_t* rxData)
242 {
243 
244  SPIDRV_MTransferB(ezradioSpiHandlePtr, txData, rxData, byteCount);
245 }
GPIO_Port_TypeDef
Definition: em_gpio.h:345
void ezradio_hal_SetNsel(void)
Definition: ezradio_hal.c:165
SPIDRV API definition.
#define PRS
Ecode_t SPIDRV_MTransmitB(SPIDRV_Handle_t handle, const void *buffer, int count)
Start a SPI master blocking transmit transfer.
Definition: spidrv.c:843
void ezradio_hal_SpiInit(void)
Definition: ezradio_hal.c:126
void ezradio_hal_AssertShutdown(void)
Definition: ezradio_hal.c:141
Ecode_t SPIDRV_MTransferB(SPIDRV_Handle_t handle, const void *txBuffer, void *rxBuffer, int count)
Start a SPI master blocking transfer.
Definition: spidrv.c:694
void ezradio_hal_GpioInit(GPIOINT_IrqCallbackPtr_t ezradioIrqCallback, bool enablePTI)
Definition: ezradio_hal.c:66
void GPIOINT_CallbackRegister(uint8_t pin, GPIOINT_IrqCallbackPtr_t callbackPtr)
Registers user callback for given pin number.
Definition: gpiointerrupt.c:91
#define GPIO_INSENSE_PRS
Definition: efm32g_gpio.h:1060
#define PRS_CH_CTRL_SOURCESEL_GPIOH
Definition: efm32g_prs.h:282
uint32_t bitRate
SPI bitrate.
Definition: spidrv.h:134
This file contains EZRadio HAL.
void ezradio_hal_SpiWriteReadData(uint8_t byteCount, uint8_t *txData, uint8_t *rxData)
Definition: ezradio_hal.c:241
void ezradio_hal_SpiWriteData(uint8_t byteCount, uint8_t *pData)
Definition: ezradio_hal.c:218
EZRADIODRV configuration file.
void GPIO_PinModeSet(GPIO_Port_TypeDef port, unsigned int pin, GPIO_Mode_TypeDef mode, unsigned int out)
Set the mode for a GPIO pin.
Definition: em_gpio.c:269
#define SPIDRV_MASTER_USARTRF0
Configuration data for SPI master using USARTRF0.
Definition: spidrv.h:482
General Purpose IO (GPIO) peripheral API.
void ezradio_hal_SpiWriteByte(uint8_t byteToWrite)
Definition: ezradio_hal.c:197
__STATIC_INLINE void GPIO_PinOutSet(GPIO_Port_TypeDef port, unsigned int pin)
Set a single pin in GPIO data out register to 1.
Definition: em_gpio.h:856
void ezradio_hal_SpiReadData(uint8_t byteCount, uint8_t *pData)
Definition: ezradio_hal.c:229
__STATIC_INLINE void GPIO_InputSenseSet(uint32_t val, uint32_t mask)
Enable/disable input sensing.
Definition: em_gpio.h:662
void CMU_ClockEnable(CMU_Clock_TypeDef clock, bool enable)
Enable/disable a clock.
Definition: em_cmu.c:1453
void ezradio_hal_SpiReadByte(uint8_t *readByte)
Definition: ezradio_hal.c:207
__STATIC_INLINE void GPIO_IntConfig(GPIO_Port_TypeDef port, unsigned int pin, bool risingEdge, bool fallingEdge, bool enable)
Configure GPIO interrupt.
Definition: em_gpio.h:1104
#define PRS_CH_CTRL_SIGSEL_GPIOPIN15
Definition: efm32g_prs.h:248
CS controlled by application.
Definition: spidrv.h:81
void(* GPIOINT_IrqCallbackPtr_t)(uint8_t pin)
GPIO interrupt callback function pointer.
Definition: gpiointerrupt.h:46
GPIOINT API definition.
void ezradio_hal_ClearNsel(void)
Definition: ezradio_hal.c:157
Ecode_t SPIDRV_Init(SPIDRV_Handle_t handle, SPIDRV_Init_t *initData)
Initialize a SPI driver instance.
Definition: spidrv.c:101
uint8_t ezradio_hal_NirqLevel(void)
Definition: ezradio_hal.c:175
__STATIC_INLINE void GPIO_PinOutClear(GPIO_Port_TypeDef port, unsigned int pin)
Set a single pin in GPIO data out port register to 0.
Definition: em_gpio.h:811
#define SPIDRV_MASTER_USART1
Configuration data for SPI master using USART1.
Definition: spidrv.h:436
__STATIC_INLINE unsigned int GPIO_PinInGet(GPIO_Port_TypeDef port, unsigned int pin)
Read the pad value for a single pin in a GPIO port.
Definition: em_gpio.h:781
#define SPIDRV_MASTER_USARTRF1
Configuration data for SPI master using USARTRF1.
Definition: spidrv.h:497
void ezradio_hal_DeassertShutdown(void)
Definition: ezradio_hal.c:149
SPIDRV_CsControl_t csControl
Select master mode chip select (CS) control scheme.
Definition: spidrv.h:140
Peripheral Reflex System (PRS) peripheral API.
Ecode_t SPIDRV_MReceiveB(SPIDRV_Handle_t handle, void *buffer, int count)
Start a SPI master blocking receive transfer.
Definition: spidrv.c:602
#define PRS_CH_CTRL_SIGSEL_GPIOPIN14
Definition: efm32g_prs.h:246