altos: Initial TeleMini v3.0 code
[fw/altos] / src / telemini-v3.0 / ao_pins.h
1 /*
2  * Copyright © 2013 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; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 #define HAS_BEEP                1
19 #define HAS_BATTERY_REPORT      1
20
21 #define AO_STACK_SIZE   384
22
23 #define IS_FLASH_LOADER 0
24
25 /* 40MHz clock based on 16MHz reference */
26 //#define AO_HSI48      1
27 #define AO_HSE                  16000000
28 #define AO_RCC_CFGR_PLLMUL      STM_RCC_CFGR_PLLMUL_5
29 #define AO_RCC_CFGR2_PLLDIV     STM_RCC_CFGR2_PREDIV_2
30 #define AO_PLLMUL               5
31 #define AO_PLLDIV               2
32
33 /* HCLK = 40MHz */
34 #define AO_AHB_PRESCALER        1
35 #define AO_RCC_CFGR_HPRE_DIV    STM_RCC_CFGR_HPRE_DIV_1
36
37 /* APB = 40MHz */
38 #define AO_APB_PRESCALER        1
39 #define AO_RCC_CFGR_PPRE_DIV    STM_RCC_CFGR_PPRE_DIV_1
40
41 /* Send PLL clock to cc1200 */
42 #define AO_MCO_PORT             (&stm_gpioa)
43 #define AO_MCO_PIN              9
44 #define AO_MCO_AF               STM_AFR_AF5
45
46 #define HAS_USB                 0
47 #define AO_USB_DIRECTIO         0
48 #define AO_PA11_PA12_RMP        0
49
50 #define PACKET_HAS_SLAVE        1
51
52 #define AO_LOG_FORMAT           AO_LOG_FORMAT_EASYMINI
53
54 #define HAS_BOOT_RADIO          0
55
56 #define HAS_ACCEL               0
57 #define HAS_GPS                 0
58 #define HAS_RADIO               1
59 #define HAS_RADIO_RATE          1
60 #define HAS_FLIGHT              1
61 #define HAS_EEPROM              1
62 #define HAS_TELEMETRY           1
63 #define HAS_APRS                0
64 #define HAS_LOG                 1
65 #define USE_INTERNAL_FLASH      0
66 #define HAS_IGNITE              1
67 #define HAS_IGNITE_REPORT       1
68
69 /* Beeper is on Tim1 CH3 */
70 #define BEEPER_CHANNEL          3
71
72 /* LED */
73 #define LED_PORT_ENABLE         STM_RCC_AHBENR_IOPAEN
74 #define LED_PORT                (&stm_gpioa)
75 #define LED_PIN_GREEN           15
76 #define AO_LED_GREEN            (1 << 15)
77 #define AO_LED_PANIC            AO_LED_GREEN
78
79 #define LEDS_AVAILABLE          AO_LED_GREEN
80
81 /* USART */
82
83 #define HAS_SERIAL              0
84 #define USE_SERIAL_0_STDIN      1
85 #define SERIAL_0_18_19          1
86 #define SERIAL_0_14_15          0
87 #define SERIAL_0_17_18          0
88 #define SERIAL_0_26_27          0
89
90 /* SPI */
91
92 #define HAS_SPI_0               1
93 #define SPI_SCK0_P0_6           1
94 #define HAS_SPI_1               1
95 #define SPI_SCK1_P1_15          1
96 #define SPI_MISO1_P0_22         1
97 #define SPI_MOSI1_P0_21         1
98
99 /* M25 */
100
101 #define M25_MAX_CHIPS           1
102 #define AO_M25_SPI_CS_PORT      (&stm_gpioa)
103 #define AO_M25_SPI_CS_MASK      (1 << 3)
104 #define AO_M25_SPI_BUS          AO_SPI_1_PA5_PA6_PA7
105
106 /* MS5607 */
107
108 #define HAS_MS5607              1
109 #define HAS_MS5611              0
110 #define AO_MS5607_PRIVATE_PINS  0
111 #define AO_MS5607_CS_PORT       (&stm_gpioa)
112 #define AO_MS5607_CS_PIN        4
113 #define AO_MS5607_CS_MASK       (1 << AO_MS5607_CS_PIN)
114 #define AO_MS5607_MISO_PORT     (&stm_gpiob)
115 #define AO_MS5607_MISO_PIN      4
116 #define AO_MS5607_MISO_MASK     (1 << AO_MS5607_MISO_PIN)
117 #define AO_MS5607_SPI_INDEX     AO_SPI_1_PB3_PB4_PB5
118
119 /* CC1200 */
120
121 // #define AO_RADIO_CAL_DEFAULT         5695733
122 #define AO_RADIO_CAL_DEFAULT    5695947
123
124 #define AO_FEC_DEBUG            0
125 #define AO_CC1200_SPI_CS_PORT   (&stm_gpiob)
126 #define AO_CC1200_SPI_CS_PIN    0
127 #define AO_CC1200_SPI_BUS       AO_SPI_1_PA5_PA6_PA7
128 #define AO_CC1200_SPI           stm_spi1
129
130 #define AO_CC1200_INT_PORT              (&stm_gpiob)
131 #define AO_CC1200_INT_PIN               1
132
133 #define AO_CC1200_INT_GPIO      2
134 #define AO_CC1200_INT_GPIO_IOCFG        CC1200_IOCFG2
135
136
137 #define AO_DATA_RING            16
138
139 /*
140  * ADC
141  */
142
143 #define HAS_ADC                 1
144
145 #define AO_ADC_PIN0_PORT        (&stm_gpioa)
146 #define AO_ADC_PIN0_PIN         0
147 #define AO_ADC_PIN0_CH          0
148 #define AO_ADC_PIN1_PORT        (&stm_gpioa)
149 #define AO_ADC_PIN1_PIN         1
150 #define AO_ADC_PIN1_CH          1
151 #define AO_ADC_PIN2_PORT        (&stm_gpioa)
152 #define AO_ADC_PIN2_PIN         2
153 #define AO_ADC_PIN2_CH          2
154
155 #define AO_ADC_RCC_AHBENR       ((1 << STM_RCC_AHBENR_IOPAEN))
156
157 #define AO_NUM_ADC              3
158
159 struct ao_adc {
160         int16_t         sense_a;
161         int16_t         sense_m;
162         int16_t         v_batt;
163 };
164
165 /*
166  * Igniter
167  */
168
169 #define AO_IGNITER_CLOSED       400
170 #define AO_IGNITER_OPEN         60
171
172 #define AO_IGNITER_DROGUE_PORT  (&stm_gpiob)
173 #define AO_IGNITER_DROGUE_PIN   7
174 #define AO_IGNITER_SET_DROGUE(v)        ao_gpio_set(AO_IGNITER_DROGUE_PORT, AO_IGNITER_DROGUE_PIN, AO_IGNITER_DROGUE, v)
175
176 #define AO_IGNITER_MAIN_PORT    (&stm_gpiob)
177 #define AO_IGNITER_MAIN_PIN     6
178 #define AO_IGNITER_SET_MAIN(v)          ao_gpio_set(AO_IGNITER_MAIN_PORT, AO_IGNITER_MAIN_PIN, AO_IGNITER_MAIN, v)
179
180 #define AO_SENSE_DROGUE(p)      ((p)->adc.sense_a)
181 #define AO_SENSE_MAIN(p)        ((p)->adc.sense_m)
182
183 #define AO_ADC_DUMP(p) \
184         printf("tick: %5u apogee: %5d main: %5d batt: %5d\n", \
185                (p)->tick, (p)->adc.sense_a, (p)->adc.sense_m, (p)->adc.v_batt)
186
187 /*
188  * Voltage divider on ADC battery sampler
189  */
190 #define AO_BATTERY_DIV_PLUS     100     /* 100k */
191 #define AO_BATTERY_DIV_MINUS    27      /* 27k */
192
193 /*
194  * Voltage divider on ADC igniter samplers
195  */
196 #define AO_IGNITE_DIV_PLUS      100     /* 100k */
197 #define AO_IGNITE_DIV_MINUS     27      /* 27k */
198
199 /*
200  * ADC reference in decivolts
201  */
202 #define AO_ADC_REFERENCE_DV     33