metro-m0: Add GPS support
[fw/altos] / src / metro-m0 / ao_pins.h
1 /*
2  * Copyright © 2022 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  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #ifndef _AO_PINS_H_
20 #define _AO_PINS_H_
21
22 #define LED_0_PORT      (&samd21_port_a)
23 #define LED_0_PIN       2
24
25 #define LED_BLUE        (1 << 0)
26
27 #define AO_LED_PANIC    LED_BLUE
28
29 #define HAS_USB         1
30 #define USE_USB_STDIO   1
31
32 #define HAS_LED         1
33
34 #define AO_DFLL48M              48000000
35 #define AO_XOSC32K              32768
36
37 #define AO_AHB_PRESCALER        1
38 #define AO_APBA_PRESCALER       1
39
40 #define HAS_SPI_0               1
41 #define HAS_SPI_5               1
42
43 /*
44  * SPI Flash memory
45  */
46
47 #define M25_MAX_CHIPS           1
48
49 #if 1
50 #define AO_M25_SPI_CS_PORT      (&samd21_port_a)
51 #define AO_M25_SPI_CS_MASK      (1 << 13)
52 #define AO_M25_SPI_BUS          AO_SPI_5_PB22_PB23_PB03
53 #else
54
55 #define AO_M25_SPI_CS_PORT      (&samd21_port_a)
56 #define AO_M25_SPI_CS_MASK      (1 << 14) /* D2 */
57 #define AO_M25_SPI_BUS          AO_SPI_4_PB10_PB11_PA12
58
59 #endif
60
61 /*
62  * Beeper
63  */
64
65 #define HAS_BEEP                1
66
67 /* Beep on PA11 function F TCC0.3 */
68
69 #define AO_BEEP_TCC     (&samd21_tcc0)
70 #define AO_BEEP_TCC_APBC_MASK   SAMD21_PM_APBCMASK_TCC0
71 #define AO_BEEP_PORT    (&samd21_port_a)
72 #define AO_BEEP_PIN     (11)
73 #define AO_BEEP_FUNC    SAMD21_PORT_PMUX_FUNC_F
74
75 /* ADC */
76 #define AO_DATA_RING            32
77
78 #define HAS_ADC                 1
79
80 struct ao_adc {
81         int16_t                 a[6];
82         int16_t                 temp;
83 };
84
85 #define AO_NUM_ADC_PIN  6
86 #define AO_NUM_ADC      (AO_NUM_ADC_PIN + 1)
87
88 #define AO_ADC_DUMP(p)                                                  \
89         printf("tick: %5lu a0: %5d a1: %5d a2: %5d a3: %5d a4: %5d a5: %5d temp: %5d\n", \
90                (p)->tick,                                               \
91                (p)->adc.a[0], (p)->adc.a[1], (p)->adc.a[2],             \
92                (p)->adc.a[3], (p)->adc.a[4], (p)->adc.a[5],             \
93                (p)->adc.temp);
94
95 #define AO_ADC_PIN0_PORT        (&samd21_port_a)
96 #define AO_ADC_PIN0_PIN         2
97 #define AO_ADC_SQ0              0
98
99 #define AO_ADC_PIN1_PORT        (&samd21_port_b)
100 #define AO_ADC_PIN1_PIN         8
101 #define AO_ADC_SQ1              2
102
103 #define AO_ADC_PIN2_PORT        (&samd21_port_b)
104 #define AO_ADC_PIN2_PIN         9
105 #define AO_ADC_SQ2              3
106
107 #define AO_ADC_PIN3_PORT        (&samd21_port_a)
108 #define AO_ADC_PIN3_PIN         4
109 #define AO_ADC_SQ3              4
110
111 #define AO_ADC_PIN4_PORT        (&samd21_port_a)
112 #define AO_ADC_PIN4_PIN         5
113 #define AO_ADC_SQ4              5
114
115 #define AO_ADC_PIN5_PORT        (&samd21_port_b)
116 #define AO_ADC_PIN5_PIN         2
117 #define AO_ADC_SQ5              10
118
119 #define AO_ADC_SQ6              SAMD21_ADC_INPUTCTRL_MUXPOS_TEMP
120
121 /* GPS */
122 #define HAS_GPS                 1
123
124 #define AO_SERIAL_SPEED_UBLOX   AO_SERIAL_SPEED_9600
125
126 #define HAS_SERIAL_0            1
127 #define USE_SERIAL_0_STDIN      0
128 #define SERIAL_0_PA08_PA09      1
129
130 #define ao_gps_getchar          ao_serial0_getchar
131 #define ao_gps_putchar          ao_serial0_putchar
132 #define ao_gps_set_speed        ao_serial0_set_speed
133 #define ao_gps_fifo             (ao_samd21_usart0.rx_fifo)
134
135 #endif /* _AO_PINS_H_ */