Mbed OS Reference
Loading...
Searching...
No Matches
static_pinmap.h
1/* mbed Microcontroller Library
2 * Copyright (c) 2018-2019 ARM Limited
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17#ifndef STATIC_PINMAP_H
18#define STATIC_PINMAP_H
19
20#include "hal/PinNameAliases.h"
21#include "PinNames.h"
22#include "spi_api.h"
23#include "pwmout_api.h"
24#include "analogin_api.h"
25#include "analogout_api.h"
26#include "i2c_api.h"
27#include "serial_api.h"
28#include "qspi_api.h"
29#include "ospi_api.h"
30#include "can_api.h"
31#include <mstd_cstddef>
32
33#if STATIC_PINMAP_READY
34#include "PeripheralPinMaps.h"
35
36
37#if defined(DEVICE_PWMOUT) && defined(PINMAP_PWM)
38MSTD_CONSTEXPR_FN_14 PinMap get_pwm_pinmap(const PinName pin)
39{
40 for (const PinMap &pinmap : PINMAP_PWM) {
41 if (pinmap.pin == pin) {
42 return {pin, pinmap.peripheral, pinmap.function};
43 }
44 }
45 return {NC, (int) NC, (int) NC};
46}
47#endif // DEVICE_PWMOUT
48
49#if defined(DEVICE_ANALOGIN) && defined(PINMAP_ANALOGIN)
50MSTD_CONSTEXPR_FN_14 PinMap get_analogin_pinmap(const PinName pin)
51{
52 for (const PinMap &pinmap : PINMAP_ANALOGIN) {
53 if (pinmap.pin == pin) {
54 return {pin, pinmap.peripheral, pinmap.function};
55 }
56 }
57
58#if PINMAP_ANALOGIN_INTERNAL
59 for (const PinMap &pinmap : PINMAP_ANALOGIN_INTERNAL) {
60 if (pinmap.pin == pin) {
61 return {pin, pinmap.peripheral, pinmap.function};
62 }
63 }
64#endif
65
66 return {NC, (int) NC, (int) NC};
67}
68#endif // DEVICE_ANALOGIN
69
70#if defined(DEVICE_ANALOGOUT) && defined(PINMAP_ANALOGOUT)
71MSTD_CONSTEXPR_FN_14 PinMap get_analogout_pinmap(const PinName pin)
72{
73 for (const PinMap &pinmap : PINMAP_ANALOGOUT) {
74 if (pinmap.pin == pin) {
75 return {pin, pinmap.peripheral, pinmap.function};
76 }
77 }
78 return {NC, (int) NC, (int) NC};
79}
80#endif // DEVICE_ANALOGOUT
81
82#if defined(DEVICE_I2C) && defined(PINMAP_I2C_SDA) && defined(PINMAP_I2C_SCL)
83MSTD_CONSTEXPR_FN_14 i2c_pinmap_t get_i2c_pinmap(const PinName sda, const PinName scl)
84{
85 const PinMap *sda_map = nullptr;
86 for (const PinMap &pinmap : PINMAP_I2C_SDA) {
87 if (pinmap.pin == sda) {
88 sda_map = &pinmap;
89 break;
90 }
91 }
92
93 const PinMap *scl_map = nullptr;
94 for (const PinMap &pinmap : PINMAP_I2C_SCL) {
95 if (pinmap.pin == scl) {
96 scl_map = &pinmap;
97 break;
98 }
99 }
100
101 if (!sda_map || !scl_map || sda_map->peripheral != scl_map->peripheral) {
102 return {(int) NC, NC, (int) NC, NC, (int) NC};
103 }
104
105 return {sda_map->peripheral, sda_map->pin, sda_map->function, scl_map->pin, scl_map->function};
106}
107#endif //DEVICE_I2C
108
109#if defined(DEVICE_SERIAL) && defined(PINMAP_UART_TX) && defined(PINMAP_UART_RX)
110MSTD_CONSTEXPR_FN_14 serial_pinmap_t get_uart_pinmap(const PinName tx, const PinName rx)
111{
112 const PinMap *tx_map = nullptr;
113 for (const PinMap &pinmap : PINMAP_UART_TX) {
114 if (pinmap.pin == tx) {
115 tx_map = &pinmap;
116 break;
117 }
118 }
119
120 const PinMap *rx_map = nullptr;
121 for (const PinMap &pinmap : PINMAP_UART_RX) {
122 if (pinmap.pin == rx) {
123 rx_map = &pinmap;
124 break;
125 }
126 }
127
128 if (!tx_map || !rx_map || rx_map->peripheral != tx_map->peripheral) {
129 return {(int) NC, NC, (int) NC, NC, (int) NC, false};
130 }
131
132 if (tx_map->pin == CONSOLE_TX && rx_map->pin == CONSOLE_RX) {
133 return {tx_map->peripheral, tx_map->pin, tx_map->function, rx_map->pin, rx_map->function, true};
134 } else {
135 return {tx_map->peripheral, tx_map->pin, tx_map->function, rx_map->pin, rx_map->function, false};
136 }
137}
138
139#if defined(DEVICE_SERIAL_FC) && defined(PINMAP_UART_RTS) && defined(PINMAP_UART_CTS)
140MSTD_CONSTEXPR_FN_14 serial_fc_pinmap_t get_uart_fc_pinmap(const PinName rxflow, const PinName txflow)
141{
142 const PinMap *rts_map = nullptr;
143 for (const PinMap &pinmap : PINMAP_UART_RTS) {
144 if (pinmap.pin == rxflow) {
145 rts_map = &pinmap;
146 break;
147 }
148 }
149
150 const PinMap *cts_map = nullptr;
151 for (const PinMap &pinmap : PINMAP_UART_CTS) {
152 if (pinmap.pin == txflow) {
153 cts_map = &pinmap;
154 break;
155 }
156 }
157
158 if ((!rts_map || !cts_map) || (rts_map->peripheral != cts_map->peripheral)) {
159 return {(int) NC, NC, (int) NC, NC, (int) NC};
160 }
161
162 return {cts_map->peripheral, cts_map->pin, cts_map->function, rts_map->pin, rts_map->function};
163}
164#endif // DEVICE_SERIAL_FC
165#endif // DEVICE_SERIAL
166
167#if defined(DEVICE_SPI) && defined(PINMAP_SPI_MOSI) && defined(PINMAP_SPI_MISO) && defined(PINMAP_SPI_SCLK) && defined(PINMAP_SPI_SSEL)
168MSTD_CONSTEXPR_FN_14 spi_pinmap_t get_spi_pinmap(const PinName mosi, const PinName miso, const PinName sclk, const PinName ssel = NC)
169{
170 const PinMap *mosi_map = nullptr;
171 for (const PinMap &pinmap : PINMAP_SPI_MOSI) {
172 if (pinmap.pin == mosi) {
173 mosi_map = &pinmap;
174 break;
175 }
176 }
177
178 const PinMap *miso_map = nullptr;
179 for (const PinMap &pinmap : PINMAP_SPI_MISO) {
180 if (pinmap.pin == miso) {
181 miso_map = &pinmap;
182 break;
183 }
184 }
185
186 const PinMap *sclk_map = nullptr;
187 for (const PinMap &pinmap : PINMAP_SPI_SCLK) {
188 if (pinmap.pin == sclk) {
189 sclk_map = &pinmap;
190 break;
191 }
192 }
193
194 const PinMap *ssel_map = nullptr;
195 for (const PinMap &pinmap : PINMAP_SPI_SSEL) {
196 if (pinmap.pin == ssel) {
197 ssel_map = &pinmap;
198 break;
199 }
200 }
201
202 if ((!mosi_map || !miso_map || !sclk_map || !ssel_map) ||
203 (mosi_map->peripheral != miso_map->peripheral || mosi_map->peripheral != sclk_map->peripheral) ||
204 (ssel_map->pin != NC && mosi_map->peripheral != ssel_map->peripheral)) {
205 return {(int) NC, NC, (int) NC, NC, (int) NC, NC, (int) NC, NC, (int) NC};
206 }
207
208 return {mosi_map->peripheral, mosi_map->pin, mosi_map->function, miso_map->pin, miso_map->function, sclk_map->pin, sclk_map->function, ssel_map->pin, ssel_map->function};
209}
210#endif // DEVICE_SPI
211
212#if defined(DEVICE_CAN) && defined(PINMAP_CAN_RD) && defined(PINMAP_CAN_TD)
213MSTD_CONSTEXPR_FN_14 can_pinmap_t get_can_pinmap(const PinName rd, const PinName td)
214{
215 const PinMap *rd_map = nullptr;
216 for (const PinMap &pinmap : PINMAP_CAN_RD) {
217 if (pinmap.pin == rd) {
218 rd_map = &pinmap;
219 break;
220 }
221 }
222
223 const PinMap *td_map = nullptr;
224 for (const PinMap &pinmap : PINMAP_CAN_TD) {
225 if (pinmap.pin == td) {
226 td_map = &pinmap;
227 break;
228 }
229 }
230
231 if (!rd_map || !td_map || rd_map->peripheral != td_map->peripheral) {
232 return {(int) NC, NC, (int) NC, NC, (int) NC};
233 }
234
235 return {rd_map->peripheral, rd_map->pin, rd_map->function, td_map->pin, td_map->function};
236}
237#endif //DEVICE_CAN
238
239#if defined(DEVICE_QSPI) && defined(PINMAP_QSPI_DATA0) && defined(PINMAP_QSPI_DATA1) && defined(PINMAP_QSPI_DATA2) && defined(PINMAP_QSPI_DATA3) && defined(PINMAP_QSPI_SCLK) && defined(PINMAP_QSPI_SSEL)
240MSTD_CONSTEXPR_FN_14 qspi_pinmap_t get_qspi_pinmap(const PinName data0, const PinName data1, const PinName data2, const PinName data3, const PinName sclk, const PinName ssel)
241{
242 const PinMap *data0_map = nullptr;
243 for (const PinMap &pinmap : PINMAP_QSPI_DATA0) {
244 if (pinmap.pin == data0) {
245 data0_map = &pinmap;
246 break;
247 }
248 }
249
250 const PinMap *data1_map = nullptr;
251 for (const PinMap &pinmap : PINMAP_QSPI_DATA1) {
252 if (pinmap.pin == data1) {
253 data1_map = &pinmap;
254 break;
255 }
256 }
257
258 const PinMap *data2_map = nullptr;
259 for (const PinMap &pinmap : PINMAP_QSPI_DATA2) {
260 if (pinmap.pin == data2) {
261 data2_map = &pinmap;
262 break;
263 }
264 }
265
266 const PinMap *data3_map = nullptr;
267 for (const PinMap &pinmap : PINMAP_QSPI_DATA3) {
268 if (pinmap.pin == data3) {
269 data3_map = &pinmap;
270 break;
271 }
272 }
273
274 const PinMap *sclk_map = nullptr;
275 for (const PinMap &pinmap : PINMAP_QSPI_SCLK) {
276 if (pinmap.pin == sclk) {
277 sclk_map = &pinmap;
278 break;
279 }
280 }
281
282 const PinMap *ssel_map = nullptr;
283 for (const PinMap &pinmap : PINMAP_QSPI_SSEL) {
284 if (pinmap.pin == ssel) {
285 ssel_map = &pinmap;
286 break;
287 }
288 }
289
290 if (!data0_map || !data1_map || !data2_map || !data3_map || !sclk_map || !ssel_map || data0_map->peripheral != data1_map->peripheral || data0_map->peripheral != data2_map->peripheral || data0_map->peripheral != data3_map->peripheral || data0_map->peripheral != sclk_map->peripheral || data0_map->peripheral != ssel_map->peripheral) {
291 return {(int) NC, NC, (int) NC, NC, (int) NC, NC, (int) NC, NC, (int) NC};
292 }
293
294 return {data0_map->peripheral, data0_map->pin, data0_map->function, data1_map->pin, data1_map->function, data2_map->pin, data2_map->function, data3_map->pin, data3_map->function, sclk_map->pin, sclk_map->function, ssel_map->pin, ssel_map->function};
295}
296#endif //DEVICE_QSPI
297
298#if defined(DEVICE_OSPI) && defined(PINMAP_OSPI_DATA0) && defined(PINMAP_OSPI_DATA1) && defined(PINMAP_OSPI_DATA2) && defined(PINMAP_OSPI_DATA3) && defined(PINMAP_OSPI_DATA4) && defined(PINMAP_OSPI_DATA5) && defined(PINMAP_OSPI_DATA6) && defined(PINMAP_OSPI_DATA7) && defined(PINMAP_OSPI_SCLK) && defined(PINMAP_OSPI_SSEL) && defined(PINMAP_OSPI_DQS)
299MSTD_CONSTEXPR_FN_14 ospi_pinmap_t get_ospi_pinmap(const PinName data0, const PinName data1, const PinName data2, const PinName data3, const PinName data4, const PinName data5, const PinName data6, const PinName data7, const PinName sclk, const PinName ssel, const PinName dqs)
300{
301 const PinMap *data0_map = nullptr;
302 for (const PinMap &pinmap : PINMAP_OSPI_DATA0) {
303 if (pinmap.pin == data0) {
304 data0_map = &pinmap;
305 break;
306 }
307 }
308
309 const PinMap *data1_map = nullptr;
310 for (const PinMap &pinmap : PINMAP_OSPI_DATA1) {
311 if (pinmap.pin == data1) {
312 data1_map = &pinmap;
313 break;
314 }
315 }
316
317 const PinMap *data2_map = nullptr;
318 for (const PinMap &pinmap : PINMAP_OSPI_DATA2) {
319 if (pinmap.pin == data2) {
320 data2_map = &pinmap;
321 break;
322 }
323 }
324
325 const PinMap *data3_map = nullptr;
326 for (const PinMap &pinmap : PINMAP_OSPI_DATA3) {
327 if (pinmap.pin == data3) {
328 data3_map = &pinmap;
329 break;
330 }
331 }
332
333 const PinMap *data4_map = nullptr;
334 for (const PinMap &pinmap : PINMAP_OSPI_DATA4) {
335 if (pinmap.pin == data4) {
336 data4_map = &pinmap;
337 break;
338 }
339 }
340
341 const PinMap *data5_map = nullptr;
342 for (const PinMap &pinmap : PINMAP_OSPI_DATA5) {
343 if (pinmap.pin == data5) {
344 data5_map = &pinmap;
345 break;
346 }
347 }
348
349 const PinMap *data6_map = nullptr;
350 for (const PinMap &pinmap : PINMAP_OSPI_DATA6) {
351 if (pinmap.pin == data6) {
352 data6_map = &pinmap;
353 break;
354 }
355 }
356
357 const PinMap *data7_map = nullptr;
358 for (const PinMap &pinmap : PINMAP_OSPI_DATA7) {
359 if (pinmap.pin == data7) {
360 data7_map = &pinmap;
361 break;
362 }
363 }
364
365 const PinMap *sclk_map = nullptr;
366 for (const PinMap &pinmap : PINMAP_OSPI_SCLK) {
367 if (pinmap.pin == sclk) {
368 sclk_map = &pinmap;
369 break;
370 }
371 }
372
373 const PinMap *ssel_map = nullptr;
374 for (const PinMap &pinmap : PINMAP_OSPI_SSEL) {
375 if (pinmap.pin == ssel) {
376 ssel_map = &pinmap;
377 break;
378 }
379 }
380
381 const PinMap *dqs_map = nullptr;
382 for (const PinMap &pinmap : PINMAP_OSPI_DQS) {
383 if (pinmap.pin == dqs) {
384 dqs_map = &pinmap;
385 break;
386 }
387 }
388
389
390 if (!data0_map || !data1_map || !data2_map || !data3_map || !data4_map || !data5_map || !data6_map || !data7_map || !sclk_map || !ssel_map || !dqs_map || data0_map->peripheral != data1_map->peripheral || data0_map->peripheral != data2_map->peripheral || data0_map->peripheral != data3_map->peripheral || data0_map->peripheral != data4_map->peripheral || data0_map->peripheral != data5_map->peripheral || data0_map->peripheral != data6_map->peripheral || data0_map->peripheral != data7_map->peripheral || data0_map->peripheral != sclk_map->peripheral || data0_map->peripheral != ssel_map->peripheral || data0_map->peripheral != dqs_map->peripheral) {
391 return {(int) NC, NC, (int) NC, NC, (int) NC, NC, (int) NC, NC, (int) NC, NC, (int) NC, NC, (int) NC, NC, (int) NC, NC, (int) NC};
392 }
393
394 return {data0_map->peripheral, data0_map->pin, data0_map->function, data1_map->pin, data1_map->function, data2_map->pin, data2_map->function, data3_map->pin, data3_map->function, data4_map->pin, data4_map->function, data5_map->pin, data5_map->function, data6_map->pin, data6_map->function, data7_map->pin, data7_map->function, sclk_map->pin, sclk_map->function, ssel_map->pin, ssel_map->function, dqs_map->pin, dqs_map->function};
395}
396#endif //DEVICE_OSPI
397
398#else // STATIC_PINMAP_READY
399
400#if DEVICE_PWMOUT
401MSTD_CONSTEXPR_FN_14 PinMap get_pwm_pinmap(const PinName pin)
402{
403 return {pin, (int) NC, (int) NC};
404}
405#endif // DEVICE_PWMOUT
406
407#if DEVICE_ANALOGIN
408MSTD_CONSTEXPR_FN_14 PinMap get_analogin_pinmap(const PinName pin)
409{
410 return {pin, (int) NC, (int) NC};
411}
412#endif // DEVICE_ANALOGIN
413
414#if DEVICE_ANALOGOUT
415MSTD_CONSTEXPR_FN_14 PinMap get_analogout_pinmap(const PinName pin)
416{
417 return {pin, (int) NC, (int) NC};
418}
419#endif // DEVICE_ANALOGOUT
420
421#if DEVICE_I2C
422MSTD_CONSTEXPR_FN_14 i2c_pinmap_t get_i2c_pinmap(const PinName sda, const PinName scl)
423{
424 return {(int) NC, sda, (int) NC, scl, (int) NC};
425}
426#endif //DEVICE_I2C
427
428#if DEVICE_SERIAL
429MSTD_CONSTEXPR_FN_14 serial_pinmap_t get_uart_pinmap(const PinName tx, const PinName rx)
430{
431 return {(int) NC, tx, (int) NC, rx, (int) NC, false};
432}
433
434#if DEVICE_SERIAL_FC
435MSTD_CONSTEXPR_FN_14 serial_fc_pinmap_t get_uart_fc_pinmap(const PinName rxflow, const PinName txflow)
436{
437 return {(int) NC, txflow, (int) NC, rxflow, (int) NC};
438}
439#endif // DEVICE_SERIAL_FC
440#endif // DEVICE_SERIAL
441
442#if DEVICE_SPI
443MSTD_CONSTEXPR_FN_14 spi_pinmap_t get_spi_pinmap(const PinName mosi, const PinName miso, const PinName sclk, const PinName ssel)
444{
445 return {(int) NC, mosi, (int) NC, miso, (int) NC, sclk, (int) NC, ssel, (int) NC};
446}
447#endif // DEVICE_SERIAL
448
449#if DEVICE_CAN
450MSTD_CONSTEXPR_FN_14 can_pinmap_t get_can_pinmap(const PinName rd, const PinName td)
451{
452 return {(int) NC, rd, (int) NC, td, (int) NC};
453}
454#endif //DEVICE_CAN
455
456#if DEVICE_QSPI
457MSTD_CONSTEXPR_FN_14 qspi_pinmap_t get_qspi_pinmap(const PinName data0, const PinName data1, const PinName data2, const PinName data3, const PinName sclk, const PinName ssel)
458{
459 return {(int) NC, data0, (int) NC, data1, (int) NC, data2, (int) NC, data3, (int) NC, sclk, (int) NC, ssel, (int) NC};
460}
461#endif //DEVICE_QSPI
462
463#if DEVICE_OSPI
464MSTD_CONSTEXPR_FN_14 ospi_pinmap_t get_ospi_pinmap(const PinName data0, const PinName data1, const PinName data2, const PinName data3, const PinName data4, const PinName data5, const PinName data6, const PinName data7, const PinName sclk, const PinName ssel, const PinName dqs)
465{
466 return {(int) NC, data0, (int) NC, data1, (int) NC, data2, (int) NC, data3, (int) NC, data4, (int) NC, data5, (int) NC, data6, (int) NC, data7, (int) NC, sclk, (int) NC, ssel, (int) NC, dqs, (int) NC};
467}
468#endif //DEVICE_OSPI
469
470#endif // STATIC_PINMAP_READY
471
472#endif // STATIC_PINMAP_H
Definition: pinmap.h:31