|
|
@ -22,13 +22,21 @@
|
|
|
|
volatile enum {FORWARD, BACKWARD} direction;
|
|
|
|
volatile enum {FORWARD, BACKWARD} direction;
|
|
|
|
volatile bool running = false;
|
|
|
|
volatile bool running = false;
|
|
|
|
|
|
|
|
|
|
|
|
void setup (void) { // All the blackbox code
|
|
|
|
void setup_system (void) {
|
|
|
|
|
|
|
|
|
|
|
|
// Set up clock
|
|
|
|
// Set up clock
|
|
|
|
rcc_clock_setup_in_hse_8mhz_out_24mhz();
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
rcc_periph_clock_enable(RCC_GPIOA);
|
|
|
|
|
|
|
|
|
|
|
|
// Enable AFIO (we need that to map GPIO to EXTI)
|
|
|
|
// 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
|
|
|
|
// This one is for EXTI0 ~~ GPIOx0 pins
|
|
|
|
nvic_enable_irq(NVIC_EXTI0_IRQ);
|
|
|
|
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
|
|
|
|
// GPIO A0 is the push button
|
|
|
|
// And we set it as a regular button and enable its interrupts in the next block
|
|
|
|
// 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);
|
|
|
|
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
|
|
|
|
// libopencm3 has a pre-declared interrupt handlers, so it needs to have this name
|
|
|
|
void exti0_isr (void) {
|
|
|
|
void exti0_isr (void) {
|
|
|
|
// Clear the interrupt
|
|
|
|
// Clear the interrupt
|
|
|
|