-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
63 lines (52 loc) · 1.38 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
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <libopencm3/cm3/cortex.h>
#include <libopencm3/usb/usbd.h>
#include <libopencm3/cm3/nvic.h>
#include "platform/platform.h"
#include "i2c_led/i2c_led.h"
#include "io/io.h"
#include "nt_timer/nt_timer.h"
#include "usb/usb.h"
int main(int UNUSED(argc), char **UNUSED(argv))
{
uint16_t pin_state;
uint16_t prev_pin_state;
// Make certain the hardware is back at reset state
platform_reset_hardware();
// disable interrupts
cm_disable_interrupts();
// initilize each module in order
platform_init();
io_init();
initialize_timer();
i2c_led_init();
pin_state = get_inputs();
prev_pin_state = pin_state;
// enable interrupts
cm_enable_interrupts();
// Start USB
usb_reenumerate();
// continualy poll the input lines
// Loop forever pollong the input lines looking for a change
while (true) {
poll_usb();
// examine the next timer even and determine if a callback function should be executed
run_timer_event();
// read the value of the input pins
pin_state = get_inputs();
// check if port changed
if (prev_pin_state == pin_state) {
continue;
}
// *** The port is not the same as previous poll ***
// Update the USB interrupt endpoint data
if (usb_set_interrupt_data(pin_state)) {
// store the port state
prev_pin_state = pin_state;
}
}
/* Should never get here */
return EXIT_SUCCESS;
}