JY vor 3 Monaten
Ursprung
Commit
f01d31c843
5 geänderte Dateien mit 239 neuen und 9 gelöschten Zeilen
  1. 6 6
      HW_UART_ATY.c
  2. 6 1
      IAP_YMODEM_ATY.c
  3. 2 2
      IAP_YMODEM_ATY.h
  4. 148 0
      LED_BREATH_ATY.c
  5. 77 0
      LED_BREATH_ATY.h

+ 6 - 6
HW_UART_ATY.c

@@ -140,7 +140,7 @@ void UartSendFloatStr(float dataFloat, uint8_t DECIMALS_NUM, struct HW_UART_ATY_
     uint32_t integerPart, decimalPart;
     uint32_t power10 = 1;  // Used to compute 10^DECIMALS_NUM
     uint8_t i;
-    
+
     // Handle negative numbers
     if (dataFloat < 0) {
         UartSendByte('-', dev);
@@ -180,7 +180,7 @@ void UartSendFloatStr(float dataFloat, uint8_t DECIMALS_NUM, struct HW_UART_ATY_
 
         // Handle leading zeros in the decimal part
         for (i = DECIMALS_NUM - 1; i > 0; i--) {
-            if (decimalPart < power10 / 10) { 
+            if (decimalPart < power10 / 10) {
                 UartSendByte('0', dev);  // Send leading zeros
                 power10 /= 10;
             }
@@ -338,10 +338,10 @@ FILE __stdout;
 PUTCHAR_PROTOTYPE \
 {
 #ifdef LL
-    LL_USART_TransmitData8(PRINTF_UART, ch);
-    while(!LL_USART_IsActiveFlag_TC(PRINTF_UART)){}
+    // LL_USART_TransmitData8(PRINTF_UART, ch);
+    // while(!LL_USART_IsActiveFlag_TC(PRINTF_UART)){}
 #else
-    HAL_UART_Transmit(&PRINTF_UART, (uint8_t*)&ch, 1, 0xFFFF);
+    // HAL_UART_Transmit(&PRINTF_UART, (uint8_t*)&ch, 1, 0xFFFF);
 #endif
     return ch;
 }
@@ -349,7 +349,7 @@ PUTCHAR_PROTOTYPE \
 GETCHAR_PROTOTYPE \
 {
     uint8_t ch = 0;
-    HAL_UART_Receive(&PRINTF_UART, &ch, 1, 0xFFFF);
+    // HAL_UART_Receive(&PRINTF_UART, &ch, 1, 0xFFFF);
     return ch;
 }
 #endif /* PLATFORM */

+ 6 - 1
IAP_YMODEM_ATY.c

@@ -294,9 +294,13 @@ void Main_Menu(void)
     }
 }
 
+#include "rtc.h"
 void Main_Cycle(void)
 {
     uint8_t sKey[2] = {0};
+    HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR1, 101);
+    HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR2, 250);
+    HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR3, 705);
     Interface_PutString("\r\n\r\nS to start\r\n\r\n");
     while(1)
     {
@@ -304,7 +308,7 @@ void Main_Cycle(void)
         if(hcdc->RxLength > 1024){
             uint8_t t[1] = {0};
             Interface_Receive(t, 1, 10);
-            continue; 
+            continue;
         }
         #endif
         if(1)
@@ -320,6 +324,7 @@ void Main_Cycle(void)
                         Interface_PutString("\r\nStart program execution...\r\n");
                         JumpToAppWithReset();
                     }
+                   
                     else if(sKey[1] == '1'){
                         Interface_Clean();
                         if(Interface_Download() != COM_OK){

+ 2 - 2
IAP_YMODEM_ATY.h

@@ -46,8 +46,8 @@
 // #endif
 
 #ifndef IAP_S_TIME
-//#define IAP_S_TIME RX_TIMEOUT
- #define IAP_S_TIME 1000
+#define IAP_S_TIME RX_TIMEOUT
+// #define IAP_S_TIME 1000
 #endif
 #ifndef IAP_3_TIME
 #define IAP_3_TIME 5000

+ 148 - 0
LED_BREATH_ATY.c

@@ -0,0 +1,148 @@
+/**
+* @file LED_BREATH_ATY.c
+*
+* @param Project DEVICE_GENERAL_ATY_LIB
+*
+* @author ATY
+*
+* @copyright
+*       - Copyright 2017 - 2025 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_250814 > ATY
+*           -# Preliminary version, first Release
+********************************************************************************
+*/
+
+#ifndef __LED_BREATH_ATY_C
+#define __LED_BREATH_ATY_C
+
+#include "LED_BREATH_ATY.h"
+
+/******************************* For user *************************************/
+
+/******************************************************************************/
+
+
+void SetLedBreathMode(struct LED_BREATH_ATY_Dev* dev, LedBreathMode_t mode)
+{
+    dev->breathMode = mode;
+    dev->breathTimer = 0;
+    dev->breathDir = 1;
+    dev->breathVal = 0;
+
+    dev->breathPauseCnt = 0;
+}
+
+void LedBreath(struct LED_BREATH_ATY_Dev* dev)
+{
+    dev->breathUpdate = 0;
+    dev->breathTimer++;
+
+    switch(dev->breathMode)
+    {
+        case BREATH_MODE_SMOOTH:
+            if(dev->breathTimer >= BREATH_LED_SPEED_MID * 2) { dev->breathUpdate = 1; }
+            break;
+        case BREATH_MODE_STEP:
+            if(dev->breathTimer >= BREATH_LED_SPEED_MID * 2) { dev->breathStep = 10; dev->breathUpdate = 1; }
+            break;
+        case BREATH_MODE_FAST:
+            if(dev->breathTimer >= BREATH_LED_SPEED_MID / 4) { dev->breathUpdate = 1; }
+            break;
+        case BREATH_MODE_SLOW:
+            if(dev->breathTimer >= BREATH_LED_SPEED_MID * 4) { dev->breathUpdate = 1; }
+            break;
+        case BREATH_MODE_PAUSE_TOP:
+            if(dev->breathTimer >= BREATH_LED_SPEED_MID * 2) { dev->breathUpdate = 1; }
+            if(dev->breathVal == dev->breathMax && dev->breathPauseCnt < 10) {
+                dev->breathPauseCnt++;
+                dev->breathUpdate = 0;
+            }
+            else if(dev->breathVal == dev->breathMax) {
+                dev->breathPauseCnt = 0;
+            }
+            break;
+        case BREATH_MODE_PAUSE_BOTTOM:
+            if(dev->breathTimer >= BREATH_LED_SPEED_MID * 2) { dev->breathUpdate = 1; }
+            if(dev->breathVal == dev->breathMin && dev->breathPauseCnt < 10) {
+                dev->breathPauseCnt++;
+                dev->breathUpdate = 0;
+            }
+            else if(dev->breathVal == dev->breathMin) {
+                dev->breathPauseCnt = 0;
+            }
+            break;
+        case BREATH_MODE_PULSE:
+            if(dev->breathDir == -1){
+                dev->breathVal = 1;
+                dev->breathUpdate = 1;
+            }
+            else{
+                if(dev->breathTimer >= BREATH_LED_SPEED_MID * 2) { dev->breathUpdate = 1; }
+            }
+
+        default:
+            if(dev->breathTimer >= BREATH_LED_SPEED_MID * 2) { dev->breathUpdate = 1; }
+            break;
+    }
+
+    if(dev->breathUpdate) {
+        dev->breathTimer = 0;
+        dev->breathVal += (dev->breathDir * dev->breathStep);
+
+        if(dev->breathVal >= dev->breathMax) {
+            dev->breathVal = dev->breathMax;
+            dev->breathDir = -1;
+        }
+        else if(dev->breathVal <= dev->breathMin) {
+            dev->breathVal = dev->breathMin;
+            dev->breathDir = 1;
+        }
+
+        dev->pwmSet(dev->breathVal);
+    }
+
+}
+
+#endif /* __LED_BREATH_ATY_C */
+
+/************************************ etc *************************************/
+/* init */
+// void LED_1_Breath_PWM_SET(uint8_t breathVal){
+//     // __HAL_TIM_SET_COUNTER(&htim2, 0);
+//     __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_2, breathVal * 65535 / 100);
+// }
+// struct LED_BREATH_ATY_Dev LED_BREATH_ATY_t_2 = {
+//     .breathMode = BREATH_MODE_FAST,
+//     .breathTimer = 0,
+//     .breathDir = 1,
+//     .breathVal = 0,
+//     .breathPauseCnt = 0,
+//     .breathStep = 1,
+//     .breathMax = BREATH_LED_MAX,
+//     .breathMin = BREATH_LED_MIN,
+//     .breathUpdate = 0,
+//     .pwmSet = LED_2_Breath_PWM_SET,
+//     .lock = _ATY_UNLOCKED,
+//     .debugEnable = 0,
+//     .LOG = printf
+// };
+
+/* use */
+// LedBreath(&LED_BREATH_ATY_t_1); // put at 1ms cycle
+
+/******************************************************************************/
+
+
+/******************************** End Of File *********************************/

+ 77 - 0
LED_BREATH_ATY.h

@@ -0,0 +1,77 @@
+/**
+* @file LED_BREATH_ATY.h
+*
+* @param Project DEVICE_GENERAL_ATY_LIB
+*
+* @author ATY
+*
+* @copyright
+*       - Copyright 2017 - 2025 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_250814 > ATY
+*           -# Preliminary version, first Release
+********************************************************************************
+*/
+
+#ifndef __LED_BREATH_ATY_H
+#define __LED_BREATH_ATY_H
+
+#include "INCLUDE_ATY.h"
+
+/******************************* For user *************************************/
+#define BREATH_LED_MAX 100      // LED最大亮度
+#define BREATH_LED_MIN 50        // LED最小亮度
+#define BREATH_LED_MID (BREATH_LED_MIN + ((BREATH_LED_MAX - BREATH_LED_MIN) / 2))        // LED中等亮度
+#define BREATH_LED_SPEED_MID 30 // LED中等速度
+
+
+/******************************************************************************/
+typedef enum {
+    BREATH_MODE_SMOOTH,         // 平滑呼吸
+    BREATH_MODE_STEP,           // 阶梯呼吸
+    BREATH_MODE_FAST,           // 快速呼吸
+    BREATH_MODE_SLOW,           // 慢速呼吸
+    BREATH_MODE_PAUSE_TOP,      // 顶部停顿
+    BREATH_MODE_PAUSE_BOTTOM,   // 底部停顿
+    BREATH_MODE_PULSE           // 突然亮起
+} LedBreathMode_t;
+
+struct LED_BREATH_ATY_Dev
+{
+    LedBreathMode_t breathMode;
+    uint32_t breathTimer;
+    int8_t breathDir;
+    uint8_t breathVal;
+
+    uint8_t breathPauseCnt;
+
+    uint8_t breathStep;
+    uint8_t breathMax;
+    uint8_t breathMin;
+    uint8_t breathUpdate;
+
+    void (*pwmSet)(uint8_t breathVal);
+
+    uint8_t lock;
+    uint8_t debugEnable;
+    void (*LOG)(const char*, ...);
+};
+
+void LedBreath(struct LED_BREATH_ATY_Dev* dev);
+void SetLedBreathMode(struct LED_BREATH_ATY_Dev* dev, LedBreathMode_t mode);
+
+
+#endif /* __LED_BREATH_ATY_H */
+
+/******************************** End Of File *********************************/