158 lines
3.5 KiB
C
158 lines
3.5 KiB
C
/*
|
||
******************************************************************************
|
||
*
|
||
* @file led.c
|
||
* @brief led module
|
||
* @ic TP3102
|
||
*
|
||
* @version 1.0
|
||
* @date 2022/08/04 15:00:40
|
||
* @author Alex Xu
|
||
*
|
||
* Copyright (c) 2013-2099,Tkplusemi Technology Co.,Ltd.
|
||
* All Rights Reserved
|
||
*
|
||
* History:
|
||
* Revision Date Author Desc
|
||
* 1.0.0 2022/08/04 Alex build this file
|
||
******************************************************************************/
|
||
/*_____ I N C L U D E S ____________________________________________________*/
|
||
|
||
#include "led.h"
|
||
|
||
#if LED_DISPLAY
|
||
|
||
/******************************************************************************\
|
||
Macro definitions
|
||
\******************************************************************************/
|
||
|
||
/******************************************************************************\
|
||
Variables definitions
|
||
\******************************************************************************/
|
||
|
||
/******************************************************************************\
|
||
Functions definitions
|
||
\******************************************************************************/
|
||
#if 0
|
||
/*
|
||
* 函数名称 : LED_On
|
||
* 功能描述 : 点亮LED
|
||
* 参 数 : LED的ID
|
||
* 返回值 : NONE
|
||
*/
|
||
/******************************************************************************/
|
||
static void LED_On(uint8_t LedId)
|
||
/******************************************************************************/
|
||
{
|
||
switch(LedId)
|
||
{
|
||
case LED_R:
|
||
LEDR_ON();
|
||
break;
|
||
|
||
case LED_B:
|
||
LEDB_ON();
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
/*
|
||
* 函数名称 : LED_Off
|
||
* 功能描述 : 熄灭LED
|
||
* 参 数 : LED的ID
|
||
* 返回值 : NONE
|
||
*/
|
||
/******************************************************************************/
|
||
static void LED_Off(uint8_t LedId)
|
||
/******************************************************************************/
|
||
{
|
||
switch(LedId)
|
||
{
|
||
case LED_R:
|
||
LEDR_OFF();
|
||
break;
|
||
|
||
case LED_B:
|
||
LEDB_OFF();
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
#endif
|
||
|
||
#ifdef BREATHING_LIGHT
|
||
|
||
idata BRTH_LED_INFO BL_LED;
|
||
|
||
/*
|
||
* 函数名称 : LED_Breathing_Light
|
||
* 功能描述 : LED呼吸灯驱动,需放在100us时间片中,每20ms改变一次占空比。
|
||
模拟人体呼吸,吸气和呼气各占1.5s,人眼的图像滞留时间0.04s(1/24帧画面)
|
||
按最快0.04s(40ms)。亮20ms,灭20ms,人眼看到的应该是一直亮。
|
||
呼吸灯,就是改变这40ms中,亮和灭所占用的百分百。
|
||
1500/20=75个周期,40ms/75=266us。75个变化周期中,每个周期增长1个单位266us,
|
||
|
||
75个周期刚好是40ms,这样就能达到全亮,反之全灭。
|
||
* 参 数 : NONE
|
||
* 返回值 : NONE
|
||
*/
|
||
/******************************************************************************/
|
||
void LED_Breathing_Light(void)
|
||
/******************************************************************************/
|
||
{
|
||
if ( BL_LED.Breathing_Light_On )
|
||
{
|
||
if( BL_LED.BL_Timer <= BL_LED.BL_Flash_Duty )
|
||
{
|
||
LEDB_ON();
|
||
}
|
||
else
|
||
{
|
||
LEDB_OFF();
|
||
}
|
||
|
||
if( BL_LED.BL_Timer >= BL_DUTY_MAX )
|
||
{
|
||
BL_LED.BL_Timer = 0;
|
||
|
||
if(BL_LED.Flash_Duty_Declining)
|
||
{
|
||
BL_LED.BL_Flash_Duty -= BL_STEP;
|
||
}
|
||
else
|
||
if(BL_LED.Flash_Duty_Rising)
|
||
{
|
||
BL_LED.BL_Flash_Duty += BL_STEP;
|
||
}
|
||
}
|
||
|
||
if( BL_DUTY_MAX <= BL_LED.BL_Flash_Duty )
|
||
{
|
||
BL_LED.Flash_Duty_Declining = 1;
|
||
|
||
BL_LED.Flash_Duty_Rising = 0;
|
||
}
|
||
else
|
||
if( BL_LED.BL_Flash_Duty <= 1 )
|
||
{
|
||
BL_LED.Flash_Duty_Rising = 1;
|
||
|
||
BL_LED.Flash_Duty_Declining = 0;
|
||
}
|
||
}
|
||
|
||
BL_LED.BL_Timer += LED_PLUS_TIME;
|
||
}
|
||
|
||
#endif
|
||
|
||
#endif
|
||
|
||
|