-
Notifications
You must be signed in to change notification settings - Fork 8
/
Pins.h
282 lines (225 loc) · 6.8 KB
/
Pins.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#pragma once
#include "pin.h"
#include "stm32.h"
// SWD
using PinSWDIO = Pin<'A',13>;
using PinSWDCLK = Pin<'A',14>;
using PinSWO = Pin<'B',3>;
#if BOARD == BOARD_SIGMA // Sigma board
// USB
using PinUsbDP = Pin<'A',12>;
using PinUsbDM = Pin<'A',11>;
// connected to USART-TX blue wire
using PinUsbVbus = Pin<'A',9>;
// real USB connection status
using PinUsbConnect = Pin<'B',15>;
// Misc
using PinButton = Pin<'B',14, 'L'>; // active low
using PinBuzzer = Pin<'C',8>; // TIM3_CH3 remapped
// Inputs
using PinWirePink = Pin<'C',0>;
using PinWireGreenYellow = Pin<'C',1>;
using PinWireViolet = Pin<'C',4>;
using PinWireBlackWhite = Pin<'B',0>;
using PinWireGreenBlack = Pin<'B',7>;
//using PinWireYellowBlack = Pin<'?',??>;
// Outputs
using PinWireYellowRed = Pin<'C',15>;
using PinWireBlueRed = Pin<'C',13>;
using PinWireBlackYellow = Pin<'C',3>;
using PinWireBlueBlack = Pin<'A',0>;
using PinWireYellow = Pin<'A',1>;
using PinWireOrangeViolet = Pin<'A',4>;
using PinWireBlackRed = Pin<'A',5>;
using PinWireOrangeGray = Pin<'A',6>;
using PinWireGrayBlack = Pin<'A',7>;
using PinWireOrangeBlack = Pin<'B',2>;
// SigmaBus - USART1
using PinWireBlue = Pin<'A',10>; // RX
using PinWireGreen = Pin<'A',9>; // TX !!! same as VBus
// CAN-bus; TJA1048
using PinCan1Rx = Pin<'B',8>; // remapped!
using PinCan1Tx = Pin<'B',9>;
using PinCan1Stdby = Pin<'B',1>;
using PinCan2Rx = Pin<'B',12>;
using PinCan2Tx = Pin<'B',13>;
using PinCan2Stdby = Pin<'C',14>;
// LIN; TJA1022
using PinLin1Tx = Pin<'A',2>; // USART2
using PinLin1Rx = Pin<'A',3>;
using PinLin1Slp = Pin<'A',8>;
using PinLin2Tx = Pin<'B',10>; // USART3
using PinLin2Rx = Pin<'B',11>;
using PinLin2Slp = Pin<'D',2>;
using PinLinBreak = Pin<'B',6>; // high to break link
using PinLin1Pullup = DummyPin<>;
using PinLin2Pullup = DummyPin<>;
// External flash
// SPI3, remapped
using PinFlashCS = Pin<'C',9>;
using PinFlashSCK = Pin<'C',10>;
using PinFlashMISO = Pin<'C',11>;
using PinFlashMOSI = Pin<'C',12>;
// unknown:
// PC2, PC5, PC6, PC7, PA15, PB4, PB5
inline void initRemap()
{
// use only SWD (not JTAG)
// remap CAN1, TIM3 (buzzer), SPI3
AFIO->MAPR =
AFIO_MAPR_SWJ_CFG_0 * 2 |
AFIO_MAPR_CAN_REMAP_0*2 |
AFIO_MAPR_TIM3_REMAP_0*3 |
AFIO_MAPR_SPI3_REMAP;
}
#elif BOARD == BOARD_2CAN
// USB
using PinUsbDP = Pin<'A',12>;
using PinUsbDM = Pin<'A',11>;
// connected to USART-TX blue wire
using PinUsbVbus = Pin<'A',9>;
using PinUsbConnect = DummyPinOn;
// CAN-bus; TJA1048
using PinCan1Rx = Pin<'B',8>; // remapped
using PinCan1Tx = Pin<'B',9>;
using PinCan1Stdby = Pin<'B',7>;
using PinCan2Rx = Pin<'B',5>; // remapped
using PinCan2Tx = Pin<'B',6>;
using PinCan2Stdby = Pin<'B',4>;
inline void initRemap()
{
// use only SWD (not JTAG)
// remap CAN1, CAN2
AFIO->MAPR =
AFIO_MAPR_SWJ_CFG_0 * 2 |
AFIO_MAPR_CAN_REMAP_0*2 |
AFIO_MAPR_CAN2_REMAP;
}
#elif BOARD == BOARD_CSAT
// USB
using PinUsbDP = Pin<'A',12>;
using PinUsbDM = Pin<'A',11>;
using PinUsbVbus = Pin<'A',9>;
using PinUsbConnect = DummyPinOn;
//using PinUsbConnect = Pin<'A',9>;
//using PinUsbVbus = DummyPinOn;
// CAN-bus; TJA1042
using PinCan1Rx = Pin<'B',8>; // remapped
using PinCan1Tx = Pin<'B',9>;
using PinCan1Stdby = Pin<'B',7, 'L'>;
using PinCan2Rx = Pin<'B',5>; // remapped
using PinCan2Tx = Pin<'B',6>;
using PinCan2Stdby = Pin<'B',4, 'L'>;
using PinCan22Rx = Pin<'B',12>; // "third" channel
using PinCan22Tx = Pin<'B',13>;
using PinCan22Stdby = Pin<'B',14, 'L'>;
// LIN; TJA1021
using PinLin1Tx = Pin<'A',2>; // USART2
using PinLin1Rx = Pin<'A',3>;
using PinLin1Slp = Pin<'A',4>;
using PinLin2Tx = Pin<'B',10>; // USART3
using PinLin2Rx = Pin<'B',11>;
using PinLin2Slp = Pin<'A',5>;
using PinLin1Pullup = DummyPin<>;
using PinLin2Pullup = DummyPin<>;
// Misc
using PinButton = Pin<'A',0, 'L'>; // active low
using PinLedTx = Pin<'A',6, 'L'>; // TIM3 ch1
using PinLedRx = Pin<'A',7, 'L'>; // TIM3 ch2
inline void initRemap()
{
// use only SWD (not JTAG)
// remap CAN1, CAN2
AFIO->MAPR =
AFIO_MAPR_SWJ_CFG_0 * 2 |
AFIO_MAPR_CAN_REMAP_REMAP2 | // PB8,PB9
AFIO_MAPR_CAN2_REMAP; // PB5,PB6
}
#elif BOARD == BOARD_2CAN30
// USB
using PinUsbDP = Pin<'A',12>;
using PinUsbDM = Pin<'A',11>;
using PinUsbVbus = Pin<'A',9>;
using PinUsbConnect = Pin<'B',5>;
// CAN-bus; TJA1048
using PinCan1Rx = Pin<'B',8>; // remapped
using PinCan1Tx = Pin<'B',9>;
using PinCan1Stdby = Pin<'B',7>;
using PinCan2Rx = Pin<'B',12>;
using PinCan2Tx = Pin<'B',13>;
using PinCan2Stdby = Pin<'B',11>;
// Misc
using PinButton = Pin<'B',14,'L'>; // active low
inline void initRemap()
{
// use only SWD (not JTAG)
// remap CAN1
AFIO->MAPR =
AFIO_MAPR_SWJ_CFG_0 * 2 |
AFIO_MAPR_CAN_REMAP_0*2;
}
#elif BOARD == BOARD_2CAN2LIN // 2CAN-2LIN board
// USB
using PinUsbDP = Pin<'A',12>;
using PinUsbDM = Pin<'A',11>;
using PinUsbVbus = Pin<'A',9>;
// real USB connection status
using PinUsbConnect = Pin<'B',3>;
// Misc
using PinButton = Pin<'B',10, 'L'>; // active low
using PinLedTx = Pin<'C',6>; // TIM3 ch1 remapped
using PinLedRx = Pin<'C',7>; // TIM3 ch2
// CAN-bus
using PinCan1Rx = Pin<'B',8>; // remapped!
using PinCan1Tx = Pin<'B',9>;
using PinCan1Stdby = Pin<'B',7, 'L'>;
using PinCan2Rx = Pin<'B',5>; // remapped!
using PinCan2Tx = Pin<'B',6>;
using PinCan2Stdby = Pin<'B',14, 'L'>;
// LIN
using PinLin1Tx = Pin<'A',2>; // USART2
using PinLin1Rx = Pin<'A',3>;
using PinLin1Slp = Pin<'C',5>;
using PinLin2Tx = Pin<'C',10>; // USART3 remapped
using PinLin2Rx = Pin<'C',11>;
using PinLin2Slp = Pin<'B',1>;
using PinLinBreak = Pin<'A',0>; // high to break link
using PinLin1Pullup = Pin<'C',4>;
using PinLin2Pullup = Pin<'B',0>;
// External flash
// SPI1
using PinFlashCS = Pin<'A',4>;
using PinFlashSCK = Pin<'A',5>;
using PinFlashMISO = Pin<'A',6>;
using PinFlashMOSI = Pin<'A',7>;
inline void initRemap()
{
// use only SWD (not JTAG)
// remap CAN1, CAN2, USART3, TIM3
AFIO->MAPR =
AFIO_MAPR_SWJ_CFG_0 * 2 |
AFIO_MAPR_CAN_REMAP_0 * 2 |
AFIO_MAPR_CAN2_REMAP |
AFIO_MAPR_USART3_REMAP_0 * 1 |
AFIO_MAPR_TIM3_REMAP_0 * 3
;
}
#else
#error undefined BOARD !
#endif // BOARD == xxx
namespace TestPins {
inline void setMode(char port, int pin, int mode)
{
auto gpio = (GPIOxTypeDef*)(pGPIOA_BASE + (pGPIOB_BASE-pGPIOA_BASE) * (port-'A'));
auto &control = (pin < 8) ? gpio->CRL : gpio->CRH;
int offset = (pin & 7) * 4;
control = (control & ~(0xF << offset)) | (mode << offset);
}
inline void setOut(char port, int pin, int on)
{
auto gpio = (GPIOxTypeDef*)(pGPIOA_BASE + (pGPIOB_BASE-pGPIOA_BASE) * (port-'A'));
pin &= 0xF;
if (on) gpio->BSRR = 1<<pin;
else gpio->BRR = 1<<pin;
}
};