/**
 * Configures the EZRadio GPIO port and pins
 *
 * @param[in] ezradioIrqCallback EZRadio interrupt callback configuration
 * @param[in] enablePTI If true enables the radio PTI bridge in the controller.
 */
void ezradio_hal_GpioInit( GPIOINT_IrqCallbackPtr_t ezradioIrqCallback, bool enablePTI )
{
#if defined(_EZR32_HAPPY_FAMILY)
  (void)enablePTI;
#endif

#if !defined(EZRADIODRV_SPI_4WIRE_MODE)
   GPIO_PinModeSet( (GPIO_Port_TypeDef) RF_USARTRF_CS_PORT, RF_USARTRF_CS_PIN, gpioModePushPull, 1 );
#endif

   /* Setup enable and interrupt pins to radio */
   GPIO_PinModeSet( (GPIO_Port_TypeDef) RF_SDN_PORT, RF_SDN_PIN, gpioModePushPull,  0 );
   GPIO_PinModeSet( (GPIO_Port_TypeDef) RF_INT_PORT, RF_INT_PIN, gpioModeInputPull, 1 );

   /* EZR32HG family uses hard wired PTI interface from the radio to the board controller */
#if ( !defined(_EZR32_HAPPY_FAMILY) && !defined(EZRADIODRV_DISABLE_PTI) )
   if (enablePTI)
   {
     /* Setup PRS for PTI pins */
     CMU_ClockEnable(cmuClock_PRS, true);

     /* Configure RF_GPIO0 and RF_GPIO1 to inputs. */
     GPIO_PinModeSet((GPIO_Port_TypeDef)RF_GPIO0_PORT, RF_GPIO0_PIN, gpioModeInput, 0);
     GPIO_PinModeSet((GPIO_Port_TypeDef)RF_GPIO1_PORT, RF_GPIO1_PIN, gpioModeInput, 0);

     /* Pin PA0 and PA1 output the GPIO0 and GPIO1 via PRS to PTI */
     GPIO_PinModeSet(gpioPortA, 0, gpioModePushPull, 0);
     GPIO_PinModeSet(gpioPortA, 1, gpioModePushPull, 0);

     /* Disable INT for PRS channels */
     GPIO_IntConfig((GPIO_Port_TypeDef)RF_GPIO0_PORT, RF_GPIO0_PIN, false, false, false);
     GPIO_IntConfig((GPIO_Port_TypeDef)RF_GPIO1_PORT, RF_GPIO1_PIN, false, false, false);

     /* Setup PRS for RF GPIO pins  */
     PRS_SourceAsyncSignalSet(0, PRS_CH_CTRL_SOURCESEL_GPIOH, PRS_CH_CTRL_SIGSEL_GPIOPIN15);
     PRS_SourceAsyncSignalSet(1, PRS_CH_CTRL_SOURCESEL_GPIOH, PRS_CH_CTRL_SIGSEL_GPIOPIN14);
     PRS->ROUTE = (PRS_ROUTE_CH0PEN | PRS_ROUTE_CH1PEN);

     /* Make sure PRS sensing is enabled (should be by default) */
     GPIO_InputSenseSet(GPIO_INSENSE_PRS, GPIO_INSENSE_PRS);
   }
#endif //#if !defined(_EZR32_HAPPY_FAMILY)

#if defined(EZRADIODRV_DISABLE_PTI) && defined(EZRADIODRV_COMM_USE_GPIO1_FOR_CTS)
   //Enable GPIO1 for CTS input
   GPIO_PinModeSet((GPIO_Port_TypeDef)RF_GPIO1_PORT, RF_GPIO1_PIN, gpioModeInput, 0);
#endif

   if (NULL != ezradioIrqCallback)
   {
       /* Register callback and enable interrupt */
       GPIOINT_CallbackRegister( RF_INT_PIN, ezradioIrqCallback );
       GPIO_IntConfig( (GPIO_Port_TypeDef) RF_INT_PORT, RF_INT_PIN, false, true, true );
   }

}
Exemplo n.º 2
0
/** @brief Initialize External Device GPIOs
 * @param  deviceIntCB The callback routine for device general interrupt
 *                     (NULL to disable)
 * @param  deviceRdyCB The callback routine for device ready interrupt
 *                     (NULL to disable)
 * @return bitmask of configured features for this device
 * @note First initialization after bootup leaves the device powered down
 *       and unselected.  Subsequent inits don't touch the device powered
 *       or selected states and can be used to reconfigure callback(s),
 *       which always clears any stale/pending events.  For deviceRdyCB,
 *       its interrupt is enabled upon configuration; for deviceIntCB,
 *       halExtDeviceIntEnable() must subsequently be called to enable it.
 */
HalExtDeviceConfig halExtDeviceInit(HalExtDeviceIrqCB deviceIntCB,
                                    HalExtDeviceIrqCB deviceRdyCB)
{
  UNUSED_VAR(halExtDeviceRdyCB); // Work around potential compiler warnings
  UNUSED_VAR(halExtDeviceIntCB); // Work around potential compiler warnings
  halExtDeviceRdyCB = deviceRdyCB;
  halExtDeviceIntCB = deviceIntCB; 

  CMU_ClockEnable(cmuClock_PRS, true);

  /* Pin is configured to Push-pull: SDN */
  GPIO_PinModeSet((GPIO_Port_TypeDef) RF_SDN_PORT, RF_SDN_PIN, gpioModePushPull, 1u);

  /* Pin is configured to Push-pull: nSEL */
  GPIO_PinModeSet((GPIO_Port_TypeDef) RF_USARTRF_CS_PORT, RF_USARTRF_CS_PIN, gpioModePushPull, 1u);

  /* Pin PE13 is configured input: nIRQ */
  //GPIO_PinModeSet(RF_INT_PORT, RF_INT_PIN, gpioModeInput, 0u);

  /* Pin PA15 and PE14 are connected to GPIO0 and GPIO1 respectively. */
  GPIO_PinModeSet((GPIO_Port_TypeDef) RF_GPIO0_PORT, RF_GPIO0_PIN, gpioModeInput, 0);
  GPIO_PinModeSet((GPIO_Port_TypeDef) RF_GPIO1_PORT, RF_GPIO1_PIN, gpioModeInput, 0);

  /* Pin PA0 and PA1 are output the GPIO0 and GPIO1 via PRS */
  GPIO_PinModeSet(gpioPortA, 0, gpioModePushPull, 0);
  GPIO_PinModeSet(gpioPortA, 1, gpioModePushPull, 0);

  /* Configure INT/PRS channels */
  GPIO_IntConfig((GPIO_Port_TypeDef) RF_GPIO0_PORT, RF_GPIO0_PIN, false, false, false);
  GPIO_IntConfig((GPIO_Port_TypeDef) RF_GPIO1_PORT, RF_GPIO1_PIN, false, false, false);

  /* Setup PRS */
  PRS_SourceAsyncSignalSet(0, PRS_CH_CTRL_SOURCESEL_GPIOH, PRS_CH_CTRL_SIGSEL_GPIOPIN15);
  PRS_SourceAsyncSignalSet(1, PRS_CH_CTRL_SOURCESEL_GPIOH, PRS_CH_CTRL_SIGSEL_GPIOPIN14);
  PRS->ROUTE = (PRS_ROUTE_CH0PEN | PRS_ROUTE_CH1PEN);

  /* Make sure PRS sensing is enabled (should be by default) */
  GPIO_InputSenseSet(GPIO_INSENSE_PRS, GPIO_INSENSE_PRS);

  /* TODO: Check whether the removed part is required 
     for the EZR32 implementation */
  halExtDeviceRdyCfgIrq();
  halExtDeviceIntCfgIrq();
  
  return 0;
}
/**************************************************************************//**
 * @brief   Toggle a GPIO pin automatically at the given frequency.
 *
 * @param[in] gpioPort  GPIO port number of GPIO ping to toggle.
 * @param[in] gpioPin   GPIO pin number.
 *
 * @return  EMSTATUS code of the operation.
 *****************************************************************************/
EMSTATUS PAL_GpioPinAutoToggle (unsigned int gpioPort,
                                unsigned int gpioPin,
                                unsigned int frequency)
{
  EMSTATUS status = EMSTATUS_OK;

#ifdef INCLUDE_PAL_GPIO_PIN_AUTO_TOGGLE_HW_ONLY

#if defined( BSP_STK_2010 )
  /* We only support auto HW toggling on GPIO port E pin 10 on Zero STK.  */
  if ( (gpioPortE != gpioPort) || (10 != gpioPin) )

#elif defined( BSP_STK_2011 )
  /* We only support auto HW toggling on GPIO port F pin 3 on Happy STK.  */
  if ( (gpioPortF != gpioPort) || (3 != gpioPin) )

#elif defined( BSP_STK_2500 )
  /* We only support auto HW toggling on GPIO port D pin 13 on Pearl STK.  */
  if ( (gpioPortD != gpioPort) || (13 != gpioPin) )

#else
#error "Illegal display auto-toggle setup."
#endif
  {
    status = PAL_EMSTATUS_INVALID_PARAM;
  }
  else
  {
    /* Setup PRS to drive the GPIO pin which is connected to the
       display com inversion pin (EXTCOMIN) using the RTC COMP0 signal or
       RTCC CCV1 signal as source. */
#if defined(PAL_CLOCK_RTCC)
    uint32_t     source  = PRS_CH_CTRL_SOURCESEL_RTCC;
    uint32_t     signal  = PRS_CH_CTRL_SIGSEL_RTCCCCV1;
#else
    uint32_t     source  = PRS_CH_CTRL_SOURCESEL_RTC;
    uint32_t     signal  = PRS_CH_CTRL_SIGSEL_RTCCOMP0;
#endif

    /* Enable PRS clock */
    CMU_ClockEnable(cmuClock_PRS, true);

    /* Set up PRS to trigger from an RTC compare match */
    PRS_SourceAsyncSignalSet(LCD_AUTO_TOGGLE_PRS_CH, source, signal);

    /* This outputs the PRS pulse on the EXTCOMIN pin */
#if defined(_SILICON_LABS_32B_PLATFORM_2)
    LCD_AUTO_TOGGLE_PRS_ROUTELOC();
    PRS->ROUTEPEN |= LCD_AUTO_TOGGLE_PRS_ROUTEPEN;
#else
    PRS->ROUTE = ( PRS->ROUTE & ~_PRS_ROUTE_LOCATION_MASK )
                 | LCD_AUTO_TOGGLE_PRS_ROUTE_LOC;
    PRS->ROUTE |= LCD_AUTO_TOGGLE_PRS_ROUTE_PEN;
#endif
  }
#else
  /* Store GPIO pin data. */
  gpioPortNo = gpioPort;
  gpioPinNo  = gpioPin;
#endif

  if (EMSTATUS_OK == status)
  {
    /* Setup GPIO pin. */
    GPIO_PinModeSet((GPIO_Port_TypeDef)gpioPort, gpioPin, gpioModePushPull, 0 );

#if defined(PAL_CLOCK_RTCC)
    /* Setup RTCC to to toggle PRS or generate interrupts at given frequency. */
    rtccSetup(frequency);
#else
    /* Setup RTC to to toggle PRS or generate interrupts at given frequency. */
    rtcSetup(frequency);
#endif
  }

  return status;
}