altos/easytimer-v2: Add logging bits
[fw/altos] / src / easytimer-v2 / ao_pins.h
1 /*
2  * Copyright © 2012 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 AO_CONFIG_MAX_SIZE      1024
31
32 #define HAS_EEPROM              1
33 #define USE_INTERNAL_FLASH      0
34 #define USE_EEPROM_CONFIG       0
35 #define USE_STORAGE_CONFIG      1
36 #define HAS_USB                 1
37 #define HAS_BEEP                1
38 #define HAS_BATTERY_REPORT      1
39 #define AO_BEEP_TCC             (&samd21_tcc2)
40 #define AO_BEEP_TCC_APBC_MASK   SAMD21_PM_APBCMASK_TCC2
41 #define AO_BEEP_PORT            (&samd21_port_a)
42 #define AO_BEEP_PIN             16
43 #define AO_BEEP_FUNC            SAMD21_PORT_PMUX_FUNC_E
44 #define HAS_RADIO               0
45 #define HAS_TELEMETRY           0
46 #define HAS_APRS                0
47 #define HAS_COMPANION           0
48
49 #define HAS_SPI_0               1
50 #define HAS_SPI_3               1
51 #define HAS_SPI_5               1
52
53 #define LEDS_AVAILABLE          0
54
55 #define HAS_GPS                 0
56 #define HAS_FLIGHT              1
57 #define HAS_ADC                 1
58 #define HAS_ADC_TEMP            1
59 #define HAS_LOG                 1
60
61 /*
62  * Igniter
63  */
64
65 #define HAS_IGNITE              0
66 #define HAS_IGNITE_REPORT       1
67 #define AO_PYRO_NUM             2
68
69 #define AO_SENSE_PYRO(p,n)      ((p)->adc.sense[n])
70 #define AO_IGNITER_CLOSED       400
71 #define AO_IGNITER_OPEN         60
72
73 /* Pyro A */
74 #define AO_PYRO_PORT_0          (&samd21_port_a)
75 #define AO_PYRO_PIN_0           1
76
77 #define AO_ADC_SENSE_A          0
78 #define AO_ADC_SENSE_A_PORT     (&samd21_port_a)
79 #define AO_ADC_SENSE_A_PIN      2
80
81 /* Pyro B */
82 #define AO_PYRO_PORT_1          (&samd21_port_b)
83 #define AO_PYRO_PIN_1           9
84
85 #define AO_ADC_SENSE_B          2
86 #define AO_ADC_SENSE_B_PORT     (&samd21_port_b)
87 #define AO_ADC_SENSE_B_PIN      8
88
89
90 /*
91  * ADC
92  */
93 #define AO_DATA_RING            32
94 #define AO_ADC_NUM_SENSE        2
95
96 struct ao_adc {
97         int16_t                 sense[AO_ADC_NUM_SENSE];
98         int16_t                 v_batt;
99         int16_t                 temp;
100 };
101
102 #define AO_ADC_DUMP(p) \
103         printf("tick: %5lu A: %5d B: %5d batt: %5d\n", \
104                (p)->tick, \
105                (p)->adc.sense[0], (p)->adc.sense[1], \
106                (p)->adc.v_batt);
107
108 #define AO_ADC_V_BATT           10
109 #define AO_ADC_V_BATT_PORT      (&samd21_port_b)
110 #define AO_ADC_V_BATT_PIN       2
111
112 #define AO_ADC_TEMP             SAMD21_ADC_INPUTCTRL_MUXPOS_TEMP
113
114 #define AO_NUM_ADC_PIN          (AO_ADC_NUM_SENSE + 1)
115
116 #define AO_ADC_PIN0_PORT        AO_ADC_SENSE_A_PORT
117 #define AO_ADC_PIN0_PIN         AO_ADC_SENSE_A_PIN
118 #define AO_ADC_PIN1_PORT        AO_ADC_SENSE_B_PORT
119 #define AO_ADC_PIN1_PIN         AO_ADC_SENSE_B_PIN
120 #define AO_ADC_PIN2_PORT        AO_ADC_V_BATT_PORT
121 #define AO_ADC_PIN2_PIN         AO_ADC_V_BATT_PIN
122
123 #define AO_NUM_ADC              (AO_NUM_ADC_PIN + 1)
124
125 #define AO_ADC_SQ0              AO_ADC_SENSE_A
126 #define AO_ADC_SQ1              AO_ADC_SENSE_B
127 #define AO_ADC_SQ2              AO_ADC_V_BATT
128 #define AO_ADC_SQ3              AO_ADC_TEMP
129
130 /*
131  * Voltage divider on ADC battery sampler
132  */
133 #define AO_BATTERY_DIV_PLUS     100     /* 100k */
134 #define AO_BATTERY_DIV_MINUS    27      /* 27k */
135
136 /*
137  * Voltage divider on ADC igniter samplers
138  */
139 #define AO_IGNITE_DIV_PLUS      100     /* 100k */
140 #define AO_IGNITE_DIV_MINUS     27      /* 27k */
141
142 /*
143  * ADC reference in decivolts
144  */
145 #define AO_ADC_REFERENCE_DV     33
146
147 /*
148  * SPI Flash memory
149  */
150
151 #define M25_MAX_CHIPS           1
152 #define AO_M25_SPI_CS_PORT      (&samd21_port_a)
153 #define AO_M25_SPI_CS_MASK      (1 << 27)
154 #define AO_M25_SPI_BUS          AO_SPI_0_PA04_PA05_PA06
155
156 /*
157  * On EasyTimer v2, bmi088 pin 1 (NE corner of chip) is placed towards the
158  * USB and antenna edges of the board. Relative to bmi088 specs, to
159  * get the above values, we need to flip the Y axis, assigning values
160  * as follows:
161  *
162  *      +along          +X      +roll   +X
163  *      +across         -Y      +pitch  -Y
164  *      +through        +Z      +yaw    +Z
165  */
166
167 #define HAS_BMI088              1
168 #define AO_BMI088_SPI_BUS       AO_SPI_5_PB22_PB23_PB03
169 #define AO_BMI088_ACC_CS_PORT   (&samd21_port_a)
170 #define AO_BMI088_ACC_CS_PIN    10
171 #define AO_BMI088_GYR_CS_PORT   (&samd21_port_a)
172 #define AO_BMI088_GYR_CS_PIN    11
173 #define HAS_IMU                 1
174
175 #define ao_bmi088_along(m)      ((m)->acc.x)
176 #define ao_bmi088_across(m)     (-(m)->acc.y)
177 #define ao_bmi088_through(m)    ((m)->acc.z)
178
179 #define ao_bmi088_roll(m)       ((m)->gyr.x)
180 #define ao_bmi088_pitch(m)      (-(m)->gyr.y)
181 #define ao_bmi088_yaw(m)        ((m)->gyr.z)
182
183 #define ao_data_along(packet)   ao_bmi088_along(&(packet)->bmi088)
184 #define ao_data_across(packet)  ao_bmi088_across(&(packet)->bmi088)
185 #define ao_data_through(packet) ao_bmi088_through(&(packet)->bmi088)
186
187 #define ao_data_roll(packet)    ao_bmi088_roll(&(packet)->bmi088)
188 #define ao_data_pitch(packet)   ao_bmi088_pitch(&(packet)->bmi088)
189 #define ao_data_yaw(packet)     ao_bmi088_yaw(&(packet)->bmi088)
190
191 /*
192  * MMC5983
193  *
194  *      pin 1 NE corner of chip
195  *
196  *      +along          -Y
197  *      +across         +X
198  *      +through        -Z
199  */
200
201 #define HAS_MMC5983                     1
202 #define AO_MMC5983_INT_PORT             (&samd21_port_a)
203 #define AO_MMC5983_INT_PIN              9
204 #define AO_MMC5983_SPI_CLK_PORT         (&samd21_port_a)
205 #define AO_MMC5983_SPI_CLK_PIN          23
206 #define AO_MMC5983_SPI_MISO_PORT        (&samd21_port_a)
207 #define AO_MMC5983_SPI_MISO_PIN         20
208 #define AO_MMC5983_SPI_MOSI_PORT        (&samd21_port_a)
209 #define AO_MMC5983_SPI_MOSI_PIN         22
210 #define AO_MMC5983_SPI_INDEX            (AO_SPI_3_PA22_PA23_PA20 | AO_SPI_MODE_3)
211 #define AO_MMC5983_SPI_CS_PORT          (&samd21_port_a)
212 #define AO_MMC5983_SPI_CS_PIN           8
213
214 #define ao_mmc5983_along(m)             (-(m)->y)
215 #define ao_mmc5983_across(m)            ((m)->x)
216 #define ao_mmc5983_through(m)           (-(m)->z)
217
218 #define ao_data_mag_along(packet)       ao_mmc5983_along(&(packet)->mmc5983)
219 #define ao_data_mag_across(packet)      ao_mmc5983_across(&(packet)->mmc5983)
220 #define ao_data_mag_through(packet)     ao_mmc5983_through(&(packet)->mmc5983)
221
222 /*
223  * Monitor
224  */
225
226 #define HAS_MONITOR             0
227 #define LEGACY_MONITOR          0
228 #define HAS_MONITOR_PUT         1
229 #define AO_MONITOR_LED          0
230 #define HAS_RSSI                0
231
232 /*
233  * Logging
234  */
235
236 #define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX        (1024 * 1024)
237 #define AO_CONFIG_MAX_SIZE                      1024
238 #define LOG_ERASE_MARK                          0x55
239 #define LOG_MAX_ERASE                           128
240 #define AO_LOG_FORMAT                           AO_LOG_FORMAT_EASYTIMER_2
241 #define AO_LOG_NORMALIZED                       1
242
243 #endif /* _AO_PINS_H_ */