/***************************************************************************//** * @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); volatile uint8_t state = 4; volatile uint8_t sw0_pushed = 0; volatile uint8_t sw1_pushed = 0; volatile uint16_t counter; volatile uint32_t sumarum = 0; volatile uint8_t display = 0; volatile uint8_t clear = 0; /***************************************************************************//** * @brief SysTick_Handler * Interrupt Service Routine for system tick counter * @note * No wrap around protection ******************************************************************************/ void SysTick_Handler(void) { msTicks++; static uint8_t done0 = 0; static uint8_t done1 = 0; static uint8_t cnt = 10; switch(state) { case 0: if (!GPIO_PinInGet(gpioPortB, 10)) { led0_time++; sw0_pushed = 1; } else { if (sw0_pushed == 1) { state = 1; sw0_pushed = 0; } } break; case 1: if (!GPIO_PinInGet(gpioPortB, 9)) { led1_time++; sw1_pushed = 1; } else { if (sw1_pushed == 1) { sw1_pushed = 0; counter = 2000; sumarum = led0_time + led1_time; display = 1; state = 2; } } break; case 2: if (counter) counter--; if (!counter) { clear = 1; if (!GPIO_PinInGet(gpioPortB, 10) && !GPIO_PinInGet(gpioPortB, 9)) { state = 3; } } break; case 3: if (led0_time > 0) { BSP_LedSet(0); led0_time--; } else { BSP_LedClear(0); done0 = 1; } if (led1_time > 0) { BSP_LedSet(1); led1_time--; } else { BSP_LedClear(1); done1 = 1; } if (done0 && done1) { done0 = 0; done1 = 0; state = 4; } break; case 4: if (cnt > 0) { cnt--; } else { cnt = 10; state = 0; } break; } } /***************************************************************************//** * @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, false, false, true); GPIO_IntConfig(gpioPortB, 10, false, false, 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(); while (1) { if (display) { SegmentLCD_Number(sumarum); display = 0; } if (clear) { //sum = 0; SegmentLCD_AllOff(); clear = 0; } } }