| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- /**
- * @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 -
- * <a href="https://mengze.top/MZ-ATY_VCJS">
- * https://mengze.top/MZ-ATY_VCJS</a>
- * - CC 4.0 BY-NC-SA -
- * <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
- * https://creativecommons.org/licenses/by-nc-sa/4.0/</a>
- * - 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 = 0;
- /**
- * @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 *********************************/
|