diff options
author | xengineering <me@xengineering.eu> | 2021-09-27 12:09:19 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2021-09-27 12:15:28 +0200 |
commit | 6c90271b1d20235d917509454dc1b4e4a66f13f6 (patch) | |
tree | 6ddce5007b977cc1a5a68a60bcc3f6db365f0c70 | |
parent | b41240dc6326464403b73351cb8ff24abedee59a (diff) | |
download | ledcontrol-6c90271b1d20235d917509454dc1b4e4a66f13f6.tar ledcontrol-6c90271b1d20235d917509454dc1b4e4a66f13f6.tar.zst ledcontrol-6c90271b1d20235d917509454dc1b4e4a66f13f6.zip |
Cleanup Code
-rw-r--r-- | src/main.c | 33 |
1 files changed, 18 insertions, 15 deletions
@@ -2,7 +2,6 @@ #include <libopencm3/stm32/rcc.h> -#include <libopencm3/stm32/flash.h> #include <libopencm3/stm32/gpio.h> #include <libopencm3/stm32/timer.h> #include <libopencm3/cm3/nvic.h> @@ -10,10 +9,11 @@ static void clock_init(void); static void gpio_init(void); -void tim2_isr(void); static void nvic_init(void); static void timer_init(void); +void tim2_isr(void); + void main(void) { @@ -43,13 +43,6 @@ static void gpio_init(void) } -void tim2_isr(void) -{ - gpio_toggle(GPIOC, GPIO13); - TIM_SR(TIM2) &= ~TIM_SR_UIF; // clear interrrupt flag -} - - static void nvic_init(void) { nvic_enable_irq(NVIC_TIM2_IRQ); @@ -59,10 +52,20 @@ static void nvic_init(void) static void timer_init(void) { - gpio_set(GPIOC, GPIO13); - TIM_CNT(TIM2) = 1; // set start value - TIM_PSC(TIM2) = 1440; // set prescaler - TIM_ARR(TIM2) = 50000; // interrupt value - TIM_DIER(TIM2) |= TIM_DIER_UIE; // update interrupt enable - TIM_CR1(TIM2) |= TIM_CR1_CEN; // enable timer + // set LED on + gpio_clear(GPIOC, GPIO13); + + // setup timer + timer_set_counter(TIM2, 1); + timer_set_prescaler(TIM2, 1440); + timer_set_period(TIM2, 50000); + timer_enable_irq(TIM2, TIM_DIER_UIE); // set action to trigger interrupt + timer_enable_counter(TIM2); +} + + +void tim2_isr(void) +{ + gpio_toggle(GPIOC, GPIO13); + TIM_SR(TIM2) &= ~TIM_SR_UIF; // clear interrrupt flag } |