metro-m0: Add GPS support
[fw/altos] / src / metro-m0 / metro-m0.c
1 /*
2  * Copyright © 2016 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  */
14
15 #include <ao.h>
16 #include <ao_led.h>
17 #include <ao_dma_samd21.h>
18 #include <ao_exti.h>
19
20 static int      pressed;
21
22 static void
23 ao_button_callback(void)
24 {
25         pressed = 1;
26         ao_wakeup(&pressed);
27 }
28
29 static void
30 ao_beep_test(void)
31 {
32         AO_BEEP_TCC->ctrlbset = (SAMD21_TCC_CTRLB_CMD_READSYNC << SAMD21_TCC_CTRLB_CMD);
33         printf("pressed timer %ld\n", AO_BEEP_TCC->count);
34         fflush(stdout);
35         ao_beep_for(AO_BEEP_MID_DEFAULT, AO_MS_TO_TICKS(200));
36 }
37
38 static void
39 ao_button(void)
40 {
41         ao_exti_setup(&samd21_port_a, 10, AO_EXTI_MODE_FALLING | AO_EXTI_MODE_PULL_UP, ao_button_callback);
42         ao_exti_enable(&samd21_port_a, 10);
43         for (;;) {
44                 ao_arch_block_interrupts();
45                 pressed = 0;
46                 while (!pressed)
47                         ao_sleep(&pressed);
48                 ao_arch_release_interrupts();
49                 ao_beep_test();
50         }
51 }
52
53 static struct ao_task ao_button_task;
54
55 const struct ao_cmds ao_test_cmds[] = {
56         { ao_beep_test, "b \0beep" },
57         { 0, NULL },
58 };
59
60 int main(void)
61 {
62         ao_led_init();
63         ao_clock_init();
64         ao_task_init();
65         ao_timer_init();
66         ao_dma_init();
67         ao_exti_init();
68         ao_spi_init();
69         ao_adc_init();
70         ao_serial_init();
71         ao_gps_init();
72         ao_beep_init();
73         ao_usb_init();
74         ao_storage_init();
75         ao_cmd_init();
76
77         ao_cmd_register(ao_test_cmds);
78         ao_add_task(&ao_button_task, ao_button, "button");
79         ao_start_scheduler();
80
81         return 0;
82 }