mirror of https://github.com/rusefi/openblt.git
104 lines
4.1 KiB
C
104 lines
4.1 KiB
C
|
/************************************************************************************//**
|
||
|
* \file Demo\ARMCM3_STM32F2_Olimex_STM32P207_IAR\Prog\led.c
|
||
|
* \brief LED driver source file.
|
||
|
* \ingroup Prog_ARMCM3_STM32F2_Olimex_STM32P207_IAR
|
||
|
* \internal
|
||
|
*----------------------------------------------------------------------------------------
|
||
|
* C O P Y R I G H T
|
||
|
*----------------------------------------------------------------------------------------
|
||
|
* Copyright (c) 2018 by Feaser http://www.feaser.com All rights reserved
|
||
|
*
|
||
|
*----------------------------------------------------------------------------------------
|
||
|
* L I C E N S E
|
||
|
*----------------------------------------------------------------------------------------
|
||
|
* This file is part of OpenBLT. OpenBLT is free software: you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU General Public License as published by the Free
|
||
|
* Software Foundation, either version 3 of the License, or (at your option) any later
|
||
|
* version.
|
||
|
*
|
||
|
* OpenBLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||
|
* PURPOSE. See the GNU General Public License for more details.
|
||
|
*
|
||
|
* You have received a copy of the GNU General Public License along with OpenBLT. It
|
||
|
* should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy.
|
||
|
*
|
||
|
* \endinternal
|
||
|
****************************************************************************************/
|
||
|
|
||
|
/****************************************************************************************
|
||
|
* Include files
|
||
|
****************************************************************************************/
|
||
|
#include "header.h" /* generic header */
|
||
|
|
||
|
|
||
|
/****************************************************************************************
|
||
|
* Macro definitions
|
||
|
****************************************************************************************/
|
||
|
/** \brief Toggle interval time in milliseconds. */
|
||
|
#define LED_TOGGLE_MS (500)
|
||
|
|
||
|
|
||
|
/************************************************************************************//**
|
||
|
** \brief Initializes the LED.
|
||
|
** \return none.
|
||
|
**
|
||
|
****************************************************************************************/
|
||
|
void LedInit(void)
|
||
|
{
|
||
|
GPIO_InitTypeDef GPIO_InitStructure;
|
||
|
|
||
|
/* GPIOF peripheral clock enable for LED_STAT1 */
|
||
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
|
||
|
|
||
|
/* configure PF6 with as output with internal pull-up */
|
||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
|
||
|
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||
|
GPIO_Init(GPIOF, &GPIO_InitStructure);
|
||
|
GPIO_ResetBits(GPIOF, GPIO_Pin_8);
|
||
|
} /*** end of LedInit ***/
|
||
|
|
||
|
|
||
|
/************************************************************************************//**
|
||
|
** \brief Toggles the LED at a fixed time interval.
|
||
|
** \return none.
|
||
|
**
|
||
|
****************************************************************************************/
|
||
|
void LedToggle(void)
|
||
|
{
|
||
|
static unsigned char led_toggle_state = 0;
|
||
|
static unsigned long timer_counter_last = 0;
|
||
|
unsigned long timer_counter_now;
|
||
|
|
||
|
/* check if toggle interval time passed */
|
||
|
timer_counter_now = TimerGet();
|
||
|
if ( (timer_counter_now - timer_counter_last) < LED_TOGGLE_MS)
|
||
|
{
|
||
|
/* not yet time to toggle */
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
/* determine toggle action */
|
||
|
if (led_toggle_state == 0)
|
||
|
{
|
||
|
led_toggle_state = 1;
|
||
|
/* turn the LED on */
|
||
|
GPIO_SetBits(GPIOF, GPIO_Pin_8);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
led_toggle_state = 0;
|
||
|
/* turn the LED off */
|
||
|
GPIO_ResetBits(GPIOF, GPIO_Pin_8);
|
||
|
}
|
||
|
|
||
|
/* store toggle time to determine next toggle interval */
|
||
|
timer_counter_last = timer_counter_now;
|
||
|
} /*** end of LedToggle ***/
|
||
|
|
||
|
|
||
|
/*********************************** end of led.c **************************************/
|