/***************************************************************************//** * @file * @brief LCD controller demo for EFM32GG_STK3700 development kit * @version 5.3.5 ******************************************************************************* * # License * Copyright 2015 Silicon Labs, Inc. http://www.silabs.com ******************************************************************************* * * This file is licensed under the Silabs License Agreement. See the file * "Silabs_License_Agreement.txt" for details. Before using this software for * any purpose, you must agree to the terms of that agreement. * ******************************************************************************/ #include #include #include "em_device.h" #include "em_chip.h" #include "em_cmu.h" #include "em_gpio.h" #include "bsp.h" #include "segmentlcd.h" #include "bsp_trace.h" #include "gpiointerrupt.h" volatile uint32_t msTicks; /* counts 1ms timeTicks */ volatile uint32_t led0_time = 0; volatile uint32_t led1_time = 0; volatile uint8_t led0_start = 0; volatile uint8_t led1_start = 0; volatile uint8_t toggle_leds = 0; /* Locatl prototypes */ void Delay(uint32_t dlyTicks); /***************************************************************************//** * @brief SysTick_Handler * Interrupt Service Routine for system tick counter * @note * No wrap around protection ******************************************************************************/ void SysTick_Handler(void) { msTicks++; /* increment counter necessary in Delay()*/ if (!GPIO_PinInGet(gpioPortB, 9)) { led0_time++; } if (!GPIO_PinInGet(gpioPortB, 10)) { led1_time++; } } /***************************************************************************//** * @brief Delays number of msTick Systicks (typically 1 ms) * @param dlyTicks Number of ticks to delay ******************************************************************************/ void Delay(uint32_t dlyTicks) { uint32_t curTicks; curTicks = msTicks; while ((msTicks - curTicks) < dlyTicks) ; } /***************************************************************************//** * @brief Gpio callback * @param pin - pin which triggered interrupt ******************************************************************************/ void gpioCallback(uint8_t pin) { if (pin == 9) { if (GPIO_PinInGet(gpioPortB, 9)) led0_start = 1; else if (!GPIO_PinInGet(gpioPortB, 10)) toggle_leds = 1; else led0_time = 0; } else if (pin == 10) { if (GPIO_PinInGet(gpioPortB, 10)) led1_start = 1; else if (!GPIO_PinInGet(gpioPortB, 9)) toggle_leds = 1; else led1_time = 0; } } /***************************************************************************//** * @brief Gpio setup. Setup button pins to trigger falling edge interrupts. * Register callbacks for that interrupts. ******************************************************************************/ void gpioSetup(void) { /* Enable GPIO in CMU */ CMU_ClockEnable(cmuClock_GPIO, true); /* Initialize GPIO interrupt dispatcher */ GPIOINT_Init(); /* Configure PB9 and PB10 as input */ GPIO_PinModeSet(gpioPortB, 9, gpioModeInput, 0); GPIO_PinModeSet(gpioPortB, 10, gpioModeInput, 0); /* Register callbacks before setting up and enabling pin interrupt. */ GPIOINT_CallbackRegister(9, gpioCallback); GPIOINT_CallbackRegister(10, gpioCallback); /* Set falling edge interrupt for both ports */ GPIO_IntConfig(gpioPortB, 9, true, true, true); GPIO_IntConfig(gpioPortB, 10, true, true, true); } /***************************************************************************//** * @brief Main function ******************************************************************************/ int main(void) { uint32_t sum; uint32_t led0_time_tmp; uint32_t led1_time_tmp; /* Chip errata */ CHIP_Init(); /* If first word of user data page is non-zero, enable eA Profiler trace */ BSP_TraceProfilerSetup(); /* Enable two leds to show we're alive */ BSP_LedsInit(); /* Setup SysTick Timer for 1 msec interrupts */ if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) { while (1) ; } /* Enable LCD without voltage boost */ SegmentLCD_Init(false); /* Initialize gpio */ gpioSetup(); /* Infinite loop with test pattern. */ while (1) { if (led0_start && led1_start) { sum = led0_time + led1_time; if (!led1_time_tmp) led1_time_tmp = led1_time; if (!led0_time_tmp) led0_time_tmp = led0_time; SegmentLCD_Number(sum); Delay(2000); led1_start = 0; led0_start = 0; SegmentLCD_AllOff(); } if (toggle_leds) { while (led0_time_tmp) { //&& led1_time_tmp != 0) { if (led0_time_tmp > 0) { led0_time_tmp--; BSP_LedSet(0); } else BSP_LedClear(0); /*if (led1_time_tmp > 0) { led1_time_tmp--; BSP_LedSet(1); } else BSP_LedClear(1); */ Delay(1); } toggle_leds = 0; } } }