CuVoodoo STM32F1 firmware template
global.h
Go to the documentation of this file.
1 /* This program is free software: you can redistribute it and/or modify
2  * it under the terms of the GNU General Public License as published by
3  * the Free Software Foundation, either version 3 of the License, or
4  * (at your option) any later version.
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program. If not, see <http://www.gnu.org/licenses/>.
13  *
14  */
20 #pragma once
21 
23 #define DEBUG false
24 
26 #define LENGTH(x) (sizeof(x) / sizeof((x)[0]))
27 
28 #define CAT2(x,y) x##y
29 
30 #define CAT3(x,y,z) x##y##z
31 
32 #define CAT4(w,x,y,z) w##x##y##z
33 
39 #define GPIO(x) CAT2(GPIO,x)
40 
41 #define RCC_GPIO(x) CAT2(RCC_GPIO,x)
42 
43 #define TIM(x) CAT2(TIM,x)
44 
45 #define RCC_TIM(x) CAT2(RCC_TIM,x)
46 
47 #define NVIC_TIM_IRQ(x) CAT3(NVIC_TIM,x,_IRQ)
48 
49 #define TIM_ISR(x) CAT3(tim,x,_isr)
50 
51 #define TIM_CH_PORT(x,y) CAT4(GPIO_BANK_TIM,x,_CH,y)
52 
53 #define TIM_CH_PIN(x,y) CAT4(GPIO_TIM,x,_CH,y)
54 
55 #define RCC_TIM_CH(x,y) CAT4(RCC_TIM,x,_CH,y)
56 #define RCC_TIM1_CH1 RCC_GPIOA
57 #define RCC_TIM1_CH2 RCC_GPIOA
58 #define RCC_TIM1_CH3 RCC_GPIOA
59 #define RCC_TIM1_CH4 RCC_GPIOA
60 #define RCC_TIM1_CH1N RCC_GPIOB
61 #define RCC_TIM1_CH2N RCC_GPIOB
62 #define RCC_TIM1_CH3N RCC_GPIOB
63 #define RCC_TIM2_CH1_ETR RCC_GPIOA
64 #define RCC_TIM2_CH2 RCC_GPIOA
65 #define RCC_TIM2_CH3 RCC_GPIOA
66 #define RCC_TIM2_CH4 RCC_GPIOA
67 #define RCC_TIM3_CH1 RCC_GPIOA
68 #define RCC_TIM3_CH2 RCC_GPIOA
69 #define RCC_TIM3_CH3 RCC_GPIOB
70 #define RCC_TIM3_CH4 RCC_GPIOB
71 #define RCC_TIM4_CH1 RCC_GPIOB
72 #define RCC_TIM4_CH2 RCC_GPIOB
73 #define RCC_TIM4_CH3 RCC_GPIOB
74 #define RCC_TIM4_CH4 RCC_GPIOB
75 #define RCC_TIM5_CH1 RCC_GPIOA
76 #define RCC_TIM5_CH2 RCC_GPIOA
77 #define RCC_TIM5_CH3 RCC_GPIOA
78 #define RCC_TIM5_CH4 RCC_GPIOA
80 #define TIM_IC(x) CAT2(TIM_IC,x)
81 
82 #define TIM_IC_IN_TI(x) CAT2(TIM_IC_IN_TI,x)
83 
84 #define TIM_SR_CCIF(x) CAT3(TIM_SR_CC,x,IF)
85 
86 #define TIM_DIER_CCIE(x) CAT3(TIM_DIER_CC,x,IE)
87 
88 #define TIM_CCR(x,y) CAT2(TIM_CCR,y)(TIM(x))
89 
90 #define EXTI(x) CAT2(EXTI,x)
91 
92 #define NVIC_EXTI_IRQ(x) CAT3(NVIC_EXTI,x,_IRQ)
93 #define NVIC_EXTI5_IRQ NVIC_EXTI9_5_IRQ
94 #define NVIC_EXTI6_IRQ NVIC_EXTI9_5_IRQ
95 #define NVIC_EXTI7_IRQ NVIC_EXTI9_5_IRQ
96 #define NVIC_EXTI8_IRQ NVIC_EXTI9_5_IRQ
97 #define NVIC_EXTI9_IRQ NVIC_EXTI9_5_IRQ
98 #define NVIC_EXTI10_IRQ NVIC_EXTI15_10_IRQ
99 #define NVIC_EXTI11_IRQ NVIC_EXTI15_10_IRQ
100 #define NVIC_EXTI12_IRQ NVIC_EXTI15_10_IRQ
101 #define NVIC_EXTI13_IRQ NVIC_EXTI15_10_IRQ
102 #define NVIC_EXTI14_IRQ NVIC_EXTI15_10_IRQ
103 #define NVIC_EXTI15_IRQ NVIC_EXTI15_10_IRQ
105 #define EXTI_ISR(x) CAT3(exti,x,_isr)
106 #define exti5_isr exti9_5_isr
107 #define exti6_isr exti9_5_isr
108 #define exti7_isr exti9_5_isr
109 #define exti8_isr exti9_5_isr
110 #define exti9_isr exti9_5_isr
111 #define exti10_isr exti15_10_isr
112 #define exti11_isr exti15_10_isr
113 #define exti12_isr exti15_10_isr
114 #define exti13_isr exti15_10_isr
115 #define exti14_isr exti15_10_isr
116 #define exti15_isr exti15_10_isr
118 #define USART(x) CAT2(USART,x)
119 
120 #define USART_RCC(x) CAT2(RCC_USART,x)
121 
122 #define USART_IRQ(x) CAT3(NVIC_USART,x,_IRQ)
123 
124 #define USART_ISR(x) CAT3(usart,x,_isr)
125 
126 #define USART_PORT(x) CAT2(USART_PORT,x)
127 #define USART_PORT1 GPIOA
128 #define USART_PORT2 GPIOA
129 #define USART_PORT3 GPIOB
131 #define USART_PORT_RCC(x) CAT2(RCC_USART_PORT,x)
132 #define RCC_USART_PORT1 RCC_GPIOA
133 #define RCC_USART_PORT2 RCC_GPIOA
134 #define RCC_USART_PORT3 RCC_GPIOB
136 #define USART_PIN_TX(x) CAT3(GPIO_USART,x,_TX)
137 
138 #define USART_PIN_RX(x) CAT3(GPIO_USART,x,_RX)
139 
140 #define ADC12_IN_PORT(x) CAT3(ADC12_IN,x,_PORT)
141 #define ADC12_IN0_PORT GPIOA
142 #define ADC12_IN1_PORT GPIOA
143 #define ADC12_IN2_PORT GPIOA
144 #define ADC12_IN3_PORT GPIOA
145 #define ADC12_IN4_PORT GPIOA
146 #define ADC12_IN5_PORT GPIOA
147 #define ADC12_IN6_PORT GPIOA
148 #define ADC12_IN7_PORT GPIOA
149 #define ADC12_IN8_PORT GPIOB
150 #define ADC12_IN9_PORT GPIOB
151 #define ADC12_IN10_PORT GPIOC
152 #define ADC12_IN11_PORT GPIOC
153 #define ADC12_IN12_PORT GPIOC
154 #define ADC12_IN13_PORT GPIOC
155 #define ADC12_IN14_PORT GPIOC
156 #define ADC12_IN15_PORT GPIOC
158 #define ADC12_IN_PIN(x) CAT3(ADC12_IN,x,_PIN)
159 #define ADC12_IN0_PIN GPIO0
160 #define ADC12_IN1_PIN GPIO1
161 #define ADC12_IN2_PIN GPIO2
162 #define ADC12_IN3_PIN GPIO3
163 #define ADC12_IN4_PIN GPIO4
164 #define ADC12_IN5_PIN GPIO5
165 #define ADC12_IN6_PIN GPIO6
166 #define ADC12_IN7_PIN GPIO7
167 #define ADC12_IN8_PIN GPIO0
168 #define ADC12_IN9_PIN GPIO1
169 #define ADC12_IN10_PIN GPIO0
170 #define ADC12_IN11_PIN GPIO1
171 #define ADC12_IN12_PIN GPIO2
172 #define ADC12_IN13_PIN GPIO3
173 #define ADC12_IN14_PIN GPIO4
174 #define ADC12_IN15_PIN GPIO5
176 #define RCC_ADC12_IN(x) CAT2(RCC_ADC12_IN,x)
177 #define RCC_ADC12_IN0 RCC_GPIOA
178 #define RCC_ADC12_IN1 RCC_GPIOA
179 #define RCC_ADC12_IN2 RCC_GPIOA
180 #define RCC_ADC12_IN3 RCC_GPIOA
181 #define RCC_ADC12_IN4 RCC_GPIOA
182 #define RCC_ADC12_IN5 RCC_GPIOA
183 #define RCC_ADC12_IN6 RCC_GPIOA
184 #define RCC_ADC12_IN7 RCC_GPIOA
185 #define RCC_ADC12_IN8 RCC_GPIOB
186 #define RCC_ADC12_IN9 RCC_GPIOB
187 #define RCC_ADC12_IN10 RCC_GPIOC
188 #define RCC_ADC12_IN11 RCC_GPIOC
189 #define RCC_ADC12_IN12 RCC_GPIOC
190 #define RCC_ADC12_IN13 RCC_GPIOC
191 #define RCC_ADC12_IN14 RCC_GPIOC
192 #define RCC_ADC12_IN15 RCC_GPIOC
194 #define ADC_CHANNEL(x) CAT2(ADC_CHANNEL,x)
195 
196 #define I2C(x) CAT2(I2C,x)
197 
198 #define RCC_I2C(x) CAT2(RCC_I2C,x)
199 
200 #define RCC_I2C_SCL_PORT(x) CAT3(RCC_I2C,x,_PORT)
201 #define RCC_I2C1_PORT RCC_GPIOB
202 #define RCC_I2C2_PORT RCC_GPIOB
204 #define RCC_I2C_SDA_PORT(x) CAT3(RCC_I2C,x,_PORT)
205 #define RCC_I2C1_SDA_PORT RCC_GPIOB
206 #define RCC_I2C2_SDA_PORT RCC_GPIOB
208 #define I2C_SCL_PORT(x) CAT3(GPIO_BANK_I2C,x,_SCL)
209 
210 #define I2C_SDA_PORT(x) CAT3(GPIO_BANK_I2C,x,_SDA)
211 
212 #define I2C_SCL_PIN(x) CAT3(GPIO_I2C,x,_SCL)
213 
214 #define I2C_SDA_PIN(x) CAT3(GPIO_I2C,x,_SDA)
215 
216 #define SPI(x) CAT2(SPI,x)
217 
218 #define RCC_SPI(x) CAT2(RCC_SPI,x)
219 
220 #define RCC_SPI_NSS_PORT(x) CAT3(RCC_SPI,x,_NSS_PORT)
221 #define RCC_SPI1_NSS_PORT RCC_GPIOA
222 #define RCC_SPI1_RE_NSS_PORT RCC_GPIOA
223 #define RCC_SPI2_NSS_PORT RCC_GPIOB
225 #define RCC_SPI_SCK_PORT(x) CAT3(RCC_SPI,x,_SCK_PORT)
226 #define RCC_SPI1_SCK_PORT RCC_GPIOA
227 #define RCC_SPI1_RE_SCK_PORT RCC_GPIOB
228 #define RCC_SPI2_SCK_PORT RCC_GPIOB
230 #define RCC_SPI_MISO_PORT(x) CAT3(RCC_SPI,x,_MISO_PORT)
231 #define RCC_SPI1_MISO_PORT RCC_GPIOA
232 #define RCC_SPI1_RE_MISO_PORT RCC_GPIOB
233 #define RCC_SPI2_MISO_PORT RCC_GPIOB
235 #define RCC_SPI_MOSI_PORT(x) CAT3(RCC_SPI,x,_MOSI_PORT)
236 #define RCC_SPI1_MOSI_PORT RCC_GPIOA
237 #define RCC_SPI1_RE_MOSI_PORT RCC_GPIOB
238 #define RCC_SPI2_MOSI_PORT RCC_GPIOB
240 #define SPI_NSS_PORT(x) CAT3(GPIO_BANK_SPI,x,_NSS)
241 
242 #define SPI_SCK_PORT(x) CAT3(GPIO_BANK_SPI,x,_SCK)
243 
244 #define SPI_MISO_PORT(x) CAT3(GPIO_BANK_SPI,x,_MISO)
245 
246 #define SPI_MOSI_PORT(x) CAT3(GPIO_BANK_SPI,x,_MOSI)
247 
248 #define SPI_NSS_PIN(x) CAT3(GPIO_SPI,x,_NSS)
249 
250 #define SPI_SCK_PIN(x) CAT3(GPIO_SPI,x,_SCK)
251 
252 #define SPI_MISO_PIN(x) CAT3(GPIO_SPI,x,_MISO)
253 
254 #define SPI_MOSI_PIN(x) CAT3(GPIO_SPI,x,_MOSI)
255 
261 #if defined(SYSTEM_BOARD) || defined(CORE_BOARD)
262 /* on system and core board LED is on pin 11/PA1 */
263 #define LED_PORT A
264 #define LED_PIN 1
265 #elif defined(BLUE_PILL)
266 /* on minimum system LED is on pin 2/PC13 */
267 #define LED_PORT C
268 #define LED_PIN 13
269 #elif defined (MAPLE_MINI)
270 /* on maple mini LED is on pin 19/PB1 */
271 #define LED_PORT B
272 #define LED_PIN 1
273 #endif
274 
279 #if defined(MAPLE_MINI)
280 /* on maple mini user button is on 32/PB8 */
281 #define BUTTON_PORT B
282 #define BUTTON_PIN 8
283 #elif defined(CORE_BOARD)
284 /* on core board user button is on PA8 */
285 #define BUTTON_PORT A
286 #define BUTTON_PIN 8
287 #endif
288 
290 extern volatile bool button_flag;
297 char* b2s(uint64_t binary, uint8_t rjust);
298 
300 void led_on(void);
301 
303 void led_off(void);
304 
306 void led_toggle(void);
307 
309 void board_setup(void);
310 
void led_off(void)
switch off board LED
Definition: global.c:68
void led_on(void)
switch on board LED
Definition: global.c:59
void led_toggle(void)
toggle board LED
Definition: global.c:77
char * b2s(uint64_t binary, uint8_t rjust)
get binary representation of a number
Definition: global.c:36
volatile bool button_flag
flag set when board user button has been pressed/released
Definition: global.c:34
void board_setup(void)
setup board peripherals
Definition: global.c:82