#include "em_device.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "em_emu.h"
#include "em_gpio.h"
#include "bsp.h"
/**************************************************************************//**
* @brief GPIO Even IRQ for pushbuttons on even-numbered pins
*****************************************************************************/
void GPIO_EVEN_IRQHandler(void)
{
// Clear all even pin interrupt flags
GPIO_IntClear(0x5555);
// Toggle LED0
GPIO_PinOutToggle(BSP_GPIO_LED0_PORT, BSP_GPIO_LED0_PIN);
}
/**************************************************************************//**
* @brief GPIO Odd IRQ for pushbuttons on odd-numbered pins
*****************************************************************************/
void GPIO_ODD_IRQHandler(void)
{
// Clear all odd pin interrupt flags
GPIO_IntClear(0xAAAA);
// Toggle LED01
GPIO_PinOutToggle(BSP_GPIO_LED1_PORT, BSP_GPIO_LED1_PIN);
}
/**************************************************************************//**
* @brief GPIO initialization
*****************************************************************************/
void initGPIO(void)
{
// Enable GPIO clock
CMU_ClockEnable(cmuClock_GPIO, true);
// Configure PB0 and PB1 as input with glitch filter enabled
GPIO_PinModeSet(BSP_GPIO_PB0_PORT, BSP_GPIO_PB0_PIN, gpioModeInputPullFilter, 1);
GPIO_PinModeSet(BSP_GPIO_PB1_PORT, BSP_GPIO_PB1_PIN, gpioModeInputPullFilter, 1);
// Configure LED0 and LED1 as output
GPIO_PinModeSet(BSP_GPIO_LED0_PORT, BSP_GPIO_LED0_PIN, gpioModePushPull, 0);
GPIO_PinModeSet(BSP_GPIO_LED1_PORT, BSP_GPIO_LED1_PIN, gpioModePushPull, 0);
// Enable IRQ for even numbered GPIO pins
NVIC_EnableIRQ(GPIO_EVEN_IRQn);
// Enable IRQ for odd numbered GPIO pins
NVIC_EnableIRQ(GPIO_ODD_IRQn);
// Enable falling-edge interrupts for PB pins
GPIO_ExtIntConfig(BSP_GPIO_PB0_PORT, BSP_GPIO_PB0_PIN,BSP_GPIO_PB0_PIN, 0, 1, true);
GPIO_ExtIntConfig(BSP_GPIO_PB1_PORT, BSP_GPIO_PB1_PIN, BSP_GPIO_PB1_PIN, 0, 1, true);
}
/**************************************************************************//**
* @brief Main function
*****************************************************************************/
int main(void)
{
// Chip errata
CHIP_Init();
// Initializations
initGPIO();
while (1){
// Enter Low Energy Mode until an interrupt occurs
EMU_EnterEM3(false);
}
}