From 23598a80db110a63978c87094038fca8921af45e Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 15 Apr 2024 20:53:59 +0300 Subject: [PATCH] version 1 --- .mxproject | 16 ++--- .vscode/settings.json | 5 ++ Core/Inc/DS_Button.h | 26 ++++++++ Core/Inc/main.h | 2 + Core/Src/DS_Button.c | 101 +++++++++++++++++++++++++++++++ Core/Src/main.c | 58 +++++++----------- LedBlinking.ioc | 14 +++-- cmake/stm32cubemx/CMakeLists.txt | 1 + 8 files changed, 175 insertions(+), 48 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 Core/Inc/DS_Button.h create mode 100644 Core/Src/DS_Button.c diff --git a/.mxproject b/.mxproject index 1634b62..a3fc5ad 100644 --- a/.mxproject +++ b/.mxproject @@ -1,3 +1,11 @@ +[PreviousLibFiles] +LibFiles=Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_tim.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_tim_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_rcc.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_rcc.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_rcc_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_bus.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_crs.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_system.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_utils.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_def.h;Drivers\STM32F0xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_i2c.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_i2c_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_gpio.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_gpio_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_gpio.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_dma_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_dma.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_dma.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_cortex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_cortex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_pwr.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_pwr_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_pwr.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_flash.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_flash_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_exti.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_exti.h;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_tim.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_tim_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_rcc.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_rcc_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_i2c.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_i2c_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_gpio.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_dma.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_cortex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_pwr.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_pwr_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_flash.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_flash_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_exti.c;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_tim.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_tim_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_rcc.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_rcc.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_rcc_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_bus.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_crs.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_system.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_utils.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_def.h;Drivers\STM32F0xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_i2c.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_i2c_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_gpio.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_gpio_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_gpio.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_dma_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_dma.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_dma.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_cortex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_cortex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_pwr.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_pwr_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_pwr.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_flash.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_flash_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_exti.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_exti.h;Drivers\CMSIS\Device\ST\STM32F0xx\Include\stm32f030x6.h;Drivers\CMSIS\Device\ST\STM32F0xx\Include\stm32f0xx.h;Drivers\CMSIS\Device\ST\STM32F0xx\Include\system_stm32f0xx.h;Drivers\CMSIS\Device\ST\STM32F0xx\Source\Templates\system_stm32f0xx.c;Drivers\CMSIS\Include\cmsis_armcc.h;Drivers\CMSIS\Include\cmsis_armclang.h;Drivers\CMSIS\Include\cmsis_compiler.h;Drivers\CMSIS\Include\cmsis_gcc.h;Drivers\CMSIS\Include\cmsis_iccarm.h;Drivers\CMSIS\Include\cmsis_version.h;Drivers\CMSIS\Include\core_armv8mbl.h;Drivers\CMSIS\Include\core_armv8mml.h;Drivers\CMSIS\Include\core_cm0.h;Drivers\CMSIS\Include\core_cm0plus.h;Drivers\CMSIS\Include\core_cm1.h;Drivers\CMSIS\Include\core_cm23.h;Drivers\CMSIS\Include\core_cm3.h;Drivers\CMSIS\Include\core_cm33.h;Drivers\CMSIS\Include\core_cm4.h;Drivers\CMSIS\Include\core_cm7.h;Drivers\CMSIS\Include\core_sc000.h;Drivers\CMSIS\Include\core_sc300.h;Drivers\CMSIS\Include\mpu_armv7.h;Drivers\CMSIS\Include\mpu_armv8.h;Drivers\CMSIS\Include\tz_context.h; + +[PreviousUsedCMakes] +SourceFiles=Core\Src\main.c;Core\Src\stm32f0xx_it.c;Core\Src\stm32f0xx_hal_msp.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_tim.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_tim_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_rcc.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_rcc_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_i2c.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_i2c_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_gpio.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_dma.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_cortex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_pwr.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_pwr_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_flash.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_flash_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_exti.c;Drivers\CMSIS\Device\ST\STM32F0xx\Source\Templates\system_stm32f0xx.c;Core\Src\system_stm32f0xx.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_tim.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_tim_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_rcc.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_rcc_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_i2c.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_i2c_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_gpio.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_dma.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_cortex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_pwr.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_pwr_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_flash.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_flash_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_exti.c;Drivers\CMSIS\Device\ST\STM32F0xx\Source\Templates\system_stm32f0xx.c;Core\Src\system_stm32f0xx.c;;; +HeaderPath=Drivers\STM32F0xx_HAL_Driver\Inc;Drivers\STM32F0xx_HAL_Driver\Inc\Legacy;Drivers\CMSIS\Device\ST\STM32F0xx\Include;Drivers\CMSIS\Include;Core\Inc; +CDefines=USE_HAL_DRIVER;STM32F030x6;USE_HAL_DRIVER;USE_HAL_DRIVER; + [PreviousGenFiles] AdvancedFolderStructure=true HeaderFileListSize=3 @@ -15,11 +23,3 @@ SourceFolderListSize=1 SourcePath#0=..\Core\Src SourceFiles=; -[PreviousLibFiles] -LibFiles=Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_tim.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_tim_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_rcc.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_rcc.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_rcc_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_bus.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_crs.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_system.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_utils.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_def.h;Drivers\STM32F0xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_i2c.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_i2c_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_gpio.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_gpio_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_gpio.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_dma_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_dma.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_dma.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_cortex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_cortex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_pwr.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_pwr_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_pwr.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_flash.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_flash_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_exti.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_exti.h;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_tim.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_tim_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_rcc.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_rcc_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_i2c.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_i2c_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_gpio.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_dma.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_cortex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_pwr.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_pwr_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_flash.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_flash_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_exti.c;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_tim.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_tim_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_rcc.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_rcc.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_rcc_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_bus.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_crs.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_system.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_utils.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_def.h;Drivers\STM32F0xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_i2c.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_i2c_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_gpio.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_gpio_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_gpio.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_dma_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_dma.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_dma.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_cortex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_cortex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_pwr.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_pwr_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_pwr.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_flash.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_flash_ex.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_hal_exti.h;Drivers\STM32F0xx_HAL_Driver\Inc\stm32f0xx_ll_exti.h;Drivers\CMSIS\Device\ST\STM32F0xx\Include\stm32f030x6.h;Drivers\CMSIS\Device\ST\STM32F0xx\Include\stm32f0xx.h;Drivers\CMSIS\Device\ST\STM32F0xx\Include\system_stm32f0xx.h;Drivers\CMSIS\Device\ST\STM32F0xx\Source\Templates\system_stm32f0xx.c;Drivers\CMSIS\Include\cmsis_armcc.h;Drivers\CMSIS\Include\cmsis_armclang.h;Drivers\CMSIS\Include\cmsis_compiler.h;Drivers\CMSIS\Include\cmsis_gcc.h;Drivers\CMSIS\Include\cmsis_iccarm.h;Drivers\CMSIS\Include\cmsis_version.h;Drivers\CMSIS\Include\core_armv8mbl.h;Drivers\CMSIS\Include\core_armv8mml.h;Drivers\CMSIS\Include\core_cm0.h;Drivers\CMSIS\Include\core_cm0plus.h;Drivers\CMSIS\Include\core_cm1.h;Drivers\CMSIS\Include\core_cm23.h;Drivers\CMSIS\Include\core_cm3.h;Drivers\CMSIS\Include\core_cm33.h;Drivers\CMSIS\Include\core_cm4.h;Drivers\CMSIS\Include\core_cm7.h;Drivers\CMSIS\Include\core_sc000.h;Drivers\CMSIS\Include\core_sc300.h;Drivers\CMSIS\Include\mpu_armv7.h;Drivers\CMSIS\Include\mpu_armv8.h;Drivers\CMSIS\Include\tz_context.h; - -[PreviousUsedCMakes] -SourceFiles=Core\Src\main.c;Core\Src\stm32f0xx_it.c;Core\Src\stm32f0xx_hal_msp.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_tim.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_tim_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_rcc.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_rcc_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_i2c.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_i2c_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_gpio.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_dma.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_cortex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_pwr.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_pwr_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_flash.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_flash_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_exti.c;Drivers\CMSIS\Device\ST\STM32F0xx\Source\Templates\system_stm32f0xx.c;Core\Src\system_stm32f0xx.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_tim.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_tim_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_rcc.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_rcc_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_i2c.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_i2c_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_gpio.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_dma.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_cortex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_pwr.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_pwr_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_flash.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_flash_ex.c;Drivers\STM32F0xx_HAL_Driver\Src\stm32f0xx_hal_exti.c;Drivers\CMSIS\Device\ST\STM32F0xx\Source\Templates\system_stm32f0xx.c;Core\Src\system_stm32f0xx.c;;; -HeaderPath=Drivers\STM32F0xx_HAL_Driver\Inc;Drivers\STM32F0xx_HAL_Driver\Inc\Legacy;Drivers\CMSIS\Device\ST\STM32F0xx\Include;Drivers\CMSIS\Include;Core\Inc; -CDefines=USE_HAL_DRIVER;STM32F030x6;USE_HAL_DRIVER;USE_HAL_DRIVER; - diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..17f0091 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "main.h": "c" + } +} \ No newline at end of file diff --git a/Core/Inc/DS_Button.h b/Core/Inc/DS_Button.h new file mode 100644 index 0000000..31c158e --- /dev/null +++ b/Core/Inc/DS_Button.h @@ -0,0 +1,26 @@ +#ifndef DS_BUTTON_H +#define DS_BUTTON_H + +#include "stm32f0xx_hal.h" +#include + +typedef struct DS_Button +{ + GPIO_TypeDef* Port; + uint16_t Pin; + bool Pressed, Released, PressedLong; + uint32_t PrevTick, PressStartTick; + uint8_t Storage; +}DS_Button; + +void DS_ButtonInit(DS_Button* Button, GPIO_TypeDef* Port, uint16_t Pin); + +void DS_ButtonUpdate(DS_Button* Button); + +bool DS_ButtonPressed(DS_Button* Button); + +bool DS_ButtonReleased(DS_Button* Button); + +bool DS_Button_PressedLong(DS_Button* Button); + +#endif //DS_BUTTON_H \ No newline at end of file diff --git a/Core/Inc/main.h b/Core/Inc/main.h index c603ce8..5f1267f 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -65,6 +65,8 @@ void Error_Handler(void); #define Led3_GPIO_Port GPIOA #define Led4_Pin GPIO_PIN_3 #define Led4_GPIO_Port GPIOA +#define Button_Pin GPIO_PIN_5 +#define Button_GPIO_Port GPIOA /* USER CODE BEGIN Private defines */ diff --git a/Core/Src/DS_Button.c b/Core/Src/DS_Button.c new file mode 100644 index 0000000..73e02b8 --- /dev/null +++ b/Core/Src/DS_Button.c @@ -0,0 +1,101 @@ + +#include "DS_Button.h" + +void DS_ButtonInit(DS_Button* Button, GPIO_TypeDef *Port, uint16_t Pin) +{ + Button->Port = Port; + Button->Pin = Pin; + Button->Pressed = false; + Button->Released = false; + Button->PrevTick = 0; + Button->Storage = 5; + Button->PressedLong = false; + Button->PressStartTick = 0; +} + +void DS_ButtonUpdate(DS_Button *Button) +{ + //создаём переменную + //устанавливаем для неё границы от 0 до 10 + //если кнопка нажата - увеличиваем значение переменной, пока не доберемся до максимального (10) + //если отпущена - уменьшаем, стремясь к нулю + //опрос состояния делаем не чаще чем 1 раз в 10 миллисекунд + //первое изменение делаем большим - 5 (имитация гистерезиса) + //по достижении нуля - устанавливаем флаг что кнопка отпущена + //по достижении 10 - флаг кнопка нажата + + uint32_t CurrentTick = HAL_GetTick(); + if ((CurrentTick - Button->PrevTick)<10) + return; + + + GPIO_PinState PinState = HAL_GPIO_ReadPin(Button->Port, Button->Pin); + if (PinState == GPIO_PIN_SET) + { + if(Button->Storage == 0) + Button->Storage +=5; + else if(Button->Storage<=10) + Button->Storage++; + + if(Button->PressStartTick == 0) + Button->PressStartTick = CurrentTick; + else if ((CurrentTick - Button->PressStartTick)>1000) + Button->PressedLong = true; + } + else + { + if(Button->Storage == 10) + Button->Storage -=5; + else if(Button->Storage > 0) + Button->Storage--; + + Button->PressStartTick = 0; + Button->PressedLong = false; + } + + switch (Button->Storage) + { + case 0: + Button->Pressed = false; + Button->Released = true; + break; + case 10: + Button->Pressed = true; + Button->Released = false; + break; + + default: + break; + } + +} + +bool DS_ButtonPressed(DS_Button *Button) +{ + if (Button->Pressed) + { + return true; + } + return false; +} + +bool DS_ButtonReleased(DS_Button *Button) +{ + if(Button->Released) + { + return true; + } + return false; +} + +bool DS_Button_PressedLong(DS_Button *Button) +{ + if(Button->PressedLong) + { + Button->PressedLong = false; + Button->PressStartTick = 0; + return true; + + } + return false; +} diff --git a/Core/Src/main.c b/Core/Src/main.c index 4ad5b58..9803627 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -21,7 +21,7 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ - +#include "DS_Button.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -54,7 +54,7 @@ static void MX_GPIO_Init(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ -uint8_t j; +GPIO_PinState ButtonState; /* USER CODE END 0 */ /** @@ -87,50 +87,30 @@ int main(void) /* Initialize all configured peripherals */ MX_GPIO_Init(); /* USER CODE BEGIN 2 */ - + DS_Button Button; + DS_ButtonInit(&Button, Button_GPIO_Port, Button_Pin); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { - //////// - //2 раза красным - //2 раза синими - //желтый на 3 сек - //интервал моргания 100 миллисек - ////// - //повторить 3 раза - - //выключить всё на 10 сек - for (j = 0; j < 3; j++) + DS_ButtonUpdate(&Button); + + if(DS_ButtonPressed(&Button)) { HAL_GPIO_WritePin(Led1_GPIO_Port, Led1_Pin, GPIO_PIN_SET); - HAL_Delay(100); - HAL_GPIO_WritePin(Led1_GPIO_Port, Led1_Pin, GPIO_PIN_RESET); - HAL_Delay(100); - HAL_GPIO_WritePin(Led1_GPIO_Port, Led1_Pin, GPIO_PIN_SET); - HAL_Delay(100); - HAL_GPIO_WritePin(Led1_GPIO_Port, Led1_Pin, GPIO_PIN_RESET); - HAL_Delay(100); - - for (uint8_t i = 0; i < 2; i++) - { - HAL_GPIO_WritePin(Led3_GPIO_Port, Led3_Pin, GPIO_PIN_SET); - HAL_GPIO_WritePin(Led4_GPIO_Port, Led4_Pin, GPIO_PIN_SET); - HAL_Delay(100); - HAL_GPIO_WritePin(Led3_GPIO_Port, Led3_Pin, GPIO_PIN_RESET); - HAL_GPIO_WritePin(Led4_GPIO_Port, Led4_Pin, GPIO_PIN_RESET); - HAL_Delay(100); - } - - HAL_GPIO_WritePin(Led2_GPIO_Port, Led2_Pin, GPIO_PIN_SET); - HAL_Delay(3000); - HAL_GPIO_WritePin(Led2_GPIO_Port, Led2_Pin, GPIO_PIN_RESET); } - HAL_Delay(10000); - + else + { + HAL_GPIO_WritePin(Led1_GPIO_Port, Led1_Pin, GPIO_PIN_RESET); + } + if(DS_Button_PressedLong(&Button)) + { + HAL_GPIO_TogglePin(Led3_GPIO_Port, Led3_Pin); + HAL_GPIO_TogglePin(Led4_GPIO_Port, Led4_Pin); + } /* USER CODE END WHILE */ @@ -199,6 +179,12 @@ static void MX_GPIO_Init(void) GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + /*Configure GPIO pin : Button_Pin */ + GPIO_InitStruct.Pin = Button_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_PULLDOWN; + HAL_GPIO_Init(Button_GPIO_Port, &GPIO_InitStruct); + /* USER CODE BEGIN MX_GPIO_Init_2 */ /* USER CODE END MX_GPIO_Init_2 */ } diff --git a/LedBlinking.ioc b/LedBlinking.ioc index 66c7f36..6e255e5 100644 --- a/LedBlinking.ioc +++ b/LedBlinking.ioc @@ -17,10 +17,11 @@ Mcu.Pin0=PA0 Mcu.Pin1=PA1 Mcu.Pin2=PA2 Mcu.Pin3=PA3 -Mcu.Pin4=PA13 -Mcu.Pin5=PA14 -Mcu.Pin6=VP_SYS_VS_Systick -Mcu.PinsNb=7 +Mcu.Pin4=PA5 +Mcu.Pin5=PA13 +Mcu.Pin6=PA14 +Mcu.Pin7=VP_SYS_VS_Systick +Mcu.PinsNb=8 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32F030F4Px @@ -52,6 +53,11 @@ PA3.GPIOParameters=GPIO_Label PA3.GPIO_Label=Led4 PA3.Locked=true PA3.Signal=GPIO_Output +PA5.GPIOParameters=GPIO_PuPd,GPIO_Label +PA5.GPIO_Label=Button +PA5.GPIO_PuPd=GPIO_PULLDOWN +PA5.Locked=true +PA5.Signal=GPIO_Input PinOutPanel.RotationAngle=0 ProjectManager.AskForMigrate=true ProjectManager.BackupPrevious=false diff --git a/cmake/stm32cubemx/CMakeLists.txt b/cmake/stm32cubemx/CMakeLists.txt index 31a78c4..959e4b3 100644 --- a/cmake/stm32cubemx/CMakeLists.txt +++ b/cmake/stm32cubemx/CMakeLists.txt @@ -22,6 +22,7 @@ target_include_directories(stm32cubemx INTERFACE target_sources(stm32cubemx INTERFACE ../../Core/Src/main.c + ../../Core/Src/DS_Button.c ../../Core/Src/stm32f0xx_it.c ../../Core/Src/stm32f0xx_hal_msp.c ../../Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal_tim.c