altos: Add bit-bang i2c driver
[fw/altos] / src / easymini-v2.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_BATTERY_REPORT      1
21
22 #define AO_STACK_SIZE   448
23
24 #define IS_FLASH_LOADER 0
25
26 /* 48MHz clock based on 16MHz reference */
27 //#define AO_HSI48      1
28 #define AO_HSE                  16000000
29 #define AO_RCC_CFGR_PLLMUL      STM_RCC_CFGR_PLLMUL_3
30 #define AO_RCC_CFGR2_PLLDIV     STM_RCC_CFGR2_PREDIV_1
31 #define AO_PLLMUL               3
32 #define AO_PLLDIV               1
33
34 /* HCLK = 48MHz */
35 #define AO_AHB_PRESCALER        1
36 #define AO_RCC_CFGR_HPRE_DIV    STM_RCC_CFGR_HPRE_DIV_1
37
38 /* APB = 40MHz */
39 #define AO_APB_PRESCALER        1
40 #define AO_RCC_CFGR_PPRE_DIV    STM_RCC_CFGR_PPRE_DIV_1
41
42 #define HAS_USB                 1
43 #define AO_USB_DIRECTIO         0
44 #define AO_PA11_PA12_RMP        1
45 #define AO_USB_FORCE_IDLE       1
46
47 #define AO_LOG_FORMAT           AO_LOG_FORMAT_EASYMINI2
48
49 #define HAS_BOOT_RADIO          0
50
51 #define HAS_ACCEL               0
52 #define HAS_GPS                 0
53 #define HAS_RADIO               0
54 #define HAS_FLIGHT              1
55 #define HAS_EEPROM              1
56 #define HAS_TELEMETRY           0
57 #define HAS_APRS                0
58 #define HAS_LOG                 1
59 #define USE_INTERNAL_FLASH      0
60 #define HAS_IGNITE              1
61 #define HAS_IGNITE_REPORT       1
62
63 /* Beeper is on Tim3 CH4 */
64 #define BEEPER_TIMER            3
65 #define BEEPER_CHANNEL          4
66 #define BEEPER_PORT             (&stm_gpiob)
67 #define BEEPER_PIN              1
68 #define BEEPER_AFR              STM_AFR_AF1
69
70 /* SPI */
71
72 #define HAS_SPI_1               1
73 #define SPI_1_PA5_PA6_PA7       1
74 #define SPI_1_PB3_PB4_PB5       1
75 #define SPI_1_OSPEEDR           STM_OSPEEDR_MEDIUM
76
77 /* M25 */
78
79 #define M25_MAX_CHIPS           1
80 #define AO_M25_SPI_CS_PORT      (&stm_gpioa)
81 #define AO_M25_SPI_CS_MASK      (1 << 15)
82 #define AO_M25_SPI_BUS          AO_SPI_1_PB3_PB4_PB5
83
84 /* MS5607 */
85
86 #define HAS_MS5607              1
87 #define HAS_MS5611              0
88 #define AO_MS5607_PRIVATE_PINS  1
89 #define AO_MS5607_CS_PORT       (&stm_gpioa)
90 #define AO_MS5607_CS_PIN        4
91 #define AO_MS5607_CS_MASK       (1 << AO_MS5607_CS_PIN)
92 #define AO_MS5607_MISO_PORT     (&stm_gpioa)
93 #define AO_MS5607_MISO_PIN      6
94 #define AO_MS5607_MISO_MASK     (1 << AO_MS5607_MISO_PIN)
95 #define AO_MS5607_SPI_INDEX     AO_SPI_1_PA5_PA6_PA7
96
97 #define AO_DATA_RING            64
98
99 /*
100  * ADC
101  */
102
103 #define HAS_ADC                 1
104
105 #define AO_ADC_PIN0_PORT        (&stm_gpioa)    /* sense_m */
106 #define AO_ADC_PIN0_PIN         0
107 #define AO_ADC_PIN0_CH          0
108 #define AO_ADC_PIN1_PORT        (&stm_gpioa)    /* sense_a */
109 #define AO_ADC_PIN1_PIN         1
110 #define AO_ADC_PIN1_CH          1
111 #define AO_ADC_PIN2_PORT        (&stm_gpioa)    /* v_batt */
112 #define AO_ADC_PIN2_PIN         2
113 #define AO_ADC_PIN2_CH          2
114
115 #define AO_ADC_RCC_AHBENR       ((1 << STM_RCC_AHBENR_IOPAEN))
116
117 #define AO_NUM_ADC              3
118
119 struct ao_adc {
120         int16_t         sense_m;
121         int16_t         sense_a;
122         int16_t         v_batt;
123 };
124
125 /*
126  * Igniter
127  */
128
129 #define AO_IGNITER_CLOSED       400
130 #define AO_IGNITER_OPEN         60
131
132 #define AO_IGNITER_DROGUE_PORT  (&stm_gpioa)
133 #define AO_IGNITER_DROGUE_PIN   3
134
135 #define AO_IGNITER_MAIN_PORT    (&stm_gpiob)
136 #define AO_IGNITER_MAIN_PIN     7
137
138 #define AO_SENSE_DROGUE(p)      ((p)->adc.sense_a)
139 #define AO_SENSE_MAIN(p)        ((p)->adc.sense_m)
140
141 #define AO_ADC_DUMP(p) \
142         printf("tick: %5u apogee: %5d main: %5d batt: %5d\n", \
143                (p)->tick, (p)->adc.sense_a, (p)->adc.sense_m, (p)->adc.v_batt)
144
145 /*
146  * Voltage divider on ADC battery sampler
147  */
148 #define AO_BATTERY_DIV_PLUS     100     /* 100k */
149 #define AO_BATTERY_DIV_MINUS    27      /* 27k */
150
151 /*
152  * Voltage divider on ADC igniter samplers
153  */
154 #define AO_IGNITE_DIV_PLUS      100     /* 100k */
155 #define AO_IGNITE_DIV_MINUS     27      /* 27k */
156
157 /*
158  * ADC reference in decivolts
159  */
160 #define AO_ADC_REFERENCE_DV     33