From d65a758c316f32c8d50099aa301719d4e79fc9f7 Mon Sep 17 00:00:00 2001 From: andrey Date: Fri, 27 Feb 2026 15:38:07 +0300 Subject: [PATCH] add --- john103C6T6NewVer/Core/Src/main.c | 31 ++- john103C6T6NewVer/MDK-ARM/john103C6T6.uvoptx | 63 ++++-- john103C6T6NewVer/linkBlink/linkBlink.c | 199 +++++-------------- john103C6T6NewVer/linkBlink/linkBlink.h | 95 ++------- schem.pdsprj.DESKTOP-RQ2QP65.z.workspace | 4 +- 5 files changed, 144 insertions(+), 248 deletions(-) diff --git a/john103C6T6NewVer/Core/Src/main.c b/john103C6T6NewVer/Core/Src/main.c index 5b53c19..30fd375 100644 --- a/john103C6T6NewVer/Core/Src/main.c +++ b/john103C6T6NewVer/Core/Src/main.c @@ -46,7 +46,7 @@ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ - +#include "linkBlink.h" /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ @@ -133,10 +133,18 @@ int main(void) MX_TIM2_Init(); MX_ADC1_Init(); MX_I2C1_Init(); + // MX_RTC_Init(); /* USER CODE BEGIN 2 */ - - BufferState_t buffer_init(); + LED_BlinkRx_Config_t led_rx = + { + .port = GPIOC, + .pin = GPIO_PIN_13, + .blink_period = 10, // 100 мс + .blink_count = 2 // 3 мигания + }; + LED_BlinkRx_Init(&led_rx); + BufferState_t buffer_init(); led_blink(GPIOC, 13, rest_iter, reset_blink_delay); MODBUS_FirstInit(&hmodbus1, &mb_huart, &mb_htim); @@ -163,10 +171,21 @@ int main(void) /* USER CODE BEGIN WHILE */ while (1) { - - - + if (MB_DATA.Coils.reserve3[3]==1) + { + MB_DATA.Coils.reserve3[3]=0; + LED_BlinkRx_Init(&led_rx); + } +//////блинкер по приему RS + if (hmodbus1.f.blink==1) + { + hmodbus1.f.blink=0; + LED_BlinkRx_OnRx(); + } + LED_BlinkRx_Process(); +////// +////// запись во флэш if (MB_DATA.Coils.reserve3[0]==1) { MB_DATA.Coils.reserve3[0] = 0; diff --git a/john103C6T6NewVer/MDK-ARM/john103C6T6.uvoptx b/john103C6T6NewVer/MDK-ARM/john103C6T6.uvoptx index 626a087..9af9e4d 100644 --- a/john103C6T6NewVer/MDK-ARM/john103C6T6.uvoptx +++ b/john103C6T6NewVer/MDK-ARM/john103C6T6.uvoptx @@ -152,50 +152,82 @@ 0 0 - 180 + 109 1 -
134248318
+
0
0 0 0 0 0 - 1 - ../Core/Src/main.c + 0 + ..\Core\Inc\main.h - \\\../Core/Src/main.c\180 +
1 0 37 1 -
134247384
+
0
0 0 0 0 0 - 1 + 0 ..\EEPROM_Emul\src\flash_ring.c - \\john103C6T6\../EEPROM_Emul/src/flash_ring.c\37 +
2 0 - 175 + 139 1 -
134248290
+
0
0 0 0 0 0 - 1 + 0 ../Core/Src/main.c - \\john103C6T6\../Core/Src/main.c\175 + +
+ + 3 + 0 + 199 + 1 +
0
+ 0 + 0 + 0 + 0 + 0 + 0 + ../Core/Src/main.c + + +
+ + 4 + 0 + 191 + 1 +
0
+ 0 + 0 + 0 + 0 + 0 + 0 + ../Core/Src/main.c + +
@@ -339,6 +371,11 @@ 1 record + + 28 + 1 + led_rx,0x0A + @@ -1073,7 +1110,7 @@ 6 50 1 - 1 + 0 0 0 ..\linkBlink\linkBlink.c diff --git a/john103C6T6NewVer/linkBlink/linkBlink.c b/john103C6T6NewVer/linkBlink/linkBlink.c index 94da588..ab683f0 100644 --- a/john103C6T6NewVer/linkBlink/linkBlink.c +++ b/john103C6T6NewVer/linkBlink/linkBlink.c @@ -1,161 +1,58 @@ #include "linkBlink.h" -static uint32_t GetTick(LedBlinker_HandleTypeDef* hblinker) { - if (hblinker->htim != NULL) { - return __HAL_TIM_GET_COUNTER(hblinker->htim); - } - return HAL_GetTick(); // +/* */ +static LED_BlinkRx_Config_t led_cfg; + +/* */ +static uint32_t last_tick = 0; // +static uint8_t toggle_counter = 0; // +static uint8_t blinking = 0; // + + +/** + * @brief + */ +void LED_BlinkRx_Init(LED_BlinkRx_Config_t *cfg) +{ + led_cfg = *cfg; } -HAL_StatusTypeDef LedBlinker_Init(LedBlinker_HandleTypeDef* hblinker, - GPIO_TypeDef* led_port, uint16_t led_pin, - GPIO_TypeDef* de_re_port, uint16_t de_re_pin, - TIM_HandleTypeDef* htim) { - if (hblinker == NULL || led_port == NULL) { - return HAL_ERROR; - } - - // - hblinker->led_port = led_port; - hblinker->led_pin = led_pin; - hblinker->de_re_port = de_re_port; - hblinker->de_re_pin = de_re_pin; - hblinker->htim = htim; - hblinker->blink_duration = 100; - hblinker->last_blink_tick = 0; - hblinker->led_state = false; - hblinker->blinking = false; - hblinker->blink_count = 0; - hblinker->target_blink_count = 1; - hblinker->last_packet_tick = 0; - - // - GPIO_InitTypeDef GPIO_InitStruct = {0}; - GPIO_InitStruct.Pin = led_pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(led_port, &GPIO_InitStruct); - - // - HAL_GPIO_WritePin(led_port, led_pin, GPIO_PIN_RESET); - - // RS485 - if (de_re_port != NULL && de_re_pin != 0) { - GPIO_InitStruct.Pin = de_re_pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(de_re_port, &GPIO_InitStruct); - - // - HAL_GPIO_WritePin(de_re_port, de_re_pin, GPIO_PIN_RESET); - } - - return HAL_OK; + +/** + * @brief + */ +void LED_BlinkRx_OnRx(void) +{ + + blinking = 1; + toggle_counter = 0; + last_tick = HAL_GetTick(); } -void LedBlinker_Update(LedBlinker_HandleTypeDef* hblinker) { - if (hblinker == NULL || !hblinker->blinking) return; - - uint32_t current_tick = HAL_GetTick(); - - if ((current_tick - hblinker->last_blink_tick) >= hblinker->blink_duration) { - hblinker->last_blink_tick = current_tick; - - // - hblinker->led_state = !hblinker->led_state; - HAL_GPIO_WritePin(hblinker->led_port, hblinker->led_pin, - hblinker->led_state ? GPIO_PIN_SET : GPIO_PIN_RESET); - - // , - if (!hblinker->led_state) { - hblinker->blink_count++; - if (hblinker->blink_count >= hblinker->target_blink_count) { - hblinker->blinking = false; - HAL_GPIO_WritePin(hblinker->led_port, hblinker->led_pin, GPIO_PIN_RESET); - } + +/** + * @brief ( while(1)) + */ +void LED_BlinkRx_Process(void) +{ + if (!blinking) + return; + + /* */ + if (HAL_GetTick() - last_tick >= led_cfg.blink_period) + { + last_tick = HAL_GetTick(); + + /* */ + HAL_GPIO_TogglePin(led_cfg.port, led_cfg.pin); + toggle_counter++; + + /* = 2 ( + ) */ + if (toggle_counter >= led_cfg.blink_count * 2) + { + HAL_GPIO_WritePin(led_cfg.port, led_cfg.pin, GPIO_PIN_SET); + blinking = 0; } } -} - -void LedBlinker_ProcessPacket(LedBlinker_HandleTypeDef* hblinker, - uint8_t* data, uint16_t len) { - if (hblinker == NULL || data == NULL || len == 0) return; - - hblinker->last_packet_tick = HAL_GetTick(); - - // - if (len >= 1) { - // : - uint8_t blink_count = data[0]; - if (blink_count == 0) blink_count = 1; - if (blink_count > 20) blink_count = 20; // - - // ( ) - uint32_t duration = 100; - if (len >= 2) { - duration = 50 + (data[1] * 10); - if (duration > 1000) duration = 1000; - } - - LedBlinker_BlinkPattern(hblinker, blink_count, duration); - } - - // - if (len >= 4 && data[0] == 0xFF) { - // - LedBlinker_BlinkPattern(hblinker, 5, 50); - } -} - -void LedBlinker_BlinkOnce(LedBlinker_HandleTypeDef* hblinker, uint32_t duration) { - if (hblinker == NULL) return; - - hblinker->blink_duration = duration; - hblinker->target_blink_count = 1; - hblinker->blink_count = 0; - hblinker->blinking = true; - hblinker->led_state = false; - hblinker->last_blink_tick = GetTick(hblinker); - - // - HAL_GPIO_WritePin(hblinker->led_port, hblinker->led_pin, GPIO_PIN_SET); - hblinker->led_state = true; -} - -void LedBlinker_BlinkPattern(LedBlinker_HandleTypeDef* hblinker, - uint8_t count, uint32_t duration) { - if (hblinker == NULL || count == 0) return; - - hblinker->blink_duration = duration; - hblinker->target_blink_count = count; - hblinker->blink_count = 0; - hblinker->blinking = true; - hblinker->led_state = false; - hblinker->last_blink_tick = HAL_GetTick(); - - // - HAL_GPIO_WritePin(hblinker->led_port, hblinker->led_pin, GPIO_PIN_SET); - hblinker->led_state = true; -} - -void LedBlinker_SetRS485Mode(LedBlinker_HandleTypeDef* hblinker, bool transmit) { - if (hblinker == NULL || hblinker->de_re_port == NULL) return; - - HAL_GPIO_WritePin(hblinker->de_re_port, hblinker->de_re_pin, - transmit ? GPIO_PIN_SET : GPIO_PIN_RESET); -} - -bool LedBlinker_IsBlinking(LedBlinker_HandleTypeDef* hblinker) { - return (hblinker != NULL) ? hblinker->blinking : false; -} - -uint32_t LedBlinker_GetTimeSinceLastPacket(LedBlinker_HandleTypeDef* hblinker) { - if (hblinker == NULL) return 0; - - if (hblinker->last_packet_tick == 0) return 0; - - return GetTick(hblinker) - hblinker->last_packet_tick; } \ No newline at end of file diff --git a/john103C6T6NewVer/linkBlink/linkBlink.h b/john103C6T6NewVer/linkBlink/linkBlink.h index e3115fb..b59fe4b 100644 --- a/john103C6T6NewVer/linkBlink/linkBlink.h +++ b/john103C6T6NewVer/linkBlink/linkBlink.h @@ -1,90 +1,33 @@ -#ifndef LED_BLINKER_RS485_H -#define LED_BLINKER_RS485_H +#ifndef LED_BLINK_RX_H +#define LED_BLINK_RX_H -#include "stm32f1xx_hal.h" // -#include -#include - -typedef struct { - GPIO_TypeDef* led_port; // - uint16_t led_pin; // - GPIO_TypeDef* de_re_port; // RS485 (NULL ) - uint16_t de_re_pin; // RS485 - TIM_HandleTypeDef* htim; // - uint32_t blink_duration; // - uint32_t last_blink_tick; // ( ) - bool led_state; // - bool blinking; // - uint8_t blink_count; // - uint8_t target_blink_count; // - uint32_t last_packet_tick; // -} LedBlinker_HandleTypeDef; +#include "stm32f1xx_hal.h" // (stm32f4xx_hal.h ..) /** - * - * @param hblinker - - * @param led_port - - * @param led_pin - - * @param de_re_port - RS485 (NULL ) - * @param de_re_pin - RS485 - * @param htim - - * @return HAL_OK HAL_ERROR + * @brief */ -HAL_StatusTypeDef LedBlinker_Init(LedBlinker_HandleTypeDef* hblinker, - GPIO_TypeDef* led_port, uint16_t led_pin, - GPIO_TypeDef* de_re_port, uint16_t de_re_pin, - TIM_HandleTypeDef* htim); +typedef struct +{ + GPIO_TypeDef *port; // GPIO + uint16_t pin; // GPIO + + uint32_t blink_period; // () + uint8_t blink_count; // +} LED_BlinkRx_Config_t; /** - * ( ) - * @param hblinker - + * @brief */ -void LedBlinker_Update(LedBlinker_HandleTypeDef* hblinker); +void LED_BlinkRx_Init(LED_BlinkRx_Config_t *cfg); /** - * - * @param hblinker - - * @param data - - * @param len - + * @brief */ -void LedBlinker_ProcessPacket(LedBlinker_HandleTypeDef* hblinker, - uint8_t* data, uint16_t len); +void LED_BlinkRx_OnRx(void); /** - * - * @param hblinker - - * @param duration - + * @brief */ -void LedBlinker_BlinkOnce(LedBlinker_HandleTypeDef* hblinker, uint32_t duration); +void LED_BlinkRx_Process(void); -/** - * - * @param hblinker - - * @param count - - * @param duration - - */ -void LedBlinker_BlinkPattern(LedBlinker_HandleTypeDef* hblinker, - uint8_t count, uint32_t duration); - -/** - * RS485 - * @param hblinker - - * @param transmit - true , false - */ -void LedBlinker_SetRS485Mode(LedBlinker_HandleTypeDef* hblinker, bool transmit); - -/** - * , - * @param hblinker - - * @return true - */ -bool LedBlinker_IsBlinking(LedBlinker_HandleTypeDef* hblinker); - -/** - * - * @param hblinker - - * @return - */ -uint32_t LedBlinker_GetTimeSinceLastPacket(LedBlinker_HandleTypeDef* hblinker); - -#endif // LED_BLINKER_RS485_H \ No newline at end of file +#endif \ No newline at end of file diff --git a/schem.pdsprj.DESKTOP-RQ2QP65.z.workspace b/schem.pdsprj.DESKTOP-RQ2QP65.z.workspace index 4da3025..008131e 100644 --- a/schem.pdsprj.DESKTOP-RQ2QP65.z.workspace +++ b/schem.pdsprj.DESKTOP-RQ2QP65.z.workspace @@ -3,7 +3,7 @@ 2c0000000200000003000000ffffffffffffffffffffffffffffffff40000000670000008c080000bd050000 - + @@ -18,7 +18,7 @@ - +