EFM32 Leopard Gecko Software Documentation  efm32lg-doc-4.2.1
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 
41 #include "gpiointerrupt.h"
42 #include "ezradio_hal.h"
43 
45 
46 static SPIDRV_HandleData_t ezradioSpiHandle;
47 static SPIDRV_Handle_t ezradioSpiHandlePtr = &ezradioSpiHandle;
48 
49 #if (defined _EZR32_HAPPY_FAMILY)
50 static SPIDRV_Init_t ezradioSpiInitData = SPIDRV_MASTER_USARTRF1;
51 #else
52 static SPIDRV_Init_t ezradioSpiInitData = SPIDRV_MASTER_USARTRF0;
53 #endif
54 
56 
63 void ezradio_hal_GpioInit( GPIOINT_IrqCallbackPtr_t ezradioIrqCallback, bool enablePTI )
64 {
65 #if (defined _EZR32_HAPPY_FAMILY)
66  (void)enablePTI;
67 #endif
68 
69  GPIO_PinModeSet( (GPIO_Port_TypeDef) RF_USARTRF_CS_PORT, RF_USARTRF_CS_PIN, gpioModePushPull, 1 );
70 
71  /* Setup enable and interrupt pins to radio */
72  GPIO_PinModeSet( (GPIO_Port_TypeDef) RF_SDN_PORT, RF_SDN_PIN, gpioModePushPull, 0 );
73  GPIO_PinModeSet( (GPIO_Port_TypeDef) RF_INT_PORT, RF_INT_PIN, gpioModeInputPull, 1 );
74 
75  /* EZR32HG family uses hard wired PTI interface from the radio to the board controler */
76 #if !(defined _EZR32_HAPPY_FAMILY)
77  if (enablePTI)
78  {
79  /* Setup PRS for PTI pins */
81 
82  /* Configure RF_GPIO0 and RF_GPIO1 to inputs. */
83  GPIO_PinModeSet((GPIO_Port_TypeDef)RF_GPIO0_PORT, RF_GPIO0_PIN, gpioModeInput, 0);
84  GPIO_PinModeSet((GPIO_Port_TypeDef)RF_GPIO1_PORT, RF_GPIO1_PIN, gpioModeInput, 0);
85 
86  /* Pin PA0 and PA1 output the GPIO0 and GPIO1 via PRS to PTI */
87  GPIO_PinModeSet(gpioPortA, 0, gpioModePushPull, 0);
88  GPIO_PinModeSet(gpioPortA, 1, gpioModePushPull, 0);
89 
90  /* Disable INT for PRS channels */
91  GPIO_IntConfig((GPIO_Port_TypeDef)RF_GPIO0_PORT, RF_GPIO0_PIN, false, false, false);
92  GPIO_IntConfig((GPIO_Port_TypeDef)RF_GPIO1_PORT, RF_GPIO1_PIN, false, false, false);
93 
94  /* Setup PRS for RF GPIO pins */
98 
99  /* Make sure PRS sensing is enabled (should be by default) */
101  }
102 #endif //#if !(defined _EZR32_HAPPY_FAMILY)
103 
104  if (NULL != ezradioIrqCallback)
105  {
106  /* Register callback and enable interrupt */
107  GPIOINT_CallbackRegister( RF_INT_PIN, ezradioIrqCallback );
108  GPIO_IntConfig( (GPIO_Port_TypeDef) RF_INT_PORT, RF_INT_PIN, false, true, true );
109  }
110 
111  return;
112 }
113 
118 {
119  ezradioSpiInitData.bitRate = 8E6;
120  ezradioSpiInitData.csControl = spidrvCsControlApplication;
121 
122  SPIDRV_Init( ezradioSpiHandlePtr, &ezradioSpiInitData );
123 
124  return;
125 }
126 
131 {
132  GPIO_PinOutSet( (GPIO_Port_TypeDef) RF_SDN_PORT, RF_SDN_PIN);
133 }
134 
139 {
140  GPIO_PinOutClear( (GPIO_Port_TypeDef) RF_SDN_PORT, RF_SDN_PIN);
141 }
142 
147 {
148  GPIO_PinOutClear( (GPIO_Port_TypeDef) RF_USARTRF_CS_PORT, RF_USARTRF_CS_PIN);
149 }
150 
155 {
156  GPIO_PinOutSet( (GPIO_Port_TypeDef) RF_USARTRF_CS_PORT, RF_USARTRF_CS_PIN);
157 }
158 
165 {
166  return GPIO_PinInGet( (GPIO_Port_TypeDef) RF_INT_PORT, RF_INT_PIN);
167 }
168 
174 void ezradio_hal_SpiWriteByte(uint8_t byteToWrite)
175 {
176  SPIDRV_MTransmitB(ezradioSpiHandlePtr, &byteToWrite, 1);
177 }
178 
184 void ezradio_hal_SpiReadByte(uint8_t* readByte)
185 {
186  SPIDRV_MReceiveB(ezradioSpiHandlePtr, readByte, 1);
187 }
188 
195 void ezradio_hal_SpiWriteData(uint8_t byteCount, uint8_t* pData)
196 {
197  SPIDRV_MTransmitB(ezradioSpiHandlePtr, pData, byteCount);
198 }
199 
206 void ezradio_hal_SpiReadData(uint8_t byteCount, uint8_t* pData)
207 {
208 
209  SPIDRV_MReceiveB(ezradioSpiHandlePtr, pData, byteCount);
210 }
GPIO_Port_TypeDef
Definition: em_gpio.h:232
void ezradio_hal_SetNsel(void)
Definition: ezradio_hal.c:154
SPIDRV API definition.
Ecode_t SPIDRV_MTransmitB(SPIDRV_Handle_t handle, const void *buffer, int count)
Start a SPI master blocking transmit transfer.
Definition: spidrv.c:805
void ezradio_hal_SpiInit(void)
Definition: ezradio_hal.c:117
void ezradio_hal_AssertShutdown(void)
Definition: ezradio_hal.c:130
#define PRS_ROUTE_CH0PEN
Definition: efm32lg_prs.h:187
void ezradio_hal_GpioInit(GPIOINT_IrqCallbackPtr_t ezradioIrqCallback, bool enablePTI)
Definition: ezradio_hal.c:63
void GPIOINT_CallbackRegister(uint8_t pin, GPIOINT_IrqCallbackPtr_t callbackPtr)
Registers user callback for given pin number.
Definition: gpiointerrupt.c:91
#define PRS
uint32_t bitRate
SPI bitrate.
Definition: spidrv.h:137
This file contains EZRadio HAL.
void ezradio_hal_SpiWriteData(uint8_t byteCount, uint8_t *pData)
Definition: ezradio_hal.c:195
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:226
#define SPIDRV_MASTER_USARTRF0
Configuration data for SPI master using USARTRF0.
Definition: spidrv.h:388
General Purpose IO (GPIO) peripheral API.
void ezradio_hal_SpiWriteByte(uint8_t byteToWrite)
Definition: ezradio_hal.c:174
#define PRS_ROUTE_CH1PEN
Definition: efm32lg_prs.h:192
__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:745
void ezradio_hal_SpiReadData(uint8_t byteCount, uint8_t *pData)
Definition: ezradio_hal.c:206
__STATIC_INLINE void GPIO_InputSenseSet(uint32_t val, uint32_t mask)
Enable/disable input sensing.
Definition: em_gpio.h:548
void CMU_ClockEnable(CMU_Clock_TypeDef clock, bool enable)
Enable/disable a clock.
Definition: em_cmu.c:1369
void ezradio_hal_SpiReadByte(uint8_t *readByte)
Definition: ezradio_hal.c:184
#define GPIO_INSENSE_PRS
#define PRS_CH_CTRL_SOURCESEL_GPIOH
Definition: efm32lg_prs.h:429
CS controlled by application.
Definition: spidrv.h:84
void(* GPIOINT_IrqCallbackPtr_t)(uint8_t pin)
GPIO interrupt callback function pointer.
Definition: gpiointerrupt.h:49
GPIOINT API definition.
void ezradio_hal_ClearNsel(void)
Definition: ezradio_hal.c:146
Ecode_t SPIDRV_Init(SPIDRV_Handle_t handle, SPIDRV_Init_t *initData)
Initialize a SPI driver instance.
Definition: spidrv.c:91
uint8_t ezradio_hal_NirqLevel(void)
Definition: ezradio_hal.c:164
__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:698
__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:675
void PRS_SourceAsyncSignalSet(unsigned int ch, uint32_t source, uint32_t signal)
Set source and asynchronous signal to be used for a channel.
Definition: em_prs.c:111
#define PRS_CH_CTRL_SIGSEL_GPIOPIN14
Definition: efm32lg_prs.h:378
#define SPIDRV_MASTER_USARTRF1
Configuration data for SPI master using USARTRF1.
Definition: spidrv.h:403
void ezradio_hal_DeassertShutdown(void)
Definition: ezradio_hal.c:138
void GPIO_IntConfig(GPIO_Port_TypeDef port, unsigned int pin, bool risingEdge, bool fallingEdge, bool enable)
Configure GPIO interrupt.
Definition: em_gpio.c:168
SPIDRV_CsControl_t csControl
Select master mode chip select (CS) control scheme.
Definition: spidrv.h:143
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:565
#define PRS_CH_CTRL_SIGSEL_GPIOPIN15
Definition: efm32lg_prs.h:382