first stab at support for TeleMetrum v4.0
[fw/altos] / src / telemetrum-v4.0 / 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 AO_XOSC                 1
23 #define AO_XOSC_FREQ            16000000
24 #define AO_XOSC_DIV             256
25 #define AO_XOSC_MUL             768
26
27 #define AO_AHB_PRESCALER        1
28 #define AO_APBA_PRESCALER       1
29
30 #define HAS_SERIAL_1            1
31 #define USE_SERIAL_1_STDIN      0
32
33 #define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX        (512 * 1024)
34 #define AO_CONFIG_MAX_SIZE                      1024
35 #define LOG_ERASE_MARK                          0x55
36 #define LOG_MAX_ERASE                           128
37 #define AO_LOG_FORMAT                           AO_LOG_FORMAT_TELEMETRUM
38
39 #define HAS_EEPROM              1
40 #define USE_INTERNAL_FLASH      0
41 #define USE_EEPROM_CONFIG       1
42 #define USE_STORAGE_CONFIG      0
43 #define HAS_USB                 1
44 #define USE_USB_STDIO   1
45 #define HAS_BEEP                1
46 #define HAS_BATTERY_REPORT      1
47 #define BEEPER_CHANNEL          4
48 #define BEEPER_TIMER            3
49 #define BEEPER_PORT             (&samd21_port_a)
50 #define BEEPER_PIN              16
51 #define HAS_RADIO               1
52 #define HAS_TELEMETRY           1
53 #define HAS_APRS                1
54 #define HAS_COMPANION           1
55
56 #define HAS_SPI_1               1
57 #define SPI_1_PA5_PA6_PA7       1       /* Barometer */
58 #define SPI_1_PB3_PB4_PB5       1       /* Accelerometer */
59 #define SPI_1_PE13_PE14_PE15    0
60 #define SPI_1_OSPEEDR           STM_OSPEEDR_10MHz
61
62 #define HAS_SPI_2               1
63 #define SPI_2_PB13_PB14_PB15    1       /* Flash, Companion, Radio */
64 #define SPI_2_PD1_PD3_PD4       0
65 #define SPI_2_OSPEEDR           STM_OSPEEDR_10MHz
66
67 #define PACKET_HAS_SLAVE        1
68 #define PACKET_HAS_MASTER       0
69
70 #define LOW_LEVEL_DEBUG         0
71
72 #define LED_PORT                (&samd21_port_b)
73 #define LED_PIN_RED             10
74 #define LED_PIN_GREEN           11
75 #define AO_LED_RED              (1 << LED_PIN_RED)
76 #define AO_LED_GREEN            (1 << LED_PIN_GREEN)
77
78 #define LEDS_AVAILABLE          (AO_LED_RED | AO_LED_GREEN)
79
80 #define HAS_GPS                 1
81 #define HAS_FLIGHT              1
82 #define HAS_ADC                 1
83 #define HAS_ADC_TEMP            1
84 #define HAS_LOG                 1
85
86 /*
87  * Igniter
88  */
89
90 #define HAS_IGNITE              1
91 #define HAS_IGNITE_REPORT       1
92
93 #define AO_SENSE_DROGUE(p)      ((p)->adc.sense_a)
94 #define AO_SENSE_MAIN(p)        ((p)->adc.sense_m)
95 #define AO_IGNITER_CLOSED       400
96 #define AO_IGNITER_OPEN         60
97
98 /* Drogue */
99 #define AO_IGNITER_DROGUE_PORT  (&samd21_port_a)
100 #define AO_IGNITER_DROGUE_PIN   19
101
102 /* Main */
103 #define AO_IGNITER_MAIN_PORT    (&samd21_port_a)
104 #define AO_IGNITER_MAIN_PIN     18
105
106 /*
107  * ADC
108  */
109 #define AO_DATA_RING            32
110 #define AO_ADC_NUM_SENSE        2
111
112 struct ao_adc {
113         int16_t                 sense_a;
114         int16_t                 sense_m;
115         int16_t                 v_batt;
116         int16_t                 temp;
117 };
118
119 #define AO_ADC_DUMP(p) \
120         printf("tick: %5lu drogue: %5d main: %5d batt: %5d\n", \
121                (p)->tick, \
122                (p)->adc.sense_a, (p)->adc.sense_m, \
123                (p)->adc.v_batt);
124
125 #define AO_ADC_SENSE_DROGUE     1
126 #define AO_ADC_SENSE_DROGUE_PORT        (&samd21_port_a)
127 #define AO_ADC_SENSE_DROGUE_PIN 10
128
129 #define AO_ADC_SENSE_MAIN       1
130 #define AO_ADC_SENSE_MAIN_PORT  (&samd21_port_a)
131 #define AO_ADC_SENSE_MAIN_PIN   11
132
133 #define AO_ADC_V_BATT           8
134 #define AO_ADC_V_BATT_PORT      (&samd21_port_a)
135 #define AO_ADC_V_BATT_PIN       9
136
137 #define AO_ADC_TEMP             16
138
139 #define AO_NUM_ADC_PIN          3
140
141 #define AO_ADC_PIN0_PORT        AO_ADC_SENSE_DROGUE_PORT
142 #define AO_ADC_PIN0_PIN         AO_ADC_SENSE_DROGUE_PIN
143 #define AO_ADC_PIN1_PORT        AO_ADC_SENSE_MAIN_PORT
144 #define AO_ADC_PIN1_PIN         AO_ADC_SENSE_MAIN_PIN
145 #define AO_ADC_PIN2_PORT        AO_ADC_V_BATT_PORT
146 #define AO_ADC_PIN2_PIN         AO_ADC_V_BATT_PIN
147
148 #define AO_NUM_ADC              (AO_NUM_ADC_PIN + 1)
149
150 #define AO_ADC_SQ1              AO_ADC_SENSE_DROGUE
151 #define AO_ADC_SQ2              AO_ADC_SENSE_MAIN
152 #define AO_ADC_SQ3              AO_ADC_V_BATT
153 #define AO_ADC_SQ4              AO_ADC_TEMP
154
155 /*
156  * Voltage divider on ADC battery sampler
157  */
158 #define AO_BATTERY_DIV_PLUS     56      /* 5.6k */
159 #define AO_BATTERY_DIV_MINUS    100     /* 10k */
160
161 /*
162  * Voltage divider on ADC igniter samplers
163  */
164 #define AO_IGNITE_DIV_PLUS      100     /* 100k */
165 #define AO_IGNITE_DIV_MINUS     27      /* 27k */
166
167 /*
168  * ADC reference in decivolts
169  */
170 #define AO_ADC_REFERENCE_DV     33
171
172 /*
173  * GPS
174  */
175
176 #define AO_SERIAL_SPEED_UBLOX   AO_SERIAL_SPEED_9600
177
178 #define ao_gps_getchar          ao_serial3_getchar
179 #define ao_gps_putchar          ao_serial3_putchar
180 #define ao_gps_set_speed        ao_serial3_set_speed
181 #define ao_gps_fifo             (ao_stm_usart3.rx_fifo)
182
183 /*
184  * Pressure sensor settings
185  */
186 #define HAS_MS5607              1
187 #define HAS_MS5611              0
188 #define AO_MS5607_PRIVATE_PINS  1
189 #define AO_MS5607_CS_PORT       (&samd21_port_a)
190 #define AO_MS5607_CS_PIN        21
191 #define AO_MS5607_CS_MASK       (1 << AO_MS5607_CS)
192 #define AO_MS5607_MISO_PORT     (&samd21_port_a)
193 #define AO_MS5607_MISO_PIN      20
194
195 /*
196  * SPI Flash memory
197  */
198
199 #define M25_MAX_CHIPS           1
200 #define AO_M25_SPI_CS_PORT      (&samd21_port_a)
201 #define AO_M25_SPI_CS_MASK      (1 << 8)
202
203 /*
204  * Radio (cc1200)
205  */
206
207 /* gets pretty close to 434.550 */
208
209 #define AO_RADIO_CAL_DEFAULT    5695733
210
211 #define AO_CC1200_SPI_CS_PORT   (&samd21_port_a)
212 #define AO_CC1200_SPI_CS_PIN    7
213
214 #define AO_CC1200_INT_PORT              (&samd21_port_b)
215 #define AO_CC1200_INT_PIN               (8)
216 #define AO_CC1200_MCU_WAKEUP_PORT       (&samd21_port_b)
217 #define AO_CC1200_MCU_WAKEUP_PIN        (9)
218
219 #define AO_CC1200_INT_GPIO      2
220 #define AO_CC1200_INT_GPIO_IOCFG        CC1200_IOCFG2
221
222 #define AO_CC1200_MARC_GPIO     3
223 #define AO_CC1200_MARC_GPIO_IOCFG       CC1200_IOCFG3
224
225 #define HAS_BOOT_RADIO          0
226
227 #define HAS_HIGHG_ACCEL         1
228
229 /* ADXL375 */
230
231 #define HAS_ADXL375             1
232 #define AO_ADXL375_CS_PORT      (&samd21_port_a)
233 #define AO_ADXL375_CS_PIN       8
234
235 #define AO_ADXL375_AXIS         x
236 #define AO_ADXL375_INVERT       1
237
238 #define NUM_CMDS                16
239
240 /*
241  * Companion
242  */
243
244 #define AO_COMPANION_CS_PORT    (&samd21_port_a)
245 #define AO_COMPANION_CS_PIN     (13)
246
247 /*
248  * Monitor
249  */
250
251 #define HAS_MONITOR             0
252 #define LEGACY_MONITOR          0
253 #define HAS_MONITOR_PUT         1
254 #define AO_MONITOR_LED          0
255 #define HAS_RSSI                0
256
257 /*
258  * Profiling Viterbi decoding
259  */
260
261 #ifndef AO_PROFILE
262 #define AO_PROFILE              0
263 #endif
264
265 #endif /* _AO_PINS_H_ */