/**
* @file LED_ATY.c
*
* @param Project DEVICE_GENERAL_ATY_LIB
*
* @author ATY
*
* @copyright
* - Copyright 2017 - 2023 MZ-ATY
* - This code follows:
* - MZ-ATY Various Contents Joint Statement -
*
* https://mengze.top/MZ-ATY_VCJS
* - CC 4.0 BY-NC-SA -
*
* https://creativecommons.org/licenses/by-nc-sa/4.0/
* - Your use will be deemed to have accepted the terms of this statement.
*
* @brief functions of LED for all embedded device
*
* @version
* - 1_01_220901 > ATY
* -# Preliminary version, first Release
********************************************************************************
*/
#ifndef __LED_ATY_C
#define __LED_ATY_C
#include "LED_ATY.h"
/******************************* For user *************************************/
/******************************************************************************/
uint32_t ledBlinkStep = 0;
uint8_t ledBlinkType = 20;
/**
* @brief set sysled blink ledBlinkType
* @note put this function at timer IT callback, change
* @note 1: light on and off cycle
* 10: light on and off cycle long time ver
* 2: light on blink twice
* 20: light off blink twice
* 3: light on blink thrice
* 30: light off blink thrice
* 40: breath
* @note if(ledBlinkType - 40 >= 10) at large time cycle
* if(ledBlinkType - 40 < 10) at small time cycle(breath type is 40-49)
*/
void SysLedBlink(void)
{
static uint8_t ledBlinkLastType = 0;
if(ledBlinkLastType != ledBlinkType)
{
ledBlinkLastType = ledBlinkType;
ledBlinkStep = 0;
}
if(ledBlinkType == 1)
{
if(ledBlinkStep == 0)
{
ledBlinkStep = 1;
GPIO_SET_L(SYSLED_PORT, SYSLED_PIN);
}
else if(ledBlinkStep != 0)
{
ledBlinkStep = 0;
GPIO_SET_H(SYSLED_PORT, SYSLED_PIN);
#ifdef __DEBUG_LED_ATY
// printf("\r\nSysLed Blink.");
#endif /* __DEBUG_LED_ATY */
}
}
else if(ledBlinkType == 10)
{
ledBlinkStep++;
if(ledBlinkStep < 10)
GPIO_SET_L(SYSLED_PORT, SYSLED_PIN);
else if(ledBlinkStep >= 10 && ledBlinkStep < 20)
GPIO_SET_H(SYSLED_PORT, SYSLED_PIN);
else
{
ledBlinkStep = 0;
}
}
// Type 2 & 3 put at short timer is better, like 100ms
else if(ledBlinkType == 2)
{
if(ledBlinkStep == 0)
{
ledBlinkStep = 1;
GPIO_SET_L(SYSLED_PORT, SYSLED_PIN);
}
else if(ledBlinkStep == 1)
{
ledBlinkStep = 2;
GPIO_SET_H(SYSLED_PORT, SYSLED_PIN);
}
else if(ledBlinkStep == 2)
{
ledBlinkStep = 3;
GPIO_SET_L(SYSLED_PORT, SYSLED_PIN);
}
else if(ledBlinkStep == 3)
{
ledBlinkStep = 4;
GPIO_SET_H(SYSLED_PORT, SYSLED_PIN);
}
else if((ledBlinkStep >= 4) && (ledBlinkStep < LED_LONG_STEPS))
{
ledBlinkStep++;
}
else if(ledBlinkStep == LED_LONG_STEPS)
{
ledBlinkStep = 0;
#ifdef __DEBUG_LED_ATY
// printf("\r\nSysLed Blink.");
#endif /* __DEBUG_LED_ATY */
}
}
else if(ledBlinkType == 20)
{
if(ledBlinkStep == 0)
{
ledBlinkStep = 1;
GPIO_SET_H(SYSLED_PORT, SYSLED_PIN);
}
else if(ledBlinkStep == 1)
{
ledBlinkStep = 2;
GPIO_SET_L(SYSLED_PORT, SYSLED_PIN);
}
else if(ledBlinkStep == 2)
{
ledBlinkStep = 3;
GPIO_SET_H(SYSLED_PORT, SYSLED_PIN);
}
else if(ledBlinkStep == 3)
{
ledBlinkStep = 4;
GPIO_SET_L(SYSLED_PORT, SYSLED_PIN);
}
else if((ledBlinkStep >= 4) && (ledBlinkStep < LED_LONG_STEPS))
{
ledBlinkStep++;
}
else if(ledBlinkStep == LED_LONG_STEPS)
{
ledBlinkStep = 0;
#ifdef __DEBUG_LED_ATY
// printf("\r\nSysLed Blink.");
#endif /* __DEBUG_LED_ATY */
}
}
else if(ledBlinkType == 3)
{
if(ledBlinkStep == 0)
{
ledBlinkStep = 1;
GPIO_SET_L(SYSLED_PORT, SYSLED_PIN);
}
else if(ledBlinkStep == 1)
{
ledBlinkStep = 2;
GPIO_SET_H(SYSLED_PORT, SYSLED_PIN);
}
else if(ledBlinkStep == 2)
{
ledBlinkStep = 3;
GPIO_SET_L(SYSLED_PORT, SYSLED_PIN);
}
else if(ledBlinkStep == 3)
{
ledBlinkStep = 4;
GPIO_SET_H(SYSLED_PORT, SYSLED_PIN);
}
else if(ledBlinkStep == 4)
{
ledBlinkStep = 5;
GPIO_SET_L(SYSLED_PORT, SYSLED_PIN);
}
else if(ledBlinkStep == 5)
{
ledBlinkStep = 6;
GPIO_SET_H(SYSLED_PORT, SYSLED_PIN);
}
else if((ledBlinkStep >= 6) && (ledBlinkStep < LED_LONG_STEPS))
{
ledBlinkStep++;
}
else if(ledBlinkStep == LED_LONG_STEPS)
{
ledBlinkStep = 0;
#ifdef __DEBUG_LED_ATY
// printf("\r\nSysLed Blink.");
#endif /* __DEBUG_LED_ATY */
}
}
else if(ledBlinkType == 30)
{
if(ledBlinkStep == 0)
{
ledBlinkStep = 1;
GPIO_SET_H(SYSLED_PORT, SYSLED_PIN);
}
else if(ledBlinkStep == 1)
{
ledBlinkStep = 2;
GPIO_SET_L(SYSLED_PORT, SYSLED_PIN);
}
else if(ledBlinkStep == 2)
{
ledBlinkStep = 3;
GPIO_SET_H(SYSLED_PORT, SYSLED_PIN);
}
else if(ledBlinkStep == 3)
{
ledBlinkStep = 4;
GPIO_SET_L(SYSLED_PORT, SYSLED_PIN);
}
else if(ledBlinkStep == 4)
{
ledBlinkStep = 5;
GPIO_SET_H(SYSLED_PORT, SYSLED_PIN);
}
else if(ledBlinkStep == 5)
{
ledBlinkStep = 6;
GPIO_SET_L(SYSLED_PORT, SYSLED_PIN);
}
else if((ledBlinkStep >= 6) && (ledBlinkStep < LED_LONG_STEPS))
{
ledBlinkStep++;
}
else if(ledBlinkStep == LED_LONG_STEPS)
{
ledBlinkStep = 0;
#ifdef __DEBUG_LED_ATY
// printf("\r\nSysLed Blink.");
#endif /* __DEBUG_LED_ATY */
}
}
else if(ledBlinkType == 40) // put at 1ms cycle, cycle more faster, led animation more breathly
{
// ms when cycle is 1ms // 3000 at 1ms cycle, 60000 at 24MHz main while cycle
#define FLOW_CYCLE_COUNT ((uint32_t)60000)
// #define FLOW_CYCLE_COUNT (3000)
// led brghtness split // 10 at 1ms cycle, 1000 at 24MHz main while cycle
#define ONE_PULSE_COUNT (60)
// #define ONE_PULSE_COUNT (10)
static uint16_t cycleCount = 0;
if(cycleCount < ONE_PULSE_COUNT)
cycleCount++;
else
cycleCount = 0;
ledBlinkStep++;
// UartSendFloatStr(cycleCount);
if(ledBlinkStep < FLOW_CYCLE_COUNT){
if(cycleCount < (ONE_PULSE_COUNT * ledBlinkStep / FLOW_CYCLE_COUNT))
GPIO_SET_H(SYSLED_PORT, SYSLED_PIN);
else
GPIO_SET_L(SYSLED_PORT, SYSLED_PIN);
}
else if(ledBlinkStep >= FLOW_CYCLE_COUNT && ledBlinkStep < FLOW_CYCLE_COUNT * 2){
if(cycleCount < (ONE_PULSE_COUNT * (ledBlinkStep - FLOW_CYCLE_COUNT) / FLOW_CYCLE_COUNT))
GPIO_SET_L(SYSLED_PORT, SYSLED_PIN);
else
GPIO_SET_H(SYSLED_PORT, SYSLED_PIN);
}
if(ledBlinkStep >= FLOW_CYCLE_COUNT * 2)
ledBlinkStep = 0;
}
}
#endif /* __LED_ATY_C */
/******************************** End Of File *********************************/