From affcd4a0257a814908c40bd4013a881d106729ac Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 7 Jul 2023 23:54:08 +0200 Subject: [PATCH] Add IRQ Handler - toggle LED_GREEN --- Core/Inc/cppmain.h | 5 ++--- Core/Src/cppmain.cc | 37 ++++++++++++++++++++++++++++++++++++- Core/Src/main.c | 11 +++++++++-- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/Core/Inc/cppmain.h b/Core/Inc/cppmain.h index 50283a2..3fb827d 100644 --- a/Core/Inc/cppmain.h +++ b/Core/Inc/cppmain.h @@ -9,12 +9,12 @@ #define INC_CPPMAIN_H - #ifdef __cplusplus extern "C" { #endif -void cppmain(void); + void irq1(); + void cppmain(void); #ifdef __cplusplus }; @@ -22,4 +22,3 @@ void cppmain(void); #endif /* INC_CPPMAIN_H */ - diff --git a/Core/Src/cppmain.cc b/Core/Src/cppmain.cc index 39795ac..cf9ccbb 100644 --- a/Core/Src/cppmain.cc +++ b/Core/Src/cppmain.cc @@ -16,6 +16,9 @@ const double pi{ std::acos(-1) }; +// Serial Logging +// -------------- + void log(const std::string &msg) { std::string out{ msg }; @@ -28,6 +31,10 @@ void log(std::string &&msg) log(msg); } + +// DAC +// --- + void set_dac_1(uint32_t val) { HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_L, val); @@ -38,6 +45,34 @@ void set_dac_2(uint32_t val) HAL_DAC_SetValue(&hdac, DAC_CHANNEL_2, DAC_ALIGN_12B_L, val); } + +// LED +// --- + +void led_green_toggle() +{ + HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin); +} + +void led_green_on() +{ + HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, GPIO_PIN_SET); +} + +void led_green_off() +{ + HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, GPIO_PIN_RESET); +} + + +// MAIN +// ---- + +void irq1() +{ + led_green_toggle(); +} + void cppmain(void) { HAL_DAC_Start(&hdac, DAC_CHANNEL_1); @@ -45,7 +80,7 @@ void cppmain(void) while (true) { unsigned char res = t * ((t >> 12 | t >> 8) & 63 & t >> 4); set_dac_1((res % 256) * 100); - for (int g = 0; g < 6000; g++) {} + for (int g = 0; g < 600000; g++) {} t++; t %= (std::numeric_limits::max() - 1); } diff --git a/Core/Src/main.c b/Core/Src/main.c index f45196d..d12caf5 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -25,7 +25,7 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ - +#include "cppmain.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -159,7 +159,14 @@ void SystemClock_Config(void) } /* USER CODE BEGIN 4 */ - +void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) +{ + if(GPIO_Pin == BUT_BLUE_Pin) { + irq1(); + } else { + __NOP(); + } +} /* USER CODE END 4 */ /**