From 206a710b0d204a724ff62348b8ecba841322b490 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Sun, 21 Jun 2026 21:46:38 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D1=81=D0=B8=D0=BD=D1=82=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8?= =?UTF-8?q?=D0=B1=D0=BA=D0=B8=20=D0=B8=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=BC?= =?UTF-8?q?=D0=B8=D0=BA=D1=80=D0=BE=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=BB=D0=BB=D0=B5=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Inc/DS_Button.h | 8 ++++++-- Src/DS_Button.c | 32 ++++++++++++++++---------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/Inc/DS_Button.h b/Inc/DS_Button.h index afed754..e5a1d07 100644 --- a/Inc/DS_Button.h +++ b/Inc/DS_Button.h @@ -7,6 +7,10 @@ #include "stm32g0xx_hal.h" #endif +#ifdef STM32G0B1xx + #include "stm32g0xx_hal.h" +#endif + #ifdef STM32F030xx #include "stm32f0xx_hal.h" #endif @@ -16,7 +20,7 @@ typedef struct DS_Button { GPIO_TypeDef* Port; uint16_t Pin; - bool Presed, Released, PresedLong, PresedLongLong; + bool Pressed, Released, PressedLong, PressedLongLong; uint32_t PrevTick, PressStartTick, PressStartTickLong; uint8_t Storage; @@ -38,6 +42,6 @@ bool DS_ButtonPressedLongLong(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 \ No newline at end of file diff --git a/Src/DS_Button.c b/Src/DS_Button.c index 138df20..395dc37 100644 --- a/Src/DS_Button.c +++ b/Src/DS_Button.c @@ -4,9 +4,9 @@ void DS_ButtonInit(DS_Button* Button, GPIO_TypeDef *Port, uint16_t Pin) { Button->Port = Port; Button->Pin = Pin; - Button->Presed = false; - Button->PresedLong = false; - Button->PresedLongLong = false; + Button->Pressed = false; + Button->PressedLong = false; + Button->PressedLongLong = false; Button->Released = false; Button->PrevTick = 0; Button->PressStartTick = 0; @@ -38,12 +38,12 @@ void DS_ButtonUpdate(DS_Button *Button) if (Button->PressStartTick == 0) Button->PressStartTick = CurrentTick; else if ((CurrentTick-Button->PressStartTick)>1000) - Button->PresedLong = true; + Button->PressedLong = true; if (Button->PressStartTickLong == 0) Button->PressStartTickLong = CurrentTick; else if ((CurrentTick-Button->PressStartTickLong)>5000) - Button->PresedLongLong = true; + Button->PressedLongLong = true; @@ -57,10 +57,10 @@ void DS_ButtonUpdate(DS_Button *Button) Button->Storage -=1; Button->PressStartTick = 0; - Button->PresedLong = false; + Button->PressedLong = false; Button->PressStartTickLong = 0; - Button->PresedLongLong = false; + Button->PressedLongLong = false; } switch (Button->Storage) @@ -70,16 +70,16 @@ void DS_ButtonUpdate(DS_Button *Button) { Button->FallingEdge = true; } - Button->Presed = false; + Button->Pressed = false; Button->Released = true; break; case 10: - if (Button->Presed == false) + if (Button->Pressed == false) { Button->RisingEdge = true; } - Button->Presed = true; + Button->Pressed = true; Button->Released = false; break; @@ -91,7 +91,7 @@ void DS_ButtonUpdate(DS_Button *Button) bool DS_ButtonPressed(DS_Button *Button) { - if (Button->Presed) + if (Button->Pressed) { return true; } @@ -109,9 +109,9 @@ bool DS_ButtonReleased(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; return true; } @@ -120,10 +120,10 @@ bool DS_ButtonPressedLong(DS_Button *Button) bool DS_ButtonPressedLongLong(DS_Button *Button) { - if (Button->PresedLongLong) + if (Button->PressedLongLong) { Button->PressStartTick = 0; - Button->PresedLongLong = false; + Button->PressedLongLong = false; Button->PressStartTickLong = Button->PressStartTickLong+500; return true; } @@ -140,7 +140,7 @@ bool DS_ButtonRisingEdge(DS_Button *Button) return false; } -bool DS_ButtonFalingEdge(DS_Button *Button) +bool DS_ButtonFallingEdge(DS_Button *Button) { if (Button->FallingEdge) {