aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/main.c b/src/main.c
index 241f369..98de161 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,7 +1,4 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
+#include <stdbool.h>
#include "stm32f091xc.h"
// GPIO A
@@ -74,22 +71,20 @@ void shield_config() {
TIM3->CR1 |= TIM_CR1_CEN; // enable counter
}
-
void toggle_direction() {
led_direction = !led_direction;
}
void EXTI4_15_IRQHandler(void) {
- // toggle_direction();
- led_direction = !led_direction;
- return;
+ toggle_direction();
+ EXTI->PR |= EXTI_PR_PIF8;
}
void interrupt_setup() {
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
// RCC->APB2ENR |= RCC_APB2ENR_SYSCFGCOMPEN;
- SYSCFG->EXTICR[PINOUT_BTN / 4] &= ~(0xF << ((PINOUT_BTN % 4) * 4));
- SYSCFG->EXTICR[PINOUT_BTN / 4] |= (0x1 << ((PINOUT_BTN % 4) * 4));
+ SYSCFG->EXTICR[2] &= ~(SYSCFG_EXTICR3_EXTI8_Msk);
+ SYSCFG->EXTICR[2] |= (SYSCFG_EXTICR3_EXTI8_PB);
EXTI->IMR |= (1 << PINOUT_BTN);
EXTI->RTSR &= ~(1 << PINOUT_BTN);
@@ -146,7 +141,7 @@ void dumb_delay() {
* It uses the channel 1 capture/compare register to check if the time (in
* milliseconds) has expired.
*/
-int timer_delay(unsigned short millis) {
+void timer_delay(unsigned short millis) {
TIM3->CCR1 = millis; // set delay amount
TIM3->CNT = 0; // reset timer
TIM3->SR &= ~(TIM_SR_CC1IF); // reset capture/compare output
@@ -157,6 +152,8 @@ int main() {
shield_config();
interrupt_setup();
+ // int test = 0;
+
while (1) {
// if ((TIM3->SR & TIM_SR_CC1IF) > 0) {
// toggle_direction();
@@ -166,9 +163,8 @@ int main() {
// }
timer_delay(100);
next_led();
- }
-}
+ // test = (test + 1) % 5;
-#ifdef __cplusplus
+ // if (test == 0) toggle_direction();
+ }
}
-#endif