altos: Eliminate 'pin' field from GPIO functions
[fw/altos] / src / telemini-v3.0 / ao_pins.h
1 /*
2  * Copyright © 2017 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 #define HAS_BEEP                1
20 #define HAS_SERIAL_1            0
21 #define HAS_BATTERY_REPORT      1
22
23 #define AO_STACK_SIZE   448
24
25 #define IS_FLASH_LOADER 0
26
27 /* 48MHz clock based on 16MHz reference */
28 //#define AO_HSI48      1
29 #define AO_HSE                  16000000
30 #define AO_RCC_CFGR_PLLMUL      STM_RCC_CFGR_PLLMUL_3
31 #define AO_RCC_CFGR2_PLLDIV     STM_RCC_CFGR2_PREDIV_1
32 #define AO_PLLMUL               3
33 #define AO_PLLDIV               1
34
35 /* HCLK = 48MHz */
36 #define AO_AHB_PRESCALER        1
37 #define AO_RCC_CFGR_HPRE_DIV    STM_RCC_CFGR_HPRE_DIV_1
38
39 /* APB = 40MHz */
40 #define AO_APB_PRESCALER        1
41 #define AO_RCC_CFGR_PPRE_DIV    STM_RCC_CFGR_PPRE_DIV_1
42
43 #define HAS_USB                 1
44 #define AO_USB_DIRECTIO         0
45 #define AO_PA11_PA12_RMP        1
46 #define AO_USB_FORCE_IDLE       1
47
48 #define PACKET_HAS_SLAVE        1
49
50 #define AO_LOG_FORMAT           AO_LOG_FORMAT_TELEMINI3
51 #define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX        ((uint32_t) 112 * (uint32_t) 1024)
52
53 #define HAS_BOOT_RADIO          0
54
55 #define HAS_ACCEL               0
56 #define HAS_GPS                 0
57 #define HAS_RADIO               1
58 #define HAS_RADIO_RATE          1
59 #define HAS_FLIGHT              1
60 #define HAS_EEPROM              1
61 #define HAS_TELEMETRY           1
62 #define AO_SEND_MINI            AO_TELEMETRY_MINI3
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 #define AO_SMALL_ALTITUDE_TABLE 1
69
70 /* Use debug connector clock for recovery mode */
71 #define HAS_FORCE_FREQ          1
72 #define AO_RECOVERY_PORT        (&stm_gpioa)
73 #define AO_RECOVERY_PIN         14
74 #define AO_RECOVERY_VALUE       0
75 #define AO_RECOVERY_MODE        AO_EXTI_MODE_PULL_UP
76
77 /* Beeper is on Tim1 CH3 */
78 #define BEEPER_CHANNEL          4
79 #define BEEPER_TIMER            2
80 #define BEEPER_PORT             (&stm_gpioa)
81 #define BEEPER_PIN              3
82
83 /* SPI */
84
85 #define HAS_SPI_1               1
86 #define SPI_1_PA5_PA6_PA7       1
87 #define SPI_1_PB3_PB4_PB5       1
88 #define SPI_1_OSPEEDR           STM_OSPEEDR_MEDIUM
89
90 /* M25 */
91
92 #define M25_MAX_CHIPS           1
93 #define AO_M25_SPI_CS_PORT      (&stm_gpioa)
94 #define AO_M25_SPI_CS_MASK      (1 << 4)
95 #define AO_M25_SPI_BUS          AO_SPI_1_PA5_PA6_PA7
96
97 /* MS5607 */
98
99 #define HAS_MS5607              1
100 #define HAS_MS5611              0
101 #define AO_MS5607_PRIVATE_PINS  1
102 #define AO_MS5607_CS_PORT       (&stm_gpioa)
103 #define AO_MS5607_CS_PIN        15
104 #define AO_MS5607_CS_MASK       (1 << AO_MS5607_CS_PIN)
105 #define AO_MS5607_MISO_PORT     (&stm_gpiob)
106 #define AO_MS5607_MISO_PIN      4
107 #define AO_MS5607_MISO_MASK     (1 << AO_MS5607_MISO_PIN)
108 #define AO_MS5607_SPI_INDEX     AO_SPI_1_PB3_PB4_PB5
109 #define AO_MS5607_SPI_SPEED     AO_SPI_SPEED_12MHz
110
111 /* CC1200 */
112
113 // #define AO_RADIO_CAL_DEFAULT         5695733
114 #define AO_RADIO_CAL_DEFAULT    5695717
115
116 #define AO_FEC_DEBUG            0
117 #define CC1200_DEBUG            0
118 #define AO_CC1200_SPI_CS_PORT   (&stm_gpiob)
119 #define AO_CC1200_SPI_CS_PIN    0
120 #define AO_CC1200_SPI_BUS       AO_SPI_1_PA5_PA6_PA7
121 #define AO_CC1200_SPI           stm_spi1
122 #define AO_CC1200_SPI_SPEED     AO_SPI_SPEED_12MHz
123
124 #define AO_CC1200_INT_PORT              (&stm_gpiob)
125 #define AO_CC1200_INT_PIN               1
126
127 #define AO_CC1200_INT_GPIO      2
128 #define AO_CC1200_INT_GPIO_IOCFG        CC1200_IOCFG2
129
130
131 #define AO_DATA_RING            16
132
133 /*
134  * ADC
135  */
136
137 #define HAS_ADC                 1
138
139 #define AO_ADC_PIN0_PORT        (&stm_gpioa)    /* sense_m */
140 #define AO_ADC_PIN0_PIN         0
141 #define AO_ADC_PIN0_CH          0
142 #define AO_ADC_PIN1_PORT        (&stm_gpioa)    /* sense_a */
143 #define AO_ADC_PIN1_PIN         1
144 #define AO_ADC_PIN1_CH          1
145 #define AO_ADC_PIN2_PORT        (&stm_gpioa)    /* v_batt */
146 #define AO_ADC_PIN2_PIN         2
147 #define AO_ADC_PIN2_CH          2
148
149 #define AO_ADC_RCC_AHBENR       ((1 << STM_RCC_AHBENR_IOPAEN))
150
151 #define AO_NUM_ADC              3
152
153 struct ao_adc {
154         int16_t         sense_m;
155         int16_t         sense_a;
156         int16_t         v_batt;
157 };
158
159 /*
160  * Igniter
161  */
162
163 #define AO_IGNITER_CLOSED       400
164 #define AO_IGNITER_OPEN         60
165
166 #define AO_IGNITER_DROGUE_PORT  (&stm_gpiob)
167 #define AO_IGNITER_DROGUE_PIN   7
168
169 #define AO_IGNITER_MAIN_PORT    (&stm_gpiob)
170 #define AO_IGNITER_MAIN_PIN     6
171
172 #define AO_SENSE_DROGUE(p)      ((p)->adc.sense_a)
173 #define AO_SENSE_MAIN(p)        ((p)->adc.sense_m)
174
175 #define AO_ADC_DUMP(p) \
176         printf("tick: %5u apogee: %5d main: %5d batt: %5d\n", \
177                (p)->tick, (p)->adc.sense_a, (p)->adc.sense_m, (p)->adc.v_batt)
178
179 /*
180  * Voltage divider on ADC battery sampler
181  */
182 #define AO_BATTERY_DIV_PLUS     56      /* 5.6k */
183 #define AO_BATTERY_DIV_MINUS    100     /* 10k */
184
185 /*
186  * Voltage divider on ADC igniter samplers
187  */
188 #define AO_IGNITE_DIV_PLUS      100     /* 100k */
189 #define AO_IGNITE_DIV_MINUS     27      /* 27k */
190
191 /*
192  * ADC reference in decivolts
193  */
194 #define AO_ADC_REFERENCE_DV     33