Compare commits

9 Commits
4 changed files with 64 additions and 34 deletions
+1
View File
@@ -0,0 +1 @@
7e6b20c14c052ef4a32f478ba39d7658f0e70101
+19
View File
@@ -0,0 +1,19 @@
# 🤖 Технический контекст проекта (Сгенерировано ИИ)
### README для репозитория
**1. Краткое назначение проекта.**
Проект содержит исходный файл `DS_Button.c`, предназначенный для разработки функциональности кнопки в системе.
**2. Тип стека.**
Стек относится к библиотеке пользовательского интерфейса или компонентов (UI/UX).
**3. Архитектурный разбор:**
- **Файл `DS_Button.c`**: содержит реализацию функционала, связанного с работой кнопки в системе.
<!-- USER_CUSTOM_CONTEXT_START -->
# ✍️ Заметки разработчика
*Допишите сюда свои требования, и ИИ учтет их при следующем запуске*
+15 -3
View File
@@ -2,13 +2,25 @@
#define DS_BUTTON_H #define DS_BUTTON_H
#include <stdbool.h> #include <stdbool.h>
#include "stm32f0xx_hal.h"
#ifdef STM32G030xx
#include "stm32g0xx_hal.h"
#endif
#ifdef STM32G0B1xx
#include "stm32g0xx_hal.h"
#endif
#ifdef STM32F030xx
#include "stm32f0xx_hal.h"
#endif
typedef struct DS_Button typedef struct DS_Button
{ {
GPIO_TypeDef* Port; GPIO_TypeDef* Port;
uint16_t Pin; uint16_t Pin;
bool Presed, Released, PresedLong, PresedLongLong; bool Pressed, Released, PressedLong, PressedLongLong;
uint32_t PrevTick, PressStartTick, PressStartTickLong; uint32_t PrevTick, PressStartTick, PressStartTickLong;
uint8_t Storage; uint8_t Storage;
@@ -30,6 +42,6 @@ bool DS_ButtonPressedLongLong(DS_Button* Button);
bool DS_ButtonRisingEdge(DS_Button* Button); bool DS_ButtonRisingEdge(DS_Button* Button);
bool DS_ButtonFalingEdge(DS_Button* Button); bool DS_ButtonFallingEdge(DS_Button* Button);
#endif //DS_BUTTON_H #endif //DS_BUTTON_H
+28 -30
View File
@@ -1,24 +1,22 @@
#include "../inc/DS_Button.h" #include "../inc/DS_Button.h"
void DS_ButtonInit(DS_Button* Button, GPIO_TypeDef *Port, uint16_t Pin) void DS_ButtonInit(DS_Button *Button, GPIO_TypeDef *Port, uint16_t Pin) {
{ Button->Port = Port;
Button->Port = Port; Button->Pin = Pin;
Button->Pin = Pin; Button->Pressed = false;
Button->Presed = false; Button->PressedLong = false;
Button->PresedLong = false; Button->PressedLongLong = false;
Button->PresedLongLong = false; Button->Released = false;
Button->Released = false; Button->PrevTick = 0;
Button->PrevTick = 0; Button->PressStartTick = 0;
Button->PressStartTick = 0; Button->PressStartTickLong = 0;
Button->PressStartTickLong = 0; Button->Storage = 5; // Начальное среднее положение для стабилизации
Button->Storage = 5;
Button->FallingEdge = false; Button->FallingEdge = false;
Button->RisingEdge = false; Button->RisingEdge = false;
} }
void DS_ButtonUpdate(DS_Button *Button) void DS_ButtonUpdate(DS_Button * Button) {
{
uint32_t CurrentTick = HAL_GetTick(); uint32_t CurrentTick = HAL_GetTick();
if ((CurrentTick - Button->PrevTick) < 10) if ((CurrentTick - Button->PrevTick) < 10)
return; return;
@@ -31,19 +29,19 @@ void DS_ButtonUpdate(DS_Button *Button)
{ {
if (Button->Storage == 0) if (Button->Storage == 0)
Button->Storage +=5; Button->Storage +=5;
else if (Button->Storage <= 10) else if (Button->Storage < 10)
Button->Storage +=1; Button->Storage +=1;
if (Button->PressStartTick == 0) if (Button->PressStartTick == 0)
Button->PressStartTick = CurrentTick; Button->PressStartTick = CurrentTick;
else if ((CurrentTick-Button->PressStartTick)>1000) else if ((CurrentTick-Button->PressStartTick)>1000)
Button->PresedLong = true; Button->PressedLong = true;
if (Button->PressStartTickLong == 0) if (Button->PressStartTickLong == 0)
Button->PressStartTickLong = CurrentTick; Button->PressStartTickLong = CurrentTick;
else if ((CurrentTick-Button->PressStartTickLong)>5000) else if ((CurrentTick-Button->PressStartTickLong)>5000)
Button->PresedLongLong = true; Button->PressedLongLong = true;
@@ -57,10 +55,10 @@ void DS_ButtonUpdate(DS_Button *Button)
Button->Storage -=1; Button->Storage -=1;
Button->PressStartTick = 0; Button->PressStartTick = 0;
Button->PresedLong = false; Button->PressedLong = false;
Button->PressStartTickLong = 0; Button->PressStartTickLong = 0;
Button->PresedLongLong = false; Button->PressedLongLong = false;
} }
switch (Button->Storage) switch (Button->Storage)
@@ -70,16 +68,16 @@ void DS_ButtonUpdate(DS_Button *Button)
{ {
Button->FallingEdge = true; Button->FallingEdge = true;
} }
Button->Presed = false; Button->Pressed = false;
Button->Released = true; Button->Released = true;
break; break;
case 10: case 10:
if (Button->Presed == false) if (Button->Pressed == false)
{ {
Button->RisingEdge = true; Button->RisingEdge = true;
} }
Button->Presed = true; Button->Pressed = true;
Button->Released = false; Button->Released = false;
break; break;
@@ -91,7 +89,7 @@ void DS_ButtonUpdate(DS_Button *Button)
bool DS_ButtonPressed(DS_Button *Button) bool DS_ButtonPressed(DS_Button *Button)
{ {
if (Button->Presed) if (Button->Pressed)
{ {
return true; return true;
} }
@@ -109,9 +107,9 @@ bool DS_ButtonReleased(DS_Button *Button)
bool DS_ButtonPressedLong(DS_Button *Button) bool DS_ButtonPressedLong(DS_Button *Button)
{ {
if (Button->PresedLong) if (Button->PressedLong)
{ {
Button->PresedLong = false; Button->PressedLong = false;
Button->PressStartTick = Button->PressStartTick + 500; Button->PressStartTick = Button->PressStartTick + 500;
return true; return true;
} }
@@ -120,10 +118,10 @@ bool DS_ButtonPressedLong(DS_Button *Button)
bool DS_ButtonPressedLongLong(DS_Button *Button) bool DS_ButtonPressedLongLong(DS_Button *Button)
{ {
if (Button->PresedLongLong) if (Button->PressedLongLong)
{ {
Button->PressStartTick = 0; Button->PressStartTick = 0;
Button->PresedLongLong = false; Button->PressedLongLong = false;
Button->PressStartTickLong = Button->PressStartTickLong+500; Button->PressStartTickLong = Button->PressStartTickLong+500;
return true; return true;
} }
@@ -140,7 +138,7 @@ bool DS_ButtonRisingEdge(DS_Button *Button)
return false; return false;
} }
bool DS_ButtonFalingEdge(DS_Button *Button) bool DS_ButtonFallingEdge(DS_Button *Button)
{ {
if (Button->FallingEdge) if (Button->FallingEdge)
{ {