From c33223883912819964bad8568f3dc3a34e1daadc Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Thu, 2 Dec 2021 05:30:14 +0100 Subject: [PATCH] Split function setup into block for each peripheral --- main.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 0452b18..7fc0b8c 100644 --- a/main.c +++ b/main.c @@ -22,13 +22,21 @@ volatile enum {FORWARD, BACKWARD} direction; volatile bool running = false; -void setup (void) { // All the blackbox code - +void setup_system (void) { // Set up clock rcc_clock_setup_in_hse_8mhz_out_24mhz(); +} - // Enable the two GPIOs +void setup_gpio_out (void) { + // Enable clock for GPIO C rcc_periph_clock_enable(RCC_GPIOC); + // GPIO C8 amd C9 are the two LEDs + gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO8 | GPIO9); + +} + +void setup_exti0_in (void) { + // Enable clock for GPIO A rcc_periph_clock_enable(RCC_GPIOA); // Enable AFIO (we need that to map GPIO to EXTI) @@ -39,8 +47,6 @@ void setup (void) { // All the blackbox code // This one is for EXTI0 ~~ GPIOx0 pins nvic_enable_irq(NVIC_EXTI0_IRQ); - // GPIO C8 amd C9 are the two LEDs - gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO8 | GPIO9); // GPIO A0 is the push button // And we set it as a regular button and enable its interrupts in the next block @@ -55,6 +61,12 @@ void setup (void) { // All the blackbox code exti_enable_request(EXTI0); } +void setup (void) { + setup_system(); + setup_gpio_out(); + setup_exti0_in(); +} + // libopencm3 has a pre-declared interrupt handlers, so it needs to have this name void exti0_isr (void) { // Clear the interrupt