altos: Switch micropeak v2.0 to stm32l0
[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       STM_MSI_FREQ
24
25 #define LED_0_PORT      (&stm_gpioa)
26 #define LED_0_PIN       1
27 #define AO_LED_ORANGE   (1 << 0)
28 #define AO_LED_REPORT   AO_LED_ORANGE
29 #define AO_LED_PANIC    AO_LED_ORANGE
30
31 #define LEDS_AVAILABLE  (AO_LED_ORANGE)
32
33 #define AO_POWER_MANAGEMENT     0
34
35 /* HCLK = MSI (2.097MHz) */
36 #define AO_AHB_PRESCALER        (1)
37 #define AO_RCC_CFGR_HPRE_DIV    (STM_RCC_CFGR_HPRE_DIV_1)
38
39 /* APB = MSI */
40 #define AO_APB1_PRESCALER       (1)
41 #define AO_APB2_PRESCALER       (1)
42 #define AO_RCC_CFGR_PPRE_DIV    (STM_RCC_CFGR_PPRE_DIV_1)
43
44 #define PACKET_HAS_SLAVE        0
45 #define HAS_SERIAL_1            0
46 #define HAS_SERIAL_2            1
47 #define USE_SERIAL_2_STDIN      1
48 #define USE_SERIAL_2_FLOW       0
49 #define USE_SERIAL_2_SW_FLOW    0
50 #define SERIAL_2_PA9_PA10       1
51
52 #define IS_FLASH_LOADER         0
53
54 #define HAS_MS5607              1
55 #define HAS_SENSOR_ERRORS       0
56 #define HAS_MS5611              0
57 #define HAS_MS5607_TASK         0
58 #define HAS_EEPROM              1
59 #define HAS_CONFIG_SAVE         0
60 #define HAS_BEEP                0
61
62 /* Logging */
63 #define LOG_INTERVAL            1
64 #define SAMPLE_SLEEP            AO_MS_TO_TICKS(100)
65 #define BOOST_DELAY             AO_SEC_TO_TICKS(60)
66 #define AO_LOG_ID               AO_LOG_ID_MICROPEAK2
67 #define HAS_LOG                 1
68 #define AO_LOG_FORMAT           AO_LOG_FORMAT_MICROPEAK2
69 #define FLIGHT_LOG_APPEND       1
70
71 /* Kalman filter */
72
73 #define AO_MK_STEP_100MS        1
74 #define AO_MK_STEP_96MS         0
75
76 /* SPI */
77 #define HAS_SPI_1               1
78 #define SPI_1_POWER_MANAGE      1
79 #define SPI_1_PA5_PA6_PA7       1
80 #define SPI_1_PB3_PB4_PB5       0
81 #define SPI_1_OSPEEDR           STM_OSPEEDR_MEDIUM
82
83 #define HAS_SPI_2               0
84
85 /* MS5607 */
86 #define HAS_MS5607              1
87 #define HAS_MS5611              0
88 #define AO_MS5607_PRIVATE_PINS  0
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 typedef int32_t alt_t;
98
99 #define AO_ALT_VALUE(x)         ((x) * (alt_t) 10)
100
101 #define HAS_ADC                 0
102 #define HAS_AO_DELAY            1
103
104 static inline void
105 ao_power_off(void) __attribute((noreturn));
106
107 static inline void
108 ao_power_off(void) {
109         for (;;) {
110         }
111 }
112
113 extern alt_t ao_max_height;
114
115 #define ao_async_stop() do {                                    \
116                 ao_serial2_drain();                             \
117                 stm_moder_set(&stm_gpioa, 2, STM_MODER_OUTPUT); \
118                 ao_serial_shutdown();                           \
119         } while (0)
120
121 #define ao_async_start() do {                                           \
122                 ao_serial_init();                                       \
123                 stm_moder_set(&stm_gpioa, 2, STM_MODER_ALTERNATE);      \
124                 ao_delay(AO_MS_TO_TICKS(100));                          \
125         } while (0)
126
127 #define ao_async_byte(b) ao_serial2_putchar((char) (b))
128
129 #define ao_eeprom_read(pos, ptr, size) ao_storage_read(pos, ptr, size)
130 #define ao_eeprom_write(pos, ptr, size) ao_storage_write(pos, ptr, size)
131 #define MAX_LOG_OFFSET  ao_storage_total
132 #define ao_storage_log_max ao_storage_total
133
134 extern uint32_t __flash__[];
135 extern uint32_t __flash_end__[];
136
137 #define AO_BOOT_APPLICATION_BOUND       ((uint32_t *) __flash__)
138 #define USE_STORAGE_CONFIG      0
139
140 #endif /* _AO_PINS_H_ */