-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
executable file
·102 lines (81 loc) · 2.09 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "stm32f4xx.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"
#include <stdio.h>
#include <math.h>
#include "accelerometers/accelerometers.h"
#include "accelerometers/accavg.h"
#include "timed_task.h"
#include "gesture_recog.h"
static void init_systick();
//static void delay_ms(uint32_t n);
volatile uint32_t msTicks; // counts 1 ms timeTicks
// SysTick Handler (Interrupt Service Routine for the System Tick interrupt)
void SysTick_Handler(void)
{
msTicks++;
}
// initialize the system tick
void init_systick(void)
{
SystemCoreClockUpdate(); /* Get Core Clock Frequency */
if (SysTick_Config(SystemCoreClock / 1000)) { /* SysTick 1 msec interrupts */
while (1); /* Capture error */
}
}
/*
// pause for a specified number (n) of milliseconds
void delay_ms(uint32_t n)
{
uint32_t msTicks2 = msTicks + n;
while(msTicks < msTicks2) ;
}
*/
void init_LED_pins()
{
RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN; // enable clock to GPIOD
for (int i=12; i<=15; i++)
{
GPIOD->MODER &= ~(0x3 << (2*i)); // clear the 2 bits corresponding to pin i
GPIOD->MODER |= (1 << (2*i)); // set pin i to be general purpose output
}
}
void LED_On(uint32_t i)
{
GPIOD->BSRRL = 1 << (i+12);
}
void LED_Off(uint32_t i)
{
GPIOD->BSRRH = 1 << (i+12);
}
void init_button()
{
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN; // enable clock to GPIOA
GPIOA->MODER &= ~(0x3 << (2*0)); // clear the 2 bits corresponding to pin 0
// if the 2 bits corresponding to pin 0 are 00, then it is in input mode
}
void initialise_monitor_handles();
int main(void)
{
// initialize
SystemInit();
initialise_monitor_handles();
init_systick();
init_LED_pins();
init_button();
init_accelerometers();
//populate accel data
for (int i =0; i < NUMSAMPLES; ++i){
collectAccelData();
}
//task related
add_timed_task(update,.020); //seconds
add_timed_task(printPitchRoll,1.0);
add_timed_task(collectAccelData,.010);
add_timed_task(printtimes,5);
while (1)
{
//execute all tasks
execute_tasks();
}
}