altos/micropeak-v2.0: Reduce power usage
[fw/altos] / src / micropeak-v2.0 / ao_pins.h
1 /*
2  * Copyright © 2011 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 #ifndef _AO_PINS_H_
19 #define _AO_PINS_H_
20
21 extern uint8_t ao_on_battery;
22
23 #define AO_SYSCLK       (ao_on_battery ? STM_HSI_FREQ : 48000000)
24
25 #define LED_PORT_ENABLE STM_RCC_AHBENR_IOPAEN
26 #define LED_PORT        (&stm_gpioa)
27 #define LED_PIN_ORANGE  2
28 #define AO_LED_ORANGE   (1 << LED_PIN_ORANGE)
29 #define AO_LED_REPORT   AO_LED_ORANGE
30 #define AO_LED_PANIC    AO_LED_ORANGE
31
32 #define LEDS_AVAILABLE  (AO_LED_ORANGE)
33
34 #define AO_POWER_MANAGEMENT     0
35
36 /* 48MHz clock based on USB */
37 #define AO_HSI48        1
38 /* Need HSI running to flash */
39 #define AO_NEED_HSI     1
40
41 /* HCLK = 12MHz usb / 2MHz battery */
42 #define AO_AHB_PRESCALER        (ao_on_battery ? 16 : 1)
43 #define AO_RCC_CFGR_HPRE_DIV    (ao_on_battery ? STM_RCC_CFGR_HPRE_DIV_16 : STM_RCC_CFGR_HPRE_DIV_1)
44
45 /* APB = 12MHz usb / 2MHz battery */
46 #define AO_APB_PRESCALER        (ao_on_battery ? 2 : 1)
47 #define AO_RCC_CFGR_PPRE_DIV    (ao_on_battery ? STM_RCC_CFGR_PPRE_DIV_2 : STM_RCC_CFGR_PPRE_DIV_1)
48
49 #define HAS_USB                 1
50 #define AO_PA11_PA12_RMP        1
51
52 #define PACKET_HAS_SLAVE        0
53 #define HAS_SERIAL_1            0
54 #define HAS_SERIAL_2            1
55 #define USE_SERIAL_2_STDIN      0
56 #define USE_SERIAL_2_FLOW       0
57 #define USE_SERIAL_2_SW_FLOW    0
58 #define SERIAL_2_PA2_PA3        1
59 #define SERIAL_2_PA14_PA15      0
60 #define USE_SERIAL2_FLOW        0
61 #define USE_SERIAL2_SW_FLOW     0
62
63 #define IS_FLASH_LOADER         0
64
65 #define HAS_MS5607              1
66 #define HAS_SENSOR_ERRORS       0
67 #define HAS_MS5611              0
68 #define HAS_MS5607_TASK         0
69 #define HAS_EEPROM              1
70 #define HAS_CONFIG_SAVE         0
71 #define HAS_BEEP                0
72
73 /* Logging */
74 #define LOG_INTERVAL            1
75 #define SAMPLE_SLEEP            AO_MS_TO_TICKS(100)
76 #define BOOST_DELAY             AO_SEC_TO_TICKS(60)
77 #define AO_LOG_ID               AO_LOG_ID_MICROPEAK2
78 #define HAS_LOG                 1
79 #define AO_LOG_FORMAT           AO_LOG_FORMAT_MICROPEAK2
80 #define FLIGHT_LOG_APPEND       1
81
82 /* Kalman filter */
83
84 #define AO_MK_STEP_100MS        1
85 #define AO_MK_STEP_96MS         0
86
87 /* SPI */
88 #define HAS_SPI_1               1
89 #define SPI_1_POWER_MANAGE      1
90 #define SPI_1_PA5_PA6_PA7       1
91 #define SPI_1_PB3_PB4_PB5       0
92 #define SPI_1_OSPEEDR           STM_OSPEEDR_MEDIUM
93
94 #define HAS_SPI_2               0
95
96 /* MS5607 */
97 #define HAS_MS5607              1
98 #define HAS_MS5611              0
99 #define AO_MS5607_PRIVATE_PINS  0
100 #define AO_MS5607_CS_PORT       (&stm_gpioa)
101 #define AO_MS5607_CS_PIN        4
102 #define AO_MS5607_CS_MASK       (1 << AO_MS5607_CS_PIN)
103 #define AO_MS5607_MISO_PORT     (&stm_gpioa)
104 #define AO_MS5607_MISO_PIN      6
105 #define AO_MS5607_MISO_MASK     (1 << AO_MS5607_MISO_PIN)
106 #define AO_MS5607_SPI_INDEX     AO_SPI_1_PA5_PA6_PA7
107
108 typedef int32_t alt_t;
109
110 #define AO_ALT_VALUE(x)         ((x) * (alt_t) 10)
111
112 #define AO_DATA_RING            32
113
114 #define HAS_ADC                 0
115
116 static inline void
117 ao_power_off(void) __attribute((noreturn));
118
119 static inline void
120 ao_power_off(void) {
121         for (;;) {
122         }
123 }
124
125 extern alt_t ao_max_height;
126
127 void ao_delay_until(uint16_t target);
128
129 #define ao_async_stop() do {                                    \
130                 ao_serial2_drain();                             \
131                 stm_moder_set(&stm_gpioa, 2, STM_MODER_OUTPUT); \
132                 ao_serial_shutdown();                           \
133         } while (0)
134
135 #define ao_async_start() do {                                           \
136                 ao_serial_init();                                       \
137                 stm_moder_set(&stm_gpioa, 2, STM_MODER_ALTERNATE);      \
138                 ao_delay(AO_MS_TO_TICKS(100));                          \
139         } while (0)
140
141 #define ao_async_byte(b) ao_serial2_putchar((char) (b))
142
143 #define ao_eeprom_read(pos, ptr, size) ao_storage_read(pos, ptr, size)
144 #define ao_eeprom_write(pos, ptr, size) ao_storage_write(pos, ptr, size)
145 #define MAX_LOG_OFFSET  ao_storage_total
146 #define ao_storage_log_max ao_storage_total
147
148 extern uint32_t __flash__[];
149 extern uint32_t __flash_end__[];
150
151 #define AO_BOOT_APPLICATION_BOUND       ((uint32_t *) __flash__)
152 #define USE_STORAGE_CONFIG      0
153
154 #endif /* _AO_PINS_H_ */